mirror of
https://github.com/DarkflameUniverse/DarkflameServer
synced 2024-08-30 18:43:58 +00:00
It compiles at least now
This commit is contained in:
parent
83da45575e
commit
a43e03255c
@ -35,11 +35,11 @@ Leaderboard::~Leaderboard() {
|
||||
for (auto& entry : entries) for (auto data : entry) delete data;
|
||||
}
|
||||
|
||||
void Leaderboard::WriteLeaderboardRow(std::ostringstream& leaderboard, const uint32_t& index, LDFBaseData* data) {
|
||||
inline void WriteLeaderboardRow(std::ostringstream& leaderboard, const uint32_t& index, LDFBaseData* data) {
|
||||
leaderboard << "\nResult[0].Row[" << index << "]." << data->GetString();
|
||||
}
|
||||
|
||||
void Leaderboard::Serialize(RakNet::BitStream* bitStream) {
|
||||
void Leaderboard::Serialize(RakNet::BitStream* bitStream) const {
|
||||
bitStream->Write(gameID);
|
||||
bitStream->Write(infoType);
|
||||
|
||||
@ -172,6 +172,7 @@ const std::string_view Leaderboard::GetColumns(Leaderboard::Type leaderboardType
|
||||
columns = "bestTime, score";
|
||||
break;
|
||||
case Type::None:
|
||||
columns = "";
|
||||
// This type is included here simply to resolve a compiler warning on mac about unused enum types
|
||||
break;
|
||||
}
|
||||
@ -202,6 +203,7 @@ const std::string_view Leaderboard::GetInsertFormat(Leaderboard::Type leaderboar
|
||||
columns = "bestTime=%i, score=%i";
|
||||
break;
|
||||
case Type::None:
|
||||
columns = "";
|
||||
// This type is included here simply to resolve a compiler warning on mac about unused enum types
|
||||
break;
|
||||
}
|
||||
@ -234,6 +236,7 @@ const std::string_view Leaderboard::GetOrdering(Leaderboard::Type leaderboardTyp
|
||||
orderBase = "bestTime DESC, score DESC";
|
||||
break;
|
||||
case Type::None:
|
||||
orderBase = "";
|
||||
// This type is included here simply to resolve a compiler warning on mac about unused enum types
|
||||
break;
|
||||
}
|
||||
@ -349,7 +352,7 @@ void Leaderboard::Send(const LWOOBJID targetID) const {
|
||||
}
|
||||
}
|
||||
|
||||
std::string LeaderboardManager::FormatInsert(const Leaderboard::Type& type, const Score& score, const bool useUpdate) {
|
||||
std::string FormatInsert(const Leaderboard::Type& type, const Score& score, const bool useUpdate) {
|
||||
auto insertFormat = Leaderboard::GetInsertFormat(type);
|
||||
|
||||
auto* queryType = useUpdate ? "UPDATE" : "INSERT";
|
||||
@ -371,7 +374,7 @@ std::string LeaderboardManager::FormatInsert(const Leaderboard::Type& type, cons
|
||||
return finishedQuery;
|
||||
}
|
||||
|
||||
void LeaderboardManager::SaveScore(const LWOOBJID& playerID, GameID gameID, Leaderboard::Type leaderboardType, uint32_t primaryScore, uint32_t secondaryScore, uint32_t tertiaryScore) {
|
||||
void LeaderboardManager::SaveScore(const LWOOBJID& playerID, const GameID gameID, const Leaderboard::Type leaderboardType, const uint32_t primaryScore, const uint32_t secondaryScore, const uint32_t tertiaryScore) {
|
||||
auto* lookup = "SELECT * FROM leaderboard WHERE character_id = ? AND game_id = ?;";
|
||||
|
||||
std::unique_ptr<sql::PreparedStatement> query(Database::CreatePreppedStmt(lookup));
|
||||
@ -443,7 +446,7 @@ void LeaderboardManager::SaveScore(const LWOOBJID& playerID, GameID gameID, Lead
|
||||
saveStatement->execute();
|
||||
}
|
||||
|
||||
void LeaderboardManager::SendLeaderboard(uint32_t gameID, Leaderboard::InfoType infoType, bool weekly, LWOOBJID playerID, LWOOBJID targetID, uint32_t resultStart, uint32_t resultEnd) {
|
||||
void LeaderboardManager::SendLeaderboard(const uint32_t gameID, const Leaderboard::InfoType infoType, const bool weekly, const LWOOBJID playerID, const LWOOBJID targetID, const uint32_t resultStart, const uint32_t resultEnd) {
|
||||
Leaderboard leaderboard(gameID, infoType, weekly, playerID, GetLeaderboardType(gameID));
|
||||
leaderboard.SetupLeaderboard(resultStart, resultEnd);
|
||||
leaderboard.Send(targetID);
|
||||
|
@ -17,7 +17,39 @@ namespace RakNet {
|
||||
class BitStream;
|
||||
};
|
||||
|
||||
typedef uint32_t GameID;
|
||||
class Score {
|
||||
public:
|
||||
Score() {
|
||||
primaryScore = 0;
|
||||
secondaryScore = 0;
|
||||
tertiaryScore = 0;
|
||||
}
|
||||
Score(const uint32_t primaryScore, const uint32_t secondaryScore = 0, const uint32_t tertiaryScore = 0) {
|
||||
this->primaryScore = primaryScore;
|
||||
this->secondaryScore = secondaryScore;
|
||||
this->tertiaryScore = tertiaryScore;
|
||||
}
|
||||
bool operator<(const Score& rhs) const {
|
||||
return primaryScore < rhs.primaryScore || (primaryScore == rhs.primaryScore && secondaryScore < rhs.secondaryScore) || (primaryScore == rhs.primaryScore && secondaryScore == rhs.secondaryScore && tertiaryScore < rhs.tertiaryScore);
|
||||
}
|
||||
bool operator>(const Score& rhs) const {
|
||||
return primaryScore > rhs.primaryScore || (primaryScore == rhs.primaryScore && secondaryScore > rhs.secondaryScore) || (primaryScore == rhs.primaryScore && secondaryScore == rhs.secondaryScore && tertiaryScore > rhs.tertiaryScore);
|
||||
}
|
||||
void SetPrimaryScore(const uint32_t score) { primaryScore = score; }
|
||||
uint32_t GetPrimaryScore() const { return primaryScore; }
|
||||
|
||||
void SetSecondaryScore(const uint32_t score) { secondaryScore = score; }
|
||||
uint32_t GetSecondaryScore() const { return secondaryScore; }
|
||||
|
||||
void SetTertiaryScore(const uint32_t score) { tertiaryScore = score; }
|
||||
uint32_t GetTertiaryScore() const { return tertiaryScore; }
|
||||
private:
|
||||
uint32_t primaryScore;
|
||||
uint32_t secondaryScore;
|
||||
uint32_t tertiaryScore;
|
||||
};
|
||||
|
||||
using GameID = uint32_t;
|
||||
|
||||
class Leaderboard {
|
||||
public:
|
||||
@ -50,7 +82,7 @@ public:
|
||||
*
|
||||
* Expensive! Leaderboards are very string intensive so be wary of performatnce calling this method.
|
||||
*/
|
||||
void Serialize(RakNet::BitStream* bitStream);
|
||||
void Serialize(RakNet::BitStream* bitStream) const;
|
||||
|
||||
/**
|
||||
* Based on the associated gameID, return true if the score provided
|
||||
@ -79,8 +111,6 @@ public:
|
||||
static const std::string_view GetInsertFormat(Type leaderboardType);
|
||||
static const std::string_view GetOrdering(Type leaderboardType);
|
||||
private:
|
||||
inline void WriteLeaderboardRow(std::ostringstream& leaderboard, const uint32_t& index, LDFBaseData* data);
|
||||
|
||||
// Returns true if the string needs formatting
|
||||
bool GetRankingQuery(std::string& lookupReturn) const;
|
||||
|
||||
@ -100,53 +130,13 @@ private:
|
||||
};
|
||||
|
||||
namespace LeaderboardManager {
|
||||
class Score {
|
||||
public:
|
||||
Score() {
|
||||
primaryScore = 0;
|
||||
secondaryScore = 0;
|
||||
tertiaryScore = 0;
|
||||
}
|
||||
Score(const uint32_t primaryScore, const uint32_t secondaryScore = 0, const uint32_t tertiaryScore = 0) {
|
||||
this->primaryScore = primaryScore;
|
||||
this->secondaryScore = secondaryScore;
|
||||
this->tertiaryScore = tertiaryScore;
|
||||
}
|
||||
bool operator<(const Score& rhs) const {
|
||||
return primaryScore < rhs.primaryScore || (primaryScore == rhs.primaryScore && secondaryScore < rhs.secondaryScore) || (primaryScore == rhs.primaryScore && secondaryScore == rhs.secondaryScore && tertiaryScore < rhs.tertiaryScore);
|
||||
}
|
||||
bool operator>(const Score& rhs) const {
|
||||
return primaryScore > rhs.primaryScore || (primaryScore == rhs.primaryScore && secondaryScore > rhs.secondaryScore) || (primaryScore == rhs.primaryScore && secondaryScore == rhs.secondaryScore && tertiaryScore > rhs.tertiaryScore);
|
||||
}
|
||||
void SetPrimaryScore(const uint32_t score) { primaryScore = score; }
|
||||
uint32_t GetPrimaryScore() const { return primaryScore; }
|
||||
|
||||
void SetSecondaryScore(const uint32_t score) { secondaryScore = score; }
|
||||
uint32_t GetSecondaryScore() const { return secondaryScore; }
|
||||
|
||||
void SetTertiaryScore(const uint32_t score) { tertiaryScore = score; }
|
||||
uint32_t GetTertiaryScore() const { return tertiaryScore; }
|
||||
private:
|
||||
uint32_t primaryScore;
|
||||
uint32_t secondaryScore;
|
||||
uint32_t tertiaryScore;
|
||||
};
|
||||
|
||||
using LeaderboardCache = std::map<GameID, Leaderboard::Type>;
|
||||
void SendLeaderboard(GameID gameID, Leaderboard::InfoType infoType, bool weekly, LWOOBJID playerID, LWOOBJID targetID, uint32_t resultStart = 0, uint32_t resultEnd = 10);
|
||||
|
||||
/**
|
||||
* @brief Public facing Score saving method. This method is simply a wrapper to ensure va_end is called properly.
|
||||
*
|
||||
* @param playerID The player whos score to save
|
||||
* @param gameID The ID of the game which was played
|
||||
* @param argumentCount The number of arguments in the va_list
|
||||
* @param ... The score to save
|
||||
*/
|
||||
void SaveScore(const LWOOBJID& playerID, GameID gameID, Leaderboard::Type leaderboardType, uint32_t primaryScore, uint32_t secondaryScore = 0, uint32_t tertiaryScore = 0);
|
||||
void SaveScore(const LWOOBJID& playerID, const GameID gameID, const Leaderboard::Type leaderboardType, const uint32_t primaryScore, const uint32_t secondaryScore = 0, const uint32_t tertiaryScore = 0);
|
||||
|
||||
void GetLeaderboard(uint32_t gameID, Leaderboard::InfoType infoType, bool weekly, LWOOBJID playerID = LWOOBJID_EMPTY);
|
||||
std::string FormatInsert(const Leaderboard::Type& type, const Score& score, const bool useUpdate);
|
||||
void GetLeaderboard(const uint32_t gameID, const Leaderboard::InfoType infoType, const bool weekly, const LWOOBJID playerID = LWOOBJID_EMPTY);
|
||||
|
||||
Leaderboard::Type GetLeaderboardType(const GameID gameID);
|
||||
extern LeaderboardCache leaderboardCache;
|
||||
|
@ -36,7 +36,7 @@ ScriptedActivityComponent::ScriptedActivityComponent(Entity* parent, int activit
|
||||
|
||||
for (CDActivities activity : activities) {
|
||||
m_ActivityInfo = activity;
|
||||
if (static_cast<LeaderboardType>(activity.leaderboardType) == LeaderboardType::Racing && Game::config->GetValue("solo_racing") == "1") {
|
||||
if (static_cast<Leaderboard::Type>(activity.leaderboardType) == Leaderboard::Type::Racing && Game::config->GetValue("solo_racing") == "1") {
|
||||
m_ActivityInfo.minTeamSize = 1;
|
||||
m_ActivityInfo.minTeams = 1;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream* inStream, const System
|
||||
Entity* entity = EntityManager::Instance()->GetEntity(objectID);
|
||||
|
||||
User* usr = UserManager::Instance()->GetUser(sysAddr);
|
||||
if (messageID != 888) Game::logger->Log("GameMessageHandler", "message %i", messageID);
|
||||
if (messageID != eGameMessageType::READY_FOR_UPDATES) Game::logger->Log("GameMessageHandler", "message %i", messageID);
|
||||
if (!entity) {
|
||||
Game::logger->Log("GameMessageHandler", "Failed to find associated entity (%llu), aborting GM (%X)!", objectID, messageID);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user