Add game packets
This commit is contained in:
parent
3be31e8b81
commit
0a0835fd2d
24
.travis.yml
24
.travis.yml
@ -7,27 +7,3 @@ rust:
|
||||
matrix:
|
||||
allow_failures:
|
||||
- rust: nightly
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- libcurl4-openssl-dev
|
||||
- libelf-dev
|
||||
- libdw-dev
|
||||
- cmake
|
||||
- gcc
|
||||
- binutils-dev
|
||||
- libiberty-dev
|
||||
after_success: |
|
||||
wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
|
||||
tar xzf master.tar.gz &&
|
||||
cd kcov-master &&
|
||||
mkdir build &&
|
||||
cd build &&
|
||||
cmake .. &&
|
||||
make &&
|
||||
make install DESTDIR=../../kcov-build &&
|
||||
cd ../.. &&
|
||||
rm -rf kcov-master &&
|
||||
for file in target/debug/minecraft_protocol*; do [ -x "${file}" ] || continue; mkdir -p "target/cov/$(basename $file)"; ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; done &&
|
||||
bash <(curl -s https://codecov.io/bash) &&
|
||||
echo "Uploaded code coverage"
|
||||
|
@ -127,6 +127,7 @@ pub enum DataType {
|
||||
RefType {
|
||||
ref_name: String,
|
||||
},
|
||||
#[serde(rename(serialize = "Message"))]
|
||||
Chat,
|
||||
}
|
||||
|
||||
@ -136,7 +137,7 @@ impl DataType {
|
||||
DataType::Uuid { .. } => Some("uuid::Uuid"),
|
||||
DataType::CompoundTag => Some("nbt::CompoundTag"),
|
||||
DataType::RefType { .. } => Some(state.data_import()),
|
||||
DataType::Chat => Some("crate::chat::Message"),
|
||||
DataType::Chat => Some("crate::data::chat::Message"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ use heck::{CamelCase, SnakeCase};
|
||||
|
||||
use crate::data::input::{Container, Data, ProtocolData, ProtocolState};
|
||||
use crate::data::output;
|
||||
use crate::data::output::Field;
|
||||
use serde::Serialize;
|
||||
use serde_json::json;
|
||||
use std::collections::HashMap;
|
||||
@ -49,10 +48,10 @@ pub fn main() {
|
||||
transform_protocol_state(output::State::Login, &protocol_input.login),
|
||||
output::State::Login,
|
||||
),
|
||||
// (
|
||||
// transform_protocol_state(output::State::Game, &protocol_input.game),
|
||||
// output::State::Game,
|
||||
// ),
|
||||
(
|
||||
transform_protocol_state(output::State::Game, &protocol_input.game),
|
||||
output::State::Game,
|
||||
),
|
||||
];
|
||||
|
||||
for (protocol, state) in protocols {
|
||||
@ -102,10 +101,16 @@ fn transform_protocol_state(
|
||||
state: output::State,
|
||||
protocol_state: &ProtocolState,
|
||||
) -> output::Protocol {
|
||||
let server_bound_packets =
|
||||
transform_protocol_data(&protocol_state.to_server, output::Bound::Server);
|
||||
let client_bound_packets =
|
||||
transform_protocol_data(&protocol_state.to_client, output::Bound::Client);
|
||||
let server_bound_packets = transform_protocol_data(
|
||||
protocol_state,
|
||||
&protocol_state.to_server,
|
||||
output::Bound::Server,
|
||||
);
|
||||
let client_bound_packets = transform_protocol_data(
|
||||
protocol_state,
|
||||
&protocol_state.to_client,
|
||||
output::Bound::Client,
|
||||
);
|
||||
|
||||
output::Protocol {
|
||||
state,
|
||||
@ -115,6 +120,7 @@ fn transform_protocol_state(
|
||||
}
|
||||
|
||||
fn transform_protocol_data(
|
||||
protocol_state: &ProtocolState,
|
||||
protocol_data: &ProtocolData,
|
||||
bound: output::Bound,
|
||||
) -> Vec<output::Packet> {
|
||||
@ -128,12 +134,18 @@ fn transform_protocol_data(
|
||||
continue;
|
||||
}
|
||||
|
||||
let no_prefix_name = unformatted_name.trim_start_matches("packet_");
|
||||
let no_prefix_unformatted = unformatted_name.trim_start_matches("packet_");
|
||||
|
||||
let id = *packet_ids
|
||||
.get(no_prefix_name)
|
||||
.get(no_prefix_unformatted)
|
||||
.expect("Failed to get packet id");
|
||||
let packet_name = rename_packet(&no_prefix_name.to_camel_case(), &bound);
|
||||
|
||||
let packet_name = rename_packet(
|
||||
unformatted_name,
|
||||
&no_prefix_unformatted.to_camel_case(),
|
||||
&bound,
|
||||
protocol_state,
|
||||
);
|
||||
|
||||
let mut fields = vec![];
|
||||
|
||||
@ -248,8 +260,13 @@ fn transform_data_type(name: &str) -> Option<output::DataType> {
|
||||
}
|
||||
}
|
||||
|
||||
fn rename_packet(name: &str, bound: &output::Bound) -> String {
|
||||
match (name, bound) {
|
||||
fn rename_packet(
|
||||
unformatted_name: &str,
|
||||
name: &str,
|
||||
bound: &output::Bound,
|
||||
protocol_state: &ProtocolState,
|
||||
) -> String {
|
||||
let new_name = match (name, bound) {
|
||||
("EncryptionBegin", output::Bound::Server) => "EncryptionResponse",
|
||||
("EncryptionBegin", output::Bound::Client) => "EncryptionRequest",
|
||||
("PingStart", output::Bound::Server) => "StatusRequest",
|
||||
@ -258,7 +275,29 @@ fn rename_packet(name: &str, bound: &output::Bound) -> String {
|
||||
("Ping", output::Bound::Client) => "PingResponse",
|
||||
_ => name,
|
||||
}
|
||||
.to_owned()
|
||||
.to_owned();
|
||||
|
||||
if new_name == name
|
||||
&& protocol_state
|
||||
.to_client
|
||||
.types
|
||||
.contains_key(unformatted_name)
|
||||
&& protocol_state
|
||||
.to_server
|
||||
.types
|
||||
.contains_key(unformatted_name)
|
||||
{
|
||||
bidirectional(&new_name, bound)
|
||||
} else {
|
||||
new_name.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
fn bidirectional(name: &str, bound: &output::Bound) -> String {
|
||||
match bound {
|
||||
output::Bound::Server => format!("ServerBound{}", name),
|
||||
output::Bound::Client => format!("ClientBound{}", name),
|
||||
}
|
||||
}
|
||||
|
||||
fn modify_field(packet_name: &str, field: output::Field) -> output::Field {
|
||||
@ -268,6 +307,10 @@ 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 {
|
||||
ref_name: "MessagePosition".to_owned(),
|
||||
}),
|
||||
_ => field,
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,16 +1,16 @@
|
||||
// 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 minecraft_protocol_derive::Packet;
|
||||
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,12 +39,14 @@ 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)
|
||||
}
|
||||
@ -52,14 +54,17 @@ 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)
|
||||
}
|
||||
@ -70,7 +75,7 @@ pub enum LoginClientBoundPacket {
|
||||
EncryptionRequest(EncryptionRequest),
|
||||
Success(Success),
|
||||
Compress(Compress),
|
||||
LoginPluginRequest(LoginPluginRequest),
|
||||
LoginPluginRequest(LoginPluginRequest)
|
||||
}
|
||||
|
||||
impl LoginClientBoundPacket {
|
||||
@ -80,7 +85,7 @@ impl LoginClientBoundPacket {
|
||||
Self::EncryptionRequest(_) => 0x01,
|
||||
Self::Success(_) => 0x02,
|
||||
Self::Compress(_) => 0x03,
|
||||
Self::LoginPluginRequest(_) => 0x04,
|
||||
Self::LoginPluginRequest(_) => 0x04
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,38 +116,41 @@ impl LoginClientBoundPacket {
|
||||
|
||||
Ok(Self::LoginPluginRequest(login_plugin_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id })
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disconnect(reason: Chat) -> Self {
|
||||
let disconnect = Disconnect { reason };
|
||||
pub fn disconnect(reason: Message) -> Self {
|
||||
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)
|
||||
}
|
||||
@ -151,7 +159,7 @@ impl LoginClientBoundPacket {
|
||||
let login_plugin_request = LoginPluginRequest {
|
||||
message_id,
|
||||
channel,
|
||||
data,
|
||||
data
|
||||
};
|
||||
|
||||
Self::LoginPluginRequest(login_plugin_request)
|
||||
@ -160,13 +168,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)]
|
||||
@ -174,32 +182,33 @@ 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: Chat,
|
||||
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)]
|
||||
@ -208,5 +217,6 @@ pub struct LoginPluginRequest {
|
||||
pub message_id: i32,
|
||||
pub channel: String,
|
||||
#[packet(with = "rest")]
|
||||
pub data: Vec<u8>,
|
||||
pub data: Vec<u8>
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user