abort games with more than MAX_PLAYERS sides

This commit is contained in:
Gunter Labes 2008-04-27 06:14:45 +00:00
parent c545f4df6a
commit b6d132ac7c
2 changed files with 29 additions and 4 deletions

View file

@ -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;

View file

@ -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"
@ -1210,15 +1211,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";
@ -1308,6 +1320,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();