[General]: Cleanup party component (#809)

This commit is contained in:
Edo 2023-03-05 17:27:29 +00:00 committed by GitHub
parent 6e7556b177
commit be5bdcb9d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 76 additions and 52 deletions

View File

@ -223,7 +223,7 @@ namespace Components
DownloadProgress(&fDownload, bytes - fDownload.receivedBytes); DownloadProgress(&fDownload, bytes - fDownload.receivedBytes);
}); });
bool result = false; auto result = false;
fDownload.buffer = webIO.get(url, &result); fDownload.buffer = webIO.get(url, &result);
if (!result) fDownload.buffer.clear(); if (!result) fDownload.buffer.clear();

View File

@ -12,7 +12,7 @@ namespace Components::GSC
const auto scriptValue = Game::Scr_GetConstString(0); const auto scriptValue = Game::Scr_GetConstString(0);
const auto* string = Game::SL_ConvertToString(scriptValue); const auto* string = Game::SL_ConvertToString(scriptValue);
char out[1024] = {0}; // 1024 is the max for a string in this SL system char out[1024]{}; // 1024 is the max for a string in this SL system
bool changed = false; bool changed = false;
size_t i = 0; size_t i = 0;

View File

@ -349,10 +349,18 @@ namespace Components
{ {
for (int i = 0; i < maxClientCount; ++i) for (int i = 0; i < maxClientCount; ++i)
{ {
if (Game::svs_clients[i].header.state >= Game::CS_CONNECTED) if (Game::svs_clients[i].header.state < Game::CS_ACTIVE) continue;
if (!Game::svs_clients[i].gentity || !Game::svs_clients[i].gentity->client) continue;
const auto* client = Game::svs_clients[i].gentity->client;
const auto team = client->sess.cs.team;
if (Game::svs_clients[i].bIsTestClient || team == Game::TEAM_SPECTATOR)
{ {
if (Game::svs_clients[i].bIsTestClient) ++botCount; ++botCount;
else ++clientCount; }
else
{
++clientCount;
} }
} }
} }
@ -543,7 +551,7 @@ namespace Components
if (clients >= maxClients) if (clients >= maxClients)
{ {
Party::ConnectError("@EXE_SERVERISFULL"); ConnectError("@EXE_SERVERISFULL");
} }
else else
{ {

View File

@ -14,28 +14,25 @@ namespace Components
{ {
ServerInfo::Container ServerInfo::PlayerContainer; ServerInfo::Container ServerInfo::PlayerContainer;
Game::dvar_t** ServerInfo::CGScoreboardHeight;
Game::dvar_t** ServerInfo::CGScoreboardWidth;
unsigned int ServerInfo::GetPlayerCount() unsigned int ServerInfo::GetPlayerCount()
{ {
return ServerInfo::PlayerContainer.playerList.size(); return PlayerContainer.playerList.size();
} }
const char* ServerInfo::GetPlayerText(unsigned int index, int column) const char* ServerInfo::GetPlayerText(unsigned int index, int column)
{ {
if (index < ServerInfo::PlayerContainer.playerList.size()) if (index < PlayerContainer.playerList.size())
{ {
switch (column) switch (column)
{ {
case 0: case 0:
return Utils::String::VA("%d", index); return Utils::String::VA("%d", index);
case 1: case 1:
return ServerInfo::PlayerContainer.playerList[index].name.data(); return PlayerContainer.playerList[index].name.data();
case 2: case 2:
return Utils::String::VA("%d", ServerInfo::PlayerContainer.playerList[index].score); return Utils::String::VA("%d", PlayerContainer.playerList[index].score);
case 3: case 3:
return Utils::String::VA("%d", ServerInfo::PlayerContainer.playerList[index].ping); return Utils::String::VA("%d", PlayerContainer.playerList[index].ping);
default: default:
break; break;
} }
@ -46,13 +43,13 @@ namespace Components
void ServerInfo::SelectPlayer(unsigned int index) void ServerInfo::SelectPlayer(unsigned int index)
{ {
ServerInfo::PlayerContainer.currentPlayer = index; PlayerContainer.currentPlayer = index;
} }
void ServerInfo::ServerStatus([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info) void ServerInfo::ServerStatus([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
{ {
ServerInfo::PlayerContainer.currentPlayer = 0; PlayerContainer.currentPlayer = 0;
ServerInfo::PlayerContainer.playerList.clear(); PlayerContainer.playerList.clear();
auto* serverInfo = ServerList::GetCurrentServer(); auto* serverInfo = ServerList::GetCurrentServer();
@ -78,8 +75,8 @@ namespace Components
Dvar::Var("uiSi_ModName").set(serverInfo->mod.data() + 5); Dvar::Var("uiSi_ModName").set(serverInfo->mod.data() + 5);
} }
ServerInfo::PlayerContainer.target = serverInfo->addr; PlayerContainer.target = serverInfo->addr;
Network::SendCommand(ServerInfo::PlayerContainer.target, "getstatus"); Network::SendCommand(PlayerContainer.target, "getstatus");
} }
} }
@ -90,22 +87,24 @@ namespace Components
auto addressText = Network::Address(*Game::connectedHost).getString(); auto addressText = Network::Address(*Game::connectedHost).getString();
if (addressText == "0.0.0.0:0" || addressText == "loopback") if (addressText == "0.0.0.0:0"s || addressText == "loopback"s)
addressText = "Listen Server"; {
addressText = "Listen Server"s;
}
// Get x positions // Get x positions
auto y = (480.0f - (*ServerInfo::CGScoreboardHeight)->current.value) * 0.5f; auto y = (480.0f - (*Game::cg_scoreboardHeight)->current.value) * 0.5f;
y += (*ServerInfo::CGScoreboardHeight)->current.value + 6.0f; y += (*Game::cg_scoreboardHeight)->current.value + 6.0f;
const auto x = 320.0f - (*ServerInfo::CGScoreboardWidth)->current.value * 0.5f; const auto x = 320.0f - (*Game::cg_scoreboardWidth)->current.value * 0.5f;
const auto x2 = 320.0f + (*ServerInfo::CGScoreboardWidth)->current.value * 0.5f; const auto x2 = 320.0f + (*Game::cg_scoreboardWidth)->current.value * 0.5f;
// Draw only when stream friendly ui is not enabled // Draw only when stream friendly ui is not enabled
if (!Friends::UIStreamFriendly.get<bool>()) if (!Friends::UIStreamFriendly.get<bool>())
{ {
constexpr auto fontSize = 0.35f; constexpr auto fontSize = 0.35f;
Game::UI_DrawText(cxt, reinterpret_cast<const char*>(0x7ED3F8), 0x7FFFFFFF, font, x, y, 0, 0, fontSize, reinterpret_cast<float*>(0x747F34), 3); Game::UI_DrawText(cxt, reinterpret_cast<const char*>(0x7ED3F8), std::numeric_limits<int>::max(), font, x, y, 0, 0, fontSize, reinterpret_cast<float*>(0x747F34), 3);
Game::UI_DrawText(cxt, addressText.data(), 0x7FFFFFFF, font, x2 - Game::UI_TextWidth(addressText.data(), 0, font, fontSize), y, 0, 0, fontSize, reinterpret_cast<float*>(0x747F34), 3); Game::UI_DrawText(cxt, addressText.data(), std::numeric_limits<int>::max(), font, x2 - Game::UI_TextWidth(addressText.data(), 0, font, fontSize), y, 0, 0, fontSize, reinterpret_cast<float*>(0x747F34), 3);
} }
} }
@ -115,7 +114,7 @@ namespace Components
{ {
pushad pushad
push eax push eax
call ServerInfo::DrawScoreboardInfo call DrawScoreboardInfo
pop eax pop eax
popad popad
@ -187,28 +186,25 @@ namespace Components
ServerInfo::ServerInfo() ServerInfo::ServerInfo()
{ {
ServerInfo::PlayerContainer.currentPlayer = 0; PlayerContainer.currentPlayer = 0;
ServerInfo::CGScoreboardHeight = reinterpret_cast<Game::dvar_t**>(0x9FD070);
ServerInfo::CGScoreboardWidth = reinterpret_cast<Game::dvar_t**>(0x9FD0AC);
// Draw IP and hostname on the scoreboard // Draw IP and hostname on the scoreboard
Utils::Hook(0x4FC6EA, ServerInfo::DrawScoreboardStub, HOOK_CALL).install()->quick(); Utils::Hook(0x4FC6EA, DrawScoreboardStub, HOOK_CALL).install()->quick();
// Ignore native getStatus implementation // Ignore native getStatus implementation
Utils::Hook::Nop(0x62654E, 6); Utils::Hook::Nop(0x62654E, 6);
// Add uiscript // Add uiscript
UIScript::Add("ServerStatus", ServerInfo::ServerStatus); UIScript::Add("ServerStatus", ServerStatus);
// Add uifeeder // Add uifeeder
UIFeeder::Add(13.0f, ServerInfo::GetPlayerCount, ServerInfo::GetPlayerText, ServerInfo::SelectPlayer); UIFeeder::Add(13.0f, GetPlayerCount, GetPlayerText, SelectPlayer);
Network::OnClientPacket("getStatus", [](const Network::Address& address, [[maybe_unused]] const std::string& data) Network::OnClientPacket("getStatus", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
{ {
std::string playerList; std::string playerList;
Utils::InfoString info = ServerInfo::GetInfo(); Utils::InfoString info = GetInfo();
info.set("challenge", Utils::ParseChallenge(data)); info.set("challenge", Utils::ParseChallenge(data));
for (std::size_t i = 0; i < Game::MAX_CLIENTS; ++i) for (std::size_t i = 0; i < Game::MAX_CLIENTS; ++i)
@ -219,7 +215,15 @@ namespace Components
if (Dedicated::IsRunning()) if (Dedicated::IsRunning())
{ {
if (Game::svs_clients[i].header.state < Game::CS_CONNECTED) continue; if (Game::svs_clients[i].header.state < Game::CS_ACTIVE) continue;
if (!Game::svs_clients[i].gentity || !Game::svs_clients[i].gentity->client) continue;
const auto* client = Game::svs_clients[i].gentity->client;
const auto team = client->sess.cs.team;
if (team == Game::TEAM_SPECTATOR)
{
continue;
}
score = Game::SV_GameClientNum_Score(static_cast<int>(i)); score = Game::SV_GameClientNum_Score(static_cast<int>(i));
ping = Game::svs_clients[i].ping; ping = Game::svs_clients[i].ping;
@ -242,12 +246,12 @@ namespace Components
Network::OnClientPacket("statusResponse", [](const Network::Address& address, [[maybe_unused]] const std::string& data) Network::OnClientPacket("statusResponse", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
{ {
if (ServerInfo::PlayerContainer.target != address) if (PlayerContainer.target != address)
{ {
return; return;
} }
const Utils::InfoString info(data.substr(0, data.find_first_of("\n"))); const Utils::InfoString info(data.substr(0, data.find_first_of('\n')));
Dvar::Var("uiSi_ServerName").set(info.get("sv_hostname")); Dvar::Var("uiSi_ServerName").set(info.get("sv_hostname"));
Dvar::Var("uiSi_MaxClients").set(info.get("sv_maxclients")); Dvar::Var("uiSi_MaxClients").set(info.get("sv_maxclients"));
@ -281,7 +285,7 @@ namespace Components
if (Utils::String::StartsWith(info.get("fs_game"), "mods/")) if (Utils::String::StartsWith(info.get("fs_game"), "mods/"))
{ {
auto mod = info.get("fs_game"); const auto mod = info.get("fs_game");
Dvar::Var("uiSi_ModName").set(mod.substr(5)); Dvar::Var("uiSi_ModName").set(mod.substr(5));
} }
@ -291,23 +295,23 @@ namespace Components
for (std::size_t i = 1; i < lines.size(); ++i) for (std::size_t i = 1; i < lines.size(); ++i)
{ {
ServerInfo::Container::Player player; Container::Player player;
std::string currentData = lines[i]; std::string currentData = lines[i];
if (currentData.size() < 3) continue; if (currentData.size() < 3) continue;
// Insert score // Insert score
player.score = atoi(currentData.substr(0, currentData.find_first_of(" ")).data()); player.score = atoi(currentData.substr(0, currentData.find_first_of(' ')).data());
// Remove score // Remove score
currentData = currentData.substr(currentData.find_first_of(" ") + 1); currentData = currentData.substr(currentData.find_first_of(' ') + 1);
// Insert ping // Insert ping
player.ping = atoi(currentData.substr(0, currentData.find_first_of(" ")).data()); player.ping = atoi(currentData.substr(0, currentData.find_first_of(' ')).data());
// Remove ping // Remove ping
currentData = currentData.substr(currentData.find_first_of(" ") + 1); currentData = currentData.substr(currentData.find_first_of(' ') + 1);
if (currentData[0] == '\"') if (currentData[0] == '\"')
{ {
@ -321,13 +325,13 @@ namespace Components
player.name = currentData; player.name = currentData;
ServerInfo::PlayerContainer.playerList.push_back(player); PlayerContainer.playerList.push_back(player);
} }
}); });
} }
ServerInfo::~ServerInfo() ServerInfo::~ServerInfo()
{ {
ServerInfo::PlayerContainer.playerList.clear(); PlayerContainer.playerList.clear();
} }
} }

View File

@ -28,9 +28,6 @@ namespace Components
Network::Address target; Network::Address target;
}; };
static Game::dvar_t** CGScoreboardHeight;
static Game::dvar_t** CGScoreboardWidth;
static Container PlayerContainer; static Container PlayerContainer;
static void ServerStatus([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info); static void ServerStatus([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info);

View File

@ -822,7 +822,9 @@ namespace Components
{ {
auto* menu = Game::Menus_FindByName(Game::uiContext, "pc_join_unranked"); auto* menu = Game::Menus_FindByName(Game::uiContext, "pc_join_unranked");
if (!menu) if (!menu)
{
return false; return false;
}
return Game::Menu_IsVisible(Game::uiContext, menu); return Game::Menu_IsVisible(Game::uiContext, menu);
} }

View File

@ -179,7 +179,7 @@ namespace Components
return; return;
} }
const auto index = std::atoi(params->get(1)); const auto index = std::strtol(params->get(1), nullptr, 0);
const auto stat = Game::LiveStorage_GetStat(0, index); const auto stat = Game::LiveStorage_GetStat(0, index);
Logger::Print(Game::CON_CHANNEL_SYSTEM, "Stat {}: {}\n", index, stat); Logger::Print(Game::CON_CHANNEL_SYSTEM, "Stat {}: {}\n", index, stat);
}); });

View File

@ -74,6 +74,8 @@ namespace Game
const dvar_t** cg_chatHeight = reinterpret_cast<const dvar_t**>(0x7ED398); const dvar_t** cg_chatHeight = reinterpret_cast<const dvar_t**>(0x7ED398);
const dvar_t** cg_chatTime = reinterpret_cast<const dvar_t**>(0x9F5DE8); const dvar_t** cg_chatTime = reinterpret_cast<const dvar_t**>(0x9F5DE8);
const dvar_t** cg_scoreboardHeight = reinterpret_cast<const dvar_t**>(0x9FD070);
const dvar_t** cg_scoreboardWidth = reinterpret_cast<const dvar_t**>(0x9FD0AC);
const dvar_t** version = reinterpret_cast<const dvar_t**>(0x1AD7930); const dvar_t** version = reinterpret_cast<const dvar_t**>(0x1AD7930);

View File

@ -126,6 +126,8 @@ namespace Game
extern const dvar_t** cg_chatHeight; extern const dvar_t** cg_chatHeight;
extern const dvar_t** cg_chatTime; extern const dvar_t** cg_chatTime;
extern const dvar_t** cg_scoreboardHeight;
extern const dvar_t** cg_scoreboardWidth;
extern const dvar_t** version; extern const dvar_t** version;

View File

@ -411,6 +411,13 @@ namespace Utils
} }
} }
std::string WebIO::GetCacheBuster()
{
return "?" + std::to_string(
std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::system_clock::now().time_since_epoch()).count());
}
bool WebIO::createDirectory(const std::string& directory) const bool WebIO::createDirectory(const std::string& directory) const
{ {
return (FtpCreateDirectoryA(this->hConnect_, directory.data()) == TRUE); return (FtpCreateDirectoryA(this->hConnect_, directory.data()) == TRUE);

View File

@ -65,6 +65,8 @@ namespace Utils
void setProgressCallback(const Slot<void(std::size_t, std::size_t)>& callback); void setProgressCallback(const Slot<void(std::size_t, std::size_t)>& callback);
void cancelDownload(); void cancelDownload();
static std::string GetCacheBuster();
private: private:
enum Command enum Command
{ {