]> git.lizzy.rs Git - minetest.git/blob - builtin/client/chatcommands.lua
Add on_deactivate callback for luaentities (#10723)
[minetest.git] / builtin / client / chatcommands.lua
1 -- Minetest: builtin/client/chatcommands.lua
2
3
4 core.register_on_sending_chat_message(function(message)
5         if message:sub(1,2) == ".." then
6                 return false
7         end
8
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)
12         end
13
14         if first_char ~= "." then
15                 return false
16         end
17
18         local cmd, param = string.match(message, "^%.([^ ]+) *(.*)")
19         param = param or ""
20
21         if not cmd then
22                 core.display_chat_message(core.gettext("-!- Empty command"))
23                 return true
24         end
25
26         -- Run core.registered_on_chatcommand callbacks.
27         if core.run_callbacks(core.registered_on_chatcommand, 5, cmd, param) then
28                 return true
29         end
30
31         local cmd_def = core.registered_chatcommands[cmd]
32         if cmd_def then
33                 core.set_last_run_mod(cmd_def.mod_origin)
34                 local _, result = cmd_def.func(param)
35                 if result then
36                         core.display_chat_message(result)
37                 end
38         else
39                 core.display_chat_message(core.gettext("-!- Invalid command: ") .. cmd)
40         end
41
42         return true
43 end)
44
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.")
51                 end
52
53                 local players = table.concat(player_names, ", ")
54                 return true, core.gettext("Online players: ") .. players
55         end
56 })
57
58 core.register_chatcommand("disconnect", {
59         description = core.gettext("Exit to main menu"),
60         func = function(param)
61                 core.disconnect()
62         end,
63 })
64
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")
70         end,
71 })
72
73 function core.run_server_chatcommand(cmd, param)
74         core.send_chat_message("/" .. cmd .. " " .. param)
75 end