summaryrefslogtreecommitdiff
path: root/src/to_clt
diff options
context:
space:
mode:
authorLizzy Fleckenstein <eliasfleckenstein@web.de>2023-02-10 15:53:15 +0100
committerLizzy Fleckenstein <eliasfleckenstein@web.de>2023-02-10 15:53:15 +0100
commit6c875082474431a39596b1547b436a9bec1f5533 (patch)
treebafa770893e6a5a1daea8b57cc5a3f3574da3cb6 /src/to_clt
downloadmt_net-6c875082474431a39596b1547b436a9bec1f5533.tar.xz
Initial commit
Diffstat (limited to 'src/to_clt')
-rw-r--r--src/to_clt/chat.rs16
-rw-r--r--src/to_clt/env.rs44
-rw-r--r--src/to_clt/hud.rs155
-rw-r--r--src/to_clt/media.rs33
-rw-r--r--src/to_clt/status.rs80
5 files changed, 328 insertions, 0 deletions
diff --git a/src/to_clt/chat.rs b/src/to_clt/chat.rs
new file mode 100644
index 0000000..4d99853
--- /dev/null
+++ b/src/to_clt/chat.rs
@@ -0,0 +1,16 @@
+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/env.rs b/src/to_clt/env.rs
new file mode 100644
index 0000000..f242298
--- /dev/null
+++ b/src/to_clt/env.rs
@@ -0,0 +1,44 @@
+use super::*;
+
+#[mt_derive(to = "clt")]
+pub struct ObjAdd; // TODO
+
+#[mt_derive(to = "clt")]
+pub struct ObjMsg; // TODO
+
+#[mt_derive(to = "clt", repr = "u8", enumset)]
+pub enum MapBlockFlag {
+ IsUnderground = 0,
+ DayNightDiff,
+ LightExpired,
+ NotGenerated,
+}
+
+pub const ALWAYS_LIT_FROM: u16 = 0xf000;
+
+#[mt_derive(to = "clt")]
+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: (),
+
+ #[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],
+
+ 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
new file mode 100644
index 0000000..f45d735
--- /dev/null
+++ b/src/to_clt/hud.rs
@@ -0,0 +1,155 @@
+use super::*;
+
+#[mt_derive(to = "clt", repr = "u32", enumset)]
+pub enum HudStyleFlag {
+ Bold,
+ Italic,
+ Mono,
+}
+
+#[mt_derive(to = "clt", repr = "u8", tag = "attribute", content = "value")]
+pub enum HudChange {
+ Pos([f32; 2]) = 0,
+ Name(String),
+ Scale([f32; 2]),
+ Text(String),
+ Number(u32),
+ Item(u32),
+ Dir(u32),
+ Align([f32; 2]),
+ Offset([f32; 2]),
+ WorldPos([f32; 3]),
+ ZIndex(i32),
+ Text2(String),
+ Style(EnumSet<HudStyleFlag>),
+}
+
+#[mt_derive(to = "clt", repr = "u8")]
+pub enum HudType {
+ Image = 0,
+ Text,
+ Statbar,
+ Inv,
+ Waypoint,
+ ImageWaypoint,
+}
+
+#[mt_derive(to = "clt")]
+pub struct HudElement {
+ pub hud_type: HudType,
+ pub pos: [f32; 2],
+ pub name: String,
+ pub scale: [f32; 2],
+ pub text: String,
+ pub number: u32,
+ pub item: u32,
+ pub dir: u32,
+ pub align: [f32; 2],
+ pub offset: [f32; 2],
+ pub world_pos: [f32; 3],
+ pub z_index: i32,
+ pub text_2: String,
+ pub style: EnumSet<HudStyleFlag>,
+}
+
+impl HudElement {
+ pub fn apply_change(&mut self, change: HudChange) {
+ use HudChange::*;
+
+ match change {
+ Pos(v) => self.pos = v,
+ Name(v) => self.name = v,
+ Scale(v) => self.scale = v,
+ Text(v) => self.text = v,
+ Number(v) => self.number = v,
+ Item(v) => self.item = v,
+ Dir(v) => self.dir = v,
+ Align(v) => self.align = v,
+ Offset(v) => self.offset = v,
+ WorldPos(v) => self.world_pos = v,
+ ZIndex(v) => self.z_index = v,
+ Text2(v) => self.text_2 = v,
+ Style(v) => self.style = v,
+ }
+ }
+}
+
+#[mt_derive(to = "clt", repr = "u32", enumset)]
+pub enum HudFlag {
+ Hotbar,
+ HealthBar,
+ Crosshair,
+ WieldedItem,
+ BreathBar,
+ Minimap,
+ RadarMinimap,
+}
+
+#[mt_derive(to = "clt", repr = "u16", tag = "attribute", content = "value")]
+pub enum HotbarParam {
+ Size(#[mt(const16 = 4)] u32) = 0,
+ Image(String),
+ SelectionImage(String),
+}
+
+#[mt_derive(to = "clt", repr = "u16")]
+pub enum MinimapType {
+ None = 0,
+ Surface,
+ Radar,
+ Texture,
+}
+
+#[mt_derive(to = "clt")]
+pub struct MinimapMode {
+ pub minimap_type: MinimapType,
+ pub label: String,
+ pub size: u16,
+ pub texture: String,
+ pub scale: u16,
+}
+
+#[mt_derive(to = "clt", custom)]
+pub struct MinimapModePkt {
+ current: u16,
+ modes: Vec<MinimapMode>,
+}
+
+#[cfg(feature = "server")]
+impl MtSerialize for MinimapModePkt {
+ fn mt_serialize<C: MtCfg>(
+ &self,
+ writer: &mut impl std::io::Write,
+ ) -> Result<(), SerializeError> {
+ DefCfg::write_len(self.modes.len(), writer)?;
+ self.current.mt_serialize::<DefCfg>(writer)?;
+ self.modes.mt_serialize::<()>(writer)?;
+
+ Ok(())
+ }
+}
+
+#[cfg(feature = "client")]
+impl MtDeserialize for MinimapModePkt {
+ 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()?;
+
+ Ok(Self { current, modes })
+ }
+}
+
+/*
+TODO: rustify this
+
+var DefaultMinimap = []MinimapMode{
+ {Type: NoMinimap},
+ {Type: SurfaceMinimap, Size: 256},
+ {Type: SurfaceMinimap, Size: 128},
+ {Type: SurfaceMinimap, Size: 64},
+ {Type: RadarMinimap, Size: 512},
+ {Type: RadarMinimap, Size: 256},
+ {Type: RadarMinimap, Size: 128},
+}
+*/
diff --git a/src/to_clt/media.rs b/src/to_clt/media.rs
new file mode 100644
index 0000000..0dd1f3d
--- /dev/null
+++ b/src/to_clt/media.rs
@@ -0,0 +1,33 @@
+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")]
+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 = "u16")]
+pub enum SoundSrcType {
+ Nowhere = 0,
+ Pos,
+ Obj,
+}
diff --git a/src/to_clt/status.rs b/src/to_clt/status.rs
new file mode 100644
index 0000000..54adb45
--- /dev/null
+++ b/src/to_clt/status.rs
@@ -0,0 +1,80 @@
+use super::*;
+
+#[mt_derive(to = "clt", repr = "u8", tag = "reason")]
+pub enum KickReason {
+ WrongPasswd,
+ UnexpectedData,
+ SrvIsSingleplayer,
+ UnsupportedVersion,
+ BadNameChars,
+ BadName,
+ TooManyClts,
+ EmptyPasswd,
+ AlreadyConnected,
+ SrvErr,
+ Custom { custom: String },
+ Shutdown { custom: String, reconnect: bool },
+ Crash { custom: String, reconnect: bool },
+}
+
+impl KickReason {
+ pub fn reconnect(&self) -> bool {
+ use KickReason::*;
+
+ match self {
+ Shutdown { reconnect, .. } | Crash { reconnect, .. } => *reconnect,
+ _ => false,
+ }
+ }
+}
+
+impl fmt::Display for KickReason {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ use KickReason::*;
+
+ match self {
+ WrongPasswd => write!(f, "wrong password"),
+ UnexpectedData => write!(f, "unexpected data"),
+ SrvIsSingleplayer => write!(f, "server is singleplayer"),
+ UnsupportedVersion => write!(f, "unsupported client version"),
+ BadNameChars => write!(f, "disallowed character(s) in player name"),
+ BadName => write!(f, "disallowed player name"),
+ TooManyClts => write!(f, "too many clients"),
+ EmptyPasswd => write!(f, "empty password"),
+ AlreadyConnected => write!(f, "another client is already connected with the same name"),
+ SrvErr => write!(f, "unsupported client version"),
+ Custom { custom } => write!(f, "{custom}"),
+ Shutdown { custom, .. } => {
+ if custom.is_empty() {
+ write!(f, "server shutdown")
+ } else {
+ write!(f, "server shutdown: {custom}")
+ }
+ }
+ Crash { custom, .. } => {
+ if custom.is_empty() {
+ write!(f, "server crash")
+ } else {
+ write!(f, "server crash: {custom}")
+ }
+ }
+ }
+ }
+}
+
+#[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,
+}