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