Skip to content
Merged
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
19 changes: 16 additions & 3 deletions src/network/protocols/server_lobby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,13 @@ void ServerLobby::liveJoinRequest(Event* event)
if (!spectator)
{
auto spectators_by_limit = getSpectatorsByLimit();
setPlayerKarts(data, peer);
if (!setPlayerKarts(data, peer))
{
// The kart list is part of the live-join request. Do not continue
// with uninitialised kart data after rejecting a malformed list.
rejectLiveJoin(peer, BLR_NONE);
return;
}

std::vector<int> used_id;
for (unsigned i = 0; i < peer->getPlayerProfiles().size(); i++)
Expand Down Expand Up @@ -4167,9 +4173,15 @@ void ServerLobby::addLiveJoinPlaceholder(
} // addLiveJoinPlaceholder

//-----------------------------------------------------------------------------
void ServerLobby::setPlayerKarts(const NetworkString& ns, STKPeer* peer) const
bool ServerLobby::setPlayerKarts(const NetworkString& ns, STKPeer* peer) const
{
unsigned player_count = ns.getUInt8();
if (player_count > peer->getPlayerProfiles().size())
{
Log::warn("ServerLobby", "Too many kart entries from %s.",
peer->getAddress().toString().c_str());
return false;
}
for (unsigned i = 0; i < player_count; i++)
{
std::string kart;
Expand All @@ -4192,7 +4204,7 @@ void ServerLobby::setPlayerKarts(const NetworkString& ns, STKPeer* peer) const
}
if (peer->getClientCapabilities().find("real_addon_karts") ==
peer->getClientCapabilities().end() || ns.size() == 0)
return;
return true;
for (unsigned i = 0; i < player_count; i++)
{
KartData kart_data(ns);
Expand All @@ -4219,6 +4231,7 @@ void ServerLobby::setPlayerKarts(const NetworkString& ns, STKPeer* peer) const
player->setKartData(kart_data);
}
}
return true;
} // setPlayerKarts

//-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/network/protocols/server_lobby.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class ServerLobby : public LobbyProtocol
void encodePlayers(BareNetworkString* bns,
std::vector<std::shared_ptr<NetworkPlayerProfile> >& players) const;
std::vector<std::shared_ptr<NetworkPlayerProfile> > getLivePlayers() const;
void setPlayerKarts(const NetworkString& ns, STKPeer* peer) const;
bool setPlayerKarts(const NetworkString& ns, STKPeer* peer) const;
bool handleAssets(const NetworkString& ns, STKPeer* peer);
void liveJoinRequest(Event* event);
void rejectLiveJoin(STKPeer* peer, BackLobbyReason blr);
Expand Down