diff --git a/Cargo.toml b/Cargo.toml index c327452..4436a00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,21 +1,6 @@ -[package] -name = "minecraft-protocol" -version = "0.1.0" -authors = ["vagola "] -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" +[workspace] -[dependencies] -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" +members = [ + "protocol", + "protocol-derive", +] \ No newline at end of file diff --git a/protocol-derive/Cargo.toml b/protocol-derive/Cargo.toml new file mode 100644 index 0000000..61812aa --- /dev/null +++ b/protocol-derive/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "minecraft-protocol-derive" +version = "0.0.0" +authors = ["vagola "] +edition = "2018" +description = "Derive macro for Minecraft packet read and write" +publish = false + +[lib] +proc-macro = true + +[dependencies] +syn = "1.0" +quote = "1.0" diff --git a/protocol-derive/src/lib.rs b/protocol-derive/src/lib.rs new file mode 100644 index 0000000..8be285d --- /dev/null +++ b/protocol-derive/src/lib.rs @@ -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(&self, writer: &mut W) -> Result<(), EncodeError> { + + } + + fn decode(reader: &mut R) -> Result { + + } + } + }; + + TokenStream::from(output) +} diff --git a/protocol/Cargo.toml b/protocol/Cargo.toml new file mode 100644 index 0000000..4e380b0 --- /dev/null +++ b/protocol/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "minecraft-protocol" +version = "0.1.0" +authors = ["vagola "] +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" diff --git a/src/chat.rs b/protocol/src/chat.rs similarity index 100% rename from src/chat.rs rename to protocol/src/chat.rs diff --git a/src/game.rs b/protocol/src/game.rs similarity index 100% rename from src/game.rs rename to protocol/src/game.rs diff --git a/src/lib.rs b/protocol/src/lib.rs similarity index 100% rename from src/lib.rs rename to protocol/src/lib.rs diff --git a/src/login.rs b/protocol/src/login.rs similarity index 96% rename from src/login.rs rename to protocol/src/login.rs index 639f02a..46d9872 100644 --- a/src/login.rs +++ b/protocol/src/login.rs @@ -106,6 +106,7 @@ impl LoginClientBoundPacket { } } +#[derive(minecraft_protocol_derive::MinecraftPacket)] pub struct LoginStart { pub name: String, } @@ -118,20 +119,6 @@ impl LoginStart { } } -impl Packet for LoginStart { - type Output = Self; - - fn encode(&self, writer: &mut W) -> Result<(), EncodeError> { - writer.write_string(&self.name, LOGIN_MAX_LENGTH) - } - - fn decode(reader: &mut R) -> Result { - let name = reader.read_string(LOGIN_MAX_LENGTH)?; - - Ok(LoginStart { name }) - } -} - pub struct EncryptionResponse { pub shared_secret: Vec, pub verify_token: Vec, diff --git a/src/status.rs b/protocol/src/status.rs similarity index 100% rename from src/status.rs rename to protocol/src/status.rs diff --git a/test/chat/click_change_page.json b/protocol/test/chat/click_change_page.json similarity index 100% rename from test/chat/click_change_page.json rename to protocol/test/chat/click_change_page.json diff --git a/test/chat/click_open_url.json b/protocol/test/chat/click_open_url.json similarity index 100% rename from test/chat/click_open_url.json rename to protocol/test/chat/click_open_url.json diff --git a/test/chat/click_run_command.json b/protocol/test/chat/click_run_command.json similarity index 100% rename from test/chat/click_run_command.json rename to protocol/test/chat/click_run_command.json diff --git a/test/chat/click_suggest_command.json b/protocol/test/chat/click_suggest_command.json similarity index 100% rename from test/chat/click_suggest_command.json rename to protocol/test/chat/click_suggest_command.json diff --git a/test/chat/hover_show_entity.json b/protocol/test/chat/hover_show_entity.json similarity index 100% rename from test/chat/hover_show_entity.json rename to protocol/test/chat/hover_show_entity.json diff --git a/test/chat/hover_show_item.json b/protocol/test/chat/hover_show_item.json similarity index 100% rename from test/chat/hover_show_item.json rename to protocol/test/chat/hover_show_item.json diff --git a/test/chat/hover_show_text.json b/protocol/test/chat/hover_show_text.json similarity index 100% rename from test/chat/hover_show_text.json rename to protocol/test/chat/hover_show_text.json diff --git a/test/chat/keybind_jump.json b/protocol/test/chat/keybind_jump.json similarity index 100% rename from test/chat/keybind_jump.json rename to protocol/test/chat/keybind_jump.json diff --git a/test/chat/text_hello_world.json b/protocol/test/chat/text_hello_world.json similarity index 100% rename from test/chat/text_hello_world.json rename to protocol/test/chat/text_hello_world.json diff --git a/test/chat/translate_opped_steve.json b/protocol/test/chat/translate_opped_steve.json similarity index 100% rename from test/chat/translate_opped_steve.json rename to protocol/test/chat/translate_opped_steve.json