Add multi version support
This commit is contained in:
parent
b043dbb07b
commit
a121323eed
@ -10,7 +10,6 @@ repository = "https://github.com/eihwaz/minecraft-protocol"
|
||||
keywords = ["minecraft", "cli", "protocol", "packet", "io"]
|
||||
|
||||
[dependencies]
|
||||
structopt = "0.3"
|
||||
serde = "1.0.120"
|
||||
serde_json = "1.0"
|
||||
handlebars = "3.5.2"
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit e656aafb77f477d3726ed46209f0d4bb7052a04b
|
||||
Subproject commit cc155f399397755abeb9275de40fc82b65a252f4
|
@ -26,7 +26,8 @@ pub struct Packets {
|
||||
#[serde(untagged)]
|
||||
pub enum Data {
|
||||
Type(String),
|
||||
Container(Vec<Container>),
|
||||
Containers(Vec<Container>),
|
||||
Container(Box<Container>),
|
||||
Mapper {
|
||||
#[serde(rename = "type")]
|
||||
mappings_type: String,
|
||||
|
@ -1,13 +1,16 @@
|
||||
use crate::frontend;
|
||||
use crate::mappings::Mappings;
|
||||
use crate::{backend, frontend, transformers};
|
||||
use handlebars::{Handlebars, TemplateRenderError};
|
||||
use serde::Serialize;
|
||||
use serde_json::json;
|
||||
use std::collections::HashSet;
|
||||
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, Copy, Clone)]
|
||||
#[derive(Debug)]
|
||||
pub enum State {
|
||||
Handshake,
|
||||
Status,
|
||||
@ -16,7 +19,7 @@ pub enum State {
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub fn data_import(&self) -> &str {
|
||||
pub fn data_import(&self) -> &'static str {
|
||||
match self {
|
||||
State::Handshake => "crate::data::handshake::*",
|
||||
State::Status => "crate::data::status::*",
|
||||
@ -109,6 +112,8 @@ pub enum DataType {
|
||||
Int {
|
||||
var_int: bool,
|
||||
},
|
||||
#[serde(rename(serialize = "u32"))]
|
||||
UnsignedInt,
|
||||
#[serde(rename(serialize = "i64"))]
|
||||
Long {
|
||||
var_long: bool,
|
||||
@ -136,7 +141,7 @@ pub enum DataType {
|
||||
}
|
||||
|
||||
impl DataType {
|
||||
pub fn import<'a>(&self, state: &'a State) -> Option<&'a str> {
|
||||
pub fn import(&self, state: &State) -> Option<&'static str> {
|
||||
match self {
|
||||
DataType::Uuid { .. } => Some("uuid::Uuid"),
|
||||
DataType::CompoundTag => Some("nbt::CompoundTag"),
|
||||
@ -149,75 +154,156 @@ impl DataType {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Protocol {
|
||||
pub state: State,
|
||||
pub server_bound_packets: Vec<Packet>,
|
||||
pub client_bound_packets: Vec<Packet>,
|
||||
}
|
||||
|
||||
impl Protocol {
|
||||
pub fn new(
|
||||
state: State,
|
||||
server_bound_packets: Vec<Packet>,
|
||||
client_bound_packets: Vec<Packet>,
|
||||
) -> Protocol {
|
||||
pub fn new(server_bound_packets: Vec<Packet>, client_bound_packets: Vec<Packet>) -> Protocol {
|
||||
Protocol {
|
||||
state,
|
||||
server_bound_packets,
|
||||
client_bound_packets,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn data_type_imports(&self) -> HashSet<&str> {
|
||||
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(&self.state))
|
||||
.filter_map(|f| f.data_type.import(state))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct GenerateContext<'a> {
|
||||
packet_enum_name: String,
|
||||
packets: &'a Vec<frontend::Packet>,
|
||||
}
|
||||
|
||||
pub fn generate_rust_file<W: Write>(
|
||||
protocol: &frontend::Protocol,
|
||||
pub fn generate_rust_files<M: Mappings>(
|
||||
versions_data: HashMap<String, File>,
|
||||
template_engine: &Handlebars,
|
||||
mut writer: W,
|
||||
mappings: &M,
|
||||
) -> Result<(), TemplateRenderError> {
|
||||
let server_bound_ctx = GenerateContext {
|
||||
packet_enum_name: format!("{}{}BoundPacket", &protocol.state, frontend::Bound::Server),
|
||||
packets: &protocol.server_bound_packets,
|
||||
};
|
||||
generate_versions_module_file(template_engine, versions_data.keys().cloned().collect())?;
|
||||
|
||||
let client_bound_ctx = GenerateContext {
|
||||
packet_enum_name: format!("{}{}BoundPacket", &protocol.state, frontend::Bound::Client),
|
||||
packets: &protocol.client_bound_packets,
|
||||
};
|
||||
for (version, data_file) in versions_data.iter() {
|
||||
println!("Generating protocol data for version {}", version);
|
||||
|
||||
let mut imports = vec![
|
||||
"crate::DecodeError",
|
||||
"crate::Decoder",
|
||||
"std::io::Read",
|
||||
"minecraft_protocol_derive::Packet",
|
||||
];
|
||||
let protocol_handler: backend::ProtocolHandler =
|
||||
serde_json::from_reader(data_file).expect("Failed to parse protocol data");
|
||||
|
||||
imports.extend(protocol.data_type_imports().iter());
|
||||
let frontend_protocols =
|
||||
transformers::transform_protocol_handler(mappings, &protocol_handler);
|
||||
|
||||
template_engine.render_to_write(
|
||||
"packet_imports",
|
||||
&json!({ "imports": imports }),
|
||||
&mut writer,
|
||||
)?;
|
||||
let formatted_version = version.replace(".", "_").replace("-", "_");
|
||||
|
||||
template_engine.render_to_write("packet_enum", &server_bound_ctx, &mut writer)?;
|
||||
template_engine.render_to_write("packet_enum", &client_bound_ctx, &mut writer)?;
|
||||
let folder_name = format!("protocol/src/version/v_{}", formatted_version);
|
||||
let folder_path = Path::new(&folder_name);
|
||||
|
||||
template_engine.render_to_write("packet_structs", &server_bound_ctx, &mut writer)?;
|
||||
template_engine.render_to_write("packet_structs", &client_bound_ctx, &mut writer)?;
|
||||
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(())
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
use std::fs::File;
|
||||
|
||||
use crate::mappings::CodeMappings;
|
||||
use structopt::StructOpt;
|
||||
use std::fs;
|
||||
use std::io::Error;
|
||||
use std::path::Path;
|
||||
|
||||
pub mod backend;
|
||||
pub mod frontend;
|
||||
@ -9,74 +11,47 @@ pub mod mappings;
|
||||
pub mod templates;
|
||||
pub mod transformers;
|
||||
|
||||
#[derive(StructOpt)]
|
||||
#[structopt(name = "protocol-generator")]
|
||||
struct Opt {
|
||||
#[structopt(short, long, default_value = "1.14.4")]
|
||||
protocol_version: String,
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let opt: Opt = Opt::from_args();
|
||||
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();
|
||||
|
||||
let protocol_data_file_name = format!(
|
||||
"protocol-generator/minecraft-data/data/pc/{}/protocol.json",
|
||||
opt.protocol_version
|
||||
);
|
||||
|
||||
let protocol_data_file =
|
||||
File::open(protocol_data_file_name).expect("Failed to open protocol data file");
|
||||
|
||||
let protocol_handler: backend::ProtocolHandler =
|
||||
serde_json::from_reader(protocol_data_file).expect("Failed to parse protocol data");
|
||||
|
||||
let mappings = CodeMappings {};
|
||||
|
||||
let protocols = vec![
|
||||
(
|
||||
transformers::transform_protocol(
|
||||
&mappings,
|
||||
frontend::State::Handshake,
|
||||
&protocol_handler.handshaking,
|
||||
),
|
||||
frontend::State::Handshake,
|
||||
),
|
||||
(
|
||||
transformers::transform_protocol(
|
||||
&mappings,
|
||||
frontend::State::Status,
|
||||
&protocol_handler.status,
|
||||
),
|
||||
frontend::State::Status,
|
||||
),
|
||||
(
|
||||
transformers::transform_protocol(
|
||||
&mappings,
|
||||
frontend::State::Login,
|
||||
&protocol_handler.login,
|
||||
),
|
||||
frontend::State::Login,
|
||||
),
|
||||
(
|
||||
transformers::transform_protocol(
|
||||
&mappings,
|
||||
frontend::State::Game,
|
||||
&protocol_handler.game,
|
||||
),
|
||||
frontend::State::Game,
|
||||
),
|
||||
];
|
||||
|
||||
for (protocol, state) in protocols {
|
||||
let file_name = format!(
|
||||
"protocol/src/packet/{}.rs",
|
||||
state.to_string().to_lowercase()
|
||||
);
|
||||
|
||||
let file = File::create(file_name).expect("Failed to create file");
|
||||
|
||||
frontend::generate_rust_file(&protocol, &template_engine, &file)
|
||||
.expect("Failed to generate rust file");
|
||||
}
|
||||
frontend::generate_rust_files(versions_data, &template_engine, &mappings)
|
||||
.expect("Failed to generate rust files");
|
||||
}
|
||||
|
@ -15,6 +15,12 @@ pub trait Mappings {
|
||||
|
||||
pub struct CodeMappings {}
|
||||
|
||||
impl CodeMappings {
|
||||
pub fn new() -> CodeMappings {
|
||||
CodeMappings {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Mappings for CodeMappings {
|
||||
fn rename_packet(
|
||||
&self,
|
||||
@ -50,15 +56,15 @@ impl Mappings for CodeMappings {
|
||||
|
||||
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(),
|
||||
}),
|
||||
// ("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,
|
||||
}
|
||||
}
|
||||
|
@ -6,30 +6,25 @@ pub fn create_template_engine() -> Handlebars<'static> {
|
||||
|
||||
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());
|
||||
|
||||
template_engine
|
||||
.register_template_file(
|
||||
"packet_imports",
|
||||
"protocol-generator/templates/packet_imports.hbs",
|
||||
)
|
||||
.expect("Failed to register template");
|
||||
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
|
||||
.register_template_file(
|
||||
"packet_enum",
|
||||
"protocol-generator/templates/packet_enum.hbs",
|
||||
)
|
||||
.expect("Failed to register template");
|
||||
}
|
||||
|
||||
fn register_template_file(template_engine: &mut Handlebars, name: &str) {
|
||||
template_engine
|
||||
.register_template_file(
|
||||
"packet_structs",
|
||||
"protocol-generator/templates/packet_structs.hbs",
|
||||
)
|
||||
.register_template_file(name, format!("protocol-generator/templates/{}.hbs", name))
|
||||
.expect("Failed to register template");
|
||||
|
||||
template_engine
|
||||
}
|
||||
|
||||
fn format_snake_case(
|
||||
@ -71,3 +66,24 @@ fn format_packet_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(())
|
||||
}
|
||||
|
@ -1,12 +1,34 @@
|
||||
use crate::backend::Data;
|
||||
use crate::mappings::Mappings;
|
||||
use crate::{backend, frontend};
|
||||
use heck::{CamelCase, SnakeCase};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn transform_protocol<M: Mappings>(
|
||||
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,
|
||||
state: frontend::State,
|
||||
protocol: &backend::Protocol,
|
||||
) -> frontend::Protocol {
|
||||
let server_bound_packets = transform_packets(
|
||||
@ -24,7 +46,6 @@ pub fn transform_protocol<M: Mappings>(
|
||||
);
|
||||
|
||||
frontend::Protocol {
|
||||
state,
|
||||
server_bound_packets,
|
||||
client_bound_packets,
|
||||
}
|
||||
@ -36,7 +57,7 @@ fn get_packet_ids(packets: &backend::Packets) -> HashMap<String, u8> {
|
||||
.get("packet")
|
||||
.and_then(|d| d.get(1))
|
||||
.and_then(|d| match d {
|
||||
backend::Data::Container(data) => data.get(0),
|
||||
backend::Data::Containers(data) => data.get(0),
|
||||
_ => None,
|
||||
})
|
||||
.and_then(|c| match c {
|
||||
@ -92,7 +113,7 @@ fn transform_packets<M: Mappings>(
|
||||
let mut fields = vec![];
|
||||
|
||||
for data in data_vec {
|
||||
if let backend::Data::Container(container_vec) = data {
|
||||
if let backend::Data::Containers(container_vec) = data {
|
||||
for container in container_vec {
|
||||
match container {
|
||||
backend::Container::Value { name, data } => {
|
||||
@ -183,6 +204,7 @@ fn transform_data_type(name: &str) -> Option<frontend::DataType> {
|
||||
"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 }),
|
||||
|
@ -1,15 +1,15 @@
|
||||
{{~#if packets}}
|
||||
pub enum {{packet_enum_name}} {
|
||||
pub enum {{protocol_enum_name}} {
|
||||
{{~#each packets as |p|}}
|
||||
{{p.name}}{{#if p.fields}}({{p.name}}){{/if}}{{#unless @last}},{{/unless}}
|
||||
{{p.name}}{{#if p.fields}}({{p.name}}){{/if}},
|
||||
{{~/each}}
|
||||
}
|
||||
|
||||
impl {{packet_enum_name}} {
|
||||
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}}{{#unless @last}},{{/unless}}
|
||||
Self::{{p.name}}{{#if p.fields}}(_){{/if}} => {{packet_id p.id}},
|
||||
{{~/each}}
|
||||
}
|
||||
}
|
||||
@ -36,7 +36,7 @@ impl {{packet_enum_name}} {
|
||||
{{~#if p.fields}}
|
||||
let {{snake_case p.name}} = {{p.name}} {
|
||||
{{~#each p.fields as |f|}}
|
||||
{{f.name}}{{#unless @last}},{{/unless}}
|
||||
{{f.name}},
|
||||
{{~/each}}
|
||||
};
|
||||
|
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~}}
|
@ -1,5 +1,6 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
{{#each imports as |i|~}}
|
||||
use {{i}};
|
||||
{{/each~}}
|
||||
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~}}
|
@ -1,47 +0,0 @@
|
||||
use crate::impl_enum_encoder_decoder;
|
||||
use nbt::CompoundTag;
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use std::io::{Read, Write};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, FromPrimitive, ToPrimitive)]
|
||||
pub enum MessagePosition {
|
||||
Chat,
|
||||
System,
|
||||
HotBar,
|
||||
}
|
||||
|
||||
impl_enum_encoder_decoder!(MessagePosition);
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, FromPrimitive, ToPrimitive)]
|
||||
pub enum GameMode {
|
||||
Survival = 0,
|
||||
Creative = 1,
|
||||
Adventure = 2,
|
||||
Spectator = 3,
|
||||
Hardcore = 8,
|
||||
}
|
||||
|
||||
impl_enum_encoder_decoder!(GameMode);
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Position {
|
||||
pub x: i32,
|
||||
pub y: i16,
|
||||
pub z: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Slot {
|
||||
pub id: i32,
|
||||
pub amount: u8,
|
||||
pub compound_tag: CompoundTag,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Metadata {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TagsMap {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ParticleData {}
|
@ -1,3 +1,2 @@
|
||||
pub mod chat;
|
||||
pub mod game;
|
||||
pub mod status;
|
||||
pub mod server_status;
|
||||
|
@ -10,12 +10,11 @@ use uuid::Uuid;
|
||||
|
||||
use data::chat::Message;
|
||||
|
||||
use crate::data::game::{Metadata, ParticleData, Position, Slot, TagsMap};
|
||||
use crate::error::{DecodeError, EncodeError};
|
||||
|
||||
pub mod data;
|
||||
pub mod error;
|
||||
pub mod packet;
|
||||
pub mod version;
|
||||
|
||||
/// Current supported protocol version.
|
||||
pub const PROTOCOL_VERSION: u32 = 498;
|
||||
@ -510,123 +509,6 @@ macro_rules! impl_json_encoder_decoder (
|
||||
);
|
||||
);
|
||||
|
||||
impl Encoder for Position {
|
||||
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
|
||||
let encoded_x = (self.x & 0x3FFFFFF) as i64;
|
||||
let encoded_y = (self.y & 0xFFF) as i64;
|
||||
let encoded_z = (self.z & 0x3FFFFFF) as i64;
|
||||
|
||||
writer.write_i64::<BigEndian>((encoded_x << 38) | (encoded_z << 12) | encoded_y)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Decoder for Position {
|
||||
type Output = Self;
|
||||
|
||||
fn decode<R: Read>(reader: &mut R) -> Result<Self::Output, DecodeError> {
|
||||
let encoded = reader.read_i64::<BigEndian>()?;
|
||||
|
||||
let x = (encoded >> 38) as i32;
|
||||
let y = (encoded & 0xFFF) as i16;
|
||||
let z = (encoded << 26 >> 38) as i32;
|
||||
|
||||
Ok(Position { x, y, z })
|
||||
}
|
||||
}
|
||||
|
||||
impl Encoder for Option<Slot> {
|
||||
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
|
||||
match self {
|
||||
Some(slot) => {
|
||||
writer.write_bool(true)?;
|
||||
slot.encode(writer)
|
||||
}
|
||||
None => writer.write_bool(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Decoder for Option<Slot> {
|
||||
type Output = Self;
|
||||
|
||||
fn decode<R: Read>(reader: &mut R) -> Result<Self::Output, DecodeError> {
|
||||
if reader.read_bool()? {
|
||||
Ok(Some(Slot::decode(reader)?))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Encoder for Slot {
|
||||
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
|
||||
writer.write_var_i32(self.id)?;
|
||||
writer.write_u8(self.amount)?;
|
||||
writer.write_compound_tag(&self.compound_tag)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Decoder for Slot {
|
||||
type Output = Self;
|
||||
|
||||
fn decode<R: Read>(reader: &mut R) -> Result<Self::Output, DecodeError> {
|
||||
let id = reader.read_var_i32()?;
|
||||
let amount = reader.read_u8()?;
|
||||
let compound_tag = reader.read_compound_tag()?;
|
||||
|
||||
Ok(Slot {
|
||||
id,
|
||||
amount,
|
||||
compound_tag,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Encoder for Metadata {
|
||||
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Decoder for Metadata {
|
||||
type Output = Self;
|
||||
|
||||
fn decode<R: Read>(reader: &mut R) -> Result<Self::Output, DecodeError> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Encoder for TagsMap {
|
||||
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Decoder for TagsMap {
|
||||
type Output = Self;
|
||||
|
||||
fn decode<R: Read>(reader: &mut R) -> Result<Self::Output, DecodeError> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Encoder for ParticleData {
|
||||
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Decoder for ParticleData {
|
||||
type Output = Self;
|
||||
|
||||
fn decode<R: Read>(reader: &mut R) -> Result<Self::Output, DecodeError> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
mod var_int {
|
||||
use std::io::{Read, Write};
|
||||
|
||||
|
@ -1,4 +0,0 @@
|
||||
pub mod game;
|
||||
pub mod handshake;
|
||||
pub mod login;
|
||||
pub mod status;
|
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
@ -5,11 +5,11 @@ use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum HandshakeServerBoundPacket {
|
||||
pub enum ServerBoundHandshakePacket {
|
||||
SetProtocol(SetProtocol),
|
||||
}
|
||||
|
||||
impl HandshakeServerBoundPacket {
|
||||
impl ServerBoundHandshakePacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::SetProtocol(_) => 0x00,
|
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;
|
@ -1,17 +1,16 @@
|
||||
// This file is automatically generated.
|
||||
// It is not intended for manual editing.
|
||||
use crate::data::status::*;
|
||||
use crate::DecodeError;
|
||||
use crate::Decoder;
|
||||
use minecraft_protocol_derive::Packet;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum StatusServerBoundPacket {
|
||||
pub enum ServerBoundStatusPacket {
|
||||
StatusRequest,
|
||||
PingRequest(PingRequest),
|
||||
}
|
||||
|
||||
impl StatusServerBoundPacket {
|
||||
impl ServerBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusRequest => 0x00,
|
||||
@ -42,12 +41,12 @@ impl StatusServerBoundPacket {
|
||||
}
|
||||
}
|
||||
|
||||
pub enum StatusClientBoundPacket {
|
||||
pub enum ClientBoundStatusPacket {
|
||||
StatusResponse(StatusResponse),
|
||||
PingResponse(PingResponse),
|
||||
}
|
||||
|
||||
impl StatusClientBoundPacket {
|
||||
impl ClientBoundStatusPacket {
|
||||
pub fn get_type_id(&self) -> u8 {
|
||||
match self {
|
||||
Self::StatusResponse(_) => 0x00,
|
||||
@ -71,7 +70,7 @@ impl StatusClientBoundPacket {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn status_response(response: ServerStatus) -> Self {
|
||||
pub fn status_response(response: String) -> Self {
|
||||
let status_response = StatusResponse { response };
|
||||
|
||||
Self::StatusResponse(status_response)
|
||||
@ -91,7 +90,7 @@ pub struct PingRequest {
|
||||
|
||||
#[derive(Packet, Debug)]
|
||||
pub struct StatusResponse {
|
||||
pub response: ServerStatus,
|
||||
pub response: String,
|
||||
}
|
||||
|
||||
#[derive(Packet, Debug)]
|
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
55
protocol/src/version/v_1_13_1/handshake.rs
Normal file
55
protocol/src/version/v_1_13_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,
|
||||
}
|
209
protocol/src/version/v_1_13_1/login.rs
Normal file
209
protocol/src/version/v_1_13_1/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_1/mod.rs
Normal file
6
protocol/src/version/v_1_13_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_13_1/status.rs
Normal file
99
protocol/src/version/v_1_13_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,
|
||||
}
|
3263
protocol/src/version/v_1_13_2/game.rs
Normal file
3263
protocol/src/version/v_1_13_2/game.rs
Normal file
File diff suppressed because it is too large
Load Diff
55
protocol/src/version/v_1_13_2/handshake.rs
Normal file
55
protocol/src/version/v_1_13_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,
|
||||
}
|
209
protocol/src/version/v_1_13_2/login.rs
Normal file
209
protocol/src/version/v_1_13_2/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_2/mod.rs
Normal file
6
protocol/src/version/v_1_13_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_13_2/status.rs
Normal file
99
protocol/src/version/v_1_13_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,
|
||||
}
|
3263
protocol/src/version/v_1_13_2_pre1/game.rs
Normal file
3263
protocol/src/version/v_1_13_2_pre1/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
Loading…
x
Reference in New Issue
Block a user