]> git.lizzy.rs Git - dragonfireclient.git/blob - builtin/client/chatcommands.lua
[CSM] Move `.list_players` and `.disconnect` to builtin. (#5550)
[dragonfireclient.git] / builtin / client / chatcommands.lua
1 -- Minetest: builtin/client/chatcommands.lua
2
3
4 core.register_on_sending_chat_messages(function(message)
5         local first_char = message:sub(1,1)
6         if first_char == "/" or first_char == "." then
7                 core.display_chat_message("issued command: " .. message)
8         end
9
10         if first_char ~= "." then
11                 return false
12         end
13
14         local cmd, param = string.match(message, "^%.([^ ]+) *(.*)")
15         if not param then
16                 param = ""
17         end
18
19         if not cmd then
20                 core.display_chat_message("-!- Empty command")
21                 return true
22         end
23
24         local cmd_def = core.registered_chatcommands[cmd]
25         if cmd_def then
26                 core.set_last_run_mod(cmd_def.mod_origin)
27                 local _, message = cmd_def.func(param)
28                 if message then
29                         core.display_chat_message(message)
30                 end
31         else
32                 core.display_chat_message("-!- Invalid command: " .. cmd)
33         end
34
35         return true
36 end)
37
38 core.register_chatcommand("list_players", {
39         description = "List online players",
40         func = function(param)
41                 local players = table.concat(core.get_player_names(), ", ")
42                 core.display_chat_message("Online players: " .. players)
43         end
44 })
45
46 core.register_chatcommand("disconnect", {
47         description = "Exit to main menu",
48         func = function(param)
49                 core.disconnect()
50         end,
51 })