Skip to content

Commit

Permalink
Also log the db_id.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pentarctagon committed Mar 15, 2020
1 parent f4b96d3 commit bc24ba4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
36 changes: 17 additions & 19 deletions src/server/game.cpp
Expand Up @@ -89,7 +89,7 @@ int game::db_id_num = 1;
void game::missing_user(socket_ptr /*socket*/, const std::string& func) const
{
WRN_GAME << func << "(): Could not find user (socket:\t<some C++ pointer>"
<< ") in player_info_ in game:\t\"" << name_ << "\" (" << id_ << ")\n";
<< ") in player_info_ in game:\t\"" << name_ << "\" (" << id_ << ", " << db_id_ << ")\n";
}

game::game(player_connections& player_connections,
Expand Down Expand Up @@ -249,7 +249,7 @@ void game::perform_controller_tweaks()
msg << "Side " << side_index + 1
<< " had no controller during controller tweaks! The host was assigned control.";

LOG_GAME << msg.str() << " (game id: " << id_ << ")\n";
LOG_GAME << msg.str() << " (game id: " << id_ << ", " << db_id_ << ")\n";
send_and_record_server_message(msg.str());
}

Expand Down Expand Up @@ -280,7 +280,7 @@ void game::perform_controller_tweaks()
if(sides_[side_index] == 0) {
std::stringstream msg;
msg << "Side " << side_index + 1 << " had no controller AFTER controller tweaks! Ruh Roh!";
LOG_GAME << msg.str() << " (game id: " << id_ << ")\n";
LOG_GAME << msg.str() << " (game id: " << id_ << ", " << db_id_ << ")\n";
}
}
}
Expand Down Expand Up @@ -311,10 +311,8 @@ void game::start_game(const socket_ptr& starter)
LOG_GAME
<< client_address(starter) << "\t" << player_connections_.find(starter)->name() << "\t"
<< (advance ? "advanced" : "started") << (save ? " reloaded" : "") << " game:\t\"" << name_ << "\" (" << id_
// << ") with: " << list_users(players_, __func__) << ". Settings: map: " << s["id"]
<< ") with: " << list_users(players_, __func__)
<< ", " << db_id_ << ") with: " << list_users(players_, __func__)
<< ". Settings: map: " << multiplayer["mp_scenario"]
// << "\tera: " << (s.child("era") ? (*s.child("era"))["id"] : "")
<< "\tera: " << multiplayer["mp_era"]
<< "\tXP: " << multiplayer["experience_modifier"]
<< "\tGPV: " << multiplayer["mp_village_gold"]
Expand Down Expand Up @@ -346,7 +344,7 @@ void game::start_game(const socket_ptr& starter)
<< " has no controller but should! The host needs to assign control for the game to proceed past "
"that side's turn.";

LOG_GAME << msg.str() << " (game id: " << id_ << ")\n";
LOG_GAME << msg.str() << " (game id: " << id_ << ", " << db_id_ << ")\n";
send_and_record_server_message(msg.str());
}
}
Expand Down Expand Up @@ -772,7 +770,7 @@ void game::mute_observer(const simple_wml::node& mute, const socket_ptr& muter)
}

LOG_GAME << client_address(muter) << "\t" << game::username(muter) << " muted: " << username << " ("
<< client_address(user) << ")\tin game:\t\"" << name_ << "\" (" << id_ << ")\n";
<< client_address(user) << ")\tin game:\t\"" << name_ << "\" (" << id_ << ", " << db_id_ << ")\n";

muted_observers_.push_back(user);
send_and_record_server_message(username.to_string() + " has been muted.");
Expand Down Expand Up @@ -804,7 +802,7 @@ void game::unmute_observer(const simple_wml::node& unmute, const socket_ptr& unm
}

LOG_GAME << client_address(unmuter) << "\t" << game::username(unmuter) << " unmuted: " << username << " ("
<< client_address(user) << ")\tin game:\t\"" << name_ << "\" (" << id_ << ")\n";
<< client_address(user) << ")\tin game:\t\"" << name_ << "\" (" << id_ << ", " << db_id_ << ")\n";

muted_observers_.erase(std::remove(muted_observers_.begin(), muted_observers_.end(), user), muted_observers_.end());
send_and_record_server_message(username.to_string() + " has been unmuted.");
Expand Down Expand Up @@ -838,7 +836,7 @@ socket_ptr game::kick_member(const simple_wml::node& kick, const socket_ptr& kic
}

LOG_GAME << client_address(kicker) << "\t" << game::username(kicker) << "\tkicked: " << username << " ("
<< client_address(user) << ")\tfrom game:\t\"" << name_ << "\" (" << id_ << ")\n";
<< client_address(user) << ")\tfrom game:\t\"" << name_ << "\" (" << id_ << ", " << db_id_ << ")\n";

