1 use super::{common::rnd_reply, strings::*}; |
1 use super::{common::rnd_reply, strings::*}; |
2 use crate::{ |
2 use crate::{ |
3 core::{ |
3 core::{ |
4 room::{HwRoom, RoomFlags, MAX_TEAMS_IN_ROOM}, |
4 room::{HwRoom, RoomFlags, MAX_TEAMS_IN_ROOM}, |
5 server::{ChangeMasterError, ChangeMasterResult, HwServer, LeaveRoomResult}, |
5 server::{ |
|
6 ChangeMasterError, ChangeMasterResult, HwServer, LeaveRoomResult, StartGameError, |
|
7 }, |
6 types, |
8 types, |
7 types::{ClientId, GameCfg, RoomId, VoteType, Voting, MAX_HEDGEHOGS_PER_TEAM}, |
9 types::{ClientId, GameCfg, RoomId, VoteType, Voting, MAX_HEDGEHOGS_PER_TEAM}, |
8 }, |
10 }, |
9 protocol::messages::{ |
11 protocol::messages::{ |
10 add_flags, remove_flags, server_chat, HwProtocolMessage, HwServerMessage::*, |
12 add_flags, remove_flags, server_chat, HwProtocolMessage, HwServerMessage::*, |
115 let msg = match msg { |
117 let msg = match msg { |
116 Some(s) => format!("part: {}", s), |
118 Some(s) => format!("part: {}", s), |
117 None => "part".to_string(), |
119 None => "part".to_string(), |
118 }; |
120 }; |
119 |
121 |
120 match server.leave_room(client_id) { |
122 let result = server.leave_room(client_id); |
121 Ok(result) => { |
123 super::common::get_room_leave_data(server, room_id, &msg, result, response); |
122 let room = server.room(room_id); |
|
123 super::common::get_room_leave_data(server, room, &msg, result, response) |
|
124 } |
|
125 Err(_) => (), |
|
126 } |
|
127 } |
124 } |
128 Chat(msg) => { |
125 Chat(msg) => { |
129 response.add( |
126 response.add( |
130 ChatMsg { |
127 ChatMsg { |
131 nick: client.nick.clone(), |
128 nick: client.nick.clone(), |
149 if client.is_admin() { |
146 if client.is_admin() { |
150 room.set_is_fixed(true); |
147 room.set_is_fixed(true); |
151 room.set_join_restriction(false); |
148 room.set_join_restriction(false); |
152 room.set_team_add_restriction(false); |
149 room.set_team_add_restriction(false); |
153 room.set_unregistered_players_restriction(true); |
150 room.set_unregistered_players_restriction(true); |
|
151 } else { |
|
152 response.warn(ACCESS_DENIED) |
154 } |
153 } |
155 } |
154 } |
156 Unfix => { |
155 Unfix => { |
157 if client.is_admin() { |
156 if client.is_admin() { |
158 room.set_is_fixed(false); |
157 room.set_is_fixed(false); |
|
158 } else { |
|
159 response.warn(ACCESS_DENIED) |
159 } |
160 } |
160 } |
161 } |
161 Greeting(text) => { |
162 Greeting(text) => { |
162 if client.is_admin() || client.is_master() && !room.is_fixed() { |
163 if client.is_admin() || client.is_master() && !room.is_fixed() { |
163 room.greeting = text.unwrap_or(String::new()); |
164 room.greeting = text.unwrap_or(String::new()); |
204 }; |
205 }; |
205 response.add(msg.send_all().in_room(room.id)); |
206 response.add(msg.send_all().in_room(room.id)); |
206 client.set_is_ready(!client.is_ready()); |
207 client.set_is_ready(!client.is_ready()); |
207 |
208 |
208 if room.is_fixed() && room.ready_players_number == room.players_number { |
209 if room.is_fixed() && room.ready_players_number == room.players_number { |
209 super::common::start_game(server, room_id, response); |
210 let result = server.start_game(room_id); |
|
211 super::common::get_start_game_data(server, room_id, result, response); |
210 } |
212 } |
211 } |
213 } |
212 AddTeam(mut info) => { |
214 AddTeam(mut info) => { |
213 if room.teams.len() >= room.max_teams as usize { |
215 if room.teams.len() >= room.max_teams as usize { |
214 response.warn("Too many teams!"); |
216 response.warn("Too many teams!"); |
478 room.flags.toggle(room_message_flag(&message)); |
480 room.flags.toggle(room_message_flag(&message)); |
479 super::common::get_room_update(None, room, Some(&client), response); |
481 super::common::get_room_update(None, room, Some(&client), response); |
480 } |
482 } |
481 } |
483 } |
482 StartGame => { |
484 StartGame => { |
483 super::common::start_game(server, room_id, response); |
485 let result = server.start_game(room_id); |
|
486 super::common::get_start_game_data(server, room_id, result, response); |
484 } |
487 } |
485 EngineMessage(em) => { |
488 EngineMessage(em) => { |
486 if client.teams_in_game > 0 { |
489 if client.teams_in_game > 0 { |
487 let decoding = decode(&em[..]).unwrap(); |
490 let decoding = decode(&em[..]).unwrap(); |
488 let messages = by_msg(&decoding); |
491 let messages = by_msg(&decoding); |