author | alfadur <mail@none> |
Wed, 06 Feb 2019 00:14:04 +0300 | |
changeset 14707 | 9f98086de1b6 |
parent 14704 | 932ff7683653 |
child 14708 | 5122c584804e |
permissions | -rw-r--r-- |
13416 | 1 |
use super::{ |
14478 | 2 |
client::HWClient, |
14395 | 3 |
core::HWServer, |
14478 | 4 |
coretypes::{ClientId, GameCfg, RoomId, VoteType}, |
5 |
handlers, |
|
6 |
room::HWRoom, |
|
13494 | 7 |
room::{GameInfo, RoomFlags}, |
13416 | 8 |
}; |
13666 | 9 |
use crate::{ |
14478 | 10 |
protocol::messages::{server_chat, HWProtocolMessage, HWServerMessage, HWServerMessage::*}, |
11 |
utils::to_engine_msg, |
|
13416 | 12 |
}; |
14478 | 13 |
use rand::{distributions::Uniform, thread_rng, Rng}; |
14 |
use std::{io, io::Write, iter::once, mem::replace}; |
|
12138 | 15 |
|
14477 | 16 |
#[cfg(feature = "official-server")] |
17 |
use super::database; |
|
18 |
||
13419 | 19 |
pub enum Destination { |
13426 | 20 |
ToId(ClientId), |
13419 | 21 |
ToSelf, |
13423 | 22 |
ToAll { |
13419 | 23 |
room_id: Option<RoomId>, |
13486 | 24 |
protocol: Option<u16>, |
14478 | 25 |
skip_self: bool, |
26 |
}, |
|
13419 | 27 |
} |
28 |
||
29 |
pub struct PendingMessage { |
|
30 |
pub destination: Destination, |
|
14478 | 31 |
pub message: HWServerMessage, |
13419 | 32 |
} |
33 |
||
34 |
impl PendingMessage { |
|
13426 | 35 |
pub fn send(message: HWServerMessage, client_id: ClientId) -> PendingMessage { |
14478 | 36 |
PendingMessage { |
37 |
destination: Destination::ToId(client_id), |
|
38 |
message, |
|
39 |
} |
|
13426 | 40 |
} |
41 |
||
13419 | 42 |
pub fn send_self(message: HWServerMessage) -> PendingMessage { |
14478 | 43 |
PendingMessage { |
44 |
destination: Destination::ToSelf, |
|
45 |
message, |
|
46 |
} |
|
13419 | 47 |
} |
48 |
||
49 |
pub fn send_all(message: HWServerMessage) -> PendingMessage { |
|
50 |
let destination = Destination::ToAll { |
|
51 |
room_id: None, |
|
52 |
protocol: None, |
|
53 |
skip_self: false, |
|
54 |
}; |
|
14478 | 55 |
PendingMessage { |
56 |
destination, |
|
57 |
message, |
|
58 |
} |
|
13419 | 59 |
} |
60 |
||
61 |
pub fn in_room(mut self, clients_room_id: RoomId) -> PendingMessage { |
|
14478 | 62 |
if let Destination::ToAll { |
63 |
ref mut room_id, .. |
|
64 |
} = self.destination |
|
65 |
{ |
|
13419 | 66 |
*room_id = Some(clients_room_id) |
67 |
} |
|
68 |
self |
|
69 |
} |
|
70 |
||
13486 | 71 |
pub fn with_protocol(mut self, protocol_number: u16) -> PendingMessage { |
14478 | 72 |
if let Destination::ToAll { |
73 |
ref mut protocol, .. |
|
74 |
} = self.destination |
|
75 |
{ |
|
13419 | 76 |
*protocol = Some(protocol_number) |
77 |
} |
|
78 |
self |
|
79 |
} |
|
80 |
||
81 |
pub fn but_self(mut self) -> PendingMessage { |
|
14478 | 82 |
if let Destination::ToAll { |
83 |
ref mut skip_self, .. |
|
84 |
} = self.destination |
|
85 |
{ |
|
13419 | 86 |
*skip_self = true |
87 |
} |
|
88 |
self |
|
89 |
} |
|
90 |
} |
|
91 |
||
92 |
impl HWServerMessage { |
|
14478 | 93 |
pub fn send(self, client_id: ClientId) -> PendingMessage { |
94 |
PendingMessage::send(self, client_id) |
|
95 |
} |
|
96 |
pub fn send_self(self) -> PendingMessage { |
|
97 |
PendingMessage::send_self(self) |
|
98 |
} |
|
99 |
pub fn send_all(self) -> PendingMessage { |
|
100 |
PendingMessage::send_all(self) |
|
101 |
} |
|
13419 | 102 |
} |
103 |
||
12138 | 104 |
pub enum Action { |
13416 | 105 |
ChangeMaster(RoomId, Option<ClientId>), |
13423 | 106 |
StartRoomGame(RoomId), |
107 |
SendTeamRemovalMessage(String), |
|
108 |
FinishRoomGame(RoomId), |
|
14478 | 109 |
SendRoomData { |
110 |
to: ClientId, |
|
111 |
teams: bool, |
|
112 |
config: bool, |
|
113 |
flags: bool, |
|
114 |
}, |
|
13450 | 115 |
ApplyVoting(VoteType, RoomId), |
12138 | 116 |
} |
12144 | 117 |
|
118 |
use self::Action::*; |
|
119 |
||
13419 | 120 |
pub fn run_action(server: &mut HWServer, client_id: usize, action: Action) { |
12144 | 121 |
match action { |
14478 | 122 |
SendRoomData { |
123 |
to, |
|
124 |
teams, |
|
125 |
config, |
|
126 |
flags, |
|
127 |
} => { |
|
13424 | 128 |
let room_id = server.clients[client_id].room_id; |
129 |
if let Some(r) = room_id.and_then(|id| server.rooms.get(id)) { |
|
130 |
if config { |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
131 |
/* actions.push( |
14478 | 132 |
ConfigEntry("FULLMAPCONFIG".to_string(), r.map_config()) |
133 |
.send(to) |
|
134 |
.action(), |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
135 |
)*/ |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
136 |
; |
13500 | 137 |
for cfg in r.game_config() { |
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
138 |
//actions.push(cfg.to_server_msg().send(to).action()); |
13424 | 139 |
} |
140 |
} |
|
141 |
if teams { |
|
13427 | 142 |
let current_teams = match r.game_info { |
143 |
Some(ref info) => &info.teams_at_start, |
|
14478 | 144 |
None => &r.teams, |
13427 | 145 |
}; |
146 |
for (owner_id, team) in current_teams.iter() { |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
147 |
/*actions.push( |
14478 | 148 |
TeamAdd(HWRoom::team_info(&server.clients[*owner_id], &team)) |
149 |
.send(to) |
|
150 |
.action(), |
|
151 |
); |
|
152 |
actions.push(TeamColor(team.name.clone(), team.color).send(to).action()); |
|
153 |
actions.push( |
|
154 |
HedgehogsNumber(team.name.clone(), team.hedgehogs_number) |
|
155 |
.send(to) |
|
156 |
.action(), |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
157 |
);*/ |
13424 | 158 |
} |
159 |
} |
|
160 |
if flags { |
|
161 |
if let Some(id) = r.master_id { |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
162 |
/* |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
163 |
actions.push( |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
164 |
ClientFlags("+h".to_string(), vec![server.clients[id].nick.clone()]) |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
165 |
.send(to) |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
166 |
.action(), |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
167 |
); |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
168 |
*/ |
13424 | 169 |
} |
14478 | 170 |
let nicks: Vec<_> = server |
171 |
.clients |
|
172 |
.iter() |
|
13486 | 173 |
.filter(|(_, c)| c.room_id == Some(r.id) && c.is_ready()) |
14478 | 174 |
.map(|(_, c)| c.nick.clone()) |
175 |
.collect(); |
|
13424 | 176 |
if !nicks.is_empty() { |
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
177 |
/*actions.push(ClientFlags("+r".to_string(), nicks).send(to).action())*/ |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
178 |
; |
13424 | 179 |
} |
180 |
} |
|
181 |
} |
|
13450 | 182 |
} |
183 |
ApplyVoting(kind, room_id) => { |
|
184 |
let mut actions = Vec::new(); |
|
185 |
let mut id = client_id; |
|
186 |
match kind { |
|
187 |
VoteType::Kick(nick) => { |
|
188 |
if let Some(c) = server.find_client(&nick) { |
|
189 |
if c.room_id == Some(room_id) { |
|
190 |
id = c.id; |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
191 |
//actions.push(Kicked.send_self().action()); |
14696
dfe652c53470
Server action refactoring part 6 of N
alfadur <mail@none>
parents:
14694
diff
changeset
|
192 |
//actions.push(MoveToLobby("kicked".to_string())); |
13450 | 193 |
} |
194 |
} |
|
14478 | 195 |
} |
13521 | 196 |
VoteType::Map(None) => (), |
197 |
VoteType::Map(Some(name)) => { |
|
198 |
if let Some(location) = server.rooms[room_id].load_config(&name) { |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
199 |
/*actions.push( |
14478 | 200 |
server_chat(location.to_string()) |
201 |
.send_all() |
|
202 |
.in_room(room_id) |
|
203 |
.action(), |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
204 |
);*/ |
14707
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
205 |
//actions.push(SendRoomUpdate(None)); |
13521 | 206 |
for (_, c) in server.clients.iter() { |
207 |
if c.room_id == Some(room_id) { |
|
14478 | 208 |
actions.push(SendRoomData { |
209 |
to: c.id, |
|
210 |
teams: false, |
|
211 |
config: true, |
|
212 |
flags: false, |
|
213 |
}) |
|
13521 | 214 |
} |
215 |
} |
|
216 |
} |
|
14478 | 217 |
} |
13450 | 218 |
VoteType::Pause => { |
13460 | 219 |
if let Some(ref mut info) = server.rooms[room_id].game_info { |
13450 | 220 |
info.is_paused = !info.is_paused; |
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
221 |
/*actions.push( |
14478 | 222 |
server_chat("Pause toggled.".to_string()) |
223 |
.send_all() |
|
224 |
.in_room(room_id) |
|
225 |
.action(), |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
226 |
);*/ |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
227 |
/*actions.push( |
14478 | 228 |
ForwardEngineMessage(vec![to_engine_msg(once(b'I'))]) |
229 |
.send_all() |
|
230 |
.in_room(room_id) |
|
231 |
.action(), |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
232 |
);*/ |
13450 | 233 |
} |
14478 | 234 |
} |
13450 | 235 |
VoteType::NewSeed => { |
13460 | 236 |
let seed = thread_rng().gen_range(0, 1_000_000_000).to_string(); |
237 |
let cfg = GameCfg::Seed(seed); |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
238 |
/*actions.push(cfg.to_server_msg().send_all().in_room(room_id).action());*/ |
13460 | 239 |
server.rooms[room_id].set_config(cfg); |
14478 | 240 |
} |
13450 | 241 |
VoteType::HedgehogsPerTeam(number) => { |
242 |
let r = &mut server.rooms[room_id]; |
|
243 |
let nicks = r.set_hedgehogs_number(number); |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
244 |
/*actions.extend(nicks.into_iter().map(|n| { |
14478 | 245 |
HedgehogsNumber(n, number) |
246 |
.send_all() |
|
247 |
.in_room(room_id) |
|
248 |
.action() |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
249 |
}));*/ |
14478 | 250 |
} |
13450 | 251 |
} |
252 |
} |
|
13416 | 253 |
ChangeMaster(room_id, new_id) => { |
254 |
let room_client_ids = server.room_clients(room_id); |
|
14478 | 255 |
let new_id = if server |
256 |
.room(client_id) |
|
257 |
.map(|r| r.is_fixed()) |
|
258 |
.unwrap_or(false) |
|
259 |
{ |
|
13447 | 260 |
new_id |
261 |
} else { |
|
14478 | 262 |
new_id.or_else(|| room_client_ids.iter().find(|id| **id != client_id).cloned()) |
13447 | 263 |
}; |
13416 | 264 |
let new_nick = new_id.map(|id| server.clients[id].nick.clone()); |
265 |
||
13419 | 266 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
267 |
match r.master_id { |
|
268 |
Some(id) if id == c.id => { |
|
13486 | 269 |
c.set_is_master(false); |
13419 | 270 |
r.master_id = None; |
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
271 |
/*actions.push( |
14478 | 272 |
ClientFlags("-h".to_string(), vec![c.nick.clone()]) |
273 |
.send_all() |
|
274 |
.in_room(r.id) |
|
275 |
.action(), |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
276 |
);*/ |
13419 | 277 |
} |
278 |
Some(_) => unreachable!(), |
|
279 |
None => {} |
|
13416 | 280 |
} |
281 |
r.master_id = new_id; |
|
13775 | 282 |
if !r.is_fixed() && c.protocol_number < 42 { |
14478 | 283 |
r.name |
284 |
.replace_range(.., new_nick.as_ref().map_or("[]", String::as_str)); |
|
13775 | 285 |
} |
13494 | 286 |
r.set_join_restriction(false); |
287 |
r.set_team_add_restriction(false); |
|
288 |
let is_fixed = r.is_fixed(); |
|
289 |
r.set_unregistered_players_restriction(is_fixed); |
|
13416 | 290 |
if let Some(nick) = new_nick { |
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
291 |
/*actions.push( |
14478 | 292 |
ClientFlags("+h".to_string(), vec![nick]) |
293 |
.send_all() |
|
294 |
.in_room(r.id) |
|
295 |
.action(), |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
296 |
);*/ |
13416 | 297 |
} |
298 |
} |
|
13666 | 299 |
if let Some(id) = new_id { |
300 |
server.clients[id].set_is_master(true) |
|
301 |
} |
|
14478 | 302 |
} |
13423 | 303 |
StartRoomGame(room_id) => { |
14707
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
304 |
let (room_clients, room_nicks): (Vec<_>, Vec<_>) = server |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
305 |
.clients |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
306 |
.iter() |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
307 |
.map(|(id, c)| (id, c.nick.clone())) |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
308 |
.unzip(); |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
309 |
let room = &mut server.rooms[room_id]; |
13423 | 310 |
|
14707
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
311 |
if !room.has_multiple_clans() { |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
312 |
/*Warn( |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
313 |
"The game can't be started with less than two clans!".to_string(), |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
314 |
)*/ |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
315 |
} else if room.protocol_number <= 43 && room.players_number != room.ready_players_number |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
316 |
{ |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
317 |
/*Warn("Not all players are ready".to_string())*/ |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
318 |
} else if room.game_info.is_some() { |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
319 |
/*Warn("The game is already in progress".to_string())*/ |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
320 |
} else { |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
321 |
room.start_round(); |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
322 |
for id in room_clients { |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
323 |
let c = &mut server.clients[id]; |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
324 |
c.set_is_in_game(false); |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
325 |
c.team_indices = room.client_team_indices(c.id); |
13423 | 326 |
} |
14707
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
327 |
/*RunGame.send_all().in_room(room.id).action(),*/ |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
328 |
//SendRoomUpdate(None), |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
329 |
/*ClientFlags("+g".to_string(), room_nicks) |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
330 |
.send_all() |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
331 |
.in_room(room.id) |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
332 |
.action(),*/ |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
333 |
} |
13416 | 334 |
} |
13423 | 335 |
SendTeamRemovalMessage(team_name) => { |
336 |
let mut actions = Vec::new(); |
|
13521 | 337 |
if let Some(r) = server.room(client_id) { |
13423 | 338 |
if let Some(ref mut info) = r.game_info { |
339 |
let msg = once(b'F').chain(team_name.bytes()); |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
340 |
/*actions.push( |
14478 | 341 |
ForwardEngineMessage(vec![to_engine_msg(msg)]) |
342 |
.send_all() |
|
343 |
.in_room(r.id) |
|
344 |
.but_self() |
|
345 |
.action(), |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
346 |
);*/ |
13423 | 347 |
info.teams_in_game -= 1; |
348 |
if info.teams_in_game == 0 { |
|
349 |
actions.push(FinishRoomGame(r.id)); |
|
350 |
} |
|
13427 | 351 |
let remove_msg = to_engine_msg(once(b'F').chain(team_name.bytes())); |
13443 | 352 |
if let Some(m) = &info.sync_msg { |
353 |
info.msg_log.push(m.clone()); |
|
13427 | 354 |
} |
13443 | 355 |
if info.sync_msg.is_some() { |
356 |
info.sync_msg = None |
|
357 |
} |
|
358 |
info.msg_log.push(remove_msg.clone()); |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
359 |
/*actions.push( |
14478 | 360 |
ForwardEngineMessage(vec![remove_msg]) |
361 |
.send_all() |
|
362 |
.in_room(r.id) |
|
363 |
.but_self() |
|
364 |
.action(), |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
365 |
);*/ |
13423 | 366 |
} |
367 |
} |
|
368 |
} |
|
369 |
FinishRoomGame(room_id) => { |
|
13426 | 370 |
let mut actions = Vec::new(); |
371 |
||
13775 | 372 |
let r = &mut server.rooms[room_id]; |
373 |
r.ready_players_number = 1; |
|
14707
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
374 |
//actions.push(SendRoomUpdate(None)); |
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
375 |
//actions.push(RoundFinished.send_all().in_room(r.id).action()); |
13775 | 376 |
|
377 |
if let Some(info) = replace(&mut r.game_info, None) { |
|
13426 | 378 |
for (_, c) in server.clients.iter() { |
13486 | 379 |
if c.room_id == Some(room_id) && c.is_joined_mid_game() { |
14478 | 380 |
actions.push(SendRoomData { |
381 |
to: c.id, |
|
382 |
teams: false, |
|
383 |
config: true, |
|
384 |
flags: false, |
|
385 |
}); |
|
13500 | 386 |
for name in &info.left_teams { |
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
387 |
//actions.push(TeamRemove(name.clone()).send(c.id).action()); |
13426 | 388 |
} |
389 |
} |
|
390 |
} |
|
391 |
} |
|
392 |
||
14478 | 393 |
let nicks: Vec<_> = server |
394 |
.clients |
|
395 |
.iter_mut() |
|
13426 | 396 |
.filter(|(_, c)| c.room_id == Some(room_id)) |
397 |
.map(|(_, c)| { |
|
13666 | 398 |
c.set_is_ready(c.is_master()); |
13486 | 399 |
c.set_is_joined_mid_game(false); |
13426 | 400 |
c |
14478 | 401 |
}) |
402 |
.filter_map(|c| { |
|
403 |
if !c.is_master() { |
|
404 |
Some(c.nick.clone()) |
|
405 |
} else { |
|
406 |
None |
|
407 |
} |
|
408 |
}) |
|
409 |
.collect(); |
|
13775 | 410 |
|
13426 | 411 |
if !nicks.is_empty() { |
13775 | 412 |
let msg = if r.protocol_number < 38 { |
413 |
LegacyReady(false, nicks) |
|
414 |
} else { |
|
415 |
ClientFlags("-r".to_string(), nicks) |
|
416 |
}; |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
417 |
//actions.push(msg.send_all().in_room(room_id).action()); |
13426 | 418 |
} |
13423 | 419 |
} |
12144 | 420 |
} |
421 |
} |