gameServer2/src/server/room.rs
author alfadur
Wed, 27 Jun 2018 17:58:33 +0300
changeset 13431 f091f69d59e4
parent 13428 87a6cad20c90
child 13432 6f6a866c86a2
permissions -rw-r--r--
Additional round cleanup
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
     1
use std::{iter};
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
     2
use server::{
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
     3
    coretypes::{TeamInfo, GameCfg, GameCfg::*},
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
     4
    client::{ClientId, HWClient}
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
     5
};
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
     6
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
     7
const MAX_HEDGEHOGS_IN_ROOM: u8 = 48;
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
     8
pub type RoomId = usize;
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
     9
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    10
struct Ammo {
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    11
    name: String,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    12
    settings: Option<String>
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    13
}
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    14
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    15
struct Scheme {
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    16
    name: String,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    17
    settings: Option<Vec<String>>
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    18
}
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    19
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    20
struct RoomConfig {
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    21
    feature_size: u32,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    22
    map_type: String,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    23
    map_generator: u32,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    24
    maze_size: u32,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    25
    seed: String,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    26
    template: u32,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    27
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    28
    ammo: Ammo,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    29
    scheme: Scheme,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    30
    script: String,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    31
    theme: String,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    32
    drawn_map: Option<String>
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    33
}
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    34
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    35
impl RoomConfig {
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    36
    fn new() -> RoomConfig {
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    37
        RoomConfig {
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    38
            feature_size: 12,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    39
            map_type: "+rnd+".to_string(),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    40
            map_generator: 0,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    41
            maze_size: 0,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    42
            seed: "seed".to_string(),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    43
            template: 0,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    44
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    45
            ammo: Ammo {name: "Default".to_string(), settings: None },
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    46
            scheme: Scheme {name: "Default".to_string(), settings: None },
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    47
            script: "Normal".to_string(),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    48
            theme: "\u{1f994}".to_string(),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    49
            drawn_map: None
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    50
        }
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    51
    }
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    52
}
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    53
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    54
pub struct GameInfo {
13431
f091f69d59e4 Additional round cleanup
alfadur
parents: 13428
diff changeset
    55
    pub teams_in_game: u8,
f091f69d59e4 Additional round cleanup
alfadur
parents: 13428
diff changeset
    56
    pub left_teams: Vec<String>
f091f69d59e4 Additional round cleanup
alfadur
parents: 13428
diff changeset
    57
}
f091f69d59e4 Additional round cleanup
alfadur
parents: 13428
diff changeset
    58
f091f69d59e4 Additional round cleanup
alfadur
parents: 13428
diff changeset
    59
