1 -- Minetest: builtin/client/chatcommands.lua
3 core.register_on_sending_chat_message(function(message)
4 if message:sub(1,2) == ".." then
8 local first_char = message:sub(1,1)
9 if first_char == "/" or first_char == "." then
10 core.display_chat_message(core.gettext("Issued command: ") .. message)
13 if first_char ~= "." then
17 local cmd, param = string.match(message, "^%.([^ ]+) *(.*)")
21 core.display_chat_message("-!- " .. core.gettext("Empty command."))
25 -- Run core.registered_on_chatcommand callbacks.
26 if core.run_callbacks(core.registered_on_chatcommand, 5, cmd, param) then
30 local cmd_def = core.registered_chatcommands[cmd]
32 core.set_last_run_mod(cmd_def.mod_origin)
33 local _, result = cmd_def.func(param)
35 core.display_chat_message(result)
38 core.display_chat_message("-!- " .. core.gettext("Invalid command: ") .. cmd)
44 core.register_chatcommand("list_players", {
45 description = core.gettext("List online players"),
46 func = function(param)
47 local player_names = core.get_player_names()
48 if not player_names then
49 return false, core.gettext("This command is disabled by server.")
52 local players = table.concat(player_names, ", ")
53 return true, core.gettext("Online players: ") .. players
57 core.register_chatcommand("disconnect", {
58 description = core.gettext("Exit to main menu"),
59 func = function(param)
64 core.register_chatcommand("clear_chat_queue", {
65 description = core.gettext("Clear the out chat queue"),
66 func = function(param)
67 core.clear_out_chat_queue()
68 return true, core.gettext("The out chat queue is now empty.")
72 function core.run_server_chatcommand(cmd, param)
73 core.send_chat_message("/" .. cmd .. " " .. param)