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