cvars: allow to set very long descriptions

cvars: added full descriptions to yb+restricted_weapons (closes #659)
crlib: update submodule
fix: send server messages should split as string and not stringref to keep null-terminated chunks
This commit is contained in:
jeefo 2025-02-15 13:51:45 +03:00
commit b8fb2e8845
No known key found for this signature in database
GPG key ID: D696786B81B667C8
9 changed files with 77 additions and 58 deletions

@ -1 +1 @@
Subproject commit 11dc7fe543fef9d16045e7f9e01fb40668099eda Subproject commit 448e8341b8bba351c7b9e81ea9949588cedad10a

View file

@ -232,6 +232,9 @@ public:
// check the cvar bounds // check the cvar bounds
void checkCvarsBounds (); void checkCvarsBounds ();
// modify cvar description
void setCvarDescription (const ConVar &cv, StringRef info);
// sends local registration stack for engine registration // sends local registration stack for engine registration
void registerCvars (bool gameVars = false); void registerCvars (bool gameVars = false);

View file

@ -8,6 +8,9 @@
#pragma once #pragma once
class BotSupport final : public Singleton <BotSupport> { class BotSupport final : public Singleton <BotSupport> {
using AliasInfo = Twin <StringRef, StringRef>;
using AliasMap = HashMap <int32_t, AliasInfo, EmptyHash <int32_t> >;
private: private:
bool m_needToSendWelcome {}; bool m_needToSendWelcome {};
float m_welcomeReceiveTime {}; float m_welcomeReceiveTime {};
@ -15,7 +18,7 @@ private:
StringArray m_sentences {}; StringArray m_sentences {};
SmallArray <Client> m_clients {}; SmallArray <Client> m_clients {};
HashMap <int32_t, String> m_weaponAliases {}; AliasMap m_weaponAliases {};
public: public:
BotSupport (); BotSupport ();
@ -79,6 +82,9 @@ public:
// get's the wave length // get's the wave length
float getWaveLength (StringRef filename); float getWaveLength (StringRef filename);
// set custom cvar descriptions
void setCustomCvarDescriptions ();
public: public:
// re-show welcome after changelevel ? // re-show welcome after changelevel ?

View file

@ -932,6 +932,7 @@ extern ConVar cv_camping_time_max;
extern ConVar cv_smoke_grenade_checks; extern ConVar cv_smoke_grenade_checks;
extern ConVar cv_check_darkness; extern ConVar cv_check_darkness;
extern ConVar cv_use_hitbox_enemy_targeting; extern ConVar cv_use_hitbox_enemy_targeting;
extern ConVar cv_restricted_weapons;
extern ConVar mp_freezetime; extern ConVar mp_freezetime;
extern ConVar mp_roundtime; extern ConVar mp_roundtime;

View file

@ -31,9 +31,8 @@ ConVar cv_object_pickup_radius ("object_pickup_radius", "450.0", "The radius on
ConVar cv_object_destroy_radius ("object_destroy_radius", "400.0", "The radius on which bot destroy breakables around it, when not touching with them.", true, 64.0f, 1024.0f); ConVar cv_object_destroy_radius ("object_destroy_radius", "400.0", "The radius on which bot destroy breakables around it, when not touching with them.", true, 64.0f, 1024.0f);
ConVar cv_chatter_path ("chatter_path", "sound/radio/bot", "Specifies the paths for the bot chatter sound files.", false); ConVar cv_chatter_path ("chatter_path", "sound/radio/bot", "Specifies the paths for the bot chatter sound files.", false);
ConVar cv_restricted_weapons ("restricted_weapons", "", "Specifies semicolon separated list of weapons that are not allowed to buy / pickup.", false);
ConVar cv_attack_monsters ("attack_monsters", "0", "Allows or disallows bots to attack monsters."); ConVar cv_attack_monsters ("attack_monsters", "0", "Allows or disallows bots to attack monsters.");
ConVar cv_pickup_custom_items ("pickup_custom_items", "0", "Allows or disallows bots to pickup custom items."); ConVar cv_pickup_custom_items ("pickup_custom_items", "0", "Allows or disallows bots to pickup custom items.");
ConVar cv_pickup_ammo_and_kits ("pickup_ammo_and_kits", "0", "Allows bots pickup mod items like ammo, health kits and suits."); ConVar cv_pickup_ammo_and_kits ("pickup_ammo_and_kits", "0", "Allows bots pickup mod items like ammo, health kits and suits.");
ConVar cv_pickup_best ("pickup_best", "1", "Allows or disallows bots to pickup best weapons."); ConVar cv_pickup_best ("pickup_best", "1", "Allows or disallows bots to pickup best weapons.");

View file

@ -468,7 +468,7 @@ void Game::sendServerMessage (StringRef message) {
// split up the string into chunks if needed (maybe check if it's multibyte?) // split up the string into chunks if needed (maybe check if it's multibyte?)
if (message.length () > kMaxSendLength) { if (message.length () > kMaxSendLength) {
auto chunks = message.split (kMaxSendLength); auto chunks = message.split <String> (kMaxSendLength);
// send in chunks // send in chunks
for (size_t i = 0; i < chunks.length (); ++i) { for (size_t i = 0; i < chunks.length (); ++i) {
@ -733,6 +733,15 @@ void Game::checkCvarsBounds () {
} }
} }
void Game::setCvarDescription (const ConVar &cv, StringRef info) {
for (auto &var : m_cvars) {
if (var.name == cv.name ()) {
var.info = info;
break;
}
}
}
void Game::registerCvars (bool gameVars) { void Game::registerCvars (bool gameVars) {
// this function pushes all added global variables to engine registration // this function pushes all added global variables to engine registration
@ -911,6 +920,9 @@ bool Game::postload () {
// register bot cvars // register bot cvars
registerCvars (); registerCvars ();
// set custom cvar descriptions after registering them
util.setCustomCvarDescriptions ();
// handle prefixes // handle prefixes
static StringArray prefixes = { product.cmdPri, product.cmdSec }; static StringArray prefixes = { product.cmdPri, product.cmdSec };

View file

@ -933,8 +933,8 @@ CR_EXPORT int Meta_Query (char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t
// check for interface version compatibility // check for interface version compatibility
if (strcmp (ifvers, Plugin_info.ifvers) != 0) { if (strcmp (ifvers, Plugin_info.ifvers) != 0) {
auto mdll = StringRef (ifvers).split (":"); auto mdll = String (ifvers).split (":");
auto pdll = StringRef (META_INTERFACE_VERSION).split (":"); auto pdll = String (META_INTERFACE_VERSION).split (":");
gpMetaUtilFuncs->pfnLogError (PLID, "%s: meta-interface version mismatch (metamod: %s, %s: %s)", Plugin_info.name, ifvers, Plugin_info.name, Plugin_info.ifvers); gpMetaUtilFuncs->pfnLogError (PLID, "%s: meta-interface version mismatch (metamod: %s, %s: %s)", Plugin_info.name, ifvers, Plugin_info.name, Plugin_info.ifvers);

View file

@ -49,6 +49,8 @@ ConVar cv_rotate_bots ("rotate_bots", "0", "Randomly disconnect and connect bots
ConVar cv_rotate_stay_min ("rotate_stay_min", "360.0", "Specifies minimum amount of seconds bot keep connected, if rotation active.", true, 120.0f, 7200.0f); ConVar cv_rotate_stay_min ("rotate_stay_min", "360.0", "Specifies minimum amount of seconds bot keep connected, if rotation active.", true, 120.0f, 7200.0f);
ConVar cv_rotate_stay_max ("rotate_stay_max", "3600.0", "Specifies maximum amount of seconds bot keep connected, if rotation active.", true, 1800.0f, 14400.0f); ConVar cv_rotate_stay_max ("rotate_stay_max", "3600.0", "Specifies maximum amount of seconds bot keep connected, if rotation active.", true, 1800.0f, 14400.0f);
ConVar cv_restricted_weapons ("restricted_weapons", "", "", false);
ConVar mp_limitteams ("mp_limitteams", nullptr, Var::GameRef); ConVar mp_limitteams ("mp_limitteams", nullptr, Var::GameRef);
ConVar mp_autoteambalance ("mp_autoteambalance", nullptr, Var::GameRef); ConVar mp_autoteambalance ("mp_autoteambalance", nullptr, Var::GameRef);
ConVar mp_roundtime ("mp_roundtime", nullptr, Var::GameRef); ConVar mp_roundtime ("mp_roundtime", nullptr, Var::GameRef);
@ -58,28 +60,12 @@ ConVar mp_freezetime ("mp_freezetime", nullptr, Var::GameRef, true, "0");
BotManager::BotManager () { BotManager::BotManager () {
// this is a bot manager class constructor // this is a bot manager class constructor
m_lastDifficulty = 0;
m_lastWinner = -1;
m_timeRoundStart = 0.0f;
m_timeRoundMid = 0.0f;
m_timeRoundEnd = 0.0f;
m_autoKillCheckTime = 0.0f;
m_maintainTime = 0.0f;
m_quotaMaintainTime = 0.0f;
m_difficultyBalanceTime = 0.0f;
m_bombPlanted = false;
m_botsCanPause = false;
m_roundOver = false;
for (int i = 0; i < kGameTeamNum; ++i) { for (int i = 0; i < kGameTeamNum; ++i) {
m_leaderChoosen[i] = false; m_leaderChoosen[i] = false;
m_economicsGood[i] = true; m_economicsGood[i] = true;
m_lastRadioTime[i] = 0.0f; m_lastRadioTime[i] = 0.0f;
m_lastRadio[i] = -1; m_lastRadio[i] = kInvalidRadioSlot;
} }
reset (); reset ();

View file

@ -46,40 +46,39 @@ BotSupport::BotSupport () {
// register weapon aliases // register weapon aliases
m_weaponAliases = { m_weaponAliases = {
{ Weapon::USP, "usp" }, // HK USP .45 Tactical { Weapon::USP, AliasInfo { "usp", "HK USP .45 Tactical" } },
{ Weapon::Glock18, "glock" }, // Glock18 Select Fire { Weapon::Glock18, AliasInfo { "glock", "Glock18 Select Fire" } },
{ Weapon::Deagle, "deagle" }, // Desert Eagle .50AE { Weapon::Deagle, AliasInfo { "deagle", "Desert Eagle .50AE" } },
{ Weapon::P228, "p228" }, // SIG P228 { Weapon::P228, AliasInfo { "p228", "SIG P228" } },
{ Weapon::Elite, "elite" }, // Dual Beretta 96G Elite { Weapon::Elite, AliasInfo { "elite", "Dual Beretta 96G Elite" } },
{ Weapon::FiveSeven, "fn57" }, // FN Five-Seven { Weapon::FiveSeven, AliasInfo { "fn57", "FN Five-Seven" } },
{ Weapon::M3, "m3" }, // Benelli M3 Super90 { Weapon::M3, AliasInfo { "m3", "Benelli M3 Super90" } },
{ Weapon::XM1014, "xm1014" }, // Benelli XM1014 { Weapon::XM1014, AliasInfo { "xm1014", "Benelli XM1014" } },
{ Weapon::MP5, "mp5" }, // HK MP5-Navy { Weapon::MP5, AliasInfo { "mp5", "HK MP5-Navy" } },
{ Weapon::TMP, "tmp" }, // Steyr Tactical Machine Pistol { Weapon::TMP, AliasInfo { "tmp", "Steyr Tactical Machine Pistol" } },
{ Weapon::P90, "p90" }, // FN P90 { Weapon::P90, AliasInfo { "p90", "FN P90" } },
{ Weapon::MAC10, "mac10" }, // Ingram MAC-10 { Weapon::MAC10, AliasInfo { "mac10", "Ingram MAC-10" } },
{ Weapon::UMP45, "ump45" }, // HK UMP45 { Weapon::UMP45, AliasInfo { "ump45", "HK UMP45" } },
{ Weapon::AK47, "ak47" }, // Automat Kalashnikov AK-47 { Weapon::AK47, AliasInfo { "ak47", "Automat Kalashnikov AK-47" } },
{ Weapon::Galil, "galil" }, // IMI Galil { Weapon::Galil, AliasInfo { "galil", "IMI Galil" } },
{ Weapon::Famas, "famas" }, // GIAT FAMAS { Weapon::Famas, AliasInfo { "famas", "GIAT FAMAS" } },
{ Weapon::SG552, "sg552" }, // Sig SG-552 Commando { Weapon::SG552, AliasInfo { "sg552", "Sig SG-552 Commando" } },
{ Weapon::M4A1, "m4a1" }, // Colt M4A1 Carbine { Weapon::M4A1, AliasInfo { "m4a1", "Colt M4A1 Carbine" } },
{ Weapon::AUG, "aug" }, // Steyr Aug { Weapon::AUG, AliasInfo { "aug", "Steyr Aug" } },
{ Weapon::Scout, "scout" }, // Steyr Scout { Weapon::Scout, AliasInfo { "scout", "Steyr Scout" } },
{ Weapon::AWP, "awp" }, // AI Arctic Warfare/Magnum { Weapon::AWP, AliasInfo { "awp", "AI Arctic Warfare/Magnum" } },
{ Weapon::G3SG1, "g3sg1" }, // HK G3/SG-1 Sniper Rifle { Weapon::G3SG1, AliasInfo { "g3sg1", "HK G3/SG-1 Sniper Rifle" } },
{ Weapon::SG550, "sg550" }, // Sig SG-550 Sniper { Weapon::SG550, AliasInfo { "sg550", "Sig SG-550 Sniper" } },
{ Weapon::M249, "m249" }, // FN M249 Para { Weapon::M249, AliasInfo { "m249", "FN M249 Para" } },
{ Weapon::Flashbang, "flash" }, // Concussion Grenade { Weapon::Flashbang, AliasInfo { "flash", "Concussion Grenade" } },
{ Weapon::Explosive, "hegren" }, // High-Explosive Grenade { Weapon::Explosive, AliasInfo { "hegren", "High-Explosive Grenade" } },
{ Weapon::Smoke, "sgren" }, // Smoke Grenade { Weapon::Smoke, AliasInfo { "sgren", "Smoke Grenade" } },
{ Weapon::Armor, "vest" }, // Kevlar Vest { Weapon::Armor, AliasInfo { "vest", "Kevlar Vest" } },
{ Weapon::ArmorHelm, "vesthelm" }, // Kevlar Vest and Helmet { Weapon::ArmorHelm, AliasInfo { "vesthelm", "Kevlar Vest and Helmet" } },
{ Weapon::Defuser, "defuser" }, // Defuser Kit { Weapon::Defuser, AliasInfo { "defuser", "Defuser Kit" } },
{ Weapon::Shield, "shield" }, // Tactical Shield { Weapon::Shield, AliasInfo { "shield", "Tactical Shield" } },
{ Weapon::Knife, "knife" } // Knife { Weapon::Knife, AliasInfo { "knife", "Knife" } }
}; };
m_clients.resize (kGameMaxPlayers + 1); m_clients.resize (kGameMaxPlayers + 1);
} }
@ -432,7 +431,7 @@ StringRef BotSupport::weaponIdToAlias (int32_t id) {
StringRef none = "none"; StringRef none = "none";
if (m_weaponAliases.exists (id)) { if (m_weaponAliases.exists (id)) {
return m_weaponAliases[id]; return m_weaponAliases[id].first;
} }
return none; return none;
} }
@ -515,3 +514,16 @@ float BotSupport::getWaveLength (StringRef filename) {
return length / bps / channels / rate; return length / bps / channels / rate;
} }
void BotSupport::setCustomCvarDescriptions () {
// set the cvars custom descriptions here if needed
String restrictInfo = "Specifies semicolon separated list of weapons that are not allowed to buy / pickup.\n";
restrictInfo += "The list of weapons for Counter-Strike 1.6:\n";
// fill the restrict information
m_weaponAliases.foreach ([&] (const int32_t &, const AliasInfo &alias) {
restrictInfo.appendf ("%s - %s\n", alias.first, alias.second);
});
game.setCvarDescription (cv_restricted_weapons, restrictInfo);
}