author | alfadur |
Mon, 27 Aug 2018 22:28:56 +0300 | |
changeset 13709 | e335daaa77a9 |
parent 13666 | 09f4a30e50cc |
child 13775 | 5fb40c8e5542 |
permissions | -rw-r--r-- |
12147 | 1 |
use mio; |
2 |
||
13666 | 3 |
use crate::{ |
4 |
server::{ |
|
13709
e335daaa77a9
Add hogs per team named constant that absolutely no one asked for
alfadur
parents:
13666
diff
changeset
|
5 |
coretypes::{ |
e335daaa77a9
Add hogs per team named constant that absolutely no one asked for
alfadur
parents:
13666
diff
changeset
|
6 |
ClientId, RoomId, Voting, VoteType, |
e335daaa77a9
Add hogs per team named constant that absolutely no one asked for
alfadur
parents:
13666
diff
changeset
|
7 |
MAX_HEDGEHOGS_PER_TEAM |
e335daaa77a9
Add hogs per team named constant that absolutely no one asked for
alfadur
parents:
13666
diff
changeset
|
8 |
}, |
13666 | 9 |
server::HWServer, |
10 |
room::{HWRoom, RoomFlags}, |
|
11 |
actions::{Action, Action::*} |
|
12 |
}, |
|
13 |
protocol::messages::{ |
|
14 |
HWProtocolMessage, |
|
15 |
HWServerMessage::*, |
|
16 |
server_chat |
|
17 |
}, |
|
18 |
utils::is_name_illegal |
|
13416 | 19 |
}; |
13529 | 20 |
use std::{ |
21 |
mem::swap, fs::{File, OpenOptions}, |
|
22 |
io::{Read, Write, Result, Error, ErrorKind} |
|
23 |
}; |
|
13423 | 24 |
use base64::{encode, decode}; |
13492 | 25 |
use super::common::rnd_reply; |
13423 | 26 |
|
27 |
#[derive(Clone)] |
|
28 |
struct ByMsg<'a> { |
|
29 |
messages: &'a[u8] |
|
30 |
} |
|
31 |
||
32 |
impl <'a> Iterator for ByMsg<'a> { |
|
33 |
type Item = &'a[u8]; |
|
34 |
||
35 |
fn next(&mut self) -> Option<<Self as Iterator>::Item> { |
|
36 |
if let Some(size) = self.messages.get(0) { |
|
37 |
let (msg, next) = self.messages.split_at(*size as usize + 1); |
|
38 |
self.messages = next; |
|
39 |
Some(msg) |
|
40 |
} else { |
|
41 |
None |
|
42 |
} |
|
43 |
} |
|
44 |
} |
|
45 |
||
13500 | 46 |
fn by_msg(source: &[u8]) -> ByMsg { |
47 |
ByMsg {messages: source} |
|
13423 | 48 |
} |
49 |
||
50 |
const VALID_MESSAGES: &[u8] = |
|
51 |
b"M#+LlRrUuDdZzAaSjJ,NpPwtgfhbc12345\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A"; |
|
52 |
const NON_TIMED_MESSAGES: &[u8] = b"M#hb"; |
|
53 |
||
13429 | 54 |
#[cfg(canhazslicepatterns)] |
13423 | 55 |
fn is_msg_valid(msg: &[u8], team_indices: &[u8]) -> bool { |
13424 | 56 |
match msg { |
57 |
[size, typ, body..] => VALID_MESSAGES.contains(typ) |
|
58 |
&& match body { |
|
13709
e335daaa77a9
Add hogs per team named constant that absolutely no one asked for
alfadur
parents:
13666
diff
changeset
|
59 |
[1...MAX_HEDGEHOGS_PER_TEAM, team, ..] if *typ == b'h' => |
e335daaa77a9
Add hogs per team named constant that absolutely no one asked for
alfadur
parents:
13666
diff
changeset
|
60 |
team_indices.contains(team), |
13423 | 61 |
_ => *typ != b'h' |
13424 | 62 |
}, |
63 |
_ => false |
|
13423 | 64 |
} |
65 |
} |
|
66 |
||
13666 | 67 |
fn is_msg_valid(msg: &[u8], _team_indices: &[u8]) -> bool { |
13429 | 68 |
if let Some(typ) = msg.get(1) { |
69 |
VALID_MESSAGES.contains(typ) |
|
70 |
} else { |
|
71 |
false |
|
72 |
} |
|
73 |
} |
|
74 |
||
13423 | 75 |
fn is_msg_empty(msg: &[u8]) -> bool { |
13429 | 76 |
msg.get(1).filter(|t| **t == b'+').is_some() |
13423 | 77 |
} |
12147 | 78 |
|
13443 | 79 |
fn is_msg_timed(msg: &[u8]) -> bool { |
80 |
msg.get(1).filter(|t| !NON_TIMED_MESSAGES.contains(t)).is_some() |
|
81 |
} |
|
82 |
||
13460 | 83 |
fn voting_description(kind: &VoteType) -> String { |
84 |
format!("New voting started: {}", match kind { |
|
85 |
VoteType::Kick(nick) => format!("kick {}", nick), |
|
86 |
VoteType::Map(name) => format!("map {}", name.as_ref().unwrap()), |
|
87 |
VoteType::Pause => "pause".to_string(), |
|
88 |
VoteType::NewSeed => "new seed".to_string(), |
|
89 |
VoteType::HedgehogsPerTeam(number) => format!("hedgehogs per team: {}", number) |
|
90 |
}) |
|
91 |
} |
|
92 |
||
13494 | 93 |
fn room_message_flag(msg: &HWProtocolMessage) -> RoomFlags { |
13666 | 94 |
use crate::protocol::messages::HWProtocolMessage::*; |
13494 | 95 |
match msg { |
96 |
ToggleRestrictJoin => RoomFlags::RESTRICTED_JOIN, |
|
97 |
ToggleRestrictTeams => RoomFlags::RESTRICTED_TEAM_ADD, |
|
98 |
ToggleRegisteredOnly => RoomFlags::RESTRICTED_UNREGISTERED_PLAYERS, |
|
99 |
_ => RoomFlags::empty() |
|
100 |
} |
|
101 |
} |
|
102 |
||
13529 | 103 |
fn read_file(filename: &str) -> Result<String> { |
104 |
let mut reader = File::open(filename)?; |
|
105 |
let mut result = String::new(); |
|
106 |
reader.read_to_string(&mut result)?; |
|
107 |
Ok(result) |
|
108 |
} |
|
109 |
||
110 |
fn write_file(filename: &str, content: &str) -> Result<()> { |
|
111 |
let mut writer = OpenOptions::new().create(true).write(true).open(filename)?; |
|
112 |
writer.write_all(content.as_bytes()) |
|
113 |
} |
|
114 |
||
13492 | 115 |
pub fn handle(server: &mut HWServer, client_id: ClientId, room_id: RoomId, message: HWProtocolMessage) { |
13666 | 116 |
use crate::protocol::messages::HWProtocolMessage::*; |
12147 | 117 |
match message { |
13419 | 118 |
Part(None) => server.react(client_id, vec![ |
13416 | 119 |
MoveToLobby("part".to_string())]), |
13419 | 120 |
Part(Some(msg)) => server.react(client_id, vec![ |
13416 | 121 |
MoveToLobby(format!("part: {}", msg))]), |
122 |
Chat(msg) => { |
|
13419 | 123 |
let actions = { |
124 |
let c = &mut server.clients[client_id]; |
|
13500 | 125 |
let chat_msg = ChatMsg {nick: c.nick.clone(), msg}; |
13492 | 126 |
vec![chat_msg.send_all().in_room(room_id).but_self().action()] |
13419 | 127 |
}; |
128 |
server.react(client_id, actions); |
|
13416 | 129 |
}, |
13447 | 130 |
Fix => { |
131 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13494 | 132 |
if c.is_admin() { r.set_is_fixed(true) } |
13447 | 133 |
} |
134 |
} |
|
135 |
Unfix => { |
|
136 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13494 | 137 |
if c.is_admin() { r.set_is_fixed(false) } |
13447 | 138 |
} |
139 |
} |
|
140 |
Greeting(text) => { |
|
141 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13494 | 142 |
if c.is_admin() || c.is_master() && !r.is_fixed() { |
13447 | 143 |
r.greeting = text |
144 |
} |
|
145 |
} |
|
146 |
} |
|
13416 | 147 |
RoomName(new_name) => { |
148 |
let actions = |
|
149 |
if is_name_illegal(&new_name) { |
|
150 |
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 | 151 |
} else if server.rooms[room_id].is_fixed() { |
13447 | 152 |
vec![Warn("Access denied.".to_string())] |
13416 | 153 |
} else if server.has_room(&new_name) { |
154 |
vec![Warn("A room with the same name already exists.".to_string())] |
|
155 |
} else { |
|
156 |
let mut old_name = new_name.clone(); |
|
13520 | 157 |
swap(&mut server.rooms[room_id].name, &mut old_name); |
158 |
vec![SendRoomUpdate(Some(old_name))] |
|
13416 | 159 |
}; |
13419 | 160 |
server.react(client_id, actions); |
161 |
}, |
|
162 |
ToggleReady => { |
|
13666 | 163 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
13486 | 164 |
let flags = if c.is_ready() { |
13419 | 165 |
r.ready_players_number -= 1; |
166 |
"-r" |
|
167 |
} else { |
|
168 |
r.ready_players_number += 1; |
|
169 |
"+r" |
|
170 |
}; |
|
13666 | 171 |
c.set_is_ready(!c.is_ready()); |
13447 | 172 |
let mut v = |
173 |
vec![ClientFlags(flags.to_string(), vec![c.nick.clone()]) |
|
174 |
.send_all().in_room(r.id).action()]; |
|
13494 | 175 |
if r.is_fixed() && r.ready_players_number == r.players_number { |
13447 | 176 |
v.push(StartRoomGame(r.id)) |
177 |
} |
|
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 { |
13500 | 195 |
let team = r.add_team(c.id, *info); |
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 { |
|
13439 | 281 |
let v = vec![cfg.to_server_msg() |
282 |
.send_all().in_room(r.id).but_self().action()]; |
|
283 |
r.set_config(cfg); |
|
284 |
v |
|
13666 | 285 |
}; |
286 |
server.react(client_id, actions); |
|
287 |
} |
|
13419 | 288 |
} |
13528 | 289 |
Save(name, location) => { |
290 |
let actions = vec![server_chat(format!("Room config saved as {}", name)) |
|
291 |
.send_all().in_room(room_id).action()]; |
|
292 |
server.rooms[room_id].save_config(name, location); |
|
293 |
server.react(client_id, actions); |
|
294 |
} |
|
13529 | 295 |
SaveRoom(filename) => { |
13666 | 296 |
if server.clients[client_id].is_admin() { |
297 |
let actions = match server.rooms[room_id].get_saves() { |
|
13529 | 298 |
Ok(text) => match write_file(&filename, &text) { |
299 |
Ok(_) => vec![server_chat("Room configs saved successfully.".to_string()) |
|
300 |
.send_self().action()], |
|
301 |
Err(e) => { |
|
302 |
warn!("Error while writing the config file \"{}\": {}", filename, e); |
|
303 |
vec![Warn("Unable to save the room configs.".to_string())] |
|
304 |
} |
|
305 |
} |
|
306 |
Err(e) => { |
|
307 |
warn!("Error while serializing the room configs: {}", e); |
|
308 |
vec![Warn("Unable to serialize the room configs.".to_string())] |
|
309 |
} |
|
13666 | 310 |
}; |
311 |
server.react(client_id, actions); |
|
312 |
} |
|
13529 | 313 |
} |
314 |
LoadRoom(filename) => { |
|
13666 | 315 |
if server.clients[client_id].is_admin() { |
316 |
let actions = match read_file(&filename) { |
|
13529 | 317 |
Ok(text) => match server.rooms[room_id].set_saves(&text) { |
318 |
Ok(_) => vec![server_chat("Room configs loaded successfully.".to_string()) |
|
319 |
.send_self().action()], |
|
320 |
Err(e) => { |
|
321 |
warn!("Error while deserializing the room configs: {}", e); |
|
322 |
vec![Warn("Unable to deserialize the room configs.".to_string())] |
|
323 |
} |
|
324 |
} |
|
325 |
Err(e) => { |
|
326 |
warn!("Error while reading the config file \"{}\": {}", filename, e); |
|
327 |
vec![Warn("Unable to load the room configs.".to_string())] |
|
328 |
} |
|
13666 | 329 |
}; |
330 |
server.react(client_id, actions); |
|
331 |
} |
|
13529 | 332 |
} |
13528 | 333 |
Delete(name) => { |
334 |
let actions = if !server.rooms[room_id].delete_config(&name) { |
|
335 |
vec![Warn(format!("Save doesn't exist: {}", name))] |
|
336 |
} else { |
|
337 |
vec![server_chat(format!("Room config {} has been deleted", name)) |
|
338 |
.send_all().in_room(room_id).action()] |
|
339 |
}; |
|
340 |
server.react(client_id, actions); |
|
341 |
} |
|
13450 | 342 |
CallVote(None) => { |
343 |
server.react(client_id, vec![ |
|
13521 | 344 |
server_chat("Available callvote commands: kick <nickname>, map <name>, pause, newseed, hedgehogs <number>".to_string()) |
13450 | 345 |
.send_self().action()]) |
346 |
} |
|
347 |
CallVote(Some(kind)) => { |
|
13492 | 348 |
let is_in_game = server.rooms[room_id].game_info.is_some(); |
13450 | 349 |
let error = match &kind { |
350 |
VoteType::Kick(nick) => { |
|
351 |
if server.find_client(&nick).filter(|c| c.room_id == Some(room_id)).is_some() { |
|
352 |
None |
|
353 |
} else { |
|
13521 | 354 |
Some("/callvote kick: No such user!".to_string()) |
13450 | 355 |
} |
356 |
}, |
|
357 |
VoteType::Map(None) => { |
|
13521 | 358 |
let names: Vec<_> = server.rooms[room_id].saves.keys().cloned().collect(); |
359 |
if names.is_empty() { |
|
360 |
Some("/callvote map: No maps saved in this room!".to_string()) |
|
361 |
} else { |
|
362 |
Some(format!("Available maps: {}", names.join(", "))) |
|
363 |
} |
|
13450 | 364 |
}, |
365 |
VoteType::Map(Some(name)) => { |
|
13521 | 366 |
if server.rooms[room_id].saves.get(&name[..]).is_some() { |
13530 | 367 |
None |
13521 | 368 |
} else { |
13530 | 369 |
Some("/callvote map: No such map!".to_string()) |
13521 | 370 |
} |
13450 | 371 |
}, |
372 |
VoteType::Pause => { |
|
373 |
if is_in_game { |
|
374 |
None |
|
375 |
} else { |
|
13521 | 376 |
Some("/callvote pause: No game in progress!".to_string()) |
13450 | 377 |
} |
378 |
}, |
|
379 |
VoteType::NewSeed => { |
|
380 |
None |
|
381 |
}, |
|
382 |
VoteType::HedgehogsPerTeam(number) => { |
|
383 |
match number { |
|
13709
e335daaa77a9
Add hogs per team named constant that absolutely no one asked for
alfadur
parents:
13666
diff
changeset
|
384 |
1...MAX_HEDGEHOGS_PER_TEAM => None, |
13521 | 385 |
_ => Some("/callvote hedgehogs: Specify number from 1 to 8.".to_string()) |
13450 | 386 |
} |
387 |
}, |
|
388 |
}; |
|
389 |
match error { |
|
390 |
None => { |
|
13460 | 391 |
let msg = voting_description(&kind); |
13450 | 392 |
let voting = Voting::new(kind, server.room_clients(client_id)); |
13520 | 393 |
server.rooms[room_id].voting = Some(voting); |
13450 | 394 |
server.react(client_id, vec![ |
13521 | 395 |
server_chat(msg).send_all().in_room(room_id).action(), |
13450 | 396 |
AddVote{ vote: true, is_forced: false}]); |
397 |
} |
|
398 |
Some(msg) => { |
|
399 |
server.react(client_id, vec![ |
|
400 |
server_chat(msg).send_self().action()]) |
|
401 |
} |
|
402 |
} |
|
403 |
} |
|
404 |
Vote(vote) => { |
|
13520 | 405 |
server.react(client_id, vec![AddVote{ vote, is_forced: false }]); |
13450 | 406 |
} |
407 |
ForceVote(vote) => { |
|
13520 | 408 |
let is_forced = server.clients[client_id].is_admin(); |
409 |
server.react(client_id, vec![AddVote{ vote, is_forced }]); |
|
13450 | 410 |
} |
13494 | 411 |
ToggleRestrictJoin | ToggleRestrictTeams | ToggleRegisteredOnly => { |
412 |
if server.clients[client_id].is_master() { |
|
413 |
server.rooms[room_id].flags.toggle(room_message_flag(&message)); |
|
414 |
} |
|
415 |
server.react(client_id, vec![SendRoomUpdate(None)]); |
|
416 |
} |
|
13423 | 417 |
StartGame => { |
13520 | 418 |
server.react(client_id, vec![StartRoomGame(room_id)]); |
13423 | 419 |
} |
420 |
EngineMessage(em) => { |
|
421 |
let mut actions = Vec::new(); |
|
422 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
423 |
if c.teams_in_game > 0 { |
|
424 |
let decoding = decode(&em[..]).unwrap(); |
|
425 |
let messages = by_msg(&decoding); |
|
13443 | 426 |
let valid = messages.filter(|m| is_msg_valid(m, &c.team_indices)); |
427 |
let non_empty = valid.clone().filter(|m| !is_msg_empty(m)); |
|
428 |
let sync_msg = valid.clone().filter(|m| is_msg_timed(m)) |
|
429 |
.last().map(|m| if is_msg_empty(m) {Some(encode(m))} else {None}); |
|
13423 | 430 |
|
431 |
let em_response = encode(&valid.flat_map(|msg| msg).cloned().collect::<Vec<_>>()); |
|
432 |
if !em_response.is_empty() { |
|
13428 | 433 |
actions.push(ForwardEngineMessage(vec![em_response]) |
13423 | 434 |
.send_all().in_room(r.id).but_self().action()); |
435 |
} |
|
13427 | 436 |
let em_log = encode(&non_empty.flat_map(|msg| msg).cloned().collect::<Vec<_>>()); |
437 |
if let Some(ref mut info) = r.game_info { |
|
13429 | 438 |
if !em_log.is_empty() { |
13428 | 439 |
info.msg_log.push(em_log); |
440 |
} |
|
13443 | 441 |
if let Some(msg) = sync_msg { |
442 |
info.sync_msg = msg; |
|
13427 | 443 |
} |
444 |
} |
|
13423 | 445 |
} |
446 |
} |
|
447 |
server.react(client_id, actions) |
|
448 |
} |
|
449 |
RoundFinished => { |
|
450 |
let mut actions = Vec::new(); |
|
451 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13486 | 452 |
if c.is_in_game() { |
453 |
c.set_is_in_game(false); |
|
13423 | 454 |
actions.push(ClientFlags("-g".to_string(), vec![c.nick.clone()]). |
455 |
send_all().in_room(r.id).action()); |
|
13426 | 456 |
if r.game_info.is_some() { |
457 |
for team in r.client_teams(c.id) { |
|
458 |
actions.push(SendTeamRemovalMessage(team.name.clone())); |
|
459 |
} |
|
13423 | 460 |
} |
461 |
} |
|
462 |
} |
|
463 |
server.react(client_id, actions) |
|
13444
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13443
diff
changeset
|
464 |
}, |
13445
d3c86ade3d4d
Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13444
diff
changeset
|
465 |
Rnd(v) => { |
13492 | 466 |
let result = rnd_reply(&v); |
467 |
let mut echo = vec!["/rnd".to_string()]; |
|
468 |
echo.extend(v.into_iter()); |
|
469 |
let chat_msg = ChatMsg { |
|
470 |
nick: server.clients[client_id].nick.clone(), |
|
471 |
msg: echo.join(" ") |
|
472 |
}; |
|
473 |
server.react(client_id, vec![ |
|
474 |
chat_msg.send_all().in_room(room_id).action(), |
|
475 |
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
|
476 |
}, |
13419 | 477 |
_ => warn!("Unimplemented!") |
12147 | 478 |
} |
479 |
} |