Skip to content

Commit a582102

Browse files
committed
Bugfixes for kart queue + canRace is not invoked at 300 Hz now
Fixed addons not appearing, wrong type, and stopped invoking KartFilter for the second time when not ignoring the player
1 parent b5eeb68 commit a582102

File tree

4 files changed

+44
-29
lines changed

4 files changed

+44
-29
lines changed

src/network/protocols/command_manager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4228,7 +4228,7 @@ void CommandManager::add_to_queue(int x, int mask, bool to_front, std::string& s
42284228
}
42294229
else
42304230
{
4231-
get_queue(x).push_back(std::make_shared<KartFilter>(s));
4231+
get_queue(x).push_back(std::make_shared<T>(s));
42324232
// here you have to push to FRONT and not back because onetime
42334233
// queue should be invoked strictly before
42344234
if (another >= QM_START && !(mask & another))

src/network/protocols/server_lobby.cpp

+29-17
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,7 @@ void ServerLobby::asynchronousUpdate()
19851985
if (areKartFiltersIgnoringKarts())
19861986
current_kart = "";
19871987
std::string name = StringUtils::wideToUtf8(players[i]->getName());
1988-
players[i]->setKartName(getKartForBadKartChoice(name, current_kart));
1988+
players[i]->setKartName(getKartForBadKartChoice(players[i]->getPeer().get(), name, current_kart));
19891989
}
19901990

19911991
NetworkString* load_world_message = getLoadWorldMessage(players,
@@ -3192,7 +3192,7 @@ void ServerLobby::startSelection(const Event *event)
31923192
.addUInt8(ServerConfig::m_track_voting ? 1 : 0);
31933193

31943194

3195-
std::set<std::string> all_k = m_available_kts.first;
3195+
std::set<std::string> all_k = peer->getClientAssets().first;
31963196
std::string username = StringUtils::wideToUtf8(peer->getPlayerProfiles()[0]->getName());
31973197
// std::string username = StringUtils::wideToUtf8(profile->getName());
31983198
applyAllKartFilters(username, all_k);
@@ -6345,7 +6345,7 @@ void ServerLobby::setPlayerKarts(const NetworkString& ns, STKPeer* peer) const
63456345
if (areKartFiltersIgnoringKarts())
63466346
current_kart = "";
63476347
std::string name = StringUtils::wideToUtf8(peer->getPlayerProfiles()[i]->getName());
6348-
peer->getPlayerProfiles()[i]->setKartName(getKartForBadKartChoice(name, current_kart));
6348+
peer->getPlayerProfiles()[i]->setKartName(getKartForBadKartChoice(peer, name, current_kart));
63496349
}
63506350
if (peer->getClientCapabilities().find("real_addon_karts") ==
63516351
peer->getClientCapabilities().end() || ns.size() == 0)
@@ -6564,6 +6564,7 @@ std::set<STKPeer*>& ServerLobby::getSpectatorsByLimit(bool update)
65646564
if (!update)
65656565
return m_spectators_by_limit;
65666566

6567+
m_peers_ability_to_play.clear();
65676568
m_spectators_by_limit.clear();
65686569

65696570
auto peers = STKHost::get()->getPeers();
@@ -6655,7 +6656,7 @@ bool ServerLobby::supportsAI()
66556656
} // supportsAI
66566657

