Add ref types to login and remove code coverage

This commit is contained in:
Vladislavs Golubs 2021-02-07 17:20:01 +03:00
parent 87b1e7a250
commit 3be31e8b81
3 changed files with 21 additions and 17 deletions

View File

@ -2,6 +2,5 @@ minecraft-protocol
============ ============
[![crates.io](https://img.shields.io/crates/v/minecraft-protocol.svg)](https://crates.io/crates/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) [![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 Library for decoding and encoding Minecraft packets

View File

@ -50,8 +50,8 @@ pub fn main() {
output::State::Login, output::State::Login,
), ),
// ( // (
// transform_protocol_state(State::Game, &protocol_input.game), // transform_protocol_state(output::State::Game, &protocol_input.game),
// State::Game, // output::State::Game,
// ), // ),
]; ];
@ -216,7 +216,7 @@ fn transform_field(unformatted_field_name: &str, data: &Data) -> Option<output::
} }
fn format_field_name(unformatted_field_name: &str) -> String { fn format_field_name(unformatted_field_name: &str) -> String {
if unformatted_field_name == "Type" { if unformatted_field_name == "type" {
String::from("type_") String::from("type_")
} else { } else {
unformatted_field_name.to_snake_case() unformatted_field_name.to_snake_case()
@ -248,15 +248,6 @@ fn transform_data_type(name: &str) -> Option<output::DataType> {
} }
} }
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 { fn rename_packet(name: &str, bound: &output::Bound) -> String {
match (name, bound) { match (name, bound) {
("EncryptionBegin", output::Bound::Server) => "EncryptionResponse", ("EncryptionBegin", output::Bound::Server) => "EncryptionResponse",
@ -270,6 +261,17 @@ fn rename_packet(name: &str, bound: &output::Bound) -> String {
.to_owned() .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)] #[derive(Serialize)]
struct GenerateContext<'a> { struct GenerateContext<'a> {
packet_enum_name: String, packet_enum_name: String,

View File

@ -1,9 +1,11 @@
// This file is automatically generated. // This file is automatically generated.
// It is not intended for manual editing. // It is not intended for manual editing.
use crate::chat::Message;
use crate::DecodeError; use crate::DecodeError;
use crate::Decoder; use crate::Decoder;
use minecraft_protocol_derive::Packet; use minecraft_protocol_derive::Packet;
use std::io::Read; use std::io::Read;
use uuid::Uuid;
pub enum LoginServerBoundPacket { pub enum LoginServerBoundPacket {
LoginStart(LoginStart), LoginStart(LoginStart),
@ -113,7 +115,7 @@ impl LoginClientBoundPacket {
} }
} }
pub fn disconnect(reason: String) -> Self { pub fn disconnect(reason: Chat) -> Self {
let disconnect = Disconnect { reason }; let disconnect = Disconnect { reason };
Self::Disconnect(disconnect) Self::Disconnect(disconnect)
@ -133,7 +135,7 @@ impl LoginClientBoundPacket {
Self::EncryptionRequest(encryption_request) 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 }; let success = Success { uuid, username };
Self::Success(success) Self::Success(success)
@ -177,7 +179,7 @@ pub struct LoginPluginResponse {
#[derive(Packet, Debug)] #[derive(Packet, Debug)]
pub struct Disconnect { pub struct Disconnect {
pub reason: String, pub reason: Chat,
} }
#[derive(Packet, Debug)] #[derive(Packet, Debug)]
@ -189,7 +191,8 @@ pub struct EncryptionRequest {
#[derive(Packet, Debug)] #[derive(Packet, Debug)]
pub struct Success { pub struct Success {
pub uuid: String, #[packet(with = "uuid_hyp_str")]
pub uuid: Uuid,
pub username: String, pub username: String,
} }