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 pumpkin_macros::packet;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::uuid::UUID;
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[packet(0x09)]
|
#[packet(0x09)]
|
||||||
pub struct CConfigAddResourcePack<'a> {
|
pub struct CConfigAddResourcePack<'a> {
|
||||||
uuid: UUID,
|
uuid: uuid::Uuid,
|
||||||
url: &'a str,
|
url: &'a str,
|
||||||
hash: &'a str, // max 40
|
hash: &'a str, // max 40
|
||||||
forced: bool,
|
forced: bool,
|
||||||
@ -23,7 +21,7 @@ impl<'a> CConfigAddResourcePack<'a> {
|
|||||||
prompt_message: Option<TextComponent<'a>>,
|
prompt_message: Option<TextComponent<'a>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
uuid: UUID(uuid),
|
uuid,
|
||||||
url,
|
url,
|
||||||
hash,
|
hash,
|
||||||
forced,
|
forced,
|
||||||
|
|||||||
@ -2,11 +2,12 @@ use pumpkin_core::text::TextComponent;
|
|||||||
use pumpkin_macros::packet;
|
use pumpkin_macros::packet;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{uuid::UUID, BitSet, VarInt};
|
use crate::{BitSet, VarInt};
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[packet(0x39)]
|
#[packet(0x39)]
|
||||||
pub struct CPlayerChatMessage<'a> {
|
pub struct CPlayerChatMessage<'a> {
|
||||||
sender: UUID,
|
#[serde(with = "uuid::serde::compact")]
|
||||||
|
sender: uuid::Uuid,
|
||||||
index: VarInt,
|
index: VarInt,
|
||||||
message_signature: Option<&'a [u8]>,
|
message_signature: Option<&'a [u8]>,
|
||||||
message: &'a str,
|
message: &'a str,
|
||||||
@ -24,7 +25,7 @@ pub struct CPlayerChatMessage<'a> {
|
|||||||
impl<'a> CPlayerChatMessage<'a> {
|
impl<'a> CPlayerChatMessage<'a> {
|
||||||
#[expect(clippy::too_many_arguments)]
|
#[expect(clippy::too_many_arguments)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
sender: UUID,
|
sender: uuid::Uuid,
|
||||||
index: VarInt,
|
index: VarInt,
|
||||||
message_signature: Option<&'a [u8]>,
|
message_signature: Option<&'a [u8]>,
|
||||||
message: &'a str,
|
message: &'a str,
|
||||||
|
|||||||
@ -1,20 +1,32 @@
|
|||||||
use pumpkin_macros::packet;
|
use pumpkin_macros::packet;
|
||||||
use serde::Serialize;
|
use serde::{ser::SerializeSeq, Serialize};
|
||||||
|
|
||||||
use crate::{uuid::UUID, VarInt};
|
use crate::VarInt;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[packet(0x3D)]
|
#[packet(0x3D)]
|
||||||
pub struct CRemovePlayerInfo<'a> {
|
pub struct CRemovePlayerInfo<'a> {
|
||||||
players_count: VarInt,
|
players_count: VarInt,
|
||||||
players: &'a [UUID],
|
#[serde(serialize_with = "serialize_slice_uuids")]
|
||||||
|
players: &'a [uuid::Uuid],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CRemovePlayerInfo<'a> {
|
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 {
|
Self {
|
||||||
players_count,
|
players_count,
|
||||||
players,
|
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 pumpkin_macros::packet;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{uuid::UUID, VarInt};
|
use crate::VarInt;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[packet(0x01)]
|
#[packet(0x01)]
|
||||||
pub struct CSpawnEntity {
|
pub struct CSpawnEntity {
|
||||||
entity_id: VarInt,
|
entity_id: VarInt,
|
||||||
entity_uuid: UUID,
|
#[serde(with = "uuid::serde::compact")]
|
||||||
|
entity_uuid: uuid::Uuid,
|
||||||
typ: VarInt,
|
typ: VarInt,
|
||||||
x: f64,
|
x: f64,
|
||||||
y: f64,
|
y: f64,
|
||||||
@ -25,7 +26,7 @@ impl CSpawnEntity {
|
|||||||
#[expect(clippy::too_many_arguments)]
|
#[expect(clippy::too_many_arguments)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
entity_id: VarInt,
|
entity_id: VarInt,
|
||||||
entity_uuid: UUID,
|
entity_uuid: uuid::Uuid,
|
||||||
typ: VarInt,
|
typ: VarInt,
|
||||||
x: f64,
|
x: f64,
|
||||||
y: f64,
|
y: f64,
|
||||||
|
|||||||
@ -10,7 +10,6 @@ pub mod packet_decoder;
|
|||||||
pub mod packet_encoder;
|
pub mod packet_encoder;
|
||||||
pub mod server;
|
pub mod server;
|
||||||
pub mod slot;
|
pub mod slot;
|
||||||
pub mod uuid;
|
|
||||||
|
|
||||||
/// To current Minecraft protocol
|
/// To current Minecraft protocol
|
||||||
/// Don't forget to change this when porting
|
/// 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 entity = &self.entity;
|
||||||
let world = &entity.world;
|
let world = &entity.world;
|
||||||
world.broadcast_packet_all(&CPlayerChatMessage::new(
|
world.broadcast_packet_all(&CPlayerChatMessage::new(
|
||||||
pumpkin_protocol::uuid::UUID(gameprofile.id),
|
gameprofile.id,
|
||||||
1.into(),
|
1.into(),
|
||||||
chat_message.signature.as_deref(),
|
chat_message.signature.as_deref(),
|
||||||
&message,
|
&message,
|
||||||
|
|||||||
@ -13,7 +13,6 @@ use pumpkin_protocol::{
|
|||||||
CChunkData, CGameEvent, CLogin, CPlayerAbilities, CPlayerInfoUpdate, CRemoveEntities,
|
CChunkData, CGameEvent, CLogin, CPlayerAbilities, CPlayerInfoUpdate, CRemoveEntities,
|
||||||
CRemovePlayerInfo, CSetEntityMetadata, CSpawnEntity, GameEvent, Metadata, PlayerAction,
|
CRemovePlayerInfo, CSetEntityMetadata, CSpawnEntity, GameEvent, Metadata, PlayerAction,
|
||||||
},
|
},
|
||||||
uuid::UUID,
|
|
||||||
ClientPacket, VarInt,
|
ClientPacket, VarInt,
|
||||||
};
|
};
|
||||||
use pumpkin_world::level::Level;
|
use pumpkin_world::level::Level;
|
||||||
@ -170,7 +169,7 @@ impl World {
|
|||||||
// TODO: add velo
|
// TODO: add velo
|
||||||
&CSpawnEntity::new(
|
&CSpawnEntity::new(
|
||||||
entity_id.into(),
|
entity_id.into(),
|
||||||
UUID(gameprofile.id),
|
gameprofile.id,
|
||||||
(EntityType::Player as i32).into(),
|
(EntityType::Player as i32).into(),
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
@ -192,7 +191,7 @@ impl World {
|
|||||||
let gameprofile = &existing_player.gameprofile;
|
let gameprofile = &existing_player.gameprofile;
|
||||||
player.client.send_packet(&CSpawnEntity::new(
|
player.client.send_packet(&CSpawnEntity::new(
|
||||||
existing_player.entity_id().into(),
|
existing_player.entity_id().into(),
|
||||||
UUID(gameprofile.id),
|
gameprofile.id,
|
||||||
(EntityType::Player as i32).into(),
|
(EntityType::Player as i32).into(),
|
||||||
pos.x,
|
pos.x,
|
||||||
pos.y,
|
pos.y,
|
||||||
@ -292,7 +291,7 @@ impl World {
|
|||||||
let uuid = player.gameprofile.id;
|
let uuid = player.gameprofile.id;
|
||||||
self.broadcast_packet_expect(
|
self.broadcast_packet_expect(
|
||||||
&[player.client.token],
|
&[player.client.token],
|
||||||
&CRemovePlayerInfo::new(1.into(), &[UUID(uuid)]),
|
&CRemovePlayerInfo::new(1.into(), &[uuid]),
|
||||||
);
|
);
|
||||||
self.remove_entity(&player.entity);
|
self.remove_entity(&player.entity);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user