2023-05-30 04:11:37 -07:00
|
|
|
#ifndef __LEADERBOARDMANAGER__H__
|
|
|
|
#define __LEADERBOARDMANAGER__H__
|
|
|
|
|
2023-04-13 00:45:03 -07:00
|
|
|
#include <map>
|
2023-05-30 18:21:10 -07:00
|
|
|
#include <memory>
|
2023-05-30 04:11:37 -07:00
|
|
|
#include <string_view>
|
2023-04-13 00:45:03 -07:00
|
|
|
#include <vector>
|
2021-12-05 18:54:36 +01:00
|
|
|
|
2023-04-12 21:57:58 -07:00
|
|
|
#include "dCommonVars.h"
|
2023-04-14 01:32:52 -07:00
|
|
|
#include "LDFFormat.h"
|
2021-12-05 18:54:36 +01:00
|
|
|
|
2023-05-08 18:36:28 -07:00
|
|
|
namespace RakNet {
|
2023-04-12 21:57:58 -07:00
|
|
|
class BitStream;
|
2021-12-05 18:54:36 +01:00
|
|
|
};
|
|
|
|
|
2023-05-30 04:38:19 -07:00
|
|
|
using GameID = uint32_t;
|
2021-12-05 18:54:36 +01:00
|
|
|
|
|
|
|
class Leaderboard {
|
|
|
|
public:
|
2023-04-12 21:57:58 -07:00
|
|
|
|
|
|
|
// Enums for leaderboards
|
|
|
|
enum InfoType : uint32_t {
|
|
|
|
Top, // Top 11 all time players
|
|
|
|
MyStanding, // Ranking of the current player
|
|
|
|
Friends // Ranking between friends
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Type : uint32_t {
|
|
|
|
ShootingGallery,
|
|
|
|
Racing,
|
|
|
|
MonumentRace,
|
|
|
|
FootRace,
|
2023-04-17 15:19:13 -07:00
|
|
|
UnusedLeaderboard4, // There is no 4 defined anywhere in the cdclient, but it takes a Score.
|
|
|
|
Survival,
|
2023-04-13 21:55:09 -07:00
|
|
|
SurvivalNS,
|
|
|
|
Donations,
|
2023-05-09 00:06:43 -07:00
|
|
|
None
|
2023-04-12 21:57:58 -07:00
|
|
|
};
|
2023-05-31 23:05:19 -07:00
|
|
|
Leaderboard() = delete;
|
2023-05-03 00:38:38 -07:00
|
|
|
Leaderboard(const GameID gameID, const Leaderboard::InfoType infoType, const bool weekly, LWOOBJID relatedPlayer, const Leaderboard::Type = None);
|
|
|
|
|
|
|
|
~Leaderboard();
|
2023-06-05 04:10:59 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Resets the leaderboard state and frees its allocated memory
|
2024-12-06 03:03:47 -08:00
|
|
|
*
|
2023-06-05 04:10:59 -07:00
|
|
|
*/
|
2023-05-31 23:05:19 -07:00
|
|
|
void Clear();
|
2023-04-12 21:57:58 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Serialize the Leaderboard to a BitStream
|
2023-05-08 18:36:28 -07:00
|
|
|
*
|
2023-04-12 21:57:58 -07:00
|
|
|
* Expensive! Leaderboards are very string intensive so be wary of performatnce calling this method.
|
|
|
|
*/
|
2024-02-26 23:25:45 -06:00
|
|
|
void Serialize(RakNet::BitStream& bitStream) const;
|
2023-04-12 21:57:58 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the leaderboard from the database based on the associated gameID
|
2023-05-30 04:11:37 -07:00
|
|
|
*
|
2023-05-08 19:59:10 -07:00
|
|
|
* @param resultStart The index to start the leaderboard at. Zero indexed.
|
|
|
|
* @param resultEnd The index to end the leaderboard at. Zero indexed.
|
2023-04-12 21:57:58 -07:00
|
|
|
*/
|
2024-12-06 03:03:47 -08:00
|
|
|
void SetupLeaderboard(bool weekly);
|
2023-04-12 21:57:58 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends the leaderboard to the client specified by targetID.
|
|
|
|
*/
|
2023-05-30 04:23:48 -07:00
|
|
|
void Send(const LWOOBJID targetID) const;
|
2023-05-08 18:36:28 -07:00
|
|
|
|
2024-12-06 03:03:47 -08:00
|
|
|
|
2023-05-08 18:36:28 -07:00
|
|
|
|
2024-12-06 03:03:47 -08:00
|
|
|
private:
|
2023-05-28 04:30:20 -07:00
|
|
|
using LeaderboardEntry = std::vector<LDFBaseData*>;
|
|
|
|
using LeaderboardEntries = std::vector<LeaderboardEntry>;
|
|
|
|
|
2023-04-12 21:57:58 -07:00
|
|
|
LeaderboardEntries entries;
|
2022-07-28 08:39:57 -05:00
|
|
|
LWOOBJID relatedPlayer;
|
2023-04-12 21:57:58 -07:00
|
|
|
GameID gameID;
|
|
|
|
InfoType infoType;
|
|
|
|
Leaderboard::Type leaderboardType;
|
2022-07-28 08:39:57 -05:00
|
|
|
bool weekly;
|
2024-12-06 03:03:47 -08:00
|
|
|
public:
|
|
|
|
LeaderboardEntry& PushBackEntry() {
|
|
|
|
return entries.emplace_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
Type GetLeaderboardType() const {
|
|
|
|
return leaderboardType;
|
|
|
|
}
|
2021-12-05 18:54:36 +01:00
|
|
|
};
|
|
|
|
|
2023-05-30 04:11:37 -07:00
|
|
|
namespace LeaderboardManager {
|
2024-12-06 03:03:47 -08:00
|
|
|
void SendLeaderboard(const GameID gameID, const Leaderboard::InfoType infoType, const bool weekly, const LWOOBJID playerID, const LWOOBJID targetID);
|
2023-05-08 18:36:28 -07:00
|
|
|
|
2023-06-05 04:10:59 -07:00
|
|
|
void SaveScore(const LWOOBJID& playerID, const GameID activityId, const float primaryScore, const float secondaryScore = 0, const float tertiaryScore = 0);
|
2023-05-08 18:36:28 -07:00
|
|
|
|
2023-05-30 04:11:37 -07:00
|
|
|
Leaderboard::Type GetLeaderboardType(const GameID gameID);
|
2023-06-05 04:10:59 -07:00
|
|
|
extern std::map<GameID, Leaderboard::Type> leaderboardCache;
|
2021-12-05 18:54:36 +01:00
|
|
|
};
|
|
|
|
|
2023-05-30 04:11:37 -07:00
|
|
|
#endif //!__LEADERBOARDMANAGER__H__
|