1 -- Minetest: builtin/client/chatcommands.lua
4 core.register_on_sending_chat_message(function(message)
5 if message:sub(1,2) == ".." then
9 local first_char = message:sub(1,1)
10 if first_char == "/" or first_char == "." then
11 core.display_chat_message(core.gettext("issued command: ") .. message)
14 if first_char ~= "." then
18 local cmd, param = string.match(message, "^%.([^ ]+) *(.*)")
22 core.display_chat_message(core.gettext("-!- Empty command"))
26 -- Run core.registered_on_chatcommand callbacks.
27 if core.run_callbacks(core.registered_on_chatcommand, 5, cmd, param) then
31 local cmd_def = core.registered_chatcommands[cmd]
33 core.set_last_run_mod(cmd_def.mod_origin)
34 local _, result = cmd_def.func(param)
36 core.display_chat_message(result)
39 core.display_chat_message(core.gettext("-!- Invalid command: ") .. cmd)
45 core.register_chatcommand("list_players", {
46 description = core.gettext("List online players"),
47 func = function(param)
48 local player_names = core.get_player_names()
49 if not player_names then
50 return false, core.gettext("This command is disabled by server.")
53 local players = table.concat(player_names, ", ")
54 return true, core.gettext("Online players: ") .. players
58 core.register_chatcommand("disconnect", {
59 description = core.gettext("Exit to main menu"),
60 func = function(param)
65 core.register_chatcommand("clear_chat_queue", {
66 description = core.gettext("Clear the out chat queue"),
67 func = function(param)
68 core.clear_out_chat_queue()
69 return true, core.gettext("The out chat queue is now empty")
73 function core.run_server_chatcommand(cmd, param)
74 core.send_chat_message("/" .. cmd .. " " .. param)