-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Highscores #4152
Closed
Closed
WIP: Highscores #4152
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
highscoresCache = {} | ||
highscoresTimestamps = {} | ||
highscoresMaxResults = 100 | ||
highscoresCacheTime = 30 * 60 -- 30 minutes | ||
highscoresExcludedGroups = {4, 5, 6} | ||
|
||
-- VocationId : VocationClientId | ||
local vocationIdsToClientIds = { | ||
[0] = 0, | ||
[1] = 3, | ||
[2] = 4, | ||
[3] = 2, | ||
[4] = 1, | ||
[5] = 13, | ||
[6] = 14, | ||
[7] = 12, | ||
[8] = 11 | ||
} | ||
|
||
highscoresQueries = { | ||
[HIGHSCORES_CATEGORY_LEVEL] = [[ | ||
SELECT `id`, `name`, `vocation`, `level`, `experience` AS `points` FROM `players` | ||
WHERE `deletion` = 0 %s | ||
AND `group_id` NOT IN (]] .. table.concat(highscoresExcludedGroups, ", ") .. [[) | ||
ORDER BY `points` DESC LIMIT %d, %d | ||
]], | ||
[HIGHSCORES_CATEGORY_MAGLEVEL] = [[ | ||
SELECT `id`, `name`, `vocation`, `level`, `maglevel` AS `points` FROM `players` | ||
WHERE `deletion` = 0 %s | ||
AND `group_id` NOT IN (]] .. table.concat(highscoresExcludedGroups, ", ") .. [[) | ||
ORDER BY `points` DESC, `manaspent` DESC LIMIT %d, %d | ||
]], | ||
[HIGHSCORES_CATEGORY_FIST_FIGHTING] = [[ | ||
SELECT `id`, `name`, `vocation`, `level`, `skill_fist` AS `points` FROM `players` | ||
WHERE `deletion` = 0 %s | ||
AND `group_id` NOT IN (]] .. table.concat(highscoresExcludedGroups, ", ") .. [[) | ||
ORDER BY `points` DESC, `skill_fist_tries` DESC LIMIT %d, %d | ||
]], | ||
[HIGHSCORES_CATEGORY_AXE_FIGHTING] = [[ | ||
SELECT `id`, `name`, `vocation`, `level`, `skill_axe` AS `points` FROM `players` | ||
WHERE `deletion` = 0 %s | ||
AND `group_id` NOT IN (]] .. table.concat(highscoresExcludedGroups, ", ") .. [[) | ||
ORDER BY `points` DESC, `skill_axe_tries` DESC LIMIT %d, %d | ||
]], | ||
[HIGHSCORES_CATEGORY_CLUB_FIGHTING] = [[ | ||
SELECT `id`, `name`, `vocation`, `level`, `skill_club` AS `points` FROM `players` | ||
WHERE `deletion` = 0 %s | ||
AND `group_id` NOT IN (]] .. table.concat(highscoresExcludedGroups, ", ") .. [[) | ||
ORDER BY `points` DESC, `skill_club_tries` DESC LIMIT %d, %d | ||
]], | ||
[HIGHSCORES_CATEGORY_SWORD_FIGHTING] = [[ | ||
SELECT `id`, `name`, `vocation`, `level`, `skill_sword` AS `points` FROM `players` | ||
WHERE `deletion` = 0 %s | ||
AND `group_id` NOT IN (]] .. table.concat(highscoresExcludedGroups, ", ") .. [[) | ||
ORDER BY `points` DESC, `skill_sword_tries` DESC LIMIT %d, %d | ||
]], | ||
[HIGHSCORES_CATEGORY_DISTANCE_FIGHTING] = [[ | ||
SELECT `id`, `name`, `vocation`, `level`, `skill_dist` AS `points` FROM `players` | ||
WHERE `deletion` = 0 %s | ||
AND `group_id` NOT IN (]] .. table.concat(highscoresExcludedGroups, ", ") .. [[) | ||
ORDER BY `points` DESC, `skill_dist_tries` DESC LIMIT %d, %d | ||
]], | ||
[HIGHSCORES_CATEGORY_SHIELDING] = [[ | ||
SELECT `id`, `name`, `vocation`, `level`, `skill_shielding` AS `points` FROM `players` | ||
WHERE `deletion` = 0 %s | ||
AND `group_id` NOT IN (]] .. table.concat(highscoresExcludedGroups, ", ") .. [[) | ||
ORDER BY `points` DESC, `skill_shielding_tries` DESC LIMIT %d, %d | ||
]], | ||
[HIGHSCORES_CATEGORY_FISHING] = [[ | ||
SELECT `id`, `name`, `vocation`, `level`, `skill_fishing` AS `points` FROM `players` | ||
WHERE `deletion` = 0 %s | ||
AND `group_id` NOT IN (]] .. table.concat(highscoresExcludedGroups, ", ") .. [[) | ||
ORDER BY `points` DESC, `skill_fishing_tries` DESC LIMIT %d, %d | ||
]], | ||
[HIGHSCORES_CATEGORY_ACHIEVEMENTS] = [[ | ||
SELECT `id`, `name`, `vocation`, `level`, `value` AS `points` FROM `player_storage` | ||
LEFT JOIN `players` ON `players`.`id` = `player_storage`.`player_id` | ||
WHERE `deletion` = 0 %s | ||
AND `player_storage`.`key` = ]] .. PlayerStorageKeys.achievementPoints .. [[ | ||
AND `group_id` NOT IN (]] .. table.concat(highscoresExcludedGroups, ", ") .. [[) | ||
ORDER BY `points` DESC, `name` ASC LIMIT %d, %d | ||
]] | ||
-- CUSTOM HIGHSCORE | ||
--[[, | ||
[HIGHSCORES_CATEGORY_DEATHS] = [[ | ||
SELECT DISTINCT(`id`) `id`, `name`, `vocation`, `players`.`level`, | ||
(SELECT COUNT(*) FROM `player_deaths` WHERE `player_deaths`.`player_id` = `players`.`id`) AS `points` | ||
FROM `players` | ||
LEFT JOIN `player_deaths` ON `player_deaths`.`player_id` = `players`.`id` | ||
WHERE `deletion` = 0 %s | ||
AND `group_id` NOT IN (4, 5, 6) | ||
ORDER BY `points` DESC, `name` ASC LIMIT %d, %d | ||
]] | ||
--]] | ||
} | ||
|
||
function getHighscores(params) | ||
if not highscoresQueries[params.category] then | ||
return {}, os.time() | ||
end | ||
|
||
local from = (params.page - 1) * 20 | ||
local to = params.page * 20 | ||
|
||
local vocWhere = "" | ||
if params.vocation ~= 0xFFFFFFFF then | ||
local ids = Vocation(params.vocation):getPromotions() or {VOCATION_NONE} | ||
vocWhere = "AND `vocation` IN (" .. table.concat(ids, ", ") .. ")" | ||
end | ||
|
||
local entries = {} | ||
local rank = from + 1 | ||
local resultId = db.storeQuery(string.format(highscoresQueries[params.category], vocWhere, from, to)) | ||
if resultId then | ||
repeat | ||
table.insert(entries, { | ||
id = result.getNumber(resultId, "id"), | ||
rank = rank, | ||
name = result.getString(resultId, "name"), | ||
title = "", | ||
vocation = vocationIdsToClientIds[result.getNumber(resultId, "vocation")], | ||
world = configManager.getString(configKeys.SERVER_NAME), | ||
level = result.getNumber(resultId, "level"), | ||
points = result.getNumber(resultId, "points") | ||
}) | ||
rank = rank + 1 | ||
until not result.next(resultId) | ||
result.free(resultId) | ||
end | ||
return entries | ||
end | ||
|
||
function getHighscoresCacheKey(params) | ||
if (params.world == "OWN" or params.world == "") then | ||
params.world = configManager.getString(configKeys.SERVER_NAME) | ||
end | ||
return string.format("%d%s%d%d", params.category, params.world, params.vocation, params.page) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you can do the network messaging in Lua and avoid messing with the table here. Something in #4043 might be helpful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean sending the HighscoresWindow part or handling the packets received from the client?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean
Player:onRequestHighscores
should return nothing, and should create aNetworkMessage
and fill it in Lua instead of returning a table and filling the network message in C++