Skip to content

Commit e70e151

Browse files
red-001paramat
authored andcommittedMar 26, 2017
Change command prefix to "." and add "help" command.
1 parent 4d5177f commit e70e151

File tree

9 files changed

+103
-63
lines changed

9 files changed

+103
-63
lines changed
 

Diff for: ‎builtin/client/chatcommands.lua

+15-7
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,35 @@
22

33

44
core.register_on_sending_chat_messages(function(message)
5-
if not (message:sub(1,1) == "/") then
6-
return false
5+
local first_char = message:sub(1,1)
6+
if first_char == "/" or first_char == "." then
7+
core.display_chat_message("issued command: " .. message)
78
end
89

9-
core.display_chat_message("issued command: " .. message)
10+
if first_char ~= "." then
11+
return false
12+
end
1013

11-
local cmd, param = string.match(message, "^/([^ ]+) *(.*)")
14+
local cmd, param = string.match(message, "^%.([^ ]+) *(.*)")
1215
if not param then
1316
param = ""
1417
end
1518

16-
local cmd_def = core.registered_chatcommands[cmd]
19+
if not cmd then
20+
core.display_chat_message("-!- Empty command")
21+
return true
22+
end
1723

24+
local cmd_def = core.registered_chatcommands[cmd]
1825
if cmd_def then
1926
core.set_last_run_mod(cmd_def.mod_origin)
2027
local _, message = cmd_def.func(param)
2128
if message then
2229
core.display_chat_message(message)
2330
end
24-
return true
31+
else
32+
core.display_chat_message("-!- Invalid command: " .. cmd)
2533
end
2634

27-
return false
35+
return true
2836
end)

Diff for: ‎builtin/common/chatcommands.lua

