]> git.lizzy.rs Git - mt_net.git/commitdiff
Use improved attributes
authorLizzy Fleckenstein <eliasfleckenstein@web.de>
Mon, 13 Feb 2023 16:13:25 +0000 (17:13 +0100)
committerLizzy Fleckenstein <eliasfleckenstein@web.de>
Mon, 13 Feb 2023 16:13:25 +0000 (17:13 +0100)
src/lib.rs
src/to_clt.rs
src/to_clt/env.rs
src/to_clt/hud.rs
src/to_clt/media.rs
src/to_srv.rs

index 9b410a64e9601ecbbe793f078036c88e1c241c37..644d25e77b3dd82332c2e326672f0f0445d4dcbb 100644 (file)
@@ -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;
index 871328ae09d02888e977510763eb46472e49c5a7..00d952dc8444047a4c862ee3963426f36382e26c 100644 (file)
@@ -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 {
index cce76969b73540fb4e54d9f554cfaca2d22ffe70..031ee9675de64081346152b9b08e5d29b5769aa6 100644 (file)
@@ -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: (),
 }
index cf9e3379162857c7a4c476b2e5a57d926ffe92b1..64574f7659f795852633c86233684950dc1193ce 100644 (file)
@@ -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 })
     }
index 0dd1f3d6281c4fc22be5685785cb32c47bf6dbac..a6ecd32c119bd1f7721e327e1ae80fdc3cbe5b78 100644 (file)
@@ -1,18 +1,5 @@
 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
 
index 321138c69602160bb924bfb293f52379c6af092d..704acdb78e111c040339047f99b362a866bc2256 100644 (file)
@@ -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>,