From 10db943cdf04554d21134ccc56015571a8082528 Mon Sep 17 00:00:00 2001 From: dmitry Date: Sat, 10 Sep 2022 15:47:41 +0300 Subject: [PATCH] fix: unrelated client messages by resetting client command issuer, if not handled by the bot (related #360 ) --- inc/control.h | 3 +++ src/control.cpp | 25 +++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/inc/control.h b/inc/control.h index 56a1d2f..e71754f 100644 --- a/inc/control.h +++ b/inc/control.h @@ -217,6 +217,9 @@ public: // for the server commands void handleEngineCommands (); + // wrapper for menus and commands + bool handleClientSideCommandsWrapper (edict_t *ent, bool isMenus); + // for the client commands bool handleClientCommands (edict_t *ent); diff --git a/src/control.cpp b/src/control.cpp index 76a1f68..3f08bdb 100644 --- a/src/control.cpp +++ b/src/control.cpp @@ -1571,6 +1571,10 @@ bool BotControl::executeCommands () { // do not allow to execute stuff for non admins if (m_ent != game.getLocalEntity () && !(client.flags & ClientFlags::Admin)) { msg ("Access to %s commands is restricted.", product.name); + + // reset issuer, but returns "true" to suppress "unknown command" message + setIssuer (nullptr); + return true; } @@ -1919,20 +1923,25 @@ void BotControl::handleEngineCommands () { executeCommands (); } -bool BotControl::handleClientCommands (edict_t *ent) { +bool BotControl::handleClientSideCommandsWrapper (edict_t *ent, bool isMenus) { collectArgs (); setIssuer (ent); - setFromConsole (true); - return executeCommands (); + setFromConsole (!isMenus); + auto result = isMenus ? executeMenus () : executeCommands (); + + if (!result) { + setIssuer (nullptr); + } + return result; +} + +bool BotControl::handleClientCommands (edict_t *ent) { + return handleClientSideCommandsWrapper (ent, false); } bool BotControl::handleMenuCommands (edict_t *ent) { - collectArgs (); - setIssuer (ent); - - setFromConsole (false); - return ctrl.executeMenus (); + return handleClientSideCommandsWrapper (ent, true); } void BotControl::enableDrawModels (bool enable) {