From 259dd1833047225e34e722b308beba57a380a379 Mon Sep 17 00:00:00 2001 From: jeefo Date: Thu, 15 Feb 2024 08:37:02 +0300 Subject: [PATCH] mgr: added ``yb exec`` command for debugging purposes --- inc/control.h | 6 ++++-- inc/yapb.h | 6 +++--- src/control.cpp | 31 ++++++++++++++++++++++++++++--- src/engine.cpp | 4 ++-- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/inc/control.h b/inc/control.h index 2450601..4e0afba 100644 --- a/inc/control.h +++ b/inc/control.h @@ -31,11 +31,12 @@ public: struct BotCmd { String name, format, help; Handler handler = nullptr; + bool visible = true; public: explicit BotCmd () = default; - BotCmd (StringRef name, StringRef format, StringRef help, Handler handler) : name (name), format (format), help (help), handler (cr::move (handler)) + BotCmd (StringRef name, StringRef format, StringRef help, Handler handler, bool visible = true) : name (name), format (format), help (help), handler (cr::move (handler)), visible (visible) { } }; @@ -100,6 +101,7 @@ private: int cmdList (); int cmdCvars (); int cmdShowCustom (); + int cmdExec (); int cmdNode (); int cmdNodeOn (); int cmdNodeOff (); @@ -125,7 +127,7 @@ private: int cmdNodeIterateCamp (); int cmdNodeShowStats (); int cmdNodeFileInfo (); - int cmdAdjustHeight (); + int cmdNodeAdjustHeight (); private: int menuMain (int item); diff --git a/inc/yapb.h b/inc/yapb.h index 9bb4592..701b51b 100644 --- a/inc/yapb.h +++ b/inc/yapb.h @@ -776,6 +776,9 @@ public: debugMsgInternal (strings.format (fmt, cr::forward (args)...)); } + // execute client command helper + template void issueCommand (const char *fmt, Args &&...args); + private: // returns true if bot is using a sniper rifle bool usesSniper () const { @@ -826,9 +829,6 @@ private: bool usesKnife () const { return m_weaponType == WeaponType::Melee; } - - // execute client command helper - template void issueCommand (const char *fmt, Args &&...args); }; #include "config.h" diff --git a/src/control.cpp b/src/control.cpp index 3dd7bb9..a8590ba 100644 --- a/src/control.cpp +++ b/src/control.cpp @@ -320,6 +320,27 @@ int BotControl::cmdShowCustom () { return BotCommandResult::Handled; } +int BotControl::cmdExec () { + enum args { alias = 1, target, command }; + + if (!hasArg (target) || !hasArg (command)) { + return BotCommandResult::BadFormat; + } + const auto userId = intValue (target); + + // find our little target + auto bot = bots.findBotByIndex (userId); + + // bailout if not bot + if (!bot) { + msg ("Bot with #%d not found or not a bot.", userId); + return BotCommandResult::Handled; + } + bot->issueCommand (strValue (command).chars ()); + + return BotCommandResult::Handled; +} + int BotControl::cmdNode () { enum args { root, alias, cmd, cmd2 }; @@ -383,7 +404,7 @@ int BotControl::cmdNode () { addGraphCmd ("upload", "upload", "Uploads created graph to graph database.", &BotControl::cmdNodeUpload); addGraphCmd ("stats", "stats [noarguments]", "Shows the stats about node types on the map.", &BotControl::cmdNodeShowStats); addGraphCmd ("fileinfo", "fileinfo [noarguments]", "Shows basic information about graph file.", &BotControl::cmdNodeFileInfo); - addGraphCmd ("adjust_height", "adjust_height [height offset]", "Modifies all the graph nodes height (z-component) with specified offset.", &BotControl::cmdAdjustHeight); + addGraphCmd ("adjust_height", "adjust_height [height offset]", "Modifies all the graph nodes height (z-component) with specified offset.", &BotControl::cmdNodeAdjustHeight); // add path commands addGraphCmd ("path_create", "path_create [noarguments]", "Opens and displays path creation menu.", &BotControl::cmdNodePathCreate); @@ -961,7 +982,7 @@ int BotControl::cmdNodeFileInfo () { return BotCommandResult::Handled; } -int BotControl::cmdAdjustHeight () { +int BotControl::cmdNodeAdjustHeight () { enum args { graph_cmd = 1, cmd, offset }; if (!hasArg (offset)) { @@ -1876,6 +1897,9 @@ bool BotControl::executeCommands () { msg ("valid commands are: "); for (auto &item : m_cmds) { + if (!item.visible) { + continue; + } msg (" %-14.11s - %s", item.name.split ("/").first (), String (conf.translate (item.help)).lowercase ()); } return true; @@ -2151,7 +2175,8 @@ BotControl::BotControl () { m_cmds.emplace ("list/listbots", "list [noarguments]", "Lists the bots currently playing on server.", &BotControl::cmdList); m_cmds.emplace ("graph/g/wp/wpt/waypoint", "graph [help]", "Handles graph operations.", &BotControl::cmdNode); m_cmds.emplace ("cvars", "cvars [save|save_map|cvar|defaults]", "Display all the cvars with their descriptions.", &BotControl::cmdCvars); - m_cmds.emplace ("show_custom", "show_custom [noarguments]", "Shows the current values from custom.cfg.", &BotControl::cmdShowCustom); + m_cmds.emplace ("show_custom", "show_custom [noarguments]", "Shows the current values from custom.cfg.", &BotControl::cmdShowCustom, false); + m_cmds.emplace ("exec", "exec [user_id] [command]", "Executes a client command on bot entity.", &BotControl::cmdExec); // declare the menus createMenus (); diff --git a/src/engine.cpp b/src/engine.cpp index 0e031f7..795f0f5 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -980,8 +980,8 @@ void Game::applyGameModes () { static ConVarRef zp_delay ("zp_delay"); // update our ignore timer if zp_elay exists - if (zp_delay.exists () && zp_delay.value () > 0.0f && cv_ignore_enemies_after_spawn_time.float_ () < 1.0f) { - cv_ignore_enemies_after_spawn_time.set (zp_delay.value () + 2.0f); + if (zp_delay.exists () && zp_delay.value () > 0.0f) { + cv_ignore_enemies_after_spawn_time.set (zp_delay.value () + 3.0f); } }