Skip to content
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

admin2: Add resource settings cache #198

Closed
wants to merge 1 commit into from
Closed
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
58 changes: 50 additions & 8 deletions [admin]/admin2/server/admin_ACL.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
--[[**********************************
*
* Multi Theft Auto - Admin Panel
*
* admin_acl.lua
*
* Original File by lil_Toady
*
--[[**********************************
*
* Multi Theft Auto - Admin Panel
*
* admin_acl.lua
*
* Original File by lil_Toady
*
**************************************]]

local resourceSettingsCache = {}


addEventHandler("onSettingChange", root, function(setting, oldValue, newValue)
local allowedAccess = {["*"] = true, ["#"] = true, ["@"] = true}
local allowedTypes = {["boolean"] = true, ["number"] = true, ["string"] = true, ["table"] = true}

local accessScope, resName, settingName = setting:match("([@*#]?)(.-)%.(.+)")

newValue = (fromJSON(newValue) or tonumber(newValue) or newValue)

if (newValue == "true" or newValue == "false") then
newValue = (newValue == "true")
end

if (not resourceSettingsCache[resName]) then
return
end

if (not allowedAccess[accessScope] or not allowedTypes[type(newValue)]) then
return
end

local settings = resourceSettingsCache[resName]

if (settings.settings[settingName]) then
settings.settings[settingName].current = newValue
end
end)

function aSetupACL()
outputDebugString("Verifying ACL...")

Expand Down Expand Up @@ -117,6 +148,14 @@ function getResourceSettings(resName, bCountOnly)
local allowedTypes = {["boolean"] = true, ["number"] = true, ["string"] = true, ["table"] = true}
local count = 0

if (resourceSettingsCache[resName]) then
if (bCountOnly) then
return {}, resourceSettingsCache[resName].count
end

return resourceSettingsCache[resName].settings, resourceSettingsCache[resName].count
end

local rawsettings = get(resName .. ".")
if (not rawsettings) then
return {}, count
Expand Down Expand Up @@ -162,6 +201,9 @@ function getResourceSettings(resName, bCountOnly)
tableOut[name].desc = get(resName .. "." .. name .. ".desc")
end
end

resourceSettingsCache[resName] = { settings = tableOut, count = count }

return tableOut, count
end

Expand Down