/
acl.lua
202 lines (143 loc) · 5.84 KB
/
acl.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
-- Copyright (C) 2015-2017 Timo 'Timothy' Smit
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- at your option any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local acl = require (wolfa_getLuaPath()..".auth.acl")
local commands = require (wolfa_getLuaPath()..".commands.commands")
function commandAclListLevels(cmdArguments)
for _, level in ipairs(acl.getLevels()) do
et.G_Print(string.format("%5d %30s %6d players", level["id"], level["name"], level["players"]).."\n")
end
end
function commandAclAddLevel(cmdArguments)
local levelId = tonumber(cmdArguments[2])
local name = cmdArguments[3]
if not levelId then
et.G_Print("usage: acl addlevel [id] [name]\n")
return true
elseif acl.isLevel(levelId) then
et.G_Print("error: level "..levelId.." already exists\n")
return true
end
acl.addLevel(levelId, name)
et.G_Print("added level "..levelId.." ("..name..")\n")
end
function commandAclRemoveLevel(cmdArguments)
local levelId = tonumber(cmdArguments[2])
if not levelId or not acl.isLevel(levelId) then
et.G_Print("usage: acl removelevel [id]\n")
return true
end
acl.removeLevelRoles(levelId)
acl.removeLevel(levelId)
et.G_Print("removed level "..levelId.."\n")
end
function commandAclReLevel(cmdArguments)
local levelId = tonumber(cmdArguments[2])
local newLevelId = tonumber(cmdArguments[3])
if not levelId or not acl.isLevel(levelId) or not newLevelId or not acl.isLevel(newLevelId) then
et.G_Print("usage: acl relevel [id] [newid]\n")
return true
end
acl.reLevel(levelId, newLevelId)
et.G_Print("releveled all players with "..levelId.." to "..newLevelId.."\n")
end
function commandAclListLevelRoles(cmdArguments)
local levelId = tonumber(cmdArguments[2])
if not levelId or not acl.isLevel(levelId) then
et.G_Print("usage: acl listroles [id]\n")
return true
end
et.G_Print("roles for level "..levelId..":\n")
for _, role in ipairs(acl.getLevelRoles(levelId)) do
et.G_Print(role.."\n")
end
end
function commandAclIsAllowed(cmdArguments)
local levelId = tonumber(cmdArguments[2])
local role = cmdArguments[3]
if not levelId or not acl.isLevel(levelId) or not role then
et.G_Print("usage: acl isallowed [id] [role]\n")
return true
end
local isAllowed = acl.isLevelAllowed(levelId, role)
et.G_Print("level "..levelId.." "..(isAllowed and "HAS" or "HAS NOT").." "..role.."\n")
end
function commandAclAddLevelRole(cmdArguments)
local levelId = tonumber(cmdArguments[2])
local role = cmdArguments[3]
if not levelId or not acl.isLevel(levelId) or not role then
et.G_Print("usage: acl addrole [id] [role]\n")
return true
end
local isAllowed = acl.isLevelAllowed(levelId, role)
if isAllowed then
et.G_Print("error: level "..levelId.." already has '"..role.."'\n")
return true
end
acl.addLevelRole(levelId, role)
et.G_Print("added role "..role.." to level "..levelId.."\n")
end
function commandAclRemoveLevelRole(cmdArguments)
local levelId = tonumber(cmdArguments[2])
local role = cmdArguments[3]
if not levelId or not acl.isLevel(levelId) or not role then
et.G_Print("usage: acl removerole [id] [role]\n")
return true
end
local isAllowed = acl.isLevelAllowed(levelId, role)
if not isAllowed then
et.G_Print("error: level "..levelId.." does not have '"..role.."'\n")
return true
end
acl.removeLevelRole(levelId, role)
et.G_Print("removed role "..role.." from level "..levelId.."\n")
end
function commandAclCopyLevelRoles(cmdArguments)
local levelId = tonumber(cmdArguments[2])
local newLevelId = tonumber(cmdArguments[3])
if not levelId or not acl.isLevel(levelId) or not newLevelId or not acl.isLevel(newLevelId) then
et.G_Print("usage: acl copyroles [id] [newid]\n")
return true
end
if #acl.getLevelRoles(newLevelId) ~= 0 then
et.G_Print("error: level "..newLevelId.." already has roles\n")
return true
end
acl.copyLevelRoles(levelId, newLevelId)
et.G_Print("copied roles from "..levelId.." to "..newLevelId.."\n")
end
function commandAcl(cmdArguments)
local cmd = cmdArguments[1]
if cmd == "listlevels" then
return commandAclListLevels(cmdArguments)
elseif cmd == "addlevel" then
return commandAclAddLevel(cmdArguments)
elseif cmd == "removelevel" then
return commandAclRemoveLevel(cmdArguments)
elseif cmd == "relevel" then
return commandAclReLevel(cmdArguments)
elseif cmd == "listroles" then
return commandAclListLevelRoles(cmdArguments)
elseif cmd == "isallowed" then
return commandAclIsAllowed(cmdArguments)
elseif cmd == "addrole" then
return commandAclAddLevelRole(cmdArguments)
elseif cmd == "removerole" then
return commandAclRemoveLevelRole(cmdArguments)
elseif cmd == "copyroles" then
return commandAclCopyLevelRoles(cmdArguments)
else
et.G_Print("usage: acl [listlevels|addlevel|removelevel|relevel|listroles|isallowed|addrole|removerole|copyroles]")
end
return true
end
commands.addserver("acl", commandAcl, (settings.get("g_standalone") == 0))