104 pub fn client_teams(&self, client_id: ClientId) -> impl Iterator<Item = &TeamInfo> + Clone { |
104 pub fn client_teams(&self, client_id: ClientId) -> impl Iterator<Item = &TeamInfo> + Clone { |
105 client_teams_impl(&self.teams_at_start, client_id) |
105 client_teams_impl(&self.teams_at_start, client_id) |
106 } |
106 } |
107 } |
107 } |
108 |
108 |
|
109 bitflags!{ |
|
110 pub struct RoomFlags: u8 { |
|
111 const FIXED = 0b0000_0001; |
|
112 const RESTRICTED_JOIN = 0b0000_0010; |
|
113 const RESTRICTED_TEAM_ADD = 0b0000_0100; |
|
114 const RESTRICTED_UNREGISTERED_PLAYERS = 0b0000_1000; |
|
115 } |
|
116 } |
|
117 |
109 pub struct HWRoom { |
118 pub struct HWRoom { |
110 pub id: RoomId, |
119 pub id: RoomId, |
111 pub master_id: Option<ClientId>, |
120 pub master_id: Option<ClientId>, |
112 pub name: String, |
121 pub name: String, |
113 pub password: Option<String>, |
122 pub password: Option<String>, |
|
123 pub greeting: String, |
114 pub protocol_number: u16, |
124 pub protocol_number: u16, |
115 pub greeting: String, |
125 pub flags: RoomFlags, |
116 pub is_fixed: bool, |
126 |
117 |
127 pub players_number: u8, |
118 pub players_number: u32, |
|
119 pub default_hedgehog_number: u8, |
128 pub default_hedgehog_number: u8, |
120 pub team_limit: u8, |
129 pub team_limit: u8, |
121 pub ready_players_number: u8, |
130 pub ready_players_number: u8, |
122 pub teams: Vec<(ClientId, TeamInfo)>, |
131 pub teams: Vec<(ClientId, TeamInfo)>, |
123 config: RoomConfig, |
132 config: RoomConfig, |
248 self.game_info = Some(GameInfo::new( |
257 self.game_info = Some(GameInfo::new( |
249 self.teams.clone(), self.config.clone())); |
258 self.teams.clone(), self.config.clone())); |
250 } |
259 } |
251 } |
260 } |
252 |
261 |
|
262 pub fn is_fixed(&self) -> bool { |
|
263 self.flags.contains(RoomFlags::FIXED) |
|
264 } |
|
265 pub fn is_join_restricted(&self) -> bool { |
|
266 self.flags.contains(RoomFlags::RESTRICTED_JOIN) |
|
267 } |
|
268 pub fn is_team_add_restricted(&self) -> bool { |
|
269 self.flags.contains(RoomFlags::RESTRICTED_TEAM_ADD) |
|
270 } |
|
271 pub fn are_unregistered_players_restricted(&self) -> bool { |
|
272 self.flags.contains(RoomFlags::RESTRICTED_UNREGISTERED_PLAYERS) |
|
273 } |
|
274 |
|
275 pub fn set_is_fixed(&mut self, value: bool) { |
|
276 self.flags.set(RoomFlags::FIXED, value) |
|
277 } |
|
278 pub fn set_join_restriction(&mut self, value: bool) { |
|
279 self.flags.set(RoomFlags::RESTRICTED_JOIN, value) |
|
280 } |
|
281 pub fn set_team_add_restriction(&mut self, value: bool) { |
|
282 self.flags.set(RoomFlags::RESTRICTED_TEAM_ADD, value) |
|
283 } |
|
284 pub fn set_unregistered_players_restriction(&mut self, value: bool) { |
|
285 self.flags.set(RoomFlags::RESTRICTED_UNREGISTERED_PLAYERS, value) |
|
286 } |
|
287 |
|
288 fn flags_string(&self) -> String { |
|
289 let mut result = "-".to_string(); |
|
290 if self.game_info.is_some() { result += "g" } |
|
291 if self.password.is_some() { result += "p" } |
|
292 if self.is_join_restricted() { result += "j" } |
|
293 if self.are_unregistered_players_restricted() { |
|
294 result += "r" |
|
295 } |
|
296 result |
|
297 } |
|
298 |
253 pub fn info(&self, master: Option<&HWClient>) -> Vec<String> { |
299 pub fn info(&self, master: Option<&HWClient>) -> Vec<String> { |
254 let flags = "-".to_string(); |
|
255 let c = &self.config; |
300 let c = &self.config; |
256 vec![ |
301 vec![ |
257 flags, |
302 self.flags_string(), |
258 self.name.clone(), |
303 self.name.clone(), |
259 self.players_number.to_string(), |
304 self.players_number.to_string(), |
260 self.teams.len().to_string(), |
305 self.teams.len().to_string(), |
261 master.map_or("[]", |c| &c.nick).to_string(), |
306 master.map_or("[]", |c| &c.nick).to_string(), |
262 c.map_type.to_string(), |
307 c.map_type.to_string(), |