impl GameInfo {
f091f69d59e4 Additional round cleanup
alfadur
parents: 13428
diff changeset
    60
    pub fn new(teams_number: u8) -> GameInfo {
f091f69d59e4 Additional round cleanup
alfadur
parents: 13428
diff changeset
    61
        GameInfo {
f091f69d59e4 Additional round cleanup
alfadur
parents: 13428
diff changeset
    62
            teams_in_game: teams_number,
f091f69d59e4 Additional round cleanup
alfadur
parents: 13428
diff changeset
    63
            left_teams: Vec::new()
f091f69d59e4 Additional round cleanup
alfadur
parents: 13428
diff changeset
    64
        }
f091f69d59e4 Additional round cleanup
alfadur
parents: 13428
diff changeset
    65
    }
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    66
}
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    67
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    68
pub struct HWRoom {
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    69
    pub id: RoomId,
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
    70
    pub master_id: Option<ClientId>,
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    71
    pub name: String,
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    72
    pub password: Option<String>,
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    73
    pub protocol_number: u32,
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
    74
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
    75
    pub players_number: u32,
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    76
    pub default_hedgehog_number: u8,
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    77
    pub team_limit: u8,
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    78
    pub ready_players_number: u8,
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    79
    pub teams: Vec<(ClientId, TeamInfo)>,
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    80
    config: RoomConfig,
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
    81
    pub game_info: Option<GameInfo>
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    82
}
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    83
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    84
impl HWRoom {
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    85
    pub fn new(id: RoomId) -> HWRoom {
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    86
        HWRoom {
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    87
            id,
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
    88
            master_id: None,
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    89
            name: String::new(),
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    90
            password: None,
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    91
            protocol_number: 0,
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
    92
            players_number: 0,
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    93
            default_hedgehog_number: 4,
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    94
            team_limit: 8,
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    95
            ready_players_number: 0,
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    96
            teams: Vec::new(),
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    97
            config: RoomConfig::new(),
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    98
            game_info: None
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    99
        }
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
   100
    }
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   101
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   102
    pub fn hedgehogs_number(&self) -> u8 {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   103
        self.teams.iter().map(|(_, t)| t.hedgehogs_number).sum()
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   104
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   105
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   106
    pub fn addable_hedgehogs(&self) -> u8 {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   107
        MAX_HEDGEHOGS_IN_ROOM - self.hedgehogs_number()
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   108
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   109
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   110
    pub fn add_team(&mut self, owner_id: ClientId, mut team: TeamInfo) -> &TeamInfo {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   111
        team.color = iter::repeat(()).enumerate()
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   112
            .map(|(i, _)| i as u8).take(u8::max_value() as usize + 1)
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   113
            .find(|i| self.teams.iter().all(|(_, t)| t.color != *i ))
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   114
            .unwrap_or(0u8);
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   115
        team.hedgehogs_number = if self.teams.is_empty() {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   116
            self.default_hedgehog_number
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   117
        } else {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   118
            self.teams[0].1.hedgehogs_number.min(self.addable_hedgehogs())
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   119
        };
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   120
        self.teams.push((owner_id, team));
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   121
        &self.teams.last().unwrap().1
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   122
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   123
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   124
    pub fn remove_team(&mut self, name: &str) {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   125
        if let Some(index) = self.teams.iter().position(|(_, t)| t.name == name) {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   126
            self.teams.remove(index);
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   127
        }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   128
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   129
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   130
    pub fn find_team_and_owner_mut<F>(&mut self, f: F) -> Option<(ClientId, &mut TeamInfo)>
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   131
        where F: Fn(&TeamInfo) -> bool {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   132
        self.teams.iter_mut().find(|(_, t)| f(t)).map(|(id, t)| (*id, t))
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   133
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   134
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   135
    pub fn find_team<F>(&self, f: F) -> Option<&TeamInfo>
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   136
        where F: Fn(&TeamInfo) -> bool {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   137
        self.teams.iter().map(|(_, t)| t).find(|t| f(*t))
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   138
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   139
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   140
    pub fn client_teams(&self, client_id: ClientId) -> impl Iterator<Item = &TeamInfo> {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   141
        self.teams.iter().filter(move |(id, _)| *id == client_id).map(|(_, t)| t)
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   142
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   143
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   144
    pub fn client_team_indices(&self, client_id: ClientId) -> Vec<u8> {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   145
        self.teams.iter().enumerate()
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   146
            .filter(move |(_, (id, _))| *id == client_id)
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   147
            .map(|(i, _)| i as u8).collect()
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   148
    }
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   149
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   150
    pub fn find_team_owner(&self, team_name: &str) -> Option<(ClientId, &str)> {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   151
        self.teams.iter().find(|(_, t)| t.name == team_name)
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   152
            .map(|(id, t)| (*id, &t.name[..]))
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   153
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   154
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   155
    pub fn find_team_color(&self, owner_id: ClientId) -> Option<u8> {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   156
        self.client_teams(owner_id).nth(0).map(|t| t.color)
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   157
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   158
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   159
    pub fn has_multiple_clans(&self) -> bool {
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   160
        self.teams.iter().min_by_key(|(_, t)| t.color) !=
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   161
            self.teams.iter().max_by_key(|(_, t)| t.color)
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   162
    }
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13427
diff changeset
   163
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   164
    pub fn set_config(&mut self, cfg: GameCfg) {
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   165
        let c = &mut self.config;
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   166
        match cfg {
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   167
            FeatureSize(s) => c.feature_size = s,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   168
            MapType(t) => c.map_type = t,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   169
            MapGenerator(g) => c.map_generator = g,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   170
            MazeSize(s) => c.maze_size = s,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   171
            Seed(s) => c.seed = s,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   172
            Template(t) => c.template = t,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   173
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   174
            Ammo(n, s) => c.ammo = Ammo {name: n, settings: s},
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   175
            Scheme(n, s) => c.scheme = Scheme {name: n, settings: s},
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   176
            Script(s) => c.script = s,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   177
            Theme(t) => c.theme = t,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   178
            DrawnMap(m) => c.drawn_map = Some(m)
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   179
        };
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   180
    }
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   181
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   182
    pub fn info(&self, master: Option<&HWClient>) -> Vec<String> {
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   183
        let flags = "-".to_string();
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   184
        let c = &self.config;
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   185
        vec![
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   186
            flags,
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   187
            self.name.clone(),
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   188
            self.players_number.to_string(),
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   189
            self.teams.len().to_string(),
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   190
            master.map_or("[]", |c| &c.nick).to_string(),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   191
            c.map_type.to_string(),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   192
            c.script.to_string(),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   193
            c.scheme.name.to_string(),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   194
            c.ammo.name.to_string()
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   195
        ]
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   196
    }
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   197
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   198
    pub fn map_config(&self) -> Vec<String> {
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   199
        let c = &self.config;
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   200
        vec![c.feature_size.to_string(), c.map_type.to_string(),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   201
             c.map_generator.to_string(), c.maze_size.to_string(),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   202
             c.seed.to_string(), c.template.to_string()]
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   203
    }
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   204
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   205
    pub fn game_config(&self) -> Vec<GameCfg> {
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   206
        use server::coretypes::GameCfg::*;
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   207
        let c = &self.config;
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   208
        let mut v = vec![
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   209
            Ammo(c.ammo.name.to_string(), c.ammo.settings.clone()),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   210
            Scheme(c.scheme.name.to_string(), c.scheme.settings.clone()),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   211
            Script(c.script.to_string()),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   212
            Theme(c.theme.to_string())];
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   213
        if let Some(ref m) = c.drawn_map {
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   214
            v.push(DrawnMap(m.to_string()))
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   215
        }
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   216
        v
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   217
    }
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   218
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   219
    pub fn team_info(owner: &HWClient, team: &TeamInfo) -> Vec<String> {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   220
        let mut info = vec![
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   221
            team.name.clone(),
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   222
            team.grave.clone(),
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   223
            team.fort.clone(),
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   224
            team.voice_pack.clone(),
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   225
            team.flag.clone(),
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   226
            owner.nick.clone(),
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   227
            team.difficulty.to_string()];
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   228
        let hogs = team.hedgehogs.iter().flat_map(|h|
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   229
            iter::once(h.name.clone()).chain(iter::once(h.hat.clone())));
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   230
        info.extend(hogs);
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   231
        info
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   232
    }
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
   233
}