aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-07-29 15:32:04 -0500
committermat <github@matdoes.dev>2022-07-29 15:32:04 -0500
commit1b602d0be793394ac2b0d009b77c6a877a4efb7d (patch)
tree6d781edb998a362d368b6c65a86af84a91f747ba
parent4ee4687053b7442f518823b08099c156f4da4e83 (diff)
downloadazalea-drasl-1b602d0be793394ac2b0d009b77c6a877a4efb7d.tar.xz
fix errors and warnings
-rw-r--r--azalea-client/src/client.rs104
-rwxr-xr-xazalea-protocol/packet-macros/src/lib.rs121
-rwxr-xr-xazalea-protocol/src/packets/handshake/client_intention_packet.rs4
-rwxr-xr-xazalea-protocol/src/packets/handshake/mod.rs6
4 files changed, 125 insertions, 110 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index b904fa92..8b456276 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -11,13 +11,13 @@ use azalea_protocol::{
serverbound_accept_teleportation_packet::ServerboundAcceptTeleportationPacket,
serverbound_custom_payload_packet::ServerboundCustomPayloadPacket,
serverbound_keep_alive_packet::ServerboundKeepAlivePacket,
- serverbound_move_player_packet_pos_rot::ServerboundMovePlayerPacketPosRot, GamePacket,
+ serverbound_move_player_packet_pos_rot::ServerboundMovePlayerPacketPosRot,
+ ClientboundGamePacket,
},
handshake::client_intention_packet::ClientIntentionPacket,
login::{
serverbound_hello_packet::ServerboundHelloPacket,
serverbound_key_packet::{NonceOrSaltSignature, ServerboundKeyPacket},
- LoginPacket,
},
ConnectionProtocol, PROTOCOL_VERSION,
},
@@ -203,12 +203,12 @@ impl Client {
}
async fn handle(
- packet: &GamePacket,
+ packet: &ClientboundGamePacket,
client: &Client,
tx: &UnboundedSender<Event>,
) -> Result<(), HandleError> {
match packet {
- GamePacket::ClientboundLoginPacket(p) => {
+ ClientboundGamePacket::ClientboundLoginPacket(p) => {
println!("Got login packet {:?}", p);
{
@@ -307,40 +307,40 @@ impl Client {
tx.send(Event::Login).unwrap();
}
- GamePacket::ClientboundUpdateViewDistancePacket(p) => {
+ ClientboundGamePacket::ClientboundUpdateViewDistancePacket(p) => {
println!("Got view distance packet {:?}", p);
}
- GamePacket::ClientboundCustomPayloadPacket(p) => {
+ ClientboundGamePacket::ClientboundCustomPayloadPacket(p) => {
println!("Got custom payload packet {:?}", p);
}
- GamePacket::ClientboundChangeDifficultyPacket(p) => {
+ ClientboundGamePacket::ClientboundChangeDifficultyPacket(p) => {
println!("Got difficulty packet {:?}", p);
}
- GamePacket::ClientboundDeclareCommandsPacket(_p) => {
+ ClientboundGamePacket::ClientboundDeclareCommandsPacket(_p) => {
println!("Got declare commands packet");
}
- GamePacket::ClientboundPlayerAbilitiesPacket(p) => {
+ ClientboundGamePacket::ClientboundPlayerAbilitiesPacket(p) => {
println!("Got player abilities packet {:?}", p);
}
- GamePacket::ClientboundSetCarriedItemPacket(p) => {
+ ClientboundGamePacket::ClientboundSetCarriedItemPacket(p) => {
println!("Got set carried item packet {:?}", p);
}
- GamePacket::ClientboundUpdateTagsPacket(_p) => {
+ ClientboundGamePacket::ClientboundUpdateTagsPacket(_p) => {
println!("Got update tags packet");
}
- GamePacket::ClientboundDisconnectPacket(p) => {
+ ClientboundGamePacket::ClientboundDisconnectPacket(p) => {
println!("Got disconnect packet {:?}", p);
}
- GamePacket::ClientboundUpdateRecipesPacket(_p) => {
+ ClientboundGamePacket::ClientboundUpdateRecipesPacket(_p) => {
println!("Got update recipes packet");
}
- GamePacket::ClientboundEntityEventPacket(_p) => {
+ ClientboundGamePacket::ClientboundEntityEventPacket(_p) => {
// println!("Got entity event packet {:?}", p);
}
- GamePacket::ClientboundRecipePacket(_p) => {
+ ClientboundGamePacket::ClientboundRecipePacket(_p) => {
println!("Got recipe packet");
}
- GamePacket::ClientboundPlayerPositionPacket(p) => {
+ ClientboundGamePacket::ClientboundPlayerPositionPacket(p) => {
// TODO: reply with teleport confirm
println!("Got player position packet {:?}", p);
@@ -432,10 +432,10 @@ impl Client {
)
.await;
}
- GamePacket::ClientboundPlayerInfoPacket(p) => {
+ ClientboundGamePacket::ClientboundPlayerInfoPacket(p) => {
println!("Got player info packet {:?}", p);
}
- GamePacket::ClientboundSetChunkCacheCenterPacket(p) => {
+ ClientboundGamePacket::ClientboundSetChunkCacheCenterPacket(p) => {
println!("Got chunk cache center packet {:?}", p);
client
.dimension
@@ -444,7 +444,7 @@ impl Client {
.unwrap()
.update_view_center(&ChunkPos::new(p.x, p.z));
}
- GamePacket::ClientboundLevelChunkWithLightPacket(p) => {
+ ClientboundGamePacket::ClientboundLevelChunkWithLightPacket(p) => {
println!("Got chunk with light packet {} {}", p.x, p.z);
let pos = ChunkPos::new(p.x, p.z);
// let chunk = Chunk::read_with_world_height(&mut p.chunk_data);
@@ -457,10 +457,10 @@ impl Client {
.replace_with_packet_data(&pos, &mut p.chunk_data.data.as_slice())
.unwrap();
}
- GamePacket::ClientboundLightUpdatePacket(p) => {
+ ClientboundGamePacket::ClientboundLightUpdatePacket(p) => {
println!("Got light update packet {:?}", p);
}
- GamePacket::ClientboundAddEntityPacket(p) => {
+ ClientboundGamePacket::ClientboundAddEntityPacket(p) => {
println!("Got add entity packet {:?}", p);
let entity = Entity::from(p);
client
@@ -470,19 +470,19 @@ impl Client {
.expect("Dimension doesn't exist! We should've gotten a login packet by now.")
.add_entity(entity);
}
- GamePacket::ClientboundSetEntityDataPacket(_p) => {
+ ClientboundGamePacket::ClientboundSetEntityDataPacket(_p) => {
// println!("Got set entity data packet {:?}", p);
}
- GamePacket::ClientboundUpdateAttributesPacket(_p) => {
+ ClientboundGamePacket::ClientboundUpdateAttributesPacket(_p) => {
// println!("Got update attributes packet {:?}", p);
}
- GamePacket::ClientboundEntityVelocityPacket(_p) => {
+ ClientboundGamePacket::ClientboundEntityVelocityPacket(_p) => {
// println!("Got entity velocity packet {:?}", p);
}
- GamePacket::ClientboundSetEntityLinkPacket(p) => {
+ ClientboundGamePacket::ClientboundSetEntityLinkPacket(p) => {
println!("Got set entity link packet {:?}", p);
}
- GamePacket::ClientboundAddPlayerPacket(p) => {
+ ClientboundGamePacket::ClientboundAddPlayerPacket(p) => {
println!("Got add player packet {:?}", p);
let entity = Entity::from(p);
client
@@ -492,25 +492,25 @@ impl Client {
.expect("Dimension doesn't exist! We should've gotten a login packet by now.")
.add_entity(entity);
}
- GamePacket::ClientboundInitializeBorderPacket(p) => {
+ ClientboundGamePacket::ClientboundInitializeBorderPacket(p) => {
println!("Got initialize border packet {:?}", p);
}
- GamePacket::ClientboundSetTimePacket(p) => {
+ ClientboundGamePacket::ClientboundSetTimePacket(p) => {
println!("Got set time packet {:?}", p);
}
- GamePacket::ClientboundSetDefaultSpawnPositionPacket(p) => {
+ ClientboundGamePacket::ClientboundSetDefaultSpawnPositionPacket(p) => {
println!("Got set default spawn position packet {:?}", p);
}
- GamePacket::ClientboundContainerSetContentPacket(p) => {
+ ClientboundGamePacket::ClientboundContainerSetContentPacket(p) => {
println!("Got container set content packet {:?}", p);
}
- GamePacket::ClientboundSetHealthPacket(p) => {
+ ClientboundGamePacket::ClientboundSetHealthPacket(p) => {
println!("Got set health packet {:?}", p);
}
- GamePacket::ClientboundSetExperiencePacket(p) => {
+ ClientboundGamePacket::ClientboundSetExperiencePacket(p) => {
println!("Got set experience packet {:?}", p);
}
- GamePacket::ClientboundTeleportEntityPacket(p) => {
+ ClientboundGamePacket::ClientboundTeleportEntityPacket(p) => {
let mut dimension_lock = client.dimension.lock()?;
let dimension = dimension_lock.as_mut().unwrap();
@@ -523,28 +523,28 @@ impl Client {
},
)?;
}
- GamePacket::ClientboundUpdateAdvancementsPacket(p) => {
+ ClientboundGamePacket::ClientboundUpdateAdvancementsPacket(p) => {
println!("Got update advancements packet {:?}", p);
}
- GamePacket::ClientboundRotateHeadPacket(_p) => {
+ ClientboundGamePacket::ClientboundRotateHeadPacket(_p) => {
// println!("Got rotate head packet {:?}", p);
}
- GamePacket::ClientboundMoveEntityPosPacket(p) => {
+ ClientboundGamePacket::ClientboundMoveEntityPosPacket(p) => {
let mut dimension_lock = client.dimension.lock()?;
let dimension = dimension_lock.as_mut().unwrap();
dimension.move_entity_with_delta(p.entity_id, &p.delta)?;
}
- GamePacket::ClientboundMoveEntityPosrotPacket(p) => {
+ ClientboundGamePacket::ClientboundMoveEntityPosrotPacket(p) => {
let mut dimension_lock = client.dimension.lock()?;
let dimension = dimension_lock.as_mut().unwrap();
dimension.move_entity_with_delta(p.entity_id, &p.delta)?;
}
- GamePacket::ClientboundMoveEntityRotPacket(p) => {
+ ClientboundGamePacket::ClientboundMoveEntityRotPacket(p) => {
println!("Got move entity rot packet {:?}", p);
}
- GamePacket::ClientboundKeepAlivePacket(p) => {
+ ClientboundGamePacket::ClientboundKeepAlivePacket(p) => {
println!("Got keep alive packet {:?}", p);
client
.conn
@@ -553,48 +553,48 @@ impl Client {
.write(ServerboundKeepAlivePacket { id: p.id }.get())
.await;
}
- GamePacket::ClientboundRemoveEntitiesPacket(p) => {
+ ClientboundGamePacket::ClientboundRemoveEntitiesPacket(p) => {
println!("Got remove entities packet {:?}", p);
}
- GamePacket::ClientboundPlayerChatPacket(p) => {
+ ClientboundGamePacket::ClientboundPlayerChatPacket(p) => {
println!("Got player chat packet {:?}", p);
tx.send(Event::Chat(ChatPacket::Player(Box::new(p.clone()))))
.unwrap();
}
- GamePacket::ClientboundSystemChatPacket(p) => {
+ ClientboundGamePacket::ClientboundSystemChatPacket(p) => {
println!("Got system chat packet {:?}", p);
tx.send(Event::Chat(ChatPacket::System(p.clone()))).unwrap();
}
- GamePacket::ClientboundSoundPacket(p) => {
+ ClientboundGamePacket::ClientboundSoundPacket(p) => {
println!("Got sound packet {:?}", p);
}
- GamePacket::ClientboundLevelEventPacket(p) => {
+ ClientboundGamePacket::ClientboundLevelEventPacket(p) => {
println!("Got level event packet {:?}", p);
}
- GamePacket::ClientboundBlockUpdatePacket(p) => {
+ ClientboundGamePacket::ClientboundBlockUpdatePacket(p) => {
println!("Got block update packet {:?}", p);
// TODO: update world
}
- GamePacket::ClientboundAnimatePacket(p) => {
+ ClientboundGamePacket::ClientboundAnimatePacket(p) => {
println!("Got animate packet {:?}", p);
}
- GamePacket::ClientboundSectionBlocksUpdatePacket(p) => {
+ ClientboundGamePacket::ClientboundSectionBlocksUpdatePacket(p) => {
println!("Got section blocks update packet {:?}", p);
// TODO: update world
}
- GamePacket::ClientboundGameEventPacket(p) => {
+ ClientboundGamePacket::ClientboundGameEventPacket(p) => {
println!("Got game event packet {:?}", p);
}
- GamePacket::ClientboundLevelParticlesPacket(p) => {
+ ClientboundGamePacket::ClientboundLevelParticlesPacket(p) => {
println!("Got level particles packet {:?}", p);
}
- GamePacket::ClientboundServerDataPacket(p) => {
+ ClientboundGamePacket::ClientboundServerDataPacket(p) => {
println!("Got server data packet {:?}", p);
}
- GamePacket::ClientboundSetEquipmentPacket(p) => {
+ ClientboundGamePacket::ClientboundSetEquipmentPacket(p) => {
println!("Got set equipment packet {:?}", p);
}
- GamePacket::ClientboundUpdateMobEffectPacket(p) => {
+ ClientboundGamePacket::ClientboundUpdateMobEffectPacket(p) => {
println!("Got update mob effect packet {:?}", p);
}
_ => panic!("Unexpected packet {:?}", packet),
diff --git a/azalea-protocol/packet-macros/src/lib.rs b/azalea-protocol/packet-macros/src/lib.rs
index ce819733..ea4db210 100755
--- a/azalea-protocol/packet-macros/src/lib.rs
+++ b/azalea-protocol/packet-macros/src/lib.rs
@@ -235,6 +235,23 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
});
}
+ if !has_serverbound_packets {
+ serverbound_id_match_contents.extend(quote! {
+ _ => panic!("This enum is empty and can't exist.")
+ });
+ serverbound_write_match_contents.extend(quote! {
+ _ => panic!("This enum is empty and can't exist.")
+ });
+ }
+ if !has_clientbound_packets {
+ clientbound_id_match_contents.extend(quote! {
+ _ => panic!("This enum is empty and can't exist.")
+ });
+ clientbound_write_match_contents.extend(quote! {
+ _ => panic!("This enum is empty and can't exist.")
+ });
+ }
+
let mut contents = quote! {
#[derive(Clone, Debug)]
pub enum #serverbound_state_name
@@ -252,69 +269,67 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
}
};
- contents.extend(quote!{
- impl crate::packets::ProtocolPacket for #serverbound_state_name {
- fn id(&self) -> u32 {
- match self {
- #serverbound_id_match_contents
- _ => panic!("Impossible state, this packet shouldn't exist.")
- }
- }
-
- fn write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
- match self {
- #serverbound_write_match_contents
- _ => panic!("Impossible state, this packet shouldn't exist.")
- }
+ contents.extend(quote! {
+ #[allow(unreachable_code)]
+ impl crate::packets::ProtocolPacket for #serverbound_state_name {
+ fn id(&self) -> u32 {
+ match self {
+ #serverbound_id_match_contents
}
+ }
- /// Read a packet by its id, ConnectionProtocol, and flow
- fn read(
- id: u32,
- buf: &mut impl std::io::Read,
- ) -> Result<#serverbound_state_name, String>
- where
- Self: Sized,
- {
- Ok(match id {
- #serverbound_read_match_contents
- _ => return Err(format!("Unknown Serverbound {} packet id: {}", #state_name_litstr, id)),
- })
+ fn write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
+ match self {
+ #serverbound_write_match_contents
}
}
- });
- contents.extend(quote!{
- impl crate::packets::ProtocolPacket for #clientbound_state_name {
- fn id(&self) -> u32 {
- match self {
- #clientbound_id_match_contents
- _ => panic!("Impossible state, this packet shouldn't exist.")
- }
+ /// Read a packet by its id, ConnectionProtocol, and flow
+ fn read(
+ id: u32,
+ buf: &mut impl std::io::Read,
+ ) -> Result<#serverbound_state_name, String>
+ where
+ Self: Sized,
+ {
+ Ok(match id {
+ #serverbound_read_match_contents
+ _ => return Err(format!("Unknown Serverbound {} packet id: {}", #state_name_litstr, id)),
+ })
+ }
+ }
+ });
+
+ contents.extend(quote! {
+ #[allow(unreachable_code)]
+ impl crate::packets::ProtocolPacket for #clientbound_state_name {
+ fn id(&self) -> u32 {
+ match self {
+ #clientbound_id_match_contents
}
+ }
- fn write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
- match self {
- #clientbound_write_match_contents
- _ => panic!("Impossible state, this packet shouldn't exist.")
- }
+ fn write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
+ match self {
+ #clientbound_write_match_contents
}
+ }
- /// Read a packet by its id, ConnectionProtocol, and flow
- fn read(
- id: u32,
- buf: &mut impl std::io::Read,
- ) -> Result<#clientbound_state_name, String>
- where
- Self: Sized,
- {
- Ok(match id {
- #clientbound_read_match_contents
- _ => return Err(format!("Unknown Clientbound {} packet id: {}", #state_name_litstr, id)),
- })
- }
+ /// Read a packet by its id, ConnectionProtocol, and flow
+ fn read(
+ id: u32,
+ buf: &mut impl std::io::Read,
+ ) -> Result<#clientbound_state_name, String>
+ where
+ Self: Sized,
+ {
+ Ok(match id {
+ #clientbound_read_match_contents
+ _ => return Err(format!("Unknown Clientbound {} packet id: {}", #state_name_litstr, id)),
+ })
}
- });
+ }
+ });
contents.into()
}
diff --git a/azalea-protocol/src/packets/handshake/client_intention_packet.rs b/azalea-protocol/src/packets/handshake/client_intention_packet.rs
index 804778a0..ef47bba3 100755
--- a/azalea-protocol/src/packets/handshake/client_intention_packet.rs
+++ b/azalea-protocol/src/packets/handshake/client_intention_packet.rs
@@ -1,9 +1,9 @@
use crate::packets::ConnectionProtocol;
use azalea_buf::McBuf;
-use packet_macros::ClientboundHandshakePacket;
+use packet_macros::ServerboundHandshakePacket;
use std::hash::Hash;
-#[derive(Hash, Clone, Debug, McBuf, ClientboundHandshakePacket)]
+#[derive(Hash, Clone, Debug, McBuf, ServerboundHandshakePacket)]
pub struct ClientIntentionPacket {
#[var]
pub protocol_version: u32,
diff --git a/azalea-protocol/src/packets/handshake/mod.rs b/azalea-protocol/src/packets/handshake/mod.rs
index 88d9939b..8fd12529 100755
--- a/azalea-protocol/src/packets/handshake/mod.rs
+++ b/azalea-protocol/src/packets/handshake/mod.rs
@@ -4,8 +4,8 @@ use packet_macros::declare_state_packets;
declare_state_packets!(
HandshakePacket,
- Serverbound => {},
- Clientbound => {
+ Serverbound => {
0x00: client_intention_packet::ClientIntentionPacket,
- }
+ },
+ Clientbound => {}
);