1use serde::{
2 de::{self, Visitor},
3 Deserialize, Deserializer, Serialize, Serializer,
4};
5use std::fmt;
6
7#[derive(Debug, PartialEq, Eq, Hash)]
8pub struct GameType(&'static str, &'static str, &'static str, i64);
9
10impl GameType {
11 pub fn name(&self) -> String {
12 self.1.to_string()
13 }
14
15 pub fn db_name(&self) -> String {
16 self.2.to_string()
17 }
18
19 pub fn id(&self) -> i64 {
20 self.3
21 }
22
23 pub const QUAKECRAFT: Self = Self("QUAKECRAFT", "Quakecraft", "Quake", 2);
24 pub const WALLS: Self = Self("WALLS", "Walls", "Walls", 3);
25 pub const PAINTBALL: Self = Self("PAINTBALL", "Paintball", "Paintball", 4);
26 pub const SURVIVAL_GAMES: Self =
27 Self("SURVIVAL_GAMES", "Blitz Survival Games", "HungerGames", 5);
28 pub const TNTGAMES: Self = Self("TNTGAMES", "The TNT Games", "TNTGames", 6);
29 pub const VAMPIREZ: Self = Self("VAMPIREZ", "VampireZ", "VampireZ", 7);
30 pub const WALLS3: Self = Self("WALLS3", "Mega Walls", "Walls3", 13);
31 pub const ARCADE: Self = Self("ARCADE", "Arcade", "Arcade", 14);
32 pub const ARENA: Self = Self("ARENA", "Arena Brawl", "Arena", 17);
33 pub const MCGO: Self = Self("MCGO", "Cops and Crims", "MCGO", 21);
34 pub const UHC: Self = Self("UHC", "UHC Champions", "UHC", 20);
35 pub const BATTLEGROUND: Self = Self("BATTLEGROUND", "Warlords", "Battleground", 23);
36 pub const SUPER_SMASH: Self = Self("SUPER_SMASH", "Smash Heroes", "SuperSmash", 24);
37 pub const GINGERBREAD: Self = Self("GINGERBREAD", "Turbo Kart Racers", "GingerBread", 25);
38 pub const HOUSING: Self = Self("HOUSING", "Housing", "Housing", 26);
39 pub const SKYWARS: Self = Self("SKYWARS", "SkyWars", "SkyWars", 51);
40 pub const TRUE_COMBAT: Self = Self("TRUE_COMBAT", "Crazy Walls", "TrueCombat", 52);
41 pub const SPEED_UHC: Self = Self("SPEED_UHC", "Speed UHC", "SpeedUHC", 54);
42 pub const SKYCLASH: Self = Self("SKYCLASH", "SkyClash", "SkyClash", 55);
43 pub const LEGACY: Self = Self("LEGACY", "Classic Games", "Legacy", 56);
44 pub const PROTOTYPE: Self = Self("PROTOTYPE", "Prototype", "Prototype", 57);
45 pub const BEDWARS: Self = Self("BEDWARS", "Bed Wars", "Bedwars", 58);
46 pub const MURDER_MYSTERY: Self = Self("MURDER_MYSTERY", "Murder Mystery", "MurderMystery", 59);
47 pub const BUILD_BATTLE: Self = Self("BUILD_BATTLE", "Build Battle", "BuildBattle", 60);
48 pub const DUELS: Self = Self("DUELS", "Duels", "Duels", 61);
49 pub const SKYBLOCK: Self = Self("SKYBLOCK", "SkyBlock", "SkyBlock", 63);
50 pub const PIT: Self = Self("PIT", "Pit", "Pit", 64);
51 pub const REPLAY: Self = Self("REPLAY", "Replay", "Replay", 65);
52 pub const SMP: Self = Self("SMP", "SMP", "SMP", 67);
53 pub const WOOL_GAMES: Self = Self("WOOL_GAMES", "Wool Wars", "WoolGames", 68);
54 pub const UNKNOWN: Self = Self("UNKNOWN", "Unknown", "Unknown", -1);
55}
56
57impl Serialize for GameType {
58 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
59 where
60 S: Serializer,
61 {
62 serializer.serialize_str(self.0)
63 }
64}
65
66impl<'de> Deserialize<'de> for GameType {
67 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
68 where
69 D: Deserializer<'de>,
70 {
71 struct GameTypeVisitor;
72
73 impl<'de> Visitor<'de> for GameTypeVisitor {
74 type Value = GameType;
75
76 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
77 formatter.write_str("a u64 or String")
78 }
79
80 fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E>
81 where
82 E: de::Error,
83 {
84 Ok(GameType::from(value))
85 }
86
87 fn visit_string<E>(self, value: String) -> Result<Self::Value, E>
88 where
89 E: de::Error,
90 {
91 Ok(GameType::from(value))
92 }
93
94 fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
95 where
96 E: de::Error,
97 {
98 Ok(GameType::from(value.to_string()))
99 }
100 }
101
102 deserializer.deserialize_any(GameTypeVisitor)
103 }
104}
105
106impl From<u64> for GameType {
107 fn from(v: u64) -> Self {
108 match v {
109 2 => GameType::QUAKECRAFT,
110 3 => GameType::WALLS,
111 4 => GameType::PAINTBALL,
112 5 => GameType::SURVIVAL_GAMES,
113 6 => GameType::TNTGAMES,
114 7 => GameType::VAMPIREZ,
115 13 => GameType::WALLS3,
116 14 => GameType::ARCADE,
117 17 => GameType::ARENA,
118 21 => GameType::MCGO,
119 20 => GameType::UHC,
120 23 => GameType::BATTLEGROUND,
121 24 => GameType::SUPER_SMASH,
122 25 => GameType::GINGERBREAD,
123 26 => GameType::HOUSING,
124 51 => GameType::SKYWARS,
125 52 => GameType::TRUE_COMBAT,
126 54 => GameType::SPEED_UHC,
127 55 => GameType::SKYCLASH,
128 56 => GameType::LEGACY,
129 57 => GameType::PROTOTYPE,
130 58 => GameType::BEDWARS,
131 59 => GameType::MURDER_MYSTERY,
132 60 => GameType::BUILD_BATTLE,
133 61 => GameType::DUELS,
134 63 => GameType::SKYBLOCK,
135 64 => GameType::PIT,
136 65 => GameType::REPLAY,
137 67 => GameType::SMP,
138 68 => GameType::WOOL_GAMES,
139 _ => GameType::UNKNOWN,
140 }
141 }
142}
143
144impl From<String> for GameType {
145 fn from(v: String) -> Self {
146 match v.as_str() {
147 "QUAKECRAFT" => GameType::QUAKECRAFT,
148 "WALLS" => GameType::WALLS,
149 "PAINTBALL" => GameType::PAINTBALL,
150 "SURVIVAL_GAMES" => GameType::SURVIVAL_GAMES,
151 "TNTGAMES" => GameType::TNTGAMES,
152 "VAMPIREZ" => GameType::VAMPIREZ,
153 "WALLS3" => GameType::WALLS3,
154 "ARCADE" => GameType::ARCADE,
155 "ARENA" => GameType::ARENA,
156 "MCGO" => GameType::MCGO,
157 "UHC" => GameType::UHC,
158 "BATTLEGROUND" => GameType::BATTLEGROUND,
159 "SUPER_SMASH" => GameType::SUPER_SMASH,
160 "GINGERBREAD" => GameType::GINGERBREAD,
161 "HOUSING" => GameType::HOUSING,
162 "SKYWARS" => GameType::SKYWARS,
163 "TRUE_COMBAT" => GameType::TRUE_COMBAT,
164 "SPEED_UHC" => GameType::SPEED_UHC,
165 "SKYCLASH" => GameType::SKYCLASH,
166 "LEGACY" => GameType::LEGACY,
167 "PROTOTYPE" => GameType::PROTOTYPE,
168 "BEDWARS" => GameType::BEDWARS,
169 "MURDER_MYSTERY" => GameType::MURDER_MYSTERY,
170 "BUILD_BATTLE" => GameType::BUILD_BATTLE,
171 "DUELS" => GameType::DUELS,
172 "SKYBLOCK" => GameType::SKYBLOCK,
173 "PIT" => GameType::PIT,
174 "REPLAY" => GameType::REPLAY,
175 "SMP" => GameType::SMP,
176 "WOOL_GAMES" => GameType::WOOL_GAMES,
177 _ => GameType::UNKNOWN,
178 }
179 }
180}