Use unicode character set instead and light cleanup/bug fixes

This commit is contained in:
Amos 2022-03-04 12:22:17 +01:00
parent 4a0772bd18
commit 1058a6fa10
12 changed files with 167 additions and 140 deletions

View File

@ -4,6 +4,7 @@
#define WIN32_LEAN_AND_MEAN // Prevent winsock2 redefinition. #define WIN32_LEAN_AND_MEAN // Prevent winsock2 redefinition.
#include <windows.h> #include <windows.h>
#include <WinSock2.h> #include <WinSock2.h>
#include <comdef.h>
#include <stdio.h> #include <stdio.h>
#include <Psapi.h> #include <Psapi.h>

View File

@ -23,19 +23,20 @@ History:
#include "engine/net_chan.h" #include "engine/net_chan.h"
#include "engine/sys_utils.h" #include "engine/sys_utils.h"
#include "engine/host_state.h" #include "engine/host_state.h"
#include "server/server.h"
#include "client/IVEngineClient.h"
#include "networksystem/serverlisting.h" #include "networksystem/serverlisting.h"
#include "networksystem/r5net.h" #include "networksystem/r5net.h"
#include "vpc/keyvalues.h"
#include "squirrel/sqinit.h" #include "squirrel/sqinit.h"
#include "gameui/IBrowser.h"
#include "squirrel/sqapi.h" #include "squirrel/sqapi.h"
#include "server/server.h"
#include "client/IVEngineClient.h"
#include "vpc/keyvalues.h"
#include "vpklib/packedstore.h"
#include "gameui/IBrowser.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: // Purpose:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
IBrowser::IBrowser() IBrowser::IBrowser(void)
{ {
memset(m_chServerConnStringBuffer, 0, sizeof(m_chServerConnStringBuffer)); memset(m_chServerConnStringBuffer, 0, sizeof(m_chServerConnStringBuffer));
@ -73,7 +74,7 @@ IBrowser::IBrowser()
/* Obtain handle to module */ /* Obtain handle to module */
static HGLOBAL rcData = NULL; static HGLOBAL rcData = NULL;
HMODULE handle; HMODULE handle;
GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR)"unnamed", &handle); GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR)"unnamed", &handle);
HRSRC rc = FindResource(handle, MAKEINTRESOURCE(IDB_PNG1), MAKEINTRESOURCE(PNG)); HRSRC rc = FindResource(handle, MAKEINTRESOURCE(IDB_PNG1), MAKEINTRESOURCE(PNG));
/* Obtain assets from 'rsrc' */ /* Obtain assets from 'rsrc' */
if (rc != NULL) if (rc != NULL)
@ -86,7 +87,7 @@ IBrowser::IBrowser()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: // Purpose:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
IBrowser::~IBrowser() IBrowser::~IBrowser(void)
{ {
//delete r5net; //delete r5net;
} }
@ -94,7 +95,7 @@ IBrowser::~IBrowser()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: draws the main browser front-end // Purpose: draws the main browser front-end
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void IBrowser::Draw(const char* title, bool* bDraw) void IBrowser::Draw(const char* pszTitle, bool* bDraw)
{ {
if (!m_bInitialized) if (!m_bInitialized)
{ {
@ -109,7 +110,7 @@ void IBrowser::Draw(const char* title, bool* bDraw)
//ImGui::ShowDemoWindow(); //ImGui::ShowDemoWindow();
} }
if (!ImGui::Begin(title, bDraw)) if (!ImGui::Begin(pszTitle, bDraw))
{ {
ImGui::End(); ImGui::End();
return; return;
@ -124,19 +125,19 @@ void IBrowser::Draw(const char* title, bool* bDraw)
ImGui::SetNextWindowSize(ImVec2(840, 600), ImGuiCond_FirstUseEver); ImGui::SetNextWindowSize(ImVec2(840, 600), ImGuiCond_FirstUseEver);
ImGui::SetWindowPos(ImVec2(-500, 50), ImGuiCond_FirstUseEver); ImGui::SetWindowPos(ImVec2(-500, 50), ImGuiCond_FirstUseEver);
ImGui::Begin(title, NULL, ImGuiWindowFlags_NoScrollbar); ImGui::Begin(pszTitle, NULL, ImGuiWindowFlags_NoScrollbar);
{ {
CompMenu(); CompMenu();
switch (eCurrentSection) switch (eCurrentSection)
{ {
case ESection::SERVER_BROWSER: case eSection::SERVER_BROWSER:
ServerBrowserSection(); ServerBrowserSection();
break; break;
case ESection::HOST_SERVER: case eSection::HOST_SERVER:
HostServerSection(); HostServerSection();
break; break;
case ESection::SETTINGS: case eSection::SETTINGS:
SettingsSection(); SettingsSection();
break; break;
default: default:
@ -149,20 +150,20 @@ void IBrowser::Draw(const char* title, bool* bDraw)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: draws the compmenu // Purpose: draws the compmenu
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void IBrowser::CompMenu() void IBrowser::CompMenu(void)
{ {
ImGui::BeginTabBar("CompMenu"); ImGui::BeginTabBar("CompMenu");
if (ImGui::TabItemButton("Server Browser")) if (ImGui::TabItemButton("Server Browser"))
{ {
SetSection(ESection::SERVER_BROWSER); SetSection(eSection::SERVER_BROWSER);
} }
if (ImGui::TabItemButton("Host Server")) if (ImGui::TabItemButton("Host Server"))
{ {
SetSection(ESection::HOST_SERVER); SetSection(eSection::HOST_SERVER);
} }
if (ImGui::TabItemButton("Settings")) if (ImGui::TabItemButton("Settings"))
{ {
SetSection(ESection::SETTINGS); SetSection(eSection::SETTINGS);
} }
ImGui::EndTabBar(); ImGui::EndTabBar();
} }
@ -170,7 +171,7 @@ void IBrowser::CompMenu()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: draws the server browser section // Purpose: draws the server browser section
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void IBrowser::ServerBrowserSection() void IBrowser::ServerBrowserSection(void)
{ {
ImGui::BeginGroup(); ImGui::BeginGroup();
m_imServerBrowserFilter.Draw(); m_imServerBrowserFilter.Draw();
@ -183,8 +184,8 @@ void IBrowser::ServerBrowserSection()
ImGui::TextColored(ImVec4(1.00f, 0.00f, 0.00f, 1.00f), m_szServerListMessage.c_str()); ImGui::TextColored(ImVec4(1.00f, 0.00f, 0.00f, 1.00f), m_szServerListMessage.c_str());
ImGui::Separator(); ImGui::Separator();
const float FooterHeight = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing(); const float fFooterHeight = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing();
ImGui::BeginChild("ServerListChild", { 0, -FooterHeight }, true, ImGuiWindowFlags_AlwaysVerticalScrollbar); ImGui::BeginChild("ServerListChild", { 0, -fFooterHeight }, true, ImGuiWindowFlags_AlwaysVerticalScrollbar);
if (m_bDefaultTheme) { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{ 8.f, 0.f }); } if (m_bDefaultTheme) { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{ 8.f, 0.f }); }
else { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4.f, 0.f)); } else { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4.f, 0.f)); }
@ -200,32 +201,32 @@ void IBrowser::ServerBrowserSection()
for (ServerListing& server : m_vServerList) for (ServerListing& server : m_vServerList)
{ {
const char* name = server.svServerName.c_str(); const char* pszHostName = server.svServerName.c_str();
const char* map = server.svMapName.c_str(); const char* pszHostMap = server.svMapName.c_str();
const char* port = server.svPort.c_str(); const char* pszHostPort = server.svPort.c_str();
const char* playlist = server.svPlaylist.c_str(); const char* pszPlaylist = server.svPlaylist.c_str();
if (m_imServerBrowserFilter.PassFilter(name) if (m_imServerBrowserFilter.PassFilter(pszHostName)
|| m_imServerBrowserFilter.PassFilter(map) || m_imServerBrowserFilter.PassFilter(pszHostMap)
|| m_imServerBrowserFilter.PassFilter(port)) || m_imServerBrowserFilter.PassFilter(pszHostPort))
{ {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text(name); ImGui::Text(pszHostName);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text(map); ImGui::Text(pszHostMap);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text(port); ImGui::Text(pszHostPort);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text(playlist); ImGui::Text(pszPlaylist);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
std::string selectButtonText = "Connect##"; std::string svConnectBtn = "Connect##";
selectButtonText += (server.svServerName + server.svIpAddress + server.svMapName); svConnectBtn += (server.svServerName + server.svIpAddress + server.svMapName);
if (ImGui::Button(selectButtonText.c_str())) if (ImGui::Button(svConnectBtn.c_str()))
{ {
ConnectToServer(server.svIpAddress, server.svPort, server.svEncryptionKey); ConnectToServer(server.svIpAddress, server.svPort, server.svEncryptionKey);
} }
@ -264,7 +265,7 @@ void IBrowser::ServerBrowserSection()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: refreshes the server browser list with available servers // Purpose: refreshes the server browser list with available servers
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void IBrowser::RefreshServerList() void IBrowser::RefreshServerList(void)
{ {
static bool bThreadLocked = false; static bool bThreadLocked = false;
@ -288,7 +289,7 @@ void IBrowser::RefreshServerList()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: get server list from pylon. // Purpose: get server list from pylon.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void IBrowser::GetServerList() void IBrowser::GetServerList(void)
{ {
m_vServerList.clear(); m_vServerList.clear();
m_szServerListMessage.clear(); m_szServerListMessage.clear();
@ -298,37 +299,37 @@ void IBrowser::GetServerList()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: connects to specified server // Purpose: connects to specified server
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void IBrowser::ConnectToServer(const std::string& ip, const std::string& port, const std::string& encKey) void IBrowser::ConnectToServer(const std::string& svIp, const std::string& svPort, const std::string& svNetKey)
{ {
if (!encKey.empty()) if (!svNetKey.empty())
{ {
ChangeEncryptionKeyTo(encKey); ChangeEncryptionKeyTo(svNetKey);
} }
std::stringstream cmd; std::stringstream cmd;
cmd << "connect " << ip << ":" << port; cmd << "connect " << svIp << ":" << svPort;
ProcessCommand(cmd.str().c_str()); ProcessCommand(cmd.str().c_str());
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: connects to specified server // Purpose: connects to specified server
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void IBrowser::ConnectToServer(const std::string& connString, const std::string& encKey) void IBrowser::ConnectToServer(const std::string& svServer, const std::string& svNetKey)
{ {
if (!encKey.empty()) if (!svNetKey.empty())
{ {
ChangeEncryptionKeyTo(encKey); ChangeEncryptionKeyTo(svNetKey);
} }
std::stringstream cmd; std::stringstream cmd;
cmd << "connect " << connString; cmd << "connect " << svServer;
ProcessCommand(cmd.str().c_str()); ProcessCommand(cmd.str().c_str());
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: Launch server with given parameters // Purpose: Launch server with given parameters
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void IBrowser::LaunchServer() void IBrowser::LaunchServer(void)
{ {
DevMsg(eDLL_T::ENGINE, "Starting Server with name '%s', map '%s' and playlist '%s'\n", m_Server.svServerName.c_str(), m_Server.svMapName.c_str(), m_Server.svPlaylist.c_str()); DevMsg(eDLL_T::ENGINE, "Starting Server with name '%s', map '%s' and playlist '%s'\n", m_Server.svServerName.c_str(), m_Server.svMapName.c_str(), m_Server.svPlaylist.c_str());
@ -352,7 +353,7 @@ void IBrowser::LaunchServer()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: draws the hidden private server modal // Purpose: draws the hidden private server modal
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void IBrowser::HiddenServersModal() void IBrowser::HiddenServersModal(void)
{ {
bool modalOpen = true; bool modalOpen = true;
if (ImGui::BeginPopupModal("Connect to Private Server##HiddenServersConnectModal", &modalOpen)) if (ImGui::BeginPopupModal("Connect to Private Server##HiddenServersConnectModal", &modalOpen))
@ -417,9 +418,9 @@ void IBrowser::HiddenServersModal()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: draws the host section // Purpose: draws the host section
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void IBrowser::HostServerSection() void IBrowser::HostServerSection(void)
{ {
static std::string szServerNameErr = ""; static std::string svServerNameErr = "";
ImGui::InputTextWithHint("##ServerHost_ServerName", "Server Name (Required)", &m_Server.svServerName); ImGui::InputTextWithHint("##ServerHost_ServerName", "Server Name (Required)", &m_Server.svServerName);
ImGui::Spacing(); ImGui::Spacing();
@ -481,7 +482,7 @@ void IBrowser::HostServerSection()
{ {
if (ImGui::Button("Start Server##ServerHost_StartServerButton", ImVec2(ImGui::GetWindowSize().x, 32))) if (ImGui::Button("Start Server##ServerHost_StartServerButton", ImVec2(ImGui::GetWindowSize().x, 32)))
{ {
szServerNameErr.clear(); svServerNameErr.clear();
if (!m_Server.svServerName.empty() && !m_Server.svPlaylist.empty() && !m_Server.svMapName.empty()) if (!m_Server.svServerName.empty() && !m_Server.svPlaylist.empty() && !m_Server.svMapName.empty())
{ {
LaunchServer(); // Launch server. LaunchServer(); // Launch server.
@ -491,15 +492,15 @@ void IBrowser::HostServerSection()
{ {
if (m_Server.svServerName.empty()) if (m_Server.svServerName.empty())
{ {
szServerNameErr = "No Server Name assigned."; svServerNameErr = "No Server Name assigned.";
} }
else if (m_Server.svPlaylist.empty()) else if (m_Server.svPlaylist.empty())
{ {
szServerNameErr = "No Playlist assigned."; svServerNameErr = "No Playlist assigned.";
} }
else if (m_Server.svMapName.empty()) else if (m_Server.svMapName.empty())
{ {
szServerNameErr = "'levelname' was empty."; svServerNameErr = "'levelname' was empty.";
} }
} }
} }
@ -507,7 +508,7 @@ void IBrowser::HostServerSection()
if (ImGui::Button("Force Start##ServerHost_ForceStart", ImVec2(ImGui::GetWindowSize().x, 32))) if (ImGui::Button("Force Start##ServerHost_ForceStart", ImVec2(ImGui::GetWindowSize().x, 32)))
{ {
szServerNameErr.clear(); svServerNameErr.clear();
if (!m_Server.svPlaylist.empty() && !m_Server.svMapName.empty()) if (!m_Server.svPlaylist.empty() && !m_Server.svMapName.empty())
{ {
LaunchServer(); // Launch server. LaunchServer(); // Launch server.
@ -517,16 +518,16 @@ void IBrowser::HostServerSection()
{ {
if (m_Server.svPlaylist.empty()) if (m_Server.svPlaylist.empty())
{ {
szServerNameErr = "No Playlist assigned."; svServerNameErr = "No Playlist assigned.";
} }
else if (m_Server.svMapName.empty()) else if (m_Server.svMapName.empty())
{ {
szServerNameErr = "'levelname' was empty."; svServerNameErr = "'levelname' was empty.";
} }
} }
} }
ImGui::TextColored(ImVec4(1.00f, 0.00f, 0.00f, 1.00f), szServerNameErr.c_str()); ImGui::TextColored(ImVec4(1.00f, 0.00f, 0.00f, 1.00f), svServerNameErr.c_str());
ImGui::TextColored(m_iv4HostRequestMessageColor, m_szHostRequestMessage.c_str()); ImGui::TextColored(m_iv4HostRequestMessageColor, m_szHostRequestMessage.c_str());
if (!m_szHostToken.empty()) if (!m_szHostToken.empty())
{ {
@ -551,7 +552,7 @@ void IBrowser::HostServerSection()
} }
else else
{ {
szServerNameErr = "Failed to change level: 'levelname' was empty."; svServerNameErr = "Failed to change level: 'levelname' was empty.";
} }
} }
@ -574,23 +575,23 @@ void IBrowser::HostServerSection()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: updates the hoster's status // Purpose: updates the hoster's status
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void IBrowser::UpdateHostingStatus() void IBrowser::UpdateHostingStatus(void)
{ {
if (!g_pHostState || !g_pCVar) if (!g_pHostState || !g_pCVar)
{ {
return; return;
} }
eHostingStatus = g_pHostState->m_bActiveGame ? EHostStatus::HOSTING : EHostStatus::NOT_HOSTING; // Are we hosting a server? eHostingStatus = g_pHostState->m_bActiveGame ? eHostStatus::HOSTING : eHostStatus::NOT_HOSTING; // Are we hosting a server?
switch (eHostingStatus) switch (eHostingStatus)
{ {
case EHostStatus::NOT_HOSTING: case eHostStatus::NOT_HOSTING:
{ {
m_szHostRequestMessage.clear(); m_szHostRequestMessage.clear();
m_iv4HostRequestMessageColor = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); m_iv4HostRequestMessageColor = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
break; break;
} }
case EHostStatus::HOSTING: case eHostStatus::HOSTING:
{ {
if (eServerVisibility == EServerVisibility::OFFLINE) if (eServerVisibility == EServerVisibility::OFFLINE)
{ {
@ -626,12 +627,13 @@ void IBrowser::UpdateHostingStatus()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: sends the hosting POST request to the comp server // Purpose: sends the hosting POST request to the comp server
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void IBrowser::SendHostingPostRequest() void IBrowser::SendHostingPostRequest(void)
{ {
m_szHostToken = std::string(); m_szHostToken = std::string();
DevMsg(eDLL_T::CLIENT, "Sending PostServerHost request\n"); DevMsg(eDLL_T::CLIENT, "Sending PostServerHost request\n");
bool result = g_pR5net->PostServerHost(m_szHostRequestMessage, m_szHostToken, bool result = g_pR5net->PostServerHost(m_szHostRequestMessage, m_szHostToken,
ServerListing{ ServerListing
{
m_Server.svServerName, m_Server.svServerName,
std::string(g_pHostState->m_levelName), std::string(g_pHostState->m_levelName),
"", "",
@ -666,9 +668,9 @@ void IBrowser::SendHostingPostRequest()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: executes submitted commands in a separate thread // Purpose: executes submitted commands in a separate thread
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void IBrowser::ProcessCommand(const char* command_line) void IBrowser::ProcessCommand(const char* pszCommand)
{ {
std::thread t(IVEngineClient_CommandExecute, this, command_line); std::thread t(IVEngineClient_CommandExecute, this, pszCommand);
t.detach(); // Detach from render thread. t.detach(); // Detach from render thread.
// This is to avoid a race condition. // This is to avoid a race condition.
@ -678,7 +680,7 @@ void IBrowser::ProcessCommand(const char* command_line)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: draws the settings section // Purpose: draws the settings section
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void IBrowser::SettingsSection() void IBrowser::SettingsSection(void)
{ {
ImGui::InputTextWithHint("Hostname##MatchmakingServerString", "Matchmaking Server String", &m_szMatchmakingHostName); ImGui::InputTextWithHint("Hostname##MatchmakingServerString", "Matchmaking Server String", &m_szMatchmakingHostName);
if (ImGui::Button("Update Hostname")) if (ImGui::Button("Update Hostname"))
@ -700,7 +702,7 @@ void IBrowser::SettingsSection()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: regenerates encryption key // Purpose: regenerates encryption key
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void IBrowser::RegenerateEncryptionKey() void IBrowser::RegenerateEncryptionKey(void) const
{ {
HNET_GenerateKey(); HNET_GenerateKey();
} }
@ -708,15 +710,15 @@ void IBrowser::RegenerateEncryptionKey()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: changes encryption key to specified one // Purpose: changes encryption key to specified one
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void IBrowser::ChangeEncryptionKeyTo(const std::string& str) void IBrowser::ChangeEncryptionKeyTo(const std::string& svNetKey) const
{ {
HNET_SetKey(str); HNET_SetKey(svNetKey);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: sets the browser front-end style // Purpose: sets the browser front-end style
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void IBrowser::SetStyleVar() void IBrowser::SetStyleVar(void)
{ {
ImGuiStyle& style = ImGui::GetStyle(); ImGuiStyle& style = ImGui::GetStyle();
ImVec4* colors = style.Colors; ImVec4* colors = style.Colors;

View File

@ -3,14 +3,14 @@
#include "networksystem/serverlisting.h" #include "networksystem/serverlisting.h"
#include "networksystem/r5net.h" #include "networksystem/r5net.h"
enum class ESection enum class eSection
{ {
SERVER_BROWSER, SERVER_BROWSER,
HOST_SERVER, HOST_SERVER,
SETTINGS SETTINGS
}; };
enum class EHostStatus enum class eHostStatus
{ {
NOT_HOSTING, NOT_HOSTING,
HOSTING HOSTING
@ -33,40 +33,40 @@ public:
// Enum Vars // // Enum Vars //
//////////////////// ////////////////////
ESection eCurrentSection = ESection::SERVER_BROWSER; eSection eCurrentSection = eSection::SERVER_BROWSER;
EHostStatus eHostingStatus = EHostStatus::NOT_HOSTING; eHostStatus eHostingStatus = eHostStatus::NOT_HOSTING;
EServerVisibility eServerVisibility = EServerVisibility::OFFLINE; EServerVisibility eServerVisibility = EServerVisibility::OFFLINE;
public: public:
//////////////////// ////////////////////
// Funcs // // Funcs //
//////////////////// ////////////////////
IBrowser(); IBrowser(void);
~IBrowser(); ~IBrowser(void);
void Draw(const char* title, bool* bDraw); void Draw(const char* pszTitle, bool* bDraw);
void CompMenu(); void CompMenu(void);
void ServerBrowserSection(); void ServerBrowserSection(void);
void RefreshServerList(); void RefreshServerList(void);
void GetServerList(); void GetServerList(void);
void ConnectToServer(const std::string& ip, const std::string& port, const std::string& encKey); void ConnectToServer(const std::string& svIp, const std::string& svPort, const std::string& svNetKey);
void ConnectToServer(const std::string& connString, const std::string& encKey); void ConnectToServer(const std::string& svServer, const std::string& svNetKey);
void HiddenServersModal(); void HiddenServersModal(void);
void HostServerSection(); void HostServerSection(void);
void UpdateHostingStatus(); void UpdateHostingStatus(void);
void SendHostingPostRequest(); void SendHostingPostRequest(void);
void ProcessCommand(const char* command_line); void ProcessCommand(const char* pszCommand);
void LaunchServer(); void LaunchServer(void);
void SettingsSection(); void SettingsSection(void);
void RegenerateEncryptionKey(); void RegenerateEncryptionKey(void) const;
void ChangeEncryptionKeyTo(const std::string& str); void ChangeEncryptionKeyTo(const std::string& svNetKey) const;
void SetStyleVar(); void SetStyleVar(void);
//////////////////// ////////////////////
// Server Browser // // Server Browser //
@ -119,7 +119,7 @@ public:
int m_nLockedIconWidth = 0; int m_nLockedIconWidth = 0;
int m_nLockedIconHeight = 0; int m_nLockedIconHeight = 0;
void SetSection(ESection section) void SetSection(eSection section)
{ {
eCurrentSection = section; eCurrentSection = section;
} }

View File

@ -35,13 +35,18 @@ MODULEINFO GetModuleInfo(const char* szModule)
{ {
MODULEINFO modinfo = { 0 }; MODULEINFO modinfo = { 0 };
HMODULE hModule = GetModuleHandle(szModule); wchar_t szWtext[256]{};
mbstowcs(szWtext, szModule, strlen(szModule) + 1);
HMODULE hModule = GetModuleHandle(szWtext);
if (hModule == INVALID_HANDLE_VALUE) if (hModule == INVALID_HANDLE_VALUE)
{ {
return modinfo; return modinfo;
} }
if (hModule)
GetModuleInformation(GetCurrentProcess(), hModule, &modinfo, sizeof(MODULEINFO)); {
GetModuleInformation(GetCurrentProcess(), hModule, &modinfo, sizeof(MODULEINFO));
}
return modinfo; return modinfo;
} }
@ -129,8 +134,11 @@ void DbgPrint(LPCSTR sFormat, ...)
int length = vsnprintf(sBuffer, sizeof(sBuffer), sFormat, sArgs); int length = vsnprintf(sBuffer, sizeof(sBuffer), sFormat, sArgs);
va_end(sArgs); va_end(sArgs);
wchar_t szWtext[512]{}; // Convert to LPCWSTR.
mbstowcs(szWtext, sBuffer, strlen(sBuffer) + 1);
// Output the string to the debugger. // Output the string to the debugger.
OutputDebugString(sBuffer); OutputDebugString(szWtext);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -643,7 +643,7 @@ _NET_SetKey_f_CompletionFunc
*/ */
void _NET_SetKey_f_CompletionFunc(const CCommand& args) void _NET_SetKey_f_CompletionFunc(const CCommand& args)
{ {
if (args.ArgC() < 2) // Do we atleast have 2 arguments? if (args.ArgC() < 2)
{ {
return; return;
} }

View File

@ -37,7 +37,7 @@ CNetAdr2::CNetAdr2(std::string svInAdr, std::string svInPort)
svInAdr = "127.0.0.1"; svInAdr = "127.0.0.1";
} }
if (strstr(svInAdr.c_str(), "[")) if (strstr(svInAdr.c_str(), "[") || strstr(svInAdr.c_str(), "]"))
{ {
svInAdr = GetBase(svInAdr); svInAdr = GetBase(svInAdr);
} }
@ -256,10 +256,6 @@ std::string CNetAdr2::GetIP(bool bBaseOnly) const
{ {
return "loopback"; return "loopback";
} }
else if (GetType() == netadrtype_t::NA_BROADCAST)
{
return "broadcast";
}
else if (GetType() == netadrtype_t::NA_IP) else if (GetType() == netadrtype_t::NA_IP)
{ {
if (bBaseOnly) if (bBaseOnly)
@ -286,6 +282,10 @@ std::string CNetAdr2::GetPort(void) const
static std::regex rx(".*\\]:"); static std::regex rx(".*\\]:");
svport = std::regex_replace(svport, rx, ""); svport = std::regex_replace(svport, rx, "");
if (!IsValidPort(svport))
{
return "37015";
}
return svport; return svport;
} }
@ -298,6 +298,10 @@ std::string CNetAdr2::GetPort(std::string svInPort) const
static std::regex rx(".*\\]:"); static std::regex rx(".*\\]:");
svInPort = std::regex_replace(svInPort, rx, ""); svInPort = std::regex_replace(svInPort, rx, "");
if (!IsValidPort(svInPort))
{
return "37015";
}
return svInPort; return svInPort;
} }
@ -407,13 +411,7 @@ void CNetAdr2::ToSockadr(sockaddr_storage* pSadr) const
{ {
if (GetVersion() == netadrversion_t::NA_V4) if (GetVersion() == netadrversion_t::NA_V4)
{ {
if (GetType() == netadrtype_t::NA_BROADCAST) if (GetType() == netadrtype_t::NA_IP)
{
reinterpret_cast<sockaddr_in*>(pSadr)->sin_family = AF_INET;
reinterpret_cast<sockaddr_in*>(pSadr)->sin_port = htons(stoi(GetPort()));
reinterpret_cast<sockaddr_in*>(pSadr)->sin_addr.s_addr = INADDR_BROADCAST;
}
else if (GetType() == netadrtype_t::NA_IP)
{ {
reinterpret_cast<sockaddr_in*>(pSadr)->sin_family = AF_INET; reinterpret_cast<sockaddr_in*>(pSadr)->sin_family = AF_INET;
reinterpret_cast<sockaddr_in*>(pSadr)->sin_port = htons(stoi(GetPort())); reinterpret_cast<sockaddr_in*>(pSadr)->sin_port = htons(stoi(GetPort()));
@ -461,11 +459,14 @@ void CNetAdr2::ToAdrinfo(addrinfo* pHint) const
results = getaddrinfo(GetBase().c_str(), GetPort().c_str(), &hint, &pHint); results = getaddrinfo(GetBase().c_str(), GetPort().c_str(), &hint, &pHint);
if (results != 0) if (results != 0)
{ {
WCHAR* wszError = gai_strerror(results);
_bstr_t bStr(wszError);
const char* pszError = bStr;
// TODO: Implement 'Warning(..)' instead! // TODO: Implement 'Warning(..)' instead!
#ifndef NETCONSOLE #ifndef NETCONSOLE
DevMsg(eDLL_T::ENGINE, "Address info translation failed (%s)\n", gai_strerror(results)); DevMsg(eDLL_T::ENGINE, "Address info translation failed (%s)\n", pszError);
#else #else
printf("Address info translation failed (%s)\n", gai_strerror(results)); printf("Address info translation failed (%s)\n", pszError);
#endif // !NETCONSOLE #endif // !NETCONSOLE
} }
} }
@ -479,16 +480,34 @@ void CNetAdr2::ToAdrinfo(addrinfo* pHint) const
results = getaddrinfo(GetBase().c_str(), GetPort().c_str(), &hint, &pHint); results = getaddrinfo(GetBase().c_str(), GetPort().c_str(), &hint, &pHint);
if (results != 0) if (results != 0)
{ {
WCHAR* wszError = gai_strerror(results);
_bstr_t bStr(wszError);
const char* pszError = bStr;
// TODO: Implement 'Warning(..)' instead! // TODO: Implement 'Warning(..)' instead!
#ifndef NETCONSOLE #ifndef NETCONSOLE
DevMsg(eDLL_T::ENGINE, "Address info translation failed (%s)\n", gai_strerror(results)); DevMsg(eDLL_T::ENGINE, "Address info translation failed (%s)\n", pszError);
#else #else
printf("Address info translation failed (%s)\n", gai_strerror(results)); printf("Address info translation failed (%s)\n", pszError);
#endif // !NETCONSOLE #endif // !NETCONSOLE
} }
} }
} }
//-----------------------------------------------------------------------------
// Purpose: returns true if this is a valid port string.
//-----------------------------------------------------------------------------
bool CNetAdr2::IsValidPort(const std::string& svInPort) const
{
for (char const& c : svInPort)
{
if (std::isdigit(c) == 0)
{
return false;
}
}
return true;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: returns true if we are localhost. // Purpose: returns true if we are localhost.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -551,11 +570,6 @@ bool CNetAdr2::CompareAdr(const CNetAdr2& netAdr2, bool bBaseOnly) const
return true; return true;
} }
if (GetType() == netadrtype_t::NA_BROADCAST)
{
return true;
}
if (GetType() == netadrtype_t::NA_IP) if (GetType() == netadrtype_t::NA_IP)
{ {
if (!bBaseOnly && if (!bBaseOnly &&

View File

@ -29,7 +29,6 @@ enum class netadrtype_t
{ {
NA_NULL = 0, NA_NULL = 0,
NA_LOOPBACK, NA_LOOPBACK,
NA_BROADCAST,
NA_IP, NA_IP,
}; };
@ -72,6 +71,7 @@ public:
void ToSockadr(sockaddr_storage* pSadr) const; void ToSockadr(sockaddr_storage* pSadr) const;
void ToAdrinfo(addrinfo* pHint) const; void ToAdrinfo(addrinfo* pHint) const;
bool IsValidPort(const std::string& svInPort) const;
bool IsLocalhost(void) const; bool IsLocalhost(void) const;
bool IsLoopback(void) const; bool IsLoopback(void) const;
bool IsReservedAdr(void) const; bool IsReservedAdr(void) const;

View File

@ -93,9 +93,9 @@ bool CSocketCreator::ConfigureListenSocket(int iSocket)
if (results == -1) if (results == -1)
{ {
#ifndef NETCONSOLE #ifndef NETCONSOLE
DevMsg(eDLL_T::ENGINE, "Socket accept 'ioctl(FIONBIO)' failed (%i)\n", WSAGetLastError()); DevMsg(eDLL_T::ENGINE, "Socket accept 'ioctl(FIONBIO)' failed (%s)\n", NET_ErrorString(WSAGetLastError()));
#else #else
printf("Socket accept 'ioctl(FIONBIO)' failed (%i)\n", WSAGetLastError()); printf("Socket accept 'ioctl(FIONBIO)' failed (%s)\n", NET_ErrorString(WSAGetLastError()));
#endif // !NETCONSOLE #endif // !NETCONSOLE
return false; return false;
} }

View File

@ -1,11 +1,4 @@
#include "core/stdafx.h" /***********************************************************************
#include "tier0/cvar.h"
#include "mathlib/adler32.h"
#include "mathlib/crc32.h"
#include "engine/sys_utils.h"
#include "vpklib/packedstore.h"
/***********************************************************************
* * * *
* * * *
* * * *
@ -14,6 +7,13 @@
* * * *
***********************************************************************/ ***********************************************************************/
#include "core/stdafx.h"
#include "tier0/cvar.h"
#include "mathlib/adler32.h"
#include "mathlib/crc32.h"
#include "engine/sys_utils.h"
#include "vpklib/packedstore.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: initialize parameters for compression algorithm // Purpose: initialize parameters for compression algorithm
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -43,7 +43,7 @@
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc> <UseOfMfc>Static</UseOfMfc>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
@ -51,7 +51,7 @@
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc> <UseOfMfc>Static</UseOfMfc>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
@ -126,7 +126,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<AdditionalOptions>/D DEDICATED %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/D DEDICATED /D _CRT_SECURE_NO_WARNINGS %(AdditionalOptions)</AdditionalOptions>
<PrecompiledHeader>Use</PrecompiledHeader> <PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>core\stdafx.h</PrecompiledHeaderFile> <PrecompiledHeaderFile>core\stdafx.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpp17</LanguageStandard> <LanguageStandard>stdcpp17</LanguageStandard>
@ -155,7 +155,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<AdditionalOptions>/D DEDICATED %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/D DEDICATED /D _CRT_SECURE_NO_WARNINGS %(AdditionalOptions)</AdditionalOptions>
<PrecompiledHeader>Use</PrecompiledHeader> <PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>core\stdafx.h</PrecompiledHeaderFile> <PrecompiledHeaderFile>core\stdafx.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpp17</LanguageStandard> <LanguageStandard>stdcpp17</LanguageStandard>

View File

@ -388,7 +388,7 @@
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc> <UseOfMfc>Static</UseOfMfc>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
@ -396,7 +396,7 @@
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc> <UseOfMfc>Static</UseOfMfc>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
@ -491,6 +491,7 @@
</DisableSpecificWarnings> </DisableSpecificWarnings>
<LanguageStandard>stdcpp17</LanguageStandard> <LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C> <LanguageStandard_C>stdc17</LanguageStandard_C>
<AdditionalOptions>/D _CRT_SECURE_NO_WARNINGS %(AdditionalOptions)</AdditionalOptions>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
@ -530,6 +531,7 @@
<CreateHotpatchableImage> <CreateHotpatchableImage>
</CreateHotpatchableImage> </CreateHotpatchableImage>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalOptions>/D _CRT_SECURE_NO_WARNINGS %(AdditionalOptions)</AdditionalOptions>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>

View File

@ -70,7 +70,7 @@ void Console_Init()
// Create the console window // Create the console window
if (AllocConsole() == FALSE) if (AllocConsole() == FALSE)
{ {
OutputDebugString("Failed to create console window!\n"); OutputDebugStringA("Failed to create console window!\n");
return; return;
} }
@ -87,7 +87,7 @@ void Console_Init()
fclose(sBuildTxt); fclose(sBuildTxt);
} }
} }
SetConsoleTitle(sBuildBuf); SetConsoleTitleA(sBuildBuf);
//-- Open input/output streams //-- Open input/output streams
FILE* fDummy; FILE* fDummy;
@ -117,7 +117,7 @@ void Console_Init()
if (!SetConsoleMode(hOutput, dwMode)) // Some editions of Windows have 'VirtualTerminalLevel' disabled by default. if (!SetConsoleMode(hOutput, dwMode)) // Some editions of Windows have 'VirtualTerminalLevel' disabled by default.
{ {
// Warn the user if 'VirtualTerminalLevel' could not be set on users environment. // Warn the user if 'VirtualTerminalLevel' could not be set on users environment.
MessageBox(NULL, "Failed to set console mode 'VirtualTerminalLevel'.\nPlease omit the '-ansiclr' parameter and restart \nthe game if output logging appears distorted.", "SDK Warning", MB_ICONEXCLAMATION | MB_OK); MessageBoxA(NULL, "Failed to set console mode 'VirtualTerminalLevel'.\nPlease omit the '-ansiclr' parameter and restart \nthe game if output logging appears distorted.", "SDK Warning", MB_ICONEXCLAMATION | MB_OK);
} }
SetConsoleBackgroundColor(0x0000); SetConsoleBackgroundColor(0x0000);
AnsiColors_Init(); AnsiColors_Init();