privileges.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. -- Minetest: builtin/privileges.lua
  2. --
  3. -- Privileges
  4. --
  5. core.registered_privileges = {}
  6. function core.register_privilege(name, param)
  7. local function fill_defaults(def)
  8. if def.give_to_singleplayer == nil then
  9. def.give_to_singleplayer = true
  10. end
  11. if def.give_to_admin == nil then
  12. def.give_to_admin = def.give_to_singleplayer
  13. end
  14. if def.description == nil then
  15. def.description = "(no description)"
  16. end
  17. end
  18. local def = {}
  19. if type(param) == "table" then
  20. def = param
  21. else
  22. def = {description = param}
  23. end
  24. fill_defaults(def)
  25. core.registered_privileges[name] = def
  26. end
  27. core.register_privilege("interact", "Can interact with things and modify the world")
  28. core.register_privilege("shout", "Can speak in chat")
  29. core.register_privilege("basic_privs", "Can modify 'shout' and 'interact' privileges")
  30. core.register_privilege("privs", "Can modify privileges")
  31. core.register_privilege("teleport", {
  32. description = "Can teleport self",
  33. give_to_singleplayer = false,
  34. })
  35. core.register_privilege("bring", {
  36. description = "Can teleport other players",
  37. give_to_singleplayer = false,
  38. })
  39. core.register_privilege("settime", {
  40. description = "Can set the time of day using /time",
  41. give_to_singleplayer = false,
  42. })
  43. core.register_privilege("server", {
  44. description = "Can do server maintenance stuff",
  45. give_to_singleplayer = false,
  46. give_to_admin = true,
  47. })
  48. core.register_privilege("protection_bypass", {
  49. description = "Can bypass node protection in the world",
  50. give_to_singleplayer = false,
  51. })
  52. core.register_privilege("ban", {
  53. description = "Can ban and unban players",
  54. give_to_singleplayer = false,
  55. give_to_admin = true,
  56. })
  57. core.register_privilege("kick", {
  58. description = "Can kick players",
  59. give_to_singleplayer = false,
  60. give_to_admin = true,
  61. })
  62. core.register_privilege("give", {
  63. description = "Can use /give and /giveme",
  64. give_to_singleplayer = false,
  65. })
  66. core.register_privilege("password", {
  67. description = "Can use /setpassword and /clearpassword",
  68. give_to_singleplayer = false,
  69. give_to_admin = true,
  70. })
  71. core.register_privilege("fly", {
  72. description = "Can use fly mode",
  73. give_to_singleplayer = false,
  74. })
  75. core.register_privilege("fast", {
  76. description = "Can use fast mode",
  77. give_to_singleplayer = false,
  78. })
  79. core.register_privilege("noclip", {
  80. description = "Can fly through solid nodes using noclip mode",
  81. give_to_singleplayer = false,
  82. })
  83. core.register_privilege("rollback", {
  84. description = "Can use the rollback functionality",
  85. give_to_singleplayer = false,
  86. })
  87. core.register_privilege("debug", {
  88. description = "Allows enabling various debug options that may affect gameplay",
  89. give_to_singleplayer = false,
  90. give_to_admin = true,
  91. })
  92. core.register_can_bypass_userlimit(function(name, ip)
  93. local privs = core.get_player_privs(name)
  94. return privs["server"] or privs["ban"] or privs["privs"] or privs["password"]
  95. end)