[Bots]: Update (#852)

This commit is contained in:
Edo 2023-03-18 22:43:24 +00:00 committed by GitHub
parent 4b8cd96851
commit 73f1f752fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 60 deletions

View File

@ -1,8 +1,6 @@
#include <STDInclude.hpp>
#include <Utils/InfoString.hpp>
#include "Bots.hpp"
#include "ServerList.hpp"
#include "GSC/Script.hpp"
@ -14,8 +12,6 @@ namespace Components
{
std::vector<Bots::botData> Bots::BotNames;
Dvar::Var Bots::SVClanName;
struct BotMovementInfo
{
std::int32_t buttons; // Actions
@ -52,26 +48,6 @@ namespace Components
{ "activate", Game::CMD_BUTTON_ACTIVATE },
};
void Bots::RandomizeBotNames()
{
std::random_device rd;
std::mt19937 gen(rd());
std::ranges::shuffle(BotNames, gen);
}
void Bots::UpdateBotNames()
{
const auto masterPort = (*Game::com_masterPort)->current.integer;
const auto* masterServerName = (*Game::com_masterServerName)->current.string;
Game::netadr_t master;
if (ServerList::GetMasterServer(masterServerName, masterPort, master))
{
Logger::Print("Getting bots...\n");
Network::Send(master, "getbots");
}
}
void Bots::LoadBotNames()
{
FileSystem::File bots("bots.txt");
@ -111,8 +87,6 @@ namespace Components
BotNames.emplace_back(entry, clanAbbrev);
}
RandomizeBotNames();
}
int Bots::BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port)
@ -141,11 +115,6 @@ namespace Components
clanName = "BOT"s;
}
if (const auto svClanName = SVClanName.get<std::string>(); !svClanName.empty())
{
clanName = svClanName;
}
return _snprintf_s(buffer, 0x400, _TRUNCATE, connectString, num, botName.data(), clanName.data(), protocol, checksum, statVer, statStuff, port);
}
@ -382,31 +351,6 @@ namespace Components
Utils::Hook(0x441B80, G_SelectWeaponIndex_Hk, HOOK_JUMP).install()->quick();
Events::OnDvarInit([]
{
SVClanName = Dvar::Register<const char*>("sv_clanName", "", Game::DVAR_NONE, "The clan name for test clients");
});
Scheduler::OnGameInitialized(UpdateBotNames, Scheduler::Pipeline::MAIN);
Network::OnClientPacket("getbotsResponse", [](const Network::Address& address, const std::string& data)
{
const auto masterPort = (*Game::com_masterPort)->current.integer;
const auto* masterServerName = (*Game::com_masterServerName)->current.string;
Network::Address master(Utils::String::VA("%s:%u", masterServerName, masterPort));
if (master == address)
{
auto botNames = Utils::String::Split(data, '\n');
for (const auto& entry : botNames)
{
BotNames.emplace_back(std::make_pair(entry, "BOT"));
}
RandomizeBotNames();
}
});
// Reset BotMovementInfo.active when client is dropped
Events::OnClientDisconnect([](const int clientNum)
{

View File

@ -11,10 +11,6 @@ namespace Components
using botData = std::pair< std::string, std::string>;
static std::vector<botData> BotNames;
static Dvar::Var SVClanName;
static void RandomizeBotNames();
static void UpdateBotNames();
static void LoadBotNames();
static int BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port);