Misc auth improvements (refs #69, #75)

* renamed methods to camelCase
* renamed methods to be more precise
* auth.isPlayerAllowed now returns boolean values
This commit is contained in:
Timo Smit 2017-01-21 12:16:26 +01:00
parent 004ebea736
commit 9012d54da4
22 changed files with 46 additions and 50 deletions

View file

@ -48,14 +48,10 @@ function acl.clearCache()
data = {}
end
function acl.isallowed(clientId, permission)
function acl.isPlayerAllowed(clientId, permission)
local level = acl.getlevel(clientId)
if data[level] ~= nil and tables.contains(data[level], permission) then
return 1
end
return 0
return data[level] ~= nil and tables.contains(data[level], permission)
end
function acl.getLevels()
@ -118,13 +114,13 @@ function acl.removeLevelRoles(levelId)
data[levelId] = {}
end
function acl.getlevel(clientId)
function acl.getPlayerLevel(clientId)
local player = db.getplayer(players.getGUID(clientId))
return player["level_id"]
end
function acl.getlevelname(levelId)
function acl.getLevelName(levelId)
local level = db.getLevel(levelId)
return level["name"]

View file

@ -112,7 +112,7 @@ auth.PERM_IMMUNE = "immune"
-- as this module serves as a wrapper/super class, we load the selected database
-- system in this function. might have to think of a better way to implement
-- this, but it will suffice.
function auth.oninit()
function auth.onGameInit()
if settings.get("g_standalone") == 1 then
srv = require (wolfa_getLuaPath()..".auth.acl")
else
@ -125,6 +125,6 @@ function auth.oninit()
setmetatable(auth, {__index = srv})
end
events.handle("onGameInit", auth.oninit)
events.handle("onGameInit", auth.onGameInit)
return auth

View file

@ -111,11 +111,11 @@ local flags = {
[auth.PERM_IMMUNE] = "!",
}
function shrubbot.isallowed(clientId, permission)
return et.G_shrubbot_permission(clientId, flags[permission])
function shrubbot.isPlayerAllowed(clientId, permission)
return et.G_shrubbot_permission(clientId, flags[permission]) == 1
end
function shrubbot.getlevel(clientId)
function shrubbot.getPlayerLevel(clientId)
return et.G_shrubbot_level(clientId)
end

View file

@ -24,8 +24,8 @@ local players = require (wolfa_getLuaPath()..".players.players")
local settings = require (wolfa_getLuaPath()..".util.settings")
function commandAdminTest(clientId, cmdArguments)
local level = auth.getlevel(clientId)
local levelName = auth.getlevelname(level)
local level = auth.getPlayerLevel(clientId)
local levelName = auth.getLevelName(level)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dadmintest: ^7"..players.getName(clientId).." ^9is a level "..level.." user (^7"..levelName.."^9).\";")

View file

@ -55,17 +55,17 @@ function commandBan(clientId, cmdArguments)
duration = util.getTimeFromString(cmdArguments[2])
elseif cmdArguments[2] then
reason = table.concat(cmdArguments, " ", 2)
elseif auth.isallowed(clientId, "8") ~= 1 then
elseif not auth.isPlayerAllowed(clientId, "8") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dban usage: "..commands.getadmin("ban")["syntax"].."\";")
return true
end
if auth.isallowed(cmdClient, "!") == 1 then
if auth.isPlayerAllowed(cmdClient, "!") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dban: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is immune to this command.\";")
return true
elseif auth.getlevel(cmdClient) > auth.getlevel(clientId) then
elseif auth.getPlayerLevel(cmdClient) > auth.getPlayerLevel(clientId) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dban: ^9sorry, but your intended victim has a higher admin level than you do.\";")
return true

View file