66576658
//-----------------------------------------------------------------------------
6658-
bool ServerLobby::checkPeersReady(bool ignore_ai_peer) const
6659+
bool ServerLobby::checkPeersReady(bool ignore_ai_peer)
66596660
{
66606661
bool all_ready = true;
66616662
bool someone_races = false;
@@ -7256,45 +7257,52 @@ void ServerLobby::sendStringToAllPeers(std::string& s)
72567257
delete chat;
72577258
} // sendStringToAllPeers
72587259
//-----------------------------------------------------------------------------
7259-
bool ServerLobby::canRace(std::shared_ptr<STKPeer>& peer) const
7260+
bool ServerLobby::canRace(std::shared_ptr<STKPeer>& peer)
72607261
{
72617262
return canRace(peer.get());
72627263
} // canRace
72637264
//-----------------------------------------------------------------------------
7264-
bool ServerLobby::canRace(STKPeer* peer) const
7265+
bool ServerLobby::canRace(STKPeer* peer)
72657266
{
7267+
auto it = m_peers_ability_to_play.find(peer);
7268+
if (it != m_peers_ability_to_play.end())
7269+
return it->second;
7270+
72667271
if (!peer || peer->getPlayerProfiles().empty())
7267-
return false;
7272+
return m_peers_ability_to_play[peer] = false;
72687273
std::string username = StringUtils::wideToUtf8(
72697274
peer->getPlayerProfiles()[0]->getName());
72707275
if (ServerConfig::m_soccer_tournament)
72717276
{
72727277
if (m_tournament_red_players.count(username) == 0 &&
72737278
m_tournament_blue_players.count(username) == 0)
7274-
return false;
7279+
return m_peers_ability_to_play[peer] = false;
72757280
}
72767281
else if (m_spectators_by_limit.find(peer) != m_spectators_by_limit.end())
7277-
return false;
7282+
return m_peers_ability_to_play[peer] = false;
72787283

72797284
std::set<std::string> maps = peer->getClientAssets().second;
72807285
std::set<std::string> karts = peer->getClientAssets().first;
72817286

72827287
applyAllFilters(maps, true);
72837288
applyAllKartFilters(username, karts, false);
72847289

7290+
if (maps.empty() || karts.empty())
7291+
return m_peers_ability_to_play[peer] = false;
7292+
72857293
if (!m_play_requirement_tracks.empty())
72867294
for (const std::string& track: m_play_requirement_tracks)
72877295
if (peer->getClientAssets().second.count(track) == 0)
7288-
return false;
7296+
return m_peers_ability_to_play[peer] = false;
72897297
if (peer->addon_karts_count < ServerConfig::m_addon_karts_play_threshold)
7290-
return false;
7298+
return m_peers_ability_to_play[peer] = false;
72917299
if (peer->addon_tracks_count < ServerConfig::m_addon_tracks_play_threshold)
7292-
return false;
7300+
return m_peers_ability_to_play[peer] = false;
72937301
if (peer->addon_arenas_count < ServerConfig::m_addon_arenas_play_threshold)
7294-
return false;
7302+
return m_peers_ability_to_play[peer] = false;
72957303
if (peer->addon_soccers_count < ServerConfig::m_addon_soccers_play_threshold)
7296-
return false;
7297-
return true;
7304+
return m_peers_ability_to_play[peer] = false;
7305+
return m_peers_ability_to_play[peer] = true;
72987306
} // canRace
72997307
//-----------------------------------------------------------------------------
73007308
bool ServerLobby::canVote(std::shared_ptr<STKPeer>& peer) const
@@ -8218,9 +8226,13 @@ void ServerLobby::applyAllFilters(std::set<std::string>& maps, bool use_history)
82188226
}
82198227
track_context.wildcards = m_map_history;
82208228
if (!m_onetime_tracks_queue.empty())
8229+
{
82218230
m_onetime_tracks_queue.front()->apply(track_context);
8231+
}
82228232
if (!m_cyclic_tracks_queue.empty())
8233+
{
82238234
m_cyclic_tracks_queue.front()->apply(track_context);
8235+
}
82248236
}
82258237
swap(maps, track_context.elements);
82268238
} // applyAllFilters
@@ -8257,9 +8269,9 @@ bool ServerLobby::areKartFiltersIgnoringKarts() const
82578269
return false;
82588270
} // applyAllKartFilters
82598271
//-----------------------------------------------------------------------------
8260-
std::string ServerLobby::getKartForBadKartChoice(const std::string& username, const std::string& check_choice) const
8272+
std::string ServerLobby::getKartForBadKartChoice(STKPeer* peer, const std::string& username, const std::string& check_choice) const
82618273
{
8262-
std::set<std::string> karts = m_available_kts.first;
8274+
std::set<std::string> karts = peer->getClientAssets().first;
82638275
applyAllKartFilters(username, karts, true);
82648276
if (m_kart_elimination.isEliminated(username)
82658277
&& karts.count(m_kart_elimination.getKart()))

src/network/protocols/server_lobby.hpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ class ServerLobby : public LobbyProtocol
312312

313313
std::set<STKPeer*> m_team_speakers;
314314

315+
std::map<STKPeer*, bool> m_peers_ability_to_play;
316+
315317
KartElimination m_kart_elimination;
316318

317319
std::set<int> m_available_difficulties;
@@ -465,7 +467,7 @@ class ServerLobby : public LobbyProtocol
465467
void handleServerConfiguration(std::shared_ptr<STKPeer> peer,
466468
int difficulty, int mode, bool soccer_goal_target);
467469
void updateTracksForMode();
468-
bool checkPeersReady(bool ignore_ai_peer) const;
470+
bool checkPeersReady(bool ignore_ai_peer);
469471
void resetPeersReady()
470472
{
471473
for (auto it = m_peers_ready.begin(); it != m_peers_ready.end();)
@@ -571,8 +573,8 @@ class ServerLobby : public LobbyProtocol
571573
void initCategories();
572574
void initTournamentPlayers();
573575
void changeColors();
574-
bool canRace(std::shared_ptr<STKPeer>& peer) const;
575-
bool canRace(STKPeer* peer) const;
576+
bool canRace(std::shared_ptr<STKPeer>& peer);
577+
bool canRace(STKPeer* peer);
576578
bool canVote(std::shared_ptr<STKPeer>& peer) const;
577579
bool canVote(STKPeer* peer) const;
578580
bool hasHostRights(std::shared_ptr<STKPeer>& peer) const;
@@ -683,7 +685,7 @@ class ServerLobby : public LobbyProtocol
683685
void applyAllFilters(std::set<std::string>& maps, bool use_history) const;
684686
void applyAllKartFilters(const std::string& username, std::set<std::string>& karts, bool afterSelection = false) const;
685687
bool areKartFiltersIgnoringKarts() const;
686-
std::string getKartForBadKartChoice(const std::string& username, const std::string& check_choice) const;
688+
std::string getKartForBadKartChoice(STKPeer* peer, const std::string& username, const std::string& check_choice) const;
687689

688690
static int m_default_fixed_laps;
689691
}; // class ServerLobby

src/utils/track_filter.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,10 @@ void KartFilter::apply(FilterContext& context) const
420420
// return;
421421
// }
422422

423+
424+
if (!m_ignore_players_input && !context.applied_at_selection_start)
425+
return;
426+
423427
// Ignoring means that the random of allowed and randoms will be picked afterwards
424428
// Not ignoring means that the player chooses from allowed
425429
// and one instance of each random
@@ -492,20 +496,17 @@ void KartFilter::apply(FilterContext& context) const
492496
for (const std::string& kart: array)
493497
{
494498
if (m_forbidden_karts.count(kart) > 0)
499+
{
495500
continue;
496-
// if (m_allowed_karts.count(kart) == 0 && !m_allow_unspecified_karts)
497-
// continue;
501+
}
498502
if (context.elements.count(kart) == 0)
503+
{
499504
continue;
505+
}
500506
result.insert(kart);
501507
}
502508
}
503509
}
504-
else
505-
{
506-
Log::warn("TrackFilter", "Not ignoring player's input but was invoked for the second time");
507-
// should not happen
508-
}
509510
std::swap(result, context.elements);
510511
} // KartFilter::apply
511512
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)