Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4997 #5149

Merged
merged 1 commit into from
Aug 11, 2024
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
40 changes: 35 additions & 5 deletions src/network/protocols/server_lobby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,9 +968,30 @@ void ServerLobby::asynchronousUpdate()
m_item_seed = (uint32_t)StkTime::getTimeSinceEpoch();
ItemManager::updateRandomSeed(m_item_seed);
m_game_setup->setRace(winner_vote);

// For spectators that don't have the track, remember their
// spectate mode and don't load the track
std::string track_name = winner_vote.m_track_name;
auto peers = STKHost::get()->getPeers();
std::map<std::shared_ptr<STKPeer>,
AlwaysSpectateMode> previous_spectate_mode;
for (auto peer : peers)
{
if (peer->alwaysSpectate() &&
peer->getClientAssets().second.count(track_name) == 0)
{
previous_spectate_mode[peer] = peer->getAlwaysSpectate();
peer->setAlwaysSpectate(ASM_NONE);
peer->setWaitingForGame(true);
m_peers_ready.erase(peer);
}
}
bool has_always_on_spectators = false;
auto players = STKHost::get()
->getPlayersForNewGame(&has_always_on_spectators);
for (auto& p: previous_spectate_mode)
if (p.first)
p.first->setAlwaysSpectate(p.second);
auto ai_instance = m_ai_peer.lock();
if (supportsAI())
{
Expand Down Expand Up @@ -1861,17 +1882,14 @@ void ServerLobby::startSelection(const Event *event)
}
}

// Remove karts / tracks from server that are not supported on all clients
std::set<std::string> karts_erase, tracks_erase;
// Find if there are peers playing the game
auto peers = STKHost::get()->getPeers();
std::set<STKPeer*> always_spectate_peers;
bool has_peer_plays_game = false;
for (auto peer : peers)
{
if (!peer->isValidated() || peer->isWaitingForGame())
continue;
peer->eraseServerKarts(m_available_kts.first, karts_erase);
peer->eraseServerTracks(m_available_kts.second, tracks_erase);
if (peer->alwaysSpectate())
always_spectate_peers.insert(peer.get());
else if (!peer->isAIPeer())
Expand Down Expand Up @@ -1906,13 +1924,25 @@ void ServerLobby::startSelection(const Event *event)
"spectate for late coming players!");
return;
}
for(auto &peer : spectators_by_limit)
for (auto &peer : spectators_by_limit)
{
peer->setAlwaysSpectate(ASM_FULL);
peer->setWaitingForGame(true);
always_spectate_peers.insert(peer.get());
}

// Remove karts / tracks from server that are not supported
// on all clients that are playing
std::set<std::string> karts_erase, tracks_erase;
for (auto peer : peers)
{
// Spectators won't remove maps as they are already waiting for game
if (!peer->isValidated() || peer->isWaitingForGame())
continue;
peer->eraseServerKarts(m_available_kts.first, karts_erase);
peer->eraseServerTracks(m_available_kts.second, tracks_erase);
}

for (const std::string& kart_erase : karts_erase)
{
m_available_kts.first.erase(kart_erase);
Expand Down
3 changes: 3 additions & 0 deletions src/network/stk_peer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ class STKPeer : public NoCopy
void setAlwaysSpectate(AlwaysSpectateMode mode)
{ m_always_spectate.store(mode); }
// ------------------------------------------------------------------------
AlwaysSpectateMode getAlwaysSpectate() const
{ return (AlwaysSpectateMode)m_always_spectate.load(); }
// ------------------------------------------------------------------------
bool alwaysSpectate() const
{ return m_always_spectate.load() != ASM_NONE; }
// ------------------------------------------------------------------------
Expand Down
Loading