aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/handshake
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-01-01 23:55:19 -0600
committermat <github@matdoes.dev>2022-01-01 23:55:19 -0600
commita1afbb6031527c1db5831fc8e916bc0ecce633b4 (patch)
tree56fbccf52645cc2eefd231506ffe8ed71018dc01 /azalea-protocol/src/packets/handshake
parente81b85dd5bdd6d42ee84f24ed4a142f6141f170e (diff)
downloadazalea-drasl-a1afbb6031527c1db5831fc8e916bc0ecce633b4.tar.xz
start adding packet macros
Diffstat (limited to 'azalea-protocol/src/packets/handshake')
-rw-r--r--azalea-protocol/src/packets/handshake/client_intention_packet.rs60
-rw-r--r--azalea-protocol/src/packets/handshake/mod.rs2
2 files changed, 38 insertions, 24 deletions
diff --git a/azalea-protocol/src/packets/handshake/client_intention_packet.rs b/azalea-protocol/src/packets/handshake/client_intention_packet.rs
index 939a695e..b3eb8301 100644
--- a/azalea-protocol/src/packets/handshake/client_intention_packet.rs
+++ b/azalea-protocol/src/packets/handshake/client_intention_packet.rs
@@ -1,34 +1,48 @@
+use crate::{
+ mc_buf::{Readable, Writable},
+ packets::ConnectionProtocol,
+};
+use num_traits::FromPrimitive;
+use packet_macros::HandshakePacket;
use std::hash::Hash;
-use crate::{mc_buf::Writable, packets::ConnectionProtocol};
-
-use super::HandshakePacket;
-
-#[derive(Hash, Clone, Debug)]
+#[derive(Hash, Clone, Debug, HandshakePacket)]
pub struct ClientIntentionPacket {
+ #[varint]
pub protocol_version: u32,
pub hostname: String,
pub port: u16,
- /// 1 for status, 2 for login
pub intention: ConnectionProtocol,
}
-impl ClientIntentionPacket {
- pub fn get(self) -> HandshakePacket {
- HandshakePacket::ClientIntentionPacket(self)
- }
+// impl ClientIntentionPacket {
+// pub fn get(self) -> HandshakePacket {
+// HandshakePacket::ClientIntentionPacket(self)
+// }
- pub fn write(&self, buf: &mut Vec<u8>) {
- buf.write_varint(self.protocol_version as i32).unwrap();
- buf.write_utf(&self.hostname).unwrap();
- buf.write_short(self.port).unwrap();
- buf.write_varint(self.intention.clone() as i32).unwrap();
- }
+// pub fn write(&self, buf: &mut Vec<u8>) {
+// buf.write_varint(self.protocol_version as i32).unwrap();
+// buf.write_utf(&self.hostname).unwrap();
+// buf.write_short(self.port).unwrap();
+// buf.write_varint(self.intention.clone() as i32).unwrap();
+// }
- pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
- _buf: &mut T,
- ) -> Result<HandshakePacket, String> {
- Err("ClientIntentionPacket::parse not implemented".to_string())
- // Ok(ClientIntentionPacket {}.get())
- }
-}
+// pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
+// buf: &mut T,
+// ) -> Result<HandshakePacket, String> {
+// let protocol_version = buf.read_varint().await? as u32;
+// let hostname = buf.read_utf().await?;
+// let port = buf.read_short().await? as u16;
+// let intention = buf.read_varint().await?;
+
+// Ok(HandshakePacket::ClientIntentionPacket(
+// ClientIntentionPacket {
+// protocol_version,
+// hostname,
+// port,
+// intention: ConnectionProtocol::from_i32(intention)
+// .ok_or_else(|| "Invalid intention".to_string())?,
+// },
+// ))
+// }
+// }
diff --git a/azalea-protocol/src/packets/handshake/mod.rs b/azalea-protocol/src/packets/handshake/mod.rs
index 1d753645..17465fca 100644
--- a/azalea-protocol/src/packets/handshake/mod.rs
+++ b/azalea-protocol/src/packets/handshake/mod.rs
@@ -22,7 +22,7 @@ impl ProtocolPacket for HandshakePacket {
}
}
- fn write(&self, buf: &mut Vec<u8>) {
+ fn write(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
match self {
HandshakePacket::ClientIntentionPacket(packet) => packet.write(buf),
}