2017-01-22 08:05:09 +00:00
|
|
|
-- Minetest: builtin/client/chatcommands.lua
|
|
|
|
|
2017-06-09 15:48:04 +02:00
|
|
|
core.register_on_sending_chat_message(function(message)
|
2017-04-11 22:35:25 +01:00
|
|
|
if message:sub(1,2) == ".." then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2017-03-24 23:43:36 +00:00
|
|
|
local first_char = message:sub(1,1)
|
|
|
|
if first_char == "/" or first_char == "." then
|
2017-04-10 20:14:00 +01:00
|
|
|
core.display_chat_message(core.gettext("issued command: ") .. message)
|
2017-01-22 08:05:09 +00:00
|
|
|
end
|
2017-01-27 07:41:10 +01:00
|
|
|
|
2017-03-24 23:43:36 +00:00
|
|
|
if first_char ~= "." then
|
|
|
|
return false
|
|
|
|
end
|
2017-01-27 07:41:10 +01:00
|
|
|
|
2017-03-24 23:43:36 +00:00
|
|
|
local cmd, param = string.match(message, "^%.([^ ]+) *(.*)")
|
2019-08-06 19:30:18 +01:00
|
|
|
param = param or ""
|
2017-01-27 07:41:10 +01:00
|
|
|
|
2017-03-24 23:43:36 +00:00
|
|
|
if not cmd then
|
2017-04-10 20:14:00 +01:00
|
|
|
core.display_chat_message(core.gettext("-!- Empty command"))
|
2017-03-24 23:43:36 +00:00
|
|
|
return true
|
|
|
|
end
|
2017-01-27 07:41:10 +01:00
|
|
|
|
2017-03-24 23:43:36 +00:00
|
|
|
local cmd_def = core.registered_chatcommands[cmd]
|
2017-01-22 08:05:09 +00:00
|
|
|
if cmd_def then
|
|
|
|
core.set_last_run_mod(cmd_def.mod_origin)
|
2019-08-06 19:30:18 +01:00
|
|
|
local _, result = cmd_def.func(param)
|
|
|
|
if result then
|
|
|
|
core.display_chat_message(result)
|
2017-01-22 08:05:09 +00:00
|
|
|
end
|
2017-03-24 23:43:36 +00:00
|
|
|
else
|
2017-04-10 20:14:00 +01:00
|
|
|
core.display_chat_message(core.gettext("-!- Invalid command: ") .. cmd)
|
2017-01-22 08:05:09 +00:00
|
|
|
end
|
2017-01-27 07:41:10 +01:00
|
|
|
|
2017-03-24 23:43:36 +00:00
|
|
|
return true
|
2017-01-27 07:41:10 +01:00
|
|
|
end)
|
2017-04-10 20:13:20 +01:00
|
|
|
|
2017-07-15 09:28:10 +02:00
|
|
|
function core.run_server_chatcommand(cmd, param)
|
|
|
|
core.send_chat_message("/" .. cmd .. " " .. param)
|
|
|
|
end
|
2020-07-18 13:20:08 +02:00
|
|
|
|
|
|
|
|