2
0

privileges.lua 3.0 KB

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