[General]: Fix dvar name (#927)
This commit is contained in:
parent
f5633770dc
commit
9160436b05
@ -1,6 +1,7 @@
|
|||||||
#include <STDInclude.hpp>
|
#include <STDInclude.hpp>
|
||||||
|
|
||||||
#include "Bots.hpp"
|
#include "Bots.hpp"
|
||||||
|
#include "ClanTags.hpp"
|
||||||
|
|
||||||
#include "GSC/Script.hpp"
|
#include "GSC/Script.hpp"
|
||||||
|
|
||||||
@ -10,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
|
constexpr std::size_t MAX_NAME_LENGTH = 16;
|
||||||
|
|
||||||
std::vector<Bots::botData> Bots::BotNames;
|
std::vector<Bots::botData> Bots::BotNames;
|
||||||
|
|
||||||
Dvar::Var Bots::SVRandomBotNames;
|
Dvar::Var Bots::SVRandomBotNames;
|
||||||
@ -57,6 +60,16 @@ namespace Components
|
|||||||
std::ranges::shuffle(BotNames, gen);
|
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()
|
void Bots::LoadBotNames()
|
||||||
{
|
{
|
||||||
FileSystem::File bots("bots.txt");
|
FileSystem::File bots("bots.txt");
|
||||||
@ -94,6 +107,9 @@ namespace Components
|
|||||||
entry = entry.substr(0, pos);
|
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);
|
BotNames.emplace_back(entry, clanAbbrev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,7 +397,7 @@ namespace Components
|
|||||||
|
|
||||||
Utils::Hook(0x459654, SV_GetClientPing_Hk, HOOK_CALL).install()->quick();
|
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
|
// Reset BotMovementInfo.active when client is dropped
|
||||||
Events::OnClientDisconnect([](const int clientNum) -> void
|
Events::OnClientDisconnect([](const int clientNum) -> void
|
||||||
|
@ -14,6 +14,7 @@ namespace Components
|
|||||||
static Dvar::Var SVRandomBotNames;
|
static Dvar::Var SVRandomBotNames;
|
||||||
|
|
||||||
static void RandomizeBotNames();
|
static void RandomizeBotNames();
|
||||||
|
static std::string TruncBotString(const std::string& input, std::size_t length);
|
||||||
static void LoadBotNames();
|
static void LoadBotNames();
|
||||||
static int BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port);
|
static int BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port);
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ namespace Components
|
|||||||
const Game::dvar_t* ClanTags::ClanName;
|
const Game::dvar_t* ClanTags::ClanName;
|
||||||
|
|
||||||
// bgs_t and clientState_s do not have this
|
// 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)
|
const char* ClanTags::GetClanTagWithName(int clientNum, const char* playerName)
|
||||||
{
|
{
|
||||||
@ -73,7 +73,7 @@ namespace Components
|
|||||||
|
|
||||||
void ClanTags::CL_SanitizeClanName()
|
void ClanTags::CL_SanitizeClanName()
|
||||||
{
|
{
|
||||||
char saneNameBuf[5]{};
|
char saneNameBuf[MAX_CLAN_NAME_LENGTH]{};
|
||||||
auto* saneName = saneNameBuf;
|
auto* saneName = saneNameBuf;
|
||||||
|
|
||||||
assert(ClanName);
|
assert(ClanName);
|
||||||
@ -238,7 +238,7 @@ namespace Components
|
|||||||
ClanName = Game::Dvar_RegisterString("clanName", "", Game::DVAR_ARCHIVE, "Your clan abbreviation");
|
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)
|
ServerCommands::OnCommand(22, [](Command::Params* params)
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,8 @@ namespace Components
|
|||||||
class ClanTags : public Component
|
class ClanTags : public Component
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static constexpr std::size_t MAX_CLAN_NAME_LENGTH = 5;
|
||||||
|
|
||||||
ClanTags();
|
ClanTags();
|
||||||
|
|
||||||
static const char* GetClanTagWithName(int clientNum, const char* playerName);
|
static const char* GetClanTagWithName(int clientNum, const char* playerName);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user