From 9b0eb118b3a9c7f682176bbc033fbc0a515636f4 Mon Sep 17 00:00:00 2001 From: Lukas Pioch Date: Mon, 12 Jun 2017 12:59:46 +0200 Subject: [PATCH] Corrected check for level of subcommand and fixed multiple levels not working (#3758) * Corrected check for level of subcommand A message instead of an error is printed, if the sub command is unknown * Multiple levels of sub commands now works, too --- Server/Plugins/InfoReg.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Server/Plugins/InfoReg.lua b/Server/Plugins/InfoReg.lua index a605507de..1e2b3c818 100644 --- a/Server/Plugins/InfoReg.lua +++ b/Server/Plugins/InfoReg.lua @@ -59,7 +59,7 @@ local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_ -- A verb was specified, look it up in the subcommands table: local Subcommand = a_CmdInfo.Subcommands[Verb] if (Subcommand == nil) then - if (a_Level > 1) then + if (a_Level + 1 > 1) then -- This is a true subcommand, display the message and make MCS think the command was handled -- Otherwise we get weird behavior: for "/cmd verb" we get "unknown command /cmd" although "/cmd" is valid if (a_Player == nil) then @@ -81,13 +81,14 @@ local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_ end end - -- If the handler is not valid, check the next sublevel: - if (Subcommand.Handler == nil) then - if (Subcommand.Subcommands == nil) then - LOG("Cannot find handler for command " .. a_CmdString .. " " .. Verb) - return false - end + -- First check if the subcommand has subcommands + if (Subcommand.Subcommands ~= nil) then + -- Next sublevel return MultiCommandHandler(a_Split, a_Player, a_CmdString .. " " .. Verb, Subcommand, a_Level + 1, a_EntireCommand) + elseif (Subcommand.Handler == nil) then + -- Subcommand has no subcommands and the handler is not found, report error + LOGWARNING("Cannot find handler for command " .. a_CmdString .. " " .. Verb) + return false end -- Execute: