[General]: Fix dvar name (#927)

This commit is contained in:
Edo 2023-04-15 12:19:56 +02:00 committed by GitHub
parent f5633770dc
commit 9160436b05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 4 deletions

View File

@ -1,6 +1,7 @@
#include <STDInclude.hpp>
#include "Bots.hpp"
#include "ClanTags.hpp"
#include "GSC/Script.hpp"
@ -10,6 +11,8 @@
namespace Components
{
constexpr std::size_t MAX_NAME_LENGTH = 16;
std::vector<Bots::botData> Bots::BotNames;
Dvar::Var Bots::SVRandomBotNames;
@ -57,6 +60,16 @@ namespace Components
std::ranges::shuffle(BotNames, gen);
}
std::string Bots::TruncBotString(const std::string& input, const std::size_t length)
{
if (length > input.size())
{
return input;
}
return input.substr(length);
}
void Bots::LoadBotNames()
{
FileSystem::File bots("bots.txt");
@ -94,6 +107,9 @@ namespace Components
entry = entry.substr(0, pos);
}
entry = TruncBotString(entry, MAX_NAME_LENGTH - 1);
clanAbbrev = TruncBotString(clanAbbrev, ClanTags::MAX_CLAN_NAME_LENGTH - 1);
BotNames.emplace_back(entry, clanAbbrev);
}
@ -381,7 +397,7 @@ namespace Components
Utils::Hook(0x459654, SV_GetClientPing_Hk, HOOK_CALL).install()->quick();
SVRandomBotNames = Dvar::Register<bool>("sv_RandomBotNames", false, Game::DVAR_NONE, "Randomize the bots' names");
SVRandomBotNames = Dvar::Register<bool>("sv_randomBotNames", false, Game::DVAR_NONE, "Randomize the bots' names");
// Reset BotMovementInfo.active when client is dropped
Events::OnClientDisconnect([](const int clientNum) -> void

View File

@ -14,6 +14,7 @@ namespace Components
static Dvar::Var SVRandomBotNames;
static void RandomizeBotNames();
static std::string TruncBotString(const std::string& input, std::size_t length);
static void LoadBotNames();
static int BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port);

View File

@ -8,7 +8,7 @@ namespace Components
const Game::dvar_t* ClanTags::ClanName;
// bgs_t and clientState_s do not have this
char ClanTags::ClientState[Game::MAX_CLIENTS][5];
char ClanTags::ClientState[Game::MAX_CLIENTS][MAX_CLAN_NAME_LENGTH];
const char* ClanTags::GetClanTagWithName(int clientNum, const char* playerName)
{
@ -73,7 +73,7 @@ namespace Components
void ClanTags::CL_SanitizeClanName()
{
char saneNameBuf[5]{};
char saneNameBuf[MAX_CLAN_NAME_LENGTH]{};
auto* saneName = saneNameBuf;
assert(ClanName);
@ -238,7 +238,7 @@ namespace Components
ClanName = Game::Dvar_RegisterString("clanName", "", Game::DVAR_ARCHIVE, "Your clan abbreviation");
});
std::memset(&ClientState, 0, sizeof(char[Game::MAX_CLIENTS][5]));
std::memset(&ClientState, 0, sizeof(char[Game::MAX_CLIENTS][MAX_CLAN_NAME_LENGTH]));
ServerCommands::OnCommand(22, [](Command::Params* params)
{

View File

@ -5,6 +5,8 @@ namespace Components
class ClanTags : public Component
{
public:
static constexpr std::size_t MAX_CLAN_NAME_LENGTH = 5;
ClanTags();
static const char* GetClanTagWithName(int clientNum, const char* playerName);