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