From 5533b22e4dc9e6369fc489e077f36740e9403019 Mon Sep 17 00:00:00 2001 From: kimden <23140380+kimden@users.noreply.github.com> Date: Sun, 1 Jun 2025 13:36:52 +0400 Subject: [PATCH 1/2] Don't ask for GameInfo when no game, add some fields --- src/network/protocols/server_lobby.cpp | 4 ++-- src/utils/game_info.cpp | 5 +++-- src/utils/game_info.hpp | 6 ++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/network/protocols/server_lobby.cpp b/src/network/protocols/server_lobby.cpp index 73eed8b0d04..38346ac8c6a 100644 --- a/src/network/protocols/server_lobby.cpp +++ b/src/network/protocols/server_lobby.cpp @@ -2165,7 +2165,7 @@ void ServerLobby::clientDisconnected(Event* event) if (w) m_game_info->saveDisconnectingPeerInfo(peer); } - else + else if (m_state.load() != WAITING_FOR_START_GAME) Log::warn("ServerLobby", "GameInfo is not accessible??"); NetworkString* msg = getNetworkString(2); @@ -3811,7 +3811,7 @@ void ServerLobby::handlePlayerDisconnection() const if (m_game_info) m_game_info->saveDisconnectingIdInfo(i); - else + else if (m_state.load() != WAITING_FOR_START_GAME) Log::warn("ServerLobby", "GameInfo is not accessible??"); rki.makeReserved(); diff --git a/src/utils/game_info.cpp b/src/utils/game_info.cpp index 7c441612406..18443eca55f 100644 --- a/src/utils/game_info.cpp +++ b/src/utils/game_info.cpp @@ -65,6 +65,7 @@ namespace //----------------------------------------------------------------------------- + void GameInfo::setPowerupString(const std::string&& str) { if (str == g_default_powerup_string) @@ -72,8 +73,8 @@ void GameInfo::setPowerupString(const std::string&& str) else m_powerup_string = str; } // setPowerupString - //----------------------------------------------------------------------------- + void GameInfo::setKartCharString(const std::string&& str) { if (str == g_default_kart_char_string) @@ -532,4 +533,4 @@ void GameInfo::onGoalScored(bool correct_goal, const irr::core::stringw& name, m_player_info[kart_id].m_result += info.m_result; } } // onGoalScored -//----------------------------------------------------------------------------- \ No newline at end of file +//----------------------------------------------------------------------------- diff --git a/src/utils/game_info.hpp b/src/utils/game_info.hpp index e827450ffbc..549350c2471 100644 --- a/src/utils/game_info.hpp +++ b/src/utils/game_info.hpp @@ -57,6 +57,12 @@ struct GameInfo: public LobbyContextUser double m_game_duration = -1; int m_handicap = 0; std::string m_country_code = ""; + + std::string m_vote_map = ""; + int m_vote_limit = -1; + std::string m_vote_reverse = ""; + std::string m_vote_kart = ""; + std::string m_other_info = ""; PlayerInfo(bool reserved = false, bool game_event = false): From b5acbadd31eb6338c501ca63dece14848abcfd89 Mon Sep 17 00:00:00 2001 From: kimden <23140380+kimden@users.noreply.github.com> Date: Sun, 8 Jun 2025 02:21:34 +0400 Subject: [PATCH 2/2] Take vote and kart selection info and store it somewhere for now --- src/network/protocols/server_lobby.cpp | 50 +++++++++++++++++--------- src/utils/game_info.cpp | 28 +++++++++++++++ src/utils/game_info.hpp | 24 ++++++++++--- 3 files changed, 81 insertions(+), 21 deletions(-) diff --git a/src/network/protocols/server_lobby.cpp b/src/network/protocols/server_lobby.cpp index 38346ac8c6a..e98a0e9660b 100644 --- a/src/network/protocols/server_lobby.cpp +++ b/src/network/protocols/server_lobby.cpp @@ -968,9 +968,10 @@ void ServerLobby::asynchronousUpdate() } } } - m_game_info = std::make_shared(); - m_game_info->setContext(m_lobby_context.get()); - m_game_info->fillFromRaceManager(); + if (m_game_info) + m_game_info->fillFromRaceManager(); + else + Log::error("ServerLobby", "No GameInfo available for fillFromRaceManager??"); } break; } @@ -1269,7 +1270,7 @@ void ServerLobby::finishedLoadingLiveJoinClient(Event* event) if (m_game_info) points = m_game_info->onLiveJoinedPlayer(id, rki, w); else - Log::warn("ServerLobby", "GameInfo is not accessible??"); + Log::error("ServerLobby", "No GameInfo available for onLiveJoinedPlayer??"); // If the mode is not battle/CTF, points are 0. // I assume it's fine like that for now @@ -1882,6 +1883,9 @@ void ServerLobby::startSelection(const Event *event) startVotingPeriod(getSettings()->getVotingTimeout()); + m_game_info = std::make_shared(); + m_game_info->setContext(m_lobby_context.get()); + peers = STKHost::get()->getPeers(); for (auto& peer: peers) { @@ -2074,7 +2078,7 @@ void ServerLobby::checkRaceFinished() if (m_game_info) m_game_info->fillAndStoreResults(); else - Log::warn("ServerLobby", "GameInfo is not accessible??"); + Log::error("ServerLobby", "No GameInfo available for fillAndStoreResults??"); } if (getSettings()->isRanked()) @@ -2166,7 +2170,7 @@ void ServerLobby::clientDisconnected(Event* event) m_game_info->saveDisconnectingPeerInfo(peer); } else if (m_state.load() != WAITING_FOR_START_GAME) - Log::warn("ServerLobby", "GameInfo is not accessible??"); + Log::error("ServerLobby", "No GameInfo available for saveDisconnectingPeerInfo in clientDisconnected??"); NetworkString* msg = getNetworkString(2); const bool waiting_peer_disconnected = @@ -3043,17 +3047,19 @@ void ServerLobby::handlePlayerVote(Event* event) // Remove / adjust any invalid settings if (isTournament()) - { getTournament()->applyRestrictionsOnVote(&vote); - } else - { getSettings()->applyRestrictionsOnVote(&vote, t); - } // Store vote: - vote.m_player_name = event->getPeer()->getMainProfile()->getName(); - addVote(event->getPeer()->getHostId(), vote); + auto peer = event->getPeerSP(); + vote.m_player_name = peer->getMainProfile()->getName(); + addVote(peer->getHostId(), vote); + + if (m_game_info) + m_game_info->addVote(peer, vote); + else + Log::error("ServerLobby", "No GameInfo available for setVote??"); // After adding the vote, show decorated name instead vote.m_player_name = event->getPeer()->getMainProfile()->getDecoratedName(m_name_decorator); @@ -3812,7 +3818,7 @@ void ServerLobby::handlePlayerDisconnection() const if (m_game_info) m_game_info->saveDisconnectingIdInfo(i); else if (m_state.load() != WAITING_FOR_START_GAME) - Log::warn("ServerLobby", "GameInfo is not accessible??"); + Log::error("ServerLobby", "No GameInfo available for saveDisconnectingIdInfo in handlePlayerDisconnection??"); rki.makeReserved(); @@ -3909,6 +3915,7 @@ void ServerLobby::setPlayerKarts(const NetworkString& ns, std::shared_ptrgetPlayerProfiles().size()); + std::vector final_kart_names; for (unsigned i = 0; i < player_count; i++) { std::string kart; @@ -3930,9 +3937,20 @@ void ServerLobby::setPlayerKarts(const NetworkString& ns, std::shared_ptrareKartFiltersIgnoringKarts()) current_kart = ""; std::string name = StringUtils::wideToUtf8(peer->getPlayerProfiles()[i]->getName()); - peer->getPlayerProfiles()[i]->setKartName( - getAssetManager()->getKartForBadKartChoice(peer, name, current_kart)); + + std::string set_kart_name = getAssetManager()->getKartForBadKartChoice(peer, name, current_kart); + final_kart_names.push_back(set_kart_name); + peer->getPlayerProfiles()[i]->setKartName(set_kart_name); } + + if (m_game_info) + { + for (unsigned i = 0; i < player_count; i++) + m_game_info->setKarts(peer, final_kart_names); + } + else + Log::error("ServerLobby", "No GameInfo available for setKart??"); + if (peer->getClientCapabilities().find("real_addon_karts") == peer->getClientCapabilities().end() || ns.size() == 0) return; @@ -4037,7 +4055,7 @@ void ServerLobby::clientInGameWantsToBackLobby(Event* event) if (m_game_info) m_game_info->saveDisconnectingPeerInfo(peer); else - Log::warn("ServerLobby", "GameInfo is not accessible??"); + Log::error("ServerLobby", "No GameInfo available for saveDisconnectingPeerInfo in clientInGameWantsToBackLobby??"); for (const int id : peer->getAvailableKartIDs()) { diff --git a/src/utils/game_info.cpp b/src/utils/game_info.cpp index 18443eca55f..64e34b03d26 100644 --- a/src/utils/game_info.cpp +++ b/src/utils/game_info.cpp @@ -29,6 +29,7 @@ #include "network/database_connector.hpp" #include "network/network_player_profile.hpp" #include "network/protocols/server_lobby.hpp" +#include "network/peer_vote.hpp" #include "network/race_event_manager.hpp" #include "network/remote_kart_info.hpp" #include "network/stk_peer.hpp" @@ -534,3 +535,30 @@ void GameInfo::onGoalScored(bool correct_goal, const irr::core::stringw& name, } } // onGoalScored //----------------------------------------------------------------------------- + +void GameInfo::addVote(std::shared_ptr& peer, PeerVote& vote) +{ + if (!peer) + { + Log::error("GameInfo", "addVote: peer no longer exists"); + return; + } + auto& data = m_pre_game_data[peer->getHostId()]; + data.m_vote_map = vote.m_track_name; + data.m_vote_limit = vote.m_num_laps; + data.m_vote_reverse = vote.m_reverse; +} // addVote +//----------------------------------------------------------------------------- + +void GameInfo::setKarts(std::shared_ptr& peer, + std::vector& final_kart_names) +{ + if (!peer) + { + Log::error("GameInfo", "setKarts: peer no longer exists"); + return; + } + auto& data = m_pre_game_data[peer->getHostId()]; + data.m_vote_kart = final_kart_names; +} // setKarts +//----------------------------------------------------------------------------- diff --git a/src/utils/game_info.hpp b/src/utils/game_info.hpp index 549350c2471..9ef14481872 100644 --- a/src/utils/game_info.hpp +++ b/src/utils/game_info.hpp @@ -29,6 +29,7 @@ class RemoteKartInfo; class STKPeer; class World; +class PeerVote; /** A simple structure to store the info about the game. * It includes game settings, the results of individual players, as well as @@ -36,6 +37,15 @@ class World; */ struct GameInfo: public LobbyContextUser { + struct PlayerVoteInfo + { + std::string m_vote_map = ""; // not yet in db + int m_vote_limit = -1; // not yet in db + std::string m_vote_reverse = ""; // not yet in db + std::vector m_vote_kart = {}; // not yet in db + // Make sure there's only one kart at the end + }; + struct PlayerInfo { bool m_reserved; @@ -57,11 +67,7 @@ struct GameInfo: public LobbyContextUser double m_game_duration = -1; int m_handicap = 0; std::string m_country_code = ""; - - std::string m_vote_map = ""; - int m_vote_limit = -1; - std::string m_vote_reverse = ""; - std::string m_vote_kart = ""; + PlayerVoteInfo m_vote_info; std::string m_other_info = ""; @@ -84,6 +90,9 @@ struct GameInfo: public LobbyContextUser int m_flag_deactivated_time; int m_difficulty; std::string m_timestamp; + std::string m_room_number; // not yet in db + + std::map m_pre_game_data; // First RaceManager->getNumPlayers() elements in m_player_info // correspond to RaceManager->m_player_karts with the same index @@ -108,6 +117,11 @@ struct GameInfo: public LobbyContextUser void onGoalScored(bool correct_goal, const irr::core::stringw& name, int kart_id, unsigned start_pos, float time_since_start); + + void addVote(std::shared_ptr& peer, PeerVote& vote); + + void setKarts(std::shared_ptr& peer, + std::vector& final_kart_names); }; #endif