diff --git a/README.md b/README.md index 560c9de..b5ef07f 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,5 @@ minecraft-protocol ============ [![crates.io](https://img.shields.io/crates/v/minecraft-protocol.svg)](https://crates.io/crates/minecraft-protocol) [![Build Status](https://travis-ci.com/eihwaz/minecraft-protocol.svg?branch=master)](https://travis-ci.com/eihwaz/minecraft-protocol) -[![codecov](https://codecov.io/gh/eihwaz/minecraft-protocol/branch/master/graph/badge.svg)](https://codecov.io/gh/eihwaz/minecraft-protocol) Library for decoding and encoding Minecraft packets diff --git a/protocol-generator/src/main.rs b/protocol-generator/src/main.rs index 86dc94b..8997047 100644 --- a/protocol-generator/src/main.rs +++ b/protocol-generator/src/main.rs @@ -50,8 +50,8 @@ pub fn main() { output::State::Login, ), // ( - // transform_protocol_state(State::Game, &protocol_input.game), - // State::Game, + // transform_protocol_state(output::State::Game, &protocol_input.game), + // output::State::Game, // ), ]; @@ -216,7 +216,7 @@ fn transform_field(unformatted_field_name: &str, data: &Data) -> Option String { - if unformatted_field_name == "Type" { + if unformatted_field_name == "type" { String::from("type_") } else { unformatted_field_name.to_snake_case() @@ -248,15 +248,6 @@ fn transform_data_type(name: &str) -> Option { } } -fn modify_field(packet_name: &str, field: output::Field) -> output::Field { - match (packet_name, field.name.as_str()) { - ("StatusResponse", "response") => field.change_type(output::DataType::RefType { - ref_name: "ServerStatus".to_owned(), - }), - _ => field, - } -} - fn rename_packet(name: &str, bound: &output::Bound) -> String { match (name, bound) { ("EncryptionBegin", output::Bound::Server) => "EncryptionResponse", @@ -270,6 +261,17 @@ fn rename_packet(name: &str, bound: &output::Bound) -> String { .to_owned() } +fn modify_field(packet_name: &str, field: output::Field) -> output::Field { + match (packet_name, field.name.as_str()) { + ("StatusResponse", "response") => field.change_type(output::DataType::RefType { + ref_name: "ServerStatus".to_owned(), + }), + ("Success", "uuid") => field.change_type(output::DataType::Uuid { hyphenated: true }), + ("Disconnect", "reason") => field.change_type(output::DataType::Chat), + _ => field, + } +} + #[derive(Serialize)] struct GenerateContext<'a> { packet_enum_name: String, diff --git a/protocol/src/packet/login.rs b/protocol/src/packet/login.rs index 4414da5..8c3fc7f 100644 --- a/protocol/src/packet/login.rs +++ b/protocol/src/packet/login.rs @@ -1,9 +1,11 @@ // This file is automatically generated. // It is not intended for manual editing. +use crate::chat::Message; use crate::DecodeError; use crate::Decoder; use minecraft_protocol_derive::Packet; use std::io::Read; +use uuid::Uuid; pub enum LoginServerBoundPacket { LoginStart(LoginStart), @@ -113,7 +115,7 @@ impl LoginClientBoundPacket { } } - pub fn disconnect(reason: String) -> Self { + pub fn disconnect(reason: Chat) -> Self { let disconnect = Disconnect { reason }; Self::Disconnect(disconnect) @@ -133,7 +135,7 @@ impl LoginClientBoundPacket { Self::EncryptionRequest(encryption_request) } - pub fn success(uuid: String, username: String) -> Self { + pub fn success(uuid: Uuid, username: String) -> Self { let success = Success { uuid, username }; Self::Success(success) @@ -177,7 +179,7 @@ pub struct LoginPluginResponse { #[derive(Packet, Debug)] pub struct Disconnect { - pub reason: String, + pub reason: Chat, } #[derive(Packet, Debug)] @@ -189,7 +191,8 @@ pub struct EncryptionRequest { #[derive(Packet, Debug)] pub struct Success { - pub uuid: String, + #[packet(with = "uuid_hyp_str")] + pub uuid: Uuid, pub username: String, }