standardize use of compact serialization for UUIDs.
This commit is contained in:
parent
c4dc376bc9
commit
c13261ba20
@ -2,12 +2,10 @@ use pumpkin_core::text::TextComponent;
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::uuid::UUID;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x09)]
|
||||
pub struct CConfigAddResourcePack<'a> {
|
||||
uuid: UUID,
|
||||
uuid: uuid::Uuid,
|
||||
url: &'a str,
|
||||
hash: &'a str, // max 40
|
||||
forced: bool,
|
||||
@ -23,7 +21,7 @@ impl<'a> CConfigAddResourcePack<'a> {
|
||||
prompt_message: Option<TextComponent<'a>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
uuid: UUID(uuid),
|
||||
uuid,
|
||||
url,
|
||||
hash,
|
||||
forced,
|
||||
|
||||
@ -2,11 +2,12 @@ use pumpkin_core::text::TextComponent;
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{uuid::UUID, BitSet, VarInt};
|
||||
use crate::{BitSet, VarInt};
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x39)]
|
||||
pub struct CPlayerChatMessage<'a> {
|
||||
sender: UUID,
|
||||
#[serde(with = "uuid::serde::compact")]
|
||||
sender: uuid::Uuid,
|
||||
index: VarInt,
|
||||
message_signature: Option<&'a [u8]>,
|
||||
message: &'a str,
|
||||
@ -24,7 +25,7 @@ pub struct CPlayerChatMessage<'a> {
|
||||
impl<'a> CPlayerChatMessage<'a> {
|
||||
#[expect(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
sender: UUID,
|
||||
sender: uuid::Uuid,
|
||||
index: VarInt,
|
||||
message_signature: Option<&'a [u8]>,
|
||||
message: &'a str,
|
||||
|
||||
@ -1,20 +1,32 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
use serde::{ser::SerializeSeq, Serialize};
|
||||
|
||||
use crate::{uuid::UUID, VarInt};
|
||||
use crate::VarInt;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x3D)]
|
||||
pub struct CRemovePlayerInfo<'a> {
|
||||
players_count: VarInt,
|
||||
players: &'a [UUID],
|
||||
#[serde(serialize_with = "serialize_slice_uuids")]
|
||||
players: &'a [uuid::Uuid],
|
||||
}
|
||||
|
||||
impl<'a> CRemovePlayerInfo<'a> {
|
||||
pub fn new(players_count: VarInt, players: &'a [UUID]) -> Self {
|
||||
pub fn new(players_count: VarInt, players: &'a [uuid::Uuid]) -> Self {
|
||||
Self {
|
||||
players_count,
|
||||
players,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_slice_uuids<S: serde::Serializer>(
|
||||
uuids: &[uuid::Uuid],
|
||||
serializer: S,
|
||||
) -> Result<S::Ok, S::Error> {
|
||||
let mut seq = serializer.serialize_seq(Some(uuids.len()))?;
|
||||
for uuid in uuids {
|
||||
seq.serialize_element(uuid.as_bytes())?;
|
||||
}
|
||||
seq.end()
|
||||
}
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{uuid::UUID, VarInt};
|
||||
use crate::VarInt;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x01)]
|
||||
pub struct CSpawnEntity {
|
||||
entity_id: VarInt,
|
||||
entity_uuid: UUID,
|
||||
#[serde(with = "uuid::serde::compact")]
|
||||
entity_uuid: uuid::Uuid,
|
||||
typ: VarInt,
|
||||
x: f64,
|
||||
y: f64,
|
||||
@ -25,7 +26,7 @@ impl CSpawnEntity {
|
||||
#[expect(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
entity_id: VarInt,
|
||||
entity_uuid: UUID,
|
||||
entity_uuid: uuid::Uuid,
|
||||
typ: VarInt,
|
||||
x: f64,
|
||||
y: f64,
|
||||
|
||||
@ -10,7 +10,6 @@ pub mod packet_decoder;
|
||||
pub mod packet_encoder;
|
||||
pub mod server;
|
||||
pub mod slot;
|
||||
pub mod uuid;
|
||||
|
||||
/// To current Minecraft protocol
|
||||
/// Don't forget to change this when porting
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Clone)]
|
||||
/// Wrapper around uuid::UUID, Please use this in every Packet containing a UUID
|
||||
/// We use this to we can do own Serializing
|
||||
pub struct UUID(pub uuid::Uuid);
|
||||
|
||||
impl Serialize for UUID {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_bytes(self.0.as_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
impl UUID {
|
||||
pub fn new(data: &[u8]) -> Self {
|
||||
Self(uuid::Uuid::new_v3(&uuid::Uuid::NAMESPACE_DNS, data))
|
||||
}
|
||||
}
|
||||
@ -316,7 +316,7 @@ impl Player {
|
||||
let entity = &self.entity;
|
||||
let world = &entity.world;
|
||||
world.broadcast_packet_all(&CPlayerChatMessage::new(
|
||||
pumpkin_protocol::uuid::UUID(gameprofile.id),
|
||||
gameprofile.id,
|
||||
1.into(),
|
||||
chat_message.signature.as_deref(),
|
||||
&message,
|
||||
|
||||
@ -13,7 +13,6 @@ use pumpkin_protocol::{
|
||||
CChunkData, CGameEvent, CLogin, CPlayerAbilities, CPlayerInfoUpdate, CRemoveEntities,
|
||||
CRemovePlayerInfo, CSetEntityMetadata, CSpawnEntity, GameEvent, Metadata, PlayerAction,
|
||||
},
|
||||
uuid::UUID,
|
||||
ClientPacket, VarInt,
|
||||
};
|
||||
use pumpkin_world::level::Level;
|
||||
@ -170,7 +169,7 @@ impl World {
|
||||
// TODO: add velo
|
||||
&CSpawnEntity::new(
|
||||
entity_id.into(),
|
||||
UUID(gameprofile.id),
|
||||
gameprofile.id,
|
||||
(EntityType::Player as i32).into(),
|
||||
x,
|
||||
y,
|
||||
@ -192,7 +191,7 @@ impl World {
|
||||
let gameprofile = &existing_player.gameprofile;
|
||||
player.client.send_packet(&CSpawnEntity::new(
|
||||
existing_player.entity_id().into(),
|
||||
UUID(gameprofile.id),
|
||||
gameprofile.id,
|
||||
(EntityType::Player as i32).into(),
|
||||
pos.x,
|
||||
pos.y,
|
||||
@ -292,7 +291,7 @@ impl World {
|
||||
let uuid = player.gameprofile.id;
|
||||
self.broadcast_packet_expect(
|
||||
&[player.client.token],
|
||||
&CRemovePlayerInfo::new(1.into(), &[UUID(uuid)]),
|
||||
&CRemovePlayerInfo::new(1.into(), &[uuid]),
|
||||
);
|
||||
self.remove_entity(&player.entity);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user