author | alfadur <mail@none> |
Mon, 23 Dec 2019 23:47:06 +0300 | |
changeset 15523 | f4f6060b536c |
parent 15522 | 4a0b06b03199 |
child 15525 | 16d3c9acd715 |
permissions | -rw-r--r-- |
15482 | 1 |
use super::{common::rnd_reply, strings::*}; |
15519
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
2 |
use crate::core::room::GameInfo; |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
3 |
use crate::core::server::{AddTeamError, SetTeamCountError}; |
13666 | 4 |
use crate::{ |
15074 | 5 |
core::{ |
15075 | 6 |
room::{HwRoom, RoomFlags, MAX_TEAMS_IN_ROOM}, |
15492 | 7 |
server::{ |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
8 |
ChangeMasterError, ChangeMasterResult, HwRoomControl, LeaveRoomResult, ModifyTeamError, |
15518 | 9 |
StartGameError, |
15492 | 10 |
}, |
15074 | 11 |
types, |
12 |
types::{ClientId, GameCfg, RoomId, VoteType, Voting, MAX_HEDGEHOGS_PER_TEAM}, |
|
15075 | 13 |
}, |
14 |
protocol::messages::{ |
|
15 |
add_flags, remove_flags, server_chat, HwProtocolMessage, HwServerMessage::*, |
|
16 |
ProtocolFlags as Flags, |
|
13666 | 17 |
}, |
15482 | 18 |
utils::{is_name_illegal, to_engine_msg}, |
13416 | 19 |
}; |
14457 | 20 |
use base64::{decode, encode}; |
13805 | 21 |
use log::*; |
15026 | 22 |
use std::{cmp::min, iter::once, mem::swap}; |
13423 | 23 |
|
24 |
#[derive(Clone)] |
|
25 |
struct ByMsg<'a> { |
|
14457 | 26 |
messages: &'a [u8], |
13423 | 27 |
} |
28 |
||
14457 | 29 |
impl<'a> Iterator for ByMsg<'a> { |
30 |
type Item = &'a [u8]; |
|
13423 | 31 |
|
32 |
fn next(&mut self) -> Option<<Self as Iterator>::Item> { |
|
33 |
if let Some(size) = self.messages.get(0) { |
|
34 |
let (msg, next) = self.messages.split_at(*size as usize + 1); |
|
35 |
self.messages = next; |
|
36 |
Some(msg) |
|
37 |
} else { |
|
38 |
None |
|
39 |
} |
|
40 |
} |
|
41 |
} |
|
42 |
||
13524 | 43 |
fn by_msg(source: &[u8]) -> ByMsg { |
14457 | 44 |
ByMsg { messages: source } |
13423 | 45 |
} |
46 |
||
47 |
const VALID_MESSAGES: &[u8] = |
|
48 |
b"M#+LlRrUuDdZzAaSjJ,NpPwtgfhbc12345\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A"; |
|
49 |
const NON_TIMED_MESSAGES: &[u8] = b"M#hb"; |
|
50 |
||
15482 | 51 |
/*#[cfg(canhazslicepatterns)] |
13423 | 52 |
fn is_msg_valid(msg: &[u8], team_indices: &[u8]) -> bool { |
13424 | 53 |
match msg { |
15326 | 54 |
[size, typ, body..MAX] => { |
14457 | 55 |
VALID_MESSAGES.contains(typ) |
56 |
&& match body { |
|
15439 | 57 |
[1..=MAX_HEDGEHOGS_PER_TEAM, team, ..] if *typ == b'h' => { |
14457 | 58 |
team_indices.contains(team) |
59 |
} |
|
60 |
_ => *typ != b'h', |
|
61 |
} |
|
62 |
} |
|
63 |
_ => false, |
|
13423 | 64 |
} |
15482 | 65 |
}*/ |
13423 | 66 |
|
13666 | 67 |
fn is_msg_valid(msg: &[u8], _team_indices: &[u8]) -> bool { |
13429 | 68 |
if let Some(typ) = msg.get(1) { |
69 |
VALID_MESSAGES.contains(typ) |
|
70 |
} else { |
|
71 |
false |
|
72 |
} |
|
73 |
} |
|
74 |
||
13423 | 75 |
fn is_msg_empty(msg: &[u8]) -> bool { |
13429 | 76 |
msg.get(1).filter(|t| **t == b'+').is_some() |
13423 | 77 |
} |
12147 | 78 |
|
13443 | 79 |
fn is_msg_timed(msg: &[u8]) -> bool { |
14457 | 80 |
msg.get(1) |
81 |
.filter(|t| !NON_TIMED_MESSAGES.contains(t)) |
|
82 |
.is_some() |
|
13443 | 83 |
} |
84 |
||
13480 | 85 |
fn voting_description(kind: &VoteType) -> String { |
14457 | 86 |
format!( |
87 |
"New voting started: {}", |
|
88 |
match kind { |
|
89 |
VoteType::Kick(nick) => format!("kick {}", nick), |
|
90 |
VoteType::Map(name) => format!("map {}", name.as_ref().unwrap()), |
|
91 |
VoteType::Pause => "pause".to_string(), |
|
92 |
VoteType::NewSeed => "new seed".to_string(), |
|
93 |
VoteType::HedgehogsPerTeam(number) => format!("hedgehogs per team: {}", number), |
|
94 |
} |
|
95 |
) |
|
13480 | 96 |
} |
97 |
||
15075 | 98 |
fn room_message_flag(msg: &HwProtocolMessage) -> RoomFlags { |
99 |
use crate::protocol::messages::HwProtocolMessage::*; |
|
13523 | 100 |
match msg { |
101 |
ToggleRestrictJoin => RoomFlags::RESTRICTED_JOIN, |
|
102 |
ToggleRestrictTeams => RoomFlags::RESTRICTED_TEAM_ADD, |
|
103 |
ToggleRegisteredOnly => RoomFlags::RESTRICTED_UNREGISTERED_PLAYERS, |
|
14457 | 104 |
_ => RoomFlags::empty(), |
13523 | 105 |
} |
106 |
} |
|
107 |
||
14457 | 108 |
pub fn handle( |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
109 |
mut room_control: HwRoomControl, |
14671
455865ccd36c
Server action refactoring part 2 of N
alfadur <mail@none>
parents:
14457
diff
changeset
|
110 |
response: &mut super::Response, |
15075 | 111 |
message: HwProtocolMessage, |
14457 | 112 |
) { |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
113 |
let (client, room) = room_control.get(); |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
114 |
let (client_id, room_id) = (client.id, room.id); |
14697 | 115 |
|
15075 | 116 |
use crate::protocol::messages::HwProtocolMessage::*; |
12147 | 117 |
match message { |
14675
dfe652c53470
Server action refactoring part 6 of N
alfadur <mail@none>
parents:
14671
diff
changeset
|
118 |
Part(msg) => { |
14697 | 119 |
let msg = match msg { |
120 |
Some(s) => format!("part: {}", s), |
|
121 |
None => "part".to_string(), |
|
122 |
}; |
|
15482 | 123 |
|
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
124 |
let result = room_control.leave_room(); |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
125 |
super::common::get_room_leave_result( |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
126 |
room_control.server(), |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
127 |
room_control.room(), |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
128 |
&msg, |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
129 |
result, |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
130 |
response, |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
131 |
); |
14683
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
132 |
} |
13416 | 133 |
Chat(msg) => { |
14683
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
134 |
response.add( |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
135 |
ChatMsg { |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
136 |
nick: client.nick.clone(), |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
137 |
msg, |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
138 |
} |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
139 |
.send_all() |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
140 |
.in_room(room_id), |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
141 |
); |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
142 |
} |
14788 | 143 |
TeamChat(msg) => { |
144 |
if let Some(ref info) = room.game_info { |
|
145 |
if let Some(clan_color) = room.find_team_color(client_id) { |
|
146 |
let engine_msg = |
|
147 |
to_engine_msg(format!("b{}]{}\x20\x20", client.nick, msg).bytes()); |
|
148 |
let team = room.clan_team_owners(clan_color).collect(); |
|
149 |
response.add(ForwardEngineMessage(vec![engine_msg]).send_many(team)) |
|
150 |
} |
|
151 |
} |
|
152 |
} |
|
13477 | 153 |
Fix => { |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
154 |
if let Err(_) = room_control.fix_room() { |
15492 | 155 |
response.warn(ACCESS_DENIED) |
13477 | 156 |
} |
157 |
} |
|
158 |
Unfix => { |
|
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
159 |
if let Err(_) = room_control.unfix_room() { |
15492 | 160 |
response.warn(ACCESS_DENIED) |
13477 | 161 |
} |
162 |
} |
|
163 |
Greeting(text) => { |
|
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
164 |
if let Err(_) = room_control.set_room_greeting(text) { |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
165 |
response.warn(ACCESS_DENIED) |
13477 | 166 |
} |
167 |
} |
|
14788 | 168 |
MaxTeams(count) => { |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
169 |
use crate::core::server::SetTeamCountError; |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
170 |
match room_control.set_room_max_teams(count) { |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
171 |
Ok(()) => {} |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
172 |
Err(SetTeamCountError::NotMaster) => response.warn(NOT_MASTER), |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
173 |
Err(SetTeamCountError::InvalidNumber) => { |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
174 |
response.warn("/maxteams: specify number from 2 to 8") |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
175 |
} |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
176 |
}; |
14788 | 177 |
} |
13416 | 178 |
RoomName(new_name) => { |
15518 | 179 |
use crate::core::server::ModifyRoomNameError; |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
180 |
match room_control.set_room_name(new_name) { |
15518 | 181 |
Ok(old_name) => { |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
182 |
let (client, room) = room_control.get(); |
15518 | 183 |
super::common::get_room_update(Some(old_name), room, Some(client), response) |
14688
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14687
diff
changeset
|
184 |
} |
15518 | 185 |
Err(ModifyRoomNameError::AccessDenied) => response.warn(ACCESS_DENIED), |
186 |
Err(ModifyRoomNameError::InvalidName) => response.warn(ILLEGAL_ROOM_NAME), |
|
187 |
Err(ModifyRoomNameError::DuplicateName) => response.warn(ROOM_EXISTS), |
|
14688
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14687
diff
changeset
|
188 |
} |
14683
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
189 |
} |
13419 | 190 |
ToggleReady => { |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
191 |
let flags = if room_control.toggle_ready() { |
15518 | 192 |
add_flags(&[Flags::Ready]) |
14697 | 193 |
} else { |
15518 | 194 |
remove_flags(&[Flags::Ready]) |
14697 | 195 |
}; |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
196 |
let (client, room) = room_control.get(); |
13801 | 197 |
|
14697 | 198 |
let msg = if client.protocol_number < 38 { |
199 |
LegacyReady(client.is_ready(), vec![client.nick.clone()]) |
|
200 |
} else { |
|
14782 | 201 |
ClientFlags(flags, vec![client.nick.clone()]) |
14697 | 202 |
}; |
15518 | 203 |
response.add(msg.send_all().in_room(room_id)); |
14691 | 204 |
|
14697 | 205 |
if room.is_fixed() && room.ready_players_number == room.players_number { |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
206 |
let result = room_control.start_game(); |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
207 |
super::common::get_start_game_data( |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
208 |
room_control.server(), |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
209 |
room_id, |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
210 |
result, |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
211 |
response, |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
212 |
); |
13666 | 213 |
} |
13416 | 214 |
} |
15519
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
215 |
AddTeam(info) => { |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
216 |
use crate::core::server::AddTeamError; |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
217 |
match room_control.add_team(info) { |
15519
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
218 |
Ok(team) => { |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
219 |
response.add(TeamAccepted(team.name.clone()).send_self()); |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
220 |
response.add( |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
221 |
TeamAdd(team.to_protocol()) |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
222 |
.send_all() |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
223 |
.in_room(room_id) |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
224 |
.but_self(), |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
225 |
); |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
226 |
response.add( |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
227 |
TeamColor(team.name.clone(), team.color) |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
228 |
.send_all() |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
229 |
.in_room(room_id), |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
230 |
); |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
231 |
response.add( |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
232 |
HedgehogsNumber(team.name.clone(), team.hedgehogs_number) |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
233 |
.send_all() |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
234 |
.in_room(room_id), |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
235 |
); |
14688
4569d8d50286
Server action refactoring part B of N
alfadur <mail@none>
parents:
14687
diff
changeset
|
236 |
|
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
237 |
let room = room_control.room(); |
15519
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
238 |
let room_master = if let Some(id) = room.master_id { |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
239 |
Some(room_control.server().client(id)) |
15519
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
240 |
} else { |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
241 |
None |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
242 |
}; |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
243 |
super::common::get_room_update(None, room, room_master, response); |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
244 |
} |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
245 |
Err(AddTeamError::TooManyTeams) => response.warn(TOO_MANY_TEAMS), |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
246 |
Err(AddTeamError::TooManyHedgehogs) => response.warn(TOO_MANY_HEDGEHOGS), |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
247 |
Err(AddTeamError::TeamAlreadyExists) => response.warn(TEAM_EXISTS), |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
248 |
Err(AddTeamError::GameInProgress) => response.warn(ROUND_IN_PROGRESS), |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
249 |
Err(AddTeamError::Restricted) => response.warn(TEAM_ADD_RESTRICTED), |
13419 | 250 |
} |
14683
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
251 |
} |
15519
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
252 |
RemoveTeam(name) => { |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
253 |
use crate::core::server::RemoveTeamError; |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
254 |
match room_control.remove_team(&name) { |
15519
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
255 |
Ok(()) => { |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
256 |
let (client, room) = room_control.get(); |
15519
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
257 |
|
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
258 |
let removed_teams = vec![name]; |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
259 |
super::common::get_remove_teams_data( |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
260 |
room_id, |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
261 |
client.is_in_game(), |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
262 |
removed_teams, |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
263 |
response, |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
264 |
); |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
265 |
|
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
266 |
match room.game_info { |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
267 |
Some(ref info) if info.teams_in_game == 0 => { |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
268 |
if let Some(result) = room_control.end_game() { |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
269 |
super::common::get_end_game_result( |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
270 |
room_control.server(), |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
271 |
room_id, |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
272 |
result, |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
273 |
response, |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
274 |
); |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
275 |
} |
15519
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
276 |
} |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
277 |
_ => (), |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
278 |
} |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
279 |
} |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
280 |
Err(RemoveTeamError::NoTeam) => response.warn(NO_TEAM_TO_REMOVE), |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
281 |
Err(RemoveTeamError::TeamNotOwned) => response.warn(TEAM_NOT_OWNED), |
15482 | 282 |
} |
15519
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
283 |
} |
13419 | 284 |
SetHedgehogsNumber(team_name, number) => { |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
285 |
use crate::core::server::SetHedgehogsError; |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
286 |
match room_control.set_team_hedgehogs_number(&team_name, number) { |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
287 |
Ok(()) => { |
14697 | 288 |
response.add( |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
289 |
HedgehogsNumber(team_name.clone(), number) |
14697 | 290 |
.send_all() |
291 |
.in_room(room_id) |
|
292 |
.but_self(), |
|
293 |
); |
|
14676
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14675
diff
changeset
|
294 |
} |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
295 |
Err(SetHedgehogsError::NotMaster) => response.error(NOT_MASTER), |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
296 |
Err(SetHedgehogsError::NoTeam) => response.warn(NO_TEAM), |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
297 |
Err(SetHedgehogsError::InvalidNumber(previous_number)) => { |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
298 |
response.add(HedgehogsNumber(team_name.clone(), previous_number).send_self()) |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
299 |
} |
14676
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14675
diff
changeset
|
300 |
} |
14683
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
301 |
} |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
302 |
SetTeamColor(team_name, color) => match room_control.set_team_color(&team_name, color) { |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
303 |
Ok(()) => response.add( |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
304 |
TeamColor(team_name, color) |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
305 |
.send_all() |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
306 |
.in_room(room_id) |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
307 |
.but_self(), |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
308 |
), |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
309 |
Err(ModifyTeamError::NoTeam) => response.warn(NO_TEAM), |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
310 |
Err(ModifyTeamError::NotMaster) => response.error(NOT_MASTER), |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
311 |
}, |
13422 | 312 |
Cfg(cfg) => { |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
313 |
use crate::core::server::SetConfigError; |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
314 |
let msg = cfg.to_server_msg(); |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
315 |
match room_control.set_config(cfg) { |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
316 |
Ok(()) => { |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
317 |
response.add(msg.send_all().in_room(room_control.room().id).but_self()); |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
318 |
} |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
319 |
Err(SetConfigError::NotMaster) => response.error(NOT_MASTER), |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
320 |
Err(SetConfigError::RoomFixed) => response.warn(ACCESS_DENIED), |
13666 | 321 |
} |
13419 | 322 |
} |
13528 | 323 |
Save(name, location) => { |
14683
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
324 |
response.add( |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
325 |
server_chat(format!("Room config saved as {}", name)) |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
326 |
.send_all() |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
327 |
.in_room(room_id), |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
328 |
); |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
329 |
room_control.save_config(name, location); |
13528 | 330 |
} |
14785
a1077e8d26f4
implement watch message apart from replay deserializing
alfadur
parents:
14784
diff
changeset
|
331 |
#[cfg(feature = "official-server")] |
13529 | 332 |
SaveRoom(filename) => { |
14697 | 333 |
if client.is_admin() { |
334 |
match room.get_saves() { |
|
14781 | 335 |
Ok(contents) => response.request_io(super::IoTask::SaveRoom { |
336 |
room_id, |
|
337 |
filename, |
|
338 |
contents, |
|
339 |
}), |
|
13529 | 340 |
Err(e) => { |
341 |
warn!("Error while serializing the room configs: {}", e); |
|
15482 | 342 |
response.warn("Unable to serialize the room configs.") |
13529 | 343 |
} |
14676
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14675
diff
changeset
|
344 |
} |
13666 | 345 |
} |
13529 | 346 |
} |
14785
a1077e8d26f4
implement watch message apart from replay deserializing
alfadur
parents:
14784
diff
changeset
|
347 |
#[cfg(feature = "official-server")] |
13529 | 348 |
LoadRoom(filename) => { |
14697 | 349 |
if client.is_admin() { |
14781 | 350 |
response.request_io(super::IoTask::LoadRoom { room_id, filename }); |
13666 | 351 |
} |
13529 | 352 |
} |
13528 | 353 |
Delete(name) => { |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
354 |
if !room_control.delete_config(&name) { |
14676
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14675
diff
changeset
|
355 |
response.add(Warning(format!("Save doesn't exist: {}", name)).send_self()); |
13528 | 356 |
} else { |
14683
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
357 |
response.add( |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
358 |
server_chat(format!("Room config {} has been deleted", name)) |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
359 |
.send_all() |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
360 |
.in_room(room_id), |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
361 |
); |
14676
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14675
diff
changeset
|
362 |
} |
13528 | 363 |
} |
13478 | 364 |
CallVote(None) => { |
14676
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14675
diff
changeset
|
365 |
response.add(server_chat("Available callvote commands: kick <nickname>, map <name>, pause, newseed, hedgehogs <number>".to_string()) |
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14675
diff
changeset
|
366 |
.send_self()); |
13478 | 367 |
} |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
368 |
/*CallVote(Some(kind)) => { |
14697 | 369 |
let is_in_game = room.game_info.is_some(); |
13478 | 370 |
let error = match &kind { |
371 |
VoteType::Kick(nick) => { |
|
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
372 |
if room_control.server() |
14683
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
373 |
.find_client(&nick) |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
374 |
.filter(|c| c.room_id == Some(room_id)) |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
375 |
.is_some() |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
376 |
{ |
13478 | 377 |
None |
378 |
} else { |
|
13527 | 379 |
Some("/callvote kick: No such user!".to_string()) |
13478 | 380 |
} |
14683
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
381 |
} |
13478 | 382 |
VoteType::Map(None) => { |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
383 |
let names: Vec<_> = room.saves.keys().cloned().collect(); |
13527 | 384 |
if names.is_empty() { |
385 |
Some("/callvote map: No maps saved in this room!".to_string()) |
|
386 |
} else { |
|
387 |
Some(format!("Available maps: {}", names.join(", "))) |
|
388 |
} |
|
14683
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
389 |
} |
13478 | 390 |
VoteType::Map(Some(name)) => { |
14697 | 391 |
if room.saves.get(&name[..]).is_some() { |
13530 | 392 |
None |
13527 | 393 |
} else { |
13530 | 394 |
Some("/callvote map: No such map!".to_string()) |
13527 | 395 |
} |
14683
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
396 |
} |
13478 | 397 |
VoteType::Pause => { |
398 |
if is_in_game { |
|
399 |
None |
|
400 |
} else { |
|
13527 | 401 |
Some("/callvote pause: No game in progress!".to_string()) |
13478 | 402 |
} |
14683
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
403 |
} |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
404 |
VoteType::NewSeed => None, |
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
405 |
VoteType::HedgehogsPerTeam(number) => match number { |
15439 | 406 |
1..=MAX_HEDGEHOGS_PER_TEAM => None, |
14683
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
407 |
_ => Some("/callvote hedgehogs: Specify number from 1 to 8.".to_string()), |
13478 | 408 |
}, |
409 |
}; |
|
14697 | 410 |
|
13478 | 411 |
match error { |
412 |
None => { |
|
13480 | 413 |
let msg = voting_description(&kind); |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
414 |
let voting = Voting::new(kind, room_control.server().room_clients(client_id).collect()); |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
415 |
let room = room_control.server().room_mut(room_id); |
14686
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14683
diff
changeset
|
416 |
room.voting = Some(voting); |
14676
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14675
diff
changeset
|
417 |
response.add(server_chat(msg).send_all().in_room(room_id)); |
14687
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14686
diff
changeset
|
418 |
super::common::submit_vote( |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
419 |
room_control.server(), |
15074 | 420 |
types::Vote { |
14687
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14686
diff
changeset
|
421 |
is_pro: true, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14686
diff
changeset
|
422 |
is_forced: false, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14686
diff
changeset
|
423 |
}, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14686
diff
changeset
|
424 |
response, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14686
diff
changeset
|
425 |
); |
13478 | 426 |
} |
427 |
Some(msg) => { |
|
14676
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14675
diff
changeset
|
428 |
response.add(server_chat(msg).send_self()); |
13478 | 429 |
} |
430 |
} |
|
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
431 |
}*/ |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
432 |
/*Vote(vote) => { |
14687
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14686
diff
changeset
|
433 |
super::common::submit_vote( |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
434 |
room_control.server(), |
15074 | 435 |
types::Vote { |
14687
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14686
diff
changeset
|
436 |
is_pro: vote, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14686
diff
changeset
|
437 |
is_forced: false, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14686
diff
changeset
|
438 |
}, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14686
diff
changeset
|
439 |
response, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14686
diff
changeset
|
440 |
); |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
441 |
}*/ |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
442 |
/*ForceVote(vote) => { |
14697 | 443 |
let is_forced = client.is_admin(); |
14687
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14686
diff
changeset
|
444 |
super::common::submit_vote( |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
445 |
room_control.server(), |
15074 | 446 |
types::Vote { |
14687
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14686
diff
changeset
|
447 |
is_pro: vote, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14686
diff
changeset
|
448 |
is_forced, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14686
diff
changeset
|
449 |
}, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14686
diff
changeset
|
450 |
response, |
5122c584804e
Server action refactoring part A of N
alfadur <mail@none>
parents:
14686
diff
changeset
|
451 |
); |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
452 |
}*/ |
14683
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
453 |
ToggleRestrictJoin | ToggleRestrictTeams | ToggleRegisteredOnly => { |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
454 |
if room_control.toggle_flag(room_message_flag(&message)) { |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
455 |
let (client, room) = room_control.get(); |
14686
9f98086de1b6
Server action refactoring part 9 of N
alfadur <mail@none>
parents:
14683
diff
changeset
|
456 |
super::common::get_room_update(None, room, Some(&client), response); |
13523 | 457 |
} |
458 |
} |
|
13423 | 459 |
StartGame => { |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
460 |
let result = room_control.start_game(); |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
461 |
super::common::get_start_game_data(room_control.server(), room_id, result, response); |
13423 | 462 |
} |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
463 |
/*EngineMessage(em) => { |
14697 | 464 |
if client.teams_in_game > 0 { |
465 |
let decoding = decode(&em[..]).unwrap(); |
|
466 |
let messages = by_msg(&decoding); |
|
467 |
let valid = messages.filter(|m| is_msg_valid(m, &client.team_indices)); |
|
468 |
let non_empty = valid.clone().filter(|m| !is_msg_empty(m)); |
|
469 |
let sync_msg = valid.clone().filter(|m| is_msg_timed(m)).last().map(|m| { |
|
470 |
if is_msg_empty(m) { |
|
471 |
Some(encode(m)) |
|
472 |
} else { |
|
473 |
None |
|
474 |
} |
|
475 |
}); |
|
13423 | 476 |
|
14697 | 477 |
let em_response = encode(&valid.flat_map(|msg| msg).cloned().collect::<Vec<_>>()); |
478 |
if !em_response.is_empty() { |
|
479 |
response.add( |
|
480 |
ForwardEngineMessage(vec![em_response]) |
|
481 |
.send_all() |
|
482 |
.in_room(room.id) |
|
483 |
.but_self(), |
|
484 |
); |
|
485 |
} |
|
486 |
let em_log = encode(&non_empty.flat_map(|msg| msg).cloned().collect::<Vec<_>>()); |
|
487 |
if let Some(ref mut info) = room.game_info { |
|
488 |
if !em_log.is_empty() { |
|
489 |
info.msg_log.push(em_log); |
|
13423 | 490 |
} |
14697 | 491 |
if let Some(msg) = sync_msg { |
492 |
info.sync_msg = msg; |
|
13427 | 493 |
} |
13423 | 494 |
} |
495 |
} |
|
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
496 |
}*/ |
13423 | 497 |
RoundFinished => { |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
498 |
if let Some(team_names) = room_control.leave_game() { |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
499 |
let (client, room) = room_control.get(); |
14689
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14688
diff
changeset
|
500 |
response.add( |
14782 | 501 |
ClientFlags(remove_flags(&[Flags::InGame]), vec![client.nick.clone()]) |
14689
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14688
diff
changeset
|
502 |
.send_all() |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14688
diff
changeset
|
503 |
.in_room(room.id), |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14688
diff
changeset
|
504 |
); |
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14688
diff
changeset
|
505 |
|
15519
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
506 |
for team_name in team_names { |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
507 |
let msg = once(b'F').chain(team_name.bytes()); |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
508 |
response.add( |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
509 |
ForwardEngineMessage(vec![to_engine_msg(msg)]) |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
510 |
.send_all() |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
511 |
.in_room(room_id) |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
512 |
.but_self(), |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
513 |
); |
13423 | 514 |
} |
15519
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
515 |
|
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
516 |
if let Some(GameInfo { |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
517 |
teams_in_game: 0, .. |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
518 |
}) = room.game_info |
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
519 |
{ |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
520 |
if let Some(result) = room_control.end_game() { |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
521 |
super::common::get_end_game_result( |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
522 |
room_control.server(), |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
523 |
room_id, |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
524 |
result, |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
525 |
response, |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
526 |
); |
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
527 |
} |
15519
b3157d218ae2
disallow mutable clients to leave the server
alfadur <mail@none>
parents:
15518
diff
changeset
|
528 |
} |
14689
aae29ba56aec
Server action refactoring part C of N
alfadur <mail@none>
parents:
14688
diff
changeset
|
529 |
} |
14683
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
530 |
} |
13445
d3c86ade3d4d
Send the rnd reply to the room only.
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13444
diff
changeset
|
531 |
Rnd(v) => { |
13521 | 532 |
let result = rnd_reply(&v); |
533 |
let mut echo = vec!["/rnd".to_string()]; |
|
534 |
echo.extend(v.into_iter()); |
|
535 |
let chat_msg = ChatMsg { |
|
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
536 |
nick: client.nick.clone(), |
14683
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
537 |
msg: echo.join(" "), |
13521 | 538 |
}; |
14676
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14675
diff
changeset
|
539 |
response.add(chat_msg.send_all().in_room(room_id)); |
9377ee00f1f1
Server action refactoring part 7 of N
alfadur <mail@none>
parents:
14675
diff
changeset
|
540 |
response.add(result.send_all().in_room(room_id)); |
14683
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
541 |
} |
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
542 |
Delegate(nick) => match room_control.change_master(nick) { |
15487 | 543 |
Ok(ChangeMasterResult { |
544 |
old_master_id, |
|
545 |
new_master_id, |
|
546 |
}) => { |
|
547 |
if let Some(master_id) = old_master_id { |
|
548 |
response.add( |
|
549 |
ClientFlags( |
|
550 |
remove_flags(&[Flags::RoomMaster]), |
|
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
551 |
vec![room_control.server().client(master_id).nick.clone()], |
15487 | 552 |
) |
553 |
.send_all() |
|
554 |
.in_room(room_id), |
|
555 |
); |
|
556 |
} |
|
557 |
response.add( |
|
558 |
ClientFlags( |
|
559 |
add_flags(&[Flags::RoomMaster]), |
|
15523
f4f6060b536c
add a separate interface for modifying room state
alfadur <mail@none>
parents:
15522
diff
changeset
|
560 |
vec![room_control.server().client(new_master_id).nick.clone()], |
15487 | 561 |
) |
562 |
.send_all() |
|
563 |
.in_room(room_id), |
|
564 |
); |
|
565 |
} |
|
566 |
Err(ChangeMasterError::NoAccess) => { |
|
15482 | 567 |
response.warn("You're not the room master or a server admin!") |
15487 | 568 |
} |
569 |
Err(ChangeMasterError::AlreadyMaster) => { |
|
570 |
response.warn("You're already the room master.") |
|
14784 | 571 |
} |
15487 | 572 |
Err(ChangeMasterError::NoClient) => response.warn("Player is not online."), |
573 |
Err(ChangeMasterError::ClientNotInRoom) => { |
|
574 |
response.warn("The player is not in your room.") |
|
575 |
} |
|
576 |
}, |
|
14683
932ff7683653
Server action refactoring part 8 of N
alfadur <mail@none>
parents:
14676
diff
changeset
|
577 |
_ => warn!("Unimplemented!"), |
12147 | 578 |
} |
579 |
} |