2
0

privileges.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. local S = core.get_translator("__builtin")
  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 = S("(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", S("Can interact with things and modify the world"))
  28. core.register_privilege("shout", S("Can speak in chat"))
  29. local basic_privs =
  30. core.string_to_privs((core.settings:get("basic_privs") or "shout,interact"))
  31. local basic_privs_desc = S("Can modify basic privileges (@1)",
  32. core.privs_to_string(basic_privs, ', '))
  33. core.register_privilege("basic_privs", basic_privs_desc)
  34. core.register_privilege("privs", S("Can modify privileges"))
  35. core.register_privilege("teleport", {
  36. description = S("Can teleport self"),
  37. give_to_singleplayer = false,
  38. })
  39. core.register_privilege("bring", {
  40. description = S("Can teleport other players"),
  41. give_to_singleplayer = false,
  42. })
  43. core.register_privilege("settime", {
  44. description = S("Can set the time of day using /time"),
  45. give_to_singleplayer = false,
  46. })
  47. core.register_privilege("server", {
  48. description = S("Can do server maintenance stuff"),
  49. give_to_singleplayer = false,
  50. give_to_admin = true,
  51. })
  52. core.register_privilege("protection_bypass", {
  53. description = S("Can bypass node protection in the world"),
  54. give_to_singleplayer = false,
  55. })
  56. core.register_privilege("ban", {
  57. description = S("Can ban and unban players"),
  58. give_to_singleplayer = false,
  59. give_to_admin = true,
  60. })
  61. core.register_privilege("kick", {
  62. description = S("Can kick players"),
  63. give_to_singleplayer = false,
  64. give_to_admin = true,
  65. })
  66. core.register_privilege("give", {
  67. description = S("Can use /give and /giveme"),
  68. give_to_singleplayer = false,
  69. })
  70. core.register_privilege("password", {
  71. description = S("Can use /setpassword and /clearpassword"),
  72. give_to_singleplayer = false,
  73. give_to_admin = true,
  74. })
  75. core.register_privilege("fly", {
  76. description = S("Can use fly mode"),
  77. give_to_singleplayer = false,
  78. })
  79. core.register_privilege("fast", {
  80. description = S("Can use fast mode"),
  81. give_to_singleplayer = false,
  82. })
  83. core.register_privilege("noclip", {
  84. description = S("Can fly through solid nodes using noclip mode"),
  85. give_to_singleplayer = false,
  86. })
  87. core.register_privilege("rollback", {
  88. description = S("Can use the rollback functionality"),
  89. give_to_singleplayer = false,
  90. })
  91. core.register_privilege("debug", {
  92. description = S("Can enable wireframe"),
  93. give_to_singleplayer = false,
  94. })
  95. core.register_can_bypass_userlimit(function(name, ip)
  96. local privs = core.get_player_privs(name)
  97. return privs["server"] or privs["ban"] or privs["privs"] or privs["password"]
  98. end)