|
35 | 35 | #include "utils/file_utils.hpp"
|
36 | 36 | #include "utils/hit_processor.hpp"
|
37 | 37 | #include "utils/hourglass_reason.hpp"
|
| 38 | +#include "utils/lobby_asset_manager.hpp" |
38 | 39 | #include "utils/log.hpp"
|
39 | 40 | #include "utils/random_generator.hpp"
|
40 | 41 | #include "utils/string_utils.hpp"
|
@@ -608,6 +609,8 @@ CommandManager::CommandManager(ServerLobby* lobby):
|
608 | 609 | initCommands();
|
609 | 610 | initAssets();
|
610 | 611 |
|
| 612 | + m_asset_manager = lobby->getLobbyAssetManager(); |
| 613 | + |
611 | 614 | m_aux_mode_aliases = {
|
612 | 615 | {"m0"},
|
613 | 616 | {"m1"},
|
@@ -1313,10 +1316,10 @@ void CommandManager::process_addons(Context& context)
|
1313 | 1316 | // removed const reference so that I can modify `from`
|
1314 | 1317 | // without changing the original container, we copy everything anyway
|
1315 | 1318 | std::set<std::string> from =
|
1316 |
| - (argv[1] == "kart" ? m_lobby->m_addon_kts.first : |
1317 |
| - (argv[1] == "track" ? m_lobby->m_addon_kts.second : |
1318 |
| - (argv[1] == "arena" ? m_lobby->m_addon_arenas : |
1319 |
| - /*argv[1] == "soccer" ?*/ m_lobby->m_addon_soccers |
| 1319 | + (argv[1] == "kart" ? m_asset_manager->getAddonKarts() : |
| 1320 | + (argv[1] == "track" ? m_asset_manager->getAddonTracks() : |
| 1321 | + (argv[1] == "arena" ? m_asset_manager->getAddonArenas() : |
| 1322 | + /*argv[1] == "soccer" ?*/ m_asset_manager->getAddonSoccers() |
1320 | 1323 | )));
|
1321 | 1324 | if (apply_filters)
|
1322 | 1325 | m_lobby->applyAllFilters(from, false); // happily the type is never karts in this line
|
@@ -1457,13 +1460,13 @@ void CommandManager::process_checkaddon(Context& context)
|
1457 | 1460 | unsigned server_status = 0;
|
1458 | 1461 | std::vector<std::string> players[4];
|
1459 | 1462 |
|
1460 |
| - if (m_lobby->m_addon_kts.first.count(id)) |
| 1463 | + if (m_asset_manager->hasAddonKart(id)) |
1461 | 1464 | server_status |= HAS_KART;
|
1462 |
| - if (m_lobby->m_addon_kts.second.count(id)) |
| 1465 | + if (m_asset_manager->hasAddonTrack(id)) |
1463 | 1466 | server_status |= HAS_MAP;
|
1464 |
| - if (m_lobby->m_addon_arenas.count(id)) |
| 1467 | + if (m_asset_manager->hasAddonArena(id)) |
1465 | 1468 | server_status |= HAS_MAP;
|
1466 |
| - if (m_lobby->m_addon_soccers.count(id)) |
| 1469 | + if (m_asset_manager->hasAddonSoccer(id)) |
1467 | 1470 | server_status |= HAS_MAP;
|
1468 | 1471 |
|
1469 | 1472 | auto peers = STKHost::get()->getPeers();
|
@@ -1616,22 +1619,26 @@ void CommandManager::process_lsa(Context& context)
|
1616 | 1619 | if (type.empty() || // not specify addon type
|
1617 | 1620 | (!type.empty() && type.compare("kart") == 0)) // list kart addon
|
1618 | 1621 | {
|
1619 |
| - total_addons.insert(m_lobby->m_addon_kts.first.begin(), m_lobby->m_addon_kts.first.end()); |
| 1622 | + const auto& collection = m_asset_manager->getAddonKarts(); |
| 1623 | + total_addons.insert(collection.begin(), collection.end()); |
1620 | 1624 | }
|
1621 | 1625 | if (type.empty() || // not specify addon type
|
1622 | 1626 | (!type.empty() && type.compare("track") == 0))
|
1623 | 1627 | {
|
1624 |
| - total_addons.insert(m_lobby->m_addon_kts.second.begin(), m_lobby->m_addon_kts.second.end()); |
| 1628 | + const auto& collection = m_asset_manager->getAddonTracks(); |
| 1629 | + total_addons.insert(collection.begin(), collection.end()); |
1625 | 1630 | }
|
1626 | 1631 | if (type.empty() || // not specify addon type
|
1627 | 1632 | (!type.empty() && type.compare("arena") == 0))
|
1628 | 1633 | {
|
1629 |
| - total_addons.insert(m_lobby->m_addon_arenas.begin(), m_lobby->m_addon_arenas.end()); |
| 1634 | + const auto& collection = m_asset_manager->getAddonArenas(); |
| 1635 | + total_addons.insert(collection.begin(), collection.end()); |
1630 | 1636 | }
|
1631 | 1637 | if (type.empty() || // not specify addon type
|
1632 | 1638 | (!type.empty() && type.compare("soccer") == 0))
|
1633 | 1639 | {
|
1634 |
| - total_addons.insert(m_lobby->m_addon_soccers.begin(), m_lobby->m_addon_soccers.end()); |
| 1640 | + const auto& collection = m_asset_manager->getAddonSoccers(); |
| 1641 | + total_addons.insert(collection.begin(), collection.end()); |
1635 | 1642 | }
|
1636 | 1643 | std::string msg = "";
|
1637 | 1644 | for (auto& addon : total_addons)
|
@@ -1992,10 +1999,15 @@ void CommandManager::process_sha(Context& context)
|
1992 | 1999 | return;
|
1993 | 2000 | }
|
1994 | 2001 | std::set<std::string> total_addons;
|
1995 |
| - total_addons.insert(m_lobby->m_addon_kts.first.begin(), m_lobby->m_addon_kts.first.end()); |
1996 |
| - total_addons.insert(m_lobby->m_addon_kts.second.begin(), m_lobby->m_addon_kts.second.end()); |
1997 |
| - total_addons.insert(m_lobby->m_addon_arenas.begin(), m_lobby->m_addon_arenas.end()); |
1998 |
| - total_addons.insert(m_lobby->m_addon_soccers.begin(), m_lobby->m_addon_soccers.end()); |
| 2002 | + |
| 2003 | + const auto all_karts = m_asset_manager->getAddonKarts(); |
| 2004 | + const auto all_tracks = m_asset_manager->getAddonTracks(); |
| 2005 | + const auto all_arenas = m_asset_manager->getAddonArenas(); |
| 2006 | + const auto all_soccers = m_asset_manager->getAddonSoccers(); |
| 2007 | + total_addons.insert(all_karts.begin(), all_karts.end()); |
| 2008 | + total_addons.insert(all_tracks.begin(), all_tracks.end()); |
| 2009 | + total_addons.insert(all_arenas.begin(), all_arenas.end()); |
| 2010 | + total_addons.insert(all_soccers.begin(), all_soccers.end()); |
1999 | 2011 | std::string addon_id_test = Addon::createAddonId(argv[1]);
|
2000 | 2012 | bool found = total_addons.find(addon_id_test) != total_addons.end();
|
2001 | 2013 | if (found)
|
@@ -2160,7 +2172,7 @@ void CommandManager::process_gnu(Context& context)
|
2160 | 2172 | if (peer)
|
2161 | 2173 | {
|
2162 | 2174 | kart = "gnu";
|
2163 |
| - if (argv.size() > 1 && m_lobby->m_available_kts.first.count(argv[1]) > 0) |
| 2175 | + if (argv.size() > 1 && m_asset_manager->isKartAvailable(argv[1])) |
2164 | 2176 | {
|
2165 | 2177 | kart = argv[1];
|
2166 | 2178 | }
|
@@ -2569,9 +2581,9 @@ void CommandManager::process_queue_push(Context& context)
|
2569 | 2581 | bool to_front = (argv[1] == "push_front");
|
2570 | 2582 |
|
2571 | 2583 | if (argv.size() == 3 && argv[2] == "-") // kept until there's filter-type replacement
|
2572 |
| - argv[2] = getRandomMap(); |
| 2584 | + argv[2] = m_asset_manager->getRandomMap(); |
2573 | 2585 | else if (argv.size() == 3 && argv[2] == "-addon") // kept until there's filter-type replacement
|
2574 |
| - argv[2] = getRandomAddonMap(); |
| 2586 | + argv[2] = m_asset_manager->getRandomAddonMap(); |
2575 | 2587 |
|
2576 | 2588 | std::string filter_text = "";
|
2577 | 2589 | CommandManager::restoreCmdByArgv(filter_text, argv, ' ', '"', '"', '\\', 2);
|
@@ -4251,40 +4263,6 @@ bool CommandManager::assignRandomTeams(int intended_number,
|
4251 | 4263 | } // assignRandomTeams
|
4252 | 4264 | // ========================================================================
|
4253 | 4265 |
|
4254 |
| -std::string CommandManager::getRandomMap() const |
4255 |
| -{ |
4256 |
| - std::set<std::string> items; |
4257 |
| - for (const std::string& s: m_lobby->m_entering_kts.second) { |
4258 |
| - items.insert(s); |
4259 |
| - } |
4260 |
| - m_lobby->applyAllFilters(items, false); |
4261 |
| - if (items.empty()) |
4262 |
| - return ""; |
4263 |
| - RandomGenerator rg; |
4264 |
| - std::set<std::string>::iterator it = items.begin(); |
4265 |
| - std::advance(it, rg.get((int)items.size())); |
4266 |
| - return *it; |
4267 |
| -} // getRandomMap |
4268 |
| -// ======================================================================== |
4269 |
| - |
4270 |
| -std::string CommandManager::getRandomAddonMap() const |
4271 |
| -{ |
4272 |
| - std::set<std::string> items; |
4273 |
| - for (const std::string& s: m_lobby->m_entering_kts.second) { |
4274 |
| - Track* t = track_manager->getTrack(s); |
4275 |
| - if (t->isAddon()) |
4276 |
| - items.insert(s); |
4277 |
| - } |
4278 |
| - m_lobby->applyAllFilters(items, false); |
4279 |
| - if (items.empty()) |
4280 |
| - return ""; |
4281 |
| - RandomGenerator rg; |
4282 |
| - std::set<std::string>::iterator it = items.begin(); |
4283 |
| - std::advance(it, rg.get((int)items.size())); |
4284 |
| - return *it; |
4285 |
| -} // getRandomAddonMap |
4286 |
| -// ======================================================================== |
4287 |
| - |
4288 | 4266 | void CommandManager::addUser(std::string& s)
|
4289 | 4267 | {
|
4290 | 4268 | m_users.insert(s);
|
|
0 commit comments