2017-01-22 09:05:09 +01:00
|
|
|
-- Minetest: builtin/client/chatcommands.lua
|
|
|
|
|
|
|
|
|
|
|
|
core.register_on_sending_chat_messages(function(message)
|
2017-04-11 23:35:25 +02:00
|
|
|
if message:sub(1,2) == ".." then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2017-03-25 00:43:36 +01:00
|
|
|
local first_char = message:sub(1,1)
|
|
|
|
if first_char == "/" or first_char == "." then
|
2017-04-10 21:14:00 +02:00
|
|
|
core.display_chat_message(core.gettext("issued command: ") .. message)
|
2017-01-22 09:05:09 +01:00
|
|
|
end
|
2017-01-27 07:41:10 +01:00
|
|
|
|
2017-03-25 00:43:36 +01:00
|
|
|
if first_char ~= "." then
|
|
|
|
return false
|
|
|
|
end
|
2017-01-27 07:41:10 +01:00
|
|
|
|
2017-03-25 00:43:36 +01:00
|
|
|
local cmd, param = string.match(message, "^%.([^ ]+) *(.*)")
|
2017-04-11 23:35:25 +02:00
|
|
|
param = param or ""
|
2017-01-27 07:41:10 +01:00
|
|
|
|
2017-03-25 00:43:36 +01:00
|
|
|
if not cmd then
|
2017-04-10 21:14:00 +02:00
|
|
|
core.display_chat_message(core.gettext("-!- Empty command"))
|
2017-03-25 00:43:36 +01:00
|
|
|
return true
|
|
|
|
end
|
2017-01-27 07:41:10 +01:00
|
|
|
|
2017-03-25 00:43:36 +01:00
|
|
|
local cmd_def = core.registered_chatcommands[cmd]
|
2017-01-22 09:05:09 +01:00
|
|
|
if cmd_def then
|
|
|
|
core.set_last_run_mod(cmd_def.mod_origin)
|
2017-01-27 07:41:10 +01:00
|
|
|
local _, message = cmd_def.func(param)
|
2017-01-22 09:05:09 +01:00
|
|
|
if message then
|
|
|
|
core.display_chat_message(message)
|
|
|
|
end
|
2017-03-25 00:43:36 +01:00
|
|
|
else
|
2017-04-10 21:14:00 +02:00
|
|
|
core.display_chat_message(core.gettext("-!- Invalid command: ") .. cmd)
|
2017-01-22 09:05:09 +01:00
|
|
|
end
|
2017-01-27 07:41:10 +01:00
|
|
|
|
2017-03-25 00:43:36 +01:00
|
|
|
return true
|
2017-01-27 07:41:10 +01:00
|
|
|
end)
|
2017-04-10 21:13:20 +02:00
|
|
|
|
|
|
|
core.register_chatcommand("list_players", {
|
2017-04-11 23:35:25 +02:00
|
|
|
description = core.gettext("List online players"),
|
2017-04-10 21:13:20 +02:00
|
|
|
func = function(param)
|
|
|
|
local players = table.concat(core.get_player_names(), ", ")
|
2017-04-11 23:35:25 +02:00
|
|
|
core.display_chat_message(core.gettext("Online players: ") .. players)
|
2017-04-10 21:13:20 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
core.register_chatcommand("disconnect", {
|
2017-04-11 23:35:25 +02:00
|
|
|
description = core.gettext("Exit to main menu"),
|
2017-04-10 21:13:20 +02:00
|
|
|
func = function(param)
|
|
|
|
core.disconnect()
|
|
|
|
end,
|
|
|
|
})
|
2017-05-21 23:06:51 +02:00
|
|
|
|
|
|
|
core.register_chatcommand("clear_chat_queue", {
|
|
|
|
description = core.gettext("Clear the out chat queue"),
|
|
|
|
func = function(param)
|
|
|
|
core.clear_out_chat_queue()
|
|
|
|
return true, core.gettext("The out chat queue is now empty")
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
function core.run_server_chatcommand(cmd, param)
|
|
|
|
core.send_chat_message("/" .. cmd .. " " .. param)
|
|
|
|
end
|