Author: loonycyborg
Date: Fri Jun 13 22:20:22 2008
New Revision: 27156
URL: http://svn.gna.org/viewcvs/wesnoth?rev=27156&view=rev
Log:
Apply patch #1068.
Modified:
trunk/changelog
trunk/data/ais/safe.py
trunk/data/core/about.cfg
trunk/src/multiplayer.cpp
trunk/src/server/player.cpp
trunk/src/server/player.hpp
trunk/src/server/server.cpp
Modified: trunk/changelog
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=27156&r1=27155&r2=27156&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Fri Jun 13 22:20:22 2008
@@ -87,6 +87,9 @@
* created [attacks] special with expected behaviour and usage similar to
[damage] special
* wesnothd
+ * added selective ping support - saves server bandwidth
+ * updated pings to use new simple_wml
+ * pings now sent using raw method to they only get compressed once for batch
* added expiration time to bans
* added restart command to server that does graceful restart
* added option to do graceful shut down for server
@@ -100,6 +103,7 @@
* authors can specify the type of their content ('type'
field in .pbl files)
* miscellaneous and bug fixes:
+ * Client now sends 'selective_ping="1"' during login
* fixed parser bug that prevented loading binary data strings
* fixed issues with campaign info in non-compressed saved games
(bug #11386)
Modified: trunk/data/ais/safe.py
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/ais/safe.py?rev=27156&r1=27155&r2=27156&view=diff
==============================================================================
--- trunk/data/ais/safe.py (original)
+++ trunk/data/ais/safe.py Fri Jun 13 22:20:22 2008
@@ -33,7 +33,7 @@
'Assert', 'Assign','AugAssign', 'Bitand', 'Bitor', 'Bitxor', 'Break',
'CallFunc', 'Class', 'Compare', 'Const', 'Continue',
'Dict', 'Discard', 'Div', 'Ellipsis', 'Expression', 'FloorDiv',
- 'For', 'Function', 'Getattr', 'If', 'Keyword',
+ 'For', 'Function', 'Getattr', 'If', 'Keyword', 'Lambda',
'LeftShift', 'List', 'ListComp', 'ListCompFor', 'ListCompIf', 'Mod',
'Module', 'Mul', 'Name', 'Node', 'Not', 'Or', 'Pass', 'Power',
'Print', 'Printnl', 'Return', 'RightShift', 'Slice', 'Sliceobj',
@@ -126,7 +126,7 @@
# If you want to disable safe python, use this instead:
#
-# def safe_exec(code, context = None): exec code in context
+##def safe_exec(code, context = None): exec code in context
def safe_exec(code, context = None):
"""Check the code to be safe, then run it with only safe builtins on."""
safe_check(code)
Modified: trunk/data/core/about.cfg
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/core/about.cfg?rev=27156&r1=27155&r2=27156&view=diff
==============================================================================
--- trunk/data/core/about.cfg (original)
+++ trunk/data/core/about.cfg Fri Jun 13 22:20:22 2008
@@ -57,6 +57,11 @@
comment = "Macro library reorganization, major UI makeover introducing
lightweight transparent popups and linger mode, maintainance tools for WML, six
campaigns lifted from UMC, one all-original campaign, editor refactoring, and
many many code cleanups."
[/entry]
[entry]
+ name = "Greg Copeland (Oracle)"
+ comment = "coding; Server optimizations."
+ ircuser = "BlindOracle"
+ [/entry]
+ [entry]
name = "Guillaume Melquiond (silene)"
comment = "coding, bug fixes"
[/entry]
Modified: trunk/src/multiplayer.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/multiplayer.cpp?rev=27156&r1=27155&r2=27156&view=diff
==============================================================================
--- trunk/src/multiplayer.cpp (original)
+++ trunk/src/multiplayer.cpp Fri Jun 13 22:20:22 2008
@@ -239,8 +239,22 @@
first_time = false;
- config response;
- response.add_child("login")["username"] = login;
+ config response ;
+ config &sp = response.add_child("login") ;
+ sp["username"] = login ;
+
+ // Login and enable selective pings -- saves
server bandwidth
+ // If ping_timeout has a non-zero value, do not
enable
+ // selective pings as this will cause clients
to falsely
+ // believe the server has died and disconnect.
+ if( preferences::get_ping_timeout() ) {
+ // Pings required so disable selective pings
+ sp["selective_ping"] = "0" ;
+ } else {
+ // Client is bandwidth friendly so allow
+ // server to optimize ping frequency as
needed.
+ sp["selective_ping"] = "1" ;
+ }
network::send_data(response, 0, true);
network::connection data_res =
network::receive_data(data, 0, 3000);
Modified: trunk/src/server/player.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/server/player.cpp?rev=27156&r1=27155&r2=27156&view=diff
==============================================================================
--- trunk/src/server/player.cpp (original)
+++ trunk/src/server/player.cpp Fri Jun 13 22:20:22 2008
@@ -16,9 +16,10 @@
#include "player.hpp"
-player::player(const std::string& n, simple_wml::node& cfg, const size_t
max_messages, const size_t time_period)
- : name_(n), cfg_(cfg), flood_start_(0), messages_since_flood_start_(0),
- MaxMessages(max_messages), TimePeriod(time_period)
+player::player(const std::string& n, simple_wml::node& cfg, const size_t
max_messages, const size_t time_period, const bool sp)
+ : name_(n), cfg_(cfg), selective_ping_( sp ), flood_start_(0),
+ messages_since_flood_start_(0),
+ MaxMessages(max_messages), TimePeriod(time_period)
{
cfg_.set_attr_dup("name", n.c_str());
mark_available();
Modified: trunk/src/server/player.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/server/player.hpp?rev=27156&r1=27155&r2=27156&view=diff
==============================================================================
--- trunk/src/server/player.hpp (original)
+++ trunk/src/server/player.hpp Fri Jun 13 22:20:22 2008
@@ -25,13 +25,14 @@
class player
{
public:
- player(const std::string& n, simple_wml::node& cfg, const size_t
max_messages=4, const size_t time_period=10);
+ player(const std::string& n, simple_wml::node& cfg, const size_t
max_messages=4, const size_t time_period=10, const bool sp=false);
// mark a player as member of the game 'game_id' or as located in the
lobby
void mark_available(const int game_id=0, const std::string location="");
const std::string& name() const { return name_; }
+ const bool selective_ping() const { return selective_ping_ ; }
simple_wml::node* config_address() const { return &cfg_; }
@@ -41,6 +42,7 @@
private:
const std::string name_;
simple_wml::node& cfg_;
+ const bool selective_ping_ ;
time_t flood_start_;
unsigned int messages_since_flood_start_;
Modified: trunk/src/server/server.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/server/server.cpp?rev=27156&r1=27155&r2=27156&view=diff
==============================================================================
--- trunk/src/server/server.cpp (original)
+++ trunk/src/server/server.cpp Fri Jun 13 22:20:22 2008
@@ -260,6 +260,8 @@
//! std::map<network::connection,player>
player_map players_;
+ player_map ghost_players_ ;
+
std::vector<game*> games_;
game not_logged_in_;
//! The lobby is implemented as a game.
@@ -469,6 +471,7 @@
LOG_SERVER << "Statistics:"
<< "\tnumber_of_games = " << games_.size()
<< "\tnumber_of_users = " << players_.size()
+ << "\tnumber_of_ghost_users = " << ghost_players_.size()
<< "\tlobby_users = " << lobby_.nobservers() << "\n";
}
@@ -491,11 +494,13 @@
process_command("msg All games ended. Shutting
down now. Reconnect to the new server.");
throw network::error("shut down");
}
+
if (config_reload == 1) {
cfg_ = read_config();
load_config();
config_reload = 0;
}
+
// Process commands from the server socket/fifo
std::string admin_cmd;
if (input_.read_line(admin_cmd)) {
@@ -503,7 +508,7 @@
}
time_t now = time(NULL);
- if (last_ping_ + 15 <= now) {
+ if (last_ping_ + 30 <= now) {
// and check if bans have expired
ban_manager_.check_ban_times(now);
// Make sure we log stats every 5 minutes
@@ -511,12 +516,28 @@
dump_stats(now);
}
// send a 'ping' to all players to detect ghosts
- config ping;
- ping["ping"] = lexical_cast<std::string>(now);
- for (player_map::const_iterator i =
players_.begin();
- i != players_.end(); ++i)
+ DBG_SERVER << "Pinging inactive players.\n" ;
+ std::ostringstream strstr ;
+ strstr << "ping=\"" <<
lexical_cast<std::string>(now) << "\"" ;
+ simple_wml::document ping( strstr.str().c_str(),
+
simple_wml::INIT_COMPRESSED ) ;
+ simple_wml::string_span s =
ping.output_compressed() ;
+ for (player_map::const_iterator i =
ghost_players_.begin();
+ i != ghost_players_.end(); ++i)
+ {
+ DBG_SERVER << "Pinging " <<
i->second.name() << "(" << i->first << ").\n" ;
+ network::send_raw_data( s.begin(),
+ s.size(),
+ i->first ) ;
+ }
+
+ // Copy new player list on top of
ghost_players_ list.
+ // Only a single thread should be accessing this
{
- network::send_data(ping, i->first,
true);
+ // Erase before we copy - speeds inserts
+ ghost_players_.clear() ;
+ std::copy( players_.begin(), players_.end(),
+ std::inserter( ghost_players_,
ghost_players_.begin() ) ) ;
}
last_ping_ = now;
}
@@ -558,6 +579,7 @@
//message. (ugh). We will see if this looks
like binary WML
//and if it does, assume it's a leave_game
message
if(buf.front() < 5) {
+ std::cerr << "hit wesnoth bug...forcing
disconnection incorrectly." << buf.front() << std::endl ;
static simple_wml::document
leave_game_doc(
"[leave_game]\n[/leave_game]\n",
simple_wml::INIT_COMPRESSED);
@@ -684,6 +706,15 @@
proxy::received_data(sock, data);
}
+ // We know the client is alive for this interval
+ // Remove player from ghost_players map if selective_ping
+ // is enabled for the player.
+ const player_map::const_iterator pl = ghost_players_.find( sock ) ;
+ if( pl != ghost_players_.end() && pl->second.selective_ping() ) {
+ ghost_players_.erase( sock ) ;
+ }
+
+ // Process the message
simple_wml::node& root = data.root();
if(root.has_attr("ping")) {
// Ignore client side pings for now.
@@ -701,6 +732,7 @@
process_data_game(sock, data);
}
}
+
void server::process_login(const network::connection sock,
@@ -813,12 +845,29 @@
}
}
+ // Check if the version is now avaliable. If it is not, this player must
+ // always be pinged.
+ bool selective_ping = false ;
+ if( (*login)["selective_ping"].to_bool() ) {
+ selective_ping = true ;
+ DBG_SERVER << "selective ping is ENABLED for " << sock << "\n" ;
+ } else {
+ DBG_SERVER << "selective ping is DISABLED for " << sock << "\n" ;
+ }
+
send_doc(join_lobby_response_, sock);
simple_wml::node& player_cfg =
games_and_users_list_.root().add_child("user");
const player new_player(username, player_cfg, default_max_messages_,
- default_time_period_);
+ default_time_period_, selective_ping );
+
+ // If the new player does not have selective ping enabled, immediately
+ // add the player to the ghost player's list. This ensures a client
won't
+ // have to wait as long as x2 the current ping delay; which could cause
+ // a client-side disconnection.
players_.insert(std::pair<network::connection,player>(sock,
new_player));
+ if( !selective_ping )
+ ghost_players_.insert( std::pair<network::connection,player>(sock,
new_player) ) ;
not_logged_in_.remove_player(sock);
lobby_.add_player(sock, true);
@@ -940,8 +989,9 @@
out << help_msg;
} else if (command == "metrics") {
out << metrics_ << "Current number of games = " <<
games_.size() << "\n"
- "Total number of users = " << players_.size() << "\n"
- "Number of users in the lobby = " << lobby_.nobservers() <<
"\n";
+ "Total number of users = " << players_.size() << "\n"
+ "Total number of ghost users = " << ghost_players_.size() <<
"\n"
+ "Number of users in the lobby = " << lobby_.nobservers() <<
"\n";
} else if (command == "wml") {
out << simple_wml::document::stats();
} else if (command == "netstats") {
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits