author | unc0rr |
Sun, 16 Dec 2018 00:12:29 +0100 | |
changeset 14478 | 98ef2913ec73 |
parent 14436 | 06672690d71b |
child 14692 | 455865ccd36c |
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, |
|
105 |
room_id: RoomId, |
|
106 |
message: HWProtocolMessage, |
|
107 |
) { |
|
13666 | 108 |
use crate::protocol::messages::HWProtocolMessage::*; |
12147 | 109 |
match message { |
13419 | 110 |
Part(None) => server.react(client_id, vec![ |
13416 | 111 |
MoveToLobby("part".to_string())]), |
13419 | 112 |
Part(Some(msg)) => server.react(client_id, vec![ |
13416 | 113 |
MoveToLobby(format!("part: {}", msg))]), |
114 |
Chat(msg) => { |
|
13419 | 115 |
let actions = { |
116 |
let c = &mut server.clients[client_id]; |
|
13500 | 117 |
let chat_msg = ChatMsg {nick: c.nick.clone(), msg}; |
13492 | 118 |
vec![chat_msg.send_all().in_room(room_id).but_self().action()] |
13419 | 119 |
}; |
120 |
server.react(client_id, actions); |
|
13416 | 121 |
}, |
13447 | 122 |
Fix => { |
123 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13494 | 124 |
if c.is_admin() { r.set_is_fixed(true) } |
13447 | 125 |
} |
126 |
} |
|
127 |
Unfix => { |
|
128 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13494 | 129 |
if c.is_admin() { r.set_is_fixed(false) } |
13447 | 130 |
} |
131 |
} |
|
132 |
Greeting(text) => { |
|
133 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13494 | 134 |
if c.is_admin() || c.is_master() && !r.is_fixed() { |
13447 | 135 |
r.greeting = text |
136 |
} |
|
137 |
} |
|
138 |
} |
|
13416 | 139 |
RoomName(new_name) => { |
140 |
let actions = |
|
141 |
if is_name_illegal(&new_name) { |
|
142 |
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 | 143 |
} else if server.rooms[room_id].is_fixed() { |
13447 | 144 |
vec![Warn("Access denied.".to_string())] |
13416 | 145 |
} else if server.has_room(&new_name) { |
146 |
vec![Warn("A room with the same name already exists.".to_string())] |
|
147 |
} else { |
|
148 |
let mut old_name = new_name.clone(); |
|
13520 | 149 |
swap(&mut server.rooms[room_id].name, &mut old_name); |
150 |
vec![SendRoomUpdate(Some(old_name))] |
|
13416 | 151 |
}; |
13419 | 152 |
server.react(client_id, actions); |
153 |
}, |
|
154 |
ToggleReady => { |
|
13666 | 155 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
13486 | 156 |
let flags = if c.is_ready() { |
13419 | 157 |
r.ready_players_number -= 1; |
158 |
"-r" |
|
159 |
} else { |
|
160 |
r.ready_players_number += 1; |
|
161 |
"+r" |
|
162 |
}; |
|
13775 | 163 |
|
164 |
let msg = if c.protocol_number < 38 { |
|
165 |
LegacyReady(c.is_ready(), vec![c.nick.clone()]) |
|
166 |
} else { |
|
167 |
ClientFlags(flags.to_string(), vec![c.nick.clone()]) |
|
168 |
}; |
|
169 |
||
170 |
let mut v = vec![msg.send_all().in_room(r.id).action()]; |
|
171 |
||
13494 | 172 |
if r.is_fixed() && r.ready_players_number == r.players_number { |
13447 | 173 |
v.push(StartRoomGame(r.id)) |
174 |
} |
|
13775 | 175 |
|
176 |
c.set_is_ready(!c.is_ready()); |
|
13666 | 177 |
server.react(client_id, v); |
178 |
} |
|
13416 | 179 |
} |
13422 | 180 |
AddTeam(info) => { |
13419 | 181 |
let mut actions = Vec::new(); |
182 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
183 |
if r.teams.len() >= r.team_limit as usize { |
|
184 |
actions.push(Warn("Too many teams!".to_string())) |
|
185 |
} else if r.addable_hedgehogs() == 0 { |
|
186 |
actions.push(Warn("Too many hedgehogs!".to_string())) |
|
187 |
} else if r.find_team(|t| t.name == info.name) != None { |
|
188 |
actions.push(Warn("There's already a team with same name in the list.".to_string())) |
|
13423 | 189 |
} else if r.game_info.is_some() { |
13419 | 190 |
actions.push(Warn("Joining not possible: Round is in progress.".to_string())) |
13494 | 191 |
} else if r.is_team_add_restricted() { |
192 |
actions.push(Warn("This room currently does not allow adding new teams.".to_string())); |
|
13419 | 193 |
} else { |
13775 | 194 |
let team = r.add_team(c.id, *info, c.protocol_number < 42); |
13419 | 195 |
c.teams_in_game += 1; |
196 |
c.clan = Some(team.color); |
|
197 |
actions.push(TeamAccepted(team.name.clone()) |
|
198 |
.send_self().action()); |
|
199 |
actions.push(TeamAdd(HWRoom::team_info(&c, team)) |
|
200 |
.send_all().in_room(room_id).but_self().action()); |
|
201 |
actions.push(TeamColor(team.name.clone(), team.color) |
|
202 |
.send_all().in_room(room_id).action()); |
|
203 |
actions.push(HedgehogsNumber(team.name.clone(), team.hedgehogs_number) |
|
204 |
.send_all().in_room(room_id).action()); |
|
205 |
actions.push(SendRoomUpdate(None)); |
|
206 |
} |
|
207 |
} |
|
208 |
server.react(client_id, actions); |
|
209 |
}, |
|
210 |
RemoveTeam(name) => { |
|
211 |
let mut actions = Vec::new(); |
|
212 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
213 |
match r.find_team_owner(&name) { |
|
214 |
None => |
|
215 |
actions.push(Warn("Error: The team you tried to remove does not exist.".to_string())), |
|
216 |
Some((id, _)) if id != client_id => |
|
217 |
actions.push(Warn("You can't remove a team you don't own.".to_string())), |
|
218 |
Some((_, name)) => { |
|
219 |
c.teams_in_game -= 1; |
|
220 |
c.clan = r.find_team_color(c.id); |
|
221 |
actions.push(Action::RemoveTeam(name.to_string())); |
|
222 |
} |
|
223 |
} |
|
224 |
}; |
|
225 |
server.react(client_id, actions); |
|
226 |
}, |
|
227 |
SetHedgehogsNumber(team_name, number) => { |
|
13666 | 228 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
13419 | 229 |
let addable_hedgehogs = r.addable_hedgehogs(); |
13666 | 230 |
let actions = if let Some((_, team)) = r.find_team_and_owner_mut(|t| t.name == team_name) { |
13486 | 231 |
if !c.is_master() { |
13419 | 232 |
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
|
233 |
} else if number < 1 || number > MAX_HEDGEHOGS_PER_TEAM |
13419 | 234 |
|| number > addable_hedgehogs + team.hedgehogs_number { |
235 |
vec![HedgehogsNumber(team.name.clone(), team.hedgehogs_number) |
|
236 |
.send_self().action()] |
|
237 |
} else { |
|
238 |
team.hedgehogs_number = number; |
|
239 |
vec![HedgehogsNumber(team.name.clone(), number) |
|
240 |
.send_all().in_room(room_id).but_self().action()] |
|
241 |
} |
|
242 |
} else { |
|
243 |
vec![(Warn("No such team.".to_string()))] |
|
13666 | 244 |
}; |
245 |
server.react(client_id, actions); |
|
246 |
} |
|
13419 | 247 |
}, |
248 |
SetTeamColor(team_name, color) => { |
|
13666 | 249 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
250 |
let mut owner_id = None; |
|
251 |
let actions = if let Some((owner, team)) = r.find_team_and_owner_mut(|t| t.name == team_name) { |
|
13486 | 252 |
if !c.is_master() { |
13419 | 253 |
vec![ProtocolError("You're not the room master!".to_string())] |
254 |
} else if false { |
|
255 |
Vec::new() |
|
256 |
} else { |
|
257 |
owner_id = Some(owner); |
|
258 |
team.color = color; |
|
259 |
vec![TeamColor(team.name.clone(), color) |
|
260 |
.send_all().in_room(room_id).but_self().action()] |
|
261 |
} |
|
262 |
} else { |
|
263 |
vec![(Warn("No such team.".to_string()))] |
|
13666 | 264 |
}; |
13419 | 265 |
|
13666 | 266 |
if let Some(id) = owner_id { |
267 |
server.clients[id].clan = Some(color); |
|
268 |
} |
|
13419 | 269 |
|
13666 | 270 |
server.react(client_id, actions); |
271 |
}; |
|
13422 | 272 |
}, |
273 |
Cfg(cfg) => { |
|
13666 | 274 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
275 |
let actions = if r.is_fixed() { |
|
13447 | 276 |
vec![Warn("Access denied.".to_string())] |
13486 | 277 |
} else if !c.is_master() { |
13422 | 278 |
vec![ProtocolError("You're not the room master!".to_string())] |
279 |
} else { |
|
13775 | 280 |
let cfg = match cfg { |
281 |
GameCfg::Scheme(name, mut values) => { |
|
282 |
if c.protocol_number == 49 && values.len() >= 2 { |
|
283 |
let mut s = "X".repeat(50); |
|
284 |
s.push_str(&values.pop().unwrap()); |
|
285 |
values.push(s); |
|
286 |
} |
|
287 |
GameCfg::Scheme(name, values) |
|
288 |
} |
|
289 |
cfg => cfg |
|
290 |
}; |
|
291 |
||
13439 | 292 |
let v = vec![cfg.to_server_msg() |
293 |
.send_all().in_room(r.id).but_self().action()]; |
|
294 |
r.set_config(cfg); |
|
295 |
v |
|
13666 | 296 |
}; |
297 |
server.react(client_id, actions); |
|
298 |
} |
|
13419 | 299 |
} |
13528 | 300 |
Save(name, location) => { |
301 |
let actions = vec![server_chat(format!("Room config saved as {}", name)) |
|
302 |
.send_all().in_room(room_id).action()]; |
|
303 |
server.rooms[room_id].save_config(name, location); |
|
304 |
server.react(client_id, actions); |
|
305 |
} |
|
13529 | 306 |
SaveRoom(filename) => { |
13666 | 307 |
if server.clients[client_id].is_admin() { |
308 |
let actions = match server.rooms[room_id].get_saves() { |
|
14413 | 309 |
Ok(text) => match server.io.write_file(&filename, &text) { |
13529 | 310 |
Ok(_) => vec![server_chat("Room configs saved successfully.".to_string()) |
311 |
.send_self().action()], |
|
312 |
Err(e) => { |
|
313 |
warn!("Error while writing the config file \"{}\": {}", filename, e); |
|
314 |
vec![Warn("Unable to save the room configs.".to_string())] |
|
315 |
} |
|
316 |
} |
|
317 |
Err(e) => { |
|
318 |
warn!("Error while serializing the room configs: {}", e); |
|
319 |
vec![Warn("Unable to serialize the room configs.".to_string())] |
|
320 |
} |
|
13666 | 321 |
}; |
322 |
server.react(client_id, actions); |
|
323 |
} |
|
13529 | 324 |
} |
325 |
LoadRoom(filename) => { |
|
13666 | 326 |
if server.clients[client_id].is_admin() { |
14413 | 327 |
let actions = match server.io.read_file(&filename) { |
13529 | 328 |
Ok(text) => match server.rooms[room_id].set_saves(&text) { |
329 |
Ok(_) => vec![server_chat("Room configs loaded successfully.".to_string()) |
|
330 |
.send_self().action()], |
|
331 |
Err(e) => { |
|
332 |
warn!("Error while deserializing the room configs: {}", e); |
|
333 |
vec![Warn("Unable to deserialize the room configs.".to_string())] |
|
334 |
} |
|
335 |
} |
|
336 |
Err(e) => { |
|
337 |
warn!("Error while reading the config file \"{}\": {}", filename, e); |
|
338 |
vec![Warn("Unable to load the room configs.".to_string())] |
|
339 |
} |
|
13666 | 340 |
}; |
341 |
server.react(client_id, actions); |
|
342 |
} |
|
13529 | 343 |
} |
13528 | 344 |
Delete(name) => { |
345 |
let actions = if !server.rooms[room_id].delete_config(&name) { |
|
346 |
vec![Warn(format!("Save doesn't exist: {}", name))] |
|
347 |
} else { |
|
348 |
vec![server_chat(format!("Room config {} has been deleted", name)) |
|
349 |
.send_all().in_room(room_id).action()] |
|
350 |
}; |
|
351 |
server.react(client_id, actions); |
|
352 |
} |
|
13450 | 353 |
CallVote(None) => { |
354 |
server.react(client_id, vec![ |
|
13521 | 355 |
server_chat("Available callvote commands: kick <nickname>, map <name>, pause, newseed, hedgehogs <number>".to_string()) |
13450 | 356 |
.send_self().action()]) |
357 |
} |
|
358 |
CallVote(Some(kind)) => { |
|
13492 | 359 |
let is_in_game = server.rooms[room_id].game_info.is_some(); |
13450 | 360 |
let error = match &kind { |
361 |
VoteType::Kick(nick) => { |
|
362 |
if server.find_client(&nick).filter(|c| c.room_id == Some(room_id)).is_some() { |
|
363 |
None |
|
364 |
} else { |
|
13521 | 365 |
Some("/callvote kick: No such user!".to_string()) |
13450 | 366 |
} |
367 |
}, |
|
368 |
VoteType::Map(None) => { |
|
13521 | 369 |
let names: Vec<_> = server.rooms[room_id].saves.keys().cloned().collect(); |
370 |
if names.is_empty() { |
|
371 |
Some("/callvote map: No maps saved in this room!".to_string()) |
|
372 |
} else { |
|
373 |
Some(format!("Available maps: {}", names.join(", "))) |
|
374 |
} |
|
13450 | 375 |
}, |
376 |
VoteType::Map(Some(name)) => { |
|
13521 | 377 |
if server.rooms[room_id].saves.get(&name[..]).is_some() { |
13530 | 378 |
None |
13521 | 379 |
} else { |
13530 | 380 |
Some("/callvote map: No such map!".to_string()) |
13521 | 381 |
} |
13450 | 382 |
}, |
383 |
VoteType::Pause => { |
|
384 |
if is_in_game { |
|
385 |
None |
|
386 |
} else { |
|
13521 | 387 |
Some("/callvote pause: No game in progress!".to_string()) |
13450 | 388 |
} |
389 |
}, |
|
390 |
VoteType::NewSeed => { |
|
391 |
None |
|
392 |
}, |
|
393 |
VoteType::HedgehogsPerTeam(number) => { |
|
394 |
match number { |
|
13709
e335daaa77a9
Add hogs per team named constant that absolutely no one asked for
alfadur
parents:
13666
diff
changeset
|
395 |
1...MAX_HEDGEHOGS_PER_TEAM => None, |
13521 | 396 |
_ => Some("/callvote hedgehogs: Specify number from 1 to 8.".to_string()) |
13450 | 397 |
} |
398 |
}, |
|
399 |
}; |
|
400 |
match error { |
|
401 |
None => { |
|
13460 | 402 |
let msg = voting_description(&kind); |
13450 | 403 |
let voting = Voting::new(kind, server.room_clients(client_id)); |
13520 | 404 |
server.rooms[room_id].voting = Some(voting); |
13450 | 405 |
server.react(client_id, vec![ |
13521 | 406 |
server_chat(msg).send_all().in_room(room_id).action(), |
13450 | 407 |
AddVote{ vote: true, is_forced: false}]); |
408 |
} |
|
409 |
Some(msg) => { |
|
410 |
server.react(client_id, vec![ |
|
411 |
server_chat(msg).send_self().action()]) |
|
412 |
} |
|
413 |
} |
|
414 |
} |
|
415 |
Vote(vote) => { |
|
13520 | 416 |
server.react(client_id, vec![AddVote{ vote, is_forced: false }]); |
13450 | 417 |
} |
418 |
ForceVote(vote) => { |
|
13520 | 419 |
let is_forced = server.clients[client_id].is_admin(); |
420 |
server.react(client_id, vec![AddVote{ vote, is_forced }]); |
|
13450 | 421 |
} |
13494 | 422 |
ToggleRestrictJoin | ToggleRestrictTeams | ToggleRegisteredOnly => { |
423 |
if server.clients[client_id].is_master() { |
|
424 |
server.rooms[room_id].flags.toggle(room_message_flag(&message)); |
|
425 |
} |
|
426 |
server.react(client_id, vec![SendRoomUpdate(None)]); |
|
427 |
} |
|
13423 | 428 |
StartGame => { |
13520 | 429 |
server.react(client_id, vec![StartRoomGame(room_id)]); |
13423 | 430 |
} |
431 |
EngineMessage(em) => { |
|
432 |
let mut actions = Vec::new(); |
|
433 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
434 |
if c.teams_in_game > 0 { |
|
435 |
let decoding = decode(&em[..]).unwrap(); |
|
436 |
let messages = by_msg(&decoding); |
|
13443 | 437 |
let valid = messages.filter(|m| is_msg_valid(m, &c.team_indices)); |
438 |
let non_empty = valid.clone().filter(|m| !is_msg_empty(m)); |
|
439 |
let sync_msg = valid.clone().filter(|m| is_msg_timed(m)) |
|
440 |
.last().map(|m| if is_msg_empty(m) {Some(encode(m))} else {None}); |
|
13423 | 441 |
|
442 |
let em_response = encode(&valid.flat_map(|msg| msg).cloned().collect::<Vec<_>>()); |
|
443 |
if !em_response.is_empty() { |
|
13428 | 444 |
actions.push(ForwardEngineMessage(vec![em_response]) |
13423 | 445 |
.send_all().in_room(r.id).but_self().action()); |
446 |
} |
|
13427 | 447 |
let em_log = encode(&non_empty.flat_map(|msg| msg).cloned().collect::<Vec<_>>()); |
448 |
if let Some(ref mut info) = r.game_info { |
|
13429 | 449 |
if !em_log.is_empty() { |
13428 | 450 |
info.msg_log.push(em_log); |
451 |
} |
|
13443 | 452 |
if let Some(msg) = sync_msg { |
453 |
info.sync_msg = msg; |
|
13427 | 454 |
} |
455 |
} |
|
13423 | 456 |
} |
457 |
} |
|
458 |
server.react(client_id, actions) |
|
459 |
} |
|
460 |
RoundFinished => { |
|
461 |
let mut actions = Vec::new(); |
|
462 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13486 | 463 |
if c.is_in_game() { |
464 |
c.set_is_in_game(false); |
|
13423 | 465 |
actions.push(ClientFlags("-g".to_string(), vec![c.nick.clone()]). |
466 |
send_all().in_room(r.id).action()); |
|
13426 | 467 |
if r.game_info.is_some() { |
468 |
for team in r.client_teams(c.id) { |
|
469 |
actions.push(SendTeamRemovalMessage(team.name.clone())); |
|
470 |
} |
|
13423 | 471 |
} |
472 |
} |
|
473 |
} |
|
474 |
server.react(client_id, actions) |
|
13444
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13443
diff
changeset
|
475 |
}, |
13445
d3c86ade3d4d
Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13444
diff
changeset
|
476 |
Rnd(v) => { |
13492 | 477 |
let result = rnd_reply(&v); |
478 |
let mut echo = vec!["/rnd".to_string()]; |
|
479 |
echo.extend(v.into_iter()); |
|
480 |
let chat_msg = ChatMsg { |
|
481 |
nick: server.clients[client_id].nick.clone(), |
|
482 |
msg: echo.join(" ") |
|
483 |
}; |
|
484 |
server.react(client_id, vec![ |
|
485 |
chat_msg.send_all().in_room(room_id).action(), |
|
486 |
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
|
487 |
}, |
13419 | 488 |
_ => warn!("Unimplemented!") |
12147 | 489 |
} |
490 |
} |