]> git.lizzy.rs Git - mt_net.git/blob - src/to_clt/status.rs
Initial commit
[mt_net.git] / src / to_clt / status.rs
1 use super::*;
2
3 #[mt_derive(to = "clt", repr = "u8", tag = "reason")]
4 pub enum KickReason {
5     WrongPasswd,
6     UnexpectedData,
7     SrvIsSingleplayer,
8     UnsupportedVersion,
9     BadNameChars,
10     BadName,
11     TooManyClts,
12     EmptyPasswd,
13     AlreadyConnected,
14     SrvErr,
15     Custom { custom: String },
16     Shutdown { custom: String, reconnect: bool },
17     Crash { custom: String, reconnect: bool },
18 }
19
20 impl KickReason {
21     pub fn reconnect(&self) -> bool {
22         use KickReason::*;
23
24         match self {
25             Shutdown { reconnect, .. } | Crash { reconnect, .. } => *reconnect,
26             _ => false,
27         }
28     }
29 }
30
31 impl fmt::Display for KickReason {
32     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
33         use KickReason::*;
34
35         match self {
36             WrongPasswd => write!(f, "wrong password"),
37             UnexpectedData => write!(f, "unexpected data"),
38             SrvIsSingleplayer => write!(f, "server is singleplayer"),
39             UnsupportedVersion => write!(f, "unsupported client version"),
40             BadNameChars => write!(f, "disallowed character(s) in player name"),
41             BadName => write!(f, "disallowed player name"),
42             TooManyClts => write!(f, "too many clients"),
43             EmptyPasswd => write!(f, "empty password"),
44             AlreadyConnected => write!(f, "another client is already connected with the same name"),
45             SrvErr => write!(f, "unsupported client version"),
46             Custom { custom } => write!(f, "{custom}"),
47             Shutdown { custom, .. } => {
48                 if custom.is_empty() {
49                     write!(f, "server shutdown")
50                 } else {
51                     write!(f, "server shutdown: {custom}")
52                 }
53             }
54             Crash { custom, .. } => {
55                 if custom.is_empty() {
56                     write!(f, "server crash")
57                 } else {
58                     write!(f, "server crash: {custom}")
59                 }
60             }
61         }
62     }
63 }
64
65 #[mt_derive(to = "clt", repr = "u32", enumset)]
66 pub enum AuthMethod {
67     LegacyPasswd,
68     Srp,
69     FirstSrp,
70 }
71
72 #[mt_derive(to = "clt", repr = "u64", enumset)]
73 pub enum CsmRestrictionFlag {
74     NoCsms,
75     NoChatMsgs,
76     NoItemDefs,
77     NoNodeDefs,
78     LimitMapRange,
79     NoPlayerList,
80 }