gameServer2/src/server/room.rs
author alfadur
Tue, 26 Jun 2018 23:22:38 +0300
changeset 13427 5fb27f94fc3b
parent 13424 81e0ed105f5d
child 13428 87a6cad20c90
permissions -rw-r--r--
Implement game config messages
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
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    54
pub struct HWRoom {
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    55
    pub id: RoomId,
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
    56
    pub master_id: Option<ClientId>,
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    57
    pub name: String,
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    58
    pub password: Option<String>,
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    59
    pub protocol_number: u32,
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
    60
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
    61
    pub players_number: u32,
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    62
    pub default_hedgehog_number: u8,
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    63
    pub team_limit: u8,
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    64
    pub ready_players_number: u8,
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    65
    pub teams: Vec<(ClientId, TeamInfo)>,
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    66
    config: RoomConfig,
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    67
    pub game_info: Option<()>
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    68
}
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    69
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    70
impl HWRoom {
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    71
    pub fn new(id: RoomId) -> HWRoom {
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    72
        HWRoom {
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    73
            id,
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
    74
            master_id: None,
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    75
            name: String::new(),
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    76
            password: None,
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    77
            protocol_number: 0,
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
    78
            players_number: 0,
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    79
            default_hedgehog_number: 4,
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    80
            team_limit: 8,
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    81
            ready_players_number: 0,
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    82
            teams: Vec::new(),
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
    83
            config: RoomConfig::new(),
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    84
            game_info: None
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    85
        }
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    86
    }
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
    87
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    88
    pub fn hedgehogs_number(&self) -> u8 {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    89
        self.teams.iter().map(|(_, t)| t.hedgehogs_number).sum()
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    90
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    91
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    92
    pub fn addable_hedgehogs(&self) -> u8 {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    93
        MAX_HEDGEHOGS_IN_ROOM - self.hedgehogs_number()
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    94
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    95
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    96
    pub fn add_team(&mut self, owner_id: ClientId, mut team: TeamInfo) -> &TeamInfo {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    97
        team.color = iter::repeat(()).enumerate()
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    98
            .map(|(i, _)| i as u8).take(u8::max_value() as usize + 1)
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
    99
            .find(|i| self.teams.iter().all(|(_, t)| t.color != *i ))
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   100
            .unwrap_or(0u8);
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   101
        team.hedgehogs_number = if self.teams.is_empty() {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   102
            self.default_hedgehog_number
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   103
        } else {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   104
            self.teams[0].1.hedgehogs_number.min(self.addable_hedgehogs())
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   105
        };
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   106
        self.teams.push((owner_id, team));
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   107
        &self.teams.last().unwrap().1
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 remove_team(&mut self, name: &str) {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   111
        if let Some(index) = self.teams.iter().position(|(_, t)| t.name == name) {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   112
            self.teams.remove(index);
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   113
        }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   114
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   115
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   116
    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
   117
        where F: Fn(&TeamInfo) -> bool {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   118
        self.teams.iter_mut().find(|(_, t)| f(t)).map(|(id, t)| (*id, t))
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   119
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   120
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   121
    pub fn find_team<F>(&self, f: F) -> Option<&TeamInfo>
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   122
        where F: Fn(&TeamInfo) -> bool {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   123
        self.teams.iter().map(|(_, t)| t).find(|t| f(*t))
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   124
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   125
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   126
    pub fn client_teams(&self, client_id: ClientId) -> impl Iterator<Item = &TeamInfo> {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   127
        self.teams.iter().filter(move |(id, _)| *id == client_id).map(|(_, t)| t)
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_owner(&self, team_name: &str) -> Option<(ClientId, &str)> {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   131
        self.teams.iter().find(|(_, t)| t.name == team_name)
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   132
            .map(|(id, t)| (*id, &t.name[..]))
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_color(&self, owner_id: ClientId) -> Option<u8> {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   136
        self.client_teams(owner_id).nth(0).map(|t| t.color)
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   137
    }
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   138
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   139
    pub fn set_config(&mut self, cfg: GameCfg) {
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   140
        let c = &mut self.config;
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   141
        match cfg {
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   142
            FeatureSize(s) => c.feature_size = s,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   143
            MapType(t) => c.map_type = t,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   144
            MapGenerator(g) => c.map_generator = g,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   145
            MazeSize(s) => c.maze_size = s,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   146
            Seed(s) => c.seed = s,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   147
            Template(t) => c.template = t,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   148
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   149
            Ammo(n, s) => c.ammo = Ammo {name: n, settings: s},
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   150
            Scheme(n, s) => c.scheme = Scheme {name: n, settings: s},
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   151
            Script(s) => c.script = s,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   152
            Theme(t) => c.theme = t,
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   153
            DrawnMap(m) => c.drawn_map = Some(m)
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   154
        };
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   155
    }
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   156
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   157
    pub fn info(&self, master: Option<&HWClient>) -> Vec<String> {
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   158
        let flags = "-".to_string();
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   159
        let c = &self.config;
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   160
        vec![
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   161
            flags,
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   162
            self.name.clone(),
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   163
            self.players_number.to_string(),
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   164
            self.teams.len().to_string(),
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   165
            master.map_or("[]", |c| &c.nick).to_string(),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   166
            c.map_type.to_string(),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   167
            c.script.to_string(),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   168
            c.scheme.name.to_string(),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   169
            c.ammo.name.to_string()
13421
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   170
        ]
cdf69667593b partial room implementation
alfadur
parents: 13124
diff changeset
   171
    }
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   172
13427
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   173
    pub fn map_config(&self) -> Vec<String> {
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   174
        let c = &self.config;
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   175
        vec![c.feature_size.to_string(), c.map_type.to_string(),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   176
             c.map_generator.to_string(), c.maze_size.to_string(),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   177
             c.seed.to_string(), c.template.to_string()]
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   178
    }
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   179
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   180
    pub fn game_config(&self) -> Vec<GameCfg> {
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   181
        use server::coretypes::GameCfg::*;
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   182
        let c = &self.config;
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   183
        let mut v = vec![
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   184
            Ammo(c.ammo.name.to_string(), c.ammo.settings.clone()),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   185
            Scheme(c.scheme.name.to_string(), c.scheme.settings.clone()),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   186
            Script(c.script.to_string()),
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   187
            Theme(c.theme.to_string())];
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   188
        if let Some(ref m) = c.drawn_map {
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   189
            v.push(DrawnMap(m.to_string()))
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   190
        }
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   191
        v
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   192
    }
5fb27f94fc3b Implement game config messages
alfadur
parents: 13424
diff changeset
   193
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   194
    pub fn team_info(owner: &HWClient, team: &TeamInfo) -> Vec<String> {
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   195
        let mut info = vec![
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   196
            team.name.clone(),
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   197
            team.grave.clone(),
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   198
            team.fort.clone(),
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   199
            team.voice_pack.clone(),
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   200
            team.flag.clone(),
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   201
            owner.nick.clone(),
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   202
            team.difficulty.to_string()];
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   203
        let hogs = team.hedgehogs.iter().flat_map(|h|
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   204
            iter::once(h.name.clone()).chain(iter::once(h.hat.clone())));
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   205
        info.extend(hogs);
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   206
        info
81e0ed105f5d implementation of team related messages
alfadur
parents: 13421
diff changeset
   207
    }
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
   208
}