diff options
| author | mat <github@matdoes.dev> | 2021-12-06 19:59:20 +0000 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2021-12-06 19:59:20 +0000 |
| commit | 0b484df40c356cf4fe87f3d3a20eadf59eef42c9 (patch) | |
| tree | 272b2ad58c7fc850378c5bc97eaae95a79277177 /minecraft-protocol/src/packets | |
| parent | 544c8a33940572eb7ad36eeafa94f8a64a1e23bc (diff) | |
| download | azalea-drasl-0b484df40c356cf4fe87f3d3a20eadf59eef42c9.tar.xz | |
implement new packet implementation
Diffstat (limited to 'minecraft-protocol/src/packets')
| -rw-r--r-- | minecraft-protocol/src/packets/client_intention_packet.rs | 17 | ||||
| -rw-r--r-- | minecraft-protocol/src/packets/mod.rs | 14 |
2 files changed, 16 insertions, 15 deletions
diff --git a/minecraft-protocol/src/packets/client_intention_packet.rs b/minecraft-protocol/src/packets/client_intention_packet.rs index a9a4d86a..30f76387 100644 --- a/minecraft-protocol/src/packets/client_intention_packet.rs +++ b/minecraft-protocol/src/packets/client_intention_packet.rs @@ -5,17 +5,19 @@ use crate::friendly_byte_buf::FriendlyByteBuf; use super::{ConnectionProtocol, Packet}; #[derive(Hash)] -pub struct ClientIntentionPacket { - protocol_version: u32, - hostname: String, - port: u16, +pub struct ClientIntentionPacket<'a> { + pub protocol_version: u32, + pub hostname: &'a String, + pub port: u16, /// 1 for status, 2 for login - intention: ConnectionProtocol, + pub intention: ConnectionProtocol, } // implement "Packet" for "ClientIntentionPacket" -impl Packet for ClientIntentionPacket { - const ID: u8 = 0x00; +impl<'a> Packet for ClientIntentionPacket<'a> { + fn get_id(&self) -> u8 { + 0x00 + } // implement "from_reader" for "ClientIntentionPacket" fn write(&self, buf: &mut FriendlyByteBuf) { @@ -25,4 +27,3 @@ impl Packet for ClientIntentionPacket { buf.write_varint(self.intention.clone() as u32); } } - diff --git a/minecraft-protocol/src/packets/mod.rs b/minecraft-protocol/src/packets/mod.rs index 2ccdeb44..bdb80c2f 100644 --- a/minecraft-protocol/src/packets/mod.rs +++ b/minecraft-protocol/src/packets/mod.rs @@ -1,6 +1,7 @@ -pub mod client_intention_packet; - -use std::collections::HashMap; +mod client_intention_packet; +pub use client_intention_packet::ClientIntentionPacket; +mod serverbound_status_request_packet; +pub use serverbound_status_request_packet::ServerboundStatusRequestPacket; use crate::friendly_byte_buf::FriendlyByteBuf; @@ -13,9 +14,8 @@ pub enum ConnectionProtocol { } pub trait Packet { - /// The id of the packet, this is always a byte in vanilla. - /// This might be bigger than a u8 if using modpacks with lots of custom packets? - const ID: u8; - + /// Get the id of the packet, this is always a byte. + fn get_id(&self) -> u8; + fn write(&self, friendly_byte_buf: &mut FriendlyByteBuf) -> (); } |
