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