From 4b82fdb63a29d8c81fcf7c8c006766b7d0a91833 Mon Sep 17 00:00:00 2001 From: Gunter Labes Date: Sun, 27 Apr 2008 06:13:02 +0000 Subject: [PATCH] abort games with more than MAX_PLAYERS sides --- src/server/game.cpp | 2 +- src/server/server.cpp | 31 ++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/server/game.cpp b/src/server/game.cpp index 4902f8b197b..067c1f3aaaa 100644 --- a/src/server/game.cpp +++ b/src/server/game.cpp @@ -841,7 +841,7 @@ bool game::end_turn() { turn_ended = true; } // Skip over empty sides. - for (int i = 0; i < nsides_ && side_controllers_[current_side()] == "null"; ++i) { + for (int i = 0; i < nsides_ && nsides_ <= gamemap::MAX_PLAYERS && side_controllers_[current_side()] == "null"; ++i) { ++end_turn_; if (current_side() == 0) { turn_ended = true; diff --git a/src/server/server.cpp b/src/server/server.cpp index fb5cecf7b07..af86516e047 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -20,6 +20,7 @@ #include "../config.hpp" #include "../game_config.hpp" #include "../log.hpp" +#include "../map.hpp" // gamemap::MAX_PLAYERS #include "../network.hpp" #include "../filesystem.hpp" #include "../serialization/parser.hpp" @@ -1206,15 +1207,26 @@ void server::process_data_game(const network::connection sock, if (!g->is_owner(sock)) { return; } - - const bool is_init = g->level_init(); + size_t nsides = 0; + const simple_wml::node::child_list& sides = data.root().children("side"); + for (simple_wml::node::child_list::const_iterator s = sides.begin(); s != sides.end(); ++s) { + ++nsides; + } + if (nsides > gamemap::MAX_PLAYERS) { + delete_game(itor); + std::stringstream msg; + msg << "This server does not support games with more than " + << gamemap::MAX_PLAYERS << " sides."; + lobby_.send_server_message(msg.str().c_str(), sock); + return; + } // If this game is having its level data initialized // for the first time, and is ready for players to join. // We should currently have a summary of the game in g->level(). // We want to move this summary to the games_and_users_list_, and // place a pointer to that summary in the game's description. // g->level() should then receive the full data for the game. - if (!is_init) { + if (!g->level_init()) { LOG_SERVER << network::ip_address(sock) << "\t" << pl->second.name() << "\tcreated game:\t\"" << g->name() << "\" (" << g->id() << ").\n"; @@ -1307,6 +1319,19 @@ void server::process_data_game(const network::connection sock, << ") while the scenario is not yet initialized."; return; } + size_t nsides = 0; + const simple_wml::node::child_list& sides = data.root().children("side"); + for (simple_wml::node::child_list::const_iterator s = sides.begin(); s != sides.end(); ++s) { + ++nsides; + } + if (nsides > gamemap::MAX_PLAYERS) { + delete_game(itor); + std::stringstream msg; + msg << "This server does not support games with more than " + << gamemap::MAX_PLAYERS << " sides."; + lobby_.send_server_message(msg.str().c_str(), sock); + return; + } const simple_wml::node& s = *data.child("store_next_scenario"); // Record the full scenario in g->level() g->level().clear();