From f12f99333b3a9f19abcb71c8c45e453517915cc9 Mon Sep 17 00:00:00 2001 From: red-001 Date: Sat, 8 Apr 2017 19:03:57 +0100 Subject: [PATCH] Move chat command handling code from C++ to Lua (#5528) --- builtin/game/chatcommands.lua | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/builtin/game/chatcommands.lua b/builtin/game/chatcommands.lua index 16f5f3b..8df3903 100644 --- a/builtin/game/chatcommands.lua +++ b/builtin/game/chatcommands.lua @@ -7,13 +7,22 @@ core.chatcommands = core.registered_chatcommands -- BACKWARDS COMPATIBILITY core.register_on_chat_message(function(name, message) - local cmd, param = string.match(message, "^/([^ ]+) *(.*)") - if not param then - param = "" + if message:sub(1,1) ~= "/" then + return end + + local cmd, param = string.match(message, "^/([^ ]+) *(.*)") + if not cmd then + core.chat_send_player(name, "-!- Empty command") + return true + end + + param = param or "" + local cmd_def = core.registered_chatcommands[cmd] if not cmd_def then - return false + core.chat_send_player(name, "-!- Invalid command: " .. cmd) + return true end local has_privs, missing_privs = core.check_player_privs(name, cmd_def.privs) if has_privs then