@ -44,11 +44,11 @@ function commandGib(clientId, cmdArguments)
return true
end
if auth.isallowed(cmdClient, "!") == 1 then
if auth.isPlayerAllowed(cmdClient, "!") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dgib: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is immune to this command.\";")
return true
elseif auth.getlevel(cmdClient) > auth.getlevel(clientId) then
elseif auth.getPlayerLevel(cmdClient) > auth.getPlayerLevel(clientId) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dgib: ^9sorry, but your intended victim has a higher admin level than you do.\";")
return true

View file

@ -26,7 +26,7 @@ function commandHelp(clientId, cmdArguments)
local availableCommands = {}
for command, data in pairs(cmds) do
if data["function"] and data["flag"] and auth.isallowed(clientId, data["flag"]) == 1 and (not data["hidden"] or (type(data["hidden"]) == "function" and not data["hidden"]())) then
if data["function"] and data["flag"] and auth.isPlayerAllowed(clientId, data["flag"]) and (not data["hidden"] or (type(data["hidden"]) == "function" and not data["hidden"]())) then
table.insert(availableCommands, command)
end
end

View file

@ -40,7 +40,7 @@ function commandIncognito(clientId, cmdArguments)
-- et.G_Print(string.format("%s %s %d %s\n", adminName, adminGUID, adminLevel, adminFlags))
if players.getGUID(clientId) == adminGUID then
if auth.isallowed(clientId, "@") ~= 1 then
if not auth.isPlayerAllowed(clientId, "@") then
adminFlags = adminFlags.."+@"
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..clientId.." \"^dincognito: ^9you are now playing incognito.\";")

View file

@ -45,11 +45,11 @@ function commandKick(clientId, cmdArguments)
return true
end
if auth.isallowed(cmdClient, "!") == 1 then
if auth.isPlayerAllowed(cmdClient, "!") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dkick: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is immune to this command.\";")
return true
elseif auth.getlevel(cmdClient) > auth.getlevel(clientId) then
elseif auth.getPlayerLevel(cmdClient) > auth.getPlayerLevel(clientId) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dkick: ^9sorry, but your intended victim has a higher admin level than you do.\";")
return true

View file

@ -52,11 +52,11 @@ function commandListAliases(clientId, cmdArguments)
return true
end
if auth.isallowed(cmdClient, "!") == 1 then
if auth.isPlayerAllowed(cmdClient, "!") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistaliases: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is immune to this command.\";")
return true
elseif auth.getlevel(cmdClient) > auth.getlevel(clientId) then
elseif auth.getPlayerLevel(cmdClient) > auth.getPlayerLevel(clientId) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlistaliases: ^9sorry, but your intended victim has a higher admin level than you do.\";")
return true

View file

@ -47,8 +47,8 @@ function commandListPlayers(clientId, cmdArguments)
guidStub = players.getGUID(player):sub(-8)
end
local level = auth.getlevel(player)
local levelName = auth.getlevelname(level)
local level = auth.getPlayerLevel(player)
local levelName = auth.getLevelName(level)
local teamColor, teamCode

View file

@ -58,7 +58,7 @@ function commandMute(clientId, cmdArguments)
duration = util.getTimeFromString(cmdArguments[2])
elseif cmdArguments[2] then
reason = table.concat(cmdArguments, " ", 2)
elseif auth.isallowed(clientId, "8") ~= 1 then
elseif not auth.isPlayerAllowed(clientId, "8") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dmute usage: "..commands.getadmin("mute")["syntax"].."\";")
return true
@ -68,11 +68,11 @@ function commandMute(clientId, cmdArguments)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is already muted.\";")
return true
elseif auth.isallowed(cmdClient, "!") == 1 then
elseif auth.isPlayerAllowed(cmdClient, "!") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is immune to this command.\";")
return true
elseif auth.getlevel(cmdClient) > auth.getlevel(clientId) then
elseif auth.getPlayerLevel(cmdClient) > auth.getPlayerLevel(clientId) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dmute: ^9sorry, but your intended victim has a higher admin level than you do.\";")
return true

View file

