mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-01-08 22:07:10 +00:00
more const and views
This commit is contained in:
parent
7b1626901a
commit
f5f599764d
@ -149,7 +149,7 @@ void Leaderboard::QueryToLdf(std::unique_ptr<sql::ResultSet>& rows) {
|
||||
}
|
||||
|
||||
const std::string_view Leaderboard::GetColumns(Leaderboard::Type leaderboardType) {
|
||||
std::string columns;
|
||||
const char* columns;
|
||||
switch (leaderboardType) {
|
||||
case Type::ShootingGallery:
|
||||
columns = "hitPercentage, score, streak";
|
||||
@ -157,12 +157,11 @@ const std::string_view Leaderboard::GetColumns(Leaderboard::Type leaderboardType
|
||||
case Type::Racing:
|
||||
columns = "bestLapTime, bestTime, numWins";
|
||||
break;
|
||||
case Type::Donations:
|
||||
case Type::UnusedLeaderboard4:
|
||||
columns = "score";
|
||||
break;
|
||||
case Type::MonumentRace:
|
||||
columns = "bestTime";
|
||||
break;
|
||||
case Type::FootRace:
|
||||
columns = "bestTime";
|
||||
break;
|
||||
@ -172,9 +171,6 @@ const std::string_view Leaderboard::GetColumns(Leaderboard::Type leaderboardType
|
||||
case Type::SurvivalNS:
|
||||
columns = "bestTime, score";
|
||||
break;
|
||||
case Type::Donations:
|
||||
columns = "score";
|
||||
break;
|
||||
case Type::None:
|
||||
// This type is included here simply to resolve a compiler warning on mac about unused enum types
|
||||
break;
|
||||
@ -183,7 +179,7 @@ const std::string_view Leaderboard::GetColumns(Leaderboard::Type leaderboardType
|
||||
}
|
||||
|
||||
const std::string_view Leaderboard::GetInsertFormat(Leaderboard::Type leaderboardType) {
|
||||
std::string columns;
|
||||
const char* columns;
|
||||
switch (leaderboardType) {
|
||||
case Type::ShootingGallery:
|
||||
columns = "score=%i, hitPercentage=%i, streak=%i";
|
||||
@ -191,12 +187,11 @@ const std::string_view Leaderboard::GetInsertFormat(Leaderboard::Type leaderboar
|
||||
case Type::Racing:
|
||||
columns = "bestLapTime=%i, bestTime=%i, numWins=numWins + %i";
|
||||
break;
|
||||
case Type::Donations:
|
||||
case Type::UnusedLeaderboard4:
|
||||
columns = "score=%i";
|
||||
break;
|
||||
case Type::MonumentRace:
|
||||
columns = "bestTime=%i";
|
||||
break;
|
||||
case Type::FootRace:
|
||||
columns = "bestTime=%i";
|
||||
break;
|
||||
@ -206,9 +201,6 @@ const std::string_view Leaderboard::GetInsertFormat(Leaderboard::Type leaderboar
|
||||
case Type::SurvivalNS:
|
||||
columns = "bestTime=%i, score=%i";
|
||||
break;
|
||||
case Type::Donations:
|
||||
columns = "score=%i";
|
||||
break;
|
||||
case Type::None:
|
||||
// This type is included here simply to resolve a compiler warning on mac about unused enum types
|
||||
break;
|
||||
@ -217,7 +209,7 @@ const std::string_view Leaderboard::GetInsertFormat(Leaderboard::Type leaderboar
|
||||
}
|
||||
|
||||
const std::string_view Leaderboard::GetOrdering(Leaderboard::Type leaderboardType) {
|
||||
std::string orderBase;
|
||||
const char* orderBase;
|
||||
switch (leaderboardType) {
|
||||
case Type::ShootingGallery:
|
||||
orderBase = "score DESC, streak DESC, hitPercentage DESC";
|
||||
@ -225,6 +217,7 @@ const std::string_view Leaderboard::GetOrdering(Leaderboard::Type leaderboardTyp
|
||||
case Type::Racing:
|
||||
orderBase = "bestTime ASC, bestLapTime ASC, numWins DESC";
|
||||
break;
|
||||
case Type::Donations:
|
||||
case Type::UnusedLeaderboard4:
|
||||
orderBase = "score DESC";
|
||||
break;
|
||||
@ -240,9 +233,6 @@ const std::string_view Leaderboard::GetOrdering(Leaderboard::Type leaderboardTyp
|
||||
case Type::SurvivalNS:
|
||||
orderBase = "bestTime DESC, score DESC";
|
||||
break;
|
||||
case Type::Donations:
|
||||
orderBase = "score DESC";
|
||||
break;
|
||||
case Type::None:
|
||||
// This type is included here simply to resolve a compiler warning on mac about unused enum types
|
||||
break;
|
||||
@ -352,7 +342,7 @@ void Leaderboard::SetupLeaderboard(uint32_t resultStart, uint32_t resultEnd) {
|
||||
QueryToLdf(result);
|
||||
}
|
||||
|
||||
void Leaderboard::Send(LWOOBJID targetID) {
|
||||
void Leaderboard::Send(const LWOOBJID targetID) const {
|
||||
auto* player = EntityManager::Instance()->GetEntity(relatedPlayer);
|
||||
if (player != nullptr) {
|
||||
GameMessages::SendActivitySummaryLeaderboardData(targetID, this, player->GetSystemAddress());
|
||||
@ -465,7 +455,7 @@ Leaderboard::Type LeaderboardManager::GetLeaderboardType(const GameID gameID) {
|
||||
|
||||
auto* activitiesTable = CDClientManager::Instance().GetTable<CDActivitiesTable>();
|
||||
std::vector<CDActivities> activities = activitiesTable->Query([=](const CDActivities& entry) {
|
||||
return (entry.ActivityID == gameID);
|
||||
return entry.ActivityID == gameID;
|
||||
});
|
||||
auto type = !activities.empty() ? static_cast<Leaderboard::Type>(activities.at(0).leaderboardType) : Leaderboard::Type::None;
|
||||
leaderboardCache.insert_or_assign(gameID, type);
|
||||
|
@ -72,7 +72,7 @@ public:
|
||||
/**
|
||||
* Sends the leaderboard to the client specified by targetID.
|
||||
*/
|
||||
void Send(LWOOBJID targetID);
|
||||
void Send(const LWOOBJID targetID) const;
|
||||
|
||||
// Helper functions to get the columns, ordering and insert format for a leaderboard
|
||||
static const std::string_view GetColumns(Type leaderboardType);
|
||||
|
@ -1639,7 +1639,7 @@ void GameMessages::HandleActivitySummaryLeaderboardData(RakNet::BitStream* instr
|
||||
Game::logger->Log("AGS", "We got mail!");
|
||||
}
|
||||
|
||||
void GameMessages::SendActivitySummaryLeaderboardData(const LWOOBJID& objectID, Leaderboard* leaderboard, const SystemAddress& sysAddr) {
|
||||
void GameMessages::SendActivitySummaryLeaderboardData(const LWOOBJID& objectID, const Leaderboard* leaderboard, const SystemAddress& sysAddr) {
|
||||
CBITSTREAM;
|
||||
CMSGHEADER;
|
||||
|
||||
|
@ -561,7 +561,7 @@ namespace GameMessages {
|
||||
void SendUpdateReputation(const LWOOBJID objectId, const int64_t reputation, const SystemAddress& sysAddr);
|
||||
|
||||
// Leaderboards
|
||||
void SendActivitySummaryLeaderboardData(const LWOOBJID& objectID, Leaderboard* leaderboard,
|
||||
void SendActivitySummaryLeaderboardData(const LWOOBJID& objectID, const Leaderboard* leaderboard,
|
||||
const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS);
|
||||
void HandleActivitySummaryLeaderboardData(RakNet::BitStream* instream, Entity* entity, const SystemAddress& sysAddr);
|
||||
void SendRequestActivitySummaryLeaderboardData(const LWOOBJID& objectID, const LWOOBJID& targetID,
|
||||
|
Loading…
Reference in New Issue
Block a user