From b16f38a08a561e0786c98e541b81fc44651e050b Mon Sep 17 00:00:00 2001 From: xLuxy Date: Thu, 21 May 2020 13:12:19 +0200 Subject: [PATCH] admin2 (https://github.com/multitheftauto/mtasa-resources/issues/162): Add resource settings cache --- [admin]/admin2/server/admin_ACL.lua | 58 +++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/[admin]/admin2/server/admin_ACL.lua b/[admin]/admin2/server/admin_ACL.lua index 11f01a5c0..20023dc03 100644 --- a/[admin]/admin2/server/admin_ACL.lua +++ b/[admin]/admin2/server/admin_ACL.lua @@ -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...") @@ -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 @@ -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