author | alfadur |
Tue, 07 Jul 2020 01:15:15 +0300 | |
changeset 15719 | 25371cae9fd7 |
parent 15601 | db710cd8df69 |
child 15817 | 40929af15167 |
permissions | -rw-r--r-- |
13666 | 1 |
use crate::{ |
15096 | 2 |
core::{ |
3 |
client::HwClient, |
|
4 |
room::HwRoom, |
|
15547 | 5 |
server::{ |
6 |
EndGameResult, HwRoomControl, HwServer, JoinRoomError, LeaveRoomResult, StartGameError, |
|
7 |
VoteError, VoteResult, |
|
8 |
}, |
|
9 |
types::{ClientId, GameCfg, RoomId, TeamInfo, Vote, VoteType, MAX_HEDGEHOGS_PER_TEAM}, |
|
15096 | 10 |
}, |
13666 | 11 |
protocol::messages::{ |
15096 | 12 |
add_flags, remove_flags, server_chat, |
13 |
HwProtocolMessage::{self, Rnd}, |
|
14 |
HwServerMessage::{self, *}, |
|
14803 | 15 |
ProtocolFlags as Flags, |
14478 | 16 |
}, |
14709
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14708
diff
changeset
|
17 |
utils::to_engine_msg, |
13444
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
18 |
}; |
14709
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14708
diff
changeset
|
19 |
|
15565 | 20 |
use super::{ |
21 |
actions::{Destination, DestinationGroup}, |
|
22 |
Response, |
|
23 |
}; |
|
14709
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14708
diff
changeset
|
24 |
|
15095 | 25 |
use crate::core::types::RoomConfig; |
14718 | 26 |
use rand::{self, seq::SliceRandom, thread_rng, Rng}; |
14709
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14708
diff
changeset
|
27 |
use std::{iter::once, mem::replace}; |
13444
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
28 |
|
15096 | 29 |
pub fn rnd_reply(options: &[String]) -> HwServerMessage { |
13492 | 30 |
let mut rng = thread_rng(); |
14718 | 31 |
|
13492 | 32 |
let reply = if options.is_empty() { |
14718 | 33 |
(*&["heads", "tails"].choose(&mut rng).unwrap()).to_string() |
13445
d3c86ade3d4d
Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13444
diff
changeset
|
34 |
} else { |
14718 | 35 |
options.choose(&mut rng).unwrap().clone() |
13492 | 36 |
}; |
13445
d3c86ade3d4d
Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13444
diff
changeset
|
37 |
|
13492 | 38 |
ChatMsg { |
14718 | 39 |
nick: "[random]".to_string(), |
40 |
msg: reply, |
|
13492 | 41 |
} |
13444
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
42 |
} |
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
43 |
|
15465 | 44 |
pub fn get_lobby_join_data(server: &HwServer, response: &mut Response) { |
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
45 |
let client_id = response.client_id(); |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
46 |
|
15465 | 47 |
let client = server.client(client_id); |
14812 | 48 |
let nick = vec![client.nick.clone()]; |
49 |
let mut flags = vec![]; |
|
50 |
if client.is_registered() { |
|
51 |
flags.push(Flags::Registered) |
|
52 |
} |
|
53 |
if client.is_admin() { |
|
54 |
flags.push(Flags::Admin) |
|
55 |
} |
|
56 |
if client.is_contributor() { |
|
57 |
flags.push(Flags::Contributor) |
|
58 |
} |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
59 |
|
14812 | 60 |
let all_nicks: Vec<_> = server.collect_nicks(|_| true); |
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
61 |
|
14812 | 62 |
let mut flag_selectors = [ |
63 |
( |
|
64 |
Flags::Registered, |
|
65 |
server.collect_nicks(|(_, c)| c.is_registered()), |
|
66 |
), |
|
67 |
(Flags::Admin, server.collect_nicks(|(_, c)| c.is_admin())), |
|
68 |
( |
|
69 |
Flags::Contributor, |
|
70 |
server.collect_nicks(|(_, c)| c.is_contributor()), |
|
71 |
), |
|
72 |
( |
|
73 |
Flags::InRoom, |
|
74 |
server.collect_nicks(|(_, c)| c.room_id.is_some()), |
|
75 |
), |
|
76 |
]; |
|
77 |
||
15465 | 78 |
let server_msg = ServerMessage(server.get_greetings(client).to_string()); |
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
79 |
|
14802 | 80 |
let rooms_msg = Rooms( |
15545
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15544
diff
changeset
|
81 |
server |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15544
diff
changeset
|
82 |
.iter_rooms() |
15544 | 83 |
.filter(|r| r.protocol_number == client.protocol_number) |
84 |
.flat_map(|r| r.info(r.master_id.map(|id| server.client(id)))) |
|
14802 | 85 |
.collect(), |
86 |
); |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
87 |
|
14812 | 88 |
response.add(LobbyJoined(nick).send_all().but_self()); |
89 |
response.add( |
|
90 |
ClientFlags(add_flags(&flags), all_nicks.clone()) |
|
91 |
.send_all() |
|
92 |
.but_self(), |
|
93 |
); |
|
94 |
||
95 |
response.add(LobbyJoined(all_nicks).send_self()); |
|
96 |
for (flag, nicks) in &mut flag_selectors { |
|
14912 | 97 |
if !nicks.is_empty() { |
98 |
response.add(ClientFlags(add_flags(&[*flag]), replace(nicks, vec![])).send_self()); |
|
99 |
} |
|
14812 | 100 |
} |
101 |
||
14802 | 102 |
response.add(server_msg.send_self()); |
103 |
response.add(rooms_msg.send_self()); |
|
14704
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
104 |
} |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14696
diff
changeset
|
105 |
|
15463 | 106 |
pub fn get_room_join_data<'a, I: Iterator<Item = &'a HwClient> + Clone>( |
107 |
client: &HwClient, |
|
108 |
room: &HwRoom, |
|
109 |
room_clients: I, |
|
14808 | 110 |
response: &mut Response, |
111 |
) { |
|
15463 | 112 |
#[inline] |
15556 | 113 |
fn partition_nicks<'a, I, F>(clients: I, f: F) -> (Vec<String>, Vec<String>) |
15463 | 114 |
where |
15556 | 115 |
I: Iterator<Item = &'a HwClient> + Clone, |
15463 | 116 |
F: Fn(&&'a HwClient) -> bool, |
117 |
{ |
|
15556 | 118 |
( |
119 |
clients |
|
120 |
.clone() |
|
121 |
.filter(|c| f(c)) |
|
122 |
.map(|c| &c.nick) |
|
123 |
.cloned() |
|
124 |
.collect(), |
|
125 |
clients |
|
126 |
.filter(|c| !f(c)) |
|
127 |
.map(|c| &c.nick) |
|
128 |
.cloned() |
|
129 |
.collect(), |
|
130 |
) |
|
15463 | 131 |
} |
14808 | 132 |
|
15463 | 133 |
let nick = client.nick.clone(); |
15556 | 134 |
response.add( |
135 |
RoomJoined(vec![nick.clone()]) |
|
136 |
.send_all() |
|
137 |
.in_room(room.id) |
|
138 |
.but_self(), |
|
139 |
); |
|
15557
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
140 |
response.add(ClientFlags(add_flags(&[Flags::InRoom]), vec![nick.clone()]).send_all()); |
15556 | 141 |
let nicks = room_clients.clone().map(|c| c.nick.clone()).collect(); |
14808 | 142 |
response.add(RoomJoined(nicks).send_self()); |
143 |
||
14820 | 144 |
let mut flag_selectors = [ |
145 |
( |
|
146 |
Flags::RoomMaster, |
|
15556 | 147 |
partition_nicks(room_clients.clone(), |c| c.is_master()), |
14820 | 148 |
), |
15463 | 149 |
( |
150 |
Flags::Ready, |
|
15556 | 151 |
partition_nicks(room_clients.clone(), |c| c.is_ready()), |
15463 | 152 |
), |
153 |
( |
|
154 |
Flags::InGame, |
|
15556 | 155 |
partition_nicks(room_clients.clone(), |c| c.is_in_game()), |
15463 | 156 |
), |
14820 | 157 |
]; |
158 |
||
15556 | 159 |
for (flag, (set_nicks, cleared_nicks)) in &mut flag_selectors { |
160 |
if !set_nicks.is_empty() { |
|
161 |
response.add(ClientFlags(add_flags(&[*flag]), replace(set_nicks, vec![])).send_self()); |
|
162 |
} |
|
163 |
||
164 |
if !cleared_nicks.is_empty() { |
|
165 |
response.add( |
|
166 |
ClientFlags(remove_flags(&[*flag]), replace(cleared_nicks, vec![])).send_self(), |
|
167 |
); |
|
168 |
} |
|
14820 | 169 |
} |
14808 | 170 |
|
15575 | 171 |
get_active_room_teams(room, Destination::ToSelf, response); |
172 |
get_active_room_config(room, Destination::ToSelf, response); |
|
15557
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
173 |
|
14808 | 174 |
if !room.greeting.is_empty() { |
175 |
response.add( |
|
176 |
ChatMsg { |
|
177 |
nick: "[greeting]".to_string(), |
|
178 |
msg: room.greeting.clone(), |
|
179 |
} |
|
180 |
.send_self(), |
|
181 |
); |
|
182 |
} |
|
15557
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
183 |
|
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
184 |
if let Some(info) = &room.game_info { |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
185 |
response.add( |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
186 |
ClientFlags(add_flags(&[Flags::Ready, Flags::InGame]), vec![nick]) |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
187 |
.send_all() |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
188 |
.in_room(room.id), |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
189 |
); |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
190 |
response.add(RunGame.send_self()); |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
191 |
|
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
192 |
response.add( |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
193 |
ForwardEngineMessage( |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
194 |
once(to_engine_msg("e$spectate 1".bytes())) |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
195 |
.chain(info.msg_log.iter().cloned()) |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
196 |
.collect(), |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
197 |
) |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
198 |
.send_self(), |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
199 |
); |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
200 |
|
15562 | 201 |
for team in info.client_teams(client.id) { |
15557
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
202 |
response.add( |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
203 |
ForwardEngineMessage(vec![to_engine_msg(once(b'G').chain(team.name.bytes()))]) |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
204 |
.send_all() |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
205 |
.in_room(room.id), |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
206 |
); |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
207 |
} |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
208 |
|
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
209 |
if info.is_paused { |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
210 |
response.add(ForwardEngineMessage(vec![to_engine_msg(once(b'I'))]).send_self()); |
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
211 |
} |
15591 | 212 |
|
213 |
for (_, original_team) in &info.original_teams { |
|
214 |
if let Some(team) = room.find_team(|team| team.name == original_team.name) { |
|
15719 | 215 |
if team != original_team { |
216 |
response.add(TeamRemove(original_team.name.clone()).send_self()); |
|
217 |
response.add(TeamAdd(team.to_protocol()).send_self()); |
|
15591 | 218 |
} |
219 |
} else { |
|
220 |
response.add(TeamRemove(original_team.name.clone()).send_self()); |
|
221 |
} |
|
222 |
} |
|
223 |
||
15719 | 224 |
for (_, team) in &room.teams { |
225 |
if !info.original_teams.iter().any(|(_, t)| t.name == team.name) { |
|
226 |
response.add(TeamAdd(team.to_protocol()).send_self()); |
|
227 |
} |
|
228 |
} |
|
229 |
||
15591 | 230 |
get_room_config_impl(room.config(), Destination::ToSelf, response); |
15557
3f6a7a867040
add back em response on joining a game in progress
alfadur <mail@none>
parents:
15556
diff
changeset
|
231 |
} |
14808 | 232 |
} |
233 |
||
15463 | 234 |
pub fn get_room_join_error(error: JoinRoomError, response: &mut Response) { |
235 |
use super::strings::*; |
|
236 |
match error { |
|
237 |
JoinRoomError::DoesntExist => response.warn(NO_ROOM), |
|
15556 | 238 |
JoinRoomError::WrongProtocol => response.warn(INCOMPATIBLE_ROOM_PROTOCOL), |
15555 | 239 |
JoinRoomError::WrongPassword => { |
240 |
response.add(Notice("WrongPassword".to_string()).send_self()) |
|
241 |
} |
|
15463 | 242 |
JoinRoomError::Full => response.warn(ROOM_FULL), |
243 |
JoinRoomError::Restricted => response.warn(ROOM_JOIN_RESTRICTED), |
|
15556 | 244 |
JoinRoomError::RegistrationRequired => response.warn(ROOM_REGISTRATION_REQUIRED), |
15463 | 245 |
} |
246 |
} |
|
247 |
||
15504 | 248 |
pub fn get_remove_teams_data( |
249 |
room_id: RoomId, |
|
250 |
was_in_game: bool, |
|
251 |
removed_teams: Vec<String>, |
|
252 |
response: &mut Response, |
|
253 |
) { |
|
254 |
if was_in_game { |
|
255 |
for team_name in &removed_teams { |
|
256 |
let remove_msg = to_engine_msg(once(b'F').chain(team_name.bytes())); |
|
14711
f61ce544d436
Server action refactoring part N of N
alfadur <mail@none>
parents:
14710
diff
changeset
|
257 |
|
15504 | 258 |
response.add( |
259 |
ForwardEngineMessage(vec![remove_msg]) |
|
260 |
.send_all() |
|
261 |
.in_room(room_id) |
|
262 |
.but_self(), |
|
263 |
); |
|
264 |
} |
|
15563 | 265 |
} else { |
266 |
for team_name in removed_teams { |
|
267 |
response.add(TeamRemove(team_name).send_all().in_room(room_id)); |
|
268 |
} |
|
15504 | 269 |
} |
270 |
} |
|
14711
f61ce544d436
Server action refactoring part N of N
alfadur <mail@none>
parents:
14710
diff
changeset
|
271 |
|
15514 | 272 |
pub fn get_room_leave_result( |
15504 | 273 |
server: &HwServer, |
274 |
room: &HwRoom, |
|
275 |
leave_message: &str, |
|
276 |
result: LeaveRoomResult, |
|
277 |
response: &mut Response, |
|
278 |
) { |
|
279 |
let client = server.client(response.client_id); |
|
280 |
response.add(ClientFlags(remove_flags(&[Flags::InRoom]), vec![client.nick.clone()]).send_all()); |
|
281 |
||
15538 | 282 |
match result { |
15504 | 283 |
LeaveRoomResult::RoomRemoved => { |
284 |
response.add( |
|
285 |
RoomRemove(room.name.clone()) |
|
286 |
.send_all() |
|
287 |
.with_protocol(room.protocol_number), |
|
288 |
); |
|
289 |
} |
|
14711
f61ce544d436
Server action refactoring part N of N
alfadur <mail@none>
parents:
14710
diff
changeset
|
290 |
|
15504 | 291 |
LeaveRoomResult::RoomRemains { |
292 |
is_empty, |
|
293 |
was_master, |
|
294 |
new_master, |
|
295 |
was_in_game, |
|
296 |
removed_teams, |
|
297 |
} => { |
|
298 |
if !is_empty { |
|
299 |
response.add( |
|
300 |
RoomLeft(client.nick.clone(), leave_message.to_string()) |
|
301 |
.send_all() |
|
302 |
.in_room(room.id) |
|
303 |
.but_self(), |
|
304 |
); |
|
305 |
} |
|
14819 | 306 |
|
15504 | 307 |
if was_master { |
308 |
response.add( |
|
309 |
ClientFlags( |
|
310 |
remove_flags(&[Flags::RoomMaster]), |
|
311 |
vec![client.nick.clone()], |
|
312 |
) |
|
313 |
.send_all() |
|
314 |
.in_room(room.id), |
|
315 |
); |
|
14819 | 316 |
|
15504 | 317 |
if let Some(new_master_id) = new_master { |
318 |
let new_master_nick = server.client(new_master_id).nick.clone(); |
|
14819 | 319 |
response.add( |
320 |
ClientFlags(add_flags(&[Flags::RoomMaster]), vec![new_master_nick]) |
|
321 |
.send_all() |
|
322 |
.in_room(room.id), |
|
323 |
); |
|
14715 | 324 |
} |
14711
f61ce544d436
Server action refactoring part N of N
alfadur <mail@none>
parents:
14710
diff
changeset
|
325 |
} |
15504 | 326 |
|
327 |
get_remove_teams_data(room.id, was_in_game, removed_teams, response); |
|
328 |
||
329 |
response.add( |
|
330 |
RoomUpdated(room.name.clone(), room.info(Some(&client))) |
|
331 |
.send_all() |
|
332 |
.with_protocol(room.protocol_number), |
|
333 |
); |
|
14711
f61ce544d436
Server action refactoring part N of N
alfadur <mail@none>
parents:
14710
diff
changeset
|
334 |
} |
f61ce544d436
Server action refactoring part N of N
alfadur <mail@none>
parents:
14710
diff
changeset
|
335 |
} |
f61ce544d436
Server action refactoring part N of N
alfadur <mail@none>
parents:
14710
diff
changeset
|
336 |
} |
f61ce544d436
Server action refactoring part N of N
alfadur <mail@none>
parents:
14710
diff
changeset
|
337 |
|
15096 | 338 |
pub fn remove_client(server: &mut HwServer, response: &mut Response, msg: String) { |
14695
b87c71ccd17d
Server action refactoring part 5 of N
alfadur <mail@none>
parents:
14694
diff
changeset
|
339 |
let client_id = response.client_id(); |
15504 | 340 |
let client = server.client(client_id); |
14718 | 341 |
let nick = client.nick.clone(); |
14695
b87c71ccd17d
Server action refactoring part 5 of N
alfadur <mail@none>
parents:
14694
diff
changeset
|
342 |
|
15545
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15544
diff
changeset
|
343 |
if let Some(mut room_control) = server.get_room_control(client_id) { |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15544
diff
changeset
|
344 |
let room_id = room_control.room().id; |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15544
diff
changeset
|
345 |
let result = room_control.leave_room(); |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15544
diff
changeset
|
346 |
get_room_leave_result(server, server.room(room_id), &msg, result, response); |
15504 | 347 |
} |
14695
b87c71ccd17d
Server action refactoring part 5 of N
alfadur <mail@none>
parents:
14694
diff
changeset
|
348 |
|
b87c71ccd17d
Server action refactoring part 5 of N
alfadur <mail@none>
parents:
14694
diff
changeset
|
349 |
server.remove_client(client_id); |
b87c71ccd17d
Server action refactoring part 5 of N
alfadur <mail@none>
parents:
14694
diff
changeset
|
350 |
|
15465 | 351 |
response.add(LobbyLeft(nick, msg.clone()).send_all()); |
352 |
response.add(Bye(msg).send_self()); |
|
14717 | 353 |
response.remove_client(client_id); |
14694
08a8605bafaf
Server action refactoring part 4 of N
alfadur <mail@none>
parents:
14478
diff
changeset
|
354 |
} |
08a8605bafaf
Server action refactoring part 4 of N
alfadur <mail@none>
parents:
14478
diff
changeset
|
355 |
|
14707
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
356 |
pub fn get_room_update( |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
357 |
room_name: Option<String>, |
15096 | 358 |
room: &HwRoom, |
359 |
master: Option<&HwClient>, |
|
14709
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14708
diff
changeset
|
360 |
response: &mut Response, |
14707
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
361 |
) { |
14708
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14707
diff
changeset
|
362 |
let update_msg = RoomUpdated(room_name.unwrap_or(room.name.clone()), room.info(master)); |
14707
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
363 |
response.add(update_msg.send_all().with_protocol(room.protocol_number)); |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
364 |
} |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
365 |
|
15565 | 366 |
pub fn get_room_config_impl( |
367 |
config: &RoomConfig, |
|
368 |
destination: Destination, |
|
369 |
response: &mut Response, |
|
370 |
) { |
|
371 |
response.add( |
|
372 |
ConfigEntry("FULLMAPCONFIG".to_string(), config.to_map_config()) |
|
373 |
.send_to_destination(destination.clone()), |
|
374 |
); |
|
14806
a1077e8d26f4
implement watch message apart from replay deserializing
alfadur
parents:
14805
diff
changeset
|
375 |
for cfg in config.to_game_config() { |
15565 | 376 |
response.add(cfg.to_server_msg().send_to_destination(destination.clone())); |
14806
a1077e8d26f4
implement watch message apart from replay deserializing
alfadur
parents:
14805
diff
changeset
|
377 |
} |
a1077e8d26f4
implement watch message apart from replay deserializing
alfadur
parents:
14805
diff
changeset
|
378 |
} |
a1077e8d26f4
implement watch message apart from replay deserializing
alfadur
parents:
14805
diff
changeset
|
379 |
|
15575 | 380 |
pub fn get_active_room_config(room: &HwRoom, destination: Destination, response: &mut Response) { |
15565 | 381 |
get_room_config_impl(room.active_config(), destination, response); |
14806
a1077e8d26f4
implement watch message apart from replay deserializing
alfadur
parents:
14805
diff
changeset
|
382 |
} |
a1077e8d26f4
implement watch message apart from replay deserializing
alfadur
parents:
14805
diff
changeset
|
383 |
|
15565 | 384 |
pub fn get_teams<'a, I>(teams: I, destination: Destination, response: &mut Response) |
14806
a1077e8d26f4
implement watch message apart from replay deserializing
alfadur
parents:
14805
diff
changeset
|
385 |
where |
a1077e8d26f4
implement watch message apart from replay deserializing
alfadur
parents:
14805
diff
changeset
|
386 |
I: Iterator<Item = &'a TeamInfo>, |
a1077e8d26f4
implement watch message apart from replay deserializing
alfadur
parents:
14805
diff
changeset
|
387 |
{ |
a1077e8d26f4
implement watch message apart from replay deserializing
alfadur
parents:
14805
diff
changeset
|
388 |
for team in teams { |
15565 | 389 |
response.add(TeamAdd(team.to_protocol()).send_to_destination(destination.clone())); |
390 |
response |
|
391 |
.add(TeamColor(team.name.clone(), team.color).send_to_destination(destination.clone())); |
|
392 |
response.add( |
|
393 |
HedgehogsNumber(team.name.clone(), team.hedgehogs_number) |
|
394 |
.send_to_destination(destination.clone()), |
|
395 |
); |
|
14710
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14709
diff
changeset
|
396 |
} |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14709
diff
changeset
|
397 |
} |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14709
diff
changeset
|
398 |
|
15575 | 399 |
pub fn get_active_room_teams(room: &HwRoom, destination: Destination, response: &mut Response) { |
15562 | 400 |
let current_teams = match room.game_info { |
15563 | 401 |
Some(ref info) => &info.original_teams, |
15562 | 402 |
None => &room.teams, |
403 |
}; |
|
404 |
||
15565 | 405 |
get_teams(current_teams.iter().map(|(_, t)| t), destination, response); |
14710
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14709
diff
changeset
|
406 |
} |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14709
diff
changeset
|
407 |
|
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14709
diff
changeset
|
408 |
pub fn get_room_flags( |
15096 | 409 |
server: &HwServer, |
14710
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14709
diff
changeset
|
410 |
room_id: RoomId, |
15565 | 411 |
destination: Destination, |
14710
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14709
diff
changeset
|
412 |
response: &mut Response, |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14709
diff
changeset
|
413 |
) { |
15544 | 414 |
let room = server.room(room_id); |
14710
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14709
diff
changeset
|
415 |
if let Some(id) = room.master_id { |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14709
diff
changeset
|
416 |
response.add( |
14803 | 417 |
ClientFlags( |
418 |
add_flags(&[Flags::RoomMaster]), |
|
15514 | 419 |
vec![server.client(id).nick.clone()], |
14803 | 420 |
) |
15565 | 421 |
.send_to_destination(destination.clone()), |
14710
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14709
diff
changeset
|
422 |
); |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14709
diff
changeset
|
423 |
} |
15514 | 424 |
let nicks = server.collect_nicks(|(_, c)| c.room_id == Some(room_id) && c.is_ready()); |
425 |
||
14710
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14709
diff
changeset
|
426 |
if !nicks.is_empty() { |
15565 | 427 |
response |
428 |
.add(ClientFlags(add_flags(&[Flags::Ready]), nicks).send_to_destination(destination)); |
|
14710
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14709
diff
changeset
|
429 |
} |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14709
diff
changeset
|
430 |
} |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14709
diff
changeset
|
431 |
|
15547 | 432 |
pub fn check_vote( |
433 |
server: &HwServer, |
|
434 |
room: &HwRoom, |
|
435 |
kind: &VoteType, |
|
436 |
response: &mut Response, |
|
437 |
) -> bool { |
|
438 |
let error = match &kind { |
|
439 |
VoteType::Kick(nick) => { |
|
440 |
if server |
|
441 |
.find_client(&nick) |
|
442 |
.filter(|c| c.room_id == Some(room.id)) |
|
443 |
.is_some() |
|
444 |
{ |
|
445 |
None |
|
446 |
} else { |
|
447 |
Some("/callvote kick: No such user!".to_string()) |
|
448 |
} |
|
449 |
} |
|
450 |
VoteType::Map(None) => { |
|
451 |
let names: Vec<_> = room.saves.keys().cloned().collect(); |
|
452 |
if names.is_empty() { |
|
453 |
Some("/callvote map: No maps saved in this room!".to_string()) |
|
454 |
} else { |
|
455 |
Some(format!("Available maps: {}", names.join(", "))) |
|
456 |
} |
|
457 |
} |
|
458 |
VoteType::Map(Some(name)) => { |
|
459 |
if room.saves.get(&name[..]).is_some() { |
|
460 |
None |
|
461 |
} else { |
|
462 |
Some("/callvote map: No such map!".to_string()) |
|
463 |
} |
|
464 |
} |
|
465 |
VoteType::Pause => { |
|
466 |
if room.game_info.is_some() { |
|
467 |
None |
|
468 |
} else { |
|
469 |
Some("/callvote pause: No game in progress!".to_string()) |
|
470 |
} |
|
471 |
} |
|
472 |
VoteType::NewSeed => None, |
|
473 |
VoteType::HedgehogsPerTeam(number) => match number { |
|
474 |
1..=MAX_HEDGEHOGS_PER_TEAM => None, |
|
475 |
_ => Some("/callvote hedgehogs: Specify number from 1 to 8.".to_string()), |
|
476 |
}, |
|
477 |
}; |
|
478 |
||
479 |
match error { |
|
480 |
None => true, |
|
481 |
Some(msg) => { |
|
482 |
response.add(server_chat(msg).send_self()); |
|
483 |
false |
|
484 |
} |
|
485 |
} |
|
486 |
} |
|
487 |
||
488 |
pub fn get_vote_data( |
|
14708
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14707
diff
changeset
|
489 |
room_id: RoomId, |
15547 | 490 |
result: &Result<VoteResult, VoteError>, |
14709
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14708
diff
changeset
|
491 |
response: &mut Response, |
14708
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14707
diff
changeset
|
492 |
) { |
15547 | 493 |
match result { |
494 |
Ok(VoteResult::Submitted) => { |
|
495 |
response.add(server_chat("Your vote has been counted.".to_string()).send_self()) |
|
496 |
} |
|
497 |
Ok(VoteResult::Succeeded(_)) | Ok(VoteResult::Failed) => response.add( |
|
498 |
server_chat("Voting closed.".to_string()) |
|
499 |
.send_all() |
|
500 |
.in_room(room_id), |
|
501 |
), |
|
502 |
Err(VoteError::NoVoting) => { |
|
503 |
response.add(server_chat("There's no voting going on.".to_string()).send_self()) |
|
504 |
} |
|
505 |
Err(VoteError::AlreadyVoted) => { |
|
506 |
response.add(server_chat("You already have voted.".to_string()).send_self()) |
|
507 |
} |
|
508 |
} |
|
509 |
} |
|
510 |
||
511 |
pub fn handle_vote( |
|
512 |
mut room_control: HwRoomControl, |
|
513 |
result: Result<VoteResult, VoteError>, |
|
514 |
response: &mut super::Response, |
|
515 |
) { |
|
516 |
let room_id = room_control.room().id; |
|
517 |
super::common::get_vote_data(room_control.room().id, &result, response); |
|
518 |
||
519 |
if let Ok(VoteResult::Succeeded(kind)) = result { |
|
520 |
match kind { |
|
521 |
VoteType::Kick(nick) => { |
|
522 |
if let Some(kicked_client) = room_control.server().find_client(&nick) { |
|
523 |
let kicked_id = kicked_client.id; |
|
524 |
if let Some(mut room_control) = room_control.change_client(kicked_id) { |
|
15545
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15544
diff
changeset
|
525 |
response.add(Kicked.send(kicked_id)); |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15544
diff
changeset
|
526 |
let result = room_control.leave_room(); |
15547 | 527 |
super::common::get_room_leave_result( |
15545
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15544
diff
changeset
|
528 |
room_control.server(), |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15544
diff
changeset
|
529 |
room_control.room(), |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15544
diff
changeset
|
530 |
"kicked", |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15544
diff
changeset
|
531 |
result, |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15544
diff
changeset
|
532 |
response, |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15544
diff
changeset
|
533 |
); |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15544
diff
changeset
|
534 |
} |
14708
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14707
diff
changeset
|
535 |
} |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14707
diff
changeset
|
536 |
} |
15547 | 537 |
VoteType::Map(None) => (), |
538 |
VoteType::Map(Some(name)) => { |
|
539 |
if let Some(location) = room_control.load_config(&name) { |
|
540 |
let msg = server_chat(location.to_string()); |
|
541 |
let room = room_control.room(); |
|
542 |
response.add(msg.send_all().in_room(room.id)); |
|
14708
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14707
diff
changeset
|
543 |
|
15547 | 544 |
let room_master = room.master_id.map(|id| room_control.server().client(id)); |
545 |
||
546 |
super::common::get_room_update(None, room, room_master, response); |
|
547 |
||
15565 | 548 |
let room_destination = Destination::ToAll { |
549 |
group: DestinationGroup::Room(room.id), |
|
550 |
skip_self: false, |
|
551 |
}; |
|
15575 | 552 |
super::common::get_active_room_config(room, room_destination, response); |
14708
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14707
diff
changeset
|
553 |
} |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14707
diff
changeset
|
554 |
} |
15547 | 555 |
VoteType::Pause => { |
556 |
if room_control.toggle_pause() { |
|
557 |
response.add( |
|
558 |
server_chat("Pause toggled.".to_string()) |
|
559 |
.send_all() |
|
560 |
.in_room(room_id), |
|
561 |
); |
|
562 |
response.add( |
|
563 |
ForwardEngineMessage(vec![to_engine_msg(once(b'I'))]) |
|
564 |
.send_all() |
|
565 |
.in_room(room_id), |
|
566 |
); |
|
567 |
} |
|
14708
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14707
diff
changeset
|
568 |
} |
15547 | 569 |
VoteType::NewSeed => { |
570 |
let seed = thread_rng().gen_range(0, 1_000_000_000).to_string(); |
|
571 |
let cfg = GameCfg::Seed(seed); |
|
572 |
response.add(cfg.to_server_msg().send_all().in_room(room_id)); |
|
573 |
room_control.set_config(cfg); |
|
14707
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
574 |
} |
15547 | 575 |
VoteType::HedgehogsPerTeam(number) => { |
576 |
let nicks = room_control.set_hedgehogs_number(number); |
|
577 |
response.extend( |
|
578 |
nicks |
|
579 |
.into_iter() |
|
580 |
.map(|n| HedgehogsNumber(n, number).send_all().in_room(room_id)), |
|
581 |
); |
|
14708
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14707
diff
changeset
|
582 |
} |
14707
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
583 |
} |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
584 |
} |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
585 |
} |
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14704
diff
changeset
|
586 |
|
15514 | 587 |
pub fn get_start_game_data( |
588 |
server: &HwServer, |
|
589 |
room_id: RoomId, |
|
590 |
result: Result<Vec<String>, StartGameError>, |
|
591 |
response: &mut Response, |
|
592 |
) { |
|
593 |
match result { |
|
594 |
Ok(room_nicks) => { |
|
595 |
let room = server.room(room_id); |
|
596 |
response.add(RunGame.send_all().in_room(room.id)); |
|
597 |
response.add( |
|
598 |
ClientFlags(add_flags(&[Flags::InGame]), room_nicks) |
|
599 |
.send_all() |
|
600 |
.in_room(room.id), |
|
601 |
); |
|
14709
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14708
diff
changeset
|
602 |
|
15514 | 603 |
let room_master = room.master_id.map(|id| server.client(id)); |
604 |
get_room_update(None, room, room_master, response); |
|
14709
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14708
diff
changeset
|
605 |
} |
15514 | 606 |
Err(StartGameError::NotEnoughClans) => { |
607 |
response.warn("The game can't be started with less than two clans!") |
|
608 |
} |
|
609 |
Err(StartGameError::NotReady) => response.warn("Not all players are ready"), |
|
15538 | 610 |
Err(StartGameError::AlreadyInGame) => response.warn("The game is already in progress"), |
14709
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14708
diff
changeset
|
611 |
} |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14708
diff
changeset
|
612 |
} |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14708
diff
changeset
|
613 |
|
15538 | 614 |
pub fn get_end_game_result( |
615 |
server: &HwServer, |
|
616 |
room_id: RoomId, |
|
617 |
result: EndGameResult, |
|
618 |
response: &mut Response, |
|
619 |
) { |
|
620 |
let room = server.room(room_id); |
|
15547 | 621 |
let room_master = room.master_id.map(|id| server.client(id)); |
15538 | 622 |
|
14709
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14708
diff
changeset
|
623 |
get_room_update(None, room, room_master, response); |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14708
diff
changeset
|
624 |
response.add(RoundFinished.send_all().in_room(room_id)); |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14708
diff
changeset
|
625 |
|
15563 | 626 |
response.extend( |
627 |
result |
|
628 |
.left_teams |
|
629 |
.iter() |
|
15591 | 630 |
.filter(|name| room.find_team(|t| t.name == **name).is_some()) |
15563 | 631 |
.map(|name| TeamRemove(name.clone()).send_all().in_room(room.id)), |
632 |
); |
|
633 |
||
15538 | 634 |
if !result.unreadied_nicks.is_empty() { |
15563 | 635 |
response.add( |
15538 | 636 |
ClientFlags(remove_flags(&[Flags::Ready]), result.unreadied_nicks) |
15563 | 637 |
.send_all() |
638 |
.in_room(room_id), |
|
639 |
); |
|
14709
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14708
diff
changeset
|
640 |
} |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14708
diff
changeset
|
641 |
} |
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14708
diff
changeset
|
642 |
|
13444
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
643 |
#[cfg(test)] |
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
644 |
mod tests { |
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
645 |
use super::*; |
15132 | 646 |
use crate::handlers::actions::PendingMessage; |
15096 | 647 |
use crate::protocol::messages::HwServerMessage::ChatMsg; |
13444
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
648 |
|
15096 | 649 |
fn reply2string(r: HwServerMessage) -> String { |
13445
d3c86ade3d4d
Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13444
diff
changeset
|
650 |
match r { |
d3c86ade3d4d
Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13444
diff
changeset
|
651 |
ChatMsg { msg: p, .. } => String::from(p), |
d3c86ade3d4d
Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13444
diff
changeset
|
652 |
_ => panic!("expected a ChatMsg"), |
13444
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
653 |
} |
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
654 |
} |
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
655 |
|
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
656 |
fn run_handle_test(opts: Vec<String>) { |
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
657 |
let opts2 = opts.clone(); |
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
658 |
for opt in opts { |
13492 | 659 |
while reply2string(rnd_reply(&opts2)) != opt {} |
13444
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
660 |
} |
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
661 |
} |
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
662 |
|
13446
dd2e51f7303d
Add an extra test for Rnd's distribution
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13445
diff
changeset
|
663 |
/// This test terminates almost surely. |
13444
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
664 |
#[test] |
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
665 |
fn test_handle_rnd_empty() { |
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
666 |
run_handle_test(vec![]) |
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
667 |
} |
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
668 |
|
13446
dd2e51f7303d
Add an extra test for Rnd's distribution
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13445
diff
changeset
|
669 |
/// This test terminates almost surely. |
13444
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
670 |
#[test] |
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
671 |
fn test_handle_rnd_nonempty() { |
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
672 |
run_handle_test(vec!["A".to_owned(), "B".to_owned(), "C".to_owned()]) |
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
673 |
} |
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
diff
changeset
|
674 |
} |