send_and_record_server_message(username.to_string() + " has been kicked.");

Expand Down Expand Up @@ -873,7 +871,7 @@ socket_ptr game::ban_user(const simple_wml::node& ban, const socket_ptr& banner)
}

LOG_GAME << client_address(banner) << "\t" << game::username(banner) << "\tbanned: " << username << " ("
<< client_address(user) << ")\tfrom game:\t\"" << name_ << "\" (" << id_ << ")\n";
<< client_address(user) << ")\tfrom game:\t\"" << name_ << "\" (" << id_ << ", " << db_id_ << ")\n";

bans_.push_back(client_address(user));
name_bans_.push_back(username.to_string());
Expand Down Expand Up @@ -913,7 +911,7 @@ void game::unban_user(const simple_wml::node& unban, const socket_ptr& unbanner)
LOG_GAME
<< client_address(unbanner) << "\t" << player_connections_.find(unbanner)->info().name()
<< "\tunbanned: " << username << " (" << client_address(user) << ")\tfrom game:\t\"" << name_ << "\" ("
<< id_ << ")\n";
<< id_ << ", " << db_id_ << ")\n";

bans_.erase(std::remove(bans_.begin(), bans_.end(), client_address(user)), bans_.end());
name_bans_.erase(std::remove(name_bans_.begin(), name_bans_.end(), username.to_string()), name_bans_.end());
Expand Down Expand Up @@ -1021,17 +1019,17 @@ bool game::process_turn(simple_wml::document& data, const socket_ptr& user)
const simple_wml::node::child_list& commands = turn->children("command");

