@@ -167,6 +167,18 @@ core.register_chatcommand("admin", {
167
167
end ,
168
168
})
169
169
170
+ local function privileges_of (name , privs )
171
+ if not privs then
172
+ privs = core .get_player_privs (name )
173
+ end
174
+ local privstr = core .privs_to_string (privs , " , " )
175
+ if privstr == " " then
176
+ return S (" @1 does not have any privileges." , name )
177
+ else
178
+ return S (" Privileges of @1: @2" , name , privstr )
179
+ end
180
+ end
181
+
170
182
core .register_chatcommand (" privs" , {
171
183
params = S (" [<name>]" ),
172
184
description = S (" Show privileges of yourself or another player" ),
@@ -176,9 +188,7 @@ core.register_chatcommand("privs", {
176
188
if not core .player_exists (name ) then
177
189
return false , S (" Player @1 does not exist." , name )
178
190
end
179
- return true , S (" Privileges of @1: @2" , name ,
180
- core .privs_to_string (
181
- core .get_player_privs (name ), " , " ))
191
+ return true , privileges_of (name )
182
192
end ,
183
193
})
184
194
@@ -227,7 +237,10 @@ local function handle_grant_command(caller, grantname, grantprivstr)
227
237
core .string_to_privs (core .settings :get (" basic_privs" ) or " interact,shout" )
228
238
for priv , _ in pairs (grantprivs ) do
229
239
if not basic_privs [priv ] and not caller_privs .privs then
230
- return false , S (" Your privileges are insufficient." )
240
+ return false , S (" Your privileges are insufficient. " ..
241
+ " '@1' only allows you to grant: @2" ,
242
+ " basic_privs" ,
243
+ core .privs_to_string (basic_privs , ' , ' ))
231
244
end
232
245
if not core .registered_privileges [priv ] then
233
246
privs_unknown = privs_unknown .. S (" Unknown privilege: @1" , priv ) .. " \n "
@@ -246,15 +259,13 @@ local function handle_grant_command(caller, grantname, grantprivstr)
246
259
if grantname ~= caller then
247
260
core .chat_send_player (grantname ,
248
261
S (" @1 granted you privileges: @2" , caller ,
249
- core .privs_to_string (grantprivs , ' ' )))
262
+ core .privs_to_string (grantprivs , ' , ' )))
250
263
end
251
- return true , S (" Privileges of @1: @2" , grantname ,
252
- core .privs_to_string (
253
- core .get_player_privs (grantname ), ' ' ))
264
+ return true , privileges_of (grantname )
254
265
end
255
266
256
267
core .register_chatcommand (" grant" , {
257
- params = S (" <name> (<privilege> | all)" ),
268
+ params = S (" <name> (<privilege> [, <privilege2> [<...>]] | all)" ),
258
269
description = S (" Give privileges to player" ),
259
270
func = function (name , param )
260
271
local grantname , grantprivstr = string.match (param , " ([^ ]+) (.+)" )
@@ -266,7 +277,7 @@ core.register_chatcommand("grant", {
266
277
})
267
278
268
279
core .register_chatcommand (" grantme" , {
269
- params = S (" <privilege> | all" ),
280
+ params = S (" <privilege> [, <privilege2> [<...>]] | all" ),
270
281
description = S (" Grant privileges to yourself" ),
271
282
func = function (name , param )
272
283
if param == " " then
@@ -286,16 +297,13 @@ local function handle_revoke_command(caller, revokename, revokeprivstr)
286
297
return false , S (" Player @1 does not exist." , revokename )
287
298
end
288
299
289
- local revokeprivs = core .string_to_privs (revokeprivstr )
290
300
local privs = core .get_player_privs (revokename )
291
- local basic_privs =
292
- core .string_to_privs (core .settings :get (" basic_privs" ) or " interact,shout" )
293
- for priv , _ in pairs (revokeprivs ) do
294
- if not basic_privs [priv ] and not caller_privs .privs then
295
- return false , S (" Your privileges are insufficient." )
296
- end
297
- end
298
301
302
+ local revokeprivs = core .string_to_privs (revokeprivstr )
303
+ local is_singleplayer = core .is_singleplayer ()
304
+ local is_admin = not is_singleplayer
305
+ and revokename == core .settings :get (" name" )
306
+ and revokename ~= " "
299
307
if revokeprivstr == " all" then
300
308
revokeprivs = privs
301
309
privs = {}
@@ -305,27 +313,73 @@ local function handle_revoke_command(caller, revokename, revokeprivstr)
305
313
end
306
314
end
307
315
316
+ local privs_unknown = " "
317
+ local basic_privs =
318
+ core .string_to_privs (core .settings :get (" basic_privs" ) or " interact,shout" )
319
+ local irrevokable = {}
320
+ local has_irrevokable_priv = false
321
+ for priv , _ in pairs (revokeprivs ) do
322
+ if not basic_privs [priv ] and not caller_privs .privs then
323
+ return false , S (" Your privileges are insufficient. " ..
324
+ " '@1' only allows you to revoke: @2" ,
325
+ " basic_privs" ,
326
+ core .privs_to_string (basic_privs , ' , ' ))
327
+ end
328
+ local def = core .registered_privileges [priv ]
329
+ if not def then
330
+ privs_unknown = privs_unknown .. S (" Unknown privilege: @1" , priv ) .. " \n "
331
+ elseif is_singleplayer and def .give_to_singleplayer then
332
+ irrevokable [priv ] = true
333
+ elseif is_admin and def .give_to_admin then
334
+ irrevokable [priv ] = true
335
+ end
336
+ end
337
+ for priv , _ in pairs (irrevokable ) do
338
+ revokeprivs [priv ] = nil
339
+ has_irrevokable_priv = true
340
+ end
341
+ if privs_unknown ~= " " then
342
+ return false , privs_unknown
343
+ end
344
+ if has_irrevokable_priv then
345
+ if is_singleplayer then
346
+ core .chat_send_player (caller ,
347
+ S (" Note: Cannot revoke in singleplayer: @1" ,
348
+ core .privs_to_string (irrevokable , ' , ' )))
349
+ elseif is_admin then
350
+ core .chat_send_player (caller ,
351
+ S (" Note: Cannot revoke from admin: @1" ,
352
+ core .privs_to_string (irrevokable , ' , ' )))
353
+ end
354
+ end
355
+
356
+ local revokecount = 0
308
357
for priv , _ in pairs (revokeprivs ) do
309
358
-- call the on_revoke callbacks
310
359
core .run_priv_callbacks (revokename , priv , caller , " revoke" )
360
+ revokecount = revokecount + 1
311
361
end
312
362
313
363
core .set_player_privs (revokename , privs )
364
+ local new_privs = core .get_player_privs (revokename )
365
+
366
+ if revokecount == 0 then
367
+ return false , S (" No privileges were revoked." )
368
+ end
369
+
314
370
core .log (" action" , caller .. ' revoked ('
315
371
.. core .privs_to_string (revokeprivs , ' , ' )
316
372
.. ' ) privileges from ' .. revokename )
317
373
if revokename ~= caller then
318
374
core .chat_send_player (revokename ,
319
375
S (" @1 revoked privileges from you: @2" , caller ,
320
- core .privs_to_string (revokeprivs , ' ' )))
376
+ core .privs_to_string (revokeprivs , ' , ' )))
321
377
end
322
- return true , S (" Privileges of @1: @2" , revokename ,
323
- core .privs_to_string (
324
- core .get_player_privs (revokename ), ' ' ))
378
+ return true , privileges_of (revokename , new_privs )
325
379
end
326
380
327
381
core .register_chatcommand (" revoke" , {
328
- params = S (" <name> (<privilege> | all)" ),
382
+ params = S (" <name> (<privilege> [, <privilege2> [<...>]] | all)" ),
329
383
description = S (" Remove privileges from player" ),
330
384
privs = {},
331
385
func = function (name , param )
@@ -338,7 +392,7 @@ core.register_chatcommand("revoke", {
338
392
})
339
393
340
394
core .register_chatcommand (" revokeme" , {
341
- params = S (" <privilege> | all" ),
395
+ params = S (" <privilege> [, <privilege2> [<...>]] | all" ),
342
396
description = S (" Revoke privileges from yourself" ),
343
397
privs = {},
344
398
func = function (name , param )
0 commit comments