Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add subscription rank filter #1541

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Loader/Config/Settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ settings.MobileTheme = "Mobilius" -- Theme to use on mobile devices; Some UI el
settings.Ranks = {
["Moderators"] = {
Level = 100;
Users = {"Username"; "Username:UserId"; UserId; "Group:GroupId:GroupRank"; "Group:GroupId"; "Item:ItemID"; "GamePass:GamePassID";}
Users = {"Username"; "Username:UserId"; UserId; "Group:GroupId:GroupRank"; "Group:GroupId"; "Item:ItemID"; "GamePass:GamePassID"; "Subscription:SubscriptionId";}
}
}

Expand Down
3 changes: 3 additions & 0 deletions MainModule/Server/Core/Admin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,9 @@ return function(Vargs, GetEnv)
elseif filterName == "gamepass" then
local gamepassId = tonumber((string.match(filterData, "^%d+")))
return gamepassId and service.CheckPassOwnership(plr, gamepassId)
elseif filterName == "subscription" then
local subscriptionId = string.match(filterData, "^EXP%-%d+$")
return subscriptionId and service.CheckSubscriptionStatus(plr, subscriptionId)
else
local username, userId = string.match(check, "^(.*):(.*)")
if username and userId and (plr.UserId == tonumber(userId) or string.lower(plr.Name) == string.lower(username)) then
Expand Down
32 changes: 32 additions & 0 deletions MainModule/Server/Shared/Service.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ return function(errorHandler, eventChecker, fenceSpecific, env)
local service;
local passOwnershipCache = {}
local assetOwnershipCache = {}
local subscriptionStatusCache = {}
local assetInfoCache = {}
local groupInfoCache = {}
local changedLocale = nil -- This has to be nil at start, it will only be set once the user changes it in the game
Expand Down Expand Up @@ -1140,6 +1141,37 @@ return function(errorHandler, eventChecker, fenceSpecific, env)
end
end;

CheckSubscriptionStatus = function(player, subsriptionId)
if type(player) == "number" then
player = service.Players:GetPlayerByUserId(player)
end

local cacheIndex = `{player.UserId}-{subsriptionId}`
local currentCache = subscriptionStatusCache[cacheIndex]

if currentCache and currentCache.owned then
return true
elseif (currentCache and (os.time()-currentCache.lastUpdated > 60)) or not currentCache then
local cacheTab = {
owned = (currentCache and currentCache.owned) or false;
lastUpdated = os.time();
}
subscriptionStatusCache[cacheIndex] = cacheTab

local suc,ers = pcall(function()
return service.MarketplaceService:GetUserSubscriptionStatusAsync(player, subsriptionId)
end)

if suc then
cacheTab.owned = toBoolean(ers.IsSubscribed)
end

return cacheTab.owned
elseif currentCache then
return currentCache.owned
end
end;

GetGroupInfo = function(groupId)
groupId = tonumber(groupId) or 0

Expand Down
Loading