Author: soliton
Date: Sun Apr 27 08:13:02 2008
New Revision: 26160

URL: http://svn.gna.org/viewcvs/wesnoth?rev=26160&view=rev
Log:
* abort games with more than MAX_PLAYERS sides

Modified:
    trunk/src/server/game.cpp
    trunk/src/server/server.cpp

Modified: trunk/src/server/game.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/server/game.cpp?rev=26160&r1=26159&r2=26160&view=diff
==============================================================================
--- trunk/src/server/game.cpp (original)
+++ trunk/src/server/game.cpp Sun Apr 27 08:13:02 2008
@@ -841,7 +841,7 @@
                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;

Modified: trunk/src/server/server.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/server/server.cpp?rev=26160&r1=26159&r2=26160&view=diff
==============================================================================
--- trunk/src/server/server.cpp (original)
+++ trunk/src/server/server.cpp Sun Apr 27 08:13:02 2008
@@ -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 @@
                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";
@@ -1305,6 +1317,19 @@
                                << pl->second.name() << "\tsent 
[store_next_scenario] in game:\t\""
                                << g->name() << "\" (" << g->id()
                                << ") 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");


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to