mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-12-23 05:53:34 +00:00
Add some debug asserts
This commit is contained in:
parent
a595347211
commit
7b1626901a
@ -1,3 +1,5 @@
|
|||||||
|
#define _DEBUG
|
||||||
|
|
||||||
#include "LeaderboardManager.h"
|
#include "LeaderboardManager.h"
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "Database.h"
|
#include "Database.h"
|
||||||
@ -318,7 +320,7 @@ void Leaderboard::SetupLeaderboard(uint32_t resultStart, uint32_t resultEnd) {
|
|||||||
bool neededFormatting = GetRankingQuery(baseLookupStr);
|
bool neededFormatting = GetRankingQuery(baseLookupStr);
|
||||||
|
|
||||||
// If we need to format the base ranking query, do so, otherwise just copy the query since it's already formatted.
|
// If we need to format the base ranking query, do so, otherwise just copy the query since it's already formatted.
|
||||||
if (neededFormatting) snprintf(baseRankingBuffer, STRING_LENGTH, baseLookupStr.c_str(), orderBase.c_str());
|
if (neededFormatting) snprintf(baseRankingBuffer, STRING_LENGTH, baseLookupStr.c_str(), orderBase.data());
|
||||||
else std::copy(baseLookupStr.begin(), baseLookupStr.end() + 1, baseRankingBuffer);
|
else std::copy(baseLookupStr.begin(), baseLookupStr.end() + 1, baseRankingBuffer);
|
||||||
|
|
||||||
std::unique_ptr<sql::PreparedStatement> baseQuery(Database::CreatePreppedStmt(baseRankingBuffer));
|
std::unique_ptr<sql::PreparedStatement> baseQuery(Database::CreatePreppedStmt(baseRankingBuffer));
|
||||||
@ -369,12 +371,13 @@ std::string LeaderboardManager::FormatInsert(const Leaderboard::Type& type, cons
|
|||||||
// First fill in the format
|
// First fill in the format
|
||||||
constexpr uint16_t STRING_LENGTH = 400;
|
constexpr uint16_t STRING_LENGTH = 400;
|
||||||
char formattedInsert[STRING_LENGTH];
|
char formattedInsert[STRING_LENGTH];
|
||||||
snprintf(formattedInsert, STRING_LENGTH, "%s leaderboard SET %s %s;", queryType, insertFormat.data(), usedFilter);
|
int32_t res = snprintf(formattedInsert, STRING_LENGTH, "%s leaderboard SET %s %s;", queryType, insertFormat.data(), usedFilter);
|
||||||
|
DluAssert(res != -1);
|
||||||
|
|
||||||
// Then fill in our score
|
// Then fill in our score
|
||||||
char finishedQuery[STRING_LENGTH];
|
char finishedQuery[STRING_LENGTH];
|
||||||
snprintf(finishedQuery, STRING_LENGTH, formattedInsert, score.GetPrimaryScore(), score.GetSecondaryScore(), score.GetTertiaryScore());
|
res = snprintf(finishedQuery, STRING_LENGTH, formattedInsert, score.GetPrimaryScore(), score.GetSecondaryScore(), score.GetTertiaryScore());
|
||||||
DluAssert()
|
DluAssert(res != -1);
|
||||||
return finishedQuery;
|
return finishedQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,7 +389,7 @@ void LeaderboardManager::SaveScore(const LWOOBJID& playerID, GameID gameID, Lead
|
|||||||
query->setInt(2, gameID);
|
query->setInt(2, gameID);
|
||||||
std::unique_ptr<sql::ResultSet> myScoreResult(query->executeQuery());
|
std::unique_ptr<sql::ResultSet> myScoreResult(query->executeQuery());
|
||||||
|
|
||||||
std::string saveQuery;
|
std::string saveQuery("UPDATE leaderboard SET timesPlayed = timesPlayed + 1 WHERE character_id = ? AND game_id = ?;");
|
||||||
Score newScore(primaryScore, secondaryScore, tertiaryScore);
|
Score newScore(primaryScore, secondaryScore, tertiaryScore);
|
||||||
if (myScoreResult->next()) {
|
if (myScoreResult->next()) {
|
||||||
Score oldScore;
|
Score oldScore;
|
||||||
@ -439,8 +442,6 @@ void LeaderboardManager::SaveScore(const LWOOBJID& playerID, GameID gameID, Lead
|
|||||||
saveQuery = FormatInsert(leaderboardType, newScore, true);
|
saveQuery = FormatInsert(leaderboardType, newScore, true);
|
||||||
} else if (leaderboardType == Leaderboard::Type::Racing && tertiaryScore) {
|
} else if (leaderboardType == Leaderboard::Type::Racing && tertiaryScore) {
|
||||||
saveQuery = "UPDATE leaderboard SET numWins = numWins + 1, timesPlayed = timesPlayed + 1 WHERE character_id = ? AND game_id = ?;";
|
saveQuery = "UPDATE leaderboard SET numWins = numWins + 1, timesPlayed = timesPlayed + 1 WHERE character_id = ? AND game_id = ?;";
|
||||||
} else {
|
|
||||||
saveQuery = "UPDATE leaderboard SET timesPlayed = timesPlayed + 1 WHERE character_id = ? AND game_id = ?;";
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
saveQuery = FormatInsert(leaderboardType, newScore, false);
|
saveQuery = FormatInsert(leaderboardType, newScore, false);
|
||||||
|
Loading…
Reference in New Issue
Block a user