summaryrefslogtreecommitdiff
path: root/src/to_clt/kick.rs
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/kick.rs
parent3cb97b94d3e3d83fbbbefde9c0a40cdd27ea5416 (diff)
downloadmt_net-6c1870c9405a80cb9f08e7fbb2db0b504522e1b2.tar.xz
Implement NodeMeta and add Inventory stub
Diffstat (limited to 'src/to_clt/kick.rs')
-rw-r--r--src/to_clt/kick.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/to_clt/kick.rs b/src/to_clt/kick.rs
new file mode 100644
index 0000000..6389df6
--- /dev/null
+++ b/src/to_clt/kick.rs
@@ -0,0 +1,63 @@
+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}")
+ }
+ }
+ }
+ }
+}