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