WIP: procmacro for automatic packet generation
This commit is contained in:
parent
5c4721a2bc
commit
d78175d685
25
Cargo.toml
25
Cargo.toml
@ -1,21 +1,6 @@
|
|||||||
[package]
|
[workspace]
|
||||||
name = "minecraft-protocol"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["vagola <vladislavs.golubs@yandex.ru>"]
|
|
||||||
edition = "2018"
|
|
||||||
description = "Library for decoding and encoding Minecraft packets"
|
|
||||||
license = "MIT"
|
|
||||||
homepage = "https://github.com/eihwaz/minecraft-protocol"
|
|
||||||
repository = "https://github.com/eihwaz/minecraft-protocol"
|
|
||||||
keywords = ["minecraft", "protocol", "packet", "io"]
|
|
||||||
readme = "README.md"
|
|
||||||
|
|
||||||
[dependencies]
|
members = [
|
||||||
byteorder = "1"
|
"protocol",
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
"protocol-derive",
|
||||||
serde_json = "1.0"
|
]
|
||||||
uuid = { version = "0.7", features = ["v4", "serde"] }
|
|
||||||
mc-varint = { git = "https://github.com/luojia65/mc-varint" }
|
|
||||||
num-traits = "0.2"
|
|
||||||
num-derive = "0.2"
|
|
||||||
named-binary-tag = "0.2"
|
|
14
protocol-derive/Cargo.toml
Normal file
14
protocol-derive/Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[package]
|
||||||
|
name = "minecraft-protocol-derive"
|
||||||
|
version = "0.0.0"
|
||||||
|
authors = ["vagola <vladislavs.golubs@yandex.ru>"]
|
||||||
|
edition = "2018"
|
||||||
|
description = "Derive macro for Minecraft packet read and write"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
proc-macro = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
syn = "1.0"
|
||||||
|
quote = "1.0"
|
28
protocol-derive/src/lib.rs
Normal file
28
protocol-derive/src/lib.rs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
extern crate proc_macro;
|
||||||
|
|
||||||
|
use proc_macro::TokenStream;
|
||||||
|
use quote::quote;
|
||||||
|
use syn::{parse_macro_input, DeriveInput};
|
||||||
|
|
||||||
|
#[proc_macro_derive(MinecraftPacket)]
|
||||||
|
pub fn derive_packet(input: TokenStream) -> TokenStream {
|
||||||
|
let input = parse_macro_input!(input as DeriveInput);
|
||||||
|
|
||||||
|
let name = input.ident;
|
||||||
|
|
||||||
|
let output = quote! {
|
||||||
|
impl minecraft_protocol::Packet for #name {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decode<R: Read>(reader: &mut R) -> Result<Self::Output, DecodeError> {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TokenStream::from(output)
|
||||||
|
}
|
22
protocol/Cargo.toml
Normal file
22
protocol/Cargo.toml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
[package]
|
||||||
|
name = "minecraft-protocol"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["vagola <vladislavs.golubs@yandex.ru>"]
|
||||||
|
edition = "2018"
|
||||||
|
description = "Library for decoding and encoding Minecraft packets"
|
||||||
|
license = "MIT"
|
||||||
|
homepage = "https://github.com/eihwaz/minecraft-protocol"
|
||||||
|
repository = "https://github.com/eihwaz/minecraft-protocol"
|
||||||
|
keywords = ["minecraft", "protocol", "packet", "io"]
|
||||||
|
readme = "README.md"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
minecraft-protocol-derive = { path = "../protocol-derive" }
|
||||||
|
byteorder = "1"
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde_json = "1.0"
|
||||||
|
uuid = { version = "0.7", features = ["v4", "serde"] }
|
||||||
|
mc-varint = { git = "https://github.com/luojia65/mc-varint" }
|
||||||
|
num-traits = "0.2"
|
||||||
|
num-derive = "0.2"
|
||||||
|
named-binary-tag = "0.2"
|
@ -106,6 +106,7 @@ impl LoginClientBoundPacket {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(minecraft_protocol_derive::MinecraftPacket)]
|
||||||
pub struct LoginStart {
|
pub struct LoginStart {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
@ -118,20 +119,6 @@ impl LoginStart {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Packet for LoginStart {
|
|
||||||
type Output = Self;
|
|
||||||
|
|
||||||
fn encode<W: Write>(&self, writer: &mut W) -> Result<(), EncodeError> {
|
|
||||||
writer.write_string(&self.name, LOGIN_MAX_LENGTH)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn decode<R: Read>(reader: &mut R) -> Result<Self::Output, DecodeError> {
|
|
||||||
let name = reader.read_string(LOGIN_MAX_LENGTH)?;
|
|
||||||
|
|
||||||
Ok(LoginStart { name })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct EncryptionResponse {
|
pub struct EncryptionResponse {
|
||||||
pub shared_secret: Vec<u8>,
|
pub shared_secret: Vec<u8>,
|
||||||
pub verify_token: Vec<u8>,
|
pub verify_token: Vec<u8>,
|
Loading…
x
Reference in New Issue
Block a user