Change command prefix to "." and add "help" command.
authorred-001 <red-001@outlook.ie>
Fri, 24 Mar 2017 23:43:36 +0000 (23:43 +0000)
committerparamat <mat.gregory@virginmedia.com>
Sun, 26 Mar 2017 04:51:14 +0000 (05:51 +0100)
builtin/client/chatcommands.lua
builtin/common/chatcommands.lua
builtin/game/chatcommands.lua
builtin/settingtypes.txt
minetest.conf.example
src/client/keys.h
src/defaultsettings.cpp
src/game.cpp
src/guiKeyChangeMenu.cpp

index 43b4d9a72c1cce548c960354fc67a54b18b11559..7a1b4b6b71851ff2d38a5b288fd0f4e4dccc1472 100644 (file)
@@ -2,27 +2,35 @@
 
 
 core.register_on_sending_chat_messages(function(message)
-       if not (message:sub(1,1) == "/") then
-               return false
+       local first_char = message:sub(1,1)
+       if first_char == "/" or first_char == "." then
+               core.display_chat_message("issued command: " .. message)
        end
 
-       core.display_chat_message("issued command: " .. message)
+       if first_char ~= "." then
+               return false
+       end
 
-       local cmd, param = string.match(message, "^/([^ ]+) *(.*)")
+       local cmd, param = string.match(message, "^%.([^ ]+) *(.*)")
        if not param then
                param = ""
        end
 
-       local cmd_def = core.registered_chatcommands[cmd]
+       if not cmd then
+               core.display_chat_message("-!- Empty command")
+               return true
+       end
 
+       local cmd_def = core.registered_chatcommands[cmd]
        if cmd_def then
                core.set_last_run_mod(cmd_def.mod_origin)
                local _, message = cmd_def.func(param)
                if message then
                        core.display_chat_message(message)
                end
-               return true
+       else
+               core.display_chat_message("-!- Invalid command: " .. cmd)
        end
 
-       return false
+       return true
 end)
index ef3a2441030d3538c18aed616c6a1aab9b9eb167..05dd94e8d3bb9a552ae468f4d99789b1a3d2a8c9 100644 (file)
@@ -27,4 +27,75 @@ function core.override_chatcommand(name, redefinition)
                rawset(chatcommand, k, v)
        end
        core.registered_chatcommands[name] = chatcommand
