summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs2
-rw-r--r--src/to_clt.rs34
-rw-r--r--src/to_clt/env.rs36
-rw-r--r--src/to_clt/hud.rs4
-rw-r--r--src/to_clt/media.rs13
-rw-r--r--src/to_srv.rs37
6 files changed, 45 insertions, 81 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 9b410a6..644d25e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -19,7 +19,7 @@ use std::{
};
#[cfg(any(feature = "client", feature = "server"))]
-use mt_ser::{DefCfg, DeserializeError, MtCfg, MtDeserialize, MtSerialize, SerializeError};
+use mt_ser::{DefCfg, DeserializeError, MtCfg, MtDeserialize, MtSerialize, SerializeError, Utf16};
#[cfg(feature = "random")]
use generate_random::GenerateRandom;
diff --git a/src/to_clt.rs b/src/to_clt.rs
index 871328a..00d952d 100644
--- a/src/to_clt.rs
+++ b/src/to_clt.rs
@@ -34,7 +34,7 @@ pub use status::*;
pub enum ToCltPkt {
Hello {
serialize_version: u8,
- #[mt(const16 = 1)] // compression
+ #[mt(const_before = "1u16")] // compression
proto_version: u16,
auth_methods: EnumSet<AuthMethod>,
username: String,
@@ -46,6 +46,7 @@ pub enum ToCltPkt {
sudo_auth_methods: EnumSet<AuthMethod>,
} = 3,
AcceptSudoMode {
+ #[mt(const_after = "[0u8; 15]")]
sudo_auth_methods: EnumSet<AuthMethod>,
} = 4,
DenySudoMode = 5,
@@ -86,11 +87,11 @@ pub enum ToCltPkt {
should_cache: bool,
} = 44,
ChatMsg {
- #[mt(const8 = 1)]
+ #[mt(const_before = "1u8")]
msg_type: ChatMsgType,
- #[mt(utf16)]
+ #[mt(len = "Utf16")]
sender: String,
- #[mt(utf16)]
+ #[mt(len = "Utf16")]
text: String,
timestamp: i64, // unix time
} = 47,
@@ -99,7 +100,7 @@ pub enum ToCltPkt {
add: Vec<ObjAdd>,
} = 49,
ObjMsgs {
- #[mt(len0)]
+ #[mt(len = "()")]
msgs: Vec<ObjIdMsg>,
} = 50,
Hp {
@@ -113,7 +114,7 @@ pub enum ToCltPkt {
yaw: f32,
} = 52,
LegacyKick {
- #[mt(utf16)]
+ #[mt(len = "Utf16")]
reason: String,
} = 53,
Fov {
@@ -128,18 +129,19 @@ pub enum ToCltPkt {
Media {
n: u16,
i: u16,
- files: Vec<MediaPayload>, // FIXME: can we use a HashMap for this?
+ #[mt(len = "(u32, (DefCfg, u32))")]
+ files: HashMap<String, Vec<u8>>, // name -> payload
} = 56,
NodeDefs {
defs: Vec<NodeDef>,
} = 58,
AnnounceMedia {
- files: Vec<MediaAnnounce>, // FIXME: can we use a HashMap for this?
+ files: HashMap<String, String>, // name -> base64 hash
url: String,
} = 60,
- #[mt(size32, zlib)]
+ #[mt(size = "u32", zlib)]
ItemDefs {
- #[mt(const8 = 0)] // version
+ #[mt(const_before = "0u8")] // version
defs: Vec<ItemDef>,
aliases: HashMap<String, String>,
} = 61,
@@ -163,18 +165,18 @@ pub enum ToCltPkt {
privs: HashSet<String>,
} = 65,
InvFormspec {
- #[mt(size32)]
+ #[mt(size = "u32")]
formspec: String,
} = 66,
DetachedInv {
name: String,
keep: bool,
len: u16,
- #[mt(len0)]
+ #[mt(len = "()")]
inv: String,
} = 67,
ShowFormspec {
- #[mt(len32)]
+ #[mt(len = "u32")]
formspec: String,
formname: String,
} = 68,
@@ -196,7 +198,7 @@ pub enum ToCltPkt {
expiration_time: f32,
size: f32,
collide: bool,
- #[mt(len32)]
+ #[mt(len = "u32")]
texture: String,
vertical: bool,
collision_rm: bool,
@@ -216,7 +218,7 @@ pub enum ToCltPkt {
expiration_time: [f32; 2],
size: [f32; 2],
collide: bool,
- #[mt(len32)]
+ #[mt(len = "u32")]
texture: String,
id: u32,
vertical: bool,
@@ -296,7 +298,7 @@ pub enum ToCltPkt {
channel: String,
} = 88,
NodeMetasChanged {
- #[mt(size32)]
+ #[mt(size = "u32")]
changed: HashMap<[i16; 3], NodeMeta>,
} = 89,
SunParams {
diff --git a/src/to_clt/env.rs b/src/to_clt/env.rs
index cce7696..031ee96 100644
--- a/src/to_clt/env.rs
+++ b/src/to_clt/env.rs
@@ -2,7 +2,7 @@ use super::*;
#[mt_derive(to = "clt")]
pub struct ObjProps {
- #[mt(const8 = 4)] // version
+ #[mt(const_before = "4u8")] // version
pub max_hp: u16, // player only
pub collide_with_nodes: bool,
pub weight: f32, // deprecated
@@ -93,6 +93,8 @@ pub struct ObjPhysicsOverride {
pub old_sneak: bool,
}
+const GENERIC_CAO: u8 = 101;
+
#[mt_derive(to = "clt", repr = "u8", tag = "type", content = "data")]
pub enum ObjMsg {
Props(ObjProps) = 0,
@@ -116,9 +118,8 @@ pub enum ObjMsg {
Attach(ObjAttach),
PhysicsOverride(ObjPhysicsOverride),
SpawnInfant {
+ #[mt(const_after = "GENERIC_CAO")]
id: u16,
- #[mt(const8 = 101)] // GenericCAO
- infant_type: (),
} = 11,
AnimSpeed {
speed: f32,
@@ -128,31 +129,31 @@ pub enum ObjMsg {
#[mt_derive(to = "clt")]
pub struct ObjIdMsg {
pub id: u16,
- #[mt(size16)]
+ #[mt(size = "u16")]
pub msg: ObjMsg,
}
#[mt_derive(to = "clt")]
-pub struct ObjInitMsg(#[mt(size32)] ObjMsg);
+pub struct ObjInitMsg(#[mt(size = "u32")] pub ObjMsg);
#[mt_derive(to = "clt")]
pub struct ObjInitData {
- #[mt(const8 = 1)] // version
+ #[mt(const_before = "1u8")] // version
pub name: String,
pub is_player: bool,
pub id: u16,
pub pos: [f32; 3],
pub rot: [f32; 3],
pub hp: u16,
- #[mt(len8)]
+ #[mt(len = "u8")]
pub msgs: Vec<ObjInitMsg>,
}
#[mt_derive(to = "clt")]
pub struct ObjAdd {
pub id: u16,
- #[mt(const8 = 101)] // GenericCAO
- #[mt(size32)]
+ #[mt(const_before = "GENERIC_CAO")]
+ #[mt(size = "u32")]
pub init_data: ObjInitData,
}
@@ -174,25 +175,14 @@ pub const CONTENT_IGNORE: u16 = 127;
pub struct MapBlock {
pub flags: EnumSet<MapBlockFlag>,
pub lit_from: u16,
-
- #[mt(const8 = 2)]
- #[serde(skip)]
- pub param0_size: (),
-
- #[mt(const8 = 2)]
- #[serde(skip)]
- pub param12_size: (),
-
+ #[mt(const_before = "2u8")] // param0 size
+ #[mt(const_before = "2u8")] // param1 size + param2 size
#[serde(with = "serde_arrays")]
pub param_0: [u16; 4096],
#[serde(with = "serde_arrays")]
pub param_1: [u8; 4096],
#[serde(with = "serde_arrays")]
pub param_2: [u8; 4096],
-
+ #[mt(const_after = "2u8")] // version
pub node_metas: HashMap<u16, NodeMeta>,
-
- #[mt(const8 = 2)]
- #[serde(skip)]
- pub version: (),
}
diff --git a/src/to_clt/hud.rs b/src/to_clt/hud.rs
index cf9e337..64574f7 100644
--- a/src/to_clt/hud.rs
+++ b/src/to_clt/hud.rs
@@ -87,7 +87,7 @@ pub enum HudFlag {
#[mt_derive(to = "clt", repr = "u16", tag = "attribute", content = "value")]
pub enum HotbarParam {
- Size(#[mt(const16 = 4)] u32) = 0,
+ Size(#[mt(const_before = "4u16")] u32) = 0,
Image(String),
SelectionImage(String),
}
@@ -134,7 +134,7 @@ impl MtDeserialize for MinimapModesPkt {
fn mt_deserialize<C: MtCfg>(reader: &mut impl std::io::Read) -> Result<Self, DeserializeError> {
let len = DefCfg::read_len(reader)?;
let current = MtDeserialize::mt_deserialize::<DefCfg>(reader)?;
- let modes = mt_ser::mt_deserialize_sized_seq(&len, reader)?.try_collect()?;
+ let modes = mt_ser::mt_deserialize_sized_seq::<DefCfg, _>(&len, reader)?.try_collect()?;
Ok(Self { current, modes })
}
diff --git a/src/to_clt/media.rs b/src/to_clt/media.rs
index 0dd1f3d..a6ecd32 100644
--- a/src/to_clt/media.rs
+++ b/src/to_clt/media.rs
@@ -1,19 +1,6 @@
use super::*;
#[mt_derive(to = "clt")]
-pub struct MediaAnnounce {
- pub name: String,
- pub base64_sha1: String,
-}
-
-#[mt_derive(to = "clt")]
-pub struct MediaPayload {
- pub name: String,
- #[mt(len32)]
- pub data: Vec<u8>,
-}
-
-#[mt_derive(to = "clt")]
pub struct TileAnim; // TODO
#[mt_derive(to = "clt")]
diff --git a/src/to_srv.rs b/src/to_srv.rs
index 321138c..704acdb 100644
--- a/src/to_srv.rs
+++ b/src/to_srv.rs
@@ -36,36 +36,19 @@ pub enum Interaction {
}
#[mt_derive(to = "srv", repr = "u8", tag = "type")]
-#[mt(const8 = 0)] // version
+#[mt(const_before = "0u8")] // version
pub enum PointedThing {
None = 0,
Node { under: [i16; 3], above: [i16; 3] },
Obj { obj: u16 },
}
-#[mt_derive(to = "srv")]
-pub struct String32(#[mt(len32)] pub String);
-
-impl std::ops::Deref for String32 {
- type Target = String;
-
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-
-impl std::ops::DerefMut for String32 {
- fn deref_mut(&mut self) -> &mut Self::Target {
- &mut self.0
- }
-}
-
#[mt_derive(to = "srv", repr = "u16", tag = "type", content = "data")]
pub enum ToSrvPkt {
Nil = 0,
Init {
serialize_version: u8,
- #[mt(const16 = 1)] // supported compression
+ #[mt(const_before = "1u16")] // supported compression
min_proto_version: u16,
max_proto_version: u16,
player_name: String,
@@ -87,19 +70,19 @@ pub enum ToSrvPkt {
} = 25,
PlayerPos(PlayerPos) = 35,
GotBlocks {
- #[mt(len8)]
+ #[mt(len = "u8")]
blocks: Vec<[i16; 3]>,
} = 36,
DeletedBlocks {
- #[mt(len8)]
+ #[mt(len = "u8")]
blocks: Vec<[i16; 3]>,
} = 37,
InvAction {
- #[mt(len0)]
+ #[mt(len = "()")]
action: String,
} = 49,
ChatMsg {
- #[mt(utf16)]
+ #[mt(len = "Utf16")]
msg: String,
} = 50,
FallDmg {
@@ -112,7 +95,7 @@ pub enum ToSrvPkt {
Interact {
action: Interaction,
item_slot: u16,
- #[mt(size32)]
+ #[mt(size = "u32")]
pointed: PointedThing,
pos: PlayerPos,
} = 57,
@@ -122,11 +105,13 @@ pub enum ToSrvPkt {
NodeMetaFields {
pos: [i16; 3],
formname: String,
- fields: HashMap<String, String32>,
+ #[mt(len = "(DefCfg, (DefCfg, u32))")]
+ fields: HashMap<String, String>,
} = 59,
InvFields {
formname: String,
- fields: HashMap<String, String32>,
+ #[mt(len = "(DefCfg, (DefCfg, u32))")]
+ fields: HashMap<String, String>,
} = 60,
ReqMedia {
filenames: Vec<String>,