init.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. -- Customize the /help chat-command.
  2. help = help or {}
  3. help.modpath = minetest.get_modpath("help")
  4. dofile(help.modpath .. "/formspecs.lua")
  5. local function show_all(pname, param)
  6. -- Is worldedit installed?
  7. local we = minetest.get_modpath("worldedit")
  8. local commands = {}
  9. for name, data in pairs(minetest.registered_chatcommands) do
  10. local privs = data.privs or {}
  11. if minetest.check_player_privs(pname, privs) then
  12. -- If worldedit is installed, skip commands beginning with '/', because
  13. -- worldedit leaks them due to missing privs.
  14. if not we or name:sub(1, 1) ~= "/" then
  15. commands[#commands + 1] = name
  16. end
  17. end
  18. end
  19. minetest.chat_send_player(pname,
  20. "# Server: The commands available to you are: " ..
  21. table.concat(commands, ", ") .. ".")
  22. end
  23. local function show_single(pname, param)
  24. local def = minetest.registered_chatcommands[param]
  25. if not def then return end
  26. local privs = def.privs or {}
  27. if minetest.check_player_privs(pname, privs) then
  28. local cmd = "/" .. param
  29. local args = def.params and def.params ~= "" and (" " .. def.params .. ": ") or ": "
  30. local desc = def.description or "No description provided."
  31. minetest.chat_send_player(pname, "# Server: " .. cmd .. args .. desc)
  32. return
  33. end
  34. minetest.chat_send_player(pname,
  35. "# Server: That command is not available to you.")
  36. end
  37. function help.do_help(pname, param)
  38. local user = minetest.get_player_by_name(pname)
  39. if not user or not user:is_player() then return end
  40. if not param or param == "" then
  41. show_all(pname, param)
  42. return
  43. end
  44. if minetest.registered_chatcommands[param] then
  45. show_single(pname, param)
  46. return
  47. end
  48. minetest.chat_send_player(pname, "# Server: Named command does not exist.")
  49. end
  50. if not help.registered then
  51. help.registered = true
  52. -- The builtin /help tries to split commands and privs into mods. Enyekala
  53. -- doesn't support modding due to the massive differences, so the help
  54. -- formspecs need to be altered.
  55. minetest.override_chatcommand("help", {
  56. params = "",
  57. description = "Get help on privs and commands.",
  58. func = function(...)
  59. help.do_help(...)
  60. return true
  61. end,
  62. })
  63. -- This game doesn't really have any mod support due to the massive changes.
  64. -- There's no point in displaying the "mods" because they're not used as such.
  65. minetest.override_chatcommand("mods", {
  66. params = "",
  67. description = "Mods are unsupported.",
  68. func = function(name, param)
  69. local s = "# Server: Enyekala does not support mods at this time."
  70. minetest.chat_send_player(name, s)
  71. return true
  72. end,
  73. })
  74. local function add_required_priv(name, priv)
  75. local def = minetest.registered_chatcommands[name]
  76. if not def then return end
  77. def = table.copy(def)
  78. def.privs = def.privs or {}
  79. def.privs[priv] = true
  80. minetest.override_chatcommand(name, def)
  81. end
  82. -- Note: can only override *builtin* chat-commands without needing dependency.
  83. add_required_priv("revoke", "server")
  84. add_required_priv("revokeme", "server")
  85. add_required_priv("grant", "server")
  86. add_required_priv("grantme", "server")
  87. local c = "help:core"
  88. local f = help.modpath .. "/init.lua"
  89. reload.register_file(c, f, false)
  90. end