aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-04-27 18:00:50 +0000
committermat <github@matdoes.dev>2022-04-27 18:00:50 +0000
commit9b50886c30f3e9129e054b019581264c9e6cadaf (patch)
tree8dfcc5bb8980a86d650a0d3d7afb705624b818c6 /azalea-protocol/src/packets
parent60d1fa50c32c202dd04895caa51172948a4760b6 (diff)
downloadazalea-drasl-9b50886c30f3e9129e054b019581264c9e6cadaf.tar.xz
player info packet
Diffstat (limited to 'azalea-protocol/src/packets')
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs4
-rw-r--r--azalea-protocol/src/packets/game/clientbound_entity_event_packet.rs1
-rw-r--r--azalea-protocol/src/packets/game/clientbound_player_info_packet.rs101
-rwxr-xr-xazalea-protocol/src/packets/game/mod.rs2
-rwxr-xr-xazalea-protocol/src/packets/login/clientbound_game_profile_packet.rs2
5 files changed, 107 insertions, 3 deletions
diff --git a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs
index 0a16440e..b22570c1 100755
--- a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs
@@ -1,5 +1,5 @@
use super::GamePacket;
-use crate::mc_buf::{McBufReadable, McBufWritable, Readable};
+use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
use async_trait::async_trait;
use azalea_core::resource_location::ResourceLocation;
use std::hash::Hash;
@@ -115,7 +115,7 @@ impl McBufReadable for BrigadierString {
}
impl McBufWritable for BrigadierString {
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
- buf.write_i8(*self as i8);
+ buf.write_byte(*self as u8)?;
Ok(())
}
}
diff --git a/azalea-protocol/src/packets/game/clientbound_entity_event_packet.rs b/azalea-protocol/src/packets/game/clientbound_entity_event_packet.rs
index 82b0072d..55e4d419 100644
--- a/azalea-protocol/src/packets/game/clientbound_entity_event_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_entity_event_packet.rs
@@ -1,4 +1,3 @@
-use azalea_core::{game_type::GameType, resource_location::ResourceLocation};
use packet_macros::GamePacket;
// we can't identify the status in azalea-protocol since they vary depending on the entity
diff --git a/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs
new file mode 100644
index 00000000..370e6f83
--- /dev/null
+++ b/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs
@@ -0,0 +1,101 @@
+// i don't know the actual name of this packet, i couldn't find it in the source code
+
+use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
+use async_trait::async_trait;
+use azalea_chat::component::Component;
+use packet_macros::{GamePacket, McBufReadable, McBufWritable};
+use tokio::io::AsyncRead;
+use uuid::Uuid;
+
+#[derive(Clone, Debug, GamePacket)]
+pub struct ClientboundPlayerInfoPacket {
+ pub action: Action,
+}
+
+#[derive(Clone, Debug)]
+pub enum Action {
+ AddPlayer(Vec<AddPlayer>),
+ UpdateGameMode(Vec<UpdateGameMode>),
+ UpdateLatency(Vec<UpdateLatency>),
+ UpdateDisplayName(Vec<UpdateDisplayName>),
+ RemovePlayer(Vec<RemovePlayer>),
+}
+
+#[derive(Clone, Debug, McBufReadable, McBufWritable)]
+pub struct PlayerProperty {
+ name: String,
+ value: String,
+ signature: Option<String>,
+}
+
+#[derive(Clone, Debug, McBufReadable, McBufWritable)]
+pub struct AddPlayer {
+ uuid: Uuid,
+ properties: Vec<PlayerProperty>,
+ #[varint]
+ gamemode: u32,
+ #[varint]
+ ping: i32,
+ display_name: Option<Component>,
+}
+
+#[derive(Clone, Debug, McBufReadable, McBufWritable)]
+pub struct UpdateGameMode {
+ uuid: Uuid,
+ #[varint]
+ gamemode: u32,
+}
+
+#[derive(Clone, Debug, McBufReadable, McBufWritable)]
+pub struct UpdateLatency {
+ uuid: Uuid,
+ #[varint]
+ ping: i32,
+}
+
+#[derive(Clone, Debug, McBufReadable, McBufWritable)]
+pub struct UpdateDisplayName {
+ uuid: Uuid,
+ display_name: Option<Component>,
+}
+#[derive(Clone, Debug, McBufReadable, McBufWritable)]
+pub struct RemovePlayer {
+ uuid: Uuid,
+}
+
+#[async_trait]
+impl McBufReadable for Action {
+ async fn read_into<R>(buf: &mut R) -> Result<Self, String>
+ where
+ R: AsyncRead + std::marker::Unpin + std::marker::Send,
+ {
+ let id = buf.read_byte().await?;
+ Ok(match id {
+ 0 => Action::AddPlayer(Vec::<AddPlayer>::read_into(buf).await?),
+ 1 => Action::UpdateGameMode(Vec::<UpdateGameMode>::read_into(buf).await?),
+ 2 => Action::UpdateLatency(Vec::<UpdateLatency>::read_into(buf).await?),
+ 3 => Action::UpdateDisplayName(Vec::<UpdateDisplayName>::read_into(buf).await?),
+ 4 => Action::RemovePlayer(Vec::<RemovePlayer>::read_into(buf).await?),
+ _ => panic!("Unknown player info action id: {}", id),
+ })
+ }
+}
+impl McBufWritable for Action {
+ fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ buf.write_byte(match self {
+ Action::AddPlayer(_) => 0,
+ Action::UpdateGameMode(_) => 1,
+ Action::UpdateLatency(_) => 2,
+ Action::UpdateDisplayName(_) => 3,
+ Action::RemovePlayer(_) => 4,
+ })?;
+ match self {
+ Action::AddPlayer(players) => players.write_into(buf)?,
+ Action::UpdateGameMode(players) => players.write_into(buf)?,
+ Action::UpdateLatency(players) => players.write_into(buf)?,
+ Action::UpdateDisplayName(players) => players.write_into(buf)?,
+ Action::RemovePlayer(players) => players.write_into(buf)?,
+ }
+ Ok(())
+ }
+}
diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs
index 436e0cc2..0a9f1621 100755
--- a/azalea-protocol/src/packets/game/mod.rs
+++ b/azalea-protocol/src/packets/game/mod.rs
@@ -5,6 +5,7 @@ pub mod clientbound_disconnect_packet;
pub mod clientbound_entity_event_packet;
pub mod clientbound_login_packet;
pub mod clientbound_player_abilities_packet;
+pub mod clientbound_player_info_packet;
pub mod clientbound_player_position_packet;
pub mod clientbound_recipe_packet;
pub mod clientbound_set_carried_item_packet;
@@ -25,6 +26,7 @@ declare_state_packets!(
0x18: clientbound_custom_payload_packet::ClientboundCustomPayloadPacket,
0x26: clientbound_login_packet::ClientboundLoginPacket,
0x32: clientbound_player_abilities_packet::ClientboundPlayerAbilitiesPacket,
+ 0x36: clientbound_player_info_packet::ClientboundPlayerInfoPacket,
0x38: clientbound_player_position_packet::ClientboundPlayerPositionPacket,
0x39: clientbound_recipe_packet::ClientboundRecipePacket,
0x48: clientbound_set_carried_item_packet::ClientboundSetCarriedItemPacket,
diff --git a/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs b/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs
index c54aa819..ccf0f482 100755
--- a/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs
+++ b/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs
@@ -9,6 +9,7 @@ pub struct ClientboundGameProfilePacket {
pub game_profile: GameProfile,
}
+// TODO: add derives to GameProfile and have an impl McBufReadable/Writable for GameProfile
impl ClientboundGameProfilePacket {
pub fn get(self) -> LoginPacket {
LoginPacket::ClientboundGameProfilePacket(self)
@@ -25,6 +26,7 @@ impl ClientboundGameProfilePacket {
pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
buf: &mut T,
) -> Result<LoginPacket, String> {
+ // TODO: we have a thing to read from the uuid now
let uuid = Uuid::from_int_array([
buf.read_int().await? as u32,
buf.read_int().await? as u32,