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