[Bots]: Update (#852)
This commit is contained in:
parent
4b8cd96851
commit
73f1f752fd
@ -1,8 +1,6 @@
|
|||||||
#include <STDInclude.hpp>
|
#include <STDInclude.hpp>
|
||||||
#include <Utils/InfoString.hpp>
|
|
||||||
|
|
||||||
#include "Bots.hpp"
|
#include "Bots.hpp"
|
||||||
#include "ServerList.hpp"
|
|
||||||
|
|
||||||
#include "GSC/Script.hpp"
|
#include "GSC/Script.hpp"
|
||||||
|
|
||||||
@ -14,8 +12,6 @@ namespace Components
|
|||||||
{
|
{
|
||||||
std::vector<Bots::botData> Bots::BotNames;
|
std::vector<Bots::botData> Bots::BotNames;
|
||||||
|
|
||||||
Dvar::Var Bots::SVClanName;
|
|
||||||
|
|
||||||
struct BotMovementInfo
|
struct BotMovementInfo
|
||||||
{
|
{
|
||||||
std::int32_t buttons; // Actions
|
std::int32_t buttons; // Actions
|
||||||
@ -52,26 +48,6 @@ namespace Components
|
|||||||
{ "activate", Game::CMD_BUTTON_ACTIVATE },
|
{ "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()
|
void Bots::LoadBotNames()
|
||||||
{
|
{
|
||||||
FileSystem::File bots("bots.txt");
|
FileSystem::File bots("bots.txt");
|
||||||
@ -111,8 +87,6 @@ namespace Components
|
|||||||
|
|
||||||
BotNames.emplace_back(entry, clanAbbrev);
|
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)
|
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;
|
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);
|
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();
|
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
|
// Reset BotMovementInfo.active when client is dropped
|
||||||
Events::OnClientDisconnect([](const int clientNum)
|
Events::OnClientDisconnect([](const int clientNum)
|
||||||
{
|
{
|
||||||
|
@ -11,10 +11,6 @@ namespace Components
|
|||||||
using botData = std::pair< std::string, std::string>;
|
using botData = std::pair< std::string, std::string>;
|
||||||
static std::vector<botData> BotNames;
|
static std::vector<botData> BotNames;
|
||||||
|
|
||||||
static Dvar::Var SVClanName;
|
|
||||||
|
|
||||||
static void RandomizeBotNames();
|
|
||||||
static void UpdateBotNames();
|
|
||||||
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);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user