1 use std::iter; |
1 use std::{iter}; |
2 use server::{ |
2 use server::{ |
3 coretypes::{TeamInfo, GameCfg}, |
3 coretypes::{TeamInfo, GameCfg, GameCfg::*}, |
4 client::{ClientId, HWClient} |
4 client::{ClientId, HWClient} |
5 }; |
5 }; |
6 |
6 |
7 const MAX_HEDGEHOGS_IN_ROOM: u8 = 48; |
7 const MAX_HEDGEHOGS_IN_ROOM: u8 = 48; |
8 pub type RoomId = usize; |
8 pub type RoomId = usize; |
|
9 |
|
10 struct Ammo { |
|
11 name: String, |
|
12 settings: Option<String> |
|
13 } |
|
14 |
|
15 struct Scheme { |
|
16 name: String, |
|
17 settings: Option<Vec<String>> |
|
18 } |
|
19 |
|
20 struct RoomConfig { |
|
21 feature_size: u32, |
|
22 map_type: String, |
|
23 map_generator: u32, |
|
24 maze_size: u32, |
|
25 seed: String, |
|
26 template: u32, |
|
27 |
|
28 ammo: Ammo, |
|
29 scheme: Scheme, |
|
30 script: String, |
|
31 theme: String, |
|
32 drawn_map: Option<String> |
|
33 } |
|
34 |
|
35 impl RoomConfig { |
|
36 fn new() -> RoomConfig { |
|
37 RoomConfig { |
|
38 feature_size: 12, |
|
39 map_type: "+rnd+".to_string(), |
|
40 map_generator: 0, |
|
41 maze_size: 0, |
|
42 seed: "seed".to_string(), |
|
43 template: 0, |
|
44 |
|
45 ammo: Ammo {name: "Default".to_string(), settings: None }, |
|
46 scheme: Scheme {name: "Default".to_string(), settings: None }, |
|
47 script: "Normal".to_string(), |
|
48 theme: "\u{1f994}".to_string(), |
|
49 drawn_map: None |
|
50 } |
|
51 } |
|
52 } |
9 |
53 |
10 pub struct HWRoom { |
54 pub struct HWRoom { |
11 pub id: RoomId, |
55 pub id: RoomId, |
12 pub master_id: Option<ClientId>, |
56 pub master_id: Option<ClientId>, |
13 pub name: String, |
57 pub name: String, |
17 pub players_number: u32, |
61 pub players_number: u32, |
18 pub default_hedgehog_number: u8, |
62 pub default_hedgehog_number: u8, |
19 pub team_limit: u8, |
63 pub team_limit: u8, |
20 pub ready_players_number: u8, |
64 pub ready_players_number: u8, |
21 pub teams: Vec<(ClientId, TeamInfo)>, |
65 pub teams: Vec<(ClientId, TeamInfo)>, |
|
66 config: RoomConfig, |
22 pub game_info: Option<()> |
67 pub game_info: Option<()> |
23 } |
68 } |
24 |
69 |
25 impl HWRoom { |
70 impl HWRoom { |
26 pub fn new(id: RoomId) -> HWRoom { |
71 pub fn new(id: RoomId) -> HWRoom { |
88 |
134 |
89 pub fn find_team_color(&self, owner_id: ClientId) -> Option<u8> { |
135 pub fn find_team_color(&self, owner_id: ClientId) -> Option<u8> { |
90 self.client_teams(owner_id).nth(0).map(|t| t.color) |
136 self.client_teams(owner_id).nth(0).map(|t| t.color) |
91 } |
137 } |
92 |
138 |
|
139 pub fn set_config(&mut self, cfg: GameCfg) { |
|
140 let c = &mut self.config; |
|
141 match cfg { |
|
142 FeatureSize(s) => c.feature_size = s, |
|
143 MapType(t) => c.map_type = t, |
|
144 MapGenerator(g) => c.map_generator = g, |
|
145 MazeSize(s) => c.maze_size = s, |
|
146 Seed(s) => c.seed = s, |
|
147 Template(t) => c.template = t, |
|
148 |
|
149 Ammo(n, s) => c.ammo = Ammo {name: n, settings: s}, |
|
150 Scheme(n, s) => c.scheme = Scheme {name: n, settings: s}, |
|
151 Script(s) => c.script = s, |
|
152 Theme(t) => c.theme = t, |
|
153 DrawnMap(m) => c.drawn_map = Some(m) |
|
154 }; |
|
155 } |
|
156 |
93 pub fn info(&self, master: Option<&HWClient>) -> Vec<String> { |
157 pub fn info(&self, master: Option<&HWClient>) -> Vec<String> { |
94 let flags = "-".to_string(); |
158 let flags = "-".to_string(); |
|
159 let c = &self.config; |
95 vec![ |
160 vec![ |
96 flags, |
161 flags, |
97 self.name.clone(), |
162 self.name.clone(), |
98 self.players_number.to_string(), |
163 self.players_number.to_string(), |
99 self.teams.len().to_string(), |
164 self.teams.len().to_string(), |
100 master.map_or("?", |c| &c.nick).to_string(), |
165 master.map_or("[]", |c| &c.nick).to_string(), |
101 "Normal".to_string(), |
166 c.map_type.to_string(), |
102 "Default".to_string(), |
167 c.script.to_string(), |
103 "Default".to_string(), |
168 c.scheme.name.to_string(), |
104 "Default".to_string(), |
169 c.ammo.name.to_string() |
105 ] |
170 ] |
|
171 } |
|
172 |
|
173 pub fn map_config(&self) -> Vec<String> { |
|
174 let c = &self.config; |
|
175 vec![c.feature_size.to_string(), c.map_type.to_string(), |
|
176 c.map_generator.to_string(), c.maze_size.to_string(), |
|
177 c.seed.to_string(), c.template.to_string()] |
|
178 } |
|
179 |
|
180 pub fn game_config(&self) -> Vec<GameCfg> { |
|
181 use server::coretypes::GameCfg::*; |
|
182 let c = &self.config; |
|
183 let mut v = vec![ |
|
184 Ammo(c.ammo.name.to_string(), c.ammo.settings.clone()), |
|
185 Scheme(c.scheme.name.to_string(), c.scheme.settings.clone()), |
|
186 Script(c.script.to_string()), |
|
187 Theme(c.theme.to_string())]; |
|
188 if let Some(ref m) = c.drawn_map { |
|
189 v.push(DrawnMap(m.to_string())) |
|
190 } |
|
191 v |
106 } |
192 } |
107 |
193 |
108 pub fn team_info(owner: &HWClient, team: &TeamInfo) -> Vec<String> { |
194 pub fn team_info(owner: &HWClient, team: &TeamInfo) -> Vec<String> { |
109 let mut info = vec![ |
195 let mut info = vec![ |
110 team.name.clone(), |
196 team.name.clone(), |