This commit is contained in:
Vladislavs Golubs 2021-02-07 18:46:24 +03:00
parent 0a0835fd2d
commit 1d5f2112a7
4 changed files with 92 additions and 44 deletions

View File

@ -307,8 +307,8 @@ fn modify_field(packet_name: &str, field: output::Field) -> output::Field {
}),
("Success", "uuid") => field.change_type(output::DataType::Uuid { hyphenated: true }),
("Disconnect", "reason") => field.change_type(output::DataType::Chat),
("ClientBoundChatMessage", "message") => field.change_type(output::DataType::Chat),
("ClientBoundChatMessage", "position") => field.change_type(output::DataType::RefType {
("ClientBoundChat", "message") => field.change_type(output::DataType::Chat),
("ClientBoundChat", "position") => field.change_type(output::DataType::RefType {
ref_name: "MessagePosition".to_owned(),
}),
_ => field,

View File

@ -225,6 +225,20 @@ impl<R: Read> DecoderReadExt for R {
read_signed_var_int!(i64, read_var_i64, 10);
}
impl Encoder for i8 {
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
Ok(writer.write_i8(*self)?)
}
}
impl Decoder for i8 {
type Output = Self;
fn decode<R: Read>(reader: &mut R) -> Result<Self::Output, DecodeError> {
Ok(reader.read_i8()?)
}
}
impl Encoder for u8 {
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
Ok(writer.write_u8(*self)?)
@ -239,6 +253,20 @@ impl Decoder for u8 {
}
}
impl Encoder for i16 {
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
Ok(writer.write_i16::<BigEndian>(*self)?)
}
}
impl Decoder for i16 {
type Output = Self;
fn decode<R: Read>(reader: &mut R) -> Result<Self::Output, DecodeError> {
Ok(reader.read_i16::<BigEndian>()?)
}
}
impl Encoder for u16 {
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
Ok(writer.write_u16::<BigEndian>(*self)?)
@ -337,6 +365,34 @@ impl Decoder for bool {
}
}
impl Encoder for f32 {
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
Ok(writer.write_f32::<BigEndian>(*self)?)
}
}
impl Decoder for f32 {
type Output = Self;
fn decode<R: Read>(reader: &mut R) -> Result<Self::Output, DecodeError> {
Ok(reader.read_f32::<BigEndian>()?)
}
}
impl Encoder for f64 {
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
Ok(writer.write_f64::<BigEndian>(*self)?)
}
}
impl Decoder for f64 {
type Output = Self;
fn decode<R: Read>(reader: &mut R) -> Result<Self::Output, DecodeError> {
Ok(reader.read_f64::<BigEndian>()?)
}
}
impl Encoder for Vec<u8> {
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
Ok(writer.write_byte_array(self)?)

View File

@ -1,5 +1,7 @@
// This file is automatically generated.
// It is not intended for manual editing.
use crate::data::chat::Message;
use crate::data::game::*;
use crate::DecodeError;
use crate::Decoder;
use minecraft_protocol_derive::Packet;
@ -1641,7 +1643,7 @@ impl GameClientBoundPacket {
Self::NbtQueryResponse(nbt_query_response)
}
pub fn client_bound_chat(message: String, position: i8) -> Self {
pub fn client_bound_chat(message: Message, position: MessagePosition) -> Self {
let client_bound_chat = ClientBoundChat { message, position };
Self::ClientBoundChat(client_bound_chat)
@ -2892,8 +2894,8 @@ pub struct NbtQueryResponse {
#[derive(Packet, Debug)]
pub struct ClientBoundChat {
pub message: String,
pub position: i8,
pub message: Message,
pub position: MessagePosition,
}
#[derive(Packet, Debug)]

View File

@ -1,16 +1,16 @@
// This file is automatically generated.
// It is not intended for manual editing.
use crate::data::chat::Message;
use crate::DecodeError;
use crate::Decoder;
use std::io::Read;
use minecraft_protocol_derive::Packet;
use std::io::Read;
use uuid::Uuid;
use crate::data::chat::Message;
pub enum LoginServerBoundPacket {
LoginStart(LoginStart),
EncryptionResponse(EncryptionResponse),
LoginPluginResponse(LoginPluginResponse)
LoginPluginResponse(LoginPluginResponse),
}
impl LoginServerBoundPacket {
@ -18,7 +18,7 @@ impl LoginServerBoundPacket {
match self {
Self::LoginStart(_) => 0x00,
Self::EncryptionResponse(_) => 0x01,
Self::LoginPluginResponse(_) => 0x02
Self::LoginPluginResponse(_) => 0x02,
}
}
@ -39,14 +39,12 @@ impl LoginServerBoundPacket {
Ok(Self::LoginPluginResponse(login_plugin_response))
}
_ => Err(DecodeError::UnknownPacketType { type_id })
_ => Err(DecodeError::UnknownPacketType { type_id }),
}
}
pub fn login_start(username: String) -> Self {
let login_start = LoginStart {
username
};
let login_start = LoginStart { username };
Self::LoginStart(login_start)
}
@ -54,17 +52,14 @@ impl LoginServerBoundPacket {
pub fn encryption_response(shared_secret: Vec<u8>, verify_token: Vec<u8>) -> Self {
let encryption_response = EncryptionResponse {
shared_secret,
verify_token
verify_token,
};
Self::EncryptionResponse(encryption_response)
}
pub fn login_plugin_response(message_id: i32, data: Vec<u8>) -> Self {
let login_plugin_response = LoginPluginResponse {
message_id,
data
};
let login_plugin_response = LoginPluginResponse { message_id, data };
Self::LoginPluginResponse(login_plugin_response)
}
@ -75,7 +70,7 @@ pub enum LoginClientBoundPacket {
EncryptionRequest(EncryptionRequest),
Success(Success),
Compress(Compress),
LoginPluginRequest(LoginPluginRequest)
LoginPluginRequest(LoginPluginRequest),
}
impl LoginClientBoundPacket {
@ -85,7 +80,7 @@ impl LoginClientBoundPacket {
Self::EncryptionRequest(_) => 0x01,
Self::Success(_) => 0x02,
Self::Compress(_) => 0x03,
Self::LoginPluginRequest(_) => 0x04
Self::LoginPluginRequest(_) => 0x04,
}
}
@ -116,41 +111,38 @@ impl LoginClientBoundPacket {
Ok(Self::LoginPluginRequest(login_plugin_request))
}
_ => Err(DecodeError::UnknownPacketType { type_id })
_ => Err(DecodeError::UnknownPacketType { type_id }),
}
}
pub fn disconnect(reason: Message) -> Self {
let disconnect = Disconnect {
reason
};
let disconnect = Disconnect { reason };
Self::Disconnect(disconnect)
}
pub fn encryption_request(server_id: String, public_key: Vec<u8>, verify_token: Vec<u8>) -> Self {
pub fn encryption_request(
server_id: String,
public_key: Vec<u8>,
verify_token: Vec<u8>,
) -> Self {
let encryption_request = EncryptionRequest {
server_id,
public_key,
verify_token
verify_token,
};
Self::EncryptionRequest(encryption_request)
}
pub fn success(uuid: Uuid, username: String) -> Self {
let success = Success {
uuid,
username
};
let success = Success { uuid, username };
Self::Success(success)
}
pub fn compress(threshold: i32) -> Self {
let compress = Compress {
threshold
};
let compress = Compress { threshold };
Self::Compress(compress)
}
@ -159,7 +151,7 @@ impl LoginClientBoundPacket {
let login_plugin_request = LoginPluginRequest {
message_id,
channel,
data
data,
};
Self::LoginPluginRequest(login_plugin_request)
@ -168,13 +160,13 @@ impl LoginClientBoundPacket {
#[derive(Packet, Debug)]
pub struct LoginStart {
pub username: String
pub username: String,
}
#[derive(Packet, Debug)]
pub struct EncryptionResponse {
pub shared_secret: Vec<u8>,
pub verify_token: Vec<u8>
pub verify_token: Vec<u8>,
}
#[derive(Packet, Debug)]
@ -182,33 +174,32 @@ pub struct LoginPluginResponse {
#[packet(with = "var_int")]
pub message_id: i32,
#[packet(with = "rest")]
pub data: Vec<u8>
pub data: Vec<u8>,
}
#[derive(Packet, Debug)]
pub struct Disconnect {
pub reason: Message
pub reason: Message,
}
#[derive(Packet, Debug)]
pub struct EncryptionRequest {
pub server_id: String,
pub public_key: Vec<u8>,
pub verify_token: Vec<u8>
pub verify_token: Vec<u8>,
}
#[derive(Packet, Debug)]
pub struct Success {
#[packet(with = "uuid_hyp_str")]
pub uuid: Uuid,
pub username: String
pub username: String,
}
#[derive(Packet, Debug)]
pub struct Compress {
#[packet(with = "var_int")]
pub threshold: i32
pub threshold: i32,
}
#[derive(Packet, Debug)]
@ -217,6 +208,5 @@ pub struct LoginPluginRequest {
pub message_id: i32,
pub channel: String,
#[packet(with = "rest")]
pub data: Vec<u8>
pub data: Vec<u8>,
}