aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEightFactorial <murphkev000@gmail.com>2023-01-25 09:51:27 -0800
committerGitHub <noreply@github.com>2023-01-25 11:51:27 -0600
commit9a66cb97a659ed1f0e52ba3d9438de1d9b78d64a (patch)
tree16405cec7c45fb952509a5f93f6970b511315046
parent473c74175c3a8189616bded528e3e6e4785dd3c8 (diff)
downloadazalea-drasl-9a66cb97a659ed1f0e52ba3d9438de1d9b78d64a.tar.xz
Fix test and packets (#60)
* Fix test and packets * Fix bug, fix a couple more packets * add tests and fix stuff * fix warnings Co-authored-by: Ubuntu <github@matdoes.dev>
-rwxr-xr-xazalea-auth/src/game_profile.rs9
-rwxr-xr-xazalea-buf/src/lib.rs15
-rwxr-xr-xazalea-buf/src/write.rs7
-rwxr-xr-xazalea-core/src/bitset.rs9
-rwxr-xr-xazalea-protocol/src/connect.rs2
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_initialize_border_packet.rs2
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_level_particles_packet.rs17
-rw-r--r--azalea-protocol/src/packets/game/clientbound_player_info_update_packet.rs33
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_update_tags_packet.rs2
-rwxr-xr-xazalea-protocol/src/packets/game/serverbound_player_abilities_packet.rs2
-rwxr-xr-xazalea-protocol/src/packets/game/serverbound_player_input_packet.rs2
11 files changed, 71 insertions, 29 deletions
diff --git a/azalea-auth/src/game_profile.rs b/azalea-auth/src/game_profile.rs
index bdd6cda5..12815821 100755
--- a/azalea-auth/src/game_profile.rs
+++ b/azalea-auth/src/game_profile.rs
@@ -95,9 +95,8 @@ mod tests {
}
]
}"#;
- let profile = GameProfile::from(
- serde_json::from_str::<SerializableProfilePropertyValue>(json).unwrap(),
- );
+ let profile =
+ GameProfile::from(serde_json::from_str::<SerializableGameProfile>(json).unwrap());
assert_eq!(
profile,
GameProfile {
@@ -106,9 +105,9 @@ mod tests {
properties: {
let mut map = HashMap::new();
map.insert(
- "asdf".to_string(),
+ "qwer".to_string(),
ProfilePropertyValue {
- value: "qwer".to_string(),
+ value: "asdf".to_string(),
signature: Some("zxcv".to_string()),
},
);
diff --git a/azalea-buf/src/lib.rs b/azalea-buf/src/lib.rs
index 568b542e..73d76949 100755
--- a/azalea-buf/src/lib.rs
+++ b/azalea-buf/src/lib.rs
@@ -143,6 +143,21 @@ mod tests {
}
#[test]
+ fn test_write_varlong() {
+ let mut buf = Vec::new();
+ 0u64.var_write_into(&mut buf).unwrap();
+ assert_eq!(buf, vec![0]);
+
+ let mut buf = Vec::new();
+ 1u64.var_write_into(&mut buf).unwrap();
+ assert_eq!(buf, vec![1]);
+
+ let mut buf = Vec::new();
+ 9223372036854775807u64.var_write_into(&mut buf).unwrap();
+ assert_eq!(buf, vec![255, 255, 255, 255, 255, 255, 255, 255, 127]);
+ }
+
+ #[test]
fn test_list() {
let original_vec = vec!["a".to_string(), "bc".to_string(), "def".to_string()];
diff --git a/azalea-buf/src/write.rs b/azalea-buf/src/write.rs
index e00ddce9..161f8645 100755
--- a/azalea-buf/src/write.rs
+++ b/azalea-buf/src/write.rs
@@ -132,15 +132,16 @@ impl McBufVarWritable for i64 {
fn var_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
let mut buffer = [0];
let mut value = *self;
+ if value == 0 {
+ buf.write_all(&buffer).unwrap();
+ }
while value != 0 {
buffer[0] = (value & 0b0111_1111) as u8;
value = (value >> 7) & (i64::max_value() >> 6);
if value != 0 {
buffer[0] |= 0b1000_0000;
}
- // this only writes a single byte, so write_all isn't necessary
- // the let _ = is so clippy doesn't complain
- let _ = buf.write(&buffer)?;
+ buf.write_all(&buffer)?;
}
Ok(())
}
diff --git a/azalea-core/src/bitset.rs b/azalea-core/src/bitset.rs
index b45a18d2..381e86ea 100755
--- a/azalea-core/src/bitset.rs
+++ b/azalea-core/src/bitset.rs
@@ -1,4 +1,4 @@
-use std::io::{Cursor, Read, Write};
+use std::io::{Cursor, Write};
use azalea_buf::{BufReadError, McBuf, McBufReadable, McBufWritable};
@@ -106,13 +106,6 @@ impl BitSet {
pub fn set(&mut self, bit_index: usize) {
self.data[bit_index / 64] |= 1u64 << (bit_index % 64);
}
-
- /// Read a BitSet with a known length.
- pub fn read_fixed(buf: &mut Cursor<&[u8]>, length: usize) -> Result<Self, BufReadError> {
- let mut data = vec![0; length.div_ceil(8)];
- buf.read_exact(&mut data)?;
- Ok(BitSet::from(data))
- }
}
impl From<Vec<u64>> for BitSet {
diff --git a/azalea-protocol/src/connect.rs b/azalea-protocol/src/connect.rs
index 149ea95d..06b306b9 100755
--- a/azalea-protocol/src/connect.rs
+++ b/azalea-protocol/src/connect.rs
@@ -305,7 +305,7 @@ impl Connection<ClientboundLoginPacket, ServerboundLoginPacket> {
/// let e = azalea_crypto::encrypt(&p.public_key, &p.nonce).unwrap();
/// conn.authenticate(
/// &access_token,
- /// &Uuid::parse_str(&profile.id).expect("Invalid UUID"),
+ /// &profile.id,
/// e.secret_key,
/// &p
/// ).await?;
diff --git a/azalea-protocol/src/packets/game/clientbound_initialize_border_packet.rs b/azalea-protocol/src/packets/game/clientbound_initialize_border_packet.rs
index f33d75a4..77742c0a 100755
--- a/azalea-protocol/src/packets/game/clientbound_initialize_border_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_initialize_border_packet.rs
@@ -1,7 +1,7 @@
use azalea_buf::McBuf;
use azalea_protocol_macros::ClientboundGamePacket;
-#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
+#[derive(Clone, Debug, ClientboundGamePacket, McBuf)]
pub struct ClientboundInitializeBorderPacket {
pub new_center_x: f64,
pub new_center_z: f64,
diff --git a/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs b/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs
index eaa34669..6efe1f97 100755
--- a/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs
@@ -1,4 +1,4 @@
-use azalea_buf::{BufReadError, McBufReadable, McBufVarReadable, McBufWritable};
+use azalea_buf::{BufReadError, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable};
use azalea_core::ParticleData;
use azalea_protocol_macros::ClientboundGamePacket;
use std::io::{Cursor, Write};
@@ -51,7 +51,18 @@ impl McBufReadable for ClientboundLevelParticlesPacket {
}
impl McBufWritable for ClientboundLevelParticlesPacket {
- fn write_into(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> {
- todo!();
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
+ self.particle_id.var_write_into(buf)?;
+ self.override_limiter.write_into(buf)?;
+ self.x.write_into(buf)?;
+ self.y.write_into(buf)?;
+ self.z.write_into(buf)?;
+ self.x_dist.write_into(buf)?;
+ self.y_dist.write_into(buf)?;
+ self.z_dist.write_into(buf)?;
+ self.max_speed.write_into(buf)?;
+ self.count.write_into(buf)?;
+ self.data.write_without_id(buf)?;
+ Ok(())
}
}
diff --git a/azalea-protocol/src/packets/game/clientbound_player_info_update_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_info_update_packet.rs
index a3a3b45d..4fa16209 100644
--- a/azalea-protocol/src/packets/game/clientbound_player_info_update_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_player_info_update_packet.rs
@@ -3,7 +3,7 @@ use azalea_buf::{
BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable,
};
use azalea_chat::Component;
-use azalea_core::{BitSet, GameType};
+use azalea_core::{FixedBitSet, GameType};
use azalea_protocol_macros::ClientboundGamePacket;
use std::{
collections::HashMap,
@@ -151,7 +151,7 @@ impl McBufWritable for ClientboundPlayerInfoUpdatePacket {
}
}
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ActionEnumSet {
pub add_player: bool,
pub initialize_chat: bool,
@@ -163,7 +163,7 @@ pub struct ActionEnumSet {
impl McBufReadable for ActionEnumSet {
fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
- let set = BitSet::read_fixed(buf, 6)?;
+ let set = FixedBitSet::<6>::read_from(buf)?;
Ok(ActionEnumSet {
add_player: set.index(0),
initialize_chat: set.index(1),
@@ -177,7 +177,7 @@ impl McBufReadable for ActionEnumSet {
impl McBufWritable for ActionEnumSet {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- let mut set = BitSet::new(6);
+ let mut set = FixedBitSet::<6>::new();
if self.add_player {
set.set(0);
}
@@ -196,6 +196,29 @@ impl McBufWritable for ActionEnumSet {
if self.update_display_name {
set.set(5);
}
- set.write_into(buf)
+ set.write_into(buf)?;
+ Ok(())
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_action_enum_set() {
+ let data = ActionEnumSet {
+ add_player: true,
+ initialize_chat: false,
+ update_game_mode: true,
+ update_listed: false,
+ update_latency: true,
+ update_display_name: false,
+ };
+ let mut buf = Vec::new();
+ data.write_into(&mut buf).unwrap();
+ let mut data_cursor: Cursor<&[u8]> = Cursor::new(&buf);
+ let read_data = ActionEnumSet::read_from(&mut data_cursor).unwrap();
+ assert_eq!(read_data, data);
}
}
diff --git a/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs
index 3e6e413a..d09768c7 100755
--- a/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs
@@ -40,7 +40,7 @@ impl McBufReadable for TagMap {
impl McBufWritable for TagMap {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- (self.len() as u32).write_into(buf)?;
+ (self.len() as u32).var_write_into(buf)?;
for (k, v) in &self.0 {
k.write_into(buf)?;
v.write_into(buf)?;
diff --git a/azalea-protocol/src/packets/game/serverbound_player_abilities_packet.rs b/azalea-protocol/src/packets/game/serverbound_player_abilities_packet.rs
index ab1ae9a0..7f979363 100755
--- a/azalea-protocol/src/packets/game/serverbound_player_abilities_packet.rs
+++ b/azalea-protocol/src/packets/game/serverbound_player_abilities_packet.rs
@@ -23,7 +23,7 @@ impl McBufWritable for ServerboundPlayerAbilitiesPacket {
if self.is_flying {
byte |= 2;
}
- byte.write_into(buf)?;
+ u8::write_into(&byte, buf)?;
Ok(())
}
}
diff --git a/azalea-protocol/src/packets/game/serverbound_player_input_packet.rs b/azalea-protocol/src/packets/game/serverbound_player_input_packet.rs
index 30d3c3ae..2bd7f6eb 100755
--- a/azalea-protocol/src/packets/game/serverbound_player_input_packet.rs
+++ b/azalea-protocol/src/packets/game/serverbound_player_input_packet.rs
@@ -32,7 +32,7 @@ impl McBufWritable for ServerboundPlayerInputPacket {
fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
self.xxa.write_into(buf)?;
self.zza.write_into(buf)?;
- let mut byte = 0;
+ let mut byte = 0u8;
if self.is_jumping {
byte |= 1;
}