improved bandwidth statistics categories

This commit is contained in:
Pauli Nieminen 2008-06-27 21:30:26 +00:00
parent ac9aff4f39
commit 9804410bdd
3 changed files with 56 additions and 52 deletions

View file

@ -171,7 +171,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);
send_data(notify_next_scenario, starter->first, "notify_next_scenario");
}
// Send [observer] tags for all observers that are already in the game.
send_observerjoins();
@ -214,7 +214,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");
network::send_raw_data(data.begin(), data.size(), owner_, "game_control");
DBG_GAME << "take_side: took side " << side_num << " because the name matched\n";
DBG_GAME << debug_player_info();
return true;
@ -236,7 +236,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");
network::send_raw_data(data.begin(), data.size(), owner_, "game_control");
DBG_GAME << "take_side: took the first free network side which was " << side_num << "\n";
DBG_GAME << debug_player_info();
return true;
@ -389,7 +389,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);
send_data(observer_join, old_player,"game_observer_join");
// If the old player was the host of the game, choose another player.
/*if (old_player == owner_) {
host_leave = true;
@ -439,14 +439,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);
send_data(response, newplayer->first, "game_control");
// 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);
send_to_one(response, newplayer->first,"game_control");
}
// Update the level so observers who join get the new name.
@ -469,7 +469,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");
network::send_raw_data(data.begin(), data.size(), owner_, "game_control");
sides_[side] = owner_;
}
if (ai_transfer) {
@ -488,7 +488,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");
network::send_raw_data(data.begin(), data.size(), owner_,"game_control");
send_and_record_server_message((owner_name
+ " has been chosen as the new host.").c_str());
}
@ -612,7 +612,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");
network::send_raw_data(leave_game_data.begin(), leave_game_data.size(), user->first,"game_control");
remove_player(user->first);
return user->first;
}
@ -653,7 +653,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");
network::send_raw_data(leave_game_data.begin(), leave_game_data.size(), user->first,"game_control");
remove_player(user->first);
return user->first;
}
@ -690,7 +690,7 @@ void game::process_message(simple_wml::document& data, const player_map::iterato
<< user->second.name() << "> " << msg << "\n";
}
send_data(data, user->first);
send_data(data, user->first, "game_chat");
}
bool game::is_legal_command(const simple_wml::node& command, bool is_player) {
@ -786,7 +786,7 @@ bool game::process_turn(simple_wml::document& data, const player_map::const_iter
}
if (!repackage) {
record_data(data.clone());
send_data(data, user->first);
send_data(data, user->first, "game_turn");
return turn_ended;
}
for (command = commands.begin(); command != commands.end(); ++command) {
@ -795,7 +795,7 @@ bool game::process_turn(simple_wml::document& data, const player_map::const_iter
simple_wml::document* mdata = new simple_wml::document;
simple_wml::node& turn = mdata->root().add_child("turn");
(**command).copy_into(turn.add_child("command"));
send_data(*mdata, user->first);
send_data(*mdata, user->first, "game_turn");
record_data(mdata);
continue;
}
@ -821,13 +821,13 @@ bool game::process_turn(simple_wml::document& data, const player_map::const_iter
simple_wml::node& command = turn.add_child("command");
speak->copy_into(command.add_child("speak"));
if (team_name == "") {
send_data(*message, user->first);
send_data(*message, user->first,"game_chat");
record_data(message.release());
} else if (team_name == game_config::observer_team_name) {
send_data_observers(*message, user->first);
send_data_observers(*message, user->first,"game_chat");
record_data(message.release());
} else {
send_data_team(*message, team_name, user->first);
send_data_team(*message, team_name, user->first,"game_chat");
}
}
return turn_ended;
@ -894,18 +894,18 @@ 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);
send_data(observer_join, player, "game_observer");
}
DBG_GAME << debug_player_info();
// Send the user the game data.
//std::cerr << "SENDING LEVEL {{{" << level_.output() << "}}}\n";
simple_wml::string_span level_data = level_.output_compressed();
network::send_raw_data(level_data.begin(), level_data.size(), player,"game");
network::send_raw_data(level_data.begin(), level_data.size(), player,"game_level");
if(started_) {
//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");
network::send_raw_data(start_game.begin(), start_game.size(), player,"game_replay");
// 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.
@ -1034,7 +1034,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);
send_data(cfg, exclude, "game_user_list");
}
//! A member asks for the next scenario to advance to.
@ -1043,47 +1043,48 @@ 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");
network::send_raw_data(data.begin(), data.size(), user->first, "game_level");
// 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
void game::send_data(simple_wml::document& data, const network::connection exclude, const std::string& packet_type) const
{
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) {
if (*i != exclude) {
network::send_raw_data(s.begin(), s.size(), *i, "user_diff");
network::send_raw_data(s.begin(), s.size(), *i, packet_type);
}
}
}
void game::send_to_one(simple_wml::document& data, const network::connection sock) const
void game::send_to_one(simple_wml::document& data, const network::connection sock, const std::string& packet_type) const
{
simple_wml::string_span s = data.output_compressed();
network::send_raw_data(s.begin(), s.size(), sock,"game");
network::send_raw_data(s.begin(), s.size(), sock,packet_type);
}
void game::send_data_team(simple_wml::document& data,
const simple_wml::string_span& team,
const network::connection exclude) const
const network::connection exclude,
const std::string& packet_type) const
{
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)) {
network::send_raw_data(s.begin(), s.size(), *i, "game");
network::send_raw_data(s.begin(), s.size(), *i, packet_type);
}
}
}
void game::send_data_observers(simple_wml::document& data, const network::connection exclude) const {
void game::send_data_observers(simple_wml::document& data, const network::connection exclude, const std::string& packet_type) const {
simple_wml::string_span s = data.output_compressed();
for(user_vector::const_iterator i = observers_.begin(); i != observers_.end(); ++i) {
if (*i != exclude) {
network::send_raw_data(s.begin(), s.size(), *i,"game");
network::send_raw_data(s.begin(), s.size(), *i,packet_type);
}
}
}
@ -1123,11 +1124,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);
send_data(cfg, *ob, "game_observer");
} 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");
network::send_raw_data(data.begin(), data.size(), sock,"game_observer");
}
}
}
@ -1141,7 +1142,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);
send_data(observer_quit, observer->first, "game_ob_quit");
}
void game::send_history(const network::connection sock) const
@ -1257,7 +1258,7 @@ void game::send_and_record_server_message(const char* message,
{
simple_wml::document* doc = new simple_wml::document;
send_server_message(message, 0, doc);
send_data(*doc, exclude);
send_data(*doc, exclude, "server_message");
if (started_) record_data(doc);
}
@ -1265,7 +1266,7 @@ void game::send_server_message_to_all(const char* message, network::connection e
{
simple_wml::document doc;
send_server_message(message, 0, &doc);
send_data(doc, exclude);
send_data(doc, exclude, "server_message");
}
void game::send_server_message(const char* message, network::connection sock, simple_wml::document* docptr) const

View file

@ -92,8 +92,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;
void send_to_one(simple_wml::document& data, const network::connection sock) const;
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 record_data(simple_wml::document* data);
@ -139,8 +139,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;
void send_data_observers(simple_wml::document& data, const network::connection exclude=0) const;
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;
//! 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

@ -631,7 +631,7 @@ void server::run() {
simple_wml::document diff;
if(make_delete_diff(games_and_users_list_.root(), NULL, "user",
pl_it->second.config_address(), diff)) {
lobby_.send_data(diff, e.socket);
lobby_.send_data(diff, e.socket, "lobby_disc");
}
games_and_users_list_.root().remove_child("user",index);
@ -669,6 +669,9 @@ 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,
@ -826,7 +829,7 @@ void server::process_login(const network::connection sock,
// Send other players in the lobby the update that the player has joined
simple_wml::document diff;
make_add_diff(games_and_users_list_.root(), NULL, "user", diff);
lobby_.send_data(diff, sock);
lobby_.send_data(diff, sock, "lobby_login");
LOG_SERVER << network::ip_address(sock) << "\t" << username
<< "\thas logged on. (socket: " << sock << ")\n";
@ -1188,7 +1191,7 @@ void server::process_data_lobby(const network::connection sock,
simple_wml::document diff;
if(make_change_diff(games_and_users_list_.root(), NULL,
"user", pl->second.config_address(), diff)) {
lobby_.send_data(diff);
lobby_.send_data(diff, 0, "lobby_create_g");
}
return;
}
@ -1257,7 +1260,7 @@ void server::process_data_lobby(const network::connection sock,
bool diff2 = make_change_diff(games_and_users_list_.root(), NULL,
"user", pl->second.config_address(), diff);
if (diff1 || diff2) {
lobby_.send_data(diff);
lobby_.send_data(diff, 0,"lobby_join_g" );
}
}
@ -1395,7 +1398,7 @@ void server::process_data_game(const network::connection sock,
// Send the update of the game description to the lobby.
simple_wml::document diff;
make_add_diff(*games_and_users_list_.child("gamelist"), "gamelist", "game", diff);
lobby_.send_data(diff);
lobby_.send_data(diff,0,"lobby_start_g");
//! @todo FIXME: Why not save the level data in the history_?
return;
@ -1492,7 +1495,7 @@ void server::process_data_game(const network::connection sock,
// Send notification of the game starting immediately.
// g->start_game() will send data that assumes
// the [start_game] message has been sent
g->send_data(data, sock);
g->send_data(data, sock,"game_start");
g->start_game(pl);
//update the game having changed in the lobby
@ -1524,7 +1527,7 @@ void server::process_data_game(const network::connection sock,
bool diff2 = make_change_diff(games_and_users_list_.root(), NULL,
"user", pl->second.config_address(), diff);
if (diff1 || diff2) {
lobby_.send_data(diff, sock);
lobby_.send_data(diff, sock,"lobby_leave_g");
}
// Send the player who has quit the gamelist.
@ -1542,11 +1545,11 @@ void server::process_data_game(const network::connection sock,
if (g->describe_slots()) {
update_game_in_lobby(g);
}
g->send_data(data, sock);
g->send_data(data, sock,"game_start");
return;
// If a player changes his faction.
} else if (data.child("change_faction")) {
g->send_data(data, sock);
g->send_data(data, sock, "game_start");
return;
// If the owner of a side is changing the controller.
} else if (data.child("change_controller")) {
@ -1608,7 +1611,7 @@ void server::process_data_game(const network::connection sock,
// Data to store and broadcast.
} else if (data.child("stop_updates")) {
// if (g->started()) g->record_data(data);
g->send_data(data, sock);
g->send_data(data, sock,"game_start");
return;
// Data to ignore.
} else if (data.child("error")
@ -1667,16 +1670,16 @@ void server::delete_game(std::vector<game*>::iterator game_it) {
}
}
if (send_diff) {
lobby_.send_data(diff);
lobby_.send_data(diff,0,"lobby_delete_g");
}
//send users in the game a notification to leave the game since it has ended
static simple_wml::document leave_game_doc("[leave_game]\n[/leave_game]\n", simple_wml::INIT_COMPRESSED);
(*game_it)->send_data(leave_game_doc);
(*game_it)->send_data(leave_game_doc,0,"game_end");
// Put the remaining users back in the lobby.
lobby_.add_players(**game_it, true);
(*game_it)->send_data(games_and_users_list_);
(*game_it)->send_data(games_and_users_list_,0,"game_end");
delete *game_it;
games_.erase(game_it);
@ -1686,7 +1689,7 @@ void server::update_game_in_lobby(const game* g, network::connection exclude)
{
simple_wml::document diff;
if(make_change_diff(*games_and_users_list_.root().child("gamelist"), "gamelist", "game", g->description(), diff)) {
lobby_.send_data(diff, exclude);
lobby_.send_data(diff, exclude, "lobby_update_g");
}
}