2017-06-09 15:48:04 +02:00
|
|
|
core.register_on_sending_chat_message(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
|
2021-03-05 16:27:33 +01: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, "^%.([^ ]+) *(.*)")
|
2019-08-06 20:30:18 +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
|
2021-03-05 16:27:33 +01: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
|
|
|
|
2020-10-03 18:38:08 +02:00
|
|
|
-- Run core.registered_on_chatcommand callbacks.
|
|
|
|
if core.run_callbacks(core.registered_on_chatcommand, 5, cmd, param) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
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)
|
2019-08-06 20:30:18 +02:00
|
|
|
local _, result = cmd_def.func(param)
|
|
|
|
if result then
|
|
|
|
core.display_chat_message(result)
|
2017-01-22 09:05:09 +01:00
|
|
|
end
|
2017-03-25 00:43:36 +01:00
|
|
|
else
|
2021-03-05 16:27:33 +01: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)
|
2018-12-24 10:51:10 +01:00
|
|
|
local player_names = core.get_player_names()
|
|
|
|
if not player_names then
|
|
|
|
return false, core.gettext("This command is disabled by server.")
|
|
|
|
end
|
|
|
|
|
|
|
|
local players = table.concat(player_names, ", ")
|
|
|
|
return true, 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-07-15 09:28:10 +02:00
|
|
|
|
|
|
|
core.register_chatcommand("clear_chat_queue", {
|
|
|
|
description = core.gettext("Clear the out chat queue"),
|
|
|
|
func = function(param)
|
|
|
|
core.clear_out_chat_queue()
|
2021-03-05 16:27:33 +01:00
|
|
|
return true, core.gettext("The out chat queue is now empty.")
|
2017-07-15 09:28:10 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
function core.run_server_chatcommand(cmd, param)
|
|
|
|
core.send_chat_message("/" .. cmd .. " " .. param)
|
|
|
|
end
|