From 784ad5e30314fbacf61bf1370cf1df9f9a6d1a97 Mon Sep 17 00:00:00 2001 From: jeefo Date: Thu, 14 Aug 2025 19:35:26 +0300 Subject: [PATCH] graph: do not show any warnings on analyzed maps (ref #726) ctr: revert cvars to it's config value instead of hardcoded values (resolves #722) --- cfg/addons/yapb/conf/custom.cfg | 6 ++++ inc/engine.h | 2 ++ inc/storage.h | 2 +- src/config.cpp | 30 ++++++++++++++++---- src/control.cpp | 4 +-- src/engine.cpp | 49 ++++++++++++++++++--------------- src/graph.cpp | 14 ++++++---- src/storage.cpp | 11 +++++--- 8 files changed, 77 insertions(+), 41 deletions(-) diff --git a/cfg/addons/yapb/conf/custom.cfg b/cfg/addons/yapb/conf/custom.cfg index f055834..483d9c6 100644 --- a/cfg/addons/yapb/conf/custom.cfg +++ b/cfg/addons/yapb/conf/custom.cfg @@ -9,6 +9,12 @@ ; NOTE: All changes to this file takes effect only on server restart. ; +; +; Specifies the hostname the bot will attempt to connect to for checking network +; availability and enabling graph download/upload features. +; +CheckConnectivityHost = yapb.jeefo.net + ; ; Custom name for C4 model, for servers that replacing C4 model with it's own. ; By default it's "c4.mdl" (the models/ path is omitted), so if you need to use diff --git a/inc/engine.h b/inc/engine.h index 56fc325..d7d8d2c 100644 --- a/inc/engine.h +++ b/inc/engine.h @@ -247,6 +247,8 @@ public: // load the cs binary in non metamod mode bool loadCSBinary (); + void constructCSBinaryName (StringArray &libs); + // do post-load stuff bool postload (); diff --git a/inc/storage.h b/inc/storage.h index db41308..c21618a 100644 --- a/inc/storage.h +++ b/inc/storage.h @@ -89,7 +89,7 @@ public: int32_t storageToBotFile (int32_t options); // remove all bot related files from disk - void unlinkFromDisk (bool onlyTrainingData); + void unlinkFromDisk (bool onlyTrainingData, bool silenceMessages); public: // loading the graph may attempt to recurse loading, with converting or download, reset retry counter diff --git a/src/config.cpp b/src/config.cpp index 30cf4a4..81fde35 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -46,6 +46,19 @@ void BotConfig::loadMainConfig (bool isFirstLoad) { return false; }; + auto storeVarValue = [] (cvar_t *c, StringRef value) { + auto &cvars = game.getCvars (); + + for (auto &var : cvars) { + if (var.name == c->name) { + var.init = value; + engfuncs.pfnCvar_DirectSet (c, value.chars ()); + + break; + } + } + }; + String line {}; MemFile file {}; @@ -77,16 +90,16 @@ void BotConfig::loadMainConfig (bool isFirstLoad) { // preserve quota number if it's zero if (cv_quota.name () == cvar->name && cv_quota.as () <= 0) { - engfuncs.pfnCvar_DirectSet (cvar, value); + storeVarValue (cvar, value); continue; } ctrl.msg ("Bot CVAR '%s' differs from the stored in the config (%s/%s). Ignoring.", cvar->name, cvar->string, value); // ensure cvar will have old value - engfuncs.pfnCvar_DirectSet (cvar, cvar->string); + storeVarValue (cvar, cvar->string); } else { - engfuncs.pfnCvar_DirectSet (cvar, value); + storeVarValue (cvar, value); } } else { @@ -108,12 +121,17 @@ void BotConfig::loadMainConfig (bool isFirstLoad) { // preload custom config conf.loadCustomConfig (); + // startup the sockets on windows and check if our host is available + if (isFirstLoad) { + http.startup (conf.fetchCustom ("CheckConnectivityHost"), "Bot is unable to check network availability. Networking features are disabled."); + } + // bind the correct menu key for bot menu... if (!game.isDedicated ()) { auto val = cv_bind_menu_key.as (); if (!val.empty ()) { - game.serverCommand ("bind \"%s\" \"yb menu\"", val); + game.serverCommand ("bind \"%s\" \"%s menu\"", val, product.cmdPri); } } static const bool disableLogWrite = conf.fetchCustom ("DisableLogFile").startsWith ("yes"); @@ -698,10 +716,10 @@ void BotConfig::loadCustomConfig () { { "ZMDelayCvar", "zp_delay" }, { "ZMInfectedTeam", "T" }, { "EnableFakeBotFeatures", "no" }, - { "DisableLogFile", "no" } + { "DisableLogFile", "no" }, + { "CheckConnectivityHost", "yapb.jeefo.net" } }; }; - setDefaults (); // has errors ? diff --git a/src/control.cpp b/src/control.cpp index 5190f9a..e9b6872 100644 --- a/src/control.cpp +++ b/src/control.cpp @@ -636,7 +636,7 @@ int BotControl::cmdNodeErase () { // prevent accidents when graph are deleted unintentionally if (arg (iamsure) == "iamsure") { - bstor.unlinkFromDisk (false); + bstor.unlinkFromDisk (false, false); } else { msg ("Please, append \"iamsure\" as parameter to get graph erased from the disk."); @@ -647,7 +647,7 @@ int BotControl::cmdNodeErase () { int BotControl::cmdNodeEraseTraining () { enum args { graph_cmd = 1, cmd }; - bstor.unlinkFromDisk (true); + bstor.unlinkFromDisk (true, false); return BotCommandResult::Handled; } diff --git a/src/engine.cpp b/src/engine.cpp index 1f290dd..3fde67f 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -658,7 +658,7 @@ void ConVar::revert () { for (const auto &var : cvars) { if (var.name == ptr->name) { - set (var.initial); + set (var.init.chars ()); break; } } @@ -789,41 +789,38 @@ void Game::registerCvars (bool gameVars) { } } -bool Game::loadCSBinary () { - StringRef modname = getRunningModName (); - - if (modname.empty ()) { - return false; - } - - Array libs {}; - - // construct library suffix - String libSuffix {}; +void Game::constructCSBinaryName (StringArray &libs) { + String libSuffix {}; // construct library suffix if (plat.android) { libSuffix += "_android"; - } else if (plat.psvita) { + } + else if (plat.psvita) { libSuffix += "_psvita"; } if (plat.x64) { if (plat.arm) { libSuffix += "_arm64"; - } else if (plat.ppc) { + } + else if (plat.ppc) { libSuffix += "_ppc64le"; - } else { + } + else { libSuffix += "_amd64"; } - } else { + } + else { if (plat.arm) { // don't want to put whole build.h logic from xash3d, just set whatever is supported by the YaPB if (plat.android) { libSuffix += "_armv7l"; - } else { + } + else { libSuffix += "_armv7hf"; } - } else if (!plat.nix && !plat.win && !plat.macos) { + } + else if (!plat.nix && !plat.win && !plat.macos) { libSuffix += "_i386"; } } @@ -837,10 +834,21 @@ bool Game::loadCSBinary () { else libs.insert (0, { "mp", "cs" }); - for (auto &lib: libs) { + for (auto &lib : libs) { lib += libSuffix; } } +} + +bool Game::loadCSBinary () { + StringRef modname = getRunningModName (); + + if (modname.empty ()) { + return false; + } + + StringArray libs {}; + constructCSBinaryName (libs); auto libCheck = [&] (StringRef mod, StringRef dll) { // try to load gamedll @@ -971,9 +979,6 @@ bool Game::postload () { // set out user agent for http stuff http.setUserAgent (strings.format ("%s/%s", product.name, product.version)); - // startup the sockets on windows and check if our host is available (hardcoded, yup) - http.startup ("yapb.jeefo.net", "Bot is unable to check network availability. Networking features are disabled."); - // set the app name plat.setAppName (product.name.chars ()); diff --git a/src/graph.cpp b/src/graph.cpp index 06c8d2a..31650b7 100644 --- a/src/graph.cpp +++ b/src/graph.cpp @@ -1829,7 +1829,7 @@ bool BotGraph::loadGraphData () { } // notify user about graph problems - if (planner.isPathsCheckFailed ()) { + if (planner.isPathsCheckFailed () && !graph.isAnalyzed ()) { ctrl.msg ("Warning: Graph data has failed sanity check."); ctrl.msg ("Warning: Bots will use only shortest-path algo for path finding."); ctrl.msg ("Warning: This may significantly affect bots behavior on this map."); @@ -2523,6 +2523,8 @@ bool BotGraph::checkNodes (bool teleportPlayer, bool onlyPaths) { if (test.index != kInvalidNodeIndex) { if (!exists (test.index)) { if (showErrors) { + teleport (path); + msg ("Node %d path index %d out of range.", path.number, test.index); } teleport (path); @@ -2531,17 +2533,17 @@ bool BotGraph::checkNodes (bool teleportPlayer, bool onlyPaths) { } else if (test.index == path.number) { if (showErrors) { + teleport (path); + msg ("Node %d path index %d points to itself.", path.number, test.index); } - teleport (path); - return false; } } } } - if (game.mapIs (MapFlags::HostageRescue)) { + if (!onlyPaths && game.mapIs (MapFlags::HostageRescue)) { if (rescuePoints == 0) { msg ("You didn't set a rescue point."); return false; @@ -2648,10 +2650,10 @@ bool BotGraph::checkNodes (bool teleportPlayer, bool onlyPaths) { for (const auto &path : m_paths) { if (!visited[path.number]) { if (showErrors) { + teleport (path); + msg ("Path broken from node %d to node 0.", path.number); } - teleport (path); - return false; } } diff --git a/src/storage.cpp b/src/storage.cpp index 4d341c1..e983a37 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -95,7 +95,7 @@ template bool BotStorage::load (SmallArray &data, ExtenHeader * // erase the current graph just in case auto unlinkIfGraph = [&] () { if (isGraph) { - unlinkFromDisk (false); + unlinkFromDisk (false, true); } }; @@ -406,7 +406,7 @@ int32_t BotStorage::storageToBotFile (int32_t options) { return BotFile::Graph; } -void BotStorage::unlinkFromDisk (bool onlyTrainingData) { +void BotStorage::unlinkFromDisk (bool onlyTrainingData, bool silenceMessages) { // this function removes graph file from the hard disk StringArray unlinkable {}; @@ -423,9 +423,12 @@ void BotStorage::unlinkFromDisk (bool onlyTrainingData) { for (const auto &item : unlinkable) { if (plat.fileExists (item.chars ())) { plat.removeFile (item.chars ()); - ctrl.msg ("File %s, has been deleted from the hard disk", item); + + if (!silenceMessages) { + ctrl.msg ("File %s, has been deleted from the hard disk", item); + } } - else { + else if (!silenceMessages) { logger.error ("Unable to open %s", item); } }