airmash_protocol/enums/
mod.rs

1#[macro_use]
2mod macros;
3mod flag_code;
4#[cfg(test)]
5mod tests;
6
7pub use self::flag_code::FlagCode;
8
9decl_enum! {
10  /// Specifies whether the debug reply to a command should open a popup or be
11  /// displayed in the chat window.
12  ///
13  /// The original client will consider any command reply that isn't
14  /// `ShowInConsole` to be `ShowInPopup` however other clients may handle
15  /// things differently.
16  ##[default = ShowInPopup]
17  pub enum CommandReplyType {
18    /// Add a new message within the chat window.
19    ShowInConsole = 0,
20    /// Show a popup with the message.
21    ///
22    /// Note that the original client will fail to show any message that is not
23    /// valid JSON if shown in a popup.
24    ShowInPopup = 1,
25  }
26
27  /// Details on how the mob despawned.
28  pub enum DespawnType {
29    /// The mob did not hit anything and will simply vanish.
30    LifetimeEnded = 0,
31    /// The mob ran into something and exploded.
32    ///
33    /// This is generally only used for missiles, some alternate clients may
34    /// run into issues if used for box-type mobs.
35    Collided = 1,
36  }
37
38  /// All error codes that can be sent to the client.
39  ///
40  /// These are all server errors that the vanilla AIRMASH client (and the
41  /// current STARMASH client) understands. [Ab-server][ab-server] has some
42  /// additional custom error types for its sync protocols but this crate
43  /// doesn't handle those packet types at the moment.
44  ///
45  /// [ab-server]: https://github.com/wight-airmash/ab-protocol
46  pub enum ErrorType {
47    PacketFloodingDisconnect = 1,
48    PacketFloodingBan = 2,
49    Banned = 3,
50    /// This error doesn't actually show an error on the client side but
51    /// instead forces the client to reload the page.
52    ForceClientReload = 4,
53    IdleRequiredBeforeRespawn = 5,
54    AfkTimeout = 6,
55    Kicked = 7,
56    InvalidLogin = 8,
57    IncorrectProtocol = 9,
58    AccountBanned = 10,
59    AccountAlreadyLoggedIn = 11,
60    NoRespawnInBTR = 12,
61    IdleRequiredBeforeSpectate = 13,
62    NotEnoughUpgrades = 20,
63    ChatThrottled = 30,
64    FlagChangeThrottled = 31,
65    UnknownCommand = 100,
66  }
67
68  /// This is used to control whether the firewall exists in BTR.
69  ##[catchall = Present]
70  pub enum FirewallStatus {
71    /// If this status is sent then the client will remove the ring of fire.
72    Removed = 0,
73    /// Otherwise, any other status means it should exist.
74    Present = 1,
75  }
76
77  /// Flag update type
78  ///
79  /// Used to indicate whether the flag is now being carried by a player or
80  /// whether the update sets the position of the flag directly.
81  ///
82  /// Used in:
83  /// - TODO
84  pub enum FlagUpdateType {
85    Position = 1,
86    Carrier = 2,
87  }
88
89  /// Game Type.
90  ///
91  /// This is used to indicate to the client which game type is being played.
92  /// The client will then use this to decide team colouring and whether to
93  /// show CTF flags in-game. It will also decide the type of detailed score
94  /// packet that the client expects to receive: one of [`ScoreDetailedFFA`],
95  /// [`ScoreDetailedCTF`], or [`ScoreDetailedBTR`], corresponding to `FFA`,
96  /// `CTF`, and `BTR`, respectively.
97  ///
98  /// Used in:
99  /// - TODO
100  ///
101  /// [`ScoreDetailedFFA`]: crate::ScoreDetailedFFA
102  /// [`ScoreDetailedCTF`]: crate::ScoreDetailedCTF
103  /// [`ScoreDetailedBTR`]: crate::ScoreDetailedBTR
104  ##[default = FFA]
105  pub enum GameType {
106    FFA = 1,
107    CTF = 2,
108    BTR = 3,
109  }
110
111  /// The key that's had it's state changed.
112  ///
113  /// This is only used for client to server communication. For communications
114  /// back from server to client see [`ServerKeyState`].
115  ///
116  /// It is used in the following packets:
117  /// - TODO
118  ///
119  /// [`ServerKeyState`]: crate::ServerKeyState
120  pub enum KeyCode {
121    Up = 1,
122    Down = 2,
123    Left = 3,
124    Right = 4,
125    Fire = 5,
126    Special = 6,
127  }
128
129  /// Indicates the type of entity that just left the player's horizon.
130  pub enum LeaveHorizonType {
131    Player = 0,
132    Mob = 1,
133  }
134
135  /// Types of all mobs present in the game.
136  ///
137  /// In AIRMASH, mobs are any non-player and non-wall items that can be
138  /// interacted with. This includes powerups, upgrades, and all missiles.
139  ///
140  /// Used by:
141  /// - TODO
142  pub enum MobType {
143    PredatorMissile = 1,
144    GoliathMissile = 2,
145    MohawkMissile = 3,
146    Upgrade = 4,
147    TornadoSingleMissile = 5,
148    TornadoTripleMissile = 6,
149    ProwlerMissile = 7,
150    Shield = 8,
151    Inferno = 9,
152  }
153
154  /// Used to indicate the type of plane that the packet refers to.
155  ///
156  /// Used in:
157  /// - TODO
158  ##[default = Predator]
159  pub enum PlaneType {
160    Predator = 1,
161    Goliath = 2,
162    Mohawk = 3,
163    Tornado = 4,
164    Prowler = 5,
165  }
166
167  /// Indicate whether a player levelled up, or has just logged in and their
168  /// level is being communicated to the client.
169  ##[default = Login]
170  pub enum PlayerLevelType {
171    Login = 0,
172    LevelUp = 1,
173  }
174
175  /// Flag for indicating whether a player is alive or dead.
176  ///
177  /// This is used in the following packets:
178  /// - [`Login`] (specifically [`LoginPlayer`])
179  /// - [`PlayerNew`]
180  ///
181  /// [`Login`]: crate::server::Login
182  /// [`LoginPlayer`]: crate::server::LoginPlayer
183  /// [`PlayerNew`]: crate::server::PlayerNew
184  ##[default = Alive]
185  pub enum PlayerStatus {
186    Alive = 0,
187    Dead = 1,
188  }
189
190  /// The type of powerup effect that a player has.
191  ##[default = Shield]
192  pub enum PowerupType {
193    Shield = 1,
194    Inferno = 2,
195  }
196
197  /// Specific identifiers for server custom messages.
198  pub enum ServerCustomType {
199    /// Triggers the game-end screen in BTR.
200    BTR = 1,
201    /// Triggers the game-end screen in CTF.
202    CTF = 2,
203
204    /// For suggesting a different game server for the player to switch to.
205    SwitchGameSuggestion = 100,
206  }
207
208  /// Type specifier for server banner messages.
209  ///
210  /// This _mostly_ doesn't correspond to behaviour within the default client.
211  /// The one exception is that [`Informational`] messages will keep showing
212  /// even if other messages are shown. However, alternate clients may use the
213  /// custom classes to show different messages in different ways.
214  ///
215  /// [`Informational`]: ServerMessageType::Informational
216  pub enum ServerMessageType {
217    /// Used by the CTF server to show messages counting down to the start of
218    /// the next game.
219    TimeToGameStart = 1,
220    /// An informational message related to the current game state. This won't
221    /// be overwritten by any other message category so it should be used for
222    /// important game-related information.
223    ///
224    /// # Usage Examples
225    /// - CTF uses this server message type to show flag-related updates.
226    Informational = 2,
227  }
228
229  /// All upgrade types.
230  ##[default = None]
231  pub enum UpgradeType {
232    /// This seems to be sent by the official server when a player leaves.
233    /// Packets with this value are ignored by the client, so they don't seem
234    /// to affect gameplay at all.
235    None = 0,
236    Speed = 1,
237    Defense = 2,
238    Energy = 3,
239    Missile = 4,
240  }
241}
242
243#[allow(non_upper_case_globals)]
244impl ServerCustomType {
245  // Old aliases for CTF and BTR - kept here for backcompat
246  #[deprecated]
247  pub const BTRWin: Self = Self::BTR;
248  #[deprecated]
249  pub const CTFWin: Self = Self::CTF;
250}
251
252#[allow(non_upper_case_globals)]
253impl ErrorType {
254  #[deprecated(
255    since = "0.6.0",
256    note = "use ErrorType::PacketFloodingDisconnect instead"
257  )]
258  pub const DisconnectedForPacketFlooding: Self = Self::PacketFloodingDisconnect;
259  #[deprecated(since = "0.6.0", note = "use ErrorType::PacketFloodingBan instead")]
260  pub const BannedForPacketFlooding: Self = Self::PacketFloodingBan;
261  #[deprecated(since = "0.6.0", note = "use ErrorType::IncorrectProtocol instead")]
262  pub const IncorrectProtocolLevel: Self = Self::IncorrectProtocol;
263}
264
265impl MobType {
266  pub fn is_missile(&self) -> bool {
267    use self::MobType::*;
268
269    matches!(
270      self,
271      PredatorMissile
272        | GoliathMissile
273        | MohawkMissile
274        | TornadoSingleMissile
275        | TornadoTripleMissile
276        | ProwlerMissile
277    )
278  }
279
280  pub fn is_powerup(&self) -> bool {
281    use self::MobType::*;
282
283    matches!(self, Shield | Inferno)
284  }
285}
286
287#[allow(non_upper_case_globals)]
288impl ServerMessageType {
289  pub const Flag: Self = Self::Informational;
290  pub const Shutdown: Self = Self::Unknown(15);
291
292  /// Unofficial message type. Used by the rust server for banner messages at
293  /// login.
294  pub const Banner: Self = Self::Unknown(16);
295}