Added automatic detection for packet_type...

...and made bandwidth monitoring always compiled
This commit is contained in:
Pauli Nieminen 2008-09-04 09:32:38 +00:00
parent 16576d3595
commit fa2c3aa134
7 changed files with 63 additions and 115 deletions

View file

@ -628,18 +628,13 @@ void queue_disconnect(network::connection sock)
disconnection_queue.push_back(sock);
}
connection receive_data(config& cfg, connection connection_num, unsigned int timeout
#ifdef BANDWIDTH_MONITOR
, bandwidth_in_ptr* bandwidth_in
#endif
connection receive_data(config& cfg, connection connection_num, unsigned int timeout, bandwidth_in_ptr* bandwidth_in
)
{
unsigned int start_ticks = SDL_GetTicks();
while(true) {
const connection res = receive_data(cfg,connection_num
#ifdef BANDWIDTH_MONITOR
,(bool*)0 , bandwidth_in
#endif
);
if(res != 0) {
return res;
@ -659,9 +654,7 @@ connection receive_data(config& cfg, connection connection_num, unsigned int tim
}
connection receive_data(config& cfg, connection connection_num, bool* gzipped
#ifdef BANDWIDTH_MONITOR
, bandwidth_in_ptr* bandwidth_in
#endif
)
{
if(!socket_set) {
@ -717,17 +710,13 @@ connection receive_data(config& cfg, connection connection_num, bool* gzipped
TCPsocket sock = connection_num == 0 ? 0 : get_socket(connection_num);
TCPsocket s = sock;
#ifdef BANDWIDTH_MONITOR
bandwidth_in_ptr temp;
if (!bandwidth_in)
{
bandwidth_in = &temp;
}
#endif
sock = network_worker_pool::get_received_data(sock,cfg, gzipped
#ifdef BANDWIDTH_MONITOR
, *bandwidth_in
#endif
);
if (sock == NULL) {
if (!is_server() && last_ping != 0 && ping_timeout != 0)
@ -773,9 +762,7 @@ connection receive_data(config& cfg, connection connection_num, bool* gzipped
}
connection receive_data(std::vector<char>& buf
#ifdef BANDWIDTH_MONITOR
, bandwidth_in_ptr* bandwidth_in
#endif
)
{
if(!socket_set) {
@ -834,7 +821,6 @@ connection receive_data(std::vector<char>& buf
return 0;
}
#ifdef BANDWIDTH_MONITOR
{
bandwidth_in_ptr temp;
if (!bandwidth_in)
@ -844,7 +830,6 @@ connection receive_data(std::vector<char>& buf
const int headers = 5;
bandwidth_in->reset(new network::bandwidth_in(buf.size() + headers));
}
#endif
SDLNet_TCP_AddSocket(socket_set,sock);
@ -860,7 +845,6 @@ connection receive_data(std::vector<char>& buf
waiting_sockets.insert(result);
return result;
}
#ifdef BANDWIDTH_MONITOR
struct bandwidth_stats {
int out_packets;
int out_bytes;
@ -989,7 +973,6 @@ void add_bandwidth_in(const std::string packet_type, size_t len)
add_bandwidth_in(type_, len_);
}
#endif
void send_file(const std::string& filename, connection connection_num, const std::string packet_type
)
{
@ -1005,10 +988,8 @@ void send_file(const std::string& filename, connection connection_num, const std
return;
}
#ifdef BANDWIDTH_MONITOR
const int packet_headers = 5;
add_bandwidth_out(packet_type, file_size(filename) + packet_headers);
#endif
network_worker_pool::queue_file(info->second.sock, filename);
}
@ -1037,9 +1018,7 @@ size_t send_data(const config& cfg, connection connection_num, const bool gzippe
i != sockets.end(); ++i) {
DBG_NW << "server socket: " << server_socket << "\ncurrent socket: " << *i << "\n";
size = send_data(cfg,*i, gzipped
#ifdef BANDWIDTH_MONITOR
, packet_type
#endif
);
}
return size;
@ -1054,9 +1033,7 @@ size_t send_data(const config& cfg, connection connection_num, const bool gzippe
LOG_NW << "SENDING to: " << connection_num << ": " << cfg;
return network_worker_pool::queue_data(info->second.sock, cfg, gzipped
#ifdef BANDWIDTH_MONITOR
, packet_type
#endif
);
}
@ -1086,10 +1063,8 @@ void send_raw_data(const char* buf, int len, connection connection_num, const st
<< "\tnot found in connection_map. Not sending...\n";
return;
}
#ifdef BANDWIDTH_MONITOR
const int packet_headers = 5;
add_bandwidth_out(packet_type, len + packet_headers);
#endif
network_worker_pool::queue_raw_data(info->second.sock, buf, len);
}
@ -1109,9 +1084,7 @@ void send_data_all_except(const config& cfg, connection connection_num, const bo
}
send_data(cfg,*i, gzipped
#ifdef BANDWIDTH_MONITOR
, packet_type
#endif
);
}
}

View file

@ -123,7 +123,6 @@ bool disconnect(connection connection_num=0, bool force=false);
//! on the given connection (and presumably then the handling of the error
//! will include closing the connection).
void queue_disconnect(connection connection_num);
#ifdef BANDWIDTH_MONITOR
std::string get_bandwidth_stats();
std::string get_bandwidth_stats_all();
@ -150,7 +149,6 @@ struct bandwidth_in {
typedef boost::shared_ptr<bandwidth_in> bandwidth_in_ptr;
#endif
//! Function to receive data from either a certain connection,
@ -161,19 +159,13 @@ typedef boost::shared_ptr<bandwidth_in> bandwidth_in_ptr;
//! or 0 if timeout occurred.
//! Throws error if an error occurred.
connection receive_data(config& cfg, connection connection_num=0, bool* gzipped = 0
#ifdef BANDWIDTH_MONITOR
, bandwidth_in_ptr* b = 0
#endif
);
connection receive_data(config& cfg, connection connection_num, unsigned int timeout
#ifdef BANDWIDTH_MONITOR
, bandwidth_in_ptr* b = 0
#endif
);
connection receive_data(std::vector<char>& buf
#ifdef BANDWIDTH_MONITOR
, bandwidth_in_ptr* = 0
#endif
);
void send_file(const std::string&, connection, const std::string packet_type = "unknown");

View file

@ -807,9 +807,7 @@ void receive_data(TCPsocket sock)
}
TCPsocket get_received_data(TCPsocket sock, config& cfg, bool* gzipped
#ifdef BANDWIDTH_MONITOR
,network::bandwidth_in_ptr& bandwidth_in
#endif
)
{
assert(!raw_data_only);
@ -841,9 +839,7 @@ TCPsocket get_received_data(TCPsocket sock, config& cfg, bool* gzipped
if (gzipped)
*gzipped = buf->gzipped;
received_data_queue.erase(itor);
#ifdef BANDWIDTH_MONITOR
bandwidth_in.reset(new network::bandwidth_in((*itor)->raw_buffer.size()));
#endif
delete buf;
return res;
}
@ -898,9 +894,7 @@ void queue_raw_data(TCPsocket sock, const char* buf, int len)
}
size_t queue_data(TCPsocket sock,const config& buf, const bool gzipped
#ifdef BANDWIDTH_MONITOR
, const std::string& packet_type
#endif
)
{
DBG_NW << "queuing data...\n";
@ -909,9 +903,7 @@ size_t queue_data(TCPsocket sock,const config& buf, const bool gzipped
output_to_buffer(sock, buf, queued_buf->stream, gzipped);
queued_buf->gzipped = gzipped;
size_t size = queued_buf->stream.str().size();
#ifdef BANDWIDTH_MONITOR
network::add_bandwidth_out(packet_type, size);
#endif
queue_buffer(sock, queued_buf);
return size;
}

View file

@ -52,9 +52,7 @@ void set_raw_data_only();
void receive_data(TCPsocket sock);
TCPsocket get_received_data(TCPsocket sock, config& cfg, bool* gzipped
#ifdef BANDWIDTH_MONITOR
, network::bandwidth_in_ptr&
#endif
);
TCPsocket get_received_data(std::vector<char>& buf);
@ -62,9 +60,7 @@ void queue_file(TCPsocket sock, const std::string&);
void queue_raw_data(TCPsocket sock, const char* buf, int len);
size_t queue_data(TCPsocket sock, const config& buf, const bool gzipped
#ifdef BANDWIDTH_MONITOR
, const std::string& packet_type
#endif
);
bool is_locked(const TCPsocket sock);
bool close_socket(TCPsocket sock, bool force=false);

View file

@ -173,7 +173,7 @@ void game::start_game(const player_map::const_iterator starter) {
// When the host advances tell everyone that the next scenario data is
// available.
static simple_wml::document notify_next_scenario("[notify_next_scenario]\n[/notify_next_scenario]\n", simple_wml::INIT_COMPRESSED);
send_data(notify_next_scenario, starter->first, "notify_next_scenario");
send_data(notify_next_scenario, starter->first);
}
// Send [observer] tags for all observers that are already in the game.
send_observerjoins();
@ -216,7 +216,7 @@ bool game::take_side(const player_map::const_iterator user)
// Tell the host which side the new player should take.
simple_wml::string_span data = cfg.output_compressed();
network::send_raw_data(data.begin(), data.size(), owner_, "game_control");
network::send_raw_data(data.begin(), data.size(), owner_, cfg.root().first_child().to_string());
DBG_GAME << "take_side: took side " << side_num << " because the name matched\n";
DBG_GAME << debug_player_info();
return true;
@ -238,7 +238,7 @@ bool game::take_side(const player_map::const_iterator user)
cfg.root().set_attr_dup("side", (**side)["side"]);
// Tell the host which side the new player should take.
simple_wml::string_span data = cfg.output_compressed();
network::send_raw_data(data.begin(), data.size(), owner_, "game_control");
network::send_raw_data(data.begin(), data.size(), owner_, cfg.root().first_child().to_string());
DBG_GAME << "take_side: took the first free network side which was " << side_num << "\n";
DBG_GAME << debug_player_info();
return true;
@ -391,7 +391,7 @@ void game::transfer_side_control(const network::connection sock, const simple_wm
// Update the client side observer list for everyone except old player.
simple_wml::document observer_join;
observer_join.root().add_child("observer").set_attr_dup("name", old_player_name.c_str());
send_data(observer_join, old_player,"game_observer_join");
send_data(observer_join, old_player);
// If the old player was the host of the game, choose another player.
/*if (old_player == owner_) {
host_leave = true;
@ -441,14 +441,14 @@ void game::send_change_controller(const size_t side_num,
// Tell everyone but the new player that this side is network controlled now.
change.set_attr("controller", "network");
send_data(response, newplayer->first, "game_control");
send_data(response, newplayer->first);
// Tell the new player that he controls this side now.
// Just don't send it when the player left the game. (The host gets the
// side_drop already.)
if (!player_left) {
change.set_attr("controller", "human");
send_to_one(response, newplayer->first,"game_control");
send_to_one(response, newplayer->first);
}
// Update the level so observers who join get the new name.
@ -471,7 +471,7 @@ void game::transfer_ai_sides() {
drop.root().set_attr("side_drop", side_drop.c_str());
drop.root().set_attr("controller", "ai");
const simple_wml::string_span data = drop.output_compressed();
network::send_raw_data(data.begin(), data.size(), owner_, "game_control");
network::send_raw_data(data.begin(), data.size(), owner_, drop.root().first_child().to_string());
sides_[side] = owner_;
}
if (ai_transfer) {
@ -490,7 +490,7 @@ void game::notify_new_host(){
cfg_host_transfer.set_attr("name", owner_name.c_str());
cfg_host_transfer.set_attr("value", "1");
const simple_wml::string_span data = cfg.output_compressed();
network::send_raw_data(data.begin(), data.size(), owner_,"game_control");
network::send_raw_data(data.begin(), data.size(), owner_,cfg.root().first_child().to_string());
send_and_record_server_message((owner_name
+ " has been chosen as the new host.").c_str());
}
@ -614,7 +614,7 @@ network::connection game::kick_member(const simple_wml::node& kick,
// Tell the user to leave the game.
static simple_wml::document leave_game("[leave_game]\n[/leave_game]\n", simple_wml::INIT_COMPRESSED);
static const simple_wml::string_span leave_game_data = leave_game.output_compressed();
network::send_raw_data(leave_game_data.begin(), leave_game_data.size(), user->first,"game_control");
network::send_raw_data(leave_game_data.begin(), leave_game_data.size(), user->first,leave_game.root().first_child().to_string());
remove_player(user->first);
return user->first;
}
@ -655,7 +655,7 @@ network::connection game::ban_user(const simple_wml::node& ban,
//tell the user to leave the game.
static simple_wml::document leave_game("[leave_game]\n[/leave_game]\n", simple_wml::INIT_COMPRESSED);
static const simple_wml::string_span leave_game_data = leave_game.output_compressed();
network::send_raw_data(leave_game_data.begin(), leave_game_data.size(), user->first,"game_control");
network::send_raw_data(leave_game_data.begin(), leave_game_data.size(), user->first,leave_game.root().first_child().to_string());
remove_player(user->first);
return user->first;
}
@ -896,7 +896,7 @@ void game::add_player(const network::connection player, bool observer) {
observer_join.root().add_child("observer").set_attr_dup("name", user->second.name().c_str());
// Send observer join to everyone except the new observer.
send_data(observer_join, player, "game_observer");
send_data(observer_join, player);
}
DBG_GAME << debug_player_info();
// Send the user the game data.
@ -907,7 +907,7 @@ void game::add_player(const network::connection player, bool observer) {
//tell this player that the game has started
static simple_wml::document start_game_doc("[start_game]\n[/start_game]\n", simple_wml::INIT_COMPRESSED);
static const simple_wml::string_span start_game = start_game_doc.output_compressed();
network::send_raw_data(start_game.begin(), start_game.size(), player,"game_replay");
network::send_raw_data(start_game.begin(), start_game.size(), player,start_game_doc.root().first_child().to_string());
// Send observer join of all the observers in the game to the new player
// only once the game started. The client forgets about it anyway
// otherwise.
@ -1036,7 +1036,7 @@ void game::send_user_list(const network::connection exclude) const {
cfg.root().add_child("user").set_attr("name", pl->second.name().c_str());
}
}
send_data(cfg, exclude, "game_user_list");
send_data(cfg, exclude);
}
//! A member asks for the next scenario to advance to.
@ -1045,15 +1045,17 @@ void game::load_next_scenario(const player_map::const_iterator user) const {
simple_wml::document cfg_scenario;
level_.root().copy_into(cfg_scenario.root().add_child("next_scenario"));
simple_wml::string_span data = cfg_scenario.output_compressed();
network::send_raw_data(data.begin(), data.size(), user->first, "game_level");
network::send_raw_data(data.begin(), data.size(), user->first, cfg_scenario.root().first_child().to_string());
// Send the player the history of the game to-date.
send_history(user->first);
// Send observer join of all the observers in the game to the user.
send_observerjoins(user->first);
}
void game::send_data(simple_wml::document& data, const network::connection exclude, const std::string& packet_type) const
void game::send_data(simple_wml::document& data, const network::connection exclude, std::string packet_type) const
{
if (packet_type.empty())
packet_type = data.root().first_child().to_string();
simple_wml::string_span s = data.output_compressed();
const user_vector& users = all_game_users();
for(user_vector::const_iterator i = users.begin(); i != users.end(); ++i) {
@ -1063,8 +1065,10 @@ void game::send_data(simple_wml::document& data, const network::connection exclu
}
}
void game::send_to_one(simple_wml::document& data, const network::connection sock, const std::string& packet_type) const
void game::send_to_one(simple_wml::document& data, const network::connection sock, std::string packet_type) const
{
if (packet_type.empty())
packet_type = data.root().first_child().to_string();
simple_wml::string_span s = data.output_compressed();
network::send_raw_data(s.begin(), s.size(), sock,packet_type);
}
@ -1072,8 +1076,10 @@ void game::send_to_one(simple_wml::document& data, const network::connection soc
void game::send_data_team(simple_wml::document& data,
const simple_wml::string_span& team,
const network::connection exclude,
const std::string& packet_type) const
std::string packet_type) const
{
if (packet_type.empty())
packet_type = data.root().first_child().to_string();
simple_wml::string_span s = data.output_compressed();
for(user_vector::const_iterator i = players_.begin(); i != players_.end(); ++i) {
if(*i != exclude && is_on_team(team,*i)) {
@ -1082,7 +1088,9 @@ void game::send_data_team(simple_wml::document& data,
}
}
void game::send_data_observers(simple_wml::document& data, const network::connection exclude, const std::string& packet_type) const {
void game::send_data_observers(simple_wml::document& data, const network::connection exclude, std::string packet_type) const {
if (packet_type.empty())
packet_type = data.root().first_child().to_string();
simple_wml::string_span s = data.output_compressed();
for(user_vector::const_iterator i = observers_.begin(); i != observers_.end(); ++i) {
if (*i != exclude) {
@ -1126,11 +1134,11 @@ void game::send_observerjoins(const network::connection sock) const {
cfg.root().add_child("observer").set_attr_dup("name", obs->second.name().c_str());
if (sock == 0) {
// Send to everyone except the observer in question.
send_data(cfg, *ob, "game_observer");
send_data(cfg, *ob);
} else {
// Send to the (new) user.
const simple_wml::string_span& data = cfg.output_compressed();
network::send_raw_data(data.begin(), data.size(), sock,"game_observer");
network::send_raw_data(data.begin(), data.size(), sock);
}
}
}
@ -1144,7 +1152,7 @@ void game::send_observerquit(const player_map::const_iterator observer) const {
//don't need to dup the attribute because this document is
//short-lived.
observer_quit.root().add_child("observer_quit").set_attr("name", observer->second.name().c_str());
send_data(observer_quit, observer->first, "game_ob_quit");
send_data(observer_quit, observer->first);
}
void game::send_history(const network::connection sock) const

View file

@ -93,8 +93,8 @@ public:
//! Send data to all players in this game except 'exclude'.
void send_and_record_server_message(const char* message,
const network::connection exclude=0);
void send_data(simple_wml::document& data, const network::connection exclude=0, const std::string& packet_type = "unkown") const;
void send_to_one(simple_wml::document& data, const network::connection sock, const std::string& packet_type = "unkown") const;
void send_data(simple_wml::document& data, const network::connection exclude=0, std::string packet_type = "") const;
void send_to_one(simple_wml::document& data, const network::connection sock, std::string packet_type = "") const;
void record_data(simple_wml::document* data);
@ -140,8 +140,8 @@ private:
const bool player_left=true);
void transfer_ai_sides();
void send_data_team(simple_wml::document& data, const simple_wml::string_span& team,
const network::connection exclude=0, const std::string& packet_type = "unkown") const;
void send_data_observers(simple_wml::document& data, const network::connection exclude=0, const std::string& packet_type = "unkown") const;
const network::connection exclude=0, std::string packet_type = "") const;
void send_data_observers(simple_wml::document& data, const network::connection exclude=0, std::string packet_type = "") const;
//! Send [observer] tags of all the observers in the game to the user or
//! everyone if none given.
void send_observerjoins(const network::connection sock=0) const;

View file

@ -114,8 +114,10 @@ namespace {
// we take profiling info on every n requests
int request_sample_frequency = 1;
void send_doc(simple_wml::document& doc, network::connection connection, std::string type = "unknown")
void send_doc(simple_wml::document& doc, network::connection connection, std::string type = "")
{
if (type.empty())
type = doc.root().first_child().to_string();
simple_wml::string_span s = doc.output_compressed();
network::send_raw_data(s.begin(), s.size(), connection, type);
}
@ -480,7 +482,6 @@ void server::run() {
ban_manager_.check_ban_times(now);
// Make sure we log stats every 5 minutes
if (last_stats_ + 5*60 <= now) dump_stats(now);
#ifdef BANDWIDTH_MONITOR
// Send network stats every hour
static size_t prev_hour = localtime(&now)->tm_hour;
if (prev_hour != localtime(&now)->tm_hour)
@ -489,7 +490,6 @@ void server::run() {
LOG_SERVER << network::get_bandwidth_stats();
}
#endif
// send a 'ping' to all players to detect ghosts
config ping;
ping["ping"] = lexical_cast<std::string>(now);
@ -517,7 +517,7 @@ void server::run() {
} else {
DBG_SERVER << ip << "\tnew connection accepted. (socket: "
<< sock << ")\n";
send_doc(version_query_response_, sock,"command");
send_doc(version_query_response_, sock);
not_logged_in_.add_player(sock, true);
}
}
@ -525,14 +525,8 @@ void server::run() {
static int sample_counter = 0;
std::vector<char> buf;
#ifdef BANDWIDTH_MONITOR
network::bandwidth_in_ptr bandwidth_type;
#endif
while ((sock = network::receive_data(buf
#ifdef BANDWIDTH_MONITOR
, &bandwidth_type
#endif
)) != network::null_connection) {
while ((sock = network::receive_data(buf, &bandwidth_type)) != network::null_connection) {
metrics_.service_request();
if(buf.empty()) {
@ -567,9 +561,7 @@ void server::run() {
process_data(sock, data);
#ifdef BANDWIDTH_MONITOR
bandwidth_type->set_type("command");
#endif
bandwidth_type->set_type(data.root().first_child().to_string());
if(sample) {
const clock_t after_processing = get_cpu_time(sample);
metrics_.record_sample(data.root().first_child(),
@ -666,9 +658,7 @@ void server::run() {
DBG_SERVER << "done closing socket...\n";
}
}
#ifdef BANDWIDTH_MONITOR
LOG_SERVER << network::get_bandwidth_stats_all();
#endif
}
void server::process_data(const network::connection sock,
@ -713,7 +703,7 @@ void server::process_login(const network::connection sock,
LOG_SERVER << network::ip_address(sock)
<< "\tplayer joined using accepted version " << version_str
<< ":\ttelling them to log in.\n";
send_doc(login_response_, sock, "command");
send_doc(login_response_, sock);
return;
}
std::map<std::string,config>::const_iterator config_it;
@ -806,7 +796,7 @@ void server::process_login(const network::connection sock,
}
}
send_doc(join_lobby_response_, sock, "join_lobby");
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_,
@ -817,7 +807,7 @@ void server::process_login(const network::connection sock,
lobby_.add_player(sock, true);
// Send the new player the entire list of games and players
send_doc(games_and_users_list_, sock, "lobby_list");
send_doc(games_and_users_list_, sock);
if (motd_ != "") {
lobby_.send_server_message(motd_.c_str(), sock);
@ -913,8 +903,8 @@ std::string server::process_command(const std::string& query, const std::string&
out << "Server is doing graceful shut down.";
}
#ifndef _WIN32 // Not sure if this works on windows
// TODO: check if this works in windows.
// this works in windows if using "start /B"
// like in wesnoth MP server start code
} else if (command == "restart" && issuer_name == "*socket*") {
if (restart_command.empty()) {
out << "No restart_command configured! Not restarting.";
@ -929,7 +919,6 @@ std::string server::process_command(const std::string& query, const std::string&
process_command("msg The server has been restarted. You may finish your games but can't start new ones and new players can't join this server.", issuer_name);
out << "New server started.";
}
#endif
} else if (command == "help") {
out << help_msg;
} else if (command == "metrics") {
@ -943,12 +932,10 @@ std::string server::process_command(const std::string& query, const std::string&
out << "Network stats:\nPending send buffers: "
<< stats.npending_sends << "\nBytes in buffers: "
<< stats.nbytes_pending_sends << "\n";
#ifdef BANDWIDTH_MONITOR
if (parameters == "all")
out << network::get_bandwidth_stats_all();
else
out << network::get_bandwidth_stats(); // stats from previuos hour
#endif
} else if (command == "msg" || command == "lobbymsg") {
if (parameters == "") {
return "You must type a message.";
@ -1130,7 +1117,7 @@ void server::process_whisper(const network::connection sock,
"message=\"Invalid number of arguments\"\n"
"sender=\"server\"\n"
"[/message]\n", simple_wml::INIT_COMPRESSED);
send_doc(data, sock, "error");
send_doc(data, sock);
return;
}
const wesnothd::player_map::const_iterator pl = players_.find(sock);
@ -1160,7 +1147,7 @@ void server::process_whisper(const network::connection sock,
simple_wml::document cwhisper;
whisper.copy_into(cwhisper.root().add_child("whisper"));
send_doc(cwhisper, i->first, "command");
send_doc(cwhisper, i->first);
return;
}
@ -1174,7 +1161,7 @@ void server::process_whisper(const network::connection sock,
}
msg.set_attr("sender", "server");
send_doc(data, sock, "error");
send_doc(data, sock);
}
void server::process_data_lobby(const network::connection sock,
@ -1191,9 +1178,9 @@ void server::process_data_lobby(const network::connection sock,
if (data.root().child("create_game")) {
if (graceful_restart) {
static simple_wml::document leave_game_doc("[leave_game]\n[/leave_game]\n", simple_wml::INIT_COMPRESSED);
send_doc(leave_game_doc, sock,"command");
send_doc(leave_game_doc, sock);
lobby_.send_server_message("This server is shutting down. You aren't allowed to make new games. Please reconnect to the new server.", sock);
send_doc(games_and_users_list_, sock, "lobby_list");
send_doc(games_and_users_list_, sock);
return;
}
const std::string game_name = (*data.root().child("create_game"))["name"].to_string();
@ -1231,41 +1218,41 @@ void server::process_data_lobby(const network::connection sock,
if (g == games_.end()) {
WRN_SERVER << network::ip_address(sock) << "\t" << pl->second.name()
<< "\tattempted to join unknown game:\t" << game_id << ".\n";
send_doc(leave_game_doc, sock, "command");
send_doc(leave_game_doc, sock);
lobby_.send_server_message("Attempt to join unknown game.", sock);
send_doc(games_and_users_list_, sock, "lobby_list");
send_doc(games_and_users_list_, sock);
return;
} else if ((*g)->player_is_banned(sock)) {
DBG_SERVER << network::ip_address(sock) << "\tReject banned player: "
<< pl->second.name() << "\tfrom game:\t\"" << (*g)->name()
<< "\" (" << game_id << ").\n";
send_doc(leave_game_doc, sock, "command");
send_doc(leave_game_doc, sock);
lobby_.send_server_message("You are banned from this game.", sock);
send_doc(games_and_users_list_, sock, "lobby_list");
send_doc(games_and_users_list_, sock);
return;
} else if(!observer && !(*g)->password_matches(password)) {
WRN_SERVER << network::ip_address(sock) << "\t" << pl->second.name()
<< "\tattempted to join game:\t\"" << (*g)->name() << "\" ("
<< game_id << ") with bad password\n";
send_doc(leave_game_doc, sock, "command");
send_doc(leave_game_doc, sock);
lobby_.send_server_message("Incorrect password.", sock);
send_doc(games_and_users_list_, sock, "lobby_list");
send_doc(games_and_users_list_, sock);
return;
} else if (observer && !(*g)->allow_observers()) {
WRN_SERVER << network::ip_address(sock) << "\t" << pl->second.name()
<< "\tattempted to observe game:\t\"" << (*g)->name() << "\" ("
<< game_id << ") which doesn't allow observers.\n";
send_doc(leave_game_doc, sock, "command");
send_doc(leave_game_doc, sock);
lobby_.send_server_message("Attempt to observe a game that doesn't allow observers.", sock);
send_doc(games_and_users_list_, sock, "lobby_list");
send_doc(games_and_users_list_, sock);
return;
} else if (!(*g)->level_init()) {
WRN_SERVER << network::ip_address(sock) << "\t" << pl->second.name()
<< "\tattempted to join uninitialized game:\t\"" << (*g)->name()
<< "\" (" << game_id << ").\n";
send_doc(leave_game_doc, sock, "command");
send_doc(leave_game_doc, sock);
lobby_.send_server_message("Attempt to observe a game that doesn't allow observers.", sock);
send_doc(games_and_users_list_, sock, "lobby_list");
send_doc(games_and_users_list_, sock);
return;
}
LOG_SERVER << network::ip_address(sock) << "\t" << pl->second.name()
@ -1295,7 +1282,7 @@ void server::process_data_lobby(const network::connection sock,
// Player requests update of lobby content,
// for example when cancelling the create game dialog
if (data.child("refresh_lobby")) {
send_doc(games_and_users_list_, sock, "lobby_list");
send_doc(games_and_users_list_, sock);
}
}
@ -1553,7 +1540,7 @@ void server::process_data_game(const network::connection sock,
}
// Send the player who has quit the gamelist.
send_doc(games_and_users_list_, sock, "lobby_list");
send_doc(games_and_users_list_, sock);
}
return;
// If this is data describing side changes by the host.
@ -1606,7 +1593,7 @@ void server::process_data_game(const network::connection sock,
update_game_in_lobby(g, user);
}
// Send the removed user the lobby game list.
send_doc(games_and_users_list_, user, "lobby_list");
send_doc(games_and_users_list_, user);
// FIXME: should also send a user diff to the lobby
// to mark this player as available for others
}