Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
873df335b8
16
pumpkin-protocol/src/client/play/c_remove_entities.rs
Normal file
16
pumpkin-protocol/src/client/play/c_remove_entities.rs
Normal file
@ -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<VarInt>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CRemoveEntities {
|
||||||
|
pub fn new(entitiy_ids: Vec<VarInt>) -> Self {
|
||||||
|
Self { entitiy_ids }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,6 +9,7 @@ mod c_play_disconnect;
|
|||||||
mod c_player_abilities;
|
mod c_player_abilities;
|
||||||
mod c_player_chat_message;
|
mod c_player_chat_message;
|
||||||
mod c_player_info_update;
|
mod c_player_info_update;
|
||||||
|
mod c_remove_entities;
|
||||||
mod c_set_held_item;
|
mod c_set_held_item;
|
||||||
mod c_spawn_player;
|
mod c_spawn_player;
|
||||||
mod c_sync_player_position;
|
mod c_sync_player_position;
|
||||||
@ -29,6 +30,7 @@ pub use c_play_disconnect::*;
|
|||||||
pub use c_player_abilities::*;
|
pub use c_player_abilities::*;
|
||||||
pub use c_player_chat_message::*;
|
pub use c_player_chat_message::*;
|
||||||
pub use c_player_info_update::*;
|
pub use c_player_info_update::*;
|
||||||
|
pub use c_remove_entities::*;
|
||||||
pub use c_set_held_item::*;
|
pub use c_set_held_item::*;
|
||||||
pub use c_spawn_player::*;
|
pub use c_spawn_player::*;
|
||||||
pub use c_sync_player_position::*;
|
pub use c_sync_player_position::*;
|
||||||
|
|||||||
@ -258,7 +258,9 @@ impl Client {
|
|||||||
SPlayerCommand::PACKET_ID => {
|
SPlayerCommand::PACKET_ID => {
|
||||||
self.handle_player_command(server, SPlayerCommand::read(bytebuf).unwrap())
|
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),
|
_ => log::error!("Failed to handle player packet id {}", packet.id.0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -139,8 +139,8 @@ async fn main() -> io::Result<()> {
|
|||||||
};
|
};
|
||||||
if done {
|
if done {
|
||||||
if let Some(client) = connections.remove(&token) {
|
if let Some(client) = connections.remove(&token) {
|
||||||
let mut client = client.borrow_mut();
|
|
||||||
server.remove_client(&token);
|
server.remove_client(&token);
|
||||||
|
let mut client = client.borrow_mut();
|
||||||
poll.registry().deregister(&mut client.connection)?;
|
poll.registry().deregister(&mut client.connection)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@ use pumpkin_protocol::{
|
|||||||
config::CPluginMessage,
|
config::CPluginMessage,
|
||||||
play::{
|
play::{
|
||||||
CChunkDataUpdateLight, CGameEvent, CLogin, CPlayerAbilities, CPlayerInfoUpdate,
|
CChunkDataUpdateLight, CGameEvent, CLogin, CPlayerAbilities, CPlayerInfoUpdate,
|
||||||
CSpawnEntity, PlayerAction,
|
CRemoveEntities, CSpawnEntity, PlayerAction,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
BitSet, ClientPacket, Players, Sample, StatusResponse, VarInt, Version, CURRENT_MC_PROTOCOL,
|
BitSet, ClientPacket, Players, Sample, StatusResponse, VarInt, Version, CURRENT_MC_PROTOCOL,
|
||||||
@ -109,7 +109,14 @@ impl Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_client(&mut self, token: &Token) {
|
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
|
// here is where the magic happens
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user