Skip to content

Commit

Permalink
Add Player Tab list
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Aug 12, 2024
1 parent 5b63611 commit 65c2207
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 14 deletions.
20 changes: 20 additions & 0 deletions pumpkin-protocol/src/client/play/c_player_remove.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use pumpkin_macros::packet;
use serde::Serialize;

use crate::{uuid::UUID, VarInt};

#[derive(Serialize, Clone)]
#[packet(0x3D)]
pub struct CRemovePlayerInfo<'a> {
players_count: VarInt,
players: &'a [UUID],
}

impl<'a> CRemovePlayerInfo<'a> {
pub fn new(players_count: VarInt, players: &'a [UUID]) -> Self {
Self {
players_count,
players,
}
}
}
2 changes: 2 additions & 0 deletions pumpkin-protocol/src/client/play/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod c_play_disconnect;
mod c_player_abilities;
mod c_player_chat_message;
mod c_player_info_update;
mod c_player_remove;
mod c_remove_entities;
mod c_set_held_item;
mod c_set_title;
Expand All @@ -38,6 +39,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_player_remove::*;
pub use c_remove_entities::*;
pub use c_set_held_item::*;
pub use c_set_title::*;
Expand Down
1 change: 1 addition & 0 deletions pumpkin-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use thiserror::Error;
pub mod bytebuf;
pub mod client;
pub mod server;
pub mod uuid;

pub mod packet_decoder;
pub mod packet_encoder;
Expand Down
12 changes: 12 additions & 0 deletions pumpkin-protocol/src/uuid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use serde::Serialize;

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())
}
}
4 changes: 1 addition & 3 deletions pumpkin/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,7 @@ impl Client {
}
Ok(n) => {
bytes_read += n;
if bytes_read == received_data.len() {
received_data.resize(received_data.len() + 1024, 0);
}
received_data.extend(&vec![0; n]);
}
// Would block "errors" are the OS's way of saying that the
// connection is not actually ready to perform this I/O operation.
Expand Down
31 changes: 20 additions & 11 deletions pumpkin/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ use pumpkin_protocol::{
config::CPluginMessage,
play::{
CChunkDataUpdateLight, CGameEvent, CLogin, CPlayerAbilities, CPlayerInfoUpdate,
CRemoveEntities, CSpawnEntity, PlayerAction,
CRemoveEntities, CRemovePlayerInfo, CSpawnEntity, PlayerAction,
},
},
uuid::UUID,
BitSet, ClientPacket, Players, Sample, StatusResponse, VarInt, Version, CURRENT_MC_PROTOCOL,
};
use pumpkin_registry::Registry;
Expand Down Expand Up @@ -128,6 +129,8 @@ impl Server {
// todo: put this into the entitiy struct
if client.is_player() {
let id = client.player.as_ref().unwrap().entity_id();
let uuid = client.gameprofile.as_ref().unwrap().id;
self.broadcast_packet(&mut client, CRemovePlayerInfo::new(1.into(), &[UUID(uuid)]));
self.broadcast_packet(&mut client, CRemoveEntities::new(&[id.into()]))
}
}
Expand Down Expand Up @@ -185,13 +188,16 @@ impl Server {
self.broadcast_packet(
client,
CPlayerInfoUpdate::new(
0x01,
0x01 | 0x08,
&[pumpkin_protocol::client::play::Player {
uuid: gameprofile.id,
actions: vec![PlayerAction::AddPlayer {
name: gameprofile.name.clone(),
properties: gameprofile.properties.clone(),
}],
actions: vec![
PlayerAction::AddPlayer {
name: gameprofile.name.clone(),
properties: gameprofile.properties.clone(),
},
PlayerAction::UpdateListed { listed: true },
],
}],
),
);
Expand All @@ -204,14 +210,17 @@ impl Server {
let gameprofile = client.gameprofile.as_ref().unwrap();
entries.push(pumpkin_protocol::client::play::Player {
uuid: gameprofile.id,
actions: vec![PlayerAction::AddPlayer {
name: gameprofile.name.clone(),
properties: gameprofile.properties.clone(),
}],
actions: vec![
PlayerAction::AddPlayer {
name: gameprofile.name.clone(),
properties: gameprofile.properties.clone(),
},
PlayerAction::UpdateListed { listed: true },
],
})
}
}
client.send_packet(CPlayerInfoUpdate::new(0x01, &entries));
client.send_packet(CPlayerInfoUpdate::new(0x01 | 0x08, &entries));

// Start waiting for level chunks
client.send_packet(CGameEvent::new(13, 0.0));
Expand Down

0 comments on commit 65c2207

Please sign in to comment.