};
#[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;
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,
sudo_auth_methods: EnumSet<AuthMethod>,
} = 3,
AcceptSudoMode {
+ #[mt(const_after = "[0u8; 15]")]
sudo_auth_methods: EnumSet<AuthMethod>,
} = 4,
DenySudoMode = 5,
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,
add: Vec<ObjAdd>,
} = 49,
ObjMsgs {
- #[mt(len0)]
+ #[mt(len = "()")]
msgs: Vec<ObjIdMsg>,
} = 50,
Hp {
yaw: f32,
} = 52,
LegacyKick {
- #[mt(utf16)]
+ #[mt(len = "Utf16")]
reason: String,
} = 53,
Fov {
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,
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,
expiration_time: f32,
size: f32,
collide: bool,
- #[mt(len32)]
+ #[mt(len = "u32")]
texture: String,
vertical: bool,
collision_rm: bool,
expiration_time: [f32; 2],
size: [f32; 2],
collide: bool,
- #[mt(len32)]
+ #[mt(len = "u32")]
texture: String,
id: u32,
vertical: bool,
channel: String,
} = 88,
NodeMetasChanged {
- #[mt(size32)]
+ #[mt(size = "u32")]
changed: HashMap<[i16; 3], NodeMeta>,
} = 89,
SunParams {
#[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
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,
Attach(ObjAttach),
PhysicsOverride(ObjPhysicsOverride),
SpawnInfant {
+ #[mt(const_after = "GENERIC_CAO")]
id: u16,
- #[mt(const8 = 101)] // GenericCAO
- infant_type: (),
} = 11,
AnimSpeed {
speed: f32,
#[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,
}
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: (),
}
#[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),
}
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 })
}
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 = "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,
} = 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 {
Interact {
action: Interaction,
item_slot: u16,
- #[mt(size32)]
+ #[mt(size = "u32")]
pointed: PointedThing,
pos: PlayerPos,
} = 57,
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>,