@ -48,11 +48,11 @@ function commandPlayerLock(clientId, cmdArguments)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dplock: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is already locked to a team.\";")
return true
elseif auth.isallowed(cmdClient, "!") == 1 then
elseif auth.isPlayerAllowed(cmdClient, "!") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dplock: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is immune to this command.\";")
return true
elseif auth.getlevel(cmdClient) > auth.getlevel(clientId) then
elseif auth.getPlayerLevel(cmdClient) > auth.getPlayerLevel(clientId) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dplock: ^9sorry, but your intended victim has a higher admin level than you do.\";")
return true

View file

@ -42,11 +42,11 @@ function commandPlayerLock(clientId, cmdArguments)
return true
end
if auth.isallowed(cmdClient, "!") == 1 then
if auth.isPlayerAllowed(cmdClient, "!") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dput: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is immune to this command.\";")
return true
elseif auth.getlevel(cmdClient) > auth.getlevel(cmdClient) then
elseif auth.getPlayerLevel(cmdClient) > auth.getPlayerLevel(cmdClient) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dput: ^9sorry, but your intended victim has a higher admin level than you do.\";")
return true

View file

@ -65,7 +65,7 @@ function commandSetLevel(clientId, cmdArguments)
return true
end
if auth.getlevel(cmdClient) > auth.getlevel(clientId) then
if auth.getPlayerLevel(cmdClient) > auth.getPlayerLevel(clientId) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dsetlevel: ^9sorry, but your intended victim has a higher admin level than you do.\";")
return true

View file

@ -44,11 +44,11 @@ function commandSlap(clientId, cmdArguments)
return true
end
if auth.isallowed(cmdClient, "!") == 1 then
if auth.isPlayerAllowed(cmdClient, "!") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dslap: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is immune to this command.\";")
return true
elseif auth.getlevel(cmdClient) > auth.getlevel(clientId) then
elseif auth.getPlayerLevel(cmdClient) > auth.getPlayerLevel(clientId) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dslap: ^9sorry, but your intended victim has a higher admin level than you do.\";")
return true

View file

@ -56,7 +56,7 @@ function commandVoiceMute(clientId, cmdArguments)
duration = util.getTimeFromString(cmdArguments[2])
elseif cmdArguments[2] then
reason = table.concat(cmdArguments, " ", 2)
elseif auth.isallowed(clientId, "8") ~= 1 then
elseif not auth.isPlayerAllowed(clientId, "8") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvmute usage: "..commands.getadmin("vmute")["syntax"].."\";")
return true
@ -66,11 +66,11 @@ function commandVoiceMute(clientId, cmdArguments)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is already muted.\";")
return true
elseif auth.isallowed(cmdClient, "!") == 1 then
elseif auth.isPlayerAllowed(cmdClient, "!") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is immune to this command.\";")
return true
elseif auth.getlevel(cmdClient) > auth.getlevel(clientId) then
elseif auth.getPlayerLevel(cmdClient) > auth.getPlayerLevel(clientId) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvmute: ^9sorry, but your intended victim has a higher admin level than you do.\";")
return true

View file

@ -72,7 +72,7 @@ function commandWarn(clientId, cmdArguments)
return true
end
if auth.getlevel(cmdClient) > auth.getlevel(clientId) then
if auth.getPlayerLevel(cmdClient) > auth.getPlayerLevel(clientId) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dwarn: ^9sorry, but your intended victim has a higher admin level than you do.\";")
return true

View file

@ -33,7 +33,7 @@ function commandAdminChat(clientId, cmdArguments)
end
for playerId = 0, et.trap_Cvar_Get("sv_maxclients") - 1 do
if players.isConnected(playerId) and auth.isallowed(playerId, "~") == 1 then
if players.isConnected(playerId) and auth.isPlayerAllowed(playerId, "~") then
table.insert(recipients, playerId)
end
end

View file

