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