author | alfadur |
Thu, 07 Feb 2019 23:34:24 +0300 | |
changeset 14702 | f64e21f164a5 |
parent 14699 | 25c564f77b7d |
child 14785 | 65861ba8b4e8 |
permissions | -rw-r--r-- |
12152 | 1 |
use mio; |
2 |
||
14462 | 3 |
use super::common::rnd_reply; |
14694
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
4 |
use crate::utils::to_engine_msg; |
13671 | 5 |
use crate::{ |
14462 | 6 |
protocol::messages::{server_chat, HWProtocolMessage, HWServerMessage::*}, |
13671 | 7 |
server::{ |
14379 | 8 |
core::HWServer, |
14692
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
9 |
coretypes, |
14462 | 10 |
coretypes::{ClientId, GameCfg, RoomId, VoteType, Voting, MAX_HEDGEHOGS_PER_TEAM}, |
13671 | 11 |
room::{HWRoom, RoomFlags}, |
12 |
}, |
|
14462 | 13 |
utils::is_name_illegal, |
13421 | 14 |
}; |
14462 | 15 |
use base64::{decode, encode}; |
13810 | 16 |
use log::*; |
14694
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
17 |
use std::iter::once; |
14462 | 18 |
use std::mem::swap; |
13428 | 19 |
|
20 |
#[derive(Clone)] |
|
21 |
struct ByMsg<'a> { |
|
14462 | 22 |
messages: &'a [u8], |
13428 | 23 |
} |
24 |
||
14462 | 25 |
impl<'a> Iterator for ByMsg<'a> { |
26 |
type Item = &'a [u8]; |
|
13428 | 27 |
|
28 |
fn next(&mut self) -> Option<<Self as Iterator>::Item> { |
|
29 |
if let Some(size) = self.messages.get(0) { |
|
30 |
let (msg, next) = self.messages.split_at(*size as usize + 1); |
|
31 |
self.messages = next; |
|
32 |
Some(msg) |
|
33 |
} else { |
|
34 |
None |
|
35 |
} |
|
36 |
} |
|
37 |
} |
|
38 |
||
13529 | 39 |
fn by_msg(source: &[u8]) -> ByMsg { |
14462 | 40 |
ByMsg { messages: source } |
13428 | 41 |
} |
42 |
||
43 |
const VALID_MESSAGES: &[u8] = |
|
44 |
b"M#+LlRrUuDdZzAaSjJ,NpPwtgfhbc12345\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A"; |
|
45 |
const NON_TIMED_MESSAGES: &[u8] = b"M#hb"; |
|
46 |
||
13434 | 47 |
#[cfg(canhazslicepatterns)] |
13428 | 48 |
fn is_msg_valid(msg: &[u8], team_indices: &[u8]) -> bool { |
13429 | 49 |
match msg { |
14462 | 50 |
[size, typ, body..] => { |
51 |
VALID_MESSAGES.contains(typ) |
|
52 |
&& match body { |
|
53 |
[1...MAX_HEDGEHOGS_PER_TEAM, team, ..] if *typ == b'h' => { |
|
54 |
team_indices.contains(team) |
|
55 |
} |
|
56 |
_ => *typ != b'h', |
|
57 |
} |
|
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 { |
14462 | 76 |
msg.get(1) |
77 |
.filter(|t| !NON_TIMED_MESSAGES.contains(t)) |
|
78 |
.is_some() |
|
13448 | 79 |
} |
80 |
||
13485 | 81 |
fn voting_description(kind: &VoteType) -> String { |
14462 | 82 |
format!( |
83 |
"New voting started: {}", |
|
84 |
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 |
) |
|
13485 | 92 |
} |
93 |
||
13528 | 94 |
fn room_message_flag(msg: &HWProtocolMessage) -> RoomFlags { |
13671 | 95 |
use crate::protocol::messages::HWProtocolMessage::*; |
13528 | 96 |
match msg { |
97 |
ToggleRestrictJoin => RoomFlags::RESTRICTED_JOIN, |
|
98 |
ToggleRestrictTeams => RoomFlags::RESTRICTED_TEAM_ADD, |
|
99 |
ToggleRegisteredOnly => RoomFlags::RESTRICTED_UNREGISTERED_PLAYERS, |
|
14462 | 100 |
_ => RoomFlags::empty(), |
13528 | 101 |
} |
102 |
} |
|
103 |
||
14462 | 104 |
pub fn handle( |
105 |
server: &mut HWServer, |
|
106 |
client_id: ClientId, |
|
14676
455865ccd36c
Server action refactoring part 2 of N
alfadur <mail@none>
parents:
14462
diff
changeset
|
107 |
response: &mut super::Response, |
14462 | 108 |
room_id: RoomId, |
109 |
message: HWProtocolMessage, |
|
110 |
) { |
|
14702 | 111 |
let client = &mut server.clients[client_id]; |
112 |
let room = &mut server.rooms[room_id]; |
|
113 |
||
13671 | 114 |
use crate::protocol::messages::HWProtocolMessage::*; |
12152 | 115 |
match message { |
14680
dfe652c53470
Server action refactoring part 6 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
116 |
Part(msg) => { |
14702 | 117 |
let msg = match msg { |
118 |
Some(s) => format!("part: {}", s), |
|
119 |
None => "part".to_string(), |
|
120 |
}; |
|
121 |
super::common::exit_room(server, client_id, response, &msg); |
|
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
122 |
} |
13421 | 123 |
Chat(msg) => { |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
124 |
response.add( |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
125 |
ChatMsg { |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
126 |
nick: client.nick.clone(), |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
127 |
msg, |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
128 |
} |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
129 |
.send_all() |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
130 |
.in_room(room_id), |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
131 |
); |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
132 |
} |
13482 | 133 |
Fix => { |
14702 | 134 |
if client.is_admin() { |
135 |
room.set_is_fixed(true); |
|
136 |
room.set_join_restriction(false); |
|
137 |
room.set_team_add_restriction(false); |
|
138 |
room.set_unregistered_players_restriction(true); |
|
13482 | 139 |
} |
140 |
} |
|
141 |
Unfix => { |
|
14702 | 142 |
if client.is_admin() { |
143 |
room.set_is_fixed(false); |
|
13482 | 144 |
} |
145 |
} |
|
146 |
Greeting(text) => { |
|
14702 | 147 |
if client.is_admin() || client.is_master() && !room.is_fixed() { |
148 |
room.greeting = text; |
|
13482 | 149 |
} |
150 |
} |
|
13421 | 151 |
RoomName(new_name) => { |
14680
dfe652c53470
Server action refactoring part 6 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
152 |
if is_name_illegal(&new_name) { |
dfe652c53470
Server action refactoring part 6 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
153 |
response.add(Warning("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()).send_self()); |
dfe652c53470
Server action refactoring part 6 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
154 |
} else if server.has_room(&new_name) { |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
155 |
response.add( |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
156 |
Warning("A room with the same name already exists.".to_string()).send_self(), |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
157 |
); |
14680
dfe652c53470
Server action refactoring part 6 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
158 |
} else { |
dfe652c53470
Server action refactoring part 6 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
159 |
let room = &mut server.rooms[room_id]; |
14693
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
160 |
if room.is_fixed() || room.master_id != Some(client_id) { |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
161 |
response.add(Warning("Access denied.".to_string()).send_self()); |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
162 |
} else { |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
163 |
let mut old_name = new_name.clone(); |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
164 |
let client = &server.clients[client_id]; |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
165 |
swap(&mut room.name, &mut old_name); |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
166 |
super::common::get_room_update(Some(old_name), room, Some(&client), response); |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
167 |
} |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
168 |
} |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
169 |
} |
13424 | 170 |
ToggleReady => { |
14702 | 171 |
let flags = if client.is_ready() { |
172 |
room.ready_players_number -= 1; |
|
173 |
"-r" |
|
174 |
} else { |
|
175 |
room.ready_players_number += 1; |
|
176 |
"+r" |
|
177 |
}; |
|
13806 | 178 |
|
14702 | 179 |
let msg = if client.protocol_number < 38 { |
180 |
LegacyReady(client.is_ready(), vec![client.nick.clone()]) |
|
181 |
} else { |
|
182 |
ClientFlags(flags.to_string(), vec![client.nick.clone()]) |
|
183 |
}; |
|
184 |
response.add(msg.send_all().in_room(room.id)); |
|
185 |
client.set_is_ready(!client.is_ready()); |
|
14696 | 186 |
|
14702 | 187 |
if room.is_fixed() && room.ready_players_number == room.players_number { |
188 |
super::common::start_game(server, room_id, response); |
|
13671 | 189 |
} |
13421 | 190 |
} |
13427 | 191 |
AddTeam(info) => { |
14693
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
192 |
if room.teams.len() >= room.team_limit as usize { |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
193 |
response.add(Warning("Too many teams!".to_string()).send_self()); |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
194 |
} else if room.addable_hedgehogs() == 0 { |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
195 |
response.add(Warning("Too many hedgehogs!".to_string()).send_self()); |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
196 |
} else if room.find_team(|t| t.name == info.name) != None { |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
197 |
response.add( |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
198 |
Warning("There's already a team with same name in the list.".to_string()) |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
199 |
.send_self(), |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
200 |
); |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
201 |
} else if room.game_info.is_some() { |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
202 |
response.add( |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
203 |
Warning("Joining not possible: Round is in progress.".to_string()).send_self(), |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
204 |
); |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
205 |
} else if room.is_team_add_restricted() { |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
206 |
response.add( |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
207 |
Warning("This room currently does not allow adding new teams.".to_string()) |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
208 |
.send_self(), |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
209 |
); |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
210 |
} else { |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
211 |
let team = room.add_team(client.id, *info, client.protocol_number < 42); |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
212 |
client.teams_in_game += 1; |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
213 |
client.clan = Some(team.color); |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
214 |
response.add(TeamAccepted(team.name.clone()).send_self()); |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
215 |
response.add( |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
216 |
TeamAdd(HWRoom::team_info(&client, team)) |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
217 |
.send_all() |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
218 |
.in_room(room_id) |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
219 |
.but_self(), |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
220 |
); |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
221 |
response.add( |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
222 |
TeamColor(team.name.clone(), team.color) |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
223 |
.send_all() |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
224 |
.in_room(room_id), |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
225 |
); |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
226 |
response.add( |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
227 |
HedgehogsNumber(team.name.clone(), team.hedgehogs_number) |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
228 |
.send_all() |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
229 |
.in_room(room_id), |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
230 |
); |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
231 |
|
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
232 |
let room_master = if let Some(id) = room.master_id { |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
233 |
Some(&server.clients[id]) |
13424 | 234 |
} else { |
14693
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
235 |
None |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
236 |
}; |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14692
diff
changeset
|
237 |
super::common::get_room_update(None, room, room_master, response); |
13424 | 238 |
} |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
239 |
} |
14702 | 240 |
RemoveTeam(name) => match room.find_team_owner(&name) { |
241 |
None => response.add( |
|
242 |
Warning("Error: The team you tried to remove does not exist.".to_string()) |
|
243 |
.send_self(), |
|
244 |
), |
|
245 |
Some((id, _)) if id != client_id => response |
|
246 |
.add(Warning("You can't remove a team you don't own.".to_string()).send_self()), |
|
247 |
Some((_, name)) => { |
|
248 |
client.teams_in_game -= 1; |
|
249 |
client.clan = room.find_team_color(client.id); |
|
250 |
super::common::remove_teams( |
|
251 |
room, |
|
252 |
vec![name.to_string()], |
|
253 |
client.is_in_game(), |
|
254 |
response, |
|
255 |
); |
|
14696 | 256 |
|
14702 | 257 |
match room.game_info { |
258 |
Some(ref info) if info.teams_in_game == 0 => { |
|
259 |
super::common::end_game(server, room_id, response) |
|
13424 | 260 |
} |
14702 | 261 |
_ => (), |
13424 | 262 |
} |
14680
dfe652c53470
Server action refactoring part 6 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
263 |
} |
14702 | 264 |
}, |
13424 | 265 |
SetHedgehogsNumber(team_name, number) => { |
14702 | 266 |
let addable_hedgehogs = room.addable_hedgehogs(); |
267 |
if let Some((_, team)) = room.find_team_and_owner_mut(|t| t.name == team_name) { |
|
268 |
if !client.is_master() { |
|
269 |
response.add(Error("You're not the room master!".to_string()).send_self()); |
|
270 |
} else if number < 1 |
|
271 |
|| number > MAX_HEDGEHOGS_PER_TEAM |
|
272 |
|| number > addable_hedgehogs + team.hedgehogs_number |
|
273 |
{ |
|
274 |
response |
|
275 |
.add(HedgehogsNumber(team.name.clone(), team.hedgehogs_number).send_self()); |
|
13424 | 276 |
} else { |
14702 | 277 |
team.hedgehogs_number = number; |
278 |
response.add( |
|
279 |
HedgehogsNumber(team.name.clone(), number) |
|
280 |
.send_all() |
|
281 |
.in_room(room_id) |
|
282 |
.but_self(), |
|
283 |
); |
|
14681
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14680
diff
changeset
|
284 |
} |
14702 | 285 |
} else { |
286 |
response.add(Warning("No such team.".to_string()).send_self()); |
|
13671 | 287 |
} |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
288 |
} |
13424 | 289 |
SetTeamColor(team_name, color) => { |
14702 | 290 |
if let Some((owner, team)) = room.find_team_and_owner_mut(|t| t.name == team_name) { |
291 |
if !client.is_master() { |
|
292 |
response.add(Error("You're not the room master!".to_string()).send_self()); |
|
13424 | 293 |
} else { |
14702 | 294 |
team.color = color; |
295 |
response.add( |
|
296 |
TeamColor(team.name.clone(), color) |
|
297 |
.send_all() |
|
298 |
.in_room(room_id) |
|
299 |
.but_self(), |
|
300 |
); |
|
301 |
server.clients[owner].clan = Some(color); |
|
13671 | 302 |
} |
14702 | 303 |
} else { |
304 |
response.add(Warning("No such team.".to_string()).send_self()); |
|
14681
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14680
diff
changeset
|
305 |
} |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
306 |
} |
13427 | 307 |
Cfg(cfg) => { |
14702 | 308 |
if room.is_fixed() { |
309 |
response.add(Warning("Access denied.".to_string()).send_self()); |
|
310 |
} else if !client.is_master() { |
|
311 |
response.add(Error("You're not the room master!".to_string()).send_self()); |
|
312 |
} else { |
|
313 |
let cfg = match cfg { |
|
314 |
GameCfg::Scheme(name, mut values) => { |
|
315 |
if client.protocol_number == 49 && values.len() >= 2 { |
|
316 |
let mut s = "X".repeat(50); |
|
317 |
s.push_str(&values.pop().unwrap()); |
|
318 |
values.push(s); |
|
13806 | 319 |
} |
14702 | 320 |
GameCfg::Scheme(name, values) |
321 |
} |
|
322 |
cfg => cfg, |
|
323 |
}; |
|
13806 | 324 |
|
14702 | 325 |
response.add(cfg.to_server_msg().send_all().in_room(room.id).but_self()); |
326 |
room.set_config(cfg); |
|
13671 | 327 |
} |
13424 | 328 |
} |
13533 | 329 |
Save(name, location) => { |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
330 |
response.add( |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
331 |
server_chat(format!("Room config saved as {}", name)) |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
332 |
.send_all() |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
333 |
.in_room(room_id), |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
334 |
); |
14702 | 335 |
room.save_config(name, location); |
13533 | 336 |
} |
13534 | 337 |
SaveRoom(filename) => { |
14702 | 338 |
if client.is_admin() { |
339 |
match room.get_saves() { |
|
14397 | 340 |
Ok(text) => match server.io.write_file(&filename, &text) { |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
341 |
Ok(_) => response.add( |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
342 |
server_chat("Room configs saved successfully.".to_string()).send_self(), |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
343 |
), |
13534 | 344 |
Err(e) => { |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
345 |
warn!( |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
346 |
"Error while writing the config file \"{}\": {}", |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
347 |
filename, e |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
348 |
); |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
349 |
response.add( |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
350 |
Warning("Unable to save the room configs.".to_string()).send_self(), |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
351 |
); |
13534 | 352 |
} |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
353 |
}, |
13534 | 354 |
Err(e) => { |
355 |
warn!("Error while serializing the room configs: {}", e); |
|
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
356 |
response.add( |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
357 |
Warning("Unable to serialize the room configs.".to_string()) |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
358 |
.send_self(), |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
359 |
) |
13534 | 360 |
} |
14681
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14680
diff
changeset
|
361 |
} |
13671 | 362 |
} |
13534 | 363 |
} |
364 |
LoadRoom(filename) => { |
|
14702 | 365 |
if client.is_admin() { |
14681
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14680
diff
changeset
|
366 |
match server.io.read_file(&filename) { |
14702 | 367 |
Ok(text) => match room.set_saves(&text) { |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
368 |
Ok(_) => response.add( |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
369 |
server_chat("Room configs loaded successfully.".to_string()) |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
370 |
.send_self(), |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
371 |
), |
13534 | 372 |
Err(e) => { |
373 |
warn!("Error while deserializing the room configs: {}", e); |
|
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
374 |
response.add( |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
375 |
Warning("Unable to deserialize the room configs.".to_string()) |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
376 |
.send_self(), |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
377 |
); |
13534 | 378 |
} |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
379 |
}, |
13534 | 380 |
Err(e) => { |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
381 |
warn!( |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
382 |
"Error while reading the config file \"{}\": {}", |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
383 |
filename, e |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
384 |
); |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
385 |
response.add( |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
386 |
Warning("Unable to load the room configs.".to_string()).send_self(), |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
387 |
); |
13534 | 388 |
} |
14681
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14680
diff
changeset
|
389 |
} |
13671 | 390 |
} |
13534 | 391 |
} |
13533 | 392 |
Delete(name) => { |
14702 | 393 |
if !room.delete_config(&name) { |
14681
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14680
diff
changeset
|
394 |
response.add(Warning(format!("Save doesn't exist: {}", name)).send_self()); |
13533 | 395 |
} else { |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
396 |
response.add( |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
397 |
server_chat(format!("Room config {} has been deleted", name)) |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
398 |
.send_all() |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
399 |
.in_room(room_id), |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
400 |
); |
14681
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14680
diff
changeset
|
401 |
} |
13533 | 402 |
} |
13483 | 403 |
CallVote(None) => { |
14681
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14680
diff
changeset
|
404 |
response.add(server_chat("Available callvote commands: kick <nickname>, map <name>, pause, newseed, hedgehogs <number>".to_string()) |
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14680
diff
changeset
|
405 |
.send_self()); |
13483 | 406 |
} |
407 |
CallVote(Some(kind)) => { |
|
14702 | 408 |
let is_in_game = room.game_info.is_some(); |
13483 | 409 |
let error = match &kind { |
410 |
VoteType::Kick(nick) => { |
|
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
411 |
if server |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
412 |
.find_client(&nick) |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
413 |
.filter(|c| c.room_id == Some(room_id)) |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
414 |
.is_some() |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
415 |
{ |
13483 | 416 |
None |
417 |
} else { |
|
13532 | 418 |
Some("/callvote kick: No such user!".to_string()) |
13483 | 419 |
} |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
420 |
} |
13483 | 421 |
VoteType::Map(None) => { |
13532 | 422 |
let names: Vec<_> = server.rooms[room_id].saves.keys().cloned().collect(); |
423 |
if names.is_empty() { |
|
424 |
Some("/callvote map: No maps saved in this room!".to_string()) |
|
425 |
} else { |
|
426 |
Some(format!("Available maps: {}", names.join(", "))) |
|
427 |
} |
|
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
428 |
} |
13483 | 429 |
VoteType::Map(Some(name)) => { |
14702 | 430 |
if room.saves.get(&name[..]).is_some() { |
13535 | 431 |
None |
13532 | 432 |
} else { |
13535 | 433 |
Some("/callvote map: No such map!".to_string()) |
13532 | 434 |
} |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
435 |
} |
13483 | 436 |
VoteType::Pause => { |
437 |
if is_in_game { |
|
438 |
None |
|
439 |
} else { |
|
13532 | 440 |
Some("/callvote pause: No game in progress!".to_string()) |
13483 | 441 |
} |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
442 |
} |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
443 |
VoteType::NewSeed => None, |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
444 |
VoteType::HedgehogsPerTeam(number) => match number { |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
445 |
1...MAX_HEDGEHOGS_PER_TEAM => None, |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
446 |
_ => Some("/callvote hedgehogs: Specify number from 1 to 8.".to_string()), |
13483 | 447 |
}, |
448 |
}; |
|
14702 | 449 |
|
13483 | 450 |
match error { |
451 |
None => { |
|
13485 | 452 |
let msg = voting_description(&kind); |
13483 | 453 |
let voting = Voting::new(kind, server.room_clients(client_id)); |
14691
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14688
diff
changeset
|
454 |
let room = &mut server.rooms[room_id]; |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14688
diff
changeset
|
455 |
room.voting = Some(voting); |
14681
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14680
diff
changeset
|
456 |
response.add(server_chat(msg).send_all().in_room(room_id)); |
14692
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
457 |
super::common::submit_vote( |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
458 |
server, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
459 |
coretypes::Vote { |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
460 |
is_pro: true, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
461 |
is_forced: false, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
462 |
}, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
463 |
response, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
464 |
); |
13483 | 465 |
} |
466 |
Some(msg) => { |
|
14681
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14680
diff
changeset
|
467 |
response.add(server_chat(msg).send_self()); |
13483 | 468 |
} |
469 |
} |
|
470 |
} |
|
471 |
Vote(vote) => { |
|
14692
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
472 |
super::common::submit_vote( |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
473 |
server, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
474 |
coretypes::Vote { |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
475 |
is_pro: vote, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
476 |
is_forced: false, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
477 |
}, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
478 |
response, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
479 |
); |
13483 | 480 |
} |
481 |
ForceVote(vote) => { |
|
14702 | 482 |
let is_forced = client.is_admin(); |
14692
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
483 |
super::common::submit_vote( |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
484 |
server, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
485 |
coretypes::Vote { |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
486 |
is_pro: vote, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
487 |
is_forced, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
488 |
}, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
489 |
response, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14691
diff
changeset
|
490 |
); |
13483 | 491 |
} |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
492 |
ToggleRestrictJoin | ToggleRestrictTeams | ToggleRegisteredOnly => { |
14691
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14688
diff
changeset
|
493 |
if client.is_master() { |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14688
diff
changeset
|
494 |
room.flags.toggle(room_message_flag(&message)); |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14688
diff
changeset
|
495 |
super::common::get_room_update(None, room, Some(&client), response); |
13528 | 496 |
} |
497 |
} |
|
13428 | 498 |
StartGame => { |
14696 | 499 |
super::common::start_game(server, room_id, response); |
13428 | 500 |
} |
501 |
EngineMessage(em) => { |
|
14702 | 502 |
if client.teams_in_game > 0 { |
503 |
let decoding = decode(&em[..]).unwrap(); |
|
504 |
let messages = by_msg(&decoding); |
|
505 |
let valid = messages.filter(|m| is_msg_valid(m, &client.team_indices)); |
|
506 |
let non_empty = valid.clone().filter(|m| !is_msg_empty(m)); |
|
507 |
let sync_msg = valid.clone().filter(|m| is_msg_timed(m)).last().map(|m| { |
|
508 |
if is_msg_empty(m) { |
|
509 |
Some(encode(m)) |
|
510 |
} else { |
|
511 |
None |
|
512 |
} |
|
513 |
}); |
|
13428 | 514 |
|
14702 | 515 |
let em_response = encode(&valid.flat_map(|msg| msg).cloned().collect::<Vec<_>>()); |
516 |
if !em_response.is_empty() { |
|
517 |
response.add( |
|
518 |
ForwardEngineMessage(vec![em_response]) |
|
519 |
.send_all() |
|
520 |
.in_room(room.id) |
|
521 |
.but_self(), |
|
522 |
); |
|
523 |
} |
|
524 |
let em_log = encode(&non_empty.flat_map(|msg| msg).cloned().collect::<Vec<_>>()); |
|
525 |
if let Some(ref mut info) = room.game_info { |
|
526 |
if !em_log.is_empty() { |
|
527 |
info.msg_log.push(em_log); |
|
13428 | 528 |
} |
14702 | 529 |
if let Some(msg) = sync_msg { |
530 |
info.sync_msg = msg; |
|
13432 | 531 |
} |
13428 | 532 |
} |
533 |
} |
|
534 |
} |
|
535 |
RoundFinished => { |
|
14694
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
536 |
let mut game_ended = false; |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
537 |
if client.is_in_game() { |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
538 |
client.set_is_in_game(false); |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
539 |
response.add( |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
540 |
ClientFlags("-g".to_string(), vec![client.nick.clone()]) |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
541 |
.send_all() |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
542 |
.in_room(room.id), |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
543 |
); |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
544 |
let team_names: Vec<_> = room |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
545 |
.client_teams(client_id) |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
546 |
.map(|t| t.name.clone()) |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
547 |
.collect(); |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
548 |
|
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
549 |
if let Some(ref mut info) = room.game_info { |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
550 |
info.teams_in_game -= team_names.len() as u8; |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
551 |
if info.teams_in_game == 0 { |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
552 |
game_ended = true; |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
553 |
} |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
554 |
|
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
555 |
for team_name in team_names { |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
556 |
let msg = once(b'F').chain(team_name.bytes()); |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
557 |
response.add( |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
558 |
ForwardEngineMessage(vec![to_engine_msg(msg)]) |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
559 |
.send_all() |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
560 |
.in_room(room_id) |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
561 |
.but_self(), |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
562 |
); |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
563 |
|
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
564 |
let remove_msg = to_engine_msg(once(b'F').chain(team_name.bytes())); |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
565 |
if let Some(m) = &info.sync_msg { |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
566 |
info.msg_log.push(m.clone()); |
13431 | 567 |
} |
14694
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
568 |
if info.sync_msg.is_some() { |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
569 |
info.sync_msg = None |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
570 |
} |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
571 |
info.msg_log.push(remove_msg.clone()); |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
572 |
response.add( |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
573 |
ForwardEngineMessage(vec![remove_msg]) |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
574 |
.send_all() |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
575 |
.in_room(room_id) |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
576 |
.but_self(), |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
577 |
); |
13428 | 578 |
} |
579 |
} |
|
580 |
} |
|
14694
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
581 |
if game_ended { |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
582 |
super::common::end_game(server, room_id, response) |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14693
diff
changeset
|
583 |
} |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
584 |
} |
13450
d3c86ade3d4d
Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13449
diff
changeset
|
585 |
Rnd(v) => { |
13526 | 586 |
let result = rnd_reply(&v); |
587 |
let mut echo = vec!["/rnd".to_string()]; |
|
588 |
echo.extend(v.into_iter()); |
|
589 |
let chat_msg = ChatMsg { |
|
590 |
nick: server.clients[client_id].nick.clone(), |
|
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
591 |
msg: echo.join(" "), |
13526 | 592 |
}; |
14681
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14680
diff
changeset
|
593 |
response.add(chat_msg.send_all().in_room(room_id)); |
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14680
diff
changeset
|
594 |
response.add(result.send_all().in_room(room_id)); |
14688
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
595 |
} |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14681
diff
changeset
|
596 |
_ => warn!("Unimplemented!"), |
12152 | 597 |
} |
598 |
} |