Add Player Tab list

This commit is contained in:
Snowiiii 2024-08-12 15:09:34 +02:00
parent 5b636111e4
commit 65c2207c0a
6 changed files with 56 additions and 14 deletions

View File

@ -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,
}
}
}

View File

@ -12,6 +12,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_player_remove;
mod c_remove_entities; mod c_remove_entities;
mod c_set_held_item; mod c_set_held_item;
mod c_set_title; mod c_set_title;
@ -38,6 +39,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_player_remove::*;
pub use c_remove_entities::*; pub use c_remove_entities::*;
pub use c_set_held_item::*; pub use c_set_held_item::*;
pub use c_set_title::*; pub use c_set_title::*;

View File

@ -8,6 +8,7 @@ use thiserror::Error;
pub mod bytebuf; pub mod bytebuf;
pub mod client; pub mod client;
pub mod server; pub mod server;
pub mod uuid;
pub mod packet_decoder; pub mod packet_decoder;
pub mod packet_encoder; pub mod packet_encoder;

View File

@ -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())
}
}

View File

@ -294,9 +294,7 @@ impl Client {
} }
Ok(n) => { Ok(n) => {
bytes_read += n; bytes_read += n;
if bytes_read == received_data.len() { received_data.extend(&vec![0; n]);
received_data.resize(received_data.len() + 1024, 0);
}
} }
// Would block "errors" are the OS's way of saying that the // Would block "errors" are the OS's way of saying that the
// connection is not actually ready to perform this I/O operation. // connection is not actually ready to perform this I/O operation.

View File

@ -17,9 +17,10 @@ use pumpkin_protocol::{
config::CPluginMessage, config::CPluginMessage,
play::{ play::{
CChunkDataUpdateLight, CGameEvent, CLogin, CPlayerAbilities, CPlayerInfoUpdate, CChunkDataUpdateLight, CGameEvent, CLogin, CPlayerAbilities, CPlayerInfoUpdate,
CRemoveEntities, CSpawnEntity, PlayerAction, CRemoveEntities, CRemovePlayerInfo, CSpawnEntity, PlayerAction,
}, },
}, },
uuid::UUID,
BitSet, ClientPacket, Players, Sample, StatusResponse, VarInt, Version, CURRENT_MC_PROTOCOL, BitSet, ClientPacket, Players, Sample, StatusResponse, VarInt, Version, CURRENT_MC_PROTOCOL,
}; };
use pumpkin_registry::Registry; use pumpkin_registry::Registry;
@ -128,6 +129,8 @@ impl Server {
// todo: put this into the entitiy struct // todo: put this into the entitiy struct
if client.is_player() { if client.is_player() {
let id = client.player.as_ref().unwrap().entity_id(); 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()])) self.broadcast_packet(&mut client, CRemoveEntities::new(&[id.into()]))
} }
} }
@ -185,13 +188,16 @@ impl Server {
self.broadcast_packet( self.broadcast_packet(
client, client,
CPlayerInfoUpdate::new( CPlayerInfoUpdate::new(
0x01, 0x01 | 0x08,
&[pumpkin_protocol::client::play::Player { &[pumpkin_protocol::client::play::Player {
uuid: gameprofile.id, uuid: gameprofile.id,
actions: vec![PlayerAction::AddPlayer { actions: vec![
PlayerAction::AddPlayer {
name: gameprofile.name.clone(), name: gameprofile.name.clone(),
properties: gameprofile.properties.clone(), properties: gameprofile.properties.clone(),
}], },
PlayerAction::UpdateListed { listed: true },
],
}], }],
), ),
); );
@ -204,14 +210,17 @@ impl Server {
let gameprofile = client.gameprofile.as_ref().unwrap(); let gameprofile = client.gameprofile.as_ref().unwrap();
entries.push(pumpkin_protocol::client::play::Player { entries.push(pumpkin_protocol::client::play::Player {
uuid: gameprofile.id, uuid: gameprofile.id,
actions: vec![PlayerAction::AddPlayer { actions: vec![
PlayerAction::AddPlayer {
name: gameprofile.name.clone(), name: gameprofile.name.clone(),
properties: gameprofile.properties.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 // Start waiting for level chunks
client.send_packet(CGameEvent::new(13, 0.0)); client.send_packet(CGameEvent::new(13, 0.0));