]> git.lizzy.rs Git - minetest.git/blob - builtin/client/chatcommands.lua
Builtin: Fix grayed-out but enabled modpacks
[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         local cmd_def = core.registered_chatcommands[cmd]
27         if cmd_def then
28                 core.set_last_run_mod(cmd_def.mod_origin)
29                 local _, message = cmd_def.func(param)
30                 if message then
31                         core.display_chat_message(message)
32                 end
33         else
34                 core.display_chat_message(core.gettext("-!- Invalid command: ") .. cmd)
35         end
36
37         return true
38 end)
39
40 core.register_chatcommand("list_players", {
41         description = core.gettext("List online players"),
42         func = function(param)
43                 local player_names = core.get_player_names()
44                 if not player_names then
45                         return false, core.gettext("This command is disabled by server.")
46                 end
47
48                 local players = table.concat(player_names, ", ")
49                 return true, core.gettext("Online players: ") .. players
50         end
51 })
52
53 core.register_chatcommand("disconnect", {
54         description = core.gettext("Exit to main menu"),
55         func = function(param)
56                 core.disconnect()
57         end,
58 })
59
60 core.register_chatcommand("clear_chat_queue", {
61         description = core.gettext("Clear the out chat queue"),
62         func = function(param)
63                 core.clear_out_chat_queue()
64                 return true, core.gettext("The out chat queue is now empty")
65         end,
66 })
67
68 function core.run_server_chatcommand(cmd, param)
69         core.send_chat_message("/" .. cmd .. " " .. param)
70 end