Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
a121323eed | ||
|
b043dbb07b | ||
|
2d9b9dd94f | ||
|
c6d1cdecc7 | ||
|
e8a061e672 | ||
|
ebd8f5ce22 | ||
|
5245cdf16d | ||
|
1d5f2112a7 | ||
|
0a0835fd2d | ||
|
3be31e8b81 | ||
|
87b1e7a250 | ||
|
99a331c6ab | ||
|
03267e3318 | ||
|
d589bd7956 | ||
|
ab4d40e482 | ||
|
3229d02418 | ||
|
3189f0c0d9 | ||
|
f1c602092c | ||
|
fca5351977 | ||
|
02f2d6b860 | ||
|
2849483562 | ||
|
ccd8647113 |
.gitmodules.travis.ymlCargo.tomlREADME.mdgenerate.sh
protocol-derive
protocol-generator
protocol
src
data
error.rsgame.rslib.rslogin.rsstatus.rsversion
mod.rs
v_15w40b
v_16w20a
v_16w35a
v_17w15a
v_17w18b
v_17w50a
v_1_10
v_1_10_pre1
v_1_11
v_1_12
v_1_12_1
v_1_12_2
v_1_12_pre4
v_1_13
v_1_13_1
v_1_13_2
v_1_13_2_pre1
v_1_13_2_pre2
v_1_14
v_1_14_1
v_1_14_3
v_1_14_4
v_1_15
v_1_15_1
v_1_15_2
v_1_16
v_1_16_1
v_1_16_2
v_1_16_rc1
v_1_8
v_1_9
v_1_9_1_pre2
v_1_9_2
v_1_9_4
v_20w13b
test
packet
game
chunk_data.datclient_bound_chat_message.datclient_bound_keep_alive.datgame_disconnect.datjoin_game.datserver_bound_chat_message.datserver_bound_keep_alive.dat
login
encryption_request.datencryption_response.datlogin_disconnect.datlogin_plugin_request.datlogin_plugin_response.datlogin_set_compression.datlogin_start.datlogin_success.dat
status
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "protocol-generator/minecraft-data"]
|
||||
path = protocol-generator/minecraft-data
|
||||
url = https://github.com/PrismarineJS/minecraft-data
|
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"
|
||||
|
@@ -3,4 +3,5 @@
|
||||
members = [
|
||||
"protocol",
|
||||
"protocol-derive",
|
||||
]
|
||||
"protocol-generator"
|
||||
]
|
||||
|
@@ -2,6 +2,5 @@ minecraft-protocol
|
||||
============
|
||||
[](https://crates.io/crates/minecraft-protocol)
|
||||
[](https://travis-ci.com/eihwaz/minecraft-protocol)
|
||||
[](https://codecov.io/gh/eihwaz/minecraft-protocol)
|
||||
|
||||
Library for decoding and encoding Minecraft packets
|
||||
|
4
generate.sh
Executable file
4
generate.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
cargo run
|
||||
cargo fmt
|
@@ -7,7 +7,7 @@ description = "Derive macro for reading and writing Minecraft packets"
|
||||
license = "MIT"
|
||||
homepage = "https://github.com/eihwaz/minecraft-protocol"
|
||||
repository = "https://github.com/eihwaz/minecraft-protocol"
|
||||
keywords = ["minecraft", "protocol", "packet", "io"]
|
||||
keywords = ["minecraft", "derive", "protocol", "packet", "io"]
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
@@ -5,7 +5,7 @@ use proc_macro2::Ident;
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use quote::{quote, TokenStreamExt};
|
||||
use std::iter::FromIterator;
|
||||
use syn::export::Span;
|
||||
use syn::__private::Span;
|
||||
use syn::{parse_macro_input, Data, DeriveInput, Field, Fields, Lit, Meta, NestedMeta};
|
||||
|
||||
#[proc_macro_derive(Packet, attributes(packet))]
|
||||
|
17
protocol-generator/Cargo.toml
Normal file
17
protocol-generator/Cargo.toml
Normal file
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "minecraft-protocol-generator"
|
||||
version = "0.0.0"
|
||||
authors = ["vagola <vladislavs.golubs@yandex.ru>"]
|
||||
edition = "2018"
|
||||
description = "CLI for generating Rust code with Minecraft packets"
|
||||
license = "MIT"
|
||||
homepage = "https://github.com/eihwaz/minecraft-protocol"
|
||||
repository = "https://github.com/eihwaz/minecraft-protocol"
|
||||
keywords = ["minecraft", "cli", "protocol", "packet", "io"]
|
||||
|
||||
[dependencies]
|
||||
serde = "1.0.120"
|
||||
serde_json = "1.0"
|
||||
handlebars = "3.5.2"
|
||||
heck = "0.3.2"
|
||||
linked-hash-map = { version = "0.5.4", features = ["serde_impl"] }
|
1
protocol-generator/minecraft-data
Submodule
1
protocol-generator/minecraft-data
Submodule
Submodule protocol-generator/minecraft-data added at cc155f3993
101
protocol-generator/src/backend.rs
Normal file
101
protocol-generator/src/backend.rs
Normal file
@@ -0,0 +1,101 @@
|
||||
use linked_hash_map::LinkedHashMap;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ProtocolHandler {
|
||||
pub handshaking: Protocol,
|
||||
pub status: Protocol,
|
||||
pub login: Protocol,
|
||||
#[serde(rename = "play")]
|
||||
pub game: Protocol,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Protocol {
|
||||
pub to_client: Packets,
|
||||
pub to_server: Packets,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Packets {
|
||||
pub types: LinkedHashMap<String, Vec<Data>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq, Eq)]
|
||||
#[serde(untagged)]
|
||||
pub enum Data {
|
||||
Type(String),
|
||||
Containers(Vec<Container>),
|
||||
Container(Box<Container>),
|
||||
Mapper {
|
||||
#[serde(rename = "type")]
|
||||
mappings_type: String,
|
||||
mappings: LinkedHashMap<String, String>,
|
||||
},
|
||||
Switch(Switch),
|
||||
List(Box<List>),
|
||||
Bitfield(Vec<BitField>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq, Eq)]
|
||||
#[serde(untagged)]
|
||||
pub enum Container {
|
||||
Value {
|
||||
name: String,
|
||||
#[serde(rename = "type")]
|
||||
data: Data,
|
||||
},
|
||||
List {
|
||||
name: Option<String>,
|
||||
#[serde(rename = "type")]
|
||||
data_vec: Vec<Data>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq, Eq)]
|
||||
#[serde(untagged)]
|
||||
pub enum Switch {
|
||||
Value {
|
||||
#[serde(rename = "compareTo")]
|
||||
compare_to: String,
|
||||
fields: LinkedHashMap<String, Data>,
|
||||
},
|
||||
List {
|
||||
#[serde(rename = "compareTo")]
|
||||
compare_to: String,
|
||||
fields: LinkedHashMap<String, Vec<Data>>,
|
||||
},
|
||||
Empty {
|
||||
#[serde(rename = "compareTo")]
|
||||
compare_to: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq, Eq)]
|
||||
#[serde(untagged)]
|
||||
pub enum List {
|
||||
Value {
|
||||
#[serde(rename = "countType")]
|
||||
count_type: String,
|
||||
#[serde(rename = "type")]
|
||||
list_type: Data,
|
||||
},
|
||||
List {
|
||||
#[serde(rename = "countType")]
|
||||
count_type: String,
|
||||
#[serde(rename = "type")]
|
||||
list_type: Vec<Data>,
|
||||
},
|
||||
Empty {
|
||||
#[serde(rename = "countType")]
|
||||
count_type: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq, Eq)]
|
||||
pub struct BitField {
|
||||
name: String,
|
||||
size: usize,
|
||||
signed: bool,
|
||||
}
|
309
protocol-generator/src/frontend.rs
Normal file
309
protocol-generator/src/frontend.rs
Normal file
@@ -0,0 +1,309 @@
|
||||
use crate::mappings::Mappings;
|
||||
use crate::{backend, frontend, transformers};
|
||||
use handlebars::{Handlebars, TemplateRenderError};
|
||||
use serde::Serialize;
|
||||
use serde_json::json;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fmt;
|
||||
use std::fmt::Display;
|
||||
use std::fs::{create_dir_all, File};
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum State {
|
||||
Handshake,
|
||||
Status,
|
||||
Login,
|
||||
Game,
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub fn data_import(&self) -> &'static str {
|
||||
match self {
|
||||
State::Handshake => "crate::data::handshake::*",
|
||||
State::Status => "crate::data::status::*",
|
||||
State::Login => "crate::data::login::*",
|
||||
State::Game => "crate::data::game::*",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for State {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let name = match self {
|
||||
State::Handshake => "Handshake",
|
||||
State::Status => "Status",
|
||||
State::Login => "Login",
|
||||
State::Game => "Game",
|
||||
};
|
||||
|
||||
write!(f, "{}", name)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum Bound {
|
||||
Server,
|
||||
Client,
|
||||
}
|
||||
|
||||
impl Display for Bound {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let name = match self {
|
||||
Bound::Server => "Server",
|
||||
Bound::Client => "Client",
|
||||
};
|
||||
|
||||
write!(f, "{}", name)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
pub struct Packet {
|
||||
pub id: u8,
|
||||
pub name: String,
|
||||
pub fields: Vec<Field>,
|
||||
}
|
||||
|
||||
impl Packet {
|
||||
pub fn new(id: u8, name: impl ToString, fields: Vec<Field>) -> Packet {
|
||||
Packet {
|
||||
id,
|
||||
name: name.to_string(),
|
||||
fields,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
pub struct Field {
|
||||
pub name: String,
|
||||
#[serde(flatten)]
|
||||
pub data_type: DataType,
|
||||
}
|
||||
|
||||
impl Field {
|
||||
pub fn new(name: impl ToString, data_type: DataType) -> Field {
|
||||
Field {
|
||||
name: name.to_string(),
|
||||
data_type,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn change_type(&self, data_type: DataType) -> Field {
|
||||
Field::new(&self.name, data_type)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Eq, PartialEq, Debug)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum DataType {
|
||||
#[serde(rename(serialize = "bool"))]
|
||||
Boolean,
|
||||
#[serde(rename(serialize = "i8"))]
|
||||
Byte,
|
||||
#[serde(rename(serialize = "u8"))]
|
||||
UnsignedByte,
|
||||
#[serde(rename(serialize = "i16"))]
|
||||
Short,
|
||||
#[serde(rename(serialize = "u16"))]
|
||||
UnsignedShort,
|
||||
#[serde(rename(serialize = "i32"))]
|
||||
Int {
|
||||
var_int: bool,
|
||||
},
|
||||
#[serde(rename(serialize = "u32"))]
|
||||
UnsignedInt,
|
||||
#[serde(rename(serialize = "i64"))]
|
||||
Long {
|
||||
var_long: bool,
|
||||
},
|
||||
#[serde(rename(serialize = "f32"))]
|
||||
Float,
|
||||
#[serde(rename(serialize = "f64"))]
|
||||
Double,
|
||||
String {
|
||||
max_length: u16,
|
||||
},
|
||||
Uuid {
|
||||
hyphenated: bool,
|
||||
},
|
||||
#[serde(rename(serialize = "Vec<u8>"))]
|
||||
ByteArray {
|
||||
rest: bool,
|
||||
},
|
||||
CompoundTag,
|
||||
RefType {
|
||||
ref_name: String,
|
||||
},
|
||||
#[serde(rename(serialize = "Message"))]
|
||||
Chat,
|
||||
}
|
||||
|
||||
impl DataType {
|
||||
pub fn import(&self, state: &State) -> Option<&'static str> {
|
||||
match self {
|
||||
DataType::Uuid { .. } => Some("uuid::Uuid"),
|
||||
DataType::CompoundTag => Some("nbt::CompoundTag"),
|
||||
DataType::RefType { .. } => Some(state.data_import()),
|
||||
DataType::Chat => Some("crate::data::chat::Message"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Protocol {
|
||||
pub server_bound_packets: Vec<Packet>,
|
||||
pub client_bound_packets: Vec<Packet>,
|
||||
}
|
||||
|
||||
impl Protocol {
|
||||
pub fn new(server_bound_packets: Vec<Packet>, client_bound_packets: Vec<Packet>) -> Protocol {
|
||||
Protocol {
|
||||
server_bound_packets,
|
||||
client_bound_packets,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn data_type_imports(&self, state: &State) -> HashSet<&'static str> {
|
||||
self.server_bound_packets
|
||||
.iter()
|
||||
.chain(self.client_bound_packets.iter())
|
||||
.flat_map(|p| p.fields.iter())
|
||||
.filter_map(|f| f.data_type.import(state))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_rust_files<M: Mappings>(
|
||||
versions_data: HashMap<String, File>,
|
||||
template_engine: &Handlebars,
|
||||
mappings: &M,
|
||||
) -> Result<(), TemplateRenderError> {
|
||||
generate_versions_module_file(template_engine, versions_data.keys().cloned().collect())?;
|
||||
|
||||
for (version, data_file) in versions_data.iter() {
|
||||
println!("Generating protocol data for version {}", version);
|
||||
|
||||
let protocol_handler: backend::ProtocolHandler =
|
||||
serde_json::from_reader(data_file).expect("Failed to parse protocol data");
|
||||
|
||||
let frontend_protocols =
|
||||
transformers::transform_protocol_handler(mappings, &protocol_handler);
|
||||
|
||||
let formatted_version = version.replace(".", "_").replace("-", "_");
|
||||
|
||||
let folder_name = format!("protocol/src/version/v_{}", formatted_version);
|
||||
let folder_path = Path::new(&folder_name);
|
||||
|
||||
generate_protocol_module_file(template_engine, &folder_path)?;
|
||||
|
||||
for (protocol, state) in frontend_protocols {
|
||||
let file_name = format!("{}.rs", state.to_string().to_lowercase());
|
||||
|
||||
let mut file = File::create(folder_path.join(file_name))
|
||||
.expect("Failed to create protocol enum file");
|
||||
|
||||
generate_protocol_enum_header(template_engine, &protocol, &state, &mut file)?;
|
||||
|
||||
generate_protocol_enum_content(
|
||||
template_engine,
|
||||
&protocol.server_bound_packets,
|
||||
&state,
|
||||
&Bound::Server,
|
||||
&mut file,
|
||||
)?;
|
||||
|
||||
generate_protocol_enum_content(
|
||||
template_engine,
|
||||
&protocol.client_bound_packets,
|
||||
&state,
|
||||
&Bound::Client,
|
||||
&mut file,
|
||||
)?;
|
||||
|
||||
generate_packets_structs(template_engine, &protocol.server_bound_packets, &mut file)?;
|
||||
|
||||
generate_packets_structs(template_engine, &protocol.client_bound_packets, &mut file)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn generate_versions_module_file(
|
||||
template_engine: &Handlebars,
|
||||
versions: Vec<String>,
|
||||
) -> Result<(), TemplateRenderError> {
|
||||
let mut file =
|
||||
File::create("protocol/src/version/mod.rs").expect("Failed to create versions module file");
|
||||
|
||||
let ctx = json!({ "versions": versions });
|
||||
|
||||
template_engine.render_to_write("protocol_versions_module", &ctx, &mut file)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn generate_protocol_module_file(
|
||||
template_engine: &Handlebars,
|
||||
folder_path: &Path,
|
||||
) -> Result<(), TemplateRenderError> {
|
||||
generate_module_file(template_engine, folder_path, "protocol_module")
|
||||
}
|
||||
|
||||
fn generate_module_file(
|
||||
template_engine: &Handlebars,
|
||||
folder_path: &Path,
|
||||
name: &str,
|
||||
) -> Result<(), TemplateRenderError> {
|
||||
create_dir_all(folder_path).expect("Failed to create module folder");
|
||||
|
||||
let mut file = File::create(folder_path.join("mod.rs")).expect("Failed to create module file");
|
||||
|
||||
template_engine.render_to_write(name, &(), &mut file)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn generate_protocol_enum_header<W: Write>(
|
||||
template_engine: &Handlebars,
|
||||
protocol: &frontend::Protocol,
|
||||
state: &frontend::State,
|
||||
write: &mut W,
|
||||
) -> Result<(), TemplateRenderError> {
|
||||
let imports = protocol.data_type_imports(state);
|
||||
let ctx = json!({ "imports": imports });
|
||||
|
||||
template_engine.render_to_write("protocol_header", &ctx, write)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn generate_protocol_enum_content<W: Write>(
|
||||
template_engine: &Handlebars,
|
||||
packets: &Vec<Packet>,
|
||||
state: &frontend::State,
|
||||
bound: &frontend::Bound,
|
||||
write: &mut W,
|
||||
) -> Result<(), TemplateRenderError> {
|
||||
let protocol_enum_name = format!("{}Bound{}Packet", bound, state);
|
||||
let ctx = json!({ "protocol_enum_name": protocol_enum_name, "packets": packets });
|
||||
|
||||
template_engine.render_to_write("protocol_enum", &ctx, write)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn generate_packets_structs<W: Write>(
|
||||
template_engine: &Handlebars,
|
||||
packets: &Vec<Packet>,
|
||||
write: &mut W,
|
||||
) -> Result<(), TemplateRenderError> {
|
||||
let ctx = json!({ "packets": packets });
|
||||
|
||||
template_engine.render_to_write("packets_structs", &ctx, write)?;
|
||||
|
||||
Ok(())
|
||||
}
|
57
protocol-generator/src/main.rs
Normal file
57
protocol-generator/src/main.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
use std::fs::File;
|
||||
|
||||
use crate::mappings::CodeMappings;
|
||||
use std::fs;
|
||||
use std::io::Error;
|
||||
use std::path::Path;
|
||||
|
||||
pub mod backend;
|
||||
pub mod frontend;
|
||||
pub mod mappings;
|
||||
pub mod templates;
|
||||
pub mod transformers;
|
||||
|
||||
pub fn main() {
|
||||
let paths = fs::read_dir("protocol-generator/minecraft-data/data/pc/")
|
||||
.expect("Failed to open data folder");
|
||||
|
||||
let versions_data = paths
|
||||
.into_iter()
|
||||
.map(|entry| {
|
||||
entry
|
||||
.expect("Failed to get dir entry")
|
||||
.file_name()
|
||||
.into_string()
|
||||
.expect("Failed to get version string")
|
||||
})
|
||||
.filter(|version| match version.as_str() {
|
||||
"0.30c" => false, // A very old version with a lot of incompatibility.
|
||||
"1.7" => false, // Requires some fixes to support.
|
||||
_ => true,
|
||||
})
|
||||
.filter_map(|version| {
|
||||
let protocol_data_file_name = format!(
|
||||
"protocol-generator/minecraft-data/data/pc/{}/protocol.json",
|
||||
version
|
||||
);
|
||||
|
||||
let protocol_data_file_path = Path::new(&protocol_data_file_name);
|
||||
|
||||
match protocol_data_file_path.exists() {
|
||||
true => {
|
||||
let protocol_data_file = File::open(protocol_data_file_path)
|
||||
.expect("Failed to open protocol data file");
|
||||
|
||||
Some((version, protocol_data_file))
|
||||
}
|
||||
false => None,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
let template_engine = templates::create_template_engine();
|
||||
let mappings = CodeMappings::new();
|
||||
|
||||
frontend::generate_rust_files(versions_data, &template_engine, &mappings)
|
||||
.expect("Failed to generate rust files");
|
||||
}
|
71
protocol-generator/src/mappings.rs
Normal file
71
protocol-generator/src/mappings.rs
Normal file
@@ -0,0 +1,71 @@
|
||||
use crate::backend;
|
||||
use crate::frontend;
|
||||
|
||||
pub trait Mappings {
|
||||
fn rename_packet(
|
||||
&self,
|
||||
unformatted_name: &str,
|
||||
name: &str,
|
||||
bound: &frontend::Bound,
|
||||
protocol: &backend::Protocol,
|
||||
) -> String;
|
||||
|
||||
fn change_field_type(&self, packet_name: &str, field: frontend::Field) -> frontend::Field;
|
||||
}
|
||||
|
||||
pub struct CodeMappings {}
|
||||
|
||||
impl CodeMappings {
|
||||
pub fn new() -> CodeMappings {
|
||||
CodeMappings {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Mappings for CodeMappings {
|
||||
fn rename_packet(
|
||||
&self,
|
||||
unformatted_name: &str,
|
||||
name: &str,
|
||||
bound: &frontend::Bound,
|
||||
protocol: &backend::Protocol,
|
||||
) -> String {
|
||||
let new_name = match (name, bound) {
|
||||
("EncryptionBegin", frontend::Bound::Server) => "EncryptionResponse",
|
||||
("EncryptionBegin", frontend::Bound::Client) => "EncryptionRequest",
|
||||
("PingStart", frontend::Bound::Server) => "StatusRequest",
|
||||
("Ping", frontend::Bound::Server) => "PingRequest",
|
||||
("ServerInfo", frontend::Bound::Client) => "StatusResponse",
|
||||
("Ping", frontend::Bound::Client) => "PingResponse",
|
||||
("Login", frontend::Bound::Client) => "JoinGame",
|
||||
_ => name,
|
||||
}
|
||||
.to_owned();
|
||||
|
||||
if new_name == name
|
||||
&& protocol.to_client.types.contains_key(unformatted_name)
|
||||
&& protocol.to_server.types.contains_key(unformatted_name)
|
||||
{
|
||||
match bound {
|
||||
frontend::Bound::Server => format!("ServerBound{}", name),
|
||||
frontend::Bound::Client => format!("ClientBound{}", name),
|
||||
}
|
||||
} else {
|
||||
new_name.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
fn change_field_type(&self, packet_name: &str, field: frontend::Field) -> frontend::Field {
|
||||
match (packet_name, field.name.as_str()) {
|
||||
// ("StatusResponse", "response") => field.change_type(frontend::DataType::RefType {
|
||||
// ref_name: "ServerStatus".to_owned(),
|
||||
// }),
|
||||
// ("Success", "uuid") => field.change_type(frontend::DataType::Uuid { hyphenated: true }),
|
||||
// ("Disconnect", "reason") => field.change_type(frontend::DataType::Chat),
|
||||
// ("ClientBoundChat", "message") => field.change_type(frontend::DataType::Chat),
|
||||
// ("ClientBoundChat", "position") => field.change_type(frontend::DataType::RefType {
|
||||
// ref_name: "MessagePosition".to_owned(),
|
||||
// }),
|
||||
_ => field,
|
||||
}
|
||||
}
|
||||
}
|
89
protocol-generator/src/templates.rs
Normal file
89
protocol-generator/src/templates.rs
Normal file
@@ -0,0 +1,89 @@
|
||||
use handlebars::{Context, Handlebars, Helper, Output, RenderContext, RenderError};
|
||||
use heck::SnakeCase;
|
||||
|
||||
pub fn create_template_engine() -> Handlebars<'static> {
|
||||
let mut template_engine = Handlebars::new();
|
||||
|
||||
template_engine.register_helper("snake_case", Box::new(format_snake_case));
|
||||
template_engine.register_helper("packet_id", Box::new(format_packet_id));
|
||||
template_engine.register_helper(
|
||||
"protocol_version_module",
|
||||
Box::new(format_protocol_version_module),
|
||||
);
|
||||
template_engine.register_escape_fn(|s| s.to_owned());
|
||||
|
||||
register_template_file(&mut template_engine, "protocol_versions_module");
|
||||
register_template_file(&mut template_engine, "protocol_module");
|
||||
register_template_file(&mut template_engine, "protocol_enum");
|
||||
register_template_file(&mut template_engine, "packets_structs");
|
||||
register_template_file(&mut template_engine, "protocol_header");
|
||||
|
||||
template_engine
|
||||
}
|
||||
|
||||
fn register_template_file(template_engine: &mut Handlebars, name: &str) {
|
||||
template_engine
|
||||
.register_template_file(name, format!("protocol-generator/templates/{}.hbs", name))
|
||||
.expect("Failed to register template");
|
||||
}
|
||||
|
||||
fn format_snake_case(
|
||||
h: &Helper,
|
||||
_: &Handlebars,
|
||||
_: &Context,
|
||||
_: &mut RenderContext,
|
||||
out: &mut dyn Output,
|
||||
) -> Result<(), RenderError> {
|
||||
let str = h
|
||||
.param(0)
|
||||
.and_then(|v| v.value().as_str())
|
||||
.ok_or(RenderError::new(
|
||||
"Param 0 with str type is required for snake case helper.",
|
||||
))? as &str;
|
||||
|
||||
let snake_case_str = str.to_snake_case();
|
||||
|
||||
out.write(snake_case_str.as_ref())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn format_packet_id(
|
||||
h: &Helper,
|
||||
_: &Handlebars,
|
||||
_: &Context,
|
||||
_: &mut RenderContext,
|
||||
out: &mut dyn Output,
|
||||
) -> Result<(), RenderError> {
|
||||
let id = h
|
||||
.param(0)
|
||||
.and_then(|v| v.value().as_u64())
|
||||
.ok_or(RenderError::new(
|
||||
"Param 0 with u64 type is required for packet id helper.",
|
||||
))? as u64;
|
||||
|
||||
let packet_id_str = format!("{:#04X}", id);
|
||||
|
||||
out.write(packet_id_str.as_ref())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn format_protocol_version_module(
|
||||
h: &Helper,
|
||||
_: &Handlebars,
|
||||
_: &Context,
|
||||
_: &mut RenderContext,
|
||||
out: &mut dyn Output,
|
||||
) -> Result<(), RenderError> {
|
||||
let version = h
|
||||
.param(0)
|
||||
.and_then(|v| v.value().as_str())
|
||||
.ok_or(RenderError::new(
|
||||
"Param 0 with str type is required for packet id helper.",
|
||||
))? as &str;
|
||||
|
||||
let formatted_protocol_module_version =
|
||||
format!("v_{}", version.replace(".", "_").replace("-", "_"));
|
||||
|
||||
out.write(formatted_protocol_module_version.as_ref())?;
|
||||
Ok(())
|
||||
}
|
241
protocol-generator/src/transformers.rs
Normal file
241
protocol-generator/src/transformers.rs
Normal file
@@ -0,0 +1,241 @@
|
||||
use crate::mappings::Mappings;
|
||||
use crate::{backend, frontend};
|
||||
use heck::{CamelCase, SnakeCase};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn transform_protocol_handler<M: Mappings>(
|
||||
mappings: &M,
|
||||
protocol_handler: &backend::ProtocolHandler,
|
||||
) -> Vec<(frontend::Protocol, frontend::State)> {
|
||||
vec![
|
||||
(
|
||||
transform_protocol::<M>(&mappings, &protocol_handler.handshaking),
|
||||
frontend::State::Handshake,
|
||||
),
|
||||
(
|
||||
transform_protocol::<M>(&mappings, &protocol_handler.status),
|
||||
frontend::State::Status,
|
||||
),
|
||||
(
|
||||
transform_protocol::<M>(&mappings, &protocol_handler.login),
|
||||
frontend::State::Login,
|
||||
),
|
||||
(
|
||||
transform_protocol::<M>(&mappings, &protocol_handler.game),
|
||||
frontend::State::Game,
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
fn transform_protocol<M: Mappings>(
|
||||
mappings: &M,
|
||||
protocol: &backend::Protocol,
|
||||
) -> frontend::Protocol {
|
||||
let server_bound_packets = transform_packets(
|
||||
mappings,
|
||||
protocol,
|
||||
&protocol.to_server,
|
||||
frontend::Bound::Server,
|
||||
);
|
||||
|
||||
let client_bound_packets = transform_packets(
|
||||
mappings,
|
||||
protocol,
|
||||
&protocol.to_client,
|
||||
frontend::Bound::Client,
|
||||
);
|
||||
|
||||
frontend::Protocol {
|
||||
server_bound_packets,
|
||||
client_bound_packets,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_packet_ids(packets: &backend::Packets) -> HashMap<String, u8> {
|
||||
let reversed_packet_ids = packets
|
||||
.types
|
||||
.get("packet")
|
||||
.and_then(|d| d.get(1))
|
||||
.and_then(|d| match d {
|
||||
backend::Data::Containers(data) => data.get(0),
|
||||
_ => None,
|
||||
})
|
||||
.and_then(|c| match c {
|
||||
backend::Container::List { data_vec, .. } => data_vec.get(1),
|
||||
_ => None,
|
||||
})
|
||||
.and_then(|d| match d {
|
||||
backend::Data::Mapper { mappings, .. } => Some(mappings),
|
||||
_ => None,
|
||||
})
|
||||
.expect("Failed to get packet ids");
|
||||
|
||||
reversed_packet_ids
|
||||
.into_iter()
|
||||
.map(|(k, v)| {
|
||||
(
|
||||
v.clone(),
|
||||
u8::from_str_radix(k.trim_start_matches("0x"), 16).expect("Invalid packet id"),
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn transform_packets<M: Mappings>(
|
||||
mappings: &M,
|
||||
protocol: &backend::Protocol,
|
||||
packets: &backend::Packets,
|
||||
bound: frontend::Bound,
|
||||
) -> Vec<frontend::Packet> {
|
||||
let packet_ids = get_packet_ids(packets);
|
||||
let mut output_packets = vec![];
|
||||
|
||||
for (unformatted_name, data_vec) in packets.types.iter() {
|
||||
if !unformatted_name.starts_with("packet_")
|
||||
|| unformatted_name == "packet_legacy_server_list_ping"
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
let no_prefix_unformatted = unformatted_name.trim_start_matches("packet_");
|
||||
|
||||
let id = *packet_ids
|
||||
.get(no_prefix_unformatted)
|
||||
.expect("Failed to get packet id");
|
||||
|
||||
let packet_name = mappings.rename_packet(
|
||||
unformatted_name,
|
||||
&no_prefix_unformatted.to_camel_case(),
|
||||
&bound,
|
||||
protocol,
|
||||
);
|
||||
|
||||
let mut fields = vec![];
|
||||
|
||||
for data in data_vec {
|
||||
if let backend::Data::Containers(container_vec) = data {
|
||||
for container in container_vec {
|
||||
match container {
|
||||
backend::Container::Value { name, data } => {
|
||||
match transform_value_field(&name, &data) {
|
||||
Some(field) => {
|
||||
fields.push(mappings.change_field_type(&packet_name, field))
|
||||
}
|
||||
None => println!(
|
||||
"[{}] Field \"{}\" are skipped ({:?}",
|
||||
packet_name, name, data
|
||||
),
|
||||
}
|
||||
}
|
||||
backend::Container::List { name, data_vec } => {
|
||||
if let Some(name) = name {
|
||||
match transform_list_field(&name, data_vec) {
|
||||
Some(field) => {
|
||||
fields.push(mappings.change_field_type(&packet_name, field))
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let packet = frontend::Packet {
|
||||
id,
|
||||
name: packet_name,
|
||||
fields,
|
||||
};
|
||||
|
||||
output_packets.push(packet);
|
||||
}
|
||||
|
||||
output_packets
|
||||
}
|
||||
|
||||
fn transform_value_field(
|
||||
unformatted_field_name: &str,
|
||||
data: &backend::Data,
|
||||
) -> Option<frontend::Field> {
|
||||
match data {
|
||||
backend::Data::Type(name) => match transform_data_type(name) {
|
||||
Some(data_type) => Some(frontend::Field {
|
||||
name: format_field_name(unformatted_field_name),
|
||||
data_type,
|
||||
}),
|
||||
None => None,
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn transform_list_field(
|
||||
unformatted_field_name: &str,
|
||||
data_vec: &Vec<backend::Data>,
|
||||
) -> Option<frontend::Field> {
|
||||
match &data_vec[0] {
|
||||
backend::Data::Type(name) => match name.as_ref() {
|
||||
"buffer" => Some(frontend::Field {
|
||||
name: format_field_name(unformatted_field_name),
|
||||
data_type: frontend::DataType::ByteArray { rest: false },
|
||||
}),
|
||||
"array" => None,
|
||||
"switch" => None,
|
||||
"particleData" => Some(frontend::Field {
|
||||
name: format_field_name(unformatted_field_name),
|
||||
data_type: frontend::DataType::RefType {
|
||||
ref_name: "ParticleData".to_string(),
|
||||
},
|
||||
}),
|
||||
"option" => transform_value_field(unformatted_field_name, &data_vec[1]),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn transform_data_type(name: &str) -> Option<frontend::DataType> {
|
||||
match name {
|
||||
"bool" => Some(frontend::DataType::Boolean),
|
||||
"i8" => Some(frontend::DataType::Byte),
|
||||
"i16" => Some(frontend::DataType::Short),
|
||||
"i32" => Some(frontend::DataType::Int { var_int: false }),
|
||||
"i64" => Some(frontend::DataType::Long { var_long: false }),
|
||||
"u8" => Some(frontend::DataType::UnsignedByte),
|
||||
"u16" => Some(frontend::DataType::UnsignedShort),
|
||||
"u32" => Some(frontend::DataType::UnsignedInt),
|
||||
"f32" => Some(frontend::DataType::Float),
|
||||
"f64" => Some(frontend::DataType::Double),
|
||||
"varint" => Some(frontend::DataType::Int { var_int: true }),
|
||||
"varlong" => Some(frontend::DataType::Long { var_long: true }),
|
||||
"string" => Some(frontend::DataType::String { max_length: 0 }),
|
||||
"nbt" | "optionalNbt" => Some(frontend::DataType::CompoundTag),
|
||||
"UUID" => Some(frontend::DataType::Uuid { hyphenated: false }),
|
||||
"restBuffer" => Some(frontend::DataType::ByteArray { rest: true }),
|
||||
"position" => Some(frontend::DataType::RefType {
|
||||
ref_name: "Position".to_string(),
|
||||
}),
|
||||
"slot" => Some(frontend::DataType::RefType {
|
||||
ref_name: "Option<Slot>".to_string(),
|
||||
}),
|
||||
"entityMetadata" => Some(frontend::DataType::RefType {
|
||||
ref_name: "Metadata".to_string(),
|
||||
}),
|
||||
"tags" => Some(frontend::DataType::RefType {
|
||||
ref_name: "TagsMap".to_string(),
|
||||
}),
|
||||
_ => {
|
||||
println!("Unknown data type \"{}\"", name);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn format_field_name(unformatted_field_name: &str) -> String {
|
||||
if unformatted_field_name == "type" {
|
||||
String::from("type_")
|
||||
} else {
|
||||
unformatted_field_name.to_snake_case()
|
||||
}
|
||||
}
|
24
protocol-generator/templates/packets_structs.hbs
Normal file
24
protocol-generator/templates/packets_structs.hbs
Normal file
@@ -0,0 +1,24 @@
|
||||
{{~#each packets as |p|}}
|
||||
{{~#if p.fields}}
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct {{p.name}} {
|
||||
{{~#each p.fields as |f|}}
|
||||
{{~#if f.var_int}}
|
||||
#[packet(with = "var_int")]{{/if}}
|
||||
{{~#if f.var_long}}
|
||||
#[packet(with = "var_long")]{{/if}}
|
||||
{{~#if f.rest}}
|
||||
#[packet(with = "rest")]{{/if}}
|
||||
{{~#if f.hyphenated}}
|
||||
#[packet(with = "uuid_hyp_str")]{{/if}}
|
||||
{{~#if f.max_length}}
|
||||
#[packet(max_length = {{f.max_length}})]{{/if}}
|
||||
{{~#if (ne f.type "RefType")}}
|
||||
pub {{f.name}}: {{f.type}}{{#unless @last}},{{/unless}}
|
||||
{{~else}}
|
||||
pub {{f.name}}: {{f.ref_name}}{{#unless @last}},{{/unless}}
|
||||
{{~/if}}
|
||||
{{~/each}}
|
||||
}
|
||||
{{/if}}
|
||||
{{~/each}}
|
51
protocol-generator/templates/protocol_enum.hbs
Normal file
51
protocol-generator/templates/protocol_enum.hbs
Normal file
@@ -0,0 +1,51 @@
|
||||
{{~#if packets}}
|
||||
pub enum {{protocol_enum_name}} {
|
||||
{{~#each packets as |p|}}
|
||||
{{p.name}}{{#if p.fields}}({{p.name}}){{/if}},
|
||||
{{~/each}}
|
||||
}
|
||||
|
||||
impl {{protocol_enum_name}} {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
{{~#each packets as |p|}}
|
||||
Self::{{p.name}}{{#if p.fields}}(_){{/if}} => {{packet_id p.id}},
|
||||
{{~/each}}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
{{~#each packets as |p|}}
|
||||
{{packet_id p.id}} => {
|
||||
{{~#if p.fields}}
|
||||
let {{snake_case p.name}} = {{p.name}}::decode(reader)?;
|
||||
|
||||
Ok(Self::{{p.name}}({{snake_case p.name}}))
|
||||
{{~/if}}
|
||||
{{~#unless p.fields}}
|
||||
Ok(Self::{{p.name}})
|
||||
{{~/unless}}
|
||||
}
|
||||
{{~/each}}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id })
|
||||
}
|
||||
}
|
||||
{{#each packets as |p|}}
|
||||
pub fn {{snake_case p.name}}({{~#each p.fields as |f|}}{{f.name}}: {{#if (ne f.type "RefType")}}{{f.type}}{{~else}}{{f.ref_name}}{{/if}}{{#unless @last}}, {{/unless}}{{~/each}}) -> Self {
|
||||
{{~#if p.fields}}
|
||||
let {{snake_case p.name}} = {{p.name}} {
|
||||
{{~#each p.fields as |f|}}
|
||||
{{f.name}},
|
||||
{{~/each}}
|
||||
};
|
||||
|
||||
Self::{{p.name}}({{snake_case p.name}})
|
||||
{{~/if}}
|
||||
{{~#unless p.fields}}
|
||||
Self::{{p.name}}
|
||||
{{~/unless}}
|
||||
}
|
||||
{{/each~}}
|
||||
}
|
||||
{{~/if}}
|
10
protocol-generator/templates/protocol_header.hbs
Normal file
10
protocol-generator/templates/protocol_header.hbs
Normal file
@@ -0,0 +1,10 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use std::io::Read;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
|
||||
{{#each imports as |i|~}}
|
||||
use {{i}};
|
||||
{{/each~}}
|
6
protocol-generator/templates/protocol_module.hbs
Normal file
6
protocol-generator/templates/protocol_module.hbs
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
pub mod handshake;
|
||||
pub mod status;
|
||||
pub mod login;
|
||||
pub mod game;
|
@@ -0,0 +1,6 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
{{#each versions as |v|~}}
|
||||
#[cfg(feature = "{{v}}")]
|
||||
pub mod {{protocol_version_module v}};
|
||||
{{/each~}}
|
@@ -6,7 +6,7 @@
|
||||
//! ## Serialize
|
||||
//!
|
||||
//! ```
|
||||
//! use minecraft_protocol::chat::{Payload, Color, MessageBuilder};
|
||||
//! use minecraft_protocol::data::chat::{Payload, Color, MessageBuilder};
|
||||
//!
|
||||
//! let message = MessageBuilder::builder(Payload::text("Hello"))
|
||||
//! .color(Color::Yellow)
|
||||
@@ -25,7 +25,7 @@
|
||||
//! ## Deserialize
|
||||
//!
|
||||
//! ```
|
||||
//! use minecraft_protocol::chat::{MessageBuilder, Color, Payload, Message};
|
||||
//! use minecraft_protocol::data::chat::{MessageBuilder, Color, Payload, Message};
|
||||
//!
|
||||
//! let json = r#"
|
||||
//! {
|
||||
@@ -93,7 +93,7 @@ pub enum Color {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use minecraft_protocol::chat::Color;
|
||||
/// use minecraft_protocol::data::chat::Color;
|
||||
///
|
||||
/// let color = Color::Hex("#f98aff".into());
|
||||
/// ```
|
||||
@@ -444,7 +444,7 @@ fn test_serialize_text_hello_world() {
|
||||
|
||||
assert_eq!(
|
||||
message.to_json().unwrap(),
|
||||
include_str!("../test/chat/text_hello_world.json")
|
||||
include_str!("../../test/chat/text_hello_world.json")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -463,7 +463,7 @@ fn test_deserialize_text_hello_world() {
|
||||
|
||||
assert_eq!(
|
||||
expected_message,
|
||||
Message::from_json(include_str!("../test/chat/text_hello_world.json")).unwrap()
|
||||
Message::from_json(include_str!("../../test/chat/text_hello_world.json")).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -474,7 +474,7 @@ fn test_serialize_translate_opped_steve() {
|
||||
|
||||
assert_eq!(
|
||||
message.to_json().unwrap(),
|
||||
include_str!("../test/chat/translate_opped_steve.json")
|
||||
include_str!("../../test/chat/translate_opped_steve.json")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -485,7 +485,7 @@ fn test_deserialize_translate_opped_steve() {
|
||||
|
||||
assert_eq!(
|
||||
expected_message,
|
||||
Message::from_json(include_str!("../test/chat/translate_opped_steve.json")).unwrap()
|
||||
Message::from_json(include_str!("../../test/chat/translate_opped_steve.json")).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -503,7 +503,7 @@ fn test_serialize_keybind_jump() {
|
||||
|
||||
assert_eq!(
|
||||
message.to_json().unwrap(),
|
||||
include_str!("../test/chat/keybind_jump.json")
|
||||
include_str!("../../test/chat/keybind_jump.json")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -521,7 +521,7 @@ fn test_deserialize_keybind_jump() {
|
||||
|
||||
assert_eq!(
|
||||
expected_message,
|
||||
Message::from_json(include_str!("../test/chat/keybind_jump.json")).unwrap()
|
||||
Message::from_json(include_str!("../../test/chat/keybind_jump.json")).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -535,7 +535,7 @@ fn test_serialize_click_open_url() {
|
||||
|
||||
assert_eq!(
|
||||
message.to_json().unwrap(),
|
||||
include_str!("../test/chat/click_open_url.json")
|
||||
include_str!("../../test/chat/click_open_url.json")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -549,7 +549,7 @@ fn test_deserialize_click_open_url() {
|
||||
|
||||
assert_eq!(
|
||||
expected_message,
|
||||
Message::from_json(include_str!("../test/chat/click_open_url.json")).unwrap()
|
||||
Message::from_json(include_str!("../../test/chat/click_open_url.json")).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -563,7 +563,7 @@ fn test_serialize_click_run_command() {
|
||||
|
||||
assert_eq!(
|
||||
message.to_json().unwrap(),
|
||||
include_str!("../test/chat/click_run_command.json")
|
||||
include_str!("../../test/chat/click_run_command.json")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -577,7 +577,7 @@ fn test_deserialize_click_run_command() {
|
||||
|
||||
assert_eq!(
|
||||
expected_message,
|
||||
Message::from_json(include_str!("../test/chat/click_run_command.json")).unwrap()
|
||||
Message::from_json(include_str!("../../test/chat/click_run_command.json")).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -591,7 +591,7 @@ fn test_serialize_click_suggest_command() {
|
||||
|
||||
assert_eq!(
|
||||
message.to_json().unwrap(),
|
||||
include_str!("../test/chat/click_suggest_command.json")
|
||||
include_str!("../../test/chat/click_suggest_command.json")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -605,7 +605,7 @@ fn test_deserialize_click_suggest_command() {
|
||||
|
||||
assert_eq!(
|
||||
expected_message,
|
||||
Message::from_json(include_str!("../test/chat/click_suggest_command.json")).unwrap()
|
||||
Message::from_json(include_str!("../../test/chat/click_suggest_command.json")).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -619,7 +619,7 @@ fn test_serialize_click_change_page() {
|
||||
|
||||
assert_eq!(
|
||||
message.to_json().unwrap(),
|
||||
include_str!("../test/chat/click_change_page.json")
|
||||
include_str!("../../test/chat/click_change_page.json")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -633,7 +633,7 @@ fn test_deserialize_click_change_page() {
|
||||
|
||||
assert_eq!(
|
||||
expected_message,
|
||||
Message::from_json(include_str!("../test/chat/click_change_page.json")).unwrap()
|
||||
Message::from_json(include_str!("../../test/chat/click_change_page.json")).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -647,7 +647,7 @@ fn test_serialize_hover_show_text() {
|
||||
|
||||
assert_eq!(
|
||||
message.to_json().unwrap(),
|
||||
include_str!("../test/chat/hover_show_text.json")
|
||||
include_str!("../../test/chat/hover_show_text.json")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -661,7 +661,7 @@ fn test_deserialize_hover_show_text() {
|
||||
|
||||
assert_eq!(
|
||||
expected_message,
|
||||
Message::from_json(include_str!("../test/chat/hover_show_text.json")).unwrap()
|
||||
Message::from_json(include_str!("../../test/chat/hover_show_text.json")).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -675,7 +675,7 @@ fn test_serialize_hover_show_item() {
|
||||
|
||||
assert_eq!(
|
||||
message.to_json().unwrap(),
|
||||
include_str!("../test/chat/hover_show_item.json")
|
||||
include_str!("../../test/chat/hover_show_item.json")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -689,7 +689,7 @@ fn test_deserialize_hover_show_item() {
|
||||
|
||||
assert_eq!(
|
||||
expected_message,
|
||||
Message::from_json(include_str!("../test/chat/hover_show_item.json")).unwrap()
|
||||
Message::from_json(include_str!("../../test/chat/hover_show_item.json")).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -703,7 +703,7 @@ fn test_serialize_hover_show_entity() {
|
||||
|
||||
assert_eq!(
|
||||
message.to_json().unwrap(),
|
||||
include_str!("../test/chat/hover_show_entity.json")
|
||||
include_str!("../../test/chat/hover_show_entity.json")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -717,7 +717,7 @@ fn test_deserialize_hover_show_entity() {
|
||||
|
||||
assert_eq!(
|
||||
expected_message,
|
||||
Message::from_json(include_str!("../test/chat/hover_show_entity.json")).unwrap()
|
||||
Message::from_json(include_str!("../../test/chat/hover_show_entity.json")).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -729,7 +729,7 @@ fn test_serialize_hex_color() {
|
||||
|
||||
assert_eq!(
|
||||
message.to_json().unwrap(),
|
||||
include_str!("../test/chat/hex_color.json")
|
||||
include_str!("../../test/chat/hex_color.json")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -740,7 +740,7 @@ fn test_deserialize_hex_color() {
|
||||
.build();
|
||||
|
||||
assert_eq!(
|
||||
Message::from_json(include_str!("../test/chat/hex_color.json")).unwrap(),
|
||||
Message::from_json(include_str!("../../test/chat/hex_color.json")).unwrap(),
|
||||
expected_message
|
||||
);
|
||||
}
|
2
protocol/src/data/mod.rs
Normal file
2
protocol/src/data/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod chat;
|
||||
pub mod server_status;
|
32
protocol/src/data/server_status.rs
Normal file
32
protocol/src/data/server_status.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use crate::data::chat::Message;
|
||||
use crate::impl_json_encoder_decoder;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ServerVersion {
|
||||
pub name: String,
|
||||
pub protocol: u32,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||
pub struct OnlinePlayer {
|
||||
pub name: String,
|
||||
pub id: Uuid,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct OnlinePlayers {
|
||||
pub max: u32,
|
||||
pub online: u32,
|
||||
pub sample: Vec<OnlinePlayer>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ServerStatus {
|
||||
pub version: ServerVersion,
|
||||
pub players: OnlinePlayers,
|
||||
pub description: Message,
|
||||
}
|
||||
|
||||
impl_json_encoder_decoder!(ServerStatus);
|
106
protocol/src/error.rs
Normal file
106
protocol/src/error.rs
Normal file
@@ -0,0 +1,106 @@
|
||||
use nbt::decode::TagDecodeError;
|
||||
use serde_json::error::Error as JsonError;
|
||||
use std::io::Error as IoError;
|
||||
use std::string::FromUtf8Error;
|
||||
use uuid::parser::ParseError as UuidParseError;
|
||||
|
||||
/// Possible errors while encoding packet.
|
||||
#[derive(Debug)]
|
||||
pub enum EncodeError {
|
||||
/// String length can't be more than provided value.
|
||||
StringTooLong {
|
||||
/// String length.
|
||||
length: usize,
|
||||
/// Max string length.
|
||||
max_length: u16,
|
||||
},
|
||||
IOError {
|
||||
io_error: IoError,
|
||||
},
|
||||
JsonError {
|
||||
json_error: JsonError,
|
||||
},
|
||||
}
|
||||
|
||||
impl From<IoError> for EncodeError {
|
||||
fn from(io_error: IoError) -> Self {
|
||||
EncodeError::IOError { io_error }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<JsonError> for EncodeError {
|
||||
fn from(json_error: JsonError) -> Self {
|
||||
EncodeError::JsonError { json_error }
|
||||
}
|
||||
}
|
||||
|
||||
/// Possible errors while decoding packet.
|
||||
#[derive(Debug)]
|
||||
pub enum DecodeError {
|
||||
/// Packet was not recognized. Invalid data or wrong protocol version.
|
||||
UnknownPacketType {
|
||||
type_id: u8,
|
||||
},
|
||||
/// String length can't be more than provided value.
|
||||
StringTooLong {
|
||||
/// String length.
|
||||
length: usize,
|
||||
/// Max string length.
|
||||
max_length: u16,
|
||||
},
|
||||
IOError {
|
||||
io_error: IoError,
|
||||
},
|
||||
JsonError {
|
||||
json_error: JsonError,
|
||||
},
|
||||
/// Byte array was not recognized as valid UTF-8 string.
|
||||
Utf8Error {
|
||||
utf8_error: FromUtf8Error,
|
||||
},
|
||||
/// Boolean are parsed from byte. Valid byte value are 0 or 1.
|
||||
NonBoolValue,
|
||||
UuidParseError {
|
||||
uuid_parse_error: UuidParseError,
|
||||
},
|
||||
// Type id was not parsed as valid enum value.
|
||||
UnknownEnumType {
|
||||
type_id: u8,
|
||||
},
|
||||
TagDecodeError {
|
||||
tag_decode_error: TagDecodeError,
|
||||
},
|
||||
VarIntTooLong {
|
||||
max_bytes: usize,
|
||||
},
|
||||
}
|
||||
|
||||
impl From<IoError> for DecodeError {
|
||||
fn from(io_error: IoError) -> Self {
|
||||
DecodeError::IOError { io_error }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<JsonError> for DecodeError {
|
||||
fn from(json_error: JsonError) -> Self {
|
||||
DecodeError::JsonError { json_error }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FromUtf8Error> for DecodeError {
|
||||
fn from(utf8_error: FromUtf8Error) -> Self {
|
||||
DecodeError::Utf8Error { utf8_error }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<UuidParseError> for DecodeError {
|
||||
fn from(uuid_parse_error: UuidParseError) -> Self {
|
||||
DecodeError::UuidParseError { uuid_parse_error }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TagDecodeError> for DecodeError {
|
||||
fn from(tag_decode_error: TagDecodeError) -> Self {
|
||||
DecodeError::TagDecodeError { tag_decode_error }
|
||||
}
|
||||
}
|
@@ -1,504 +0,0 @@
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
|
||||
use crate::chat::Message;
|
||||
use crate::impl_enum_encoder_decoder;
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use nbt::CompoundTag;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum GameServerBoundPacket {
|
||||
ServerBoundChatMessage(ServerBoundChatMessage),
|
||||
ServerBoundKeepAlive(ServerBoundKeepAlive),
|
||||
}
|
||||
|
||||
pub enum GameClientBoundPacket {
|
||||
ClientBoundChatMessage(ClientBoundChatMessage),
|
||||
JoinGame(JoinGame),
|
||||
ClientBoundKeepAlive(ClientBoundKeepAlive),
|
||||
ChunkData(ChunkData),
|
||||
GameDisconnect(GameDisconnect),
|
||||
}
|
||||
|
||||
impl GameServerBoundPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
GameServerBoundPacket::ServerBoundChatMessage(_) => 0x03,
|
||||
GameServerBoundPacket::ServerBoundKeepAlive(_) => 0x0F,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x03 => {
|
||||
let chat_message = ServerBoundChatMessage::decode(reader)?;
|
||||
|
||||
Ok(GameServerBoundPacket::ServerBoundChatMessage(chat_message))
|
||||
}
|
||||
0x0F => {
|
||||
let keep_alive = ServerBoundKeepAlive::decode(reader)?;
|
||||
|
||||
Ok(GameServerBoundPacket::ServerBoundKeepAlive(keep_alive))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GameClientBoundPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
GameClientBoundPacket::ClientBoundChatMessage(_) => 0x0E,
|
||||
GameClientBoundPacket::GameDisconnect(_) => 0x1A,
|
||||
GameClientBoundPacket::ClientBoundKeepAlive(_) => 0x20,
|
||||
GameClientBoundPacket::ChunkData(_) => 0x21,
|
||||
GameClientBoundPacket::JoinGame(_) => 0x25,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x0E => {
|
||||
let chat_message = ClientBoundChatMessage::decode(reader)?;
|
||||
|
||||
Ok(GameClientBoundPacket::ClientBoundChatMessage(chat_message))
|
||||
}
|
||||
0x1A => {
|
||||
let game_disconnect = GameDisconnect::decode(reader)?;
|
||||
|
||||
Ok(GameClientBoundPacket::GameDisconnect(game_disconnect))
|
||||
}
|
||||
0x20 => {
|
||||
let keep_alive = ClientBoundKeepAlive::decode(reader)?;
|
||||
|
||||
Ok(GameClientBoundPacket::ClientBoundKeepAlive(keep_alive))
|
||||
}
|
||||
0x21 => {
|
||||
let chunk_data = ChunkData::decode(reader)?;
|
||||
|
||||
Ok(GameClientBoundPacket::ChunkData(chunk_data))
|
||||
}
|
||||
0x25 => {
|
||||
let join_game = JoinGame::decode(reader)?;
|
||||
|
||||
Ok(GameClientBoundPacket::JoinGame(join_game))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct ServerBoundChatMessage {
|
||||
#[packet(max_length = 256)]
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
impl ServerBoundChatMessage {
|
||||
pub fn new(message: String) -> GameServerBoundPacket {
|
||||
let chat_message = ServerBoundChatMessage { message };
|
||||
|
||||
GameServerBoundPacket::ServerBoundChatMessage(chat_message)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct ClientBoundChatMessage {
|
||||
pub message: Message,
|
||||
pub position: MessagePosition,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, FromPrimitive, ToPrimitive)]
|
||||
pub enum MessagePosition {
|
||||
Chat,
|
||||
System,
|
||||
HotBar,
|
||||
}
|
||||
|
||||
impl_enum_encoder_decoder!(MessagePosition);
|
||||
|
||||
impl ClientBoundChatMessage {
|
||||
pub fn new(message: Message, position: MessagePosition) -> GameClientBoundPacket {
|
||||
let chat_message = ClientBoundChatMessage { message, position };
|
||||
|
||||
GameClientBoundPacket::ClientBoundChatMessage(chat_message)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct JoinGame {
|
||||
pub entity_id: u32,
|
||||
pub game_mode: GameMode,
|
||||
pub dimension: i32,
|
||||
pub max_players: u8,
|
||||
#[packet(max_length = 16)]
|
||||
pub level_type: String,
|
||||
#[packet(with = "var_int")]
|
||||
pub view_distance: i32,
|
||||
pub reduced_debug_info: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, FromPrimitive, ToPrimitive)]
|
||||
pub enum GameMode {
|
||||
Survival = 0,
|
||||
Creative = 1,
|
||||
Adventure = 2,
|
||||
Spectator = 3,
|
||||
Hardcore = 8,
|
||||
}
|
||||
|
||||
impl_enum_encoder_decoder!(GameMode);
|
||||
|
||||
impl JoinGame {
|
||||
pub fn new(
|
||||
entity_id: u32,
|
||||
game_mode: GameMode,
|
||||
dimension: i32,
|
||||
max_players: u8,
|
||||
level_type: String,
|
||||
view_distance: i32,
|
||||
reduced_debug_info: bool,
|
||||
) -> GameClientBoundPacket {
|
||||
let join_game = JoinGame {
|
||||
entity_id,
|
||||
game_mode,
|
||||
dimension,
|
||||
max_players,
|
||||
level_type,
|
||||
view_distance,
|
||||
reduced_debug_info,
|
||||
};
|
||||
|
||||
GameClientBoundPacket::JoinGame(join_game)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet)]
|
||||
pub struct ServerBoundKeepAlive {
|
||||
pub id: u64,
|
||||
}
|
||||
|
||||
impl ServerBoundKeepAlive {
|
||||
pub fn new(id: u64) -> GameServerBoundPacket {
|
||||
let keep_alive = ServerBoundKeepAlive { id };
|
||||
|
||||
GameServerBoundPacket::ServerBoundKeepAlive(keep_alive)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet)]
|
||||
pub struct ClientBoundKeepAlive {
|
||||
pub id: u64,
|
||||
}
|
||||
|
||||
impl ClientBoundKeepAlive {
|
||||
pub fn new(id: u64) -> GameClientBoundPacket {
|
||||
let keep_alive = ClientBoundKeepAlive { id };
|
||||
|
||||
GameClientBoundPacket::ClientBoundKeepAlive(keep_alive)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct ChunkData {
|
||||
pub x: i32,
|
||||
pub z: i32,
|
||||
pub full: bool,
|
||||
#[packet(with = "var_int")]
|
||||
pub primary_mask: i32,
|
||||
pub heights: CompoundTag,
|
||||
pub data: Vec<u8>,
|
||||
pub tiles: Vec<CompoundTag>,
|
||||
}
|
||||
|
||||
impl ChunkData {
|
||||
pub fn new(
|
||||
x: i32,
|
||||
z: i32,
|
||||
full: bool,
|
||||
primary_mask: i32,
|
||||
heights: CompoundTag,
|
||||
data: Vec<u8>,
|
||||
tiles: Vec<CompoundTag>,
|
||||
) -> GameClientBoundPacket {
|
||||
let chunk_data = ChunkData {
|
||||
x,
|
||||
z,
|
||||
full,
|
||||
primary_mask,
|
||||
heights,
|
||||
data,
|
||||
tiles,
|
||||
};
|
||||
|
||||
GameClientBoundPacket::ChunkData(chunk_data)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct GameDisconnect {
|
||||
pub reason: Message,
|
||||
}
|
||||
|
||||
impl GameDisconnect {
|
||||
pub fn new(reason: Message) -> GameClientBoundPacket {
|
||||
let game_disconnect = GameDisconnect { reason };
|
||||
|
||||
GameClientBoundPacket::GameDisconnect(game_disconnect)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::chat::{Message, Payload};
|
||||
use crate::game::{
|
||||
ChunkData, ClientBoundChatMessage, ClientBoundKeepAlive, GameDisconnect, GameMode,
|
||||
JoinGame, MessagePosition, ServerBoundChatMessage, ServerBoundKeepAlive,
|
||||
};
|
||||
use crate::{DecodeError, Encoder, EncoderWriteExt, STRING_MAX_LENGTH};
|
||||
use crate::{Decoder, EncodeError};
|
||||
use nbt::CompoundTag;
|
||||
use std::io::Cursor;
|
||||
|
||||
#[test]
|
||||
fn test_server_bound_chat_message_encode() {
|
||||
let chat_message = ServerBoundChatMessage {
|
||||
message: String::from("hello server!"),
|
||||
};
|
||||
|
||||
let mut vec = Vec::new();
|
||||
chat_message.encode(&mut vec).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
vec,
|
||||
include_bytes!("../test/packet/game/server_bound_chat_message.dat").to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_server_bound_chat_message_decode() {
|
||||
let mut cursor = Cursor::new(
|
||||
include_bytes!("../test/packet/game/server_bound_chat_message.dat").to_vec(),
|
||||
);
|
||||
let chat_message = ServerBoundChatMessage::decode(&mut cursor).unwrap();
|
||||
|
||||
assert_eq!(chat_message.message, "hello server!");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_server_bound_chat_message_encode_invalid_length() {
|
||||
let chat_message = ServerBoundChatMessage {
|
||||
message: "abc".repeat(100),
|
||||
};
|
||||
|
||||
let mut vec = Vec::new();
|
||||
|
||||
let encode_error = chat_message
|
||||
.encode(&mut vec)
|
||||
.err()
|
||||
.expect("Expected error `StringTooLong` because message has invalid length");
|
||||
|
||||
match encode_error {
|
||||
EncodeError::StringTooLong { length, max_length } => {
|
||||
assert_eq!(length, 300);
|
||||
assert_eq!(max_length, 256);
|
||||
}
|
||||
_ => panic!("Expected `StringTooLong` but got `{:?}`", encode_error),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_server_bound_chat_message_decode_invalid_length() {
|
||||
let message = "abc".repeat(100);
|
||||
|
||||
let mut vec = Vec::new();
|
||||
vec.write_string(&message, STRING_MAX_LENGTH).unwrap();
|
||||
|
||||
let mut cursor = Cursor::new(vec);
|
||||
|
||||
let decode_error = ServerBoundChatMessage::decode(&mut cursor)
|
||||
.err()
|
||||
.expect("Expected error `StringTooLong` because message has invalid length");
|
||||
|
||||
match decode_error {
|
||||
DecodeError::StringTooLong { length, max_length } => {
|
||||
assert_eq!(length, 300);
|
||||
assert_eq!(max_length, 256);
|
||||
}
|
||||
_ => panic!("Expected `StringTooLong` but got `{:?}`", decode_error),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_client_bound_chat_message_encode() {
|
||||
let chat_message = ClientBoundChatMessage {
|
||||
message: Message::new(Payload::text("hello client!")),
|
||||
position: MessagePosition::System,
|
||||
};
|
||||
|
||||
let mut vec = Vec::new();
|
||||
chat_message.encode(&mut vec).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
vec,
|
||||
include_bytes!("../test/packet/game/client_bound_chat_message.dat").to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_client_bound_chat_message_decode() {
|
||||
let mut cursor = Cursor::new(
|
||||
include_bytes!("../test/packet/game/client_bound_chat_message.dat").to_vec(),
|
||||
);
|
||||
let chat_message = ClientBoundChatMessage::decode(&mut cursor).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
chat_message.message,
|
||||
Message::new(Payload::text("hello client!"))
|
||||
);
|
||||
|
||||
assert_eq!(chat_message.position, MessagePosition::System);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_server_bound_keep_alive_encode() {
|
||||
let keep_alive = ServerBoundKeepAlive { id: 31122019 };
|
||||
|
||||
let mut vec = Vec::new();
|
||||
keep_alive.encode(&mut vec).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
vec,
|
||||
include_bytes!("../test/packet/game/server_bound_keep_alive.dat").to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_server_bound_keep_alive_decode() {
|
||||
let mut cursor =
|
||||
Cursor::new(include_bytes!("../test/packet/game/server_bound_keep_alive.dat").to_vec());
|
||||
let keep_alive = ServerBoundKeepAlive::decode(&mut cursor).unwrap();
|
||||
|
||||
assert_eq!(keep_alive.id, 31122019);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_client_bound_keep_alive_encode() {
|
||||
let keep_alive = ClientBoundKeepAlive { id: 240714 };
|
||||
|
||||
let mut vec = Vec::new();
|
||||
keep_alive.encode(&mut vec).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
vec,
|
||||
include_bytes!("../test/packet/game/client_bound_keep_alive.dat").to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_client_bound_keep_alive_decode() {
|
||||
let mut cursor =
|
||||
Cursor::new(include_bytes!("../test/packet/game/client_bound_keep_alive.dat").to_vec());
|
||||
let keep_alive = ClientBoundKeepAlive::decode(&mut cursor).unwrap();
|
||||
|
||||
assert_eq!(keep_alive.id, 240714);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_join_game_encode() {
|
||||
let join_game = JoinGame {
|
||||
entity_id: 27,
|
||||
game_mode: GameMode::Spectator,
|
||||
dimension: 23,
|
||||
max_players: 100,
|
||||
level_type: String::from("default"),
|
||||
view_distance: 10,
|
||||
reduced_debug_info: true,
|
||||
};
|
||||
|
||||
let mut vec = Vec::new();
|
||||
join_game.encode(&mut vec).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
vec,
|
||||
include_bytes!("../test/packet/game/join_game.dat").to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_join_game_decode() {
|
||||
let mut cursor = Cursor::new(include_bytes!("../test/packet/game/join_game.dat").to_vec());
|
||||
let join_game = JoinGame::decode(&mut cursor).unwrap();
|
||||
|
||||
assert_eq!(join_game.entity_id, 27);
|
||||
assert_eq!(join_game.game_mode, GameMode::Spectator);
|
||||
assert_eq!(join_game.dimension, 23);
|
||||
assert_eq!(join_game.max_players, 100);
|
||||
assert_eq!(join_game.level_type, String::from("default"));
|
||||
assert_eq!(join_game.view_distance, 10);
|
||||
assert!(join_game.reduced_debug_info);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_chunk_data_encode() {
|
||||
let chunk_data = ChunkData {
|
||||
x: -2,
|
||||
z: 5,
|
||||
full: true,
|
||||
primary_mask: 65535,
|
||||
heights: CompoundTag::named("HeightMaps"),
|
||||
data: vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
tiles: vec![CompoundTag::named("TileEntity")],
|
||||
};
|
||||
|
||||
let mut vec = Vec::new();
|
||||
chunk_data.encode(&mut vec).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
vec,
|
||||
include_bytes!("../test/packet/game/chunk_data.dat").to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_chunk_data_decode() {
|
||||
let mut cursor = Cursor::new(include_bytes!("../test/packet/game/chunk_data.dat").to_vec());
|
||||
let chunk_data = ChunkData::decode(&mut cursor).unwrap();
|
||||
|
||||
assert_eq!(chunk_data.x, -2);
|
||||
assert_eq!(chunk_data.z, 5);
|
||||
assert!(chunk_data.full);
|
||||
assert_eq!(chunk_data.heights.name, Some(String::from("HeightMaps")));
|
||||
assert_eq!(chunk_data.data, vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
||||
assert_eq!(chunk_data.primary_mask, 65535);
|
||||
assert_eq!(chunk_data.tiles[0].name, Some(String::from("TileEntity")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_game_disconnect_encode() {
|
||||
let game_disconnect = GameDisconnect {
|
||||
reason: Message::new(Payload::text("Message")),
|
||||
};
|
||||
|
||||
let mut vec = Vec::new();
|
||||
game_disconnect.encode(&mut vec).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
vec,
|
||||
include_bytes!("../test/packet/game/game_disconnect.dat").to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_game_disconnect_decode() {
|
||||
let mut cursor =
|
||||
Cursor::new(include_bytes!("../test/packet/game/game_disconnect.dat").to_vec());
|
||||
let game_disconnect = GameDisconnect::decode(&mut cursor).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
game_disconnect.reason,
|
||||
Message::new(Payload::text("Message"))
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,25 +1,20 @@
|
||||
//! This crate implements Minecraft protocol.
|
||||
//!
|
||||
//! Information about protocol can be found at https://wiki.vg/Protocol.
|
||||
use io::Error as IoError;
|
||||
use std::io;
|
||||
use std::io::{Cursor, Read, Write};
|
||||
use std::string::FromUtf8Error;
|
||||
|
||||
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
|
||||
use serde_json::error::Error as JsonError;
|
||||
use uuid::parser::ParseError as UuidParseError;
|
||||
|
||||
use crate::chat::Message;
|
||||
use nbt::decode::TagDecodeError;
|
||||
use nbt::CompoundTag;
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
use uuid::Uuid;
|
||||
|
||||
pub mod chat;
|
||||
pub mod game;
|
||||
pub mod login;
|
||||
pub mod status;
|
||||
use data::chat::Message;
|
||||
|
||||
use crate::error::{DecodeError, EncodeError};
|
||||
|
||||
pub mod data;
|
||||
pub mod error;
|
||||
pub mod version;
|
||||
|
||||
/// Current supported protocol version.
|
||||
pub const PROTOCOL_VERSION: u32 = 498;
|
||||
@@ -27,107 +22,6 @@ pub const PROTOCOL_VERSION: u32 = 498;
|
||||
const STRING_MAX_LENGTH: u16 = 32_768;
|
||||
const HYPHENATED_UUID_LENGTH: u16 = 36;
|
||||
|
||||
/// Possible errors while encoding packet.
|
||||
#[derive(Debug)]
|
||||
pub enum EncodeError {
|
||||
/// String length can't be more than provided value.
|
||||
StringTooLong {
|
||||
/// String length.
|
||||
length: usize,
|
||||
/// Max string length.
|
||||
max_length: u16,
|
||||
},
|
||||
IOError {
|
||||
io_error: IoError,
|
||||
},
|
||||
JsonError {
|
||||
json_error: JsonError,
|
||||
},
|
||||
}
|
||||
|
||||
impl From<IoError> for EncodeError {
|
||||
fn from(io_error: IoError) -> Self {
|
||||
EncodeError::IOError { io_error }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<JsonError> for EncodeError {
|
||||
fn from(json_error: JsonError) -> Self {
|
||||
EncodeError::JsonError { json_error }
|
||||
}
|
||||
}
|
||||
|
||||
/// Possible errors while decoding packet.
|
||||
#[derive(Debug)]
|
||||
pub enum DecodeError {
|
||||
/// Packet was not recognized. Invalid data or wrong protocol version.
|
||||
UnknownPacketType {
|
||||
type_id: u8,
|
||||
},
|
||||
/// String length can't be more than provided value.
|
||||
StringTooLong {
|
||||
/// String length.
|
||||
length: usize,
|
||||
/// Max string length.
|
||||
max_length: u16,
|
||||
},
|
||||
IOError {
|
||||
io_error: IoError,
|
||||
},
|
||||
JsonError {
|
||||
json_error: JsonError,
|
||||
},
|
||||
/// Byte array was not recognized as valid UTF-8 string.
|
||||
Utf8Error {
|
||||
utf8_error: FromUtf8Error,
|
||||
},
|
||||
/// Boolean are parsed from byte. Valid byte value are 0 or 1.
|
||||
NonBoolValue,
|
||||
UuidParseError {
|
||||
uuid_parse_error: UuidParseError,
|
||||
},
|
||||
// Type id was not parsed as valid enum value.
|
||||
UnknownEnumType {
|
||||
type_id: u8,
|
||||
},
|
||||
TagDecodeError {
|
||||
tag_decode_error: TagDecodeError,
|
||||
},
|
||||
VarIntTooLong {
|
||||
max_bytes: usize,
|
||||
},
|
||||
}
|
||||
|
||||
impl From<IoError> for DecodeError {
|
||||
fn from(io_error: IoError) -> Self {
|
||||
DecodeError::IOError { io_error }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<JsonError> for DecodeError {
|
||||
fn from(json_error: JsonError) -> Self {
|
||||
DecodeError::JsonError { json_error }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FromUtf8Error> for DecodeError {
|
||||
fn from(utf8_error: FromUtf8Error) -> Self {
|
||||
DecodeError::Utf8Error { utf8_error }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<UuidParseError> for DecodeError {
|
||||
fn from(uuid_parse_error: UuidParseError) -> Self {
|
||||
DecodeError::UuidParseError { uuid_parse_error }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TagDecodeError> for DecodeError {
|
||||
fn from(tag_decode_error: TagDecodeError) -> Self {
|
||||
DecodeError::TagDecodeError { tag_decode_error }
|
||||
}
|
||||
}
|
||||
|
||||
trait Encoder {
|
||||
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError>;
|
||||
}
|
||||
@@ -331,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)?)
|
||||
@@ -345,6 +253,34 @@ 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)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl Decoder for u16 {
|
||||
type Output = Self;
|
||||
|
||||
fn decode<R: Read>(reader: &mut R) -> Result<Self::Output, DecodeError> {
|
||||
Ok(reader.read_u16::<BigEndian>()?)
|
||||
}
|
||||
}
|
||||
|
||||
impl Encoder for i32 {
|
||||
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
|
||||
Ok(writer.write_i32::<BigEndian>(*self)?)
|
||||
@@ -429,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)?)
|
||||
@@ -546,9 +510,10 @@ macro_rules! impl_json_encoder_decoder (
|
||||
);
|
||||
|
||||
mod var_int {
|
||||
use std::io::{Read, Write};
|
||||
|
||||
use crate::{DecodeError, EncodeError};
|
||||
use crate::{DecoderReadExt, EncoderWriteExt};
|
||||
use std::io::{Read, Write};
|
||||
|
||||
pub fn encode<W: Write>(value: &i32, writer: &mut W) -> Result<(), EncodeError> {
|
||||
writer.write_var_i32(*value)?;
|
||||
@@ -562,9 +527,10 @@ mod var_int {
|
||||
}
|
||||
|
||||
mod var_long {
|
||||
use std::io::{Read, Write};
|
||||
|
||||
use crate::{DecodeError, EncodeError};
|
||||
use crate::{DecoderReadExt, EncoderWriteExt};
|
||||
use std::io::{Read, Write};
|
||||
|
||||
pub fn encode<W: Write>(value: &i64, writer: &mut W) -> Result<(), EncodeError> {
|
||||
writer.write_var_i64(*value)?;
|
||||
@@ -578,9 +544,10 @@ mod var_long {
|
||||
}
|
||||
|
||||
mod rest {
|
||||
use crate::{DecodeError, EncodeError};
|
||||
use std::io::{Read, Write};
|
||||
|
||||
use crate::{DecodeError, EncodeError};
|
||||
|
||||
pub fn encode<W: Write>(value: &[u8], writer: &mut W) -> Result<(), EncodeError> {
|
||||
writer.write_all(value)?;
|
||||
|
||||
@@ -596,11 +563,14 @@ mod rest {
|
||||
}
|
||||
|
||||
mod uuid_hyp_str {
|
||||
use std::io::Cursor;
|
||||
use std::io::{Read, Write};
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
DecodeError, DecoderReadExt, EncodeError, EncoderWriteExt, HYPHENATED_UUID_LENGTH,
|
||||
};
|
||||
use std::io::{Read, Write};
|
||||
use uuid::Uuid;
|
||||
|
||||
pub fn encode<W: Write>(value: &Uuid, writer: &mut W) -> Result<(), EncodeError> {
|
||||
let uuid_hyphenated_string = value.to_hyphenated().to_string();
|
||||
|
@@ -1,479 +0,0 @@
|
||||
use crate::chat::Message;
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use std::io::Read;
|
||||
use uuid::Uuid;
|
||||
|
||||
use minecraft_protocol_derive::Packet;
|
||||
|
||||
pub enum LoginServerBoundPacket {
|
||||
LoginStart(LoginStart),
|
||||
EncryptionResponse(EncryptionResponse),
|
||||
LoginPluginResponse(LoginPluginResponse),
|
||||
}
|
||||
|
||||
pub enum LoginClientBoundPacket {
|
||||
LoginDisconnect(LoginDisconnect),
|
||||
EncryptionRequest(EncryptionRequest),
|
||||
LoginSuccess(LoginSuccess),
|
||||
SetCompression(SetCompression),
|
||||
LoginPluginRequest(LoginPluginRequest),
|
||||
}
|
||||
|
||||
impl LoginServerBoundPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
LoginServerBoundPacket::LoginStart(_) => 0x00,
|
||||
LoginServerBoundPacket::EncryptionResponse(_) => 0x01,
|
||||
LoginServerBoundPacket::LoginPluginResponse(_) => 0x02,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let login_start = LoginStart::decode(reader)?;
|
||||
|
||||
Ok(LoginServerBoundPacket::LoginStart(login_start))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_response = EncryptionResponse::decode(reader)?;
|
||||
|
||||
Ok(LoginServerBoundPacket::EncryptionResponse(
|
||||
encryption_response,
|
||||
))
|
||||
}
|
||||
0x02 => {
|
||||
let login_plugin_response = LoginPluginResponse::decode(reader)?;
|
||||
|
||||
Ok(LoginServerBoundPacket::LoginPluginResponse(
|
||||
login_plugin_response,
|
||||
))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LoginClientBoundPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
LoginClientBoundPacket::LoginDisconnect(_) => 0x00,
|
||||
LoginClientBoundPacket::EncryptionRequest(_) => 0x01,
|
||||
LoginClientBoundPacket::LoginSuccess(_) => 0x02,
|
||||
LoginClientBoundPacket::SetCompression(_) => 0x03,
|
||||
LoginClientBoundPacket::LoginPluginRequest(_) => 0x04,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let login_disconnect = LoginDisconnect::decode(reader)?;
|
||||
|
||||
Ok(LoginClientBoundPacket::LoginDisconnect(login_disconnect))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_request = EncryptionRequest::decode(reader)?;
|
||||
|
||||
Ok(LoginClientBoundPacket::EncryptionRequest(
|
||||
encryption_request,
|
||||
))
|
||||
}
|
||||
0x02 => {
|
||||
let login_success = LoginSuccess::decode(reader)?;
|
||||
|
||||
Ok(LoginClientBoundPacket::LoginSuccess(login_success))
|
||||
}
|
||||
0x03 => {
|
||||
let set_compression = SetCompression::decode(reader)?;
|
||||
|
||||
Ok(LoginClientBoundPacket::SetCompression(set_compression))
|
||||
}
|
||||
0x04 => {
|
||||
let login_plugin_request = LoginPluginRequest::decode(reader)?;
|
||||
|
||||
Ok(LoginClientBoundPacket::LoginPluginRequest(
|
||||
login_plugin_request,
|
||||
))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginStart {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
impl LoginStart {
|
||||
pub fn new(name: String) -> LoginServerBoundPacket {
|
||||
let login_start = LoginStart { name };
|
||||
|
||||
LoginServerBoundPacket::LoginStart(login_start)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionResponse {
|
||||
pub shared_secret: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
impl EncryptionResponse {
|
||||
pub fn new(shared_secret: Vec<u8>, verify_token: Vec<u8>) -> LoginServerBoundPacket {
|
||||
let encryption_response = EncryptionResponse {
|
||||
shared_secret,
|
||||
verify_token,
|
||||
};
|
||||
|
||||
LoginServerBoundPacket::EncryptionResponse(encryption_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginPluginResponse {
|
||||
#[packet(with = "var_int")]
|
||||
pub message_id: i32,
|
||||
pub successful: bool,
|
||||
#[packet(with = "rest")]
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl LoginPluginResponse {
|
||||
pub fn new(message_id: i32, successful: bool, data: Vec<u8>) -> LoginServerBoundPacket {
|
||||
let login_plugin_response = LoginPluginResponse {
|
||||
message_id,
|
||||
successful,
|
||||
data,
|
||||
};
|
||||
|
||||
LoginServerBoundPacket::LoginPluginResponse(login_plugin_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginDisconnect {
|
||||
pub reason: Message,
|
||||
}
|
||||
|
||||
impl LoginDisconnect {
|
||||
pub fn new(reason: Message) -> LoginClientBoundPacket {
|
||||
let login_disconnect = LoginDisconnect { reason };
|
||||
|
||||
LoginClientBoundPacket::LoginDisconnect(login_disconnect)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionRequest {
|
||||
#[packet(max_length = 20)]
|
||||
pub server_id: String,
|
||||
pub public_key: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
impl EncryptionRequest {
|
||||
pub fn new(
|
||||
server_id: String,
|
||||
public_key: Vec<u8>,
|
||||
verify_token: Vec<u8>,
|
||||
) -> LoginClientBoundPacket {
|
||||
let encryption_request = EncryptionRequest {
|
||||
server_id,
|
||||
public_key,
|
||||
verify_token,
|
||||
};
|
||||
|
||||
LoginClientBoundPacket::EncryptionRequest(encryption_request)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginSuccess {
|
||||
#[packet(with = "uuid_hyp_str")]
|
||||
pub uuid: Uuid,
|
||||
#[packet(max_length = 16)]
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
impl LoginSuccess {
|
||||
pub fn new(uuid: Uuid, username: String) -> LoginClientBoundPacket {
|
||||
let login_success = LoginSuccess { uuid, username };
|
||||
|
||||
LoginClientBoundPacket::LoginSuccess(login_success)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct SetCompression {
|
||||
#[packet(with = "var_int")]
|
||||
pub threshold: i32,
|
||||
}
|
||||
|
||||
impl SetCompression {
|
||||
pub fn new(threshold: i32) -> LoginClientBoundPacket {
|
||||
let set_compression = SetCompression { threshold };
|
||||
|
||||
LoginClientBoundPacket::SetCompression(set_compression)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginPluginRequest {
|
||||
#[packet(with = "var_int")]
|
||||
pub message_id: i32,
|
||||
pub channel: String,
|
||||
#[packet(with = "rest")]
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl LoginPluginRequest {
|
||||
pub fn new(message_id: i32, channel: String, data: Vec<u8>) -> LoginClientBoundPacket {
|
||||
let login_plugin_request = LoginPluginRequest {
|
||||
message_id,
|
||||
channel,
|
||||
data,
|
||||
};
|
||||
|
||||
LoginClientBoundPacket::LoginPluginRequest(login_plugin_request)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::chat::{Message, Payload};
|
||||
use crate::login::{EncryptionRequest, LoginDisconnect, LoginPluginRequest, SetCompression};
|
||||
use crate::login::{EncryptionResponse, LoginPluginResponse};
|
||||
use crate::login::{LoginStart, LoginSuccess};
|
||||
use crate::Decoder;
|
||||
use crate::Encoder;
|
||||
use std::io::Cursor;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[test]
|
||||
fn test_login_start_packet_encode() {
|
||||
let login_start = LoginStart {
|
||||
name: String::from("Username"),
|
||||
};
|
||||
|
||||
let mut vec = Vec::new();
|
||||
login_start.encode(&mut vec).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
vec,
|
||||
include_bytes!("../test/packet/login/login_start.dat").to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_login_start_packet_decode() {
|
||||
let mut cursor =
|
||||
Cursor::new(include_bytes!("../test/packet/login/login_start.dat").to_vec());
|
||||
let login_start = LoginStart::decode(&mut cursor).unwrap();
|
||||
|
||||
assert_eq!(login_start.name, String::from("Username"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_encryption_response_encode() {
|
||||
let encryption_response = EncryptionResponse {
|
||||
shared_secret: vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
verify_token: vec![1, 2, 3, 4],
|
||||
};
|
||||
|
||||
let mut vec = Vec::new();
|
||||
encryption_response.encode(&mut vec).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
vec,
|
||||
include_bytes!("../test/packet/login/encryption_response.dat").to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_encryption_response_decode() {
|
||||
let mut cursor =
|
||||
Cursor::new(include_bytes!("../test/packet/login/encryption_response.dat").to_vec());
|
||||
let encryption_response = EncryptionResponse::decode(&mut cursor).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
encryption_response.shared_secret,
|
||||
vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
);
|
||||
assert_eq!(encryption_response.verify_token, vec![1, 2, 3, 4]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_login_plugin_response_encode() {
|
||||
let login_plugin_response = LoginPluginResponse {
|
||||
message_id: 55,
|
||||
successful: true,
|
||||
data: vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
};
|
||||
|
||||
let mut vec = Vec::new();
|
||||
login_plugin_response.encode(&mut vec).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
vec,
|
||||
include_bytes!("../test/packet/login/login_plugin_response.dat").to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_login_plugin_response_decode() {
|
||||
let mut cursor =
|
||||
Cursor::new(include_bytes!("../test/packet/login/login_plugin_response.dat").to_vec());
|
||||
let login_plugin_response = LoginPluginResponse::decode(&mut cursor).unwrap();
|
||||
|
||||
assert_eq!(login_plugin_response.message_id, 55);
|
||||
assert!(login_plugin_response.successful);
|
||||
assert_eq!(
|
||||
login_plugin_response.data,
|
||||
vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_login_disconnect_encode() {
|
||||
let login_disconnect = LoginDisconnect {
|
||||
reason: Message::new(Payload::text("Message")),
|
||||
};
|
||||
|
||||
let mut vec = Vec::new();
|
||||
login_disconnect.encode(&mut vec).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
vec,
|
||||
include_bytes!("../test/packet/login/login_disconnect.dat").to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_login_disconnect_decode() {
|
||||
let mut cursor =
|
||||
Cursor::new(include_bytes!("../test/packet/login/login_disconnect.dat").to_vec());
|
||||
let login_disconnect = LoginDisconnect::decode(&mut cursor).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
login_disconnect.reason,
|
||||
Message::new(Payload::text("Message"))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_encryption_request_encode() {
|
||||
let encryption_request = EncryptionRequest {
|
||||
server_id: String::from("ServerID"),
|
||||
public_key: vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
verify_token: vec![1, 2, 3, 4],
|
||||
};
|
||||
|
||||
let mut vec = Vec::new();
|
||||
encryption_request.encode(&mut vec).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
vec,
|
||||
include_bytes!("../test/packet/login/encryption_request.dat").to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_encryption_request_decode() {
|
||||
let mut cursor =
|
||||
Cursor::new(include_bytes!("../test/packet/login/encryption_request.dat").to_vec());
|
||||
let encryption_request = EncryptionRequest::decode(&mut cursor).unwrap();
|
||||
|
||||
assert_eq!(encryption_request.server_id, String::from("ServerID"));
|
||||
assert_eq!(
|
||||
encryption_request.public_key,
|
||||
vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
);
|
||||
assert_eq!(encryption_request.verify_token, vec![1, 2, 3, 4]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_login_success_encode() {
|
||||
let login_success = LoginSuccess {
|
||||
uuid: Uuid::parse_str("35ee313b-d89a-41b8-b25e-d32e8aff0389").unwrap(),
|
||||
username: String::from("Username"),
|
||||
};
|
||||
|
||||
let mut vec = Vec::new();
|
||||
login_success.encode(&mut vec).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
vec,
|
||||
include_bytes!("../test/packet/login/login_success.dat").to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_login_success_decode() {
|
||||
let mut cursor =
|
||||
Cursor::new(include_bytes!("../test/packet/login/login_success.dat").to_vec());
|
||||
let login_success = LoginSuccess::decode(&mut cursor).unwrap();
|
||||
|
||||
assert_eq!(login_success.username, String::from("Username"));
|
||||
|
||||
assert_eq!(
|
||||
login_success.uuid,
|
||||
Uuid::parse_str("35ee313b-d89a-41b8-b25e-d32e8aff0389").unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_compression_encode() {
|
||||
let set_compression = SetCompression { threshold: 1 };
|
||||
|
||||
let mut vec = Vec::new();
|
||||
set_compression.encode(&mut vec).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
vec,
|
||||
include_bytes!("../test/packet/login/login_set_compression.dat").to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_compression_decode() {
|
||||
let mut cursor =
|
||||
Cursor::new(include_bytes!("../test/packet/login/login_set_compression.dat").to_vec());
|
||||
let set_compression = SetCompression::decode(&mut cursor).unwrap();
|
||||
|
||||
assert_eq!(set_compression.threshold, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_login_plugin_request_encode() {
|
||||
let login_plugin_request = LoginPluginRequest {
|
||||
message_id: 55,
|
||||
channel: String::from("Channel"),
|
||||
data: vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
};
|
||||
|
||||
let mut vec = Vec::new();
|
||||
login_plugin_request.encode(&mut vec).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
vec,
|
||||
include_bytes!("../test/packet/login/login_plugin_request.dat").to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_login_plugin_request_decode() {
|
||||
let mut cursor =
|
||||
Cursor::new(include_bytes!("../test/packet/login/login_plugin_request.dat").to_vec());
|
||||
let login_plugin_request = LoginPluginRequest::decode(&mut cursor).unwrap();
|
||||
|
||||
assert_eq!(login_plugin_request.message_id, 55);
|
||||
assert_eq!(login_plugin_request.channel, String::from("Channel"));
|
||||
assert_eq!(
|
||||
login_plugin_request.data,
|
||||
vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,235 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::chat::Message;
|
||||
use crate::impl_json_encoder_decoder;
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum StatusServerBoundPacket {
|
||||
StatusRequest,
|
||||
PingRequest(PingRequest),
|
||||
}
|
||||
|
||||
pub enum StatusClientBoundPacket {
|
||||
StatusResponse(StatusResponse),
|
||||
PingResponse(PingResponse),
|
||||
}
|
||||
|
||||
impl StatusServerBoundPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
StatusServerBoundPacket::StatusRequest => 0x00,
|
||||
StatusServerBoundPacket::PingRequest(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => Ok(StatusServerBoundPacket::StatusRequest),
|
||||
0x01 => {
|
||||
let ping_request = PingRequest::decode(reader)?;
|
||||
|
||||
Ok(StatusServerBoundPacket::PingRequest(ping_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StatusClientBoundPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
StatusClientBoundPacket::StatusResponse(_) => 0x00,
|
||||
StatusClientBoundPacket::PingResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingRequest {
|
||||
pub time: u64,
|
||||
}
|
||||
|
||||
impl PingRequest {
|
||||
pub fn new(time: u64) -> StatusServerBoundPacket {
|
||||
let ping_request = PingRequest { time };
|
||||
|
||||
StatusServerBoundPacket::PingRequest(ping_request)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingResponse {
|
||||
pub time: u64,
|
||||
}
|
||||
|
||||
impl PingResponse {
|
||||
pub fn new(time: u64) -> StatusClientBoundPacket {
|
||||
let ping_response = PingResponse { time };
|
||||
|
||||
StatusClientBoundPacket::PingResponse(ping_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ServerStatus {
|
||||
pub version: ServerVersion,
|
||||
pub players: OnlinePlayers,
|
||||
pub description: Message,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ServerVersion {
|
||||
pub name: String,
|
||||
pub protocol: u32,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct OnlinePlayers {
|
||||
pub max: u32,
|
||||
pub online: u32,
|
||||
pub sample: Vec<OnlinePlayer>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||
pub struct OnlinePlayer {
|
||||
pub name: String,
|
||||
pub id: Uuid,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct StatusResponse {
|
||||
pub server_status: ServerStatus,
|
||||
}
|
||||
|
||||
impl_json_encoder_decoder!(ServerStatus);
|
||||
|
||||
impl StatusResponse {
|
||||
pub fn new(server_status: ServerStatus) -> StatusClientBoundPacket {
|
||||
let status_response = StatusResponse { server_status };
|
||||
|
||||
StatusClientBoundPacket::StatusResponse(status_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::chat::{Message, Payload};
|
||||
use crate::status::{
|
||||
OnlinePlayer, OnlinePlayers, PingRequest, PingResponse, ServerStatus, ServerVersion,
|
||||
StatusResponse,
|
||||
};
|
||||
use crate::Decoder;
|
||||
use crate::Encoder;
|
||||
use std::io::Cursor;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[test]
|
||||
fn test_ping_request_encode() {
|
||||
let ping_request = PingRequest {
|
||||
time: 1577735845610,
|
||||
};
|
||||
|
||||
let mut vec = Vec::new();
|
||||
ping_request.encode(&mut vec).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
vec,
|
||||
include_bytes!("../test/packet/status/ping_request.dat").to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_status_ping_request_decode() {
|
||||
let mut cursor =
|
||||
Cursor::new(include_bytes!("../test/packet/status/ping_request.dat").to_vec());
|
||||
let ping_request = PingRequest::decode(&mut cursor).unwrap();
|
||||
|
||||
assert_eq!(ping_request.time, 1577735845610);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ping_response_encode() {
|
||||
let ping_response = PingResponse {
|
||||
time: 1577735845610,
|
||||
};
|
||||
|
||||
let mut vec = Vec::new();
|
||||
ping_response.encode(&mut vec).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
vec,
|
||||
include_bytes!("../test/packet/status/ping_response.dat").to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_status_ping_response_decode() {
|
||||
let mut cursor =
|
||||
Cursor::new(include_bytes!("../test/packet/status/ping_response.dat").to_vec());
|
||||
let ping_response = PingResponse::decode(&mut cursor).unwrap();
|
||||
|
||||
assert_eq!(ping_response.time, 1577735845610);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_status_response_encode() {
|
||||
let version = ServerVersion {
|
||||
name: String::from("1.15.1"),
|
||||
protocol: 575,
|
||||
};
|
||||
|
||||
let player = OnlinePlayer {
|
||||
id: Uuid::parse_str("2a1e1912-7103-4add-80fc-91ebc346cbce").unwrap(),
|
||||
name: String::from("Username"),
|
||||
};
|
||||
|
||||
let players = OnlinePlayers {
|
||||
online: 10,
|
||||
max: 100,
|
||||
sample: vec![player],
|
||||
};
|
||||
|
||||
let server_status = ServerStatus {
|
||||
version,
|
||||
description: Message::new(Payload::text("Description")),
|
||||
players,
|
||||
};
|
||||
|
||||
let status_response = StatusResponse { server_status };
|
||||
|
||||
let mut vec = Vec::new();
|
||||
status_response.encode(&mut vec).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
vec,
|
||||
include_bytes!("../test/packet/status/status_response.dat").to_vec()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_status_response_decode() {
|
||||
let mut cursor =
|
||||
Cursor::new(include_bytes!("../test/packet/status/status_response.dat").to_vec());
|
||||
let status_response = StatusResponse::decode(&mut cursor).unwrap();
|
||||
let server_status = status_response.server_status;
|
||||
|
||||
let player = OnlinePlayer {
|
||||
id: Uuid::parse_str("2a1e1912-7103-4add-80fc-91ebc346cbce").unwrap(),
|
||||
name: String::from("Username"),
|
||||
};
|
||||
|
||||
assert_eq!(server_status.version.name, String::from("1.15.1"));
|
||||
assert_eq!(server_status.version.protocol, 575);
|
||||
assert_eq!(server_status.players.max, 100);
|
||||
assert_eq!(server_status.players.online, 10);
|
||||
assert_eq!(server_status.players.sample, vec![player]);
|
||||
assert_eq!(
|
||||
server_status.description,
|
||||
Message::new(Payload::text("Description"))
|
||||
);
|
||||
}
|
||||
}
|
72
protocol/src/version/mod.rs
Normal file
72
protocol/src/version/mod.rs
Normal file
@@ -0,0 +1,72 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
#[cfg(feature = "15w40b")]
|
||||
pub mod v_15w40b;
|
||||
#[cfg(feature = "16w20a")]
|
||||
pub mod v_16w20a;
|
||||
#[cfg(feature = "16w35a")]
|
||||
pub mod v_16w35a;
|
||||
#[cfg(feature = "17w15a")]
|
||||
pub mod v_17w15a;
|
||||
#[cfg(feature = "17w18b")]
|
||||
pub mod v_17w18b;
|
||||
#[cfg(feature = "17w50a")]
|
||||
pub mod v_17w50a;
|
||||
#[cfg(feature = "1.10")]
|
||||
pub mod v_1_10;
|
||||
#[cfg(feature = "1.10-pre1")]
|
||||
pub mod v_1_10_pre1;
|
||||
#[cfg(feature = "1.11")]
|
||||
pub mod v_1_11;
|
||||
#[cfg(feature = "1.12")]
|
||||
pub mod v_1_12;
|
||||
#[cfg(feature = "1.12.1")]
|
||||
pub mod v_1_12_1;
|
||||
#[cfg(feature = "1.12.2")]
|
||||
pub mod v_1_12_2;
|
||||
#[cfg(feature = "1.12-pre4")]
|
||||
pub mod v_1_12_pre4;
|
||||
#[cfg(feature = "1.13")]
|
||||
pub mod v_1_13;
|
||||
#[cfg(feature = "1.13.1")]
|
||||
pub mod v_1_13_1;
|
||||
#[cfg(feature = "1.13.2")]
|
||||
pub mod v_1_13_2;
|
||||
#[cfg(feature = "1.13.2-pre1")]
|
||||
pub mod v_1_13_2_pre1;
|
||||
#[cfg(feature = "1.13.2-pre2")]
|
||||
pub mod v_1_13_2_pre2;
|
||||
#[cfg(feature = "1.14")]
|
||||
pub mod v_1_14;
|
||||
#[cfg(feature = "1.14.1")]
|
||||
pub mod v_1_14_1;
|
||||
#[cfg(feature = "1.14.3")]
|
||||
pub mod v_1_14_3;
|
||||
#[cfg(feature = "1.14.4")]
|
||||
pub mod v_1_14_4;
|
||||
#[cfg(feature = "1.15")]
|
||||
pub mod v_1_15;
|
||||
#[cfg(feature = "1.15.1")]
|
||||
pub mod v_1_15_1;
|
||||
#[cfg(feature = "1.15.2")]
|
||||
pub mod v_1_15_2;
|
||||
#[cfg(feature = "1.16")]
|
||||
pub mod v_1_16;
|
||||
#[cfg(feature = "1.16.1")]
|
||||
pub mod v_1_16_1;
|
||||
#[cfg(feature = "1.16.2")]
|
||||
pub mod v_1_16_2;
|
||||
#[cfg(feature = "1.16-rc1")]
|
||||
pub mod v_1_16_rc1;
|
||||
#[cfg(feature = "1.8")]
|
||||
pub mod v_1_8;
|
||||
#[cfg(feature = "1.9")]
|
||||
pub mod v_1_9;
|
||||
#[cfg(feature = "1.9.1-pre2")]
|
||||
pub mod v_1_9_1_pre2;
|
||||
#[cfg(feature = "1.9.2")]
|
||||
pub mod v_1_9_2;
|
||||
#[cfg(feature = "1.9.4")]
|
||||
pub mod v_1_9_4;
|
||||
#[cfg(feature = "20w13b")]
|
||||
pub mod v_20w13b;
|
2555
protocol/src/version/v_15w40b/game.rs
Normal file
2555
protocol/src/version/v_15w40b/game.rs
Normal file
File diff suppressed because it is too large
Load Diff
55
protocol/src/version/v_15w40b/handshake.rs
Normal file
55
protocol/src/version/v_15w40b/handshake.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundHandshakePacket {
|
||||
SetProtocol(SetProtocol),
|
||||
}
|
||||
|
||||
impl ServerBoundHandshakePacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::SetProtocol(_) => 0x00,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let set_protocol = SetProtocol::decode(reader)?;
|
||||
|
||||
Ok(Self::SetProtocol(set_protocol))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_protocol(
|
||||
protocol_version: i32,
|
||||
server_host: String,
|
||||
server_port: u16,
|
||||
next_state: i32,
|
||||
) -> Self {
|
||||
let set_protocol = SetProtocol {
|
||||
protocol_version,
|
||||
server_host,
|
||||
server_port,
|
||||
next_state,
|
||||
};
|
||||
|
||||
Self::SetProtocol(set_protocol)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct SetProtocol {
|
||||
#[packet(with = "var_int")]
|
||||
pub protocol_version: i32,
|
||||
pub server_host: String,
|
||||
pub server_port: u16,
|
||||
#[packet(with = "var_int")]
|
||||
pub next_state: i32,
|
||||
}
|
162
protocol/src/version/v_15w40b/login.rs
Normal file
162
protocol/src/version/v_15w40b/login.rs
Normal file
@@ -0,0 +1,162 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundLoginPacket {
|
||||
LoginStart(LoginStart),
|
||||
EncryptionResponse(EncryptionResponse),
|
||||
}
|
||||
|
||||
impl ServerBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::LoginStart(_) => 0x00,
|
||||
Self::EncryptionResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let login_start = LoginStart::decode(reader)?;
|
||||
|
||||
Ok(Self::LoginStart(login_start))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_response = EncryptionResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionResponse(encryption_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn login_start(username: String) -> Self {
|
||||
let login_start = LoginStart { username };
|
||||
|
||||
Self::LoginStart(login_start)
|
||||
}
|
||||
|
||||
pub fn encryption_response(shared_secret: Vec<u8>, verify_token: Vec<u8>) -> Self {
|
||||
let encryption_response = EncryptionResponse {
|
||||
shared_secret,
|
||||
verify_token,
|
||||
};
|
||||
|
||||
Self::EncryptionResponse(encryption_response)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundLoginPacket {
|
||||
Disconnect(Disconnect),
|
||||
EncryptionRequest(EncryptionRequest),
|
||||
Success(Success),
|
||||
Compress(Compress),
|
||||
}
|
||||
|
||||
impl ClientBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::Disconnect(_) => 0x00,
|
||||
Self::EncryptionRequest(_) => 0x01,
|
||||
Self::Success(_) => 0x02,
|
||||
Self::Compress(_) => 0x03,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let disconnect = Disconnect::decode(reader)?;
|
||||
|
||||
Ok(Self::Disconnect(disconnect))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_request = EncryptionRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionRequest(encryption_request))
|
||||
}
|
||||
0x02 => {
|
||||
let success = Success::decode(reader)?;
|
||||
|
||||
Ok(Self::Success(success))
|
||||
}
|
||||
0x03 => {
|
||||
let compress = Compress::decode(reader)?;
|
||||
|
||||
Ok(Self::Compress(compress))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disconnect(reason: String) -> Self {
|
||||
let disconnect = Disconnect { reason };
|
||||
|
||||
Self::Disconnect(disconnect)
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
Self::EncryptionRequest(encryption_request)
|
||||
}
|
||||
|
||||
pub fn success(uuid: String, username: String) -> Self {
|
||||
let success = Success { uuid, username };
|
||||
|
||||
Self::Success(success)
|
||||
}
|
||||
|
||||
pub fn compress(threshold: i32) -> Self {
|
||||
let compress = Compress { threshold };
|
||||
|
||||
Self::Compress(compress)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginStart {
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionResponse {
|
||||
pub shared_secret: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Disconnect {
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionRequest {
|
||||
pub server_id: String,
|
||||
pub public_key: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Success {
|
||||
pub uuid: String,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Compress {
|
||||
#[packet(with = "var_int")]
|
||||
pub threshold: i32,
|
||||
}
|
6
protocol/src/version/v_15w40b/mod.rs
Normal file
6
protocol/src/version/v_15w40b/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
pub mod game;
|
||||
pub mod handshake;
|
||||
pub mod login;
|
||||
pub mod status;
|
99
protocol/src/version/v_15w40b/status.rs
Normal file
99
protocol/src/version/v_15w40b/status.rs
Normal file
@@ -0,0 +1,99 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundStatusPacket {
|
||||
StatusRequest,
|
||||
PingRequest(PingRequest),
|
||||
}
|
||||
|
||||
impl ServerBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusRequest => 0x00,
|
||||
Self::PingRequest(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => Ok(Self::StatusRequest),
|
||||
0x01 => {
|
||||
let ping_request = PingRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::PingRequest(ping_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_request() -> Self {
|
||||
Self::StatusRequest
|
||||
}
|
||||
|
||||
pub fn ping_request(time: i64) -> Self {
|
||||
let ping_request = PingRequest { time };
|
||||
|
||||
Self::PingRequest(ping_request)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundStatusPacket {
|
||||
StatusResponse(StatusResponse),
|
||||
PingResponse(PingResponse),
|
||||
}
|
||||
|
||||
impl ClientBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusResponse(_) => 0x00,
|
||||
Self::PingResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let status_response = StatusResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::StatusResponse(status_response))
|
||||
}
|
||||
0x01 => {
|
||||
let ping_response = PingResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::PingResponse(ping_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_response(response: String) -> Self {
|
||||
let status_response = StatusResponse { response };
|
||||
|
||||
Self::StatusResponse(status_response)
|
||||
}
|
||||
|
||||
pub fn ping_response(time: i64) -> Self {
|
||||
let ping_response = PingResponse { time };
|
||||
|
||||
Self::PingResponse(ping_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingRequest {
|
||||
pub time: i64,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct StatusResponse {
|
||||
pub response: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingResponse {
|
||||
pub time: i64,
|
||||
}
|
2685
protocol/src/version/v_16w20a/game.rs
Normal file
2685
protocol/src/version/v_16w20a/game.rs
Normal file
File diff suppressed because it is too large
Load Diff
55
protocol/src/version/v_16w20a/handshake.rs
Normal file
55
protocol/src/version/v_16w20a/handshake.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundHandshakePacket {
|
||||
SetProtocol(SetProtocol),
|
||||
}
|
||||
|
||||
impl ServerBoundHandshakePacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::SetProtocol(_) => 0x00,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let set_protocol = SetProtocol::decode(reader)?;
|
||||
|
||||
Ok(Self::SetProtocol(set_protocol))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_protocol(
|
||||
protocol_version: i32,
|
||||
server_host: String,
|
||||
server_port: u16,
|
||||
next_state: i32,
|
||||
) -> Self {
|
||||
let set_protocol = SetProtocol {
|
||||
protocol_version,
|
||||
server_host,
|
||||
server_port,
|
||||
next_state,
|
||||
};
|
||||
|
||||
Self::SetProtocol(set_protocol)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct SetProtocol {
|
||||
#[packet(with = "var_int")]
|
||||
pub protocol_version: i32,
|
||||
pub server_host: String,
|
||||
pub server_port: u16,
|
||||
#[packet(with = "var_int")]
|
||||
pub next_state: i32,
|
||||
}
|
162
protocol/src/version/v_16w20a/login.rs
Normal file
162
protocol/src/version/v_16w20a/login.rs
Normal file
@@ -0,0 +1,162 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundLoginPacket {
|
||||
LoginStart(LoginStart),
|
||||
EncryptionResponse(EncryptionResponse),
|
||||
}
|
||||
|
||||
impl ServerBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::LoginStart(_) => 0x00,
|
||||
Self::EncryptionResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let login_start = LoginStart::decode(reader)?;
|
||||
|
||||
Ok(Self::LoginStart(login_start))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_response = EncryptionResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionResponse(encryption_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn login_start(username: String) -> Self {
|
||||
let login_start = LoginStart { username };
|
||||
|
||||
Self::LoginStart(login_start)
|
||||
}
|
||||
|
||||
pub fn encryption_response(shared_secret: Vec<u8>, verify_token: Vec<u8>) -> Self {
|
||||
let encryption_response = EncryptionResponse {
|
||||
shared_secret,
|
||||
verify_token,
|
||||
};
|
||||
|
||||
Self::EncryptionResponse(encryption_response)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundLoginPacket {
|
||||
Disconnect(Disconnect),
|
||||
EncryptionRequest(EncryptionRequest),
|
||||
Success(Success),
|
||||
Compress(Compress),
|
||||
}
|
||||
|
||||
impl ClientBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::Disconnect(_) => 0x00,
|
||||
Self::EncryptionRequest(_) => 0x01,
|
||||
Self::Success(_) => 0x02,
|
||||
Self::Compress(_) => 0x03,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let disconnect = Disconnect::decode(reader)?;
|
||||
|
||||
Ok(Self::Disconnect(disconnect))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_request = EncryptionRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionRequest(encryption_request))
|
||||
}
|
||||
0x02 => {
|
||||
let success = Success::decode(reader)?;
|
||||
|
||||
Ok(Self::Success(success))
|
||||
}
|
||||
0x03 => {
|
||||
let compress = Compress::decode(reader)?;
|
||||
|
||||
Ok(Self::Compress(compress))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disconnect(reason: String) -> Self {
|
||||
let disconnect = Disconnect { reason };
|
||||
|
||||
Self::Disconnect(disconnect)
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
Self::EncryptionRequest(encryption_request)
|
||||
}
|
||||
|
||||
pub fn success(uuid: String, username: String) -> Self {
|
||||
let success = Success { uuid, username };
|
||||
|
||||
Self::Success(success)
|
||||
}
|
||||
|
||||
pub fn compress(threshold: i32) -> Self {
|
||||
let compress = Compress { threshold };
|
||||
|
||||
Self::Compress(compress)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginStart {
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionResponse {
|
||||
pub shared_secret: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Disconnect {
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionRequest {
|
||||
pub server_id: String,
|
||||
pub public_key: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Success {
|
||||
pub uuid: String,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Compress {
|
||||
#[packet(with = "var_int")]
|
||||
pub threshold: i32,
|
||||
}
|
6
protocol/src/version/v_16w20a/mod.rs
Normal file
6
protocol/src/version/v_16w20a/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
pub mod game;
|
||||
pub mod handshake;
|
||||
pub mod login;
|
||||
pub mod status;
|
99
protocol/src/version/v_16w20a/status.rs
Normal file
99
protocol/src/version/v_16w20a/status.rs
Normal file
@@ -0,0 +1,99 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundStatusPacket {
|
||||
StatusRequest,
|
||||
PingRequest(PingRequest),
|
||||
}
|
||||
|
||||
impl ServerBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusRequest => 0x00,
|
||||
Self::PingRequest(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => Ok(Self::StatusRequest),
|
||||
0x01 => {
|
||||
let ping_request = PingRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::PingRequest(ping_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_request() -> Self {
|
||||
Self::StatusRequest
|
||||
}
|
||||
|
||||
pub fn ping_request(time: i64) -> Self {
|
||||
let ping_request = PingRequest { time };
|
||||
|
||||
Self::PingRequest(ping_request)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundStatusPacket {
|
||||
StatusResponse(StatusResponse),
|
||||
PingResponse(PingResponse),
|
||||
}
|
||||
|
||||
impl ClientBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusResponse(_) => 0x00,
|
||||
Self::PingResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let status_response = StatusResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::StatusResponse(status_response))
|
||||
}
|
||||
0x01 => {
|
||||
let ping_response = PingResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::PingResponse(ping_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_response(response: String) -> Self {
|
||||
let status_response = StatusResponse { response };
|
||||
|
||||
Self::StatusResponse(status_response)
|
||||
}
|
||||
|
||||
pub fn ping_response(time: i64) -> Self {
|
||||
let ping_response = PingResponse { time };
|
||||
|
||||
Self::PingResponse(ping_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingRequest {
|
||||
pub time: i64,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct StatusResponse {
|
||||
pub response: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingResponse {
|
||||
pub time: i64,
|
||||
}
|
2692
protocol/src/version/v_16w35a/game.rs
Normal file
2692
protocol/src/version/v_16w35a/game.rs
Normal file
File diff suppressed because it is too large
Load Diff
55
protocol/src/version/v_16w35a/handshake.rs
Normal file
55
protocol/src/version/v_16w35a/handshake.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundHandshakePacket {
|
||||
SetProtocol(SetProtocol),
|
||||
}
|
||||
|
||||
impl ServerBoundHandshakePacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::SetProtocol(_) => 0x00,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let set_protocol = SetProtocol::decode(reader)?;
|
||||
|
||||
Ok(Self::SetProtocol(set_protocol))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_protocol(
|
||||
protocol_version: i32,
|
||||
server_host: String,
|
||||
server_port: u16,
|
||||
next_state: i32,
|
||||
) -> Self {
|
||||
let set_protocol = SetProtocol {
|
||||
protocol_version,
|
||||
server_host,
|
||||
server_port,
|
||||
next_state,
|
||||
};
|
||||
|
||||
Self::SetProtocol(set_protocol)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct SetProtocol {
|
||||
#[packet(with = "var_int")]
|
||||
pub protocol_version: i32,
|
||||
pub server_host: String,
|
||||
pub server_port: u16,
|
||||
#[packet(with = "var_int")]
|
||||
pub next_state: i32,
|
||||
}
|
162
protocol/src/version/v_16w35a/login.rs
Normal file
162
protocol/src/version/v_16w35a/login.rs
Normal file
@@ -0,0 +1,162 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundLoginPacket {
|
||||
LoginStart(LoginStart),
|
||||
EncryptionResponse(EncryptionResponse),
|
||||
}
|
||||
|
||||
impl ServerBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::LoginStart(_) => 0x00,
|
||||
Self::EncryptionResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let login_start = LoginStart::decode(reader)?;
|
||||
|
||||
Ok(Self::LoginStart(login_start))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_response = EncryptionResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionResponse(encryption_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn login_start(username: String) -> Self {
|
||||
let login_start = LoginStart { username };
|
||||
|
||||
Self::LoginStart(login_start)
|
||||
}
|
||||
|
||||
pub fn encryption_response(shared_secret: Vec<u8>, verify_token: Vec<u8>) -> Self {
|
||||
let encryption_response = EncryptionResponse {
|
||||
shared_secret,
|
||||
verify_token,
|
||||
};
|
||||
|
||||
Self::EncryptionResponse(encryption_response)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundLoginPacket {
|
||||
Disconnect(Disconnect),
|
||||
EncryptionRequest(EncryptionRequest),
|
||||
Success(Success),
|
||||
Compress(Compress),
|
||||
}
|
||||
|
||||
impl ClientBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::Disconnect(_) => 0x00,
|
||||
Self::EncryptionRequest(_) => 0x01,
|
||||
Self::Success(_) => 0x02,
|
||||
Self::Compress(_) => 0x03,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let disconnect = Disconnect::decode(reader)?;
|
||||
|
||||
Ok(Self::Disconnect(disconnect))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_request = EncryptionRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionRequest(encryption_request))
|
||||
}
|
||||
0x02 => {
|
||||
let success = Success::decode(reader)?;
|
||||
|
||||
Ok(Self::Success(success))
|
||||
}
|
||||
0x03 => {
|
||||
let compress = Compress::decode(reader)?;
|
||||
|
||||
Ok(Self::Compress(compress))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disconnect(reason: String) -> Self {
|
||||
let disconnect = Disconnect { reason };
|
||||
|
||||
Self::Disconnect(disconnect)
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
Self::EncryptionRequest(encryption_request)
|
||||
}
|
||||
|
||||
pub fn success(uuid: String, username: String) -> Self {
|
||||
let success = Success { uuid, username };
|
||||
|
||||
Self::Success(success)
|
||||
}
|
||||
|
||||
pub fn compress(threshold: i32) -> Self {
|
||||
let compress = Compress { threshold };
|
||||
|
||||
Self::Compress(compress)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginStart {
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionResponse {
|
||||
pub shared_secret: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Disconnect {
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionRequest {
|
||||
pub server_id: String,
|
||||
pub public_key: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Success {
|
||||
pub uuid: String,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Compress {
|
||||
#[packet(with = "var_int")]
|
||||
pub threshold: i32,
|
||||
}
|
6
protocol/src/version/v_16w35a/mod.rs
Normal file
6
protocol/src/version/v_16w35a/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
pub mod game;
|
||||
pub mod handshake;
|
||||
pub mod login;
|
||||
pub mod status;
|
99
protocol/src/version/v_16w35a/status.rs
Normal file
99
protocol/src/version/v_16w35a/status.rs
Normal file
@@ -0,0 +1,99 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundStatusPacket {
|
||||
StatusRequest,
|
||||
PingRequest(PingRequest),
|
||||
}
|
||||
|
||||
impl ServerBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusRequest => 0x00,
|
||||
Self::PingRequest(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => Ok(Self::StatusRequest),
|
||||
0x01 => {
|
||||
let ping_request = PingRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::PingRequest(ping_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_request() -> Self {
|
||||
Self::StatusRequest
|
||||
}
|
||||
|
||||
pub fn ping_request(time: i64) -> Self {
|
||||
let ping_request = PingRequest { time };
|
||||
|
||||
Self::PingRequest(ping_request)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundStatusPacket {
|
||||
StatusResponse(StatusResponse),
|
||||
PingResponse(PingResponse),
|
||||
}
|
||||
|
||||
impl ClientBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusResponse(_) => 0x00,
|
||||
Self::PingResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let status_response = StatusResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::StatusResponse(status_response))
|
||||
}
|
||||
0x01 => {
|
||||
let ping_response = PingResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::PingResponse(ping_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_response(response: String) -> Self {
|
||||
let status_response = StatusResponse { response };
|
||||
|
||||
Self::StatusResponse(status_response)
|
||||
}
|
||||
|
||||
pub fn ping_response(time: i64) -> Self {
|
||||
let ping_response = PingResponse { time };
|
||||
|
||||
Self::PingResponse(ping_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingRequest {
|
||||
pub time: i64,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct StatusResponse {
|
||||
pub response: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingResponse {
|
||||
pub time: i64,
|
||||
}
|
2781
protocol/src/version/v_17w15a/game.rs
Normal file
2781
protocol/src/version/v_17w15a/game.rs
Normal file
File diff suppressed because it is too large
Load Diff
55
protocol/src/version/v_17w15a/handshake.rs
Normal file
55
protocol/src/version/v_17w15a/handshake.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundHandshakePacket {
|
||||
SetProtocol(SetProtocol),
|
||||
}
|
||||
|
||||
impl ServerBoundHandshakePacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::SetProtocol(_) => 0x00,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let set_protocol = SetProtocol::decode(reader)?;
|
||||
|
||||
Ok(Self::SetProtocol(set_protocol))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_protocol(
|
||||
protocol_version: i32,
|
||||
server_host: String,
|
||||
server_port: u16,
|
||||
next_state: i32,
|
||||
) -> Self {
|
||||
let set_protocol = SetProtocol {
|
||||
protocol_version,
|
||||
server_host,
|
||||
server_port,
|
||||
next_state,
|
||||
};
|
||||
|
||||
Self::SetProtocol(set_protocol)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct SetProtocol {
|
||||
#[packet(with = "var_int")]
|
||||
pub protocol_version: i32,
|
||||
pub server_host: String,
|
||||
pub server_port: u16,
|
||||
#[packet(with = "var_int")]
|
||||
pub next_state: i32,
|
||||
}
|
162
protocol/src/version/v_17w15a/login.rs
Normal file
162
protocol/src/version/v_17w15a/login.rs
Normal file
@@ -0,0 +1,162 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundLoginPacket {
|
||||
LoginStart(LoginStart),
|
||||
EncryptionResponse(EncryptionResponse),
|
||||
}
|
||||
|
||||
impl ServerBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::LoginStart(_) => 0x00,
|
||||
Self::EncryptionResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let login_start = LoginStart::decode(reader)?;
|
||||
|
||||
Ok(Self::LoginStart(login_start))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_response = EncryptionResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionResponse(encryption_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn login_start(username: String) -> Self {
|
||||
let login_start = LoginStart { username };
|
||||
|
||||
Self::LoginStart(login_start)
|
||||
}
|
||||
|
||||
pub fn encryption_response(shared_secret: Vec<u8>, verify_token: Vec<u8>) -> Self {
|
||||
let encryption_response = EncryptionResponse {
|
||||
shared_secret,
|
||||
verify_token,
|
||||
};
|
||||
|
||||
Self::EncryptionResponse(encryption_response)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundLoginPacket {
|
||||
Disconnect(Disconnect),
|
||||
EncryptionRequest(EncryptionRequest),
|
||||
Success(Success),
|
||||
Compress(Compress),
|
||||
}
|
||||
|
||||
impl ClientBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::Disconnect(_) => 0x00,
|
||||
Self::EncryptionRequest(_) => 0x01,
|
||||
Self::Success(_) => 0x02,
|
||||
Self::Compress(_) => 0x03,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let disconnect = Disconnect::decode(reader)?;
|
||||
|
||||
Ok(Self::Disconnect(disconnect))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_request = EncryptionRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionRequest(encryption_request))
|
||||
}
|
||||
0x02 => {
|
||||
let success = Success::decode(reader)?;
|
||||
|
||||
Ok(Self::Success(success))
|
||||
}
|
||||
0x03 => {
|
||||
let compress = Compress::decode(reader)?;
|
||||
|
||||
Ok(Self::Compress(compress))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disconnect(reason: String) -> Self {
|
||||
let disconnect = Disconnect { reason };
|
||||
|
||||
Self::Disconnect(disconnect)
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
Self::EncryptionRequest(encryption_request)
|
||||
}
|
||||
|
||||
pub fn success(uuid: String, username: String) -> Self {
|
||||
let success = Success { uuid, username };
|
||||
|
||||
Self::Success(success)
|
||||
}
|
||||
|
||||
pub fn compress(threshold: i32) -> Self {
|
||||
let compress = Compress { threshold };
|
||||
|
||||
Self::Compress(compress)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginStart {
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionResponse {
|
||||
pub shared_secret: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Disconnect {
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionRequest {
|
||||
pub server_id: String,
|
||||
pub public_key: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Success {
|
||||
pub uuid: String,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Compress {
|
||||
#[packet(with = "var_int")]
|
||||
pub threshold: i32,
|
||||
}
|
6
protocol/src/version/v_17w15a/mod.rs
Normal file
6
protocol/src/version/v_17w15a/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
pub mod game;
|
||||
pub mod handshake;
|
||||
pub mod login;
|
||||
pub mod status;
|
99
protocol/src/version/v_17w15a/status.rs
Normal file
99
protocol/src/version/v_17w15a/status.rs
Normal file
@@ -0,0 +1,99 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundStatusPacket {
|
||||
StatusRequest,
|
||||
PingRequest(PingRequest),
|
||||
}
|
||||
|
||||
impl ServerBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusRequest => 0x00,
|
||||
Self::PingRequest(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => Ok(Self::StatusRequest),
|
||||
0x01 => {
|
||||
let ping_request = PingRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::PingRequest(ping_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_request() -> Self {
|
||||
Self::StatusRequest
|
||||
}
|
||||
|
||||
pub fn ping_request(time: i64) -> Self {
|
||||
let ping_request = PingRequest { time };
|
||||
|
||||
Self::PingRequest(ping_request)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundStatusPacket {
|
||||
StatusResponse(StatusResponse),
|
||||
PingResponse(PingResponse),
|
||||
}
|
||||
|
||||
impl ClientBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusResponse(_) => 0x00,
|
||||
Self::PingResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let status_response = StatusResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::StatusResponse(status_response))
|
||||
}
|
||||
0x01 => {
|
||||
let ping_response = PingResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::PingResponse(ping_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_response(response: String) -> Self {
|
||||
let status_response = StatusResponse { response };
|
||||
|
||||
Self::StatusResponse(status_response)
|
||||
}
|
||||
|
||||
pub fn ping_response(time: i64) -> Self {
|
||||
let ping_response = PingResponse { time };
|
||||
|
||||
Self::PingResponse(ping_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingRequest {
|
||||
pub time: i64,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct StatusResponse {
|
||||
pub response: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingResponse {
|
||||
pub time: i64,
|
||||
}
|
2778
protocol/src/version/v_17w18b/game.rs
Normal file
2778
protocol/src/version/v_17w18b/game.rs
Normal file
File diff suppressed because it is too large
Load Diff
55
protocol/src/version/v_17w18b/handshake.rs
Normal file
55
protocol/src/version/v_17w18b/handshake.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundHandshakePacket {
|
||||
SetProtocol(SetProtocol),
|
||||
}
|
||||
|
||||
impl ServerBoundHandshakePacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::SetProtocol(_) => 0x00,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let set_protocol = SetProtocol::decode(reader)?;
|
||||
|
||||
Ok(Self::SetProtocol(set_protocol))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_protocol(
|
||||
protocol_version: i32,
|
||||
server_host: String,
|
||||
server_port: u16,
|
||||
next_state: i32,
|
||||
) -> Self {
|
||||
let set_protocol = SetProtocol {
|
||||
protocol_version,
|
||||
server_host,
|
||||
server_port,
|
||||
next_state,
|
||||
};
|
||||
|
||||
Self::SetProtocol(set_protocol)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct SetProtocol {
|
||||
#[packet(with = "var_int")]
|
||||
pub protocol_version: i32,
|
||||
pub server_host: String,
|
||||
pub server_port: u16,
|
||||
#[packet(with = "var_int")]
|
||||
pub next_state: i32,
|
||||
}
|
162
protocol/src/version/v_17w18b/login.rs
Normal file
162
protocol/src/version/v_17w18b/login.rs
Normal file
@@ -0,0 +1,162 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundLoginPacket {
|
||||
LoginStart(LoginStart),
|
||||
EncryptionResponse(EncryptionResponse),
|
||||
}
|
||||
|
||||
impl ServerBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::LoginStart(_) => 0x00,
|
||||
Self::EncryptionResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let login_start = LoginStart::decode(reader)?;
|
||||
|
||||
Ok(Self::LoginStart(login_start))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_response = EncryptionResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionResponse(encryption_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn login_start(username: String) -> Self {
|
||||
let login_start = LoginStart { username };
|
||||
|
||||
Self::LoginStart(login_start)
|
||||
}
|
||||
|
||||
pub fn encryption_response(shared_secret: Vec<u8>, verify_token: Vec<u8>) -> Self {
|
||||
let encryption_response = EncryptionResponse {
|
||||
shared_secret,
|
||||
verify_token,
|
||||
};
|
||||
|
||||
Self::EncryptionResponse(encryption_response)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundLoginPacket {
|
||||
Disconnect(Disconnect),
|
||||
EncryptionRequest(EncryptionRequest),
|
||||
Success(Success),
|
||||
Compress(Compress),
|
||||
}
|
||||
|
||||
impl ClientBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::Disconnect(_) => 0x00,
|
||||
Self::EncryptionRequest(_) => 0x01,
|
||||
Self::Success(_) => 0x02,
|
||||
Self::Compress(_) => 0x03,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let disconnect = Disconnect::decode(reader)?;
|
||||
|
||||
Ok(Self::Disconnect(disconnect))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_request = EncryptionRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionRequest(encryption_request))
|
||||
}
|
||||
0x02 => {
|
||||
let success = Success::decode(reader)?;
|
||||
|
||||
Ok(Self::Success(success))
|
||||
}
|
||||
0x03 => {
|
||||
let compress = Compress::decode(reader)?;
|
||||
|
||||
Ok(Self::Compress(compress))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disconnect(reason: String) -> Self {
|
||||
let disconnect = Disconnect { reason };
|
||||
|
||||
Self::Disconnect(disconnect)
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
Self::EncryptionRequest(encryption_request)
|
||||
}
|
||||
|
||||
pub fn success(uuid: String, username: String) -> Self {
|
||||
let success = Success { uuid, username };
|
||||
|
||||
Self::Success(success)
|
||||
}
|
||||
|
||||
pub fn compress(threshold: i32) -> Self {
|
||||
let compress = Compress { threshold };
|
||||
|
||||
Self::Compress(compress)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginStart {
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionResponse {
|
||||
pub shared_secret: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Disconnect {
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionRequest {
|
||||
pub server_id: String,
|
||||
pub public_key: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Success {
|
||||
pub uuid: String,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Compress {
|
||||
#[packet(with = "var_int")]
|
||||
pub threshold: i32,
|
||||
}
|
6
protocol/src/version/v_17w18b/mod.rs
Normal file
6
protocol/src/version/v_17w18b/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
pub mod game;
|
||||
pub mod handshake;
|
||||
pub mod login;
|
||||
pub mod status;
|
99
protocol/src/version/v_17w18b/status.rs
Normal file
99
protocol/src/version/v_17w18b/status.rs
Normal file
@@ -0,0 +1,99 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundStatusPacket {
|
||||
StatusRequest,
|
||||
PingRequest(PingRequest),
|
||||
}
|
||||
|
||||
impl ServerBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusRequest => 0x00,
|
||||
Self::PingRequest(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => Ok(Self::StatusRequest),
|
||||
0x01 => {
|
||||
let ping_request = PingRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::PingRequest(ping_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_request() -> Self {
|
||||
Self::StatusRequest
|
||||
}
|
||||
|
||||
pub fn ping_request(time: i64) -> Self {
|
||||
let ping_request = PingRequest { time };
|
||||
|
||||
Self::PingRequest(ping_request)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundStatusPacket {
|
||||
StatusResponse(StatusResponse),
|
||||
PingResponse(PingResponse),
|
||||
}
|
||||
|
||||
impl ClientBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusResponse(_) => 0x00,
|
||||
Self::PingResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let status_response = StatusResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::StatusResponse(status_response))
|
||||
}
|
||||
0x01 => {
|
||||
let ping_response = PingResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::PingResponse(ping_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_response(response: String) -> Self {
|
||||
let status_response = StatusResponse { response };
|
||||
|
||||
Self::StatusResponse(status_response)
|
||||
}
|
||||
|
||||
pub fn ping_response(time: i64) -> Self {
|
||||
let ping_response = PingResponse { time };
|
||||
|
||||
Self::PingResponse(ping_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingRequest {
|
||||
pub time: i64,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct StatusResponse {
|
||||
pub response: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingResponse {
|
||||
pub time: i64,
|
||||
}
|
2917
protocol/src/version/v_17w50a/game.rs
Normal file
2917
protocol/src/version/v_17w50a/game.rs
Normal file
File diff suppressed because it is too large
Load Diff
55
protocol/src/version/v_17w50a/handshake.rs
Normal file
55
protocol/src/version/v_17w50a/handshake.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundHandshakePacket {
|
||||
SetProtocol(SetProtocol),
|
||||
}
|
||||
|
||||
impl ServerBoundHandshakePacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::SetProtocol(_) => 0x00,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let set_protocol = SetProtocol::decode(reader)?;
|
||||
|
||||
Ok(Self::SetProtocol(set_protocol))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_protocol(
|
||||
protocol_version: i32,
|
||||
server_host: String,
|
||||
server_port: u16,
|
||||
next_state: i32,
|
||||
) -> Self {
|
||||
let set_protocol = SetProtocol {
|
||||
protocol_version,
|
||||
server_host,
|
||||
server_port,
|
||||
next_state,
|
||||
};
|
||||
|
||||
Self::SetProtocol(set_protocol)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct SetProtocol {
|
||||
#[packet(with = "var_int")]
|
||||
pub protocol_version: i32,
|
||||
pub server_host: String,
|
||||
pub server_port: u16,
|
||||
#[packet(with = "var_int")]
|
||||
pub next_state: i32,
|
||||
}
|
162
protocol/src/version/v_17w50a/login.rs
Normal file
162
protocol/src/version/v_17w50a/login.rs
Normal file
@@ -0,0 +1,162 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundLoginPacket {
|
||||
LoginStart(LoginStart),
|
||||
EncryptionResponse(EncryptionResponse),
|
||||
}
|
||||
|
||||
impl ServerBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::LoginStart(_) => 0x00,
|
||||
Self::EncryptionResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let login_start = LoginStart::decode(reader)?;
|
||||
|
||||
Ok(Self::LoginStart(login_start))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_response = EncryptionResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionResponse(encryption_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn login_start(username: String) -> Self {
|
||||
let login_start = LoginStart { username };
|
||||
|
||||
Self::LoginStart(login_start)
|
||||
}
|
||||
|
||||
pub fn encryption_response(shared_secret: Vec<u8>, verify_token: Vec<u8>) -> Self {
|
||||
let encryption_response = EncryptionResponse {
|
||||
shared_secret,
|
||||
verify_token,
|
||||
};
|
||||
|
||||
Self::EncryptionResponse(encryption_response)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundLoginPacket {
|
||||
Disconnect(Disconnect),
|
||||
EncryptionRequest(EncryptionRequest),
|
||||
Success(Success),
|
||||
Compress(Compress),
|
||||
}
|
||||
|
||||
impl ClientBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::Disconnect(_) => 0x00,
|
||||
Self::EncryptionRequest(_) => 0x01,
|
||||
Self::Success(_) => 0x02,
|
||||
Self::Compress(_) => 0x03,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let disconnect = Disconnect::decode(reader)?;
|
||||
|
||||
Ok(Self::Disconnect(disconnect))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_request = EncryptionRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionRequest(encryption_request))
|
||||
}
|
||||
0x02 => {
|
||||
let success = Success::decode(reader)?;
|
||||
|
||||
Ok(Self::Success(success))
|
||||
}
|
||||
0x03 => {
|
||||
let compress = Compress::decode(reader)?;
|
||||
|
||||
Ok(Self::Compress(compress))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disconnect(reason: String) -> Self {
|
||||
let disconnect = Disconnect { reason };
|
||||
|
||||
Self::Disconnect(disconnect)
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
Self::EncryptionRequest(encryption_request)
|
||||
}
|
||||
|
||||
pub fn success(uuid: String, username: String) -> Self {
|
||||
let success = Success { uuid, username };
|
||||
|
||||
Self::Success(success)
|
||||
}
|
||||
|
||||
pub fn compress(threshold: i32) -> Self {
|
||||
let compress = Compress { threshold };
|
||||
|
||||
Self::Compress(compress)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginStart {
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionResponse {
|
||||
pub shared_secret: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Disconnect {
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionRequest {
|
||||
pub server_id: String,
|
||||
pub public_key: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Success {
|
||||
pub uuid: String,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Compress {
|
||||
#[packet(with = "var_int")]
|
||||
pub threshold: i32,
|
||||
}
|
6
protocol/src/version/v_17w50a/mod.rs
Normal file
6
protocol/src/version/v_17w50a/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
pub mod game;
|
||||
pub mod handshake;
|
||||
pub mod login;
|
||||
pub mod status;
|
99
protocol/src/version/v_17w50a/status.rs
Normal file
99
protocol/src/version/v_17w50a/status.rs
Normal file
@@ -0,0 +1,99 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundStatusPacket {
|
||||
StatusRequest,
|
||||
PingRequest(PingRequest),
|
||||
}
|
||||
|
||||
impl ServerBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusRequest => 0x00,
|
||||
Self::PingRequest(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => Ok(Self::StatusRequest),
|
||||
0x01 => {
|
||||
let ping_request = PingRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::PingRequest(ping_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_request() -> Self {
|
||||
Self::StatusRequest
|
||||
}
|
||||
|
||||
pub fn ping_request(time: i64) -> Self {
|
||||
let ping_request = PingRequest { time };
|
||||
|
||||
Self::PingRequest(ping_request)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundStatusPacket {
|
||||
StatusResponse(StatusResponse),
|
||||
PingResponse(PingResponse),
|
||||
}
|
||||
|
||||
impl ClientBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusResponse(_) => 0x00,
|
||||
Self::PingResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let status_response = StatusResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::StatusResponse(status_response))
|
||||
}
|
||||
0x01 => {
|
||||
let ping_response = PingResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::PingResponse(ping_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_response(response: String) -> Self {
|
||||
let status_response = StatusResponse { response };
|
||||
|
||||
Self::StatusResponse(status_response)
|
||||
}
|
||||
|
||||
pub fn ping_response(time: i64) -> Self {
|
||||
let ping_response = PingResponse { time };
|
||||
|
||||
Self::PingResponse(ping_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingRequest {
|
||||
pub time: i64,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct StatusResponse {
|
||||
pub response: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingResponse {
|
||||
pub time: i64,
|
||||
}
|
2684
protocol/src/version/v_1_10/game.rs
Normal file
2684
protocol/src/version/v_1_10/game.rs
Normal file
File diff suppressed because it is too large
Load Diff
55
protocol/src/version/v_1_10/handshake.rs
Normal file
55
protocol/src/version/v_1_10/handshake.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundHandshakePacket {
|
||||
SetProtocol(SetProtocol),
|
||||
}
|
||||
|
||||
impl ServerBoundHandshakePacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::SetProtocol(_) => 0x00,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let set_protocol = SetProtocol::decode(reader)?;
|
||||
|
||||
Ok(Self::SetProtocol(set_protocol))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_protocol(
|
||||
protocol_version: i32,
|
||||
server_host: String,
|
||||
server_port: u16,
|
||||
next_state: i32,
|
||||
) -> Self {
|
||||
let set_protocol = SetProtocol {
|
||||
protocol_version,
|
||||
server_host,
|
||||
server_port,
|
||||
next_state,
|
||||
};
|
||||
|
||||
Self::SetProtocol(set_protocol)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct SetProtocol {
|
||||
#[packet(with = "var_int")]
|
||||
pub protocol_version: i32,
|
||||
pub server_host: String,
|
||||
pub server_port: u16,
|
||||
#[packet(with = "var_int")]
|
||||
pub next_state: i32,
|
||||
}
|
162
protocol/src/version/v_1_10/login.rs
Normal file
162
protocol/src/version/v_1_10/login.rs
Normal file
@@ -0,0 +1,162 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundLoginPacket {
|
||||
LoginStart(LoginStart),
|
||||
EncryptionResponse(EncryptionResponse),
|
||||
}
|
||||
|
||||
impl ServerBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::LoginStart(_) => 0x00,
|
||||
Self::EncryptionResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let login_start = LoginStart::decode(reader)?;
|
||||
|
||||
Ok(Self::LoginStart(login_start))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_response = EncryptionResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionResponse(encryption_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn login_start(username: String) -> Self {
|
||||
let login_start = LoginStart { username };
|
||||
|
||||
Self::LoginStart(login_start)
|
||||
}
|
||||
|
||||
pub fn encryption_response(shared_secret: Vec<u8>, verify_token: Vec<u8>) -> Self {
|
||||
let encryption_response = EncryptionResponse {
|
||||
shared_secret,
|
||||
verify_token,
|
||||
};
|
||||
|
||||
Self::EncryptionResponse(encryption_response)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundLoginPacket {
|
||||
Disconnect(Disconnect),
|
||||
EncryptionRequest(EncryptionRequest),
|
||||
Success(Success),
|
||||
Compress(Compress),
|
||||
}
|
||||
|
||||
impl ClientBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::Disconnect(_) => 0x00,
|
||||
Self::EncryptionRequest(_) => 0x01,
|
||||
Self::Success(_) => 0x02,
|
||||
Self::Compress(_) => 0x03,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let disconnect = Disconnect::decode(reader)?;
|
||||
|
||||
Ok(Self::Disconnect(disconnect))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_request = EncryptionRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionRequest(encryption_request))
|
||||
}
|
||||
0x02 => {
|
||||
let success = Success::decode(reader)?;
|
||||
|
||||
Ok(Self::Success(success))
|
||||
}
|
||||
0x03 => {
|
||||
let compress = Compress::decode(reader)?;
|
||||
|
||||
Ok(Self::Compress(compress))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disconnect(reason: String) -> Self {
|
||||
let disconnect = Disconnect { reason };
|
||||
|
||||
Self::Disconnect(disconnect)
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
Self::EncryptionRequest(encryption_request)
|
||||
}
|
||||
|
||||
pub fn success(uuid: String, username: String) -> Self {
|
||||
let success = Success { uuid, username };
|
||||
|
||||
Self::Success(success)
|
||||
}
|
||||
|
||||
pub fn compress(threshold: i32) -> Self {
|
||||
let compress = Compress { threshold };
|
||||
|
||||
Self::Compress(compress)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginStart {
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionResponse {
|
||||
pub shared_secret: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Disconnect {
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionRequest {
|
||||
pub server_id: String,
|
||||
pub public_key: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Success {
|
||||
pub uuid: String,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Compress {
|
||||
#[packet(with = "var_int")]
|
||||
pub threshold: i32,
|
||||
}
|
6
protocol/src/version/v_1_10/mod.rs
Normal file
6
protocol/src/version/v_1_10/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
pub mod game;
|
||||
pub mod handshake;
|
||||
pub mod login;
|
||||
pub mod status;
|
99
protocol/src/version/v_1_10/status.rs
Normal file
99
protocol/src/version/v_1_10/status.rs
Normal file
@@ -0,0 +1,99 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundStatusPacket {
|
||||
StatusRequest,
|
||||
PingRequest(PingRequest),
|
||||
}
|
||||
|
||||
impl ServerBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusRequest => 0x00,
|
||||
Self::PingRequest(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => Ok(Self::StatusRequest),
|
||||
0x01 => {
|
||||
let ping_request = PingRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::PingRequest(ping_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_request() -> Self {
|
||||
Self::StatusRequest
|
||||
}
|
||||
|
||||
pub fn ping_request(time: i64) -> Self {
|
||||
let ping_request = PingRequest { time };
|
||||
|
||||
Self::PingRequest(ping_request)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundStatusPacket {
|
||||
StatusResponse(StatusResponse),
|
||||
PingResponse(PingResponse),
|
||||
}
|
||||
|
||||
impl ClientBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusResponse(_) => 0x00,
|
||||
Self::PingResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let status_response = StatusResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::StatusResponse(status_response))
|
||||
}
|
||||
0x01 => {
|
||||
let ping_response = PingResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::PingResponse(ping_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_response(response: String) -> Self {
|
||||
let status_response = StatusResponse { response };
|
||||
|
||||
Self::StatusResponse(status_response)
|
||||
}
|
||||
|
||||
pub fn ping_response(time: i64) -> Self {
|
||||
let ping_response = PingResponse { time };
|
||||
|
||||
Self::PingResponse(ping_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingRequest {
|
||||
pub time: i64,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct StatusResponse {
|
||||
pub response: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingResponse {
|
||||
pub time: i64,
|
||||
}
|
2684
protocol/src/version/v_1_10_pre1/game.rs
Normal file
2684
protocol/src/version/v_1_10_pre1/game.rs
Normal file
File diff suppressed because it is too large
Load Diff
55
protocol/src/version/v_1_10_pre1/handshake.rs
Normal file
55
protocol/src/version/v_1_10_pre1/handshake.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundHandshakePacket {
|
||||
SetProtocol(SetProtocol),
|
||||
}
|
||||
|
||||
impl ServerBoundHandshakePacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::SetProtocol(_) => 0x00,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let set_protocol = SetProtocol::decode(reader)?;
|
||||
|
||||
Ok(Self::SetProtocol(set_protocol))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_protocol(
|
||||
protocol_version: i32,
|
||||
server_host: String,
|
||||
server_port: u16,
|
||||
next_state: i32,
|
||||
) -> Self {
|
||||
let set_protocol = SetProtocol {
|
||||
protocol_version,
|
||||
server_host,
|
||||
server_port,
|
||||
next_state,
|
||||
};
|
||||
|
||||
Self::SetProtocol(set_protocol)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct SetProtocol {
|
||||
#[packet(with = "var_int")]
|
||||
pub protocol_version: i32,
|
||||
pub server_host: String,
|
||||
pub server_port: u16,
|
||||
#[packet(with = "var_int")]
|
||||
pub next_state: i32,
|
||||
}
|
162
protocol/src/version/v_1_10_pre1/login.rs
Normal file
162
protocol/src/version/v_1_10_pre1/login.rs
Normal file
@@ -0,0 +1,162 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundLoginPacket {
|
||||
LoginStart(LoginStart),
|
||||
EncryptionResponse(EncryptionResponse),
|
||||
}
|
||||
|
||||
impl ServerBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::LoginStart(_) => 0x00,
|
||||
Self::EncryptionResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let login_start = LoginStart::decode(reader)?;
|
||||
|
||||
Ok(Self::LoginStart(login_start))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_response = EncryptionResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionResponse(encryption_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn login_start(username: String) -> Self {
|
||||
let login_start = LoginStart { username };
|
||||
|
||||
Self::LoginStart(login_start)
|
||||
}
|
||||
|
||||
pub fn encryption_response(shared_secret: Vec<u8>, verify_token: Vec<u8>) -> Self {
|
||||
let encryption_response = EncryptionResponse {
|
||||
shared_secret,
|
||||
verify_token,
|
||||
};
|
||||
|
||||
Self::EncryptionResponse(encryption_response)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundLoginPacket {
|
||||
Disconnect(Disconnect),
|
||||
EncryptionRequest(EncryptionRequest),
|
||||
Success(Success),
|
||||
Compress(Compress),
|
||||
}
|
||||
|
||||
impl ClientBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::Disconnect(_) => 0x00,
|
||||
Self::EncryptionRequest(_) => 0x01,
|
||||
Self::Success(_) => 0x02,
|
||||
Self::Compress(_) => 0x03,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let disconnect = Disconnect::decode(reader)?;
|
||||
|
||||
Ok(Self::Disconnect(disconnect))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_request = EncryptionRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionRequest(encryption_request))
|
||||
}
|
||||
0x02 => {
|
||||
let success = Success::decode(reader)?;
|
||||
|
||||
Ok(Self::Success(success))
|
||||
}
|
||||
0x03 => {
|
||||
let compress = Compress::decode(reader)?;
|
||||
|
||||
Ok(Self::Compress(compress))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disconnect(reason: String) -> Self {
|
||||
let disconnect = Disconnect { reason };
|
||||
|
||||
Self::Disconnect(disconnect)
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
Self::EncryptionRequest(encryption_request)
|
||||
}
|
||||
|
||||
pub fn success(uuid: String, username: String) -> Self {
|
||||
let success = Success { uuid, username };
|
||||
|
||||
Self::Success(success)
|
||||
}
|
||||
|
||||
pub fn compress(threshold: i32) -> Self {
|
||||
let compress = Compress { threshold };
|
||||
|
||||
Self::Compress(compress)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginStart {
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionResponse {
|
||||
pub shared_secret: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Disconnect {
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionRequest {
|
||||
pub server_id: String,
|
||||
pub public_key: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Success {
|
||||
pub uuid: String,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Compress {
|
||||
#[packet(with = "var_int")]
|
||||
pub threshold: i32,
|
||||
}
|
6
protocol/src/version/v_1_10_pre1/mod.rs
Normal file
6
protocol/src/version/v_1_10_pre1/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
pub mod game;
|
||||
pub mod handshake;
|
||||
pub mod login;
|
||||
pub mod status;
|
99
protocol/src/version/v_1_10_pre1/status.rs
Normal file
99
protocol/src/version/v_1_10_pre1/status.rs
Normal file
@@ -0,0 +1,99 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundStatusPacket {
|
||||
StatusRequest,
|
||||
PingRequest(PingRequest),
|
||||
}
|
||||
|
||||
impl ServerBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusRequest => 0x00,
|
||||
Self::PingRequest(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => Ok(Self::StatusRequest),
|
||||
0x01 => {
|
||||
let ping_request = PingRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::PingRequest(ping_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_request() -> Self {
|
||||
Self::StatusRequest
|
||||
}
|
||||
|
||||
pub fn ping_request(time: i64) -> Self {
|
||||
let ping_request = PingRequest { time };
|
||||
|
||||
Self::PingRequest(ping_request)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundStatusPacket {
|
||||
StatusResponse(StatusResponse),
|
||||
PingResponse(PingResponse),
|
||||
}
|
||||
|
||||
impl ClientBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusResponse(_) => 0x00,
|
||||
Self::PingResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let status_response = StatusResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::StatusResponse(status_response))
|
||||
}
|
||||
0x01 => {
|
||||
let ping_response = PingResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::PingResponse(ping_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_response(response: String) -> Self {
|
||||
let status_response = StatusResponse { response };
|
||||
|
||||
Self::StatusResponse(status_response)
|
||||
}
|
||||
|
||||
pub fn ping_response(time: i64) -> Self {
|
||||
let ping_response = PingResponse { time };
|
||||
|
||||
Self::PingResponse(ping_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingRequest {
|
||||
pub time: i64,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct StatusResponse {
|
||||
pub response: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingResponse {
|
||||
pub time: i64,
|
||||
}
|
2692
protocol/src/version/v_1_11/game.rs
Normal file
2692
protocol/src/version/v_1_11/game.rs
Normal file
File diff suppressed because it is too large
Load Diff
55
protocol/src/version/v_1_11/handshake.rs
Normal file
55
protocol/src/version/v_1_11/handshake.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundHandshakePacket {
|
||||
SetProtocol(SetProtocol),
|
||||
}
|
||||
|
||||
impl ServerBoundHandshakePacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::SetProtocol(_) => 0x00,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let set_protocol = SetProtocol::decode(reader)?;
|
||||
|
||||
Ok(Self::SetProtocol(set_protocol))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_protocol(
|
||||
protocol_version: i32,
|
||||
server_host: String,
|
||||
server_port: u16,
|
||||
next_state: i32,
|
||||
) -> Self {
|
||||
let set_protocol = SetProtocol {
|
||||
protocol_version,
|
||||
server_host,
|
||||
server_port,
|
||||
next_state,
|
||||
};
|
||||
|
||||
Self::SetProtocol(set_protocol)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct SetProtocol {
|
||||
#[packet(with = "var_int")]
|
||||
pub protocol_version: i32,
|
||||
pub server_host: String,
|
||||
pub server_port: u16,
|
||||
#[packet(with = "var_int")]
|
||||
pub next_state: i32,
|
||||
}
|
162
protocol/src/version/v_1_11/login.rs
Normal file
162
protocol/src/version/v_1_11/login.rs
Normal file
@@ -0,0 +1,162 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundLoginPacket {
|
||||
LoginStart(LoginStart),
|
||||
EncryptionResponse(EncryptionResponse),
|
||||
}
|
||||
|
||||
impl ServerBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::LoginStart(_) => 0x00,
|
||||
Self::EncryptionResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let login_start = LoginStart::decode(reader)?;
|
||||
|
||||
Ok(Self::LoginStart(login_start))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_response = EncryptionResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionResponse(encryption_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn login_start(username: String) -> Self {
|
||||
let login_start = LoginStart { username };
|
||||
|
||||
Self::LoginStart(login_start)
|
||||
}
|
||||
|
||||
pub fn encryption_response(shared_secret: Vec<u8>, verify_token: Vec<u8>) -> Self {
|
||||
let encryption_response = EncryptionResponse {
|
||||
shared_secret,
|
||||
verify_token,
|
||||
};
|
||||
|
||||
Self::EncryptionResponse(encryption_response)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundLoginPacket {
|
||||
Disconnect(Disconnect),
|
||||
EncryptionRequest(EncryptionRequest),
|
||||
Success(Success),
|
||||
Compress(Compress),
|
||||
}
|
||||
|
||||
impl ClientBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::Disconnect(_) => 0x00,
|
||||
Self::EncryptionRequest(_) => 0x01,
|
||||
Self::Success(_) => 0x02,
|
||||
Self::Compress(_) => 0x03,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let disconnect = Disconnect::decode(reader)?;
|
||||
|
||||
Ok(Self::Disconnect(disconnect))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_request = EncryptionRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionRequest(encryption_request))
|
||||
}
|
||||
0x02 => {
|
||||
let success = Success::decode(reader)?;
|
||||
|
||||
Ok(Self::Success(success))
|
||||
}
|
||||
0x03 => {
|
||||
let compress = Compress::decode(reader)?;
|
||||
|
||||
Ok(Self::Compress(compress))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disconnect(reason: String) -> Self {
|
||||
let disconnect = Disconnect { reason };
|
||||
|
||||
Self::Disconnect(disconnect)
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
Self::EncryptionRequest(encryption_request)
|
||||
}
|
||||
|
||||
pub fn success(uuid: String, username: String) -> Self {
|
||||
let success = Success { uuid, username };
|
||||
|
||||
Self::Success(success)
|
||||
}
|
||||
|
||||
pub fn compress(threshold: i32) -> Self {
|
||||
let compress = Compress { threshold };
|
||||
|
||||
Self::Compress(compress)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginStart {
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionResponse {
|
||||
pub shared_secret: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Disconnect {
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionRequest {
|
||||
pub server_id: String,
|
||||
pub public_key: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Success {
|
||||
pub uuid: String,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Compress {
|
||||
#[packet(with = "var_int")]
|
||||
pub threshold: i32,
|
||||
}
|
6
protocol/src/version/v_1_11/mod.rs
Normal file
6
protocol/src/version/v_1_11/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
pub mod game;
|
||||
pub mod handshake;
|
||||
pub mod login;
|
||||
pub mod status;
|
99
protocol/src/version/v_1_11/status.rs
Normal file
99
protocol/src/version/v_1_11/status.rs
Normal file
@@ -0,0 +1,99 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundStatusPacket {
|
||||
StatusRequest,
|
||||
PingRequest(PingRequest),
|
||||
}
|
||||
|
||||
impl ServerBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusRequest => 0x00,
|
||||
Self::PingRequest(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => Ok(Self::StatusRequest),
|
||||
0x01 => {
|
||||
let ping_request = PingRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::PingRequest(ping_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_request() -> Self {
|
||||
Self::StatusRequest
|
||||
}
|
||||
|
||||
pub fn ping_request(time: i64) -> Self {
|
||||
let ping_request = PingRequest { time };
|
||||
|
||||
Self::PingRequest(ping_request)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundStatusPacket {
|
||||
StatusResponse(StatusResponse),
|
||||
PingResponse(PingResponse),
|
||||
}
|
||||
|
||||
impl ClientBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusResponse(_) => 0x00,
|
||||
Self::PingResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let status_response = StatusResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::StatusResponse(status_response))
|
||||
}
|
||||
0x01 => {
|
||||
let ping_response = PingResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::PingResponse(ping_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_response(response: String) -> Self {
|
||||
let status_response = StatusResponse { response };
|
||||
|
||||
Self::StatusResponse(status_response)
|
||||
}
|
||||
|
||||
pub fn ping_response(time: i64) -> Self {
|
||||
let ping_response = PingResponse { time };
|
||||
|
||||
Self::PingResponse(ping_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingRequest {
|
||||
pub time: i64,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct StatusResponse {
|
||||
pub response: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingResponse {
|
||||
pub time: i64,
|
||||
}
|
2817
protocol/src/version/v_1_12/game.rs
Normal file
2817
protocol/src/version/v_1_12/game.rs
Normal file
File diff suppressed because it is too large
Load Diff
55
protocol/src/version/v_1_12/handshake.rs
Normal file
55
protocol/src/version/v_1_12/handshake.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundHandshakePacket {
|
||||
SetProtocol(SetProtocol),
|
||||
}
|
||||
|
||||
impl ServerBoundHandshakePacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::SetProtocol(_) => 0x00,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let set_protocol = SetProtocol::decode(reader)?;
|
||||
|
||||
Ok(Self::SetProtocol(set_protocol))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_protocol(
|
||||
protocol_version: i32,
|
||||
server_host: String,
|
||||
server_port: u16,
|
||||
next_state: i32,
|
||||
) -> Self {
|
||||
let set_protocol = SetProtocol {
|
||||
protocol_version,
|
||||
server_host,
|
||||
server_port,
|
||||
next_state,
|
||||
};
|
||||
|
||||
Self::SetProtocol(set_protocol)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct SetProtocol {
|
||||
#[packet(with = "var_int")]
|
||||
pub protocol_version: i32,
|
||||
pub server_host: String,
|
||||
pub server_port: u16,
|
||||
#[packet(with = "var_int")]
|
||||
pub next_state: i32,
|
||||
}
|
162
protocol/src/version/v_1_12/login.rs
Normal file
162
protocol/src/version/v_1_12/login.rs
Normal file
@@ -0,0 +1,162 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundLoginPacket {
|
||||
LoginStart(LoginStart),
|
||||
EncryptionResponse(EncryptionResponse),
|
||||
}
|
||||
|
||||
impl ServerBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::LoginStart(_) => 0x00,
|
||||
Self::EncryptionResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let login_start = LoginStart::decode(reader)?;
|
||||
|
||||
Ok(Self::LoginStart(login_start))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_response = EncryptionResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionResponse(encryption_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn login_start(username: String) -> Self {
|
||||
let login_start = LoginStart { username };
|
||||
|
||||
Self::LoginStart(login_start)
|
||||
}
|
||||
|
||||
pub fn encryption_response(shared_secret: Vec<u8>, verify_token: Vec<u8>) -> Self {
|
||||
let encryption_response = EncryptionResponse {
|
||||
shared_secret,
|
||||
verify_token,
|
||||
};
|
||||
|
||||
Self::EncryptionResponse(encryption_response)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundLoginPacket {
|
||||
Disconnect(Disconnect),
|
||||
EncryptionRequest(EncryptionRequest),
|
||||
Success(Success),
|
||||
Compress(Compress),
|
||||
}
|
||||
|
||||
impl ClientBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::Disconnect(_) => 0x00,
|
||||
Self::EncryptionRequest(_) => 0x01,
|
||||
Self::Success(_) => 0x02,
|
||||
Self::Compress(_) => 0x03,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let disconnect = Disconnect::decode(reader)?;
|
||||
|
||||
Ok(Self::Disconnect(disconnect))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_request = EncryptionRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionRequest(encryption_request))
|
||||
}
|
||||
0x02 => {
|
||||
let success = Success::decode(reader)?;
|
||||
|
||||
Ok(Self::Success(success))
|
||||
}
|
||||
0x03 => {
|
||||
let compress = Compress::decode(reader)?;
|
||||
|
||||
Ok(Self::Compress(compress))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disconnect(reason: String) -> Self {
|
||||
let disconnect = Disconnect { reason };
|
||||
|
||||
Self::Disconnect(disconnect)
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
Self::EncryptionRequest(encryption_request)
|
||||
}
|
||||
|
||||
pub fn success(uuid: String, username: String) -> Self {
|
||||
let success = Success { uuid, username };
|
||||
|
||||
Self::Success(success)
|
||||
}
|
||||
|
||||
pub fn compress(threshold: i32) -> Self {
|
||||
let compress = Compress { threshold };
|
||||
|
||||
Self::Compress(compress)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginStart {
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionResponse {
|
||||
pub shared_secret: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Disconnect {
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionRequest {
|
||||
pub server_id: String,
|
||||
pub public_key: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Success {
|
||||
pub uuid: String,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Compress {
|
||||
#[packet(with = "var_int")]
|
||||
pub threshold: i32,
|
||||
}
|
6
protocol/src/version/v_1_12/mod.rs
Normal file
6
protocol/src/version/v_1_12/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
pub mod game;
|
||||
pub mod handshake;
|
||||
pub mod login;
|
||||
pub mod status;
|
99
protocol/src/version/v_1_12/status.rs
Normal file
99
protocol/src/version/v_1_12/status.rs
Normal file
@@ -0,0 +1,99 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundStatusPacket {
|
||||
StatusRequest,
|
||||
PingRequest(PingRequest),
|
||||
}
|
||||
|
||||
impl ServerBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusRequest => 0x00,
|
||||
Self::PingRequest(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => Ok(Self::StatusRequest),
|
||||
0x01 => {
|
||||
let ping_request = PingRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::PingRequest(ping_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_request() -> Self {
|
||||
Self::StatusRequest
|
||||
}
|
||||
|
||||
pub fn ping_request(time: i64) -> Self {
|
||||
let ping_request = PingRequest { time };
|
||||
|
||||
Self::PingRequest(ping_request)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundStatusPacket {
|
||||
StatusResponse(StatusResponse),
|
||||
PingResponse(PingResponse),
|
||||
}
|
||||
|
||||
impl ClientBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusResponse(_) => 0x00,
|
||||
Self::PingResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let status_response = StatusResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::StatusResponse(status_response))
|
||||
}
|
||||
0x01 => {
|
||||
let ping_response = PingResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::PingResponse(ping_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_response(response: String) -> Self {
|
||||
let status_response = StatusResponse { response };
|
||||
|
||||
Self::StatusResponse(status_response)
|
||||
}
|
||||
|
||||
pub fn ping_response(time: i64) -> Self {
|
||||
let ping_response = PingResponse { time };
|
||||
|
||||
Self::PingResponse(ping_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingRequest {
|
||||
pub time: i64,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct StatusResponse {
|
||||
pub response: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingResponse {
|
||||
pub time: i64,
|
||||
}
|
2840
protocol/src/version/v_1_12_1/game.rs
Normal file
2840
protocol/src/version/v_1_12_1/game.rs
Normal file
File diff suppressed because it is too large
Load Diff
55
protocol/src/version/v_1_12_1/handshake.rs
Normal file
55
protocol/src/version/v_1_12_1/handshake.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundHandshakePacket {
|
||||
SetProtocol(SetProtocol),
|
||||
}
|
||||
|
||||
impl ServerBoundHandshakePacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::SetProtocol(_) => 0x00,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let set_protocol = SetProtocol::decode(reader)?;
|
||||
|
||||
Ok(Self::SetProtocol(set_protocol))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_protocol(
|
||||
protocol_version: i32,
|
||||
server_host: String,
|
||||
server_port: u16,
|
||||
next_state: i32,
|
||||
) -> Self {
|
||||
let set_protocol = SetProtocol {
|
||||
protocol_version,
|
||||
server_host,
|
||||
server_port,
|
||||
next_state,
|
||||
};
|
||||
|
||||
Self::SetProtocol(set_protocol)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct SetProtocol {
|
||||
#[packet(with = "var_int")]
|
||||
pub protocol_version: i32,
|
||||
pub server_host: String,
|
||||
pub server_port: u16,
|
||||
#[packet(with = "var_int")]
|
||||
pub next_state: i32,
|
||||
}
|
162
protocol/src/version/v_1_12_1/login.rs
Normal file
162
protocol/src/version/v_1_12_1/login.rs
Normal file
@@ -0,0 +1,162 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundLoginPacket {
|
||||
LoginStart(LoginStart),
|
||||
EncryptionResponse(EncryptionResponse),
|
||||
}
|
||||
|
||||
impl ServerBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::LoginStart(_) => 0x00,
|
||||
Self::EncryptionResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let login_start = LoginStart::decode(reader)?;
|
||||
|
||||
Ok(Self::LoginStart(login_start))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_response = EncryptionResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionResponse(encryption_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn login_start(username: String) -> Self {
|
||||
let login_start = LoginStart { username };
|
||||
|
||||
Self::LoginStart(login_start)
|
||||
}
|
||||
|
||||
pub fn encryption_response(shared_secret: Vec<u8>, verify_token: Vec<u8>) -> Self {
|
||||
let encryption_response = EncryptionResponse {
|
||||
shared_secret,
|
||||
verify_token,
|
||||
};
|
||||
|
||||
Self::EncryptionResponse(encryption_response)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundLoginPacket {
|
||||
Disconnect(Disconnect),
|
||||
EncryptionRequest(EncryptionRequest),
|
||||
Success(Success),
|
||||
Compress(Compress),
|
||||
}
|
||||
|
||||
impl ClientBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::Disconnect(_) => 0x00,
|
||||
Self::EncryptionRequest(_) => 0x01,
|
||||
Self::Success(_) => 0x02,
|
||||
Self::Compress(_) => 0x03,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let disconnect = Disconnect::decode(reader)?;
|
||||
|
||||
Ok(Self::Disconnect(disconnect))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_request = EncryptionRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionRequest(encryption_request))
|
||||
}
|
||||
0x02 => {
|
||||
let success = Success::decode(reader)?;
|
||||
|
||||
Ok(Self::Success(success))
|
||||
}
|
||||
0x03 => {
|
||||
let compress = Compress::decode(reader)?;
|
||||
|
||||
Ok(Self::Compress(compress))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disconnect(reason: String) -> Self {
|
||||
let disconnect = Disconnect { reason };
|
||||
|
||||
Self::Disconnect(disconnect)
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
Self::EncryptionRequest(encryption_request)
|
||||
}
|
||||
|
||||
pub fn success(uuid: String, username: String) -> Self {
|
||||
let success = Success { uuid, username };
|
||||
|
||||
Self::Success(success)
|
||||
}
|
||||
|
||||
pub fn compress(threshold: i32) -> Self {
|
||||
let compress = Compress { threshold };
|
||||
|
||||
Self::Compress(compress)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginStart {
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionResponse {
|
||||
pub shared_secret: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Disconnect {
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionRequest {
|
||||
pub server_id: String,
|
||||
pub public_key: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Success {
|
||||
pub uuid: String,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Compress {
|
||||
#[packet(with = "var_int")]
|
||||
pub threshold: i32,
|
||||
}
|
6
protocol/src/version/v_1_12_1/mod.rs
Normal file
6
protocol/src/version/v_1_12_1/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
pub mod game;
|
||||
pub mod handshake;
|
||||
pub mod login;
|
||||
pub mod status;
|
99
protocol/src/version/v_1_12_1/status.rs
Normal file
99
protocol/src/version/v_1_12_1/status.rs
Normal file
@@ -0,0 +1,99 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundStatusPacket {
|
||||
StatusRequest,
|
||||
PingRequest(PingRequest),
|
||||
}
|
||||
|
||||
impl ServerBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusRequest => 0x00,
|
||||
Self::PingRequest(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => Ok(Self::StatusRequest),
|
||||
0x01 => {
|
||||
let ping_request = PingRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::PingRequest(ping_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_request() -> Self {
|
||||
Self::StatusRequest
|
||||
}
|
||||
|
||||
pub fn ping_request(time: i64) -> Self {
|
||||
let ping_request = PingRequest { time };
|
||||
|
||||
Self::PingRequest(ping_request)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundStatusPacket {
|
||||
StatusResponse(StatusResponse),
|
||||
PingResponse(PingResponse),
|
||||
}
|
||||
|
||||
impl ClientBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusResponse(_) => 0x00,
|
||||
Self::PingResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let status_response = StatusResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::StatusResponse(status_response))
|
||||
}
|
||||
0x01 => {
|
||||
let ping_response = PingResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::PingResponse(ping_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_response(response: String) -> Self {
|
||||
let status_response = StatusResponse { response };
|
||||
|
||||
Self::StatusResponse(status_response)
|
||||
}
|
||||
|
||||
pub fn ping_response(time: i64) -> Self {
|
||||
let ping_response = PingResponse { time };
|
||||
|
||||
Self::PingResponse(ping_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingRequest {
|
||||
pub time: i64,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct StatusResponse {
|
||||
pub response: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingResponse {
|
||||
pub time: i64,
|
||||
}
|
2838
protocol/src/version/v_1_12_2/game.rs
Normal file
2838
protocol/src/version/v_1_12_2/game.rs
Normal file
File diff suppressed because it is too large
Load Diff
55
protocol/src/version/v_1_12_2/handshake.rs
Normal file
55
protocol/src/version/v_1_12_2/handshake.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundHandshakePacket {
|
||||
SetProtocol(SetProtocol),
|
||||
}
|
||||
|
||||
impl ServerBoundHandshakePacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::SetProtocol(_) => 0x00,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let set_protocol = SetProtocol::decode(reader)?;
|
||||
|
||||
Ok(Self::SetProtocol(set_protocol))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_protocol(
|
||||
protocol_version: i32,
|
||||
server_host: String,
|
||||
server_port: u16,
|
||||
next_state: i32,
|
||||
) -> Self {
|
||||
let set_protocol = SetProtocol {
|
||||
protocol_version,
|
||||
server_host,
|
||||
server_port,
|
||||
next_state,
|
||||
};
|
||||
|
||||
Self::SetProtocol(set_protocol)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct SetProtocol {
|
||||
#[packet(with = "var_int")]
|
||||
pub protocol_version: i32,
|
||||
pub server_host: String,
|
||||
pub server_port: u16,
|
||||
#[packet(with = "var_int")]
|
||||
pub next_state: i32,
|
||||
}
|
162
protocol/src/version/v_1_12_2/login.rs
Normal file
162
protocol/src/version/v_1_12_2/login.rs
Normal file
@@ -0,0 +1,162 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundLoginPacket {
|
||||
LoginStart(LoginStart),
|
||||
EncryptionResponse(EncryptionResponse),
|
||||
}
|
||||
|
||||
impl ServerBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::LoginStart(_) => 0x00,
|
||||
Self::EncryptionResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let login_start = LoginStart::decode(reader)?;
|
||||
|
||||
Ok(Self::LoginStart(login_start))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_response = EncryptionResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionResponse(encryption_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn login_start(username: String) -> Self {
|
||||
let login_start = LoginStart { username };
|
||||
|
||||
Self::LoginStart(login_start)
|
||||
}
|
||||
|
||||
pub fn encryption_response(shared_secret: Vec<u8>, verify_token: Vec<u8>) -> Self {
|
||||
let encryption_response = EncryptionResponse {
|
||||
shared_secret,
|
||||
verify_token,
|
||||
};
|
||||
|
||||
Self::EncryptionResponse(encryption_response)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundLoginPacket {
|
||||
Disconnect(Disconnect),
|
||||
EncryptionRequest(EncryptionRequest),
|
||||
Success(Success),
|
||||
Compress(Compress),
|
||||
}
|
||||
|
||||
impl ClientBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::Disconnect(_) => 0x00,
|
||||
Self::EncryptionRequest(_) => 0x01,
|
||||
Self::Success(_) => 0x02,
|
||||
Self::Compress(_) => 0x03,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let disconnect = Disconnect::decode(reader)?;
|
||||
|
||||
Ok(Self::Disconnect(disconnect))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_request = EncryptionRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionRequest(encryption_request))
|
||||
}
|
||||
0x02 => {
|
||||
let success = Success::decode(reader)?;
|
||||
|
||||
Ok(Self::Success(success))
|
||||
}
|
||||
0x03 => {
|
||||
let compress = Compress::decode(reader)?;
|
||||
|
||||
Ok(Self::Compress(compress))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disconnect(reason: String) -> Self {
|
||||
let disconnect = Disconnect { reason };
|
||||
|
||||
Self::Disconnect(disconnect)
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
Self::EncryptionRequest(encryption_request)
|
||||
}
|
||||
|
||||
pub fn success(uuid: String, username: String) -> Self {
|
||||
let success = Success { uuid, username };
|
||||
|
||||
Self::Success(success)
|
||||
}
|
||||
|
||||
pub fn compress(threshold: i32) -> Self {
|
||||
let compress = Compress { threshold };
|
||||
|
||||
Self::Compress(compress)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginStart {
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionResponse {
|
||||
pub shared_secret: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Disconnect {
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionRequest {
|
||||
pub server_id: String,
|
||||
pub public_key: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Success {
|
||||
pub uuid: String,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Compress {
|
||||
#[packet(with = "var_int")]
|
||||
pub threshold: i32,
|
||||
}
|
6
protocol/src/version/v_1_12_2/mod.rs
Normal file
6
protocol/src/version/v_1_12_2/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
pub mod game;
|
||||
pub mod handshake;
|
||||
pub mod login;
|
||||
pub mod status;
|
99
protocol/src/version/v_1_12_2/status.rs
Normal file
99
protocol/src/version/v_1_12_2/status.rs
Normal file
@@ -0,0 +1,99 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundStatusPacket {
|
||||
StatusRequest,
|
||||
PingRequest(PingRequest),
|
||||
}
|
||||
|
||||
impl ServerBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusRequest => 0x00,
|
||||
Self::PingRequest(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => Ok(Self::StatusRequest),
|
||||
0x01 => {
|
||||
let ping_request = PingRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::PingRequest(ping_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_request() -> Self {
|
||||
Self::StatusRequest
|
||||
}
|
||||
|
||||
pub fn ping_request(time: i64) -> Self {
|
||||
let ping_request = PingRequest { time };
|
||||
|
||||
Self::PingRequest(ping_request)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundStatusPacket {
|
||||
StatusResponse(StatusResponse),
|
||||
PingResponse(PingResponse),
|
||||
}
|
||||
|
||||
impl ClientBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusResponse(_) => 0x00,
|
||||
Self::PingResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let status_response = StatusResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::StatusResponse(status_response))
|
||||
}
|
||||
0x01 => {
|
||||
let ping_response = PingResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::PingResponse(ping_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_response(response: String) -> Self {
|
||||
let status_response = StatusResponse { response };
|
||||
|
||||
Self::StatusResponse(status_response)
|
||||
}
|
||||
|
||||
pub fn ping_response(time: i64) -> Self {
|
||||
let ping_response = PingResponse { time };
|
||||
|
||||
Self::PingResponse(ping_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingRequest {
|
||||
pub time: i64,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct StatusResponse {
|
||||
pub response: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingResponse {
|
||||
pub time: i64,
|
||||
}
|
2815
protocol/src/version/v_1_12_pre4/game.rs
Normal file
2815
protocol/src/version/v_1_12_pre4/game.rs
Normal file
File diff suppressed because it is too large
Load Diff
55
protocol/src/version/v_1_12_pre4/handshake.rs
Normal file
55
protocol/src/version/v_1_12_pre4/handshake.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundHandshakePacket {
|
||||
SetProtocol(SetProtocol),
|
||||
}
|
||||
|
||||
impl ServerBoundHandshakePacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::SetProtocol(_) => 0x00,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let set_protocol = SetProtocol::decode(reader)?;
|
||||
|
||||
Ok(Self::SetProtocol(set_protocol))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_protocol(
|
||||
protocol_version: i32,
|
||||
server_host: String,
|
||||
server_port: u16,
|
||||
next_state: i32,
|
||||
) -> Self {
|
||||
let set_protocol = SetProtocol {
|
||||
protocol_version,
|
||||
server_host,
|
||||
server_port,
|
||||
next_state,
|
||||
};
|
||||
|
||||
Self::SetProtocol(set_protocol)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct SetProtocol {
|
||||
#[packet(with = "var_int")]
|
||||
pub protocol_version: i32,
|
||||
pub server_host: String,
|
||||
pub server_port: u16,
|
||||
#[packet(with = "var_int")]
|
||||
pub next_state: i32,
|
||||
}
|
162
protocol/src/version/v_1_12_pre4/login.rs
Normal file
162
protocol/src/version/v_1_12_pre4/login.rs
Normal file
@@ -0,0 +1,162 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundLoginPacket {
|
||||
LoginStart(LoginStart),
|
||||
EncryptionResponse(EncryptionResponse),
|
||||
}
|
||||
|
||||
impl ServerBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::LoginStart(_) => 0x00,
|
||||
Self::EncryptionResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let login_start = LoginStart::decode(reader)?;
|
||||
|
||||
Ok(Self::LoginStart(login_start))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_response = EncryptionResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionResponse(encryption_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn login_start(username: String) -> Self {
|
||||
let login_start = LoginStart { username };
|
||||
|
||||
Self::LoginStart(login_start)
|
||||
}
|
||||
|
||||
pub fn encryption_response(shared_secret: Vec<u8>, verify_token: Vec<u8>) -> Self {
|
||||
let encryption_response = EncryptionResponse {
|
||||
shared_secret,
|
||||
verify_token,
|
||||
};
|
||||
|
||||
Self::EncryptionResponse(encryption_response)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundLoginPacket {
|
||||
Disconnect(Disconnect),
|
||||
EncryptionRequest(EncryptionRequest),
|
||||
Success(Success),
|
||||
Compress(Compress),
|
||||
}
|
||||
|
||||
impl ClientBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::Disconnect(_) => 0x00,
|
||||
Self::EncryptionRequest(_) => 0x01,
|
||||
Self::Success(_) => 0x02,
|
||||
Self::Compress(_) => 0x03,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let disconnect = Disconnect::decode(reader)?;
|
||||
|
||||
Ok(Self::Disconnect(disconnect))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_request = EncryptionRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionRequest(encryption_request))
|
||||
}
|
||||
0x02 => {
|
||||
let success = Success::decode(reader)?;
|
||||
|
||||
Ok(Self::Success(success))
|
||||
}
|
||||
0x03 => {
|
||||
let compress = Compress::decode(reader)?;
|
||||
|
||||
Ok(Self::Compress(compress))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disconnect(reason: String) -> Self {
|
||||
let disconnect = Disconnect { reason };
|
||||
|
||||
Self::Disconnect(disconnect)
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
Self::EncryptionRequest(encryption_request)
|
||||
}
|
||||
|
||||
pub fn success(uuid: String, username: String) -> Self {
|
||||
let success = Success { uuid, username };
|
||||
|
||||
Self::Success(success)
|
||||
}
|
||||
|
||||
pub fn compress(threshold: i32) -> Self {
|
||||
let compress = Compress { threshold };
|
||||
|
||||
Self::Compress(compress)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginStart {
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionResponse {
|
||||
pub shared_secret: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Disconnect {
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionRequest {
|
||||
pub server_id: String,
|
||||
pub public_key: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Success {
|
||||
pub uuid: String,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Compress {
|
||||
#[packet(with = "var_int")]
|
||||
pub threshold: i32,
|
||||
}
|
6
protocol/src/version/v_1_12_pre4/mod.rs
Normal file
6
protocol/src/version/v_1_12_pre4/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
pub mod game;
|
||||
pub mod handshake;
|
||||
pub mod login;
|
||||
pub mod status;
|
99
protocol/src/version/v_1_12_pre4/status.rs
Normal file
99
protocol/src/version/v_1_12_pre4/status.rs
Normal file
@@ -0,0 +1,99 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundStatusPacket {
|
||||
StatusRequest,
|
||||
PingRequest(PingRequest),
|
||||
}
|
||||
|
||||
impl ServerBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusRequest => 0x00,
|
||||
Self::PingRequest(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => Ok(Self::StatusRequest),
|
||||
0x01 => {
|
||||
let ping_request = PingRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::PingRequest(ping_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_request() -> Self {
|
||||
Self::StatusRequest
|
||||
}
|
||||
|
||||
pub fn ping_request(time: i64) -> Self {
|
||||
let ping_request = PingRequest { time };
|
||||
|
||||
Self::PingRequest(ping_request)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundStatusPacket {
|
||||
StatusResponse(StatusResponse),
|
||||
PingResponse(PingResponse),
|
||||
}
|
||||
|
||||
impl ClientBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusResponse(_) => 0x00,
|
||||
Self::PingResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let status_response = StatusResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::StatusResponse(status_response))
|
||||
}
|
||||
0x01 => {
|
||||
let ping_response = PingResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::PingResponse(ping_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_response(response: String) -> Self {
|
||||
let status_response = StatusResponse { response };
|
||||
|
||||
Self::StatusResponse(status_response)
|
||||
}
|
||||
|
||||
pub fn ping_response(time: i64) -> Self {
|
||||
let ping_response = PingResponse { time };
|
||||
|
||||
Self::PingResponse(ping_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingRequest {
|
||||
pub time: i64,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct StatusResponse {
|
||||
pub response: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingResponse {
|
||||
pub time: i64,
|
||||
}
|
3257
protocol/src/version/v_1_13/game.rs
Normal file
3257
protocol/src/version/v_1_13/game.rs
Normal file
File diff suppressed because it is too large
Load Diff
55
protocol/src/version/v_1_13/handshake.rs
Normal file
55
protocol/src/version/v_1_13/handshake.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundHandshakePacket {
|
||||
SetProtocol(SetProtocol),
|
||||
}
|
||||
|
||||
impl ServerBoundHandshakePacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::SetProtocol(_) => 0x00,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let set_protocol = SetProtocol::decode(reader)?;
|
||||
|
||||
Ok(Self::SetProtocol(set_protocol))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_protocol(
|
||||
protocol_version: i32,
|
||||
server_host: String,
|
||||
server_port: u16,
|
||||
next_state: i32,
|
||||
) -> Self {
|
||||
let set_protocol = SetProtocol {
|
||||
protocol_version,
|
||||
server_host,
|
||||
server_port,
|
||||
next_state,
|
||||
};
|
||||
|
||||
Self::SetProtocol(set_protocol)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct SetProtocol {
|
||||
#[packet(with = "var_int")]
|
||||
pub protocol_version: i32,
|
||||
pub server_host: String,
|
||||
pub server_port: u16,
|
||||
#[packet(with = "var_int")]
|
||||
pub next_state: i32,
|
||||
}
|
209
protocol/src/version/v_1_13/login.rs
Normal file
209
protocol/src/version/v_1_13/login.rs
Normal file
@@ -0,0 +1,209 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundLoginPacket {
|
||||
LoginStart(LoginStart),
|
||||
EncryptionResponse(EncryptionResponse),
|
||||
LoginPluginResponse(LoginPluginResponse),
|
||||
}
|
||||
|
||||
impl ServerBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::LoginStart(_) => 0x00,
|
||||
Self::EncryptionResponse(_) => 0x01,
|
||||
Self::LoginPluginResponse(_) => 0x02,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let login_start = LoginStart::decode(reader)?;
|
||||
|
||||
Ok(Self::LoginStart(login_start))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_response = EncryptionResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionResponse(encryption_response))
|
||||
}
|
||||
0x02 => {
|
||||
let login_plugin_response = LoginPluginResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::LoginPluginResponse(login_plugin_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn login_start(username: String) -> Self {
|
||||
let login_start = LoginStart { username };
|
||||
|
||||
Self::LoginStart(login_start)
|
||||
}
|
||||
|
||||
pub fn encryption_response(shared_secret: Vec<u8>, verify_token: Vec<u8>) -> Self {
|
||||
let encryption_response = EncryptionResponse {
|
||||
shared_secret,
|
||||
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 };
|
||||
|
||||
Self::LoginPluginResponse(login_plugin_response)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundLoginPacket {
|
||||
Disconnect(Disconnect),
|
||||
EncryptionRequest(EncryptionRequest),
|
||||
Success(Success),
|
||||
Compress(Compress),
|
||||
LoginPluginRequest(LoginPluginRequest),
|
||||
}
|
||||
|
||||
impl ClientBoundLoginPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::Disconnect(_) => 0x00,
|
||||
Self::EncryptionRequest(_) => 0x01,
|
||||
Self::Success(_) => 0x02,
|
||||
Self::Compress(_) => 0x03,
|
||||
Self::LoginPluginRequest(_) => 0x04,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let disconnect = Disconnect::decode(reader)?;
|
||||
|
||||
Ok(Self::Disconnect(disconnect))
|
||||
}
|
||||
0x01 => {
|
||||
let encryption_request = EncryptionRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::EncryptionRequest(encryption_request))
|
||||
}
|
||||
0x02 => {
|
||||
let success = Success::decode(reader)?;
|
||||
|
||||
Ok(Self::Success(success))
|
||||
}
|
||||
0x03 => {
|
||||
let compress = Compress::decode(reader)?;
|
||||
|
||||
Ok(Self::Compress(compress))
|
||||
}
|
||||
0x04 => {
|
||||
let login_plugin_request = LoginPluginRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::LoginPluginRequest(login_plugin_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disconnect(reason: String) -> Self {
|
||||
let disconnect = Disconnect { reason };
|
||||
|
||||
Self::Disconnect(disconnect)
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
Self::EncryptionRequest(encryption_request)
|
||||
}
|
||||
|
||||
pub fn success(uuid: String, username: String) -> Self {
|
||||
let success = Success { uuid, username };
|
||||
|
||||
Self::Success(success)
|
||||
}
|
||||
|
||||
pub fn compress(threshold: i32) -> Self {
|
||||
let compress = Compress { threshold };
|
||||
|
||||
Self::Compress(compress)
|
||||
}
|
||||
|
||||
pub fn login_plugin_request(message_id: i32, channel: String, data: Vec<u8>) -> Self {
|
||||
let login_plugin_request = LoginPluginRequest {
|
||||
message_id,
|
||||
channel,
|
||||
data,
|
||||
};
|
||||
|
||||
Self::LoginPluginRequest(login_plugin_request)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginStart {
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionResponse {
|
||||
pub shared_secret: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginPluginResponse {
|
||||
#[packet(with = "var_int")]
|
||||
pub message_id: i32,
|
||||
#[packet(with = "rest")]
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Disconnect {
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct EncryptionRequest {
|
||||
pub server_id: String,
|
||||
pub public_key: Vec<u8>,
|
||||
pub verify_token: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Success {
|
||||
pub uuid: String,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct Compress {
|
||||
#[packet(with = "var_int")]
|
||||
pub threshold: i32,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct LoginPluginRequest {
|
||||
#[packet(with = "var_int")]
|
||||
pub message_id: i32,
|
||||
pub channel: String,
|
||||
#[packet(with = "rest")]
|
||||
pub data: Vec<u8>,
|
||||
}
|
6
protocol/src/version/v_1_13/mod.rs
Normal file
6
protocol/src/version/v_1_13/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
pub mod game;
|
||||
pub mod handshake;
|
||||
pub mod login;
|
||||
pub mod status;
|
99
protocol/src/version/v_1_13/status.rs
Normal file
99
protocol/src/version/v_1_13/status.rs
Normal file
@@ -0,0 +1,99 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum ServerBoundStatusPacket {
|
||||
StatusRequest,
|
||||
PingRequest(PingRequest),
|
||||
}
|
||||
|
||||
impl ServerBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusRequest => 0x00,
|
||||
Self::PingRequest(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => Ok(Self::StatusRequest),
|
||||
0x01 => {
|
||||
let ping_request = PingRequest::decode(reader)?;
|
||||
|
||||
Ok(Self::PingRequest(ping_request))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_request() -> Self {
|
||||
Self::StatusRequest
|
||||
}
|
||||
|
||||
pub fn ping_request(time: i64) -> Self {
|
||||
let ping_request = PingRequest { time };
|
||||
|
||||
Self::PingRequest(ping_request)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClientBoundStatusPacket {
|
||||
StatusResponse(StatusResponse),
|
||||
PingResponse(PingResponse),
|
||||
}
|
||||
|
||||
impl ClientBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusResponse(_) => 0x00,
|
||||
Self::PingResponse(_) => 0x01,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode<R: Read>(type_id: u8, reader: &mut R) -> Result<Self, DecodeError> {
|
||||
match type_id {
|
||||
0x00 => {
|
||||
let status_response = StatusResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::StatusResponse(status_response))
|
||||
}
|
||||
0x01 => {
|
||||
let ping_response = PingResponse::decode(reader)?;
|
||||
|
||||
Ok(Self::PingResponse(ping_response))
|
||||
}
|
||||
_ => Err(DecodeError::UnknownPacketType { type_id }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_response(response: String) -> Self {
|
||||
let status_response = StatusResponse { response };
|
||||
|
||||
Self::StatusResponse(status_response)
|
||||
}
|
||||
|
||||
pub fn ping_response(time: i64) -> Self {
|
||||
let ping_response = PingResponse { time };
|
||||
|
||||
Self::PingResponse(ping_response)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingRequest {
|
||||
pub time: i64,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct StatusResponse {
|
||||
pub response: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct PingResponse {
|
||||
pub time: i64,
|
||||
}
|
3263
protocol/src/version/v_1_13_1/game.rs
Normal file
3263
protocol/src/version/v_1_13_1/game.rs
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user