Skip to content

Commit 30ac214

Browse files
committed
Move safeResName and pattern outside the loop for efficiency
1 parent 3269372 commit 30ac214

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

[admin]/admin/server/admin_settings.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,18 @@ function aGetResourceSettings( resName, bCountOnly )
2727
return {}, count
2828
end
2929
local settings = {}
30+
-- Escape special characters inside resName
31+
local safeResName = string.gsub(resName, '([^%w])', '%%%1')
32+
local namePattern = '^' .. safeResName .. '%.(.*)$'
3033
-- Parse raw settings
3134
for rawname,value in pairs(rawsettings) do
3235
if allowedTypes[type(value)] then
3336
if allowedAccess[string.sub(rawname,1,1)] then
3437
count = count + 1
3538
-- Remove leading '*','#' or '@'
3639
local temp = string.gsub(rawname, '^[%*%#%@](.*)', '%1')
37-
-- Escape special characters inside resName
38-
local safeResName = string.gsub(resName, '([^%w])', '%%%1')
3940
-- Remove leading 'resName.'
40-
local name = string.gsub(temp, '^' .. safeResName .. '%.(.*)$', '%1')
41+
local name = string.gsub(temp, namePattern, '%1')
4142
-- If name didn't have a leading 'resName.', then it must be the default setting
4243
local bIsDefault = ( temp == name )
4344
if settings[name] == nil then

[admin]/admin2/server/admin_ACL.lua

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function aSetupACL()
1414
local node = xmlLoadFile("conf\\ACL.xml")
1515

1616
if (not node) then
17-
outputDebugString("Vanilla ACL not found! Please reinstall the admin resource")
17+
outputDebugString("Vanilla ACL not found! Please reinstall the admin resource")
1818
return false
1919
end
2020

@@ -122,14 +122,15 @@ function getResourceSettings(resName, bCountOnly)
122122
return {}, count
123123
end
124124
local settings = {}
125+
local safeResName = string.gsub(resName, '([^%w])', '%%%1')
126+
local namePattern = '^' .. safeResName .. '%.(.*)$'
125127

126128
for rawname, value in pairs(rawsettings) do
127129
if (allowedTypes[type(value)]) then
128130
if allowedAccess[string.sub(rawname, 1, 1)] then
129131
count = count + 1
130132
local temp = string.gsub(rawname, '^[%*%#%@](.*)', '%1')
131-
local safeResName = string.gsub(resName, '([^%w])', '%%%1')
132-
local name = string.gsub(temp, '^' .. safeResName .. '%.(.*)$', '%1')
133+
local name = string.gsub(temp, namePattern, '%1')
133134
local bIsDefault = (temp == name)
134135
if (not settings[name]) then
135136
settings[name] = {}
@@ -171,7 +172,7 @@ local aACLFunctions = {
171172
if (action == ACL_ADD) then
172173
if (name and type(name) == "string") then
173174
if (aclCreateGroup(name)) then
174-
messageBox(client, "Successfully created group '" .. name .. "'", MB_INFO)
175+
messageBox(client, "Successfully created group '" .. name .. "'", MB_INFO)
175176
else
176177
messageBox(client, "Failed to create group '" .. name .. "'", MB_INFO)
177178
end
@@ -182,7 +183,7 @@ local aACLFunctions = {
182183
if (aclDestroyGroup(name)) then
183184
messageBox(client, "Successfully removed group '" .. name .. "'", MB_INFO)
184185
else
185-
messageBox(client, "Failed to remove group '" .. name .. "'", MB_INFO)
186+
messageBox(client, "Failed to remove group '" .. name .. "'", MB_INFO)
186187
end
187188
end
188189
messageBox(client, "Invalid group name", MB_INFO)
@@ -207,13 +208,13 @@ local aACLFunctions = {
207208
if (aclGroupRemoveObject(aclGetGroup(group), object)) then
208209
messageBox(client, "Successfully removed user '"..object:gsub('user.','').."' from the '"..group.."' ACL group", MB_INFO)
209210
else
210-
messageBox(client, "Failed to remove user '"..object:gsub('user.','').."' from the '"..group.."' ACL group", MB_INFO)
211+
messageBox(client, "Failed to remove user '"..object:gsub('user.','').."' from the '"..group.."' ACL group", MB_INFO)
211212
end
212213
elseif (action == ACL_ADD) then
213214
if (aclGroupAddObject(aclGetGroup(group), 'user.'..object)) then
214215
messageBox(client, "Successfully added user '"..object:gsub('user.','').."' to the '"..group.."' ACL group", MB_INFO)
215216
else
216-
messageBox(client, "Failed to add user '"..object:gsub('user.','').."' to the '"..group.."' ACL group", MB_INFO)
217+
messageBox(client, "Failed to add user '"..object:gsub('user.','').."' to the '"..group.."' ACL group", MB_INFO)
217218
end
218219
end
219220
end,
@@ -231,13 +232,13 @@ local aACLFunctions = {
231232
if (aclGroupRemoveObject(aclGetGroup(group), object)) then
232233
messageBox(client, "Successfully removed resource '"..object:gsub('resource.','').."' from the '"..group.."' ACL group", MB_INFO)
233234
else
234-
messageBox(client, "Failed to remove resource '"..object:gsub('resource.','').."' from the '"..group.."' ACL group", MB_INFO)
235+
messageBox(client, "Failed to remove resource '"..object:gsub('resource.','').."' from the '"..group.."' ACL group", MB_INFO)
235236
end
236237
elseif (action == ACL_ADD) then
237238
if (aclGroupAddObject(aclGetGroup(group), 'resource.'..object)) then
238239
messageBox(client, "Successfully added resource '"..object:gsub('resource.','').."' to the '"..group.."' ACL group", MB_INFO)
239240
else
240-
messageBox(client, "Failed to add resource '"..object:gsub('resource.','').."' to the '"..group.."' ACL group", MB_INFO)
241+
messageBox(client, "Failed to add resource '"..object:gsub('resource.','').."' to the '"..group.."' ACL group", MB_INFO)
241242
end
242243
end
243244
end,

0 commit comments

Comments
 (0)