Use u8 for packet IDs
This commit is contained in:
parent
b06f26b3e8
commit
7df3829e00
@ -17,7 +17,7 @@ use crate::types;
|
||||
/// Having a packet ID and a raw data byte array.
|
||||
pub struct RawPacket {
|
||||
/// Packet ID.
|
||||
pub id: i32,
|
||||
pub id: u8,
|
||||
|
||||
/// Packet data.
|
||||
pub data: Vec<u8>,
|
||||
@ -25,7 +25,7 @@ pub struct RawPacket {
|
||||
|
||||
impl RawPacket {
|
||||
/// Construct new raw packet.
|
||||
pub fn new(id: i32, data: Vec<u8>) -> Self {
|
||||
pub fn new(id: u8, data: Vec<u8>) -> Self {
|
||||
Self { id, data }
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ impl RawPacket {
|
||||
let (read, packet_id) = types::read_var_int(buf)?;
|
||||
buf = &buf[read..];
|
||||
|
||||
Ok(Self::new(packet_id, buf.to_vec()))
|
||||
Ok(Self::new(packet_id as u8, buf.to_vec()))
|
||||
}
|
||||
|
||||
/// Decode packet from raw buffer.
|
||||
@ -95,7 +95,7 @@ impl RawPacket {
|
||||
/// Encode compressed packet to raw buffer.
|
||||
fn encode_compressed(&self, threshold: i32) -> Result<Vec<u8>, ()> {
|
||||
// Packet payload: packet ID and data buffer
|
||||
let mut payload = types::encode_var_int(self.id)?;
|
||||
let mut payload = types::encode_var_int(self.id as i32)?;
|
||||
payload.extend_from_slice(&self.data);
|
||||
|
||||
// Determine whether to compress, encode data length bytes
|
||||
@ -126,7 +126,7 @@ impl RawPacket {
|
||||
|
||||
/// Encode uncompressed packet to raw buffer.
|
||||
fn encode_uncompressed(&self) -> Result<Vec<u8>, ()> {
|
||||
let mut data = types::encode_var_int(self.id)?;
|
||||
let mut data = types::encode_var_int(self.id as i32)?;
|
||||
data.extend_from_slice(&self.data);
|
||||
|
||||
let len = data.len() as i32;
|
||||
|
@ -3,39 +3,39 @@
|
||||
#![allow(unused)]
|
||||
|
||||
pub mod handshake {
|
||||
pub const SERVER_HANDSHAKE: i32 = 0;
|
||||
pub const SERVER_HANDSHAKE: u8 = 0;
|
||||
}
|
||||
|
||||
pub mod status {
|
||||
pub const CLIENT_STATUS: i32 = 0;
|
||||
pub const CLIENT_PING: i32 = 1;
|
||||
pub const SERVER_STATUS: i32 = 0;
|
||||
pub const SERVER_PING: i32 = 1;
|
||||
pub const CLIENT_STATUS: u8 = 0;
|
||||
pub const CLIENT_PING: u8 = 1;
|
||||
pub const SERVER_STATUS: u8 = 0;
|
||||
pub const SERVER_PING: u8 = 1;
|
||||
}
|
||||
|
||||
pub mod login {
|
||||
pub const CLIENT_DISCONNECT: i32 = 0x00;
|
||||
pub const CLIENT_LOGIN_SUCCESS: i32 = 0x02;
|
||||
pub const CLIENT_SET_COMPRESSION: i32 = 0x03;
|
||||
pub const SERVER_LOGIN_START: i32 = 0x00;
|
||||
pub const CLIENT_DISCONNECT: u8 = 0x00;
|
||||
pub const CLIENT_LOGIN_SUCCESS: u8 = 0x02;
|
||||
pub const CLIENT_SET_COMPRESSION: u8 = 0x03;
|
||||
pub const SERVER_LOGIN_START: u8 = 0x00;
|
||||
}
|
||||
|
||||
pub mod play {
|
||||
pub const CLIENT_CHAT_MSG: i32 = 0x0F;
|
||||
pub const CLIENT_PLUGIN_MESSAGE: i32 = 0x18;
|
||||
pub const CLIENT_NAMED_SOUND_EFFECT: i32 = 0x19;
|
||||
pub const CLIENT_DISCONNECT: i32 = 0x1A;
|
||||
pub const CLIENT_KEEP_ALIVE: i32 = 0x21;
|
||||
pub const CLIENT_JOIN_GAME: i32 = 0x26;
|
||||
pub const CLIENT_PLAYER_POS_LOOK: i32 = 0x38;
|
||||
pub const CLIENT_RESPAWN: i32 = 0x3D;
|
||||
pub const CLIENT_SPAWN_POS: i32 = 0x4B;
|
||||
pub const CLIENT_SET_TITLE_SUBTITLE: i32 = 0x57;
|
||||
pub const CLIENT_TIME_UPDATE: i32 = 0x58;
|
||||
pub const CLIENT_SET_TITLE_TEXT: i32 = 0x59;
|
||||
pub const CLIENT_SET_TITLE_TIMES: i32 = 0x5A;
|
||||
pub const SERVER_CLIENT_SETTINGS: i32 = 0x05;
|
||||
pub const SERVER_PLUGIN_MESSAGE: i32 = 0x0A;
|
||||
pub const SERVER_PLAYER_POS: i32 = 0x11;
|
||||
pub const SERVER_PLAYER_POS_ROT: i32 = 0x12;
|
||||
pub const CLIENT_CHAT_MSG: u8 = 0x0F;
|
||||
pub const CLIENT_PLUGIN_MESSAGE: u8 = 0x18;
|
||||
pub const CLIENT_NAMED_SOUND_EFFECT: u8 = 0x19;
|
||||
pub const CLIENT_DISCONNECT: u8 = 0x1A;
|
||||
pub const CLIENT_KEEP_ALIVE: u8 = 0x21;
|
||||
pub const CLIENT_JOIN_GAME: u8 = 0x26;
|
||||
pub const CLIENT_PLAYER_POS_LOOK: u8 = 0x38;
|
||||
pub const CLIENT_RESPAWN: u8 = 0x3D;
|
||||
pub const CLIENT_SPAWN_POS: u8 = 0x4B;
|
||||
pub const CLIENT_SET_TITLE_SUBTITLE: u8 = 0x57;
|
||||
pub const CLIENT_TIME_UPDATE: u8 = 0x58;
|
||||
pub const CLIENT_SET_TITLE_TEXT: u8 = 0x59;
|
||||
pub const CLIENT_SET_TITLE_TIMES: u8 = 0x5A;
|
||||
pub const SERVER_CLIENT_SETTINGS: u8 = 0x05;
|
||||
pub const SERVER_PLUGIN_MESSAGE: u8 = 0x0A;
|
||||
pub const SERVER_PLAYER_POS: u8 = 0x11;
|
||||
pub const SERVER_PLAYER_POS_ROT: u8 = 0x12;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user