1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::collections::HashMap;
use std::collections::LinkedList;

pub enum QueryStatus {
    Empty,
    Working,
    Ready,
    Error,
}

pub struct Player {
    pub name: Option<String>,
    pub info: HashMap<String, String>,
}

pub struct Server {
    pub name: Option<String>,
    pub country: Option<String>,
    pub game_mod: Option<String>,
    pub game_type: Option<String>,
    pub need_pass: Option<bool>,
    pub secure: Option<bool>,
    pub player_count: Option<u64>,
    pub player_limit: Option<u64>,
    pub spectator_count: Option<u64>,
    pub spectator_limit: Option<u64>,
    pub terrain: Option<String>,
    pub ping: Option<u64>,
    pub rules: HashMap<String, String>,
    pub players: LinkedList<Player>,
}

type ServerData = std::collections::HashMap<String, Server>;
type GameID = String;

type ConfStorage = std::collections::HashMap<String, String>;

type QueryFunc = fn(GameID, ConfStorage) -> ServerData;

pub struct GameEntry {
    pub status: QueryStatus,
    pub query_func: QueryFunc,
    pub servers: ServerData,
}

fn default_query_func(_: GameID, _: ConfStorage) -> ServerData {
    return ServerData::new();
}

impl Default for GameEntry {
    fn default() -> GameEntry {
        GameEntry {
            status: QueryStatus::Empty,
            query_func: default_query_func,
            servers: ServerData::new(),
        }
    }
}

pub struct GameTable {
    pub data: HashMap<GameID, GameEntry>,
}