-end
\ No newline at end of file
+end
+
+local cmd_marker = "/"
+
+if INIT == "client" then
+       cmd_marker = "."
+end
+
+local function do_help_cmd(name, param)
+       local function format_help_line(cmd, def)
+               local msg = core.colorize("#00ffff", cmd_marker .. 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 cmds = {}
+               for cmd, def in pairs(core.registered_chatcommands) do
+                       if INIT == "client" or 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 '"..cmd_marker.."help <cmd>' to get more information,"
+                               .. " or '"..cmd_marker.."help all' to list everything."
+       elseif param == "all" then
+               local cmds = {}
+               for cmd, def in pairs(core.registered_chatcommands) do
+                       if INIT == "client" or 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 INIT == "game" and 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
+
+if INIT == "client" then
+       core.register_chatcommand("help", {
+               params = "[all/<cmd>]",
+               description = "Get help for commands",
+               func = function(param)
+                       return do_help_cmd(nil, param)
+               end,
+       })
+else
+       core.register_chatcommand("help", {
+               params = "[all/privs/<cmd>]",
+               description = "Get help for commands or list privileges",
+               func = do_help_cmd,
+       })
+end
index 745b012e6f03be15bcd7af59bef960c3387afcf5..b4fa4f8288d51049e911a08e12d1c6328a3c5270 100644 (file)
@@ -82,61 +82,6 @@ core.register_chatcommand("admin", {
        end,
 })
 
-core.register_chatcommand("help", {
-       privs = {},
-       params = "[all/privs/<cmd>]",
-       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 <cmd>' 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 = "<name>",
        description = "Print privileges of player",
index d2bdf030add584118e521e155885d424a6a1b39b..e63697f61e92b13831eb5bd571fdf68ba47ad381 100644 (file)
@@ -156,6 +156,10 @@ keymap_chat (Chat key) key KEY_KEY_T
 #    See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
 keymap_cmd (Command key) key /
 
+#    Key for opening the chat window to type local commands.
+#    See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
+keymap_cmd_local (Command key) key .
+
 #    Key for opening the chat console.
 #    See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
 keyman_console (Console key) key KEY_F10
index fd76d98e0bd1ea9eacf443c5b7a1fe4513b8ed9e..78488432fb67a8418b898d92e6a2880c498369f0 100644 (file)
 #    type: key
 # keymap_cmd = /
 
+#    Key for opening the chat window to type local commands.
+#    See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
+#    type: key
+# keymap_cmd_local = .
+
 #    Key for opening the chat console.
 #    See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
 #    type: key
index 6467c443e5c632baef2c947ba0ce88415947280d..25f3e44d2ddb66cbc168dc47def8d6bfe92316cb 100644 (file)
@@ -42,6 +42,7 @@ public:
                INVENTORY,
                CHAT,
                CMD,
+               CMD_LOCAL,
                CONSOLE,
                MINIMAP,
                FREEMOVE,
index 396b69b3a0671852041e072ebeae53af24150213..5b66c583ac9ed00af24684c9618f3498e48d41f9 100644 (file)
@@ -72,6 +72,7 @@ void set_default_settings(Settings *settings)
        settings->setDefault("keymap_special1", "KEY_KEY_E");
        settings->setDefault("keymap_chat", "KEY_KEY_T");
        settings->setDefault("keymap_cmd", "/");
+       settings->setDefault("keymap_cmd_local", ".");
        settings->setDefault("keymap_minimap", "KEY_F9");
        settings->setDefault("keymap_console", "KEY_F10");
        settings->setDefault("keymap_rangeselect", "KEY_KEY_R");
index 9d52e4326e85bca01e1ea773492fa69c0e683d01..62d2405f281b8269db21dd65e7d4a5ada375499f 100644 (file)
@@ -1034,6 +1034,7 @@ void KeyCache::populate()
        key[KeyType::INVENTORY]    = getKeySetting("keymap_inventory");
        key[KeyType::CHAT]         = getKeySetting("keymap_chat");
        key[KeyType::CMD]          = getKeySetting("keymap_cmd");
+       key[KeyType::CMD_LOCAL]    = getKeySetting("keymap_cmd_local");
        key[KeyType::CONSOLE]      = getKeySetting("keymap_console");
        key[KeyType::MINIMAP]      = getKeySetting("keymap_minimap");
        key[KeyType::FREEMOVE]     = getKeySetting("keymap_freemove");
@@ -2449,6 +2450,8 @@ void Game::processKeyInput()
                openConsole(0.2, L"");
        } else if (wasKeyDown(KeyType::CMD)) {
                openConsole(0.2, L"/");
+       } else if (wasKeyDown(KeyType::CMD_LOCAL)) {
+               openConsole(0.2, L".");
        } else if (wasKeyDown(KeyType::CONSOLE)) {
                openConsole(core::clamp(g_settings->getFloat("console_height"), 0.1f, 1.0f));
        } else if (wasKeyDown(KeyType::FREEMOVE)) {
index 07137d1bc9be06446cf133d567f4a4c4a65d1178..e85ee8271252a1ef6a615ebdc63656adbd7fe045 100644 (file)
@@ -53,6 +53,7 @@ enum
        GUI_ID_KEY_CINEMATIC_BUTTON,
        GUI_ID_KEY_CHAT_BUTTON,
        GUI_ID_KEY_CMD_BUTTON,
+       GUI_ID_KEY_CMD_LOCAL_BUTTON,
        GUI_ID_KEY_CONSOLE_BUTTON,
        GUI_ID_KEY_SNEAK_BUTTON,
        GUI_ID_KEY_DROP_BUTTON,
@@ -408,6 +409,7 @@ void GUIKeyChangeMenu::init_keys()
        this->add_key(GUI_ID_KEY_INVENTORY_BUTTON, wgettext("Inventory"),        "keymap_inventory");
        this->add_key(GUI_ID_KEY_CHAT_BUTTON,      wgettext("Chat"),             "keymap_chat");
        this->add_key(GUI_ID_KEY_CMD_BUTTON,       wgettext("Command"),          "keymap_cmd");
+       this->add_key(GUI_ID_KEY_CMD_LOCAL_BUTTON, wgettext("Local command"),    "keymap_cmd_local");
        this->add_key(GUI_ID_KEY_CONSOLE_BUTTON,   wgettext("Console"),          "keymap_console");
        this->add_key(GUI_ID_KEY_FLY_BUTTON,       wgettext("Toggle fly"),       "keymap_freemove");
        this->add_key(GUI_ID_KEY_FAST_BUTTON,      wgettext("Toggle fast"),      "keymap_fastmove");