]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - builtin/client/chatcommands.lua
[CSM] Move `.list_players` and `.disconnect` to builtin. (#5550)
[dragonfireclient.git] / builtin / client / chatcommands.lua
index 43b4d9a72c1cce548c960354fc67a54b18b11559..bb5b905d89bd440815de61ec87f55305d82986a7 100644 (file)
@@ -2,27 +2,50 @@
 
 
 core.register_on_sending_chat_messages(function(message)
-       if not (message:sub(1,1) == "/") then
-               return false
+       local first_char = message:sub(1,1)
+       if first_char == "/" or first_char == "." then
+               core.display_chat_message("issued command: " .. message)
        end
 
-       core.display_chat_message("issued command: " .. message)
+       if first_char ~= "." then
+               return false
+       end
 
-       local cmd, param = string.match(message, "^/([^ ]+) *(.*)")
+       local cmd, param = string.match(message, "^%.([^ ]+) *(.*)")
        if not param then
                param = ""
        end
 
-       local cmd_def = core.registered_chatcommands[cmd]
+       if not cmd then
+               core.display_chat_message("-!- Empty command")
+               return true
+       end
 
+       local cmd_def = core.registered_chatcommands[cmd]
        if cmd_def then
                core.set_last_run_mod(cmd_def.mod_origin)
                local _, message = cmd_def.func(param)
                if message then
                        core.display_chat_message(message)
                end
-               return true
+       else
+               core.display_chat_message("-!- Invalid command: " .. cmd)
        end
 
-       return false
+       return true
 end)
+
+core.register_chatcommand("list_players", {
+       description = "List online players",
+       func = function(param)
+               local players = table.concat(core.get_player_names(), ", ")
+               core.display_chat_message("Online players: " .. players)
+       end
+})
+
+core.register_chatcommand("disconnect", {
+       description = "Exit to main menu",
+       func = function(param)
+               core.disconnect()
+       end,
+})