mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-09 17:58:20 +00:00
Implement leaderboard page offsets
This commit is contained in:
parent
5c086909ed
commit
d98ad4b94f
@ -14,7 +14,6 @@ std::vector<MetricVariable> Metrics::m_Variables = {
|
||||
MetricVariable::CPUTime,
|
||||
MetricVariable::Sleep,
|
||||
MetricVariable::Frame,
|
||||
MetricVariable::Leaderboard,
|
||||
};
|
||||
|
||||
void Metrics::AddMeasurement(MetricVariable variable, int64_t value) {
|
||||
|
@ -33,6 +33,9 @@ void Leaderboard::WriteLeaderboardRow(std::ostringstream& leaderboard, const uin
|
||||
}
|
||||
|
||||
void Leaderboard::Serialize(RakNet::BitStream* bitStream) {
|
||||
bitStream->Write(gameID);
|
||||
bitStream->Write(leaderboardType);
|
||||
|
||||
std::ostringstream leaderboard;
|
||||
|
||||
leaderboard << "ADO.Result=7:1\n"; // Unused in 1.10.64, but is in captures
|
||||
@ -49,7 +52,9 @@ void Leaderboard::Serialize(RakNet::BitStream* bitStream) {
|
||||
}
|
||||
|
||||
// Serialize the thing to a BitStream
|
||||
bitStream->Write(leaderboard.str().c_str(), leaderboard.tellp());
|
||||
bitStream->WriteAlignedBytes((const unsigned char*)leaderboard.str().c_str(), leaderboard.tellp());
|
||||
bitStream->Write0();
|
||||
bitStream->Write0();
|
||||
}
|
||||
|
||||
bool Leaderboard::GetRankingQuery(std::string& lookupReturn) const {
|
||||
@ -234,7 +239,7 @@ std::string Leaderboard::GetOrdering(Leaderboard::Type leaderboardType) {
|
||||
return orderBase;
|
||||
}
|
||||
|
||||
void Leaderboard::SetupLeaderboard() {
|
||||
void Leaderboard::SetupLeaderboard(uint32_t resultStart, uint32_t resultEnd) {
|
||||
std::string queryBase =
|
||||
R"QUERY(
|
||||
WITH leaderboardsRanked AS (
|
||||
@ -259,9 +264,9 @@ void Leaderboard::SetupLeaderboard() {
|
||||
SELECT %s, character_id, UNIX_TIMESTAMP(last_played) as lastPlayed, leaderboardsRanked.name, leaderboardsRanked.ranking FROM leaderboardsRanked, myStanding, lowestRanking
|
||||
WHERE leaderboardsRanked.ranking
|
||||
BETWEEN
|
||||
LEAST(GREATEST(CAST(myRank AS SIGNED) - 5, 1), lowestRanking.lowestRank - 10)
|
||||
LEAST(GREATEST(CAST(myRank AS SIGNED) - 5, %i), lowestRanking.lowestRank - 10)
|
||||
AND
|
||||
LEAST(GREATEST(myRank + 5, 11), lowestRanking.lowestRank)
|
||||
LEAST(GREATEST(myRank + 5, %i), lowestRanking.lowestRank)
|
||||
ORDER BY ranking ASC;
|
||||
)QUERY";
|
||||
|
||||
@ -289,8 +294,14 @@ void Leaderboard::SetupLeaderboard() {
|
||||
constexpr uint16_t STRING_LENGTH = 1526;
|
||||
char lookupBuffer[STRING_LENGTH];
|
||||
// If we are getting the friends leaderboard, add the friends query, otherwise fill it in with nothing.
|
||||
if (this->infoType == InfoType::Friends) snprintf(lookupBuffer, STRING_LENGTH, queryBase.c_str(), orderBase.c_str(), friendsQuery, selectBase.c_str());
|
||||
else snprintf(lookupBuffer, STRING_LENGTH, queryBase.c_str(), orderBase.c_str(), "", selectBase.c_str());
|
||||
if (this->infoType == InfoType::Friends) {
|
||||
snprintf(lookupBuffer, STRING_LENGTH, queryBase.c_str(),
|
||||
orderBase.c_str(), friendsQuery, selectBase.c_str(), resultStart + 1, resultEnd + 1);
|
||||
}
|
||||
else {
|
||||
snprintf(lookupBuffer, STRING_LENGTH, queryBase.c_str(),
|
||||
orderBase.c_str(), "", selectBase.c_str(), resultStart + 1, resultEnd + 1);
|
||||
}
|
||||
|
||||
std::string baseLookupStr;
|
||||
char baseRankingBuffer[STRING_LENGTH];
|
||||
@ -328,7 +339,7 @@ void Leaderboard::SetupLeaderboard() {
|
||||
QueryToLdf(result);
|
||||
}
|
||||
|
||||
void Leaderboard::Send(LWOOBJID targetID) const {
|
||||
void Leaderboard::Send(LWOOBJID targetID) {
|
||||
auto* player = EntityManager::Instance()->GetEntity(relatedPlayer);
|
||||
if (player != nullptr) {
|
||||
GameMessages::SendActivitySummaryLeaderboardData(targetID, this, player->GetSystemAddress());
|
||||
@ -516,14 +527,12 @@ void LeaderboardManager::SaveScore(const LWOOBJID& playerID, GameID gameID, Lead
|
||||
va_end(argsCopy);
|
||||
}
|
||||
|
||||
// Done
|
||||
void LeaderboardManager::SendLeaderboard(uint32_t gameID, Leaderboard::InfoType infoType, bool weekly, LWOOBJID targetID, LWOOBJID playerID) {
|
||||
Leaderboard leaderboard(gameID, infoType, weekly, playerID, GetLeaderboardType(gameID));
|
||||
leaderboard.SetupLeaderboard();
|
||||
leaderboard.Send(targetID);
|
||||
}
|
||||
|
||||
// Done
|
||||
Leaderboard::Type LeaderboardManager::GetLeaderboardType(const GameID gameID) {
|
||||
auto lookup = leaderboardCache.find(gameID);
|
||||
if (lookup != leaderboardCache.end()) return lookup->second;
|
||||
|
@ -64,12 +64,12 @@ public:
|
||||
/**
|
||||
* Builds the leaderboard from the database based on the associated gameID
|
||||
*/
|
||||
void SetupLeaderboard();
|
||||
void SetupLeaderboard(uint32_t resultStart = 0, uint32_t resultEnd = 10);
|
||||
|
||||
/**
|
||||
* Sends the leaderboard to the client specified by targetID.
|
||||
*/
|
||||
void Send(LWOOBJID targetID) const;
|
||||
void Send(LWOOBJID targetID);
|
||||
|
||||
// Helper functions to get the columns, ordering and insert format for a leaderboard
|
||||
static std::string GetColumns(Type leaderboardType);
|
||||
|
@ -1631,26 +1631,14 @@ void GameMessages::HandleActivitySummaryLeaderboardData(RakNet::BitStream* instr
|
||||
Game::logger->Log("AGS", "We got mail!");
|
||||
}
|
||||
|
||||
void GameMessages::SendActivitySummaryLeaderboardData(const LWOOBJID& objectID, const Leaderboard* leaderboard, const SystemAddress& sysAddr) {
|
||||
void GameMessages::SendActivitySummaryLeaderboardData(const LWOOBJID& objectID, Leaderboard* leaderboard, const SystemAddress& sysAddr) {
|
||||
CBITSTREAM;
|
||||
CMSGHEADER;
|
||||
|
||||
bitStream.Write(objectID);
|
||||
bitStream.Write(GAME_MSG::GAME_MSG_SEND_ACTIVITY_SUMMARY_LEADERBOARD_DATA);
|
||||
throw "";
|
||||
//bitStream.Write(leaderboard->GetGameID());
|
||||
//bitStream.Write(leaderboard->GetInfoType());
|
||||
|
||||
// Leaderboard is written back as LDF string
|
||||
//const auto leaderboardString = leaderboard->ToString();
|
||||
//bitStream.Write<uint32_t>(leaderboardString.size());
|
||||
//for (const auto c : leaderboardString) {
|
||||
// bitStream.Write<uint16_t>(c);
|
||||
//}
|
||||
//if (!leaderboardString.empty()) bitStream.Write(uint16_t(0));
|
||||
|
||||
bitStream.Write0();
|
||||
bitStream.Write0();
|
||||
leaderboard->Serialize(&bitStream);
|
||||
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
@ -561,7 +561,7 @@ namespace GameMessages {
|
||||
void SendUpdateReputation(const LWOOBJID objectId, const int64_t reputation, const SystemAddress& sysAddr);
|
||||
|
||||
// Leaderboards
|
||||
void SendActivitySummaryLeaderboardData(const LWOOBJID& objectID, const Leaderboard* leaderboard,
|
||||
void SendActivitySummaryLeaderboardData(const LWOOBJID& objectID, 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