Refactor protocol derive module (#11)

This commit is contained in:
vagola
2021-09-16 03:09:10 +03:00
committed by GitHub
parent f733fabedc
commit 70bfd01848
9 changed files with 340 additions and 209 deletions

View File

@@ -4,7 +4,7 @@ use crate::data::chat::Message;
use crate::decoder::Decoder;
use crate::error::DecodeError;
use crate::impl_enum_encoder_decoder;
use minecraft_protocol_derive::Packet;
use minecraft_protocol_derive::{Decoder, Encoder};
use nbt::CompoundTag;
use std::io::Read;
@@ -89,9 +89,9 @@ impl GameClientBoundPacket {
}
}
#[derive(Packet, Debug)]
#[derive(Encoder, Decoder, Debug)]
pub struct ServerBoundChatMessage {
#[packet(max_length = 256)]
#[data_type(max_length = 256)]
pub message: String,
}
@@ -103,7 +103,7 @@ impl ServerBoundChatMessage {
}
}
#[derive(Packet, Debug)]
#[derive(Encoder, Decoder, Debug)]
pub struct ClientBoundChatMessage {
pub message: Message,
pub position: MessagePosition,
@@ -126,15 +126,15 @@ impl ClientBoundChatMessage {
}
}
#[derive(Packet, Debug)]
#[derive(Encoder, Decoder, Debug)]
pub struct JoinGame {
pub entity_id: u32,
pub game_mode: GameMode,
pub dimension: i32,
pub max_players: u8,
#[packet(max_length = 16)]
#[data_type(max_length = 16)]
pub level_type: String,
#[packet(with = "var_int")]
#[data_type(with = "var_int")]
pub view_distance: i32,
pub reduced_debug_info: bool,
}
@@ -174,7 +174,7 @@ impl JoinGame {
}
}
#[derive(Packet)]
#[derive(Encoder, Decoder)]
pub struct ServerBoundKeepAlive {
pub id: u64,
}
@@ -187,7 +187,7 @@ impl ServerBoundKeepAlive {
}
}
#[derive(Packet)]
#[derive(Encoder, Decoder)]
pub struct ClientBoundKeepAlive {
pub id: u64,
}
@@ -200,12 +200,12 @@ impl ClientBoundKeepAlive {
}
}
#[derive(Packet, Debug)]
#[derive(Encoder, Decoder, Debug)]
pub struct ChunkData {
pub x: i32,
pub z: i32,
pub full: bool,
#[packet(with = "var_int")]
#[data_type(with = "var_int")]
pub primary_mask: i32,
pub heights: CompoundTag,
pub data: Vec<u8>,
@@ -236,7 +236,7 @@ impl ChunkData {
}
}
#[derive(Packet, Debug)]
#[derive(Encoder, Decoder, Debug)]
pub struct GameDisconnect {
pub reason: Message,
}

View File

@@ -4,7 +4,7 @@ use uuid::Uuid;
use crate::data::chat::Message;
use crate::decoder::Decoder;
use crate::error::DecodeError;
use minecraft_protocol_derive::Packet;
use minecraft_protocol_derive::{Decoder, Encoder};
pub enum LoginServerBoundPacket {
LoginStart(LoginStart),
@@ -102,7 +102,7 @@ impl LoginClientBoundPacket {
}
}
#[derive(Packet, Debug)]
#[derive(Encoder, Decoder, Debug)]
pub struct LoginStart {
pub name: String,
}
@@ -115,7 +115,7 @@ impl LoginStart {
}
}
#[derive(Packet, Debug)]
#[derive(Encoder, Decoder, Debug)]
pub struct EncryptionResponse {
pub shared_secret: Vec<u8>,
pub verify_token: Vec<u8>,
@@ -132,12 +132,12 @@ impl EncryptionResponse {
}
}
#[derive(Packet, Debug)]
#[derive(Encoder, Decoder, Debug)]
pub struct LoginPluginResponse {
#[packet(with = "var_int")]
#[data_type(with = "var_int")]
pub message_id: i32,
pub successful: bool,
#[packet(with = "rest")]
#[data_type(with = "rest")]
pub data: Vec<u8>,
}
@@ -153,7 +153,7 @@ impl LoginPluginResponse {
}
}
#[derive(Packet, Debug)]
#[derive(Encoder, Decoder, Debug)]
pub struct LoginDisconnect {
pub reason: Message,
}
@@ -166,9 +166,9 @@ impl LoginDisconnect {
}
}
#[derive(Packet, Debug)]
#[derive(Encoder, Decoder, Debug)]
pub struct EncryptionRequest {
#[packet(max_length = 20)]
#[data_type(max_length = 20)]
pub server_id: String,
pub public_key: Vec<u8>,
pub verify_token: Vec<u8>,
@@ -190,11 +190,11 @@ impl EncryptionRequest {
}
}
#[derive(Packet, Debug)]
#[derive(Encoder, Decoder, Debug)]
pub struct LoginSuccess {
#[packet(with = "uuid_hyp_str")]
#[data_type(with = "uuid_hyp_str")]
pub uuid: Uuid,
#[packet(max_length = 16)]
#[data_type(max_length = 16)]
pub username: String,
}
@@ -206,9 +206,9 @@ impl LoginSuccess {
}
}
#[derive(Packet, Debug)]
#[derive(Encoder, Decoder, Debug)]
pub struct SetCompression {
#[packet(with = "var_int")]
#[data_type(with = "var_int")]
pub threshold: i32,
}
@@ -220,12 +220,12 @@ impl SetCompression {
}
}
#[derive(Packet, Debug)]
#[derive(Encoder, Decoder, Debug)]
pub struct LoginPluginRequest {
#[packet(with = "var_int")]
#[data_type(with = "var_int")]
pub message_id: i32,
pub channel: String,
#[packet(with = "rest")]
#[data_type(with = "rest")]
pub data: Vec<u8>,
}

View File

@@ -1,7 +1,7 @@
use crate::data::server_status::*;
use crate::decoder::Decoder;
use crate::error::DecodeError;
use minecraft_protocol_derive::Packet;
use minecraft_protocol_derive::{Decoder, Encoder};
use std::io::Read;
pub enum StatusServerBoundPacket {
@@ -44,7 +44,7 @@ impl StatusClientBoundPacket {
}
}
#[derive(Packet, Debug)]
#[derive(Encoder, Decoder, Debug)]
pub struct PingRequest {
pub time: u64,
}
@@ -57,7 +57,7 @@ impl PingRequest {
}
}
#[derive(Packet, Debug)]
#[derive(Encoder, Decoder, Debug)]
pub struct PingResponse {
pub time: u64,
}
@@ -70,7 +70,7 @@ impl PingResponse {
}
}
#[derive(Packet, Debug)]
#[derive(Encoder, Decoder, Debug)]
pub struct StatusResponse {
pub server_status: ServerStatus,
}