battlebit_api/endpoints/servers/
mod.rs

1use derive_getters::Getters;
2use serde::{Deserialize, Serialize};
3
4use crate::enums::{MapSize, Gamemode, Region, DayNight, AntiCheat};
5
6/// Data of a single server
7#[allow(dead_code)]
8#[derive(Deserialize, Serialize, Clone, Debug, Getters, PartialEq)]
9#[serde(rename_all(deserialize = "PascalCase"))]
10#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
11pub struct ServerData {
12    #[cfg_attr(feature = "utoipa", schema(example = "Super Awesome Server"))]
13    /// The name of this server.
14    name: String,
15    #[cfg_attr(feature = "utoipa", schema(example = "GenericMap"))]
16    /// The map name that the server runs.
17    map: String,
18    #[cfg_attr(feature = "utoipa", schema(example = MapSize::Ultra))]
19    /// The size of the map.
20    map_size: MapSize,
21    #[cfg_attr(feature = "utoipa", schema(example = Gamemode::Conquest))]
22    /// The current gamemode on this server.
23    gamemode: Gamemode,
24    #[cfg_attr(feature = "utoipa", schema(example = Region::Europe))]
25    /// The region where this server is in.
26    region: Region,
27
28    #[serde(rename(deserialize = "Players"))]
29    #[cfg_attr(feature = "utoipa", schema(example = 124))]
30    /// The amount of players currently playing on this server.
31    // SAFETY: Unless Battlebit upgrades their engine, this number should fit into a u8.
32    player_count: u8,
33
34    #[serde(rename(deserialize = "QueuePlayers"))]
35    #[cfg_attr(feature = "utoipa", schema(example = 2))]
36    /// The amount of players currently in queue to join this server.
37    // SAFETY: The queued player count should realistically never reach 65_535.
38    queued_player_count: u16,
39
40    #[cfg_attr(feature = "utoipa", schema(example = 254))]
41    /// The maximum amount of players that can be on this server.
42    // SAFETY: Unless Battlebit upgrades their engine, this number should fit into a u8.
43    max_players: u8,
44
45    #[cfg_attr(feature = "utoipa", schema(example = 120))]
46    /// The refreshrate/tickrate of this server.
47    // SAFETY: Unless Battlebit upgrades their engine, this number should fit into a u8.
48    hz: u8,
49
50    #[cfg_attr(feature = "utoipa", schema(example = DayNight::Day))]
51    /// Time of day on the map, see DayNight for more info.
52    day_night: DayNight,
53    #[cfg_attr(feature = "utoipa", schema(example = false))]
54    /// Whether or not this server is official.
55    is_official: bool,
56    #[cfg_attr(feature = "utoipa", schema(example = false))]
57    /// Whether or not this server has a password.
58    has_password: bool,
59    #[cfg_attr(feature = "utoipa", schema(example = AntiCheat::EasyAntiCheat))]
60    /// The type of anticheat used on this server. See AntiCHeat for more info.
61    anti_cheat: AntiCheat,
62    #[cfg_attr(feature = "utoipa", schema(example = "Production 2.2.5 Hotfix"))]
63    /// The build that this server runs.
64    build: String,
65}
66
67impl ServerData {
68    /// Small check if this ServerData has `Unknown` fields.  
69    /// Mostly used by me to check if this API client is outdated.
70    pub fn has_unknown(&self) -> bool {
71        if *self.anti_cheat() == AntiCheat::Unknown { return true }
72        if *self.region() == Region::Unknown { return true }
73        if *self.gamemode() == Gamemode::Unknown { return true }
74        if *self.map_size() == MapSize::Unknown { return true }
75
76        false
77    }
78}