ids are stored in packets themselves

This commit is contained in:
mat 2021-12-06 18:51:26 +00:00
parent c4e7873a50
commit 544c8a3394
2 changed files with 14 additions and 13 deletions

View file

@ -1,16 +1,22 @@
use std::hash::Hash;
use crate::friendly_byte_buf::FriendlyByteBuf;
use super::{ConnectionProtocol, Packet};
#[derive(Hash)]
pub struct ClientIntentionPacket {
protocol_version: u32,
hostname: String,
port: u16,
/// 1 for status, 2 for login
intention: ConnectionProtocol,
}
// implement "Packet" for "ClientIntentionPacket"
impl Packet for ClientIntentionPacket {
const ID: u8 = 0x00;
// implement "from_reader" for "ClientIntentionPacket"
fn write(&self, buf: &mut FriendlyByteBuf) {
buf.write_varint(self.protocol_version);
@ -19,3 +25,4 @@ impl Packet for ClientIntentionPacket {
buf.write_varint(self.intention.clone() as u32);
}
}

View file

@ -1,8 +1,10 @@
pub mod client_intention_packet;
use std::collections::HashMap;
use crate::friendly_byte_buf::FriendlyByteBuf;
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ConnectionProtocol {
Handshaking = -1,
Play = 0,
@ -11,17 +13,9 @@ 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;
fn write(&self, friendly_byte_buf: &mut FriendlyByteBuf) -> ();
}
struct PacketSet<'a> {
pub packets: Vec<&'a dyn Packet>,
}
impl<'a> PacketSet<'a> {
fn add_packet(&mut self, packet: &'a dyn Packet) {
self.packets.push(packet);
}
}
// PacketSet