author | alfadur |
Thu, 16 Aug 2018 19:33:03 +0300 | |
changeset 13666 | 09f4a30e50cc |
parent 13530 | 80db7232b4b5 |
child 13709 | e335daaa77a9 |
permissions | -rw-r--r-- |
12147 | 1 |
use mio; |
2 |
||
13666 | 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 |
|
13416 | 16 |
}; |
13529 | 17 |
use std::{ |
18 |
mem::swap, fs::{File, OpenOptions}, |
|
19 |
io::{Read, Write, Result, Error, ErrorKind} |
|
20 |
}; |
|
13423 | 21 |
use base64::{encode, decode}; |
13492 | 22 |
use super::common::rnd_reply; |
13423 | 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 |
||
13500 | 43 |
fn by_msg(source: &[u8]) -> ByMsg { |
44 |
ByMsg {messages: source} |
|
13423 | 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 |
||
13429 | 51 |
#[cfg(canhazslicepatterns)] |
13423 | 52 |
fn is_msg_valid(msg: &[u8], team_indices: &[u8]) -> bool { |
13424 | 53 |
match msg { |
54 |
[size, typ, body..] => VALID_MESSAGES.contains(typ) |
|
55 |
&& match body { |
|
13423 | 56 |
[1...8, team, ..] if *typ == b'h' => team_indices.contains(team), |
57 |
_ => *typ != b'h' |
|
13424 | 58 |
}, |
59 |
_ => false |
|
13423 | 60 |
} |
61 |
} |
|
62 |
||
13666 | 63 |
fn is_msg_valid(msg: &[u8], _team_indices: &[u8]) -> bool { |
13429 | 64 |
if let Some(typ) = msg.get(1) { |
65 |
VALID_MESSAGES.contains(typ) |
|
66 |
} else { |
|
67 |
false |
|
68 |
} |
|
69 |
} |
|
70 |
||
13423 | 71 |
fn is_msg_empty(msg: &[u8]) -> bool { |
13429 | 72 |
msg.get(1).filter(|t| **t == b'+').is_some() |
13423 | 73 |
} |
12147 | 74 |
|
13443 | 75 |
fn is_msg_timed(msg: &[u8]) -> bool { |
76 |
msg.get(1).filter(|t| !NON_TIMED_MESSAGES.contains(t)).is_some() |
|
77 |
} |
|
78 |
||
13460 | 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 |
||
13494 | 89 |
fn room_message_flag(msg: &HWProtocolMessage) -> RoomFlags { |
13666 | 90 |
use crate::protocol::messages::HWProtocolMessage::*; |
13494 | 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 |
||
13529 | 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 |
||
13492 | 111 |
pub fn handle(server: &mut HWServer, client_id: ClientId, room_id: RoomId, message: HWProtocolMessage) { |
13666 | 112 |
use crate::protocol::messages::HWProtocolMessage::*; |
12147 | 113 |
match message { |
13419 | 114 |
Part(None) => server.react(client_id, vec![ |
13416 | 115 |
MoveToLobby("part".to_string())]), |
13419 | 116 |
Part(Some(msg)) => server.react(client_id, vec![ |
13416 | 117 |
MoveToLobby(format!("part: {}", msg))]), |
118 |
Chat(msg) => { |
|
13419 | 119 |
let actions = { |
120 |
let c = &mut server.clients[client_id]; |
|
13500 | 121 |
let chat_msg = ChatMsg {nick: c.nick.clone(), msg}; |
13492 | 122 |
vec![chat_msg.send_all().in_room(room_id).but_self().action()] |
13419 | 123 |
}; |
124 |
server.react(client_id, actions); |
|
13416 | 125 |
}, |
13447 | 126 |
Fix => { |
127 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13494 | 128 |
if c.is_admin() { r.set_is_fixed(true) } |
13447 | 129 |
} |
130 |
} |
|
131 |
Unfix => { |
|
132 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13494 | 133 |
if c.is_admin() { r.set_is_fixed(false) } |
13447 | 134 |
} |
135 |
} |
|
136 |
Greeting(text) => { |
|
137 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13494 | 138 |
if c.is_admin() || c.is_master() && !r.is_fixed() { |
13447 | 139 |
r.greeting = text |
140 |
} |
|
141 |
} |
|
142 |
} |
|
13416 | 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())] |
|
13520 | 147 |
} else if server.rooms[room_id].is_fixed() { |
13447 | 148 |
vec![Warn("Access denied.".to_string())] |
13416 | 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(); |
|
13520 | 153 |
swap(&mut server.rooms[room_id].name, &mut old_name); |
154 |
vec![SendRoomUpdate(Some(old_name))] |
|
13416 | 155 |
}; |
13419 | 156 |
server.react(client_id, actions); |
157 |
}, |
|
158 |
ToggleReady => { |
|
13666 | 159 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
13486 | 160 |
let flags = if c.is_ready() { |
13419 | 161 |
r.ready_players_number -= 1; |
162 |
"-r" |
|
163 |
} else { |
|
164 |
r.ready_players_number += 1; |
|
165 |
"+r" |
|
166 |
}; |
|
13666 | 167 |
c.set_is_ready(!c.is_ready()); |
13447 | 168 |
let mut v = |
169 |
vec![ClientFlags(flags.to_string(), vec![c.nick.clone()]) |
|
170 |
.send_all().in_room(r.id).action()]; |
|
13494 | 171 |
if r.is_fixed() && r.ready_players_number == r.players_number { |
13447 | 172 |
v.push(StartRoomGame(r.id)) |
173 |
} |
|
13666 | 174 |
server.react(client_id, v); |
175 |
} |
|
13416 | 176 |
} |
13422 | 177 |
AddTeam(info) => { |
13419 | 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())) |
|
13423 | 186 |
} else if r.game_info.is_some() { |
13419 | 187 |
actions.push(Warn("Joining not possible: Round is in progress.".to_string())) |
13494 | 188 |
} else if r.is_team_add_restricted() { |
189 |
actions.push(Warn("This room currently does not allow adding new teams.".to_string())); |
|
13419 | 190 |
} else { |
13500 | 191 |
let team = r.add_team(c.id, *info); |
13419 | 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) => { |
|
13666 | 225 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
13419 | 226 |
let addable_hedgehogs = r.addable_hedgehogs(); |
13666 | 227 |
let actions = if let Some((_, team)) = r.find_team_and_owner_mut(|t| t.name == team_name) { |
13486 | 228 |
if !c.is_master() { |
13419 | 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()))] |
|
13666 | 241 |
}; |
242 |
server.react(client_id, actions); |
|
243 |
} |
|
13419 | 244 |
}, |
245 |
SetTeamColor(team_name, color) => { |
|
13666 | 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) { |
|
13486 | 249 |
if !c.is_master() { |
13419 | 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()))] |
|
13666 | 261 |
}; |
13419 | 262 |
|
13666 | 263 |
if let Some(id) = owner_id { |
264 |
server.clients[id].clan = Some(color); |
|
265 |
} |
|
13419 | 266 |
|
13666 | 267 |
server.react(client_id, actions); |
268 |
}; |
|
13422 | 269 |
}, |
270 |
Cfg(cfg) => { |
|
13666 | 271 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
272 |
let actions = if r.is_fixed() { |
|
13447 | 273 |
vec![Warn("Access denied.".to_string())] |
13486 | 274 |
} else if !c.is_master() { |
13422 | 275 |
vec![ProtocolError("You're not the room master!".to_string())] |
276 |
} else { |
|
13439 | 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 |
|
13666 | 281 |
}; |
282 |
server.react(client_id, actions); |
|
283 |
} |
|
13419 | 284 |
} |
13528 | 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 |
} |
|
13529 | 291 |
SaveRoom(filename) => { |
13666 | 292 |
if server.clients[client_id].is_admin() { |
293 |
let actions = match server.rooms[room_id].get_saves() { |
|
13529 | 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 |
} |
|
13666 | 306 |
}; |
307 |
server.react(client_id, actions); |
|
308 |
} |
|
13529 | 309 |
} |
310 |
LoadRoom(filename) => { |
|
13666 | 311 |
if server.clients[client_id].is_admin() { |
312 |
let actions = match read_file(&filename) { |
|
13529 | 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 |
} |
|
13666 | 325 |
}; |
326 |
server.react(client_id, actions); |
|
327 |
} |
|
13529 | 328 |
} |
13528 | 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 |
} |
|
13450 | 338 |
CallVote(None) => { |
339 |
server.react(client_id, vec![ |
|
13521 | 340 |
server_chat("Available callvote commands: kick <nickname>, map <name>, pause, newseed, hedgehogs <number>".to_string()) |
13450 | 341 |
.send_self().action()]) |
342 |
} |
|
343 |
CallVote(Some(kind)) => { |
|
13492 | 344 |
let is_in_game = server.rooms[room_id].game_info.is_some(); |
13450 | 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 { |
|
13521 | 350 |
Some("/callvote kick: No such user!".to_string()) |
13450 | 351 |
} |
352 |
}, |
|
353 |
VoteType::Map(None) => { |
|
13521 | 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 |
} |
|
13450 | 360 |
}, |
361 |
VoteType::Map(Some(name)) => { |
|
13521 | 362 |
if server.rooms[room_id].saves.get(&name[..]).is_some() { |
13530 | 363 |
None |
13521 | 364 |
} else { |
13530 | 365 |
Some("/callvote map: No such map!".to_string()) |
13521 | 366 |
} |
13450 | 367 |
}, |
368 |
VoteType::Pause => { |
|
369 |
if is_in_game { |
|
370 |
None |
|
371 |
} else { |
|
13521 | 372 |
Some("/callvote pause: No game in progress!".to_string()) |
13450 | 373 |
} |
374 |
}, |
|
375 |
VoteType::NewSeed => { |
|
376 |
None |
|
377 |
}, |
|
378 |
VoteType::HedgehogsPerTeam(number) => { |
|
379 |
match number { |
|
380 |
1...8 => None, |
|
13521 | 381 |
_ => Some("/callvote hedgehogs: Specify number from 1 to 8.".to_string()) |
13450 | 382 |
} |
383 |
}, |
|
384 |
}; |
|
385 |
match error { |
|
386 |
None => { |
|
13460 | 387 |
let msg = voting_description(&kind); |
13450 | 388 |
let voting = Voting::new(kind, server.room_clients(client_id)); |
13520 | 389 |
server.rooms[room_id].voting = Some(voting); |
13450 | 390 |
server.react(client_id, vec![ |
13521 | 391 |
server_chat(msg).send_all().in_room(room_id).action(), |
13450 | 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) => { |
|
13520 | 401 |
server.react(client_id, vec![AddVote{ vote, is_forced: false }]); |
13450 | 402 |
} |
403 |
ForceVote(vote) => { |
|
13520 | 404 |
let is_forced = server.clients[client_id].is_admin(); |
405 |
server.react(client_id, vec![AddVote{ vote, is_forced }]); |
|
13450 | 406 |
} |
13494 | 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 |
} |
|
13423 | 413 |
StartGame => { |
13520 | 414 |
server.react(client_id, vec![StartRoomGame(room_id)]); |
13423 | 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); |
|
13443 | 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}); |
|
13423 | 426 |
|
427 |
let em_response = encode(&valid.flat_map(|msg| msg).cloned().collect::<Vec<_>>()); |
|
428 |
if !em_response.is_empty() { |
|
13428 | 429 |
actions.push(ForwardEngineMessage(vec![em_response]) |
13423 | 430 |
.send_all().in_room(r.id).but_self().action()); |
431 |
} |
|
13427 | 432 |
let em_log = encode(&non_empty.flat_map(|msg| msg).cloned().collect::<Vec<_>>()); |
433 |
if let Some(ref mut info) = r.game_info { |
|
13429 | 434 |
if !em_log.is_empty() { |
13428 | 435 |
info.msg_log.push(em_log); |
436 |
} |
|
13443 | 437 |
if let Some(msg) = sync_msg { |
438 |
info.sync_msg = msg; |
|
13427 | 439 |
} |
440 |
} |
|
13423 | 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) { |
|
13486 | 448 |
if c.is_in_game() { |
449 |
c.set_is_in_game(false); |
|
13423 | 450 |
actions.push(ClientFlags("-g".to_string(), vec![c.nick.clone()]). |
451 |
send_all().in_room(r.id).action()); |
|
13426 | 452 |
if r.game_info.is_some() { |
453 |
for team in r.client_teams(c.id) { |
|
454 |
actions.push(SendTeamRemovalMessage(team.name.clone())); |
|
455 |
} |
|
13423 | 456 |
} |
457 |
} |
|
458 |
} |
|
459 |
server.react(client_id, actions) |
|
13444
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13443
diff
changeset
|
460 |
}, |
13445
d3c86ade3d4d
Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13444
diff
changeset
|
461 |
Rnd(v) => { |
13492 | 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()]) |
|
13445
d3c86ade3d4d
Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13444
diff
changeset
|
472 |
}, |
13419 | 473 |
_ => warn!("Unimplemented!") |
12147 | 474 |
} |
475 |
} |