summaryrefslogtreecommitdiff
path: root/src/to_clt
diff options
context:
space:
mode:
authorLizzy Fleckenstein <eliasfleckenstein@web.de>2023-02-14 16:17:20 +0100
committerLizzy Fleckenstein <eliasfleckenstein@web.de>2023-02-14 16:17:20 +0100
commit6c1870c9405a80cb9f08e7fbb2db0b504522e1b2 (patch)
treed8db061bf9ae2ad6e67013e9cb378bca51303f55 /src/to_clt
parent3cb97b94d3e3d83fbbbefde9c0a40cdd27ea5416 (diff)
downloadmt_net-6c1870c9405a80cb9f08e7fbb2db0b504522e1b2.tar.xz
Implement NodeMeta and add Inventory stub
Diffstat (limited to 'src/to_clt')
-rw-r--r--src/to_clt/chat.rs16
-rw-r--r--src/to_clt/inv.rs37
-rw-r--r--src/to_clt/kick.rs (renamed from src/to_clt/status.rs)17
-rw-r--r--src/to_clt/map.rs71
-rw-r--r--src/to_clt/media.rs3
-rw-r--r--src/to_clt/obj.rs (renamed from src/to_clt/env.rs)32
6 files changed, 109 insertions, 67 deletions
diff --git a/src/to_clt/chat.rs b/src/to_clt/chat.rs
deleted file mode 100644
index 4d99853..0000000
--- a/src/to_clt/chat.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-use super::*;
-
-#[mt_derive(to = "clt", repr = "u8")]
-pub enum ChatMsgType {
- Raw = 0,
- Normal,
- Announce,
- System,
-}
-
-#[mt_derive(to = "clt", repr = "u8")]
-pub enum PlayerListUpdateType {
- Init = 0,
- Add,
- Remove,
-}
diff --git a/src/to_clt/inv.rs b/src/to_clt/inv.rs
new file mode 100644
index 0000000..2ada0a1
--- /dev/null
+++ b/src/to_clt/inv.rs
@@ -0,0 +1,37 @@
+use super::*;
+use mt_ser::{DeserializeError, SerializeError};
+use std::io::{Read, Write};
+
+#[mt_derive(to = "clt", custom)]
+pub struct Inventory; // TODO
+
+#[cfg(feature = "server")]
+impl MtSerialize for Inventory {
+ fn mt_serialize<C: MtCfg>(&self, writer: &mut impl Write) -> Result<(), SerializeError> {
+ "EndInventory\n".mt_serialize::<()>(writer)
+ }
+}
+
+fn read_line(reader: &mut impl Read) -> Result<String, DeserializeError> {
+ let utf8 = mt_ser::mt_deserialize_seq::<(), u8>(reader)?
+ .map_while(|x| match x {
+ Ok(0x0A) => None,
+ x => Some(x),
+ })
+ .try_collect::<Vec<_>>()?;
+
+ String::from_utf8(utf8)
+ .map_err(|e| DeserializeError::Other(format!("Invalid UTF-8: {e}").into()))
+}
+
+#[cfg(feature = "client")]
+impl MtDeserialize for Inventory {
+ fn mt_deserialize<C: MtCfg>(reader: &mut impl Read) -> Result<Self, DeserializeError> {
+ loop {
+ match read_line(reader)?.as_str() {
+ "EndInventory" => return Ok(Self),
+ _ => {}
+ }
+ }
+ }
+}
diff --git a/src/to_clt/status.rs b/src/to_clt/kick.rs
index 54adb45..6389df6 100644
--- a/src/to_clt/status.rs
+++ b/src/to_clt/kick.rs
@@ -61,20 +61,3 @@ impl fmt::Display for KickReason {
}
}
}
-
-#[mt_derive(to = "clt", repr = "u32", enumset)]
-pub enum AuthMethod {
- LegacyPasswd,
- Srp,
- FirstSrp,
-}
-
-#[mt_derive(to = "clt", repr = "u64", enumset)]
-pub enum CsmRestrictionFlag {
- NoCsms,
- NoChatMsgs,
- NoItemDefs,
- NoNodeDefs,
- LimitMapRange,
- NoPlayerList,
-}
diff --git a/src/to_clt/map.rs b/src/to_clt/map.rs
new file mode 100644
index 0000000..296a23f
--- /dev/null
+++ b/src/to_clt/map.rs
@@ -0,0 +1,71 @@
+use super::*;
+use mt_ser::{DeserializeError, SerializeError};
+
+#[mt_derive(to = "clt", repr = "u8", enumset)]
+pub enum MapBlockFlag {
+ IsUnderground = 0,
+ DayNightDiff,
+ LightExpired,
+ NotGenerated,
+}
+
+pub const ALWAYS_LIT_FROM: u16 = 0xf000;
+
+pub const CONTENT_UNKNOWN: u16 = 125;
+pub const CONTENT_AIR: u16 = 126;
+pub const CONTENT_IGNORE: u16 = 127;
+
+#[mt_derive(to = "clt")]
+pub struct NodeMetaField {
+ #[mt(len = "u32")]
+ value: String,
+ private: bool,
+}
+
+#[mt_derive(to = "clt")]
+pub struct NodeMeta {
+ #[mt(len = "u32")]
+ fields: HashMap<String, NodeMetaField>,
+ inv: Inventory,
+}
+
+#[derive(Debug)]
+pub struct NodeMetasLen;
+
+impl MtCfg for NodeMetasLen {
+ type Len = <DefCfg as MtCfg>::Len;
+ type Inner = <DefCfg as MtCfg>::Inner;
+
+ fn write_len(len: usize, writer: &mut impl std::io::Write) -> Result<(), SerializeError> {
+ if len == 0 {
+ 0u8.mt_serialize::<DefCfg>(writer)
+ } else {
+ 2u8.mt_serialize::<DefCfg>(writer)?;
+ DefCfg::write_len(len, writer)
+ }
+ }
+
+ fn read_len(reader: &mut impl std::io::Read) -> Result<Self::Len, DeserializeError> {
+ match u8::mt_deserialize::<DefCfg>(reader)? {
+ 0 => Ok(0),
+ 2 => DefCfg::read_len(reader),
+ x => Err(DeserializeError::InvalidEnum("NodeMetasLen", Box::new(x))),
+ }
+ }
+}
+
+#[mt_derive(to = "clt")]
+pub struct MapBlock {
+ pub flags: EnumSet<MapBlockFlag>,
+ pub lit_from: u16,
+ #[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(len = "NodeMetasLen")]
+ pub metas: HashMap<u16, NodeMeta>,
+}
diff --git a/src/to_clt/media.rs b/src/to_clt/media.rs
index 50c709f..2cd516b 100644
--- a/src/to_clt/media.rs
+++ b/src/to_clt/media.rs
@@ -9,9 +9,6 @@ pub struct ItemDef; // TODO
#[mt_derive(to = "clt")]
pub struct NodeDef; // TODO
-#[mt_derive(to = "clt")]
-pub struct NodeMeta; // TODO
-
#[mt_derive(to = "clt", repr = "u8")]
pub enum SoundSrcType {
Nowhere = 0,
diff --git a/src/to_clt/env.rs b/src/to_clt/obj.rs
index ecd3db3..9e88fff 100644
--- a/src/to_clt/env.rs
+++ b/src/to_clt/obj.rs
@@ -107,7 +107,7 @@ pub const GENERIC_CAO: u8 = 101;
#[mt_derive(to = "clt", repr = "u8", tag = "type", content = "data")]
pub enum ObjMsg {
- Props(ObjProps) = 0,
+ Props(Box<ObjProps>) = 0,
Pos(ObjPos),
TextureMod {
#[serde(rename = "mod")]
@@ -166,33 +166,3 @@ pub struct ObjAdd {
#[mt(size = "u32")]
pub init_data: ObjInitData,
}
-
-#[mt_derive(to = "clt", repr = "u8", enumset)]
-pub enum MapBlockFlag {
- IsUnderground = 0,
- DayNightDiff,
- LightExpired,
- NotGenerated,
-}
-
-pub const ALWAYS_LIT_FROM: u16 = 0xf000;
-
-pub const CONTENT_UNKNOWN: u16 = 125;
-pub const CONTENT_AIR: u16 = 126;
-pub const CONTENT_IGNORE: u16 = 127;
-
-#[mt_derive(to = "clt")]
-pub struct MapBlock {
- pub flags: EnumSet<MapBlockFlag>,
- pub lit_from: u16,
- #[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>,
-}