author | alfadur |
Sat, 21 Jul 2018 02:13:55 +0300 | |
changeset 13529 | 662f7df89d06 |
parent 13528 | c8b626b0a3ad |
child 13530 | 80db7232b4b5 |
permissions | -rw-r--r-- |
12147 | 1 |
use mio; |
2 |
||
13416 | 3 |
use protocol::messages::{ |
4 |
HWProtocolMessage, |
|
13450 | 5 |
HWServerMessage::*, |
6 |
server_chat |
|
13416 | 7 |
}; |
13419 | 8 |
use server::{ |
13492 | 9 |
coretypes::{ClientId, RoomId, Voting, VoteType}, |
13419 | 10 |
server::HWServer, |
13494 | 11 |
room::{HWRoom, RoomFlags}, |
13419 | 12 |
actions::{Action, Action::*} |
13 |
}; |
|
13416 | 14 |
use utils::is_name_illegal; |
13529 | 15 |
use std::{ |
16 |
mem::swap, fs::{File, OpenOptions}, |
|
17 |
io::{Read, Write, Result, Error, ErrorKind} |
|
18 |
}; |
|
13423 | 19 |
use base64::{encode, decode}; |
13492 | 20 |
use super::common::rnd_reply; |
13423 | 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 |
||
13500 | 41 |
fn by_msg(source: &[u8]) -> ByMsg { |
42 |
ByMsg {messages: source} |
|
13423 | 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 |
||
13429 | 49 |
#[cfg(canhazslicepatterns)] |
13423 | 50 |
fn is_msg_valid(msg: &[u8], team_indices: &[u8]) -> bool { |
13424 | 51 |
match msg { |
52 |
[size, typ, body..] => VALID_MESSAGES.contains(typ) |
|
53 |
&& match body { |
|
13423 | 54 |
[1...8, team, ..] if *typ == b'h' => team_indices.contains(team), |
55 |
_ => *typ != b'h' |
|
13424 | 56 |
}, |
57 |
_ => false |
|
13423 | 58 |
} |
59 |
} |
|
60 |
||
13429 | 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 |
||
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 { |
74 |
msg.get(1).filter(|t| !NON_TIMED_MESSAGES.contains(t)).is_some() |
|
75 |
} |
|
76 |
||
13460 | 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 |
||
13494 | 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 |
||
13529 | 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 |
||
13492 | 109 |
pub fn handle(server: &mut HWServer, client_id: ClientId, room_id: RoomId, message: HWProtocolMessage) { |
13416 | 110 |
use protocol::messages::HWProtocolMessage::*; |
12147 | 111 |
match message { |
13419 | 112 |
Part(None) => server.react(client_id, vec![ |
13416 | 113 |
MoveToLobby("part".to_string())]), |
13419 | 114 |
Part(Some(msg)) => server.react(client_id, vec![ |
13416 | 115 |
MoveToLobby(format!("part: {}", msg))]), |
116 |
Chat(msg) => { |
|
13419 | 117 |
let actions = { |
118 |
let c = &mut server.clients[client_id]; |
|
13500 | 119 |
let chat_msg = ChatMsg {nick: c.nick.clone(), msg}; |
13492 | 120 |
vec![chat_msg.send_all().in_room(room_id).but_self().action()] |
13419 | 121 |
}; |
122 |
server.react(client_id, actions); |
|
13416 | 123 |
}, |
13447 | 124 |
Fix => { |
125 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13494 | 126 |
if c.is_admin() { r.set_is_fixed(true) } |
13447 | 127 |
} |
128 |
} |
|
129 |
Unfix => { |
|
130 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13494 | 131 |
if c.is_admin() { r.set_is_fixed(false) } |
13447 | 132 |
} |
133 |
} |
|
134 |
Greeting(text) => { |
|
135 |
if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13494 | 136 |
if c.is_admin() || c.is_master() && !r.is_fixed() { |
13447 | 137 |
r.greeting = text |
138 |
} |
|
139 |
} |
|
140 |
} |
|
13416 | 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())] |
|
13520 | 145 |
} else if server.rooms[room_id].is_fixed() { |
13447 | 146 |
vec![Warn("Access denied.".to_string())] |
13416 | 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(); |
|
13520 | 151 |
swap(&mut server.rooms[room_id].name, &mut old_name); |
152 |
vec![SendRoomUpdate(Some(old_name))] |
|
13416 | 153 |
}; |
13419 | 154 |
server.react(client_id, actions); |
155 |
}, |
|
156 |
ToggleReady => { |
|
157 |
let actions = if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13486 | 158 |
let flags = if c.is_ready() { |
13419 | 159 |
r.ready_players_number -= 1; |
160 |
"-r" |
|
161 |
} else { |
|
162 |
r.ready_players_number += 1; |
|
163 |
"+r" |
|
164 |
}; |
|
13486 | 165 |
let is_ready = !c.is_ready(); |
166 |
c.set_is_ready(is_ready); |
|
13447 | 167 |
let mut v = |
168 |
vec![ClientFlags(flags.to_string(), vec![c.nick.clone()]) |
|
169 |
.send_all().in_room(r.id).action()]; |
|
13494 | 170 |
if r.is_fixed() && r.ready_players_number == r.players_number { |
13447 | 171 |
v.push(StartRoomGame(r.id)) |
172 |
} |
|
173 |
v |
|
13419 | 174 |
} else { |
175 |
Vec::new() |
|
176 |
}; |
|
177 |
server.react(client_id, actions); |
|
13416 | 178 |
} |
13422 | 179 |
AddTeam(info) => { |
13419 | 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())) |
|
13423 | 188 |
} else if r.game_info.is_some() { |
13419 | 189 |
actions.push(Warn("Joining not possible: Round is in progress.".to_string())) |
13494 | 190 |
} else if r.is_team_add_restricted() { |
191 |
actions.push(Warn("This room currently does not allow adding new teams.".to_string())); |
|
13419 | 192 |
} else { |
13500 | 193 |
let team = r.add_team(c.id, *info); |
13419 | 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) { |
|
13486 | 230 |
if !c.is_master() { |
13419 | 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) { |
|
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()))] |
|
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); |
|
13422 | 275 |
}, |
276 |
Cfg(cfg) => { |
|
277 |
let actions = if let (c, Some(r)) = server.client_and_room(client_id) { |
|
13494 | 278 |
if r.is_fixed() { |
13447 | 279 |
vec![Warn("Access denied.".to_string())] |
13486 | 280 |
} else if !c.is_master() { |
13422 | 281 |
vec![ProtocolError("You're not the room master!".to_string())] |
282 |
} else { |
|
13439 | 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 |
|
13422 | 287 |
} |
288 |
} else { |
|
289 |
Vec::new() |
|
290 |
}; |
|
291 |
server.react(client_id, actions); |
|
13419 | 292 |
} |
13528 | 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 |
} |
|
13529 | 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 |
} |
|
13528 | 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 |
} |
|
13450 | 350 |
CallVote(None) => { |
351 |
server.react(client_id, vec![ |
|
13521 | 352 |
server_chat("Available callvote commands: kick <nickname>, map <name>, pause, newseed, hedgehogs <number>".to_string()) |
13450 | 353 |
.send_self().action()]) |
354 |
} |
|
355 |
CallVote(Some(kind)) => { |
|
13492 | 356 |
let is_in_game = server.rooms[room_id].game_info.is_some(); |
13450 | 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 { |
|
13521 | 362 |
Some("/callvote kick: No such user!".to_string()) |
13450 | 363 |
} |
364 |
}, |
|
365 |
VoteType::Map(None) => { |
|
13521 | 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 |
} |
|
13450 | 372 |
}, |
373 |
VoteType::Map(Some(name)) => { |
|
13521 | 374 |
if server.rooms[room_id].saves.get(&name[..]).is_some() { |
375 |
Some("/callvote map: No such map!".to_string()) |
|
376 |
} else { |
|
377 |
None |
|
378 |
} |
|
13450 | 379 |
}, |
380 |
VoteType::Pause => { |
|
381 |
if is_in_game { |
|
382 |
None |
|
383 |
} else { |
|
13521 | 384 |
Some("/callvote pause: No game in progress!".to_string()) |
13450 | 385 |
} |
386 |
}, |
|
387 |
VoteType::NewSeed => { |
|
388 |
None |
|
389 |
}, |
|
390 |
VoteType::HedgehogsPerTeam(number) => { |
|
391 |
match number { |
|
392 |
1...8 => None, |
|
13521 | 393 |
_ => Some("/callvote hedgehogs: Specify number from 1 to 8.".to_string()) |
13450 | 394 |
} |
395 |
}, |
|
396 |
}; |
|
397 |
match error { |
|
398 |
None => { |
|
13460 | 399 |
let msg = voting_description(&kind); |
13450 | 400 |
let voting = Voting::new(kind, server.room_clients(client_id)); |
13520 | 401 |
server.rooms[room_id].voting = Some(voting); |
13450 | 402 |
server.react(client_id, vec![ |
13521 | 403 |
server_chat(msg).send_all().in_room(room_id).action(), |
13450 | 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) => { |
|
13520 | 413 |
server.react(client_id, vec![AddVote{ vote, is_forced: false }]); |
13450 | 414 |
} |
415 |
ForceVote(vote) => { |
|
13520 | 416 |
let is_forced = server.clients[client_id].is_admin(); |
417 |
server.react(client_id, vec![AddVote{ vote, is_forced }]); |
|
13450 | 418 |
} |
13494 | 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 |
} |
|
13423 | 425 |
StartGame => { |
13520 | 426 |
server.react(client_id, vec![StartRoomGame(room_id)]); |
13423 | 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); |
|
13443 | 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}); |
|
13423 | 438 |
|
439 |
let em_response = encode(&valid.flat_map(|msg| msg).cloned().collect::<Vec<_>>()); |
|
440 |
if !em_response.is_empty() { |
|
13428 | 441 |
actions.push(ForwardEngineMessage(vec![em_response]) |
13423 | 442 |
.send_all().in_room(r.id).but_self().action()); |
443 |
} |
|
13427 | 444 |
let em_log = encode(&non_empty.flat_map(|msg| msg).cloned().collect::<Vec<_>>()); |
445 |
if let Some(ref mut info) = r.game_info { |
|
13429 | 446 |
if !em_log.is_empty() { |
13428 | 447 |
info.msg_log.push(em_log); |
448 |
} |
|
13443 | 449 |
if let Some(msg) = sync_msg { |
450 |
info.sync_msg = msg; |
|
13427 | 451 |
} |
452 |
} |
|
13423 | 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) { |
|
13486 | 460 |
if c.is_in_game() { |
461 |
c.set_is_in_game(false); |
|
13423 | 462 |
actions.push(ClientFlags("-g".to_string(), vec![c.nick.clone()]). |
463 |
send_all().in_room(r.id).action()); |
|
13426 | 464 |
if r.game_info.is_some() { |
465 |
for team in r.client_teams(c.id) { |
|
466 |
actions.push(SendTeamRemovalMessage(team.name.clone())); |
|
467 |
} |
|
13423 | 468 |
} |
469 |
} |
|
470 |
} |
|
471 |
server.react(client_id, actions) |
|
13444
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13443
diff
changeset
|
472 |
}, |
13445
d3c86ade3d4d
Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13444
diff
changeset
|
473 |
Rnd(v) => { |
13492 | 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()]) |
|
13445
d3c86ade3d4d
Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13444
diff
changeset
|
484 |
}, |
13419 | 485 |
_ => warn!("Unimplemented!") |
12147 | 486 |
} |
487 |
} |