+72-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,75 @@ function core.override_chatcommand(name, redefinition)
2727
rawset(chatcommand, k, v)
2828
end
2929
core.registered_chatcommands[name] = chatcommand
30-
end
30+
end
31+
32+
local cmd_marker = "/"
33+
34+
if INIT == "client" then
35+
cmd_marker = "."
36+
end
37+
38+
local function do_help_cmd(name, param)
39+
local function format_help_line(cmd, def)
40+
local msg = core.colorize("#00ffff", cmd_marker .. cmd)
41+
if def.params and def.params ~= "" then
42+
msg = msg .. " " .. def.params
43+
end
44+
if def.description and def.description ~= "" then
45+
msg = msg .. ": " .. def.description
46+
end
47+
return msg
48+
end
49+
if param == "" then
50+
local cmds = {}
51+
for cmd, def in pairs(core.registered_chatcommands) do
52+
if INIT == "client" or core.check_player_privs(name, def.privs) then
53+
cmds[#cmds + 1] = cmd
54+
end
55+
end
56+
table.sort(cmds)
57+
return true, "Available commands: " .. table.concat(cmds, " ") .. "\n"
58+
.. "Use '"..cmd_marker.."help <cmd>' to get more information,"
59+
.. " or '"..cmd_marker.."help all' to list everything."
60+
elseif param == "all" then
61+
local cmds = {}
62+
for cmd, def in pairs(core.registered_chatcommands) do
63+
if INIT == "client" or core.check_player_privs(name, def.privs) then
64+
cmds[#cmds + 1] = format_help_line(cmd, def)
65+
end
66+
end
67+
table.sort(cmds)
68+
return true, "Available commands:\n"..table.concat(cmds, "\n")
69+
elseif INIT == "game" and param == "privs" then
70+
local privs = {}
71+
for priv, def in pairs(core.registered_privileges) do
72+
privs[#privs + 1] = priv .. ": " .. def.description
73+
end
74+
table.sort(privs)
75+
return true, "Available privileges:\n"..table.concat(privs, "\n")
76+
else
77+
local cmd = param
78+
local def = core.registered_chatcommands[cmd]
79+
if not def then
80+
return false, "Command not available: "..cmd
81+
else
82+
return true, format_help_line(cmd, def)
83+
end
84+
end
85+
end
86+
87+
if INIT == "client" then
88+
core.register_chatcommand("help", {
89+
params = "[all/<cmd>]",
90+
description = "Get help for commands",
91+
func = function(param)
92+
return do_help_cmd(nil, param)
93+
end,
94+
})
95+
else
96+
core.register_chatcommand("help", {
97+
params = "[all/privs/<cmd>]",
98+
description = "Get help for commands or list privileges",
99+
func = do_help_cmd,
100+
})
101+
end

Diff for: ‎builtin/game/chatcommands.lua

-55
Original file line numberDiff line numberDiff line change
@@ -82,61 +82,6 @@ core.register_chatcommand("admin", {
8282
end,
8383
})
8484

85-
core.register_chatcommand("help", {
86-
privs = {},
87-
params = "[all/privs/<cmd>]",
88-
description = "Get help for commands or list privileges",
89-
func = function(name, param)
90-
local function format_help_line(cmd, def)
91-
local msg = core.colorize("#00ffff", "/"..cmd)
92-
if def.params and def.params ~= "" then
93-
msg = msg .. " " .. def.params
94-
end
95-
if def.description and def.description ~= "" then
96-
msg = msg .. ": " .. def.description
97-
end
98-
return msg
99-
end
100-
if param == "" then
101-
local msg = ""
102-
local cmds = {}
103-
for cmd, def in pairs(core.registered_chatcommands) do
104-
if core.check_player_privs(name, def.privs) then
105-
cmds[#cmds + 1] = cmd
106-
end
107-
end
108-
table.sort(cmds)
109-
return true, "Available commands: " .. table.concat(cmds, " ") .. "\n"
110-
.. "Use '/help <cmd>' to get more information,"
111-
.. " or '/help all' to list everything."
112-
elseif param == "all" then
113-
local cmds = {}
114-
for cmd, def in pairs(core.registered_chatcommands) do
115-
if core.check_player_privs(name, def.privs) then
116-
cmds[#cmds + 1] = format_help_line(cmd, def)
117-
end
118-
end
119-
table.sort(cmds)
120-
return true, "Available commands:\n"..table.concat(cmds, "\n")
121-
elseif param == "privs" then
122-
local privs = {}
123-
for priv, def in pairs(core.registered_privileges) do
124-
privs[#privs + 1] = priv .. ": " .. def.description
125-
end
126-
table.sort(privs)
127-
return true, "Available privileges:\n"..table.concat(privs, "\n")
128-
else
129-
local cmd = param
130-
local def = core.registered_chatcommands[cmd]
131-
if not def then
132-
return false, "Command not available: "..cmd
133-
else
134-
return true, format_help_line(cmd, def)
135-
end
136-
end
137-
end,
138-
})
139-
14085
core.register_chatcommand("privs", {
14186
params = "<name>",
14287
description = "Print privileges of player",

Diff for: ‎builtin/settingtypes.txt

+4
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ keymap_chat (Chat key) key KEY_KEY_T
156156
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
157157
keymap_cmd (Command key) key /
158158

159+
# Key for opening the chat window to type local commands.
160+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
161+
keymap_cmd_local (Command key) key .
162+
159163
# Key for opening the chat console.
160164
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
161165
keyman_console (Console key) key KEY_F10

Diff for: ‎minetest.conf.example

+5
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@
148148
# type: key
149149
# keymap_cmd = /
150150

151+
# Key for opening the chat window to type local commands.
152+
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
153+
# type: key
154+
# keymap_cmd_local = .
155+
151156
# Key for opening the chat console.
152157
# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3
153158
# type: key

Diff for: ‎src/client/keys.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class KeyType {
4242
INVENTORY,
4343
CHAT,
4444
CMD,
45+
CMD_LOCAL,
4546
CONSOLE,
4647
MINIMAP,
4748
FREEMOVE,

Diff for: ‎src/defaultsettings.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ void set_default_settings(Settings *settings)
7272
settings->setDefault("keymap_special1", "KEY_KEY_E");
7373
settings->setDefault("keymap_chat", "KEY_KEY_T");
7474
settings->setDefault("keymap_cmd", "/");
75+
settings->setDefault("keymap_cmd_local", ".");
7576
settings->setDefault("keymap_minimap", "KEY_F9");
7677
settings->setDefault("keymap_console", "KEY_F10");
7778
settings->setDefault("keymap_rangeselect", "KEY_KEY_R");

Diff for: ‎src/game.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,7 @@ void KeyCache::populate()
10341034
key[KeyType::INVENTORY] = getKeySetting("keymap_inventory");
10351035
key[KeyType::CHAT] = getKeySetting("keymap_chat");
10361036
key[KeyType::CMD] = getKeySetting("keymap_cmd");
1037+
key[KeyType::CMD_LOCAL] = getKeySetting("keymap_cmd_local");
10371038
key[KeyType::CONSOLE] = getKeySetting("keymap_console");
10381039
key[KeyType::MINIMAP] = getKeySetting("keymap_minimap");
10391040
key[KeyType::FREEMOVE] = getKeySetting("keymap_freemove");
@@ -2449,6 +2450,8 @@ void Game::processKeyInput()
24492450
openConsole(0.2, L"");
24502451
} else if (wasKeyDown(KeyType::CMD)) {
24512452
openConsole(0.2, L"/");
2453+
} else if (wasKeyDown(KeyType::CMD_LOCAL)) {
2454+
openConsole(0.2, L".");
24522455
} else if (wasKeyDown(KeyType::CONSOLE)) {
24532456
openConsole(core::clamp(g_settings->getFloat("console_height"), 0.1f, 1.0f));
24542457
} else if (wasKeyDown(KeyType::FREEMOVE)) {

Diff for: ‎src/guiKeyChangeMenu.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ enum
5353
GUI_ID_KEY_CINEMATIC_BUTTON,
5454
GUI_ID_KEY_CHAT_BUTTON,
5555
GUI_ID_KEY_CMD_BUTTON,
56+
GUI_ID_KEY_CMD_LOCAL_BUTTON,
5657
GUI_ID_KEY_CONSOLE_BUTTON,
5758
GUI_ID_KEY_SNEAK_BUTTON,
5859
GUI_ID_KEY_DROP_BUTTON,
@@ -408,6 +409,7 @@ void GUIKeyChangeMenu::init_keys()
408409
this->add_key(GUI_ID_KEY_INVENTORY_BUTTON, wgettext("Inventory"), "keymap_inventory");
409410
this->add_key(GUI_ID_KEY_CHAT_BUTTON, wgettext("Chat"), "keymap_chat");
410411
this->add_key(GUI_ID_KEY_CMD_BUTTON, wgettext("Command"), "keymap_cmd");
412+
this->add_key(GUI_ID_KEY_CMD_LOCAL_BUTTON, wgettext("Local command"), "keymap_cmd_local");
411413
this->add_key(GUI_ID_KEY_CONSOLE_BUTTON, wgettext("Console"), "keymap_console");
412414
this->add_key(GUI_ID_KEY_FLY_BUTTON, wgettext("Toggle fly"), "keymap_freemove");
413415
this->add_key(GUI_ID_KEY_FAST_BUTTON, wgettext("Toggle fast"), "keymap_fastmove");

0 commit comments

Comments
 (0)
Please sign in to comment.