fix: unrelated client messages by resetting client command issuer, if not handled by the bot (related #360 )

This commit is contained in:
dmitry 2022-09-10 15:47:41 +03:00
commit 10db943cdf
No known key found for this signature in database
GPG key ID: 8297CE728B7A7E37
2 changed files with 20 additions and 8 deletions

View file

@ -217,6 +217,9 @@ public:
// for the server commands // for the server commands
void handleEngineCommands (); void handleEngineCommands ();
// wrapper for menus and commands
bool handleClientSideCommandsWrapper (edict_t *ent, bool isMenus);
// for the client commands // for the client commands
bool handleClientCommands (edict_t *ent); bool handleClientCommands (edict_t *ent);

View file

@ -1571,6 +1571,10 @@ bool BotControl::executeCommands () {
// do not allow to execute stuff for non admins // do not allow to execute stuff for non admins
if (m_ent != game.getLocalEntity () && !(client.flags & ClientFlags::Admin)) { if (m_ent != game.getLocalEntity () && !(client.flags & ClientFlags::Admin)) {
msg ("Access to %s commands is restricted.", product.name); msg ("Access to %s commands is restricted.", product.name);
// reset issuer, but returns "true" to suppress "unknown command" message
setIssuer (nullptr);
return true; return true;
} }
@ -1919,20 +1923,25 @@ void BotControl::handleEngineCommands () {
executeCommands (); executeCommands ();
} }
bool BotControl::handleClientCommands (edict_t *ent) { bool BotControl::handleClientSideCommandsWrapper (edict_t *ent, bool isMenus) {
collectArgs (); collectArgs ();
setIssuer (ent); setIssuer (ent);
setFromConsole (true); setFromConsole (!isMenus);
return executeCommands (); 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) { bool BotControl::handleMenuCommands (edict_t *ent) {
collectArgs (); return handleClientSideCommandsWrapper (ent, true);
setIssuer (ent);
setFromConsole (false);
return ctrl.executeMenus ();
} }
void BotControl::enableDrawModels (bool enable) { void BotControl::enableDrawModels (bool enable) {