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