Skip to content

Commit

Permalink
Merge pull request #333 from gfgtdf/wesnothd_sides
Browse files Browse the repository at this point in the history
don't limit server max sides
  • Loading branch information
gfgtdf committed Nov 16, 2014
2 parents 7c71f81 + a53594b commit 50d2b13
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/game_initialization/connect_engine.cpp
Expand Up @@ -824,7 +824,7 @@ side_engine::side_engine(const config& cfg, connect_engine& parent_engine,
parent_.force_lock_settings_) && parent_.params_.use_map_settings),
index_(index),
team_(0),
color_(index),
color_(std::min(index, gamemap::MAX_PLAYERS - 1)),
gold_(cfg["gold"].to_int(100)),
income_(cfg["income"]),
reserved_for_(cfg["current_player"]),
Expand Down
26 changes: 13 additions & 13 deletions src/server/game.cpp
Expand Up @@ -17,7 +17,6 @@
#include "../filesystem.hpp"
#include "../game_config.hpp" // game_config::observer_team_name
#include "../log.hpp"
#include "../map.hpp" // gamemap::MAX_PLAYERS

#include "game.hpp"
#include "player_network.hpp"
Expand Down Expand Up @@ -56,8 +55,8 @@ game::game(player_map& players, const network::connection host,
players_(),
observers_(),
muted_observers_(),
sides_(gamemap::MAX_PLAYERS),
side_controllers_(gamemap::MAX_PLAYERS),
sides_(),
side_controllers_(),
nsides_(0),
started_(false),
level_(),
Expand Down Expand Up @@ -179,10 +178,7 @@ void game::perform_controller_tweaks() {

update_side_data(); // Necessary to read the level_ and get sides_, etc. updated to match

nsides_ = 0;

for(simple_wml::node::child_list::const_iterator s = sides.begin(); s != sides.end(); ++s) {
nsides_++;
if ((**s)["controller"] != "null") {
const size_t side_index = (**s)["side"].to_int() - 1;
if(side_index >= sides_.size()) {
Expand Down Expand Up @@ -347,8 +343,17 @@ bool game::take_side(const player_map::const_iterator user)
//if we get here we couldn't find a side to take
return false;
}
void game::reset_sides()
{
side_controllers_.clear();
sides_.clear();
nsides_ = get_sides_list().size();
side_controllers_.resize(nsides_);
sides_.resize(nsides_);
}

void game::update_side_data() {
void game::update_side_data()
{
//added by iceiceice: since level_ will now reflect how an observer
if (started_) return; //views the replay start position and not the current position, the sides_, side_controllers_,
//players_ info should not be updated from the level_ after the game has started.
Expand All @@ -359,14 +364,9 @@ void game::update_side_data() {
DBG_GAME << debug_player_info();
// Remember everyone that is in the game.
const user_vector users = all_game_users();

side_controllers_.clear();
side_controllers_.resize(gamemap::MAX_PLAYERS);
sides_.clear();
sides_.resize(gamemap::MAX_PLAYERS);
players_.clear();
observers_.clear();

reset_sides();
const simple_wml::node::child_list& level_sides = get_sides_list();
/* This causes data corruption for some reason
if (!lg::debug.dont_log(log_server)) {
Expand Down
2 changes: 2 additions & 0 deletions src/server/game.hpp
Expand Up @@ -318,6 +318,8 @@ class game
/** Function to log when we don't find a connection in player_info_. */
void missing_user(network::connection socket, const std::string& func) const;

/** calculates the initial value for sides_, side_controllerds_, nsides_*/
void reset_sides();
/** Helps debugging player and observer lists. */
std::string debug_player_info() const;
/** Helps debugging controller tweaks. */
Expand Down
22 changes: 0 additions & 22 deletions src/server/server.cpp
Expand Up @@ -2336,12 +2336,6 @@ void server::process_data_lobby(const network::connection sock,
}
}


static size_t count_sides(const simple_wml::node& scenario)
{
return wesnothd::game::starting_pos(scenario)->children("side").size();
}

/**
* Process data sent from a member of a game.
*/
Expand Down Expand Up @@ -2371,14 +2365,6 @@ void server::process_data_game(const network::connection sock,
if (!g->is_owner(sock)) {
return;
}
if (count_sides(data.root()) > gamemap::MAX_PLAYERS) {
delete_game(itor);
std::stringstream msg;
msg << "This server does not support games with more than "
<< gamemap::MAX_PLAYERS << " sides. Game aborted.";
rooms_.lobby().send_server_message(msg.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().
Expand Down Expand Up @@ -2478,14 +2464,6 @@ void server::process_data_game(const network::connection sock,
return;
}
g->save_replay();
if (count_sides(*scenario) > gamemap::MAX_PLAYERS) {
delete_game(itor);
std::stringstream msg;
msg << "This server does not support games with more than "
<< gamemap::MAX_PLAYERS << " sides.";
rooms_.lobby().send_server_message(msg.str(), sock);
return;
}
// Record the full scenario in g->level()
g->level().clear();
scenario->copy_into(g->level().root());
Expand Down

0 comments on commit 50d2b13

Please sign in to comment.