author | alfadur <mail@none> |
Sat, 02 Feb 2019 15:06:39 +0300 | |
changeset 14692 | 455865ccd36c |
parent 14478 | 98ef2913ec73 |
child 14696 | dfe652c53470 |
permissions | -rw-r--r-- |
12147 | 1 |
use mio; |
2 |
||
14478 | 3 |
use super::common::rnd_reply; |
13666 | 4 |
use crate::{ |
14478 | 5 |
protocol::messages::{server_chat, HWProtocolMessage, HWServerMessage::*}, |
13666 | 6 |
server::{ |
14478 | 7 |
actions::{Action, Action::*}, |
14395 | 8 |
core::HWServer, |
14478 | 9 |
coretypes::{ClientId, GameCfg, RoomId, VoteType, Voting, MAX_HEDGEHOGS_PER_TEAM}, |
13666 | 10 |
room::{HWRoom, RoomFlags}, |
11 |
}, |
|
14478 | 12 |
utils::is_name_illegal, |
13416 | 13 |
}; |
14478 | 14 |
use base64::{decode, encode}; |
13810 | 15 |
use log::*; |
14478 | 16 |
use std::mem::swap; |
13423 | 17 |
|
18 |
#[derive(Clone)] |
|
19 |
struct ByMsg<'a> { |
|
14478 | 20 |
messages: &'a [u8], |
13423 | 21 |
} |
22 |
||
14478 | 23 |
impl<'a> Iterator for ByMsg<'a> { |
24 |
type Item = &'a [u8]; |
|
13423 | 25 |
|
26 |
fn next(&mut self) -> Option<<Self as Iterator>::Item> { |
|
27 |
if let Some(size) = self.messages.get(0) { |
|
28 |
let (msg, next) = self.messages.split_at(*size as usize + 1); |
|
29 |
self.messages = next; |
|
30 |
Some(msg) |
|
31 |
} else { |
|
32 |
None |
|
33 |
} |
|
34 |
} |
|
35 |
} |
|
36 |
||
13500 | 37 |
fn by_msg(source: &[u8]) -> ByMsg { |
14478 | 38 |
ByMsg { messages: source } |
13423 | 39 |
} |
40 |
||
41 |
const VALID_MESSAGES: &[u8] = |
|
42 |
b"M#+LlRrUuDdZzAaSjJ,NpPwtgfhbc12345\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A"; |
|
43 |
const NON_TIMED_MESSAGES: &[u8] = b"M#hb"; |
|
44 |
||
13429 | 45 |
#[cfg(canhazslicepatterns)] |
13423 | 46 |
fn is_msg_valid(msg: &[u8], team_indices: &[u8]) -> bool { |
13424 | 47 |
match msg { |
14478 | 48 |
[size, typ, body..] => { |
49 |
VALID_MESSAGES.contains(typ) |
|
50 |
&& match body { |
|
51 |
[1...MAX_HEDGEHOGS_PER_TEAM, team, ..] if *typ == b'h' => { |
|
52 |
team_indices.contains(team) |
|
53 |
} |
|
54 |
_ => *typ != b'h', |
|
55 |
} |
|
56 |
} |
|
57 |
_ => false, |
|
13423 | 58 |
} |
59 |
} |
|
60 |
||
13666 | 61 |
fn is_msg_valid(msg: &[u8], _team_indices: &[u8]) -> bool { |
13429 | 62 |
if let Some(typ) = msg.get(1) { |
63 |
VALID_MESSAGES.contains(typ) |
|
64 |
} else { |
|
65 |
false |
|
66 |
} |
|
67 |
} |
|
68 |
||
13423 | 69 |
fn is_msg_empty(msg: &[u8]) -> bool { |
13429 | 70 |
msg.get(1).filter(|t| **t == b'+').is_some() |
13423 | 71 |
} |
12147 | 72 |
|
13443 | 73 |
fn is_msg_timed(msg: &[u8]) -> bool { |
14478 | 74 |
msg.get(1) |
75 |
.filter(|t| !NON_TIMED_MESSAGES.contains(t)) |
|
76 |
.is_some() |
|
13443 | 77 |
} |
78 |
||
13460 | 79 |
fn voting_description(kind: &VoteType) -> String { |
14478 | 80 |
format!( |
81 |
"New voting started: {}", |
|
82 |
match kind { |
|
83 |
VoteType::Kick(nick) => format!("kick {}", nick), |
|
84 |
VoteType::Map(name) => format!("map {}", name.as_ref().unwrap()), |
|
85 |
VoteType::Pause => "pause".to_string(), |
|
86 |
VoteType::NewSeed => "new seed".to_string(), |
|
87 |
VoteType::HedgehogsPerTeam(number) => format!("hedgehogs per team: {}", number), |
|
88 |
} |
|
89 |
) |
|
13460 | 90 |
} |
91 |
||
13494 | 92 |
fn room_message_flag(msg: &HWProtocolMessage) -> RoomFlags { |
13666 | 93 |
use crate::protocol::messages::HWProtocolMessage::*; |
13494 | 94 |
match msg { |
95 |
ToggleRestrictJoin => RoomFlags::RESTRICTED_JOIN, |
|
96 |
ToggleRestrictTeams => RoomFlags::RESTRICTED_TEAM_ADD, |
|
97 |
ToggleRegisteredOnly => RoomFlags::RESTRICTED_UNREGISTERED_PLAYERS, |
|
14478 | 98 |
_ => RoomFlags::empty(), |
13494 | 99 |
} |
100 |
} |
|
101 |
||
14478 | 102 |
pub fn handle( |
103 |
server: &mut HWServer, |
|
104 |
client_id: ClientId, |
|
14692
455865ccd36c
Server action refactoring part 2 of N
alfadur <mail@none>
parents:
14478
diff
changeset
|
105 |
response: &mut super::Response, |
14478 | 106 |
room_id: RoomId, |
107 |
message: HWProtocolMessage, |
|
108 |
) { |
|
13666 | 109 |
use crate::protocol::messages::HWProtocolMessage::*; |
12147 | 110 |
match message { |
13419 | 111 |
Part(None) => server.react(client_id, vec![ |
13416 | 112 |
MoveToLobby("part".to_string())]), |
13419 | 113 |
Part(Some(msg)) => server.react(client_id, vec![ |
13416 | 114 |
MoveToLobby(format!("part: {}", msg))]), |
115 |
Chat(msg) => { |
|
13419 | 116 |
let actions = { |
117 |
let c = &mut server.clients[client_id]; |
|
13500 | 118 |
let chat_msg = ChatMsg {nick: c.nick.clone(), msg}; |
13492 | 119 |
vec![chat_msg.send_all().in_room(room_id).but_self().action()] |
13419 | 120 |
}; |
121 |
server.react(client_id, actions); |
|
13416 | 122 |
}, |
13447 | 123 |
Fix => { |
124 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13494 | 125 |
if c.is_admin() { r.set_is_fixed(true) } |
13447 | 126 |
} |
127 |
} |
|
128 |
Unfix => { |
|
129 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13494 | 130 |
if c.is_admin() { r.set_is_fixed(false) } |
13447 | 131 |
} |
132 |
} |
|
133 |
Greeting(text) => { |
|
134 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13494 | 135 |
if c.is_admin() || c.is_master() && !r.is_fixed() { |
13447 | 136 |
r.greeting = text |
137 |
} |
|
138 |
} |
|
139 |
} |
|
13416 | 140 |
RoomName(new_name) => { |
141 |
let actions = |
|
142 |
if is_name_illegal(&new_name) { |
|
143 |
vec![Warn("Illegal room name! A room name must be between 1-40 characters long, must not have a trailing or leading space and must not have any of these characters: $()*+?[]^{|}".to_string())] |
|
13520 | 144 |
} else if server.rooms[room_id].is_fixed() { |
13447 | 145 |
vec![Warn("Access denied.".to_string())] |
13416 | 146 |
} else if server.has_room(&new_name) { |
147 |
vec![Warn("A room with the same name already exists.".to_string())] |
|
148 |
} else { |
|
149 |
let mut old_name = new_name.clone(); |
|
13520 | 150 |
swap(&mut server.rooms[room_id].name, &mut old_name); |
151 |
vec![SendRoomUpdate(Some(old_name))] |
|
13416 | 152 |
}; |
13419 | 153 |
server.react(client_id, actions); |
154 |
}, |
|
155 |
ToggleReady => { |
|
13666 | 156 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
13486 | 157 |
let flags = if c.is_ready() { |
13419 | 158 |
r.ready_players_number -= 1; |
159 |
"-r" |
|
160 |
} else { |
|
161 |
r.ready_players_number += 1; |
|
162 |
"+r" |
|
163 |
}; |
|
13775 | 164 |
|
165 |
let msg = if c.protocol_number < 38 { |
|
166 |
LegacyReady(c.is_ready(), vec![c.nick.clone()]) |
|
167 |
} else { |
|
168 |
ClientFlags(flags.to_string(), vec![c.nick.clone()]) |
|
169 |
}; |
|
170 |
||
171 |
let mut v = vec![msg.send_all().in_room(r.id).action()]; |
|
172 |
||
13494 | 173 |
if r.is_fixed() && r.ready_players_number == r.players_number { |
13447 | 174 |
v.push(StartRoomGame(r.id)) |
175 |
} |
|
13775 | 176 |
|
177 |
c.set_is_ready(!c.is_ready()); |
|
13666 | 178 |
server.react(client_id, v); |
179 |
} |
|
13416 | 180 |
} |
13422 | 181 |
AddTeam(info) => { |
13419 | 182 |
let mut actions = Vec::new(); |
183 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
184 |
if r.teams.len() >= r.team_limit as usize { |
|
185 |
actions.push(Warn("Too many teams!".to_string())) |
|
186 |
} else if r.addable_hedgehogs() == 0 { |
|
187 |
actions.push(Warn("Too many hedgehogs!".to_string())) |
|
188 |
} else if r.find_team(|t| t.name == info.name) != None { |
|
189 |
actions.push(Warn("There's already a team with same name in the list.".to_string())) |
|
13423 | 190 |
} else if r.game_info.is_some() { |
13419 | 191 |
actions.push(Warn("Joining not possible: Round is in progress.".to_string())) |
13494 | 192 |
} else if r.is_team_add_restricted() { |
193 |
actions.push(Warn("This room currently does not allow adding new teams.".to_string())); |
|
13419 | 194 |
} else { |
13775 | 195 |
let team = r.add_team(c.id, *info, c.protocol_number < 42); |
13419 | 196 |
c.teams_in_game += 1; |
197 |
c.clan = Some(team.color); |
|
198 |
actions.push(TeamAccepted(team.name.clone()) |
|
199 |
.send_self().action()); |
|
200 |
actions.push(TeamAdd(HWRoom::team_info(&c, team)) |
|
201 |
.send_all().in_room(room_id).but_self().action()); |
|
202 |
actions.push(TeamColor(team.name.clone(), team.color) |
|
203 |
.send_all().in_room(room_id).action()); |
|
204 |
actions.push(HedgehogsNumber(team.name.clone(), team.hedgehogs_number) |
|
205 |
.send_all().in_room(room_id).action()); |
|
206 |
actions.push(SendRoomUpdate(None)); |
|
207 |
} |
|
208 |
} |
|
209 |
server.react(client_id, actions); |
|
210 |
}, |
|
211 |
RemoveTeam(name) => { |
|
212 |
let mut actions = Vec::new(); |
|
213 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
214 |
match r.find_team_owner(&name) { |
|
215 |
None => |
|
216 |
actions.push(Warn("Error: The team you tried to remove does not exist.".to_string())), |
|
217 |
Some((id, _)) if id != client_id => |
|
218 |
actions.push(Warn("You can't remove a team you don't own.".to_string())), |
|
219 |
Some((_, name)) => { |
|
220 |
c.teams_in_game -= 1; |
|
221 |
c.clan = r.find_team_color(c.id); |
|
222 |
actions.push(Action::RemoveTeam(name.to_string())); |
|
223 |
} |
|
224 |
} |
|
225 |
}; |
|
226 |
server.react(client_id, actions); |
|
227 |
}, |
|
228 |
SetHedgehogsNumber(team_name, number) => { |
|
13666 | 229 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
13419 | 230 |
let addable_hedgehogs = r.addable_hedgehogs(); |
13666 | 231 |
let actions = if let Some((_, team)) = r.find_team_and_owner_mut(|t| t.name == team_name) { |
13486 | 232 |
if !c.is_master() { |
13419 | 233 |
vec![ProtocolError("You're not the room master!".to_string())] |
13709
e335daaa77a9
Add hogs per team named constant that absolutely no one asked for
alfadur
parents:
13666
diff
changeset
|
234 |
} else if number < 1 || number > MAX_HEDGEHOGS_PER_TEAM |
13419 | 235 |
|| number > addable_hedgehogs + team.hedgehogs_number { |
236 |
vec![HedgehogsNumber(team.name.clone(), team.hedgehogs_number) |
|
237 |
.send_self().action()] |
|
238 |
} else { |
|
239 |
team.hedgehogs_number = number; |
|
240 |
vec![HedgehogsNumber(team.name.clone(), number) |
|
241 |
.send_all().in_room(room_id).but_self().action()] |
|
242 |
} |
|
243 |
} else { |
|
244 |
vec![(Warn("No such team.".to_string()))] |
|
13666 | 245 |
}; |
246 |
server.react(client_id, actions); |
|
247 |
} |
|
13419 | 248 |
}, |
249 |
SetTeamColor(team_name, color) => { |
|
13666 | 250 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
251 |
let mut owner_id = None; |
|
252 |
let actions = if let Some((owner, team)) = r.find_team_and_owner_mut(|t| t.name == team_name) { |
|
13486 | 253 |
if !c.is_master() { |
13419 | 254 |
vec![ProtocolError("You're not the room master!".to_string())] |
255 |
} else if false { |
|
256 |
Vec::new() |
|
257 |
} else { |
|
258 |
owner_id = Some(owner); |
|
259 |
team.color = color; |
|
260 |
vec![TeamColor(team.name.clone(), color) |
|
261 |
.send_all().in_room(room_id).but_self().action()] |
|
262 |
} |
|
263 |
} else { |
|
264 |
vec![(Warn("No such team.".to_string()))] |
|
13666 | 265 |
}; |
13419 | 266 |
|
13666 | 267 |
if let Some(id) = owner_id { |
268 |
server.clients[id].clan = Some(color); |
|
269 |
} |
|
13419 | 270 |
|
13666 | 271 |
server.react(client_id, actions); |
272 |
}; |
|
13422 | 273 |
}, |
274 |
Cfg(cfg) => { |
|
13666 | 275 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
276 |
let actions = if r.is_fixed() { |
|
13447 | 277 |
vec![Warn("Access denied.".to_string())] |
13486 | 278 |
} else if !c.is_master() { |
13422 | 279 |
vec![ProtocolError("You're not the room master!".to_string())] |
280 |
} else { |
|
13775 | 281 |
let cfg = match cfg { |
282 |
GameCfg::Scheme(name, mut values) => { |
|
283 |
if c.protocol_number == 49 && values.len() >= 2 { |
|
284 |
let mut s = "X".repeat(50); |
|
285 |
s.push_str(&values.pop().unwrap()); |
|
286 |
values.push(s); |
|
287 |
} |
|
288 |
GameCfg::Scheme(name, values) |
|
289 |
} |
|
290 |
cfg => cfg |
|
291 |
}; |
|
292 |
||
13439 | 293 |
let v = vec![cfg.to_server_msg() |
294 |
.send_all().in_room(r.id).but_self().action()]; |
|
295 |
r.set_config(cfg); |
|
296 |
v |
|
13666 | 297 |
}; |
298 |
server.react(client_id, actions); |
|
299 |
} |
|
13419 | 300 |
} |
13528 | 301 |
Save(name, location) => { |
302 |
let actions = vec![server_chat(format!("Room config saved as {}", name)) |
|
303 |
.send_all().in_room(room_id).action()]; |
|
304 |
server.rooms[room_id].save_config(name, location); |
|
305 |
server.react(client_id, actions); |
|
306 |
} |
|
13529 | 307 |
SaveRoom(filename) => { |
13666 | 308 |
if server.clients[client_id].is_admin() { |
309 |
let actions = match server.rooms[room_id].get_saves() { |
|
14413 | 310 |
Ok(text) => match server.io.write_file(&filename, &text) { |
13529 | 311 |
Ok(_) => vec![server_chat("Room configs saved successfully.".to_string()) |
312 |
.send_self().action()], |
|
313 |
Err(e) => { |
|
314 |
warn!("Error while writing the config file \"{}\": {}", filename, e); |
|
315 |
vec![Warn("Unable to save the room configs.".to_string())] |
|
316 |
} |
|
317 |
} |
|
318 |
Err(e) => { |
|
319 |
warn!("Error while serializing the room configs: {}", e); |
|
320 |
vec![Warn("Unable to serialize the room configs.".to_string())] |
|
321 |
} |
|
13666 | 322 |
}; |
323 |
server.react(client_id, actions); |
|
324 |
} |
|
13529 | 325 |
} |
326 |
LoadRoom(filename) => { |
|
13666 | 327 |
if server.clients[client_id].is_admin() { |
14413 | 328 |
let actions = match server.io.read_file(&filename) { |
13529 | 329 |
Ok(text) => match server.rooms[room_id].set_saves(&text) { |
330 |
Ok(_) => vec![server_chat("Room configs loaded successfully.".to_string()) |
|
331 |
.send_self().action()], |
|
332 |
Err(e) => { |
|
333 |
warn!("Error while deserializing the room configs: {}", e); |
|
334 |
vec![Warn("Unable to deserialize the room configs.".to_string())] |
|
335 |
} |
|
336 |
} |
|
337 |
Err(e) => { |
|
338 |
warn!("Error while reading the config file \"{}\": {}", filename, e); |
|
339 |
vec![Warn("Unable to load the room configs.".to_string())] |
|
340 |
} |
|
13666 | 341 |
}; |
342 |
server.react(client_id, actions); |
|
343 |
} |
|
13529 | 344 |
} |
13528 | 345 |
Delete(name) => { |
346 |
let actions = if !server.rooms[room_id].delete_config(&name) { |
|
347 |
vec![Warn(format!("Save doesn't exist: {}", name))] |
|
348 |
} else { |
|
349 |
vec![server_chat(format!("Room config {} has been deleted", name)) |
|
350 |
.send_all().in_room(room_id).action()] |
|
351 |
}; |
|
352 |
server.react(client_id, actions); |
|
353 |
} |
|
13450 | 354 |
CallVote(None) => { |
355 |
server.react(client_id, vec![ |
|
13521 | 356 |
server_chat("Available callvote commands: kick <nickname>, map <name>, pause, newseed, hedgehogs <number>".to_string()) |
13450 | 357 |
.send_self().action()]) |
358 |
} |
|
359 |
CallVote(Some(kind)) => { |
|
13492 | 360 |
let is_in_game = server.rooms[room_id].game_info.is_some(); |
13450 | 361 |
let error = match &kind { |
362 |
VoteType::Kick(nick) => { |
|
363 |
if server.find_client(&nick).filter(|c| c.room_id == Some(room_id)).is_some() { |
|
364 |
None |
|
365 |
} else { |
|
13521 | 366 |
Some("/callvote kick: No such user!".to_string()) |
13450 | 367 |
} |
368 |
}, |
|
369 |
VoteType::Map(None) => { |
|
13521 | 370 |
let names: Vec<_> = server.rooms[room_id].saves.keys().cloned().collect(); |
371 |
if names.is_empty() { |
|
372 |
Some("/callvote map: No maps saved in this room!".to_string()) |
|
373 |
} else { |
|
374 |
Some(format!("Available maps: {}", names.join(", "))) |
|
375 |
} |
|
13450 | 376 |
}, |
377 |
VoteType::Map(Some(name)) => { |
|
13521 | 378 |
if server.rooms[room_id].saves.get(&name[..]).is_some() { |
13530 | 379 |
None |
13521 | 380 |
} else { |
13530 | 381 |
Some("/callvote map: No such map!".to_string()) |
13521 | 382 |
} |
13450 | 383 |
}, |
384 |
VoteType::Pause => { |
|
385 |
if is_in_game { |
|
386 |
None |
|
387 |
} else { |
|
13521 | 388 |
Some("/callvote pause: No game in progress!".to_string()) |
13450 | 389 |
} |
390 |
}, |
|
391 |
VoteType::NewSeed => { |
|
392 |
None |
|
393 |
}, |
|
394 |
VoteType::HedgehogsPerTeam(number) => { |
|
395 |
match number { |
|
13709
e335daaa77a9
Add hogs per team named constant that absolutely no one asked for
alfadur
parents:
13666
diff
changeset
|
396 |
1...MAX_HEDGEHOGS_PER_TEAM => None, |
13521 | 397 |
_ => Some("/callvote hedgehogs: Specify number from 1 to 8.".to_string()) |
13450 | 398 |
} |
399 |
}, |
|
400 |
}; |
|
401 |
match error { |
|
402 |
None => { |
|
13460 | 403 |
let msg = voting_description(&kind); |
13450 | 404 |
let voting = Voting::new(kind, server.room_clients(client_id)); |
13520 | 405 |
server.rooms[room_id].voting = Some(voting); |
13450 | 406 |
server.react(client_id, vec![ |
13521 | 407 |
server_chat(msg).send_all().in_room(room_id).action(), |
13450 | 408 |
AddVote{ vote: true, is_forced: false}]); |
409 |
} |
|
410 |
Some(msg) => { |
|
411 |
server.react(client_id, vec![ |
|
412 |
server_chat(msg).send_self().action()]) |
|
413 |
} |
|
414 |
} |
|
415 |
} |
|
416 |
Vote(vote) => { |
|
13520 | 417 |
server.react(client_id, vec![AddVote{ vote, is_forced: false }]); |
13450 | 418 |
} |
419 |
ForceVote(vote) => { |
|
13520 | 420 |
let is_forced = server.clients[client_id].is_admin(); |
421 |
server.react(client_id, vec![AddVote{ vote, is_forced }]); |
|
13450 | 422 |
} |
13494 | 423 |
ToggleRestrictJoin | ToggleRestrictTeams | ToggleRegisteredOnly => { |
424 |
if server.clients[client_id].is_master() { |
|
425 |
server.rooms[room_id].flags.toggle(room_message_flag(&message)); |
|
426 |
} |
|
427 |
server.react(client_id, vec![SendRoomUpdate(None)]); |
|
428 |
} |
|
13423 | 429 |
StartGame => { |
13520 | 430 |
server.react(client_id, vec![StartRoomGame(room_id)]); |
13423 | 431 |
} |
432 |
EngineMessage(em) => { |
|
433 |
let mut actions = Vec::new(); |
|
434 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
435 |
if c.teams_in_game > 0 { |
|
436 |
let decoding = decode(&em[..]).unwrap(); |
|
437 |
let messages = by_msg(&decoding); |
|
13443 | 438 |
let valid = messages.filter(|m| is_msg_valid(m, &c.team_indices)); |
439 |
let non_empty = valid.clone().filter(|m| !is_msg_empty(m)); |
|
440 |
let sync_msg = valid.clone().filter(|m| is_msg_timed(m)) |
|
441 |
.last().map(|m| if is_msg_empty(m) {Some(encode(m))} else {None}); |
|
13423 | 442 |
|
443 |
let em_response = encode(&valid.flat_map(|msg| msg).cloned().collect::<Vec<_>>()); |
|
444 |
if !em_response.is_empty() { |
|
13428 | 445 |
actions.push(ForwardEngineMessage(vec![em_response]) |
13423 | 446 |
.send_all().in_room(r.id).but_self().action()); |
447 |
} |
|
13427 | 448 |
let em_log = encode(&non_empty.flat_map(|msg| msg).cloned().collect::<Vec<_>>()); |
449 |
if let Some(ref mut info) = r.game_info { |
|
13429 | 450 |
if !em_log.is_empty() { |
13428 | 451 |
info.msg_log.push(em_log); |
452 |
} |
|
13443 | 453 |
if let Some(msg) = sync_msg { |
454 |
info.sync_msg = msg; |
|
13427 | 455 |
} |
456 |
} |
|
13423 | 457 |
} |
458 |
} |
|
459 |
server.react(client_id, actions) |
|
460 |
} |
|
461 |
RoundFinished => { |
|
462 |
let mut actions = Vec::new(); |
|
463 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13486 | 464 |
if c.is_in_game() { |
465 |
c.set_is_in_game(false); |
|
13423 | 466 |
actions.push(ClientFlags("-g".to_string(), vec![c.nick.clone()]). |
467 |
send_all().in_room(r.id).action()); |
|
13426 | 468 |
if r.game_info.is_some() { |
469 |
for team in r.client_teams(c.id) { |
|
470 |
actions.push(SendTeamRemovalMessage(team.name.clone())); |
|
471 |
} |
|
13423 | 472 |
} |
473 |
} |
|
474 |
} |
|
475 |
server.react(client_id, actions) |
|
13444
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13443
diff
changeset
|
476 |
}, |
13445
d3c86ade3d4d
Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13444
diff
changeset
|
477 |
Rnd(v) => { |
13492 | 478 |
let result = rnd_reply(&v); |
479 |
let mut echo = vec!["/rnd".to_string()]; |
|
480 |
echo.extend(v.into_iter()); |
|
481 |
let chat_msg = ChatMsg { |
|
482 |
nick: server.clients[client_id].nick.clone(), |
|
483 |
msg: echo.join(" ") |
|
484 |
}; |
|
485 |
server.react(client_id, vec![ |
|
486 |
chat_msg.send_all().in_room(room_id).action(), |
|
487 |
result.send_all().in_room(room_id).action()]) |
|
13445
d3c86ade3d4d
Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13444
diff
changeset
|
488 |
}, |
13419 | 489 |
_ => warn!("Unimplemented!") |
12147 | 490 |
} |
491 |
} |