init.lua 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. privs = privs or {}
  2. privs.modpath = minetest.get_modpath("privs")
  3. privs.print_privs = function(user, param)
  4. assert(type(user) == "string")
  5. assert(type(param) == "string")
  6. local name = param:trim()
  7. if name == "" then
  8. name = user
  9. end
  10. if not minetest.player_exists(name) then
  11. minetest.chat_send_player(user, "# Server: Player <" .. rename.gpn(name) .. "> does not exist.")
  12. return true
  13. end
  14. local privs = minetest.get_player_privs(name)
  15. if privs then
  16. -- There are only two tiers. A player is either a `player`, or the server operator (ME).
  17. -- There are no other privilege tiers, and no details given, to avoid jealously problems.
  18. local string = "player"
  19. if privs.server then
  20. string = "server"
  21. end
  22. if user == name or minetest.check_player_privs(user, {privs=true}) then
  23. -- If player is querying privs of self, or player is admin, then print full privs list.
  24. minetest.chat_send_player(user, "# Server: Privileges of <" .. rename.gpn(name) .. ">: " .. core.privs_to_string(privs, ", ") .. ".")
  25. else
  26. -- Otherwise just print the generic privs rank.
  27. minetest.chat_send_player(user, "# Server: Privilege rank of <" .. rename.gpn(name) .. ">: " .. string .. ".")
  28. end
  29. return true
  30. end
  31. minetest.chat_send_player(user, "# Server: Could not obtain privileges of player <" .. rename.gpn(name) .. ">!")
  32. easyvend.sound_error(user)
  33. return true
  34. end
  35. if not privs.run_once then
  36. minetest.register_chatcommand("privs", {
  37. params = "[playername]",
  38. description = "Print privileges of a player, or your own privileges.",
  39. privs = {},
  40. func = function(...) return privs.print_privs(...) end,
  41. })
  42. local c = "privs:core"
  43. local f = privs.modpath .. "/init.lua"
  44. reload.register_file(c, f, false)
  45. privs.run_once = true
  46. end