@ -207,7 +207,7 @@ function commands.onClientCommand(clientId, cmdText)
-- mod-specific or custom commands loading
-- syntax: command arg1 arg2 ... argN
if clientcmds[wolfCmd] and clientcmds[wolfCmd]["function"] and clientcmds[wolfCmd]["flag"] then
if clientcmds[wolfCmd]["flag"] == "" or auth.isallowed(clientId, clientcmds[wolfCmd]["flag"]) == 1 then
if clientcmds[wolfCmd]["flag"] == "" or auth.isPlayerAllowed(clientId, clientcmds[wolfCmd]["flag"]) then
for i = 1, et.trap_Argc() - 1 do
cmdArguments[i] = et.trap_Argv(i)
end
@ -247,7 +247,7 @@ function commands.onClientCommand(clientId, cmdText)
clientCmd = string.lower(clientCmd)
if clientcmds[clientCmd] and clientcmds[clientCmd]["function"] and clientcmds[clientCmd]["chat"] then
if clientcmds[clientCmd]["flag"] == "" or auth.isallowed(clientId, clientcmds[clientCmd]["flag"]) == 1 then
if clientcmds[clientCmd]["flag"] == "" or auth.isPlayerAllowed(clientId, clientcmds[clientCmd]["flag"]) then
return clientcmds[clientCmd]["function"](clientId, cmdArguments) and 1 or 0
end
end
@ -288,8 +288,8 @@ function commands.onClientCommand(clientId, cmdText)
shrubCmd = string.lower(shrubCmd)
if admincmds[shrubCmd] and admincmds[shrubCmd]["function"] and admincmds[shrubCmd]["flag"] then
if wolfCmd == "say" or (((wolfCmd == "say_team" and et.gentity_get(cmdClient, "sess.sessionTeam") ~= et.TEAM_SPECTATORS) or wolfCmd == "say_buddy") and auth.isallowed(clientId, auth.PERM_TEAMCMDS) == 1) or (wolfCmd == "!"..shrubCmd and auth.isallowed(clientId, auth.PERM_SILENTCMDS) == 1) then
if admincmds[shrubCmd]["flag"] ~= "" and auth.isallowed(clientId, admincmds[shrubCmd]["flag"]) == 1 then
if wolfCmd == "say" or (((wolfCmd == "say_team" and et.gentity_get(cmdClient, "sess.sessionTeam") ~= et.TEAM_SPECTATORS) or wolfCmd == "say_buddy") and auth.isPlayerAllowed(clientId, auth.PERM_TEAMCMDS)) or (wolfCmd == "!"..shrubCmd and auth.isPlayerAllowed(clientId, auth.PERM_SILENTCMDS)) then
if admincmds[shrubCmd]["flag"] ~= "" and auth.isPlayerAllowed(clientId, admincmds[shrubCmd]["flag"]) then
local isFinished = admincmds[shrubCmd]["function"](clientId, cmdArguments)
if not admincmds[shrubCmd]["hidden"] then

View file

@ -89,7 +89,7 @@ events.handle("onGameStateChange", voting.ongamestatechange)
function voting.oncallvote(clientId, type, args)
if et.gentity_get(clientId, "sess.sessionTeam") == constants.TEAM_SPECTATORS or args[1] == "?" then
return 0
elseif voting.isrestricted(type) and auth.isallowed(clientId, PERM_NOVOTELIMIT) ~= 1 then
elseif voting.isrestricted(type) and not auth.isPlayerAllowed(clientId, PERM_NOVOTELIMIT) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"callvote: you are not allowed to call this type of vote.\";")
et.trap_SendServerCommand(clientId, "cp \"You are not allowed to call this type of vote.")

View file

@ -31,9 +31,9 @@ local userGreetings = {}
local levelGreetings = {}
function greetings.get(clientId)
local lvl = auth.getlevel(clientId)
local lvl = auth.getPlayerLevel(clientId)
if auth.isallowed(clientId, auth.PERM_INCOGNITO) ~= 1 then
if not auth.isPlayerAllowed(clientId, auth.PERM_INCOGNITO) then
if userGreetings[players.getGUID(clientId)] ~= nil then
return userGreetings[players.getGUID(clientId)]
elseif levelGreetings[lvl] ~= nil then