Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
theaddonn committed Sep 13, 2024
2 parents 8cb6bd4 + 703ef19 commit 517d464
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 21 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ bedrockrs_form = { path = "crates/form" }
bedrockrs_world = { path = "crates/world", optional = true }
bedrockrs_paletted_storage = { path = "crates/paletted_storage", optional = true }

bedrockrs_play_fab = { path = "crates/play_fab" }
bedrockrs_xsapi = { path = "crates/xsapi" }

[features]
full = ["addons", "proto", "world"]

Expand Down
6 changes: 6 additions & 0 deletions crates/play_fab/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "bedrockrs_play_fab"
version = "0.1.0"
edition = "2021"

[dependencies]
14 changes: 14 additions & 0 deletions crates/play_fab/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
30 changes: 9 additions & 21 deletions crates/proto_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,39 +189,27 @@ pub fn gamepackets(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let variants = args.packets.clone();
let variants = variants.iter().map(|(name, value)| {
if let Some(value) = value {
quote! {
#name(#value),
}
quote! { #name(#value), }
} else {
quote! {
#name(),
}
quote! { #name(), }
}
});

let compress = args.packets.clone();
let compress = compress.iter().map(|(name, value)| {
if let Some(v) = value {
quote! {
GamePackets::#name(_) => { return <#v as ::bedrockrs_proto_core::GamePacket>::COMPRESS; },
}
quote! { GamePackets::#name(_) => { return <#v as ::bedrockrs_proto_core::GamePacket>::COMPRESS; }, }
} else {
quote! {
GamePackets::#name() => { todo!("impl GamePackets::{}", stringify!(name)); },
}
quote! { GamePackets::#name() => { todo!("impl GamePackets::{}", stringify!(name)); }, }
}
});

let encrypt = args.packets.clone();
let encrypt = encrypt.iter().map(|(name, value)| {
if let Some(v) = value {
quote! {
GamePackets::#name(_) => { return <#v as ::bedrockrs_proto_core::GamePacket>::ENCRYPT; },
}
quote! { GamePackets::#name(_) => { return <#v as ::bedrockrs_proto_core::GamePacket>::ENCRYPT; }, }
} else {
quote! {
GamePackets::#name() => { todo!("impl GamePackets::{}", stringify!(name)); },
}
quote! { GamePackets::#name() => { todo!("impl GamePackets::{}", stringify!(name)); }, }
}
});

Expand All @@ -231,17 +219,17 @@ pub fn gamepackets(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
quote! {
GamePackets::#name(pk) => {
let mut buf = Vec::new();

match <#v as bedrockrs_proto_core::ProtoCodec>::proto_serialize(pk, &mut buf) {
Ok(_) => {},
Err(err) => return Err(err),
};

let len: u32 = match buf.len().try_into() {
Ok(len) => len,
Err(err) => return Err(::bedrockrs_proto_core::error::ProtoCodecError::FromIntError(err)),
};

match write_gamepacket_header(stream, len, <#v as ::bedrockrs_proto_core::GamePacket>::ID, subclient_sender_id, subclient_target_id) {
Ok(_) => {},
Err(err) => return Err(err),
Expand Down
7 changes: 7 additions & 0 deletions crates/xsapi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "bedrockrs_xsapi"
version = "0.1.0"
edition = "2021"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
1 change: 1 addition & 0 deletions crates/xsapi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod session;
Empty file.
20 changes: 20 additions & 0 deletions crates/xsapi/src/session/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Session {
pub properties: SessionProperties,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SessionProperties {
pub system: SessionPropertiesSystem,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SessionPropertiesSystem {
#[serde(rename = "joinRestriction")]
pub join_restriction: String,
#[serde(rename = "readRestriction")]
pub read_restriction: String,
pub closed: bool,
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod nbt {
#[cfg(feature = "proto")]
pub mod proto {
pub use ::bedrockrs_proto::*;
pub use ::bedrockrs_proto_core::GamePacket;

pub mod codec {
pub use ::bedrockrs_proto_core::error::ProtoCodecError;
Expand Down

0 comments on commit 517d464

Please sign in to comment.