mirror of
https://github.com/mat-1/azalea.git
synced 2024-09-19 14:42:32 +00:00
ids are stored in packets themselves
This commit is contained in:
parent
c4e7873a50
commit
544c8a3394
2 changed files with 14 additions and 13 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue