2021-12-05 17:54:36 +00:00
|
|
|
#include "LeaderboardManager.h"
|
2023-06-01 06:05:19 +00:00
|
|
|
|
2024-12-04 06:11:03 +00:00
|
|
|
#include <ranges>
|
2023-06-01 06:05:19 +00:00
|
|
|
#include <sstream>
|
2021-12-05 17:54:36 +00:00
|
|
|
#include <utility>
|
2023-06-01 06:05:19 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "Database.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "Character.h"
|
2021-12-22 03:15:29 +00:00
|
|
|
#include "Game.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "GameMessages.h"
|
2023-10-21 23:31:55 +00:00
|
|
|
#include "Logger.h"
|
2021-12-22 03:15:29 +00:00
|
|
|
#include "dConfig.h"
|
2022-12-18 15:46:04 +00:00
|
|
|
#include "CDClientManager.h"
|
2023-03-17 14:36:21 +00:00
|
|
|
#include "GeneralUtils.h"
|
|
|
|
#include "Entity.h"
|
2023-04-14 08:32:52 +00:00
|
|
|
#include "LDFFormat.h"
|
2023-05-30 11:11:37 +00:00
|
|
|
#include "DluAssert.h"
|
2023-03-17 14:36:21 +00:00
|
|
|
|
|
|
|
#include "CDActivitiesTable.h"
|
2023-04-13 07:45:03 +00:00
|
|
|
#include "Metrics.hpp"
|
2023-04-26 09:10:57 +00:00
|
|
|
|
2023-05-30 11:11:37 +00:00
|
|
|
namespace LeaderboardManager {
|
2023-06-05 11:10:59 +00:00
|
|
|
std::map<GameID, Leaderboard::Type> leaderboardCache;
|
2023-05-30 11:11:37 +00:00
|
|
|
}
|
2023-05-09 08:42:11 +00:00
|
|
|
|
2023-05-03 07:38:38 +00:00
|
|
|
Leaderboard::Leaderboard(const GameID gameID, const Leaderboard::InfoType infoType, const bool weekly, LWOOBJID relatedPlayer, const Leaderboard::Type leaderboardType) {
|
2022-07-28 13:39:57 +00:00
|
|
|
this->gameID = gameID;
|
|
|
|
this->weekly = weekly;
|
|
|
|
this->infoType = infoType;
|
|
|
|
this->leaderboardType = leaderboardType;
|
2023-05-03 07:38:38 +00:00
|
|
|
this->relatedPlayer = relatedPlayer;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 07:38:38 +00:00
|
|
|
Leaderboard::~Leaderboard() {
|
2023-06-01 06:05:19 +00:00
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Leaderboard::Clear() {
|
2023-06-05 11:10:59 +00:00
|
|
|
for (auto& entry : entries) for (auto ldfData : entry) delete ldfData;
|
2023-04-14 08:32:52 +00:00
|
|
|
}
|
|
|
|
|
2023-05-30 11:38:19 +00:00
|
|
|
inline void WriteLeaderboardRow(std::ostringstream& leaderboard, const uint32_t& index, LDFBaseData* data) {
|
2023-05-10 05:00:13 +00:00
|
|
|
leaderboard << "\nResult[0].Row[" << index << "]." << data->GetString();
|
2023-05-03 07:38:38 +00:00
|
|
|
}
|
|
|
|
|
2024-02-27 05:25:45 +00:00
|
|
|
void Leaderboard::Serialize(RakNet::BitStream& bitStream) const {
|
|
|
|
bitStream.Write(gameID);
|
|
|
|
bitStream.Write(infoType);
|
2023-05-09 02:35:19 +00:00
|
|
|
|
2023-04-13 07:45:03 +00:00
|
|
|
std::ostringstream leaderboard;
|
2023-06-01 06:05:19 +00:00
|
|
|
|
2023-05-10 05:00:13 +00:00
|
|
|
leaderboard << "ADO.Result=7:1"; // Unused in 1.10.64, but is in captures
|
2023-05-28 11:30:20 +00:00
|
|
|
leaderboard << "\nResult.Count=1:1"; // number of results, always 1
|
|
|
|
if (!this->entries.empty()) leaderboard << "\nResult[0].Index=0:RowNumber"; // "Primary key". Live doesn't include this if there are no entries.
|
|
|
|
leaderboard << "\nResult[0].RowCount=1:" << entries.size();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-05-09 01:36:28 +00:00
|
|
|
int32_t rowNumber = 0;
|
2023-05-03 07:38:38 +00:00
|
|
|
for (auto& entry : entries) {
|
2023-05-09 01:36:28 +00:00
|
|
|
for (auto* data : entry) {
|
|
|
|
WriteLeaderboardRow(leaderboard, rowNumber, data);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2023-05-09 01:36:28 +00:00
|
|
|
rowNumber++;
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2023-05-28 11:30:20 +00:00
|
|
|
|
2023-04-13 04:57:58 +00:00
|
|
|
// Serialize the thing to a BitStream
|
2023-05-09 08:42:11 +00:00
|
|
|
uint32_t leaderboardSize = leaderboard.tellp();
|
2024-02-27 05:25:45 +00:00
|
|
|
bitStream.Write<uint32_t>(leaderboardSize);
|
2023-05-09 08:42:11 +00:00
|
|
|
// Doing this all in 1 call so there is no possbility of a dangling pointer.
|
2024-02-27 05:25:45 +00:00
|
|
|
bitStream.WriteAlignedBytes(reinterpret_cast<const unsigned char*>(GeneralUtils::ASCIIToUTF16(leaderboard.str()).c_str()), leaderboardSize * sizeof(char16_t));
|
|
|
|
if (leaderboardSize > 0) bitStream.Write<uint16_t>(0);
|
|
|
|
bitStream.Write0();
|
|
|
|
bitStream.Write0();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-12-04 06:11:03 +00:00
|
|
|
// Takes the resulting query from a leaderboard lookup and converts it to the LDF we need
|
|
|
|
// to send it to a client.
|
|
|
|
void QueryToLdf(Leaderboard& leaderboard, const std::vector<ILeaderboard::Entry>& leaderboardEntries) {
|
|
|
|
using enum Leaderboard::Type;
|
|
|
|
leaderboard.Clear();
|
|
|
|
if (leaderboardEntries.empty()) return;
|
2023-05-03 07:38:38 +00:00
|
|
|
|
2024-12-04 06:11:03 +00:00
|
|
|
for (const auto& leaderboardEntry : leaderboardEntries) {
|
2023-05-09 01:36:28 +00:00
|
|
|
constexpr int32_t MAX_NUM_DATA_PER_ROW = 9;
|
2024-12-04 06:11:03 +00:00
|
|
|
auto& entry = leaderboard.PushBackEntry();
|
2023-05-09 01:36:28 +00:00
|
|
|
entry.reserve(MAX_NUM_DATA_PER_ROW);
|
2024-12-04 06:11:03 +00:00
|
|
|
entry.push_back(new LDFData<uint64_t>(u"CharacterID", leaderboardEntry.charId));
|
|
|
|
entry.push_back(new LDFData<uint64_t>(u"LastPlayed", leaderboardEntry.lastPlayedTimestamp));
|
|
|
|
entry.push_back(new LDFData<int32_t>(u"NumPlayed", leaderboardEntry.numTimesPlayed));
|
|
|
|
entry.push_back(new LDFData<std::u16string>(u"name", GeneralUtils::ASCIIToUTF16(leaderboardEntry.name)));
|
|
|
|
entry.push_back(new LDFData<uint64_t>(u"RowNumber", leaderboardEntry.ranking));
|
|
|
|
switch (leaderboard.GetLeaderboardType()) {
|
|
|
|
case ShootingGallery:
|
|
|
|
entry.push_back(new LDFData<int32_t>(u"Score", leaderboardEntry.primaryScore));
|
2023-05-09 01:36:28 +00:00
|
|
|
// Score:1
|
2024-12-04 06:11:03 +00:00
|
|
|
entry.push_back(new LDFData<int32_t>(u"Streak", leaderboardEntry.secondaryScore));
|
2023-05-09 01:36:28 +00:00
|
|
|
// Streak:1
|
2024-12-04 06:11:03 +00:00
|
|
|
entry.push_back(new LDFData<float>(u"HitPercentage", (leaderboardEntry.tertiaryScore / 100.0f)));
|
2023-06-22 04:46:11 +00:00
|
|
|
// HitPercentage:3 between 0 and 1
|
2023-05-09 01:36:28 +00:00
|
|
|
break;
|
2024-12-04 06:11:03 +00:00
|
|
|
case Racing:
|
|
|
|
entry.push_back(new LDFData<float>(u"BestTime", leaderboardEntry.primaryScore));
|
2023-05-09 01:36:28 +00:00
|
|
|
// BestLapTime:3
|
2024-12-04 06:11:03 +00:00
|
|
|
entry.push_back(new LDFData<float>(u"BestLapTime", leaderboardEntry.secondaryScore));
|
2023-05-09 01:36:28 +00:00
|
|
|
// BestTime:3
|
|
|
|
entry.push_back(new LDFData<int32_t>(u"License", 1));
|
|
|
|
// License:1 - 1 if player has completed mission 637 and 0 otherwise
|
2024-12-04 06:11:03 +00:00
|
|
|
entry.push_back(new LDFData<int32_t>(u"NumWins", leaderboardEntry.numWins));
|
2023-05-09 01:36:28 +00:00
|
|
|
// NumWins:1
|
|
|
|
break;
|
2024-12-04 06:11:03 +00:00
|
|
|
case UnusedLeaderboard4:
|
|
|
|
entry.push_back(new LDFData<int32_t>(u"Points", leaderboardEntry.primaryScore));
|
2023-05-09 01:36:28 +00:00
|
|
|
// Points:1
|
|
|
|
break;
|
2024-12-04 06:11:03 +00:00
|
|
|
case MonumentRace:
|
|
|
|
entry.push_back(new LDFData<int32_t>(u"Time", leaderboardEntry.primaryScore));
|
2023-05-09 01:36:28 +00:00
|
|
|
// Time:1(?)
|
|
|
|
break;
|
2024-12-04 06:11:03 +00:00
|
|
|
case FootRace:
|
|
|
|
entry.push_back(new LDFData<int32_t>(u"Time", leaderboardEntry.primaryScore));
|
2023-05-09 01:36:28 +00:00
|
|
|
// Time:1
|
|
|
|
break;
|
2024-12-04 06:11:03 +00:00
|
|
|
case Survival:
|
|
|
|
entry.push_back(new LDFData<int32_t>(u"Points", leaderboardEntry.primaryScore));
|
2023-05-09 01:36:28 +00:00
|
|
|
// Points:1
|
2024-12-04 06:11:03 +00:00
|
|
|
entry.push_back(new LDFData<int32_t>(u"Time", leaderboardEntry.secondaryScore));
|
2023-05-09 01:36:28 +00:00
|
|
|
// Time:1
|
|
|
|
break;
|
2024-12-04 06:11:03 +00:00
|
|
|
case SurvivalNS:
|
|
|
|
entry.push_back(new LDFData<int32_t>(u"Wave", leaderboardEntry.primaryScore));
|
2023-05-09 01:36:28 +00:00
|
|
|
// Wave:1
|
2024-12-04 06:11:03 +00:00
|
|
|
entry.push_back(new LDFData<int32_t>(u"Time", leaderboardEntry.secondaryScore));
|
2023-05-09 01:36:28 +00:00
|
|
|
// Time:1
|
|
|
|
break;
|
2024-12-04 06:11:03 +00:00
|
|
|
case Donations:
|
|
|
|
entry.push_back(new LDFData<int32_t>(u"Score", leaderboardEntry.primaryScore));
|
2023-08-04 02:44:03 +00:00
|
|
|
// Score:1
|
2023-05-09 01:36:28 +00:00
|
|
|
break;
|
2024-12-04 06:11:03 +00:00
|
|
|
case None:
|
|
|
|
[[fallthrough]];
|
2023-05-09 01:36:28 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-03 07:38:38 +00:00
|
|
|
|
2024-12-04 06:11:03 +00:00
|
|
|
std::vector<ILeaderboard::Entry> FilterTo10(const std::vector<ILeaderboard::Entry>& leaderboard, const uint32_t relatedPlayer, const Leaderboard::InfoType infoType) {
|
|
|
|
std::vector<ILeaderboard::Entry> toReturn;
|
|
|
|
|
|
|
|
int32_t index = 0;
|
|
|
|
// for friends and top, we dont need to find this players index.
|
2024-12-04 07:13:17 +00:00
|
|
|
if (infoType == Leaderboard::InfoType::MyStanding || infoType == Leaderboard::InfoType::Friends) {
|
2024-12-04 06:11:03 +00:00
|
|
|
for (; index < leaderboard.size(); index++) {
|
|
|
|
if (leaderboard[index].charId == relatedPlayer) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (leaderboard.size() < 10) {
|
|
|
|
toReturn.assign(leaderboard.begin(), leaderboard.end());
|
2024-12-04 07:13:17 +00:00
|
|
|
index = 0;
|
2024-12-04 06:11:03 +00:00
|
|
|
} else if (index < 10) {
|
|
|
|
toReturn.assign(leaderboard.begin(), leaderboard.begin() + 10); // get the top 10 since we are in the top 10
|
2024-12-04 07:13:17 +00:00
|
|
|
index = 0;
|
2024-12-04 06:11:03 +00:00
|
|
|
} else if (index > leaderboard.size() - 10) {
|
|
|
|
toReturn.assign(leaderboard.end() - 10, leaderboard.end()); // get the bottom 10 since we are in the bottom 10
|
2024-12-04 07:13:17 +00:00
|
|
|
index = leaderboard.size() - 10;
|
2024-12-04 06:11:03 +00:00
|
|
|
} else {
|
|
|
|
toReturn.assign(leaderboard.begin() + index - 5, leaderboard.begin() + index + 5); // get the 5 above and below
|
2024-12-04 07:13:17 +00:00
|
|
|
index -= 5;
|
2024-12-04 06:11:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t i = index;
|
|
|
|
for (auto& entry : toReturn) {
|
|
|
|
entry.ranking = ++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<ILeaderboard::Entry> FilterWeeklies(const std::vector<ILeaderboard::Entry>& leaderboard) {
|
|
|
|
// Filter the leaderboard to only include entries from the last week
|
|
|
|
const auto currentTime = std::chrono::system_clock::now();
|
|
|
|
auto epochTime = currentTime.time_since_epoch().count();
|
|
|
|
constexpr auto SECONDS_IN_A_WEEK = 60 * 60 * 24 * 7; // if you think im taking leap seconds into account thats cute.
|
|
|
|
|
|
|
|
std::vector<ILeaderboard::Entry> weeklyLeaderboard;
|
|
|
|
for (const auto& entry : leaderboard) {
|
|
|
|
if (epochTime - entry.lastPlayedTimestamp < SECONDS_IN_A_WEEK) {
|
|
|
|
weeklyLeaderboard.push_back(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return weeklyLeaderboard;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<ILeaderboard::Entry> FilterFriends(const std::vector<ILeaderboard::Entry>& leaderboard, const uint32_t relatedPlayer) {
|
|
|
|
// Filter the leaderboard to only include friends of the player
|
|
|
|
auto friendOfPlayer = Database::Get()->GetFriendsList(relatedPlayer);
|
|
|
|
std::vector<ILeaderboard::Entry> friendsLeaderboard;
|
|
|
|
for (const auto& entry : leaderboard) {
|
2024-12-04 08:25:09 +00:00
|
|
|
const auto res = std::ranges::find_if(friendOfPlayer, [&entry, relatedPlayer](const FriendData& data) {
|
|
|
|
return entry.charId == data.friendID || entry.charId == relatedPlayer;
|
|
|
|
});
|
|
|
|
if (res != friendOfPlayer.cend()) {
|
2024-12-04 06:11:03 +00:00
|
|
|
friendsLeaderboard.push_back(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return friendsLeaderboard;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<ILeaderboard::Entry> ProcessLeaderboard(
|
|
|
|
const std::vector<ILeaderboard::Entry>& leaderboard,
|
|
|
|
const bool weekly,
|
|
|
|
const Leaderboard::InfoType infoType,
|
|
|
|
const uint32_t relatedPlayer) {
|
|
|
|
std::vector<ILeaderboard::Entry> toReturn;
|
|
|
|
|
|
|
|
if (infoType == Leaderboard::InfoType::Friends) {
|
|
|
|
const auto friendsLeaderboard = FilterFriends(leaderboard, relatedPlayer);
|
|
|
|
toReturn = FilterTo10(weekly ? FilterWeeklies(friendsLeaderboard) : friendsLeaderboard, relatedPlayer, infoType);
|
|
|
|
} else {
|
|
|
|
toReturn = FilterTo10(weekly ? FilterWeeklies(leaderboard) : leaderboard, relatedPlayer, infoType);
|
|
|
|
}
|
|
|
|
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Leaderboard::SetupLeaderboard(bool weekly) {
|
|
|
|
const auto leaderboardType = LeaderboardManager::GetLeaderboardType(gameID);
|
|
|
|
std::vector<ILeaderboard::Entry> leaderboardRes;
|
|
|
|
|
2023-05-01 04:30:41 +00:00
|
|
|
switch (leaderboardType) {
|
2023-06-22 02:46:01 +00:00
|
|
|
case Type::SurvivalNS:
|
2024-12-04 06:11:03 +00:00
|
|
|
leaderboardRes = Database::Get()->GetNsLeaderboard(gameID);
|
|
|
|
break;
|
|
|
|
case Type::Survival:
|
|
|
|
leaderboardRes = Database::Get()->GetAgsLeaderboard(gameID);
|
|
|
|
break;
|
|
|
|
case Type::Racing:
|
|
|
|
[[fallthrough]];
|
|
|
|
case Type::MonumentRace:
|
2024-12-04 08:25:09 +00:00
|
|
|
leaderboardRes = Database::Get()->GetAscendingLeaderboard(gameID);
|
|
|
|
break;
|
|
|
|
case Type::ShootingGallery:
|
2024-12-04 06:11:03 +00:00
|
|
|
[[fallthrough]];
|
2023-06-05 09:43:02 +00:00
|
|
|
case Type::FootRace:
|
2024-12-04 06:11:03 +00:00
|
|
|
[[fallthrough]];
|
2023-06-05 09:43:02 +00:00
|
|
|
case Type::Donations:
|
2024-12-04 06:11:03 +00:00
|
|
|
[[fallthrough]];
|
2023-06-05 09:43:02 +00:00
|
|
|
case Type::None:
|
2024-12-04 06:11:03 +00:00
|
|
|
[[fallthrough]];
|
2023-06-01 06:05:19 +00:00
|
|
|
default:
|
2024-12-04 08:25:09 +00:00
|
|
|
leaderboardRes = Database::Get()->GetDescendingLeaderboard(gameID);
|
2024-12-04 06:11:03 +00:00
|
|
|
break;
|
2023-05-01 04:30:41 +00:00
|
|
|
}
|
2023-05-09 01:36:28 +00:00
|
|
|
|
2024-12-04 06:11:03 +00:00
|
|
|
const auto processedLeaderboard = ProcessLeaderboard(leaderboardRes, weekly, infoType, relatedPlayer);
|
|
|
|
|
|
|
|
QueryToLdf(*this, processedLeaderboard);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-05-30 11:23:48 +00:00
|
|
|
void Leaderboard::Send(const LWOOBJID targetID) const {
|
2023-07-22 02:38:59 +00:00
|
|
|
auto* player = Game::entityManager->GetEntity(relatedPlayer);
|
2022-07-28 13:39:57 +00:00
|
|
|
if (player != nullptr) {
|
|
|
|
GameMessages::SendActivitySummaryLeaderboardData(targetID, this, player->GetSystemAddress());
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-06-05 11:10:59 +00:00
|
|
|
void LeaderboardManager::SaveScore(const LWOOBJID& playerID, const GameID activityId, const float primaryScore, const float secondaryScore, const float tertiaryScore) {
|
|
|
|
const Leaderboard::Type leaderboardType = GetLeaderboardType(activityId);
|
2023-05-07 11:09:10 +00:00
|
|
|
|
2024-12-04 06:11:03 +00:00
|
|
|
const auto oldScore = Database::Get()->GetPlayerScore(playerID, activityId);
|
2023-05-07 07:31:38 +00:00
|
|
|
|
2024-12-04 06:11:03 +00:00
|
|
|
ILeaderboard::Score newScore{ .primaryScore = primaryScore, .secondaryScore = secondaryScore, .tertiaryScore = tertiaryScore };
|
|
|
|
if (oldScore.has_value()) {
|
|
|
|
bool lowerScoreBetter = leaderboardType == Leaderboard::Type::Racing || leaderboardType == Leaderboard::Type::MonumentRace;
|
2023-05-30 11:11:37 +00:00
|
|
|
bool newHighScore = lowerScoreBetter ? newScore < oldScore : newScore > oldScore;
|
2023-06-22 02:46:01 +00:00
|
|
|
// Nimbus station has a weird leaderboard where we need a custom scoring system
|
|
|
|
if (leaderboardType == Leaderboard::Type::SurvivalNS) {
|
2024-12-04 06:11:03 +00:00
|
|
|
newHighScore = newScore.primaryScore > oldScore->primaryScore ||
|
|
|
|
(newScore.primaryScore == oldScore->primaryScore && newScore.secondaryScore < oldScore->secondaryScore);
|
2023-06-22 02:46:01 +00:00
|
|
|
} else if (leaderboardType == Leaderboard::Type::Survival && Game::config->GetValue("classic_survival_scoring") == "1") {
|
2024-12-04 08:50:04 +00:00
|
|
|
ILeaderboard::Score oldScoreFlipped{oldScore->secondaryScore, oldScore->primaryScore, oldScore->tertiaryScore};
|
|
|
|
ILeaderboard::Score newScoreFlipped{newScore.secondaryScore, newScore.primaryScore, newScore.tertiaryScore};
|
2023-06-22 02:46:01 +00:00
|
|
|
newHighScore = newScoreFlipped > oldScoreFlipped;
|
|
|
|
}
|
2024-12-04 08:37:20 +00:00
|
|
|
|
2023-05-30 11:11:37 +00:00
|
|
|
if (newHighScore) {
|
2024-12-04 06:11:03 +00:00
|
|
|
Database::Get()->UpdateScore(playerID, activityId, newScore);
|
2023-05-30 11:11:37 +00:00
|
|
|
}
|
2023-05-07 11:09:10 +00:00
|
|
|
} else {
|
2024-12-04 06:11:03 +00:00
|
|
|
Database::Get()->SaveScore(playerID, activityId, newScore);
|
2023-05-07 07:31:38 +00:00
|
|
|
}
|
2023-08-04 02:44:03 +00:00
|
|
|
|
2023-07-22 06:18:51 +00:00
|
|
|
// track wins separately
|
|
|
|
if (leaderboardType == Leaderboard::Type::Racing && tertiaryScore != 0.0f) {
|
2024-12-04 06:11:03 +00:00
|
|
|
Database::Get()->IncrementNumWins(playerID, activityId);
|
2023-07-22 06:18:51 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-12-04 06:11:03 +00:00
|
|
|
void LeaderboardManager::SendLeaderboard(const GameID gameID, const Leaderboard::InfoType infoType, const bool weekly, const LWOOBJID playerID, const LWOOBJID targetID) {
|
2023-05-03 07:38:38 +00:00
|
|
|
Leaderboard leaderboard(gameID, infoType, weekly, playerID, GetLeaderboardType(gameID));
|
2024-12-04 06:11:03 +00:00
|
|
|
leaderboard.SetupLeaderboard(weekly);
|
2023-05-10 05:21:41 +00:00
|
|
|
leaderboard.Send(targetID);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-04-13 04:57:58 +00:00
|
|
|
Leaderboard::Type LeaderboardManager::GetLeaderboardType(const GameID gameID) {
|
|
|
|
auto lookup = leaderboardCache.find(gameID);
|
|
|
|
if (lookup != leaderboardCache.end()) return lookup->second;
|
|
|
|
|
2024-02-09 05:40:43 +00:00
|
|
|
auto* activitiesTable = CDClientManager::GetTable<CDActivitiesTable>();
|
2023-06-05 09:50:40 +00:00
|
|
|
std::vector<CDActivities> activities = activitiesTable->Query([gameID](const CDActivities& entry) {
|
2023-05-30 11:23:48 +00:00
|
|
|
return entry.ActivityID == gameID;
|
2022-07-28 13:39:57 +00:00
|
|
|
});
|
2023-05-09 08:42:11 +00:00
|
|
|
auto type = !activities.empty() ? static_cast<Leaderboard::Type>(activities.at(0).leaderboardType) : Leaderboard::Type::None;
|
2023-04-13 04:57:58 +00:00
|
|
|
leaderboardCache.insert_or_assign(gameID, type);
|
|
|
|
return type;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|