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