Allow listing server addons

This commit is contained in:
Benau 2019-12-03 10:26:01 +08:00
parent 68d549e697
commit 6d3bb566be
2 changed files with 105 additions and 0 deletions

View File

@ -152,6 +152,14 @@ ServerLobby::ServerLobby() : LobbyProtocol()
track_manager->getArenasInGroup("standard", false);
std::vector<int> all_soccers =
track_manager->getArenasInGroup("standard", true);
std::vector<int> addon_karts =
kart_properties_manager->getKartsInGroup("Add-Ons");
std::vector<int> addon_tracks =
track_manager->getTracksInGroup("Add-Ons");
std::vector<int> addon_arenas =
track_manager->getArenasInGroup("Add-Ons", false);
std::vector<int> addon_soccers =
track_manager->getArenasInGroup("Add-Ons", true);
all_t.insert(all_t.end(), all_arenas.begin(), all_arenas.end());
all_t.insert(all_t.end(), all_soccers.begin(), all_soccers.end());
@ -168,6 +176,31 @@ ServerLobby::ServerLobby() : LobbyProtocol()
m_official_kts.second.insert(t->getIdent());
}
for (int kart : addon_karts)
{
const KartProperties* kp = kart_properties_manager->getKartById(kart);
if (kp->isAddon())
m_addon_kts.first.insert(kp->getIdent());
}
for (int track : addon_tracks)
{
Track* t = track_manager->getTrack(track);
if (t->isAddon())
m_addon_kts.second.insert(t->getIdent());
}
for (int arena : addon_arenas)
{
Track* t = track_manager->getTrack(arena);
if (t->isAddon())
m_addon_arenas.insert(t->getIdent());
}
for (int soccer : addon_soccers)
{
Track* t = track_manager->getTrack(soccer);
if (t->isAddon())
m_addon_soccers.insert(t->getIdent());
}
m_rs_state.store(RS_NONE);
m_last_success_poll_time.store(StkTime::getMonoTimeMs() + 30000);
m_server_owner_id.store(-1);
@ -757,6 +790,8 @@ bool ServerLobby::notifyEventAsynchronous(Event* event)
case LE_REPORT_PLAYER: writePlayerReport(event); break;
case LE_ASSETS_UPDATE:
handleAssets(event->data(), event->getPeer()); break;
case LE_COMMAND:
handleServerCommand(event, event->getPeer()); break;
default: break;
} // switch
} // if (event->getType() == EVENT_TYPE_MESSAGE)
@ -4856,3 +4891,63 @@ bool ServerLobby::checkPeersReady(bool ignore_ai_peer) const
}
return true;
} // checkPeersReady
//-----------------------------------------------------------------------------
void ServerLobby::handleServerCommand(Event* event, STKPeer* peer) const
{
NetworkString& data = event->data();
std::string cmd;
data.decodeString(&cmd);
auto argv = StringUtils::split(cmd, ' ');
if (argv.size() == 0)
return;
if (argv[0] == "listserveraddon")
{
NetworkString* chat = getNetworkString();
chat->addUInt8(LE_CHAT);
chat->setSynchronous(true);
if (argv.size() != 2)
{
chat->encodeString16(
L"Usage: /listserveraddon [addon prefix letter(s) to find]");
}
else
{
std::set<std::string> total_addons;
total_addons.insert(m_addon_kts.first.begin(), m_addon_kts.first.end());
total_addons.insert(m_addon_kts.second.begin(), m_addon_kts.second.end());
total_addons.insert(m_addon_arenas.begin(), m_addon_arenas.end());
total_addons.insert(m_addon_soccers.begin(), m_addon_soccers.end());
std::string msg = "";
for (auto& addon : total_addons)
{
// addon_ (6 letters)
if (addon.compare(6, argv[1].length(), argv[1]) == 0)
{
msg += addon.substr(6);
msg += ", ";
}
}
if (msg.empty())
chat->encodeString16(L"Addon not found");
else
{
msg = msg.substr(0, msg.size() - 2);
chat->encodeString16((std::string("Server addon: ") + msg).c_str());
}
}
peer->sendPacket(chat, true/*reliable*/);
delete chat;
}
else
{
NetworkString* chat = getNetworkString();
chat->addUInt8(LE_CHAT);
chat->setSynchronous(true);
std::string msg = "Unknown command: ";
msg += cmd;
chat->encodeString16( msg.c_str());
peer->sendPacket(chat, true/*reliable*/);
delete chat;
}
} // handleServerCommand

View File

@ -130,6 +130,15 @@ private:
/** Official karts and tracks available in server. */
std::pair<std::set<std::string>, std::set<std::string> > m_official_kts;
/** Addon karts and tracks available in server. */
std::pair<std::set<std::string>, std::set<std::string> > m_addon_kts;
/** Addon arenas available in server. */
std::set<std::string> m_addon_arenas;
/** Addon soccers available in server. */
std::set<std::string> m_addon_soccers;
/** Available karts and tracks for all clients, this will be initialized
* with data in server first. */
std::pair<std::set<std::string>, std::set<std::string> > m_available_kts;
@ -322,6 +331,7 @@ private:
std::vector<std::shared_ptr<NetworkPlayerProfile> > getLivePlayers() const;
void setPlayerKarts(const NetworkString& ns, STKPeer* peer) const;
bool handleAssets(const NetworkString& ns, STKPeer* peer) const;
void handleServerCommand(Event* event, STKPeer* peer) const;
void liveJoinRequest(Event* event);
void rejectLiveJoin(STKPeer* peer, BackLobbyReason blr);
bool canLiveJoinNow() const;