for(simple_wml::node* command : commands) {
DBG_GAME << "game " << id_ << " received [" << (*command).first_child() << "] from player '" << username(user)
DBG_GAME << "game " << id_ << ", " << db_id_ << " received [" << (*command).first_child() << "] from player '" << username(user)
<< "'(" << user << ") during turn " << current_side_index_ + 1 << "," << current_turn_ << "\n";
if(!is_legal_command(*command, user)) {
LOG_GAME << "ILLEGAL COMMAND in game: " << id_ << " (((" << simple_wml::node_to_string(*command)
LOG_GAME << "ILLEGAL COMMAND in game: " << id_ << ", " << db_id_ << " (((" << simple_wml::node_to_string(*command)
<< ")))\n";

std::stringstream msg;
msg << "Removing illegal command '" << (*command).first_child().to_string() << "' from: " << username(user)
<< ". Current player is: " << username(current_player()) << " (" << current_side_index_ + 1 << "/" << nsides_
<< ").";
LOG_GAME << msg.str() << " (socket: " << current_player() << ") (game id: " << id_ << ")\n";
LOG_GAME << msg.str() << " (socket: " << current_player() << ") (game id: " << id_ << ", " << db_id_ << ")\n";
send_and_record_server_message(msg.str());

marked.push_back(index - marked.size());
Expand Down Expand Up @@ -1437,7 +1435,7 @@ bool game::add_player(const socket_ptr& player, bool observer)

LOG_GAME
<< client_address(player) << "\t" << player_connections_.find(user)->info().name() << "\tjoined game:\t\""
<< name_ << "\" (" << id_ << ")" << (observer ? " as an observer" : "") << ". (socket: " << player
<< name_ << "\" (" << id_ << ", " << db_id_ << ")" << (observer ? " as an observer" : "") << ". (socket: " << player
<< ")\n";

player_connections_.find(user)->info().mark_available(id_, name_);
Expand Down Expand Up @@ -1501,7 +1499,7 @@ bool game::remove_player(const socket_ptr& player, const bool disconnect, const
<< client_address(user)
<< "\t" << player_connections_.find(user)->info().name()
<< ((game_ended && !(observer && destruct)) ? (started_ ? "\tended" : "\taborted") : "\thas left")
<< " game:\t\"" << name_ << "\" (" << id_ << ")"
<< " game:\t\"" << name_ << "\" (" << id_ << ", " << db_id_ << ")"
<< (game_ended && started_ && !(observer && destruct)
? " at turn: " + lexical_cast_default<std::string, std::size_t>(current_turn())
+ " with reason: '" + termination_reason() + "'"
Expand Down Expand Up @@ -1947,7 +1945,7 @@ const user_vector game::all_game_users() const
std::string game::debug_player_info() const
{
std::stringstream result;
result << "game id: " << id_ << "\n";
result << "game id: " << id_ << ", " << db_id_ << "\n";

// result << "players_.size: " << players_.size() << "\n";
for(const socket_ptr& p : players_) {
Expand Down Expand Up @@ -1981,7 +1979,7 @@ std::string game::debug_player_info() const
std::string game::debug_sides_info() const
{
std::stringstream result;
result << "game id: " << id_ << "\n";
result << "game id: " << id_ << ", " << db_id_ << "\n";
const simple_wml::node::child_list& sides = get_sides_list();

result << "\t\t level, server\n";
Expand Down
18 changes: 9 additions & 9 deletions src/server/server.cpp
Expand Up @@ -1326,7 +1326,7 @@ void server::cleanup_game(game* game_ptr)
gamelist->remove_child("game", index);
} else {
// Can happen when the game ends before the scenario was transferred.
LOG_SERVER << "Could not find game (" << game_ptr->id() << ") to delete in games_and_users_list_.\n";
LOG_SERVER << "Could not find game (" << game_ptr->id() << ", " << game_ptr->db_id() << ") to delete in games_and_users_list_.\n";
}

delete game_ptr;
Expand Down Expand Up @@ -1441,7 +1441,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml
// g.level() should then receive the full data for the game.
if(!g.level_init()) {
LOG_SERVER << client_address(socket) << "\t" << player.name() << "\tcreated game:\t\"" << g.name() << "\" ("
<< g.id() << ").\n";
<< g.id() << ", " << g.db_id() << ").\n";
// Update our config object which describes the open games,
// and save a pointer to the description in the new game.
simple_wml::node* const gamelist = games_and_users_list_.child("gamelist");
Expand All @@ -1454,7 +1454,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml
m->copy_into(desc);
} else {
WRN_SERVER << client_address(socket) << "\t" << player.name() << "\tsent scenario data in game:\t\""
<< g.name() << "\" (" << g.id() << ") without a 'multiplayer' child.\n";
<< g.name() << "\" (" << g.id() << ", " << g.db_id() << ") without a 'multiplayer' child.\n";
// Set the description so it can be removed in delete_game().
g.set_description(&desc);
delete_game(g.id());
Expand All @@ -1469,7 +1469,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml
desc.set_attr_dup("id", lexical_cast<std::string>(g.id()).c_str());
} else {
WRN_SERVER << client_address(socket) << "\t" << player.name() << "\tsent scenario data in game:\t\""
<< g.name() << "\" (" << g.id() << ") although it's already initialized.\n";
<< g.name() << "\" (" << g.id() << ", " << g.db_id() << ") although it's already initialized.\n";
return;
}

Expand Down Expand Up @@ -1542,7 +1542,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml
if(!g.level_init()) {
WRN_SERVER << client_address(socket) << "\tWarning: " << player.name()
<< "\tsent [store_next_scenario] in game:\t\"" << g.name() << "\" (" << g.id()
<< ") while the scenario is not yet initialized.";
<< ", " << g.db_id() << ") while the scenario is not yet initialized.";
return;
}

Expand All @@ -1561,7 +1561,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml

if(g.description() == nullptr) {
ERR_SERVER << client_address(socket) << "\tERROR: \"" << g.name() << "\" (" << g.id()
<< ") is initialized but has no description_.\n";
<< ", " << g.db_id() << ") is initialized but has no description_.\n";
return;
}

Expand All @@ -1572,7 +1572,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml
m->copy_into(desc);
} else {
WRN_SERVER << client_address(socket) << "\t" << player.name() << "\tsent scenario data in game:\t\""
<< g.name() << "\" (" << g.id() << ") without a 'multiplayer' child.\n";
<< g.name() << "\" (" << g.id() << ", " << g.db_id() << ") without a 'multiplayer' child.\n";

delete_game(g.id());

Expand Down Expand Up @@ -1816,7 +1816,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml
}

WRN_SERVER << client_address(socket) << "\tReceived unknown data from: " << player.name() << " (socket:" << socket
<< ") in game: \"" << g.name() << "\" (" << g.id() << ")\n"
<< ") in game: \"" << g.name() << "\" (" << g.id() << ", " << g.db_id() << ")\n"
<< data.output();
}

Expand Down Expand Up @@ -2859,7 +2859,7 @@ void server::stopgame(const std::string& /*issuer_name*/,
if(player != player_connections_.get<name_t>().end()){
std::shared_ptr<game> g = player->get_game();
if(g){
*out << "Player '" << nick << "' is in game with id '" << g->id() << "' named '" << g->name() << "'. Ending game for reason: '" << reason << "'...";
*out << "Player '" << nick << "' is in game with id '" << g->id() << ", " << g->db_id() << "' named '" << g->name() << "'. Ending game for reason: '" << reason << "'...";
delete_game(g->id(), reason);
} else {
*out << "Player '" << nick << "' is not currently in a game.";
Expand Down

0 comments on commit bc24ba4

Please sign in to comment.