reconnect some message handlers
authoralfadur <mail@none>
Wed, 06 Feb 2019 22:40:38 +0300
changeset 14712 2071da901c63
parent 14711 f61ce544d436
child 14713 e5415faa117b
reconnect some message handlers
rust/hedgewars-server/src/main.rs
rust/hedgewars-server/src/server/handlers/common.rs
rust/hedgewars-server/src/server/handlers/inroom.rs
--- a/rust/hedgewars-server/src/main.rs	Wed Feb 06 22:29:02 2019 +0300
+++ b/rust/hedgewars-server/src/main.rs	Wed Feb 06 22:40:38 2019 +0300
@@ -1,9 +1,6 @@
 #![allow(unused_imports)]
 #![deny(bare_trait_objects)]
 
-//use std::io::*;
-//use rand::Rng;
-//use std::cmp::Ordering;
 use log::*;
 use mio::net::*;
 use mio::*;
--- a/rust/hedgewars-server/src/server/handlers/common.rs	Wed Feb 06 22:29:02 2019 +0300
+++ b/rust/hedgewars-server/src/server/handlers/common.rs	Wed Feb 06 22:40:38 2019 +0300
@@ -95,6 +95,7 @@
     is_in_game: bool,
     response: &mut Response,
 ) {
+    let mut game_ended = false;
     if let Some(ref mut info) = room.game_info {
         for team_name in &team_names {
             info.left_teams.push(team_name.clone());
@@ -109,9 +110,6 @@
                 );
 
                 info.teams_in_game -= 1;
-                if info.teams_in_game == 0 {
-                    //FinishRoomGame(room.id)
-                }
 
                 let remove_msg = to_engine_msg(once(b'F').chain(team_name.bytes()));
                 if let Some(m) = &info.sync_msg {
--- a/rust/hedgewars-server/src/server/handlers/inroom.rs	Wed Feb 06 22:29:02 2019 +0300
+++ b/rust/hedgewars-server/src/server/handlers/inroom.rs	Wed Feb 06 22:40:38 2019 +0300
@@ -190,11 +190,11 @@
                     ClientFlags(flags.to_string(), vec![client.nick.clone()])
                 };
                 response.add(msg.send_all().in_room(room.id));
+                client.set_is_ready(!client.is_ready());
+
                 if room.is_fixed() && room.ready_players_number == room.players_number {
-                    //StartRoomGame(r.id)
+                    super::common::start_game(server, room_id, response);
                 }
-
-                client.set_is_ready(!client.is_ready());
             }
         }
         AddTeam(info) => {
@@ -249,24 +249,30 @@
             }
         }
         RemoveTeam(name) => {
-            if let (client, Some(room)) = server.client_and_room(client_id) {
-                match room.find_team_owner(&name) {
-                    None => response.add(
-                        Warning("Error: The team you tried to remove does not exist.".to_string())
-                            .send_self(),
-                    ),
-                    Some((id, _)) if id != client_id => response.add(
-                        Warning("You can't remove a team you don't own.".to_string()).send_self(),
-                    ),
-                    Some((_, name)) => {
-                        client.teams_in_game -= 1;
-                        client.clan = room.find_team_color(client.id);
-                        super::common::remove_teams(
-                            room,
-                            vec![name.to_string()],
-                            client.is_in_game(),
-                            response,
-                        );
+            let client = &mut server.clients[client_id];
+            let room = &mut server.rooms[room_id];
+            match room.find_team_owner(&name) {
+                None => response.add(
+                    Warning("Error: The team you tried to remove does not exist.".to_string())
+                        .send_self(),
+                ),
+                Some((id, _)) if id != client_id => response
+                    .add(Warning("You can't remove a team you don't own.".to_string()).send_self()),
+                Some((_, name)) => {
+                    client.teams_in_game -= 1;
+                    client.clan = room.find_team_color(client.id);
+                    super::common::remove_teams(
+                        room,
+                        vec![name.to_string()],
+                        client.is_in_game(),
+                        response,
+                    );
+
+                    match room.game_info {
+                        Some(ref info) if info.teams_in_game == 0 => {
+                            super::common::end_game(server, room_id, response)
+                        }
+                        _ => (),
                     }
                 }
             }
@@ -513,7 +519,7 @@
             }
         }
         StartGame => {
-            // StartRoomGame(room_id);
+            super::common::start_game(server, room_id, response);
         }
         EngineMessage(em) => {
             if let (c, Some(r)) = server.client_and_room(client_id) {