--- a/gameServer2/src/server/actions.rs Fri Jul 06 17:16:01 2018 +0200
+++ b/gameServer2/src/server/actions.rs Fri Jul 06 21:03:03 2018 +0300
@@ -227,6 +227,10 @@
RoomJoined(vec![c.nick.clone()]).send_all().in_room(room_id).action(),
ClientFlags("+i".to_string(), vec![c.nick.clone()]).send_all().action(),
SendRoomUpdate(None)];
+ if !r.greeting.is_empty() {
+ v.push(ChatMsg {nick: "[greeting]".to_string(), msg: r.greeting.clone()}
+ .send_self().action());
+ }
if !c.is_master {
let team_names: Vec<_>;
if let Some(ref mut info) = r.game_info {
@@ -328,23 +332,24 @@
if c.is_ready && r.ready_players_number > 0 {
r.ready_players_number -= 1;
}
- if r.players_number > 0 && c.is_master {
+ if c.is_master && (r.players_number > 0 || r.is_fixed) {
actions.push(ChangeMaster(r.id, None));
}
- actions.push(RemoveClientTeams);
- actions.push(RoomLeft(c.nick.clone(), msg)
- .send_all().in_room(r.id).but_self().action());
actions.push(ClientFlags("-i".to_string(), vec![c.nick.clone()])
.send_all().action());
- actions.push(SendRoomUpdate(Some(r.name.clone())));
}
server.react(client_id, actions);
actions = Vec::new();
if let (c, Some(r)) = server.client_and_room(client_id) {
c.room_id = Some(lobby_id);
- if r.players_number == 0 {
+ if r.players_number == 0 && !r.is_fixed {
actions.push(RemoveRoom(r.id));
+ } else {
+ actions.push(RemoveClientTeams);
+ actions.push(RoomLeft(c.nick.clone(), msg)
+ .send_all().in_room(r.id).but_self().action());
+ actions.push(SendRoomUpdate(Some(r.name.clone())));
}
}
server.react(client_id, actions)
@@ -352,8 +357,12 @@
ChangeMaster(room_id, new_id) => {
let mut actions = Vec::new();
let room_client_ids = server.room_clients(room_id);
- let new_id = new_id.or_else(||
- room_client_ids.iter().find(|id| **id != client_id).map(|id| *id));
+ let new_id = if server.room(client_id).map(|r| r.is_fixed).unwrap_or(false) {
+ new_id
+ } else {
+ new_id.or_else(||
+ room_client_ids.iter().find(|id| **id != client_id).map(|id| *id))
+ };
let new_nick = new_id.map(|id| server.clients[id].nick.clone());
if let (c, Some(r)) = server.client_and_room(client_id) {
--- a/gameServer2/src/server/client.rs Fri Jul 06 17:16:01 2018 +0200
+++ b/gameServer2/src/server/client.rs Fri Jul 06 21:03:03 2018 +0300
@@ -5,6 +5,7 @@
pub room_id: Option<usize>,
pub nick: String,
pub protocol_number: u32,
+ pub is_admin: bool,
pub is_master: bool,
pub is_ready: bool,
pub is_in_game: bool,
@@ -21,6 +22,7 @@
room_id: None,
nick: String::new(),
protocol_number: 0,
+ is_admin: false,
is_master: false,
is_ready: false,
is_in_game: false,
--- a/gameServer2/src/server/handlers/inroom.rs Fri Jul 06 17:16:01 2018 +0200
+++ b/gameServer2/src/server/handlers/inroom.rs Fri Jul 06 21:03:03 2018 +0300
@@ -89,10 +89,29 @@
};
server.react(client_id, actions);
},
+ Fix => {
+ if let (c, Some(r)) = server.client_and_room(client_id) {
+ if c.is_admin { r.is_fixed = true }
+ }
+ }
+ Unfix => {
+ if let (c, Some(r)) = server.client_and_room(client_id) {
+ if c.is_admin { r.is_fixed = false }
+ }
+ }
+ Greeting(text) => {
+ if let (c, Some(r)) = server.client_and_room(client_id) {
+ if c.is_admin || c.is_master && !r.is_fixed {
+ r.greeting = text
+ }
+ }
+ }
RoomName(new_name) => {
let actions =
if is_name_illegal(&new_name) {
vec![Warn("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())]
+ } else if server.room(client_id).map(|r| r.is_fixed).unwrap_or(false) {
+ vec![Warn("Access denied.".to_string())]
} else if server.has_room(&new_name) {
vec![Warn("A room with the same name already exists.".to_string())]
} else {
@@ -116,8 +135,13 @@
"+r"
};
c.is_ready = !c.is_ready;
- vec![ClientFlags(flags.to_string(), vec![c.nick.clone()])
- .send_all().in_room(r.id).action()]
+ let mut v =
+ vec![ClientFlags(flags.to_string(), vec![c.nick.clone()])
+ .send_all().in_room(r.id).action()];
+ if r.is_fixed && r.ready_players_number as u32 == r.players_number {
+ v.push(StartRoomGame(r.id))
+ }
+ v
} else {
Vec::new()
};
@@ -223,7 +247,9 @@
},
Cfg(cfg) => {
let actions = if let (c, Some(r)) = server.client_and_room(client_id) {
- if !c.is_master {
+ if r.is_fixed {
+ vec![Warn("Access denied.".to_string())]
+ } else if !c.is_master {
vec![ProtocolError("You're not the room master!".to_string())]
} else {
let v = vec![cfg.to_server_msg()
--- a/gameServer2/src/server/room.rs Fri Jul 06 17:16:01 2018 +0200
+++ b/gameServer2/src/server/room.rs Fri Jul 06 21:03:03 2018 +0300
@@ -113,6 +113,8 @@
pub name: String,
pub password: Option<String>,
pub protocol_number: u32,
+ pub greeting: String,
+ pub is_fixed: bool,
pub players_number: u32,
pub default_hedgehog_number: u8,
@@ -130,6 +132,8 @@
master_id: None,
name: String::new(),
password: None,
+ greeting: "".to_string(),
+ is_fixed: false,
protocol_number: 0,
players_number: 0,
default_hedgehog_number: 4,