X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=builtin%2Fgame%2Fchatcommands.lua;h=b4fa4f8288d51049e911a08e12d1c6328a3c5270;hb=e70e15134c95d37241bb6f6124105c0f1c08ab8a;hp=08dc1bb1d11053189507a926871dbb8e8460e279;hpb=efa54f9c460239c23a2014076764d6c6830589e6;p=minetest.git diff --git a/builtin/game/chatcommands.lua b/builtin/game/chatcommands.lua index 08dc1bb1d..b4fa4f828 100644 --- a/builtin/game/chatcommands.lua +++ b/builtin/game/chatcommands.lua @@ -1,37 +1,10 @@ --- Minetest: builtin/chatcommands.lua +-- Minetest: builtin/game/chatcommands.lua -- -- Chat command handler -- -core.registered_chatcommands = {} core.chatcommands = core.registered_chatcommands -- BACKWARDS COMPATIBILITY -function core.register_chatcommand(cmd, def) - def = def or {} - def.params = def.params or "" - def.description = def.description or "" - def.privs = def.privs or {} - def.mod_origin = core.get_current_modname() or "??" - core.registered_chatcommands[cmd] = def -end - -function core.unregister_chatcommand(name) - if core.registered_chatcommands[name] then - core.registered_chatcommands[name] = nil - else - core.log("warning", "Not unregistering chatcommand " ..name.. - " because it doesn't exist.") - end -end - -function core.override_chatcommand(name, redefinition) - local chatcommand = core.registered_chatcommands[name] - assert(chatcommand, "Attempt to override non-existent chatcommand "..name) - for k, v in pairs(redefinition) do - rawset(chatcommand, k, v) - end - core.registered_chatcommands[name] = chatcommand -end core.register_on_chat_message(function(name, message) local cmd, param = string.match(message, "^/([^ ]+) *(.*)") @@ -109,61 +82,6 @@ core.register_chatcommand("admin", { end, }) -core.register_chatcommand("help", { - privs = {}, - params = "[all/privs/]", - description = "Get help for commands or list privileges", - func = function(name, param) - local function format_help_line(cmd, def) - local msg = core.colorize("#00ffff", "/"..cmd) - if def.params and def.params ~= "" then - msg = msg .. " " .. def.params - end - if def.description and def.description ~= "" then - msg = msg .. ": " .. def.description - end - return msg - end - if param == "" then - local msg = "" - local cmds = {} - for cmd, def in pairs(core.registered_chatcommands) do - if core.check_player_privs(name, def.privs) then - cmds[#cmds + 1] = cmd - end - end - table.sort(cmds) - return true, "Available commands: " .. table.concat(cmds, " ") .. "\n" - .. "Use '/help ' to get more information," - .. " or '/help all' to list everything." - elseif param == "all" then - local cmds = {} - for cmd, def in pairs(core.registered_chatcommands) do - if core.check_player_privs(name, def.privs) then - cmds[#cmds + 1] = format_help_line(cmd, def) - end - end - table.sort(cmds) - return true, "Available commands:\n"..table.concat(cmds, "\n") - elseif param == "privs" then - local privs = {} - for priv, def in pairs(core.registered_privileges) do - privs[#privs + 1] = priv .. ": " .. def.description - end - table.sort(privs) - return true, "Available privileges:\n"..table.concat(privs, "\n") - else - local cmd = param - local def = core.registered_chatcommands[cmd] - if not def then - return false, "Command not available: "..cmd - else - return true, format_help_line(cmd, def) - end - end - end, -}) - core.register_chatcommand("privs", { params = "", description = "Print privileges of player", @@ -836,11 +754,14 @@ core.register_chatcommand("days", { core.register_chatcommand("shutdown", { description = "Shutdown server", + params = "[reconnect] [message]", privs = {server=true}, func = function(name, param) core.log("action", name .. " shuts down server") - core.request_shutdown() core.chat_send_all("*** Server shutting down (operator request).") + local reconnect, message = param:match("([^ ]+)(.*)") + message = message or "" + core.request_shutdown(message:trim(), core.is_yes(reconnect)) end, })