diff --git a/pumpkin-protocol/src/client/play/c_remove_entities.rs b/pumpkin-protocol/src/client/play/c_remove_entities.rs new file mode 100644 index 000000000..e8dab896d --- /dev/null +++ b/pumpkin-protocol/src/client/play/c_remove_entities.rs @@ -0,0 +1,16 @@ +use pumpkin_macros::packet; +use serde::Serialize; + +use crate::VarInt; + +#[derive(Serialize, Clone)] +#[packet(0x42)] +pub struct CRemoveEntities { + entitiy_ids: Vec, +} + +impl CRemoveEntities { + pub fn new(entitiy_ids: Vec) -> Self { + Self { entitiy_ids } + } +} diff --git a/pumpkin-protocol/src/client/play/mod.rs b/pumpkin-protocol/src/client/play/mod.rs index e7aa90e77..f5ba00d37 100644 --- a/pumpkin-protocol/src/client/play/mod.rs +++ b/pumpkin-protocol/src/client/play/mod.rs @@ -9,6 +9,7 @@ mod c_play_disconnect; mod c_player_abilities; mod c_player_chat_message; mod c_player_info_update; +mod c_remove_entities; mod c_set_held_item; mod c_spawn_player; mod c_sync_player_position; @@ -29,6 +30,7 @@ pub use c_play_disconnect::*; pub use c_player_abilities::*; pub use c_player_chat_message::*; pub use c_player_info_update::*; +pub use c_remove_entities::*; pub use c_set_held_item::*; pub use c_spawn_player::*; pub use c_sync_player_position::*; diff --git a/pumpkin/src/client/mod.rs b/pumpkin/src/client/mod.rs index a9997b44b..387f1d491 100644 --- a/pumpkin/src/client/mod.rs +++ b/pumpkin/src/client/mod.rs @@ -258,7 +258,9 @@ impl Client { SPlayerCommand::PACKET_ID => { self.handle_player_command(server, SPlayerCommand::read(bytebuf).unwrap()) } - SSwingArm::PACKET_ID => self.handle_swing_arm(server, SSwingArm::read(bytebuf).unwrap()), + SSwingArm::PACKET_ID => { + self.handle_swing_arm(server, SSwingArm::read(bytebuf).unwrap()) + } _ => log::error!("Failed to handle player packet id {}", packet.id.0), } } diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 0b5372ae2..66bae804f 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -138,8 +138,8 @@ fn main() -> io::Result<()> { }; if done { if let Some(client) = connections.remove(&token) { - let mut client = client.borrow_mut(); server.remove_client(&token); + let mut client = client.borrow_mut(); poll.registry().deregister(&mut client.connection)?; } } diff --git a/pumpkin/src/server.rs b/pumpkin/src/server.rs index dd7b19235..399d6854e 100644 --- a/pumpkin/src/server.rs +++ b/pumpkin/src/server.rs @@ -15,7 +15,7 @@ use pumpkin_protocol::{ config::CPluginMessage, play::{ CChunkDataUpdateLight, CGameEvent, CLogin, CPlayerAbilities, CPlayerInfoUpdate, - CSpawnEntity, PlayerAction, + CRemoveEntities, CSpawnEntity, PlayerAction, }, }, BitSet, ClientPacket, Players, Sample, StatusResponse, VarInt, Version, CURRENT_MC_PROTOCOL, @@ -109,7 +109,14 @@ impl Server { } pub fn remove_client(&mut self, token: &Token) { - self.current_clients.remove(token); + let client = self.current_clients.remove(token).unwrap(); + let mut client = client.borrow_mut(); + // despawn the player + // todo: put this into the entitiy struct + if client.is_player() { + let id = client.player.as_ref().unwrap().entity_id(); + self.broadcast_packet(&mut client, CRemoveEntities::new(vec![id.into()])) + } } // here is where the magic happens