Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions src/network/protocols/server_lobby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,9 +968,10 @@ void ServerLobby::asynchronousUpdate()
}
}
}
m_game_info = std::make_shared<GameInfo>();
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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1882,6 +1883,9 @@ void ServerLobby::startSelection(const Event *event)

startVotingPeriod(getSettings()->getVotingTimeout());

m_game_info = std::make_shared<GameInfo>();
m_game_info->setContext(m_lobby_context.get());

peers = STKHost::get()->getPeers();
for (auto& peer: peers)
{
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -2165,8 +2169,8 @@ void ServerLobby::clientDisconnected(Event* event)
if (w)
m_game_info->saveDisconnectingPeerInfo(peer);
}
else
Log::warn("ServerLobby", "GameInfo is not accessible??");
else if (m_state.load() != WAITING_FOR_START_GAME)
Log::error("ServerLobby", "No GameInfo available for saveDisconnectingPeerInfo in clientDisconnected??");

NetworkString* msg = getNetworkString(2);
const bool waiting_peer_disconnected =
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -3811,8 +3817,8 @@ void ServerLobby::handlePlayerDisconnection() const

if (m_game_info)
m_game_info->saveDisconnectingIdInfo(i);
else
Log::warn("ServerLobby", "GameInfo is not accessible??");
else if (m_state.load() != WAITING_FOR_START_GAME)
Log::error("ServerLobby", "No GameInfo available for saveDisconnectingIdInfo in handlePlayerDisconnection??");

rki.makeReserved();

Expand Down Expand Up @@ -3909,6 +3915,7 @@ void ServerLobby::setPlayerKarts(const NetworkString& ns, std::shared_ptr<STKPee
{
unsigned player_count = ns.getUInt8();
player_count = std::min(player_count, (unsigned)peer->getPlayerProfiles().size());
std::vector<std::string> final_kart_names;
for (unsigned i = 0; i < player_count; i++)
{
std::string kart;
Expand All @@ -3930,9 +3937,20 @@ void ServerLobby::setPlayerKarts(const NetworkString& ns, std::shared_ptr<STKPee
if (getQueues()->areKartFiltersIgnoringKarts())
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;
Expand Down Expand Up @@ -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())
{
Expand Down
33 changes: 31 additions & 2 deletions src/utils/game_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -65,15 +66,16 @@ namespace


//-----------------------------------------------------------------------------

void GameInfo::setPowerupString(const std::string&& str)
{
if (str == g_default_powerup_string)
m_powerup_string = "";
else
m_powerup_string = str;
} // setPowerupString

//-----------------------------------------------------------------------------

void GameInfo::setKartCharString(const std::string&& str)
{
if (str == g_default_kart_char_string)
Expand Down Expand Up @@ -532,4 +534,31 @@ void GameInfo::onGoalScored(bool correct_goal, const irr::core::stringw& name,
m_player_info[kart_id].m_result += info.m_result;
}
} // onGoalScored
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

void GameInfo::addVote(std::shared_ptr<STKPeer>& 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<STKPeer>& peer,
std::vector<std::string>& 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
//-----------------------------------------------------------------------------
20 changes: 20 additions & 0 deletions src/utils/game_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,23 @@
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
* important team game events like flag captures or goals.
*/
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<std::string> m_vote_kart = {}; // not yet in db
// Make sure there's only one kart at the end
};

struct PlayerInfo
{
bool m_reserved;
Expand All @@ -57,6 +67,8 @@ struct GameInfo: public LobbyContextUser
double m_game_duration = -1;
int m_handicap = 0;
std::string m_country_code = "";
PlayerVoteInfo m_vote_info;

std::string m_other_info = "";

PlayerInfo(bool reserved = false, bool game_event = false):
Expand All @@ -78,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<uint32_t, PlayerVoteInfo> m_pre_game_data;

// First RaceManager->getNumPlayers() elements in m_player_info
// correspond to RaceManager->m_player_karts with the same index
Expand All @@ -102,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<STKPeer>& peer, PeerVote& vote);

void setKarts(std::shared_ptr<STKPeer>& peer,
std::vector<std::string>& final_kart_names);
};

#endif
Loading