2022-01-12 02:53:07 +01:00
|
|
|
/******************************************************************************
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
File : IBrowser.cpp
|
|
|
|
Date : 09:06:2021
|
|
|
|
Author : Sal
|
|
|
|
Purpose: Implements the in-game server browser front-end
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
History:
|
|
|
|
- 09:06:2021 21:07 : Created by Sal
|
|
|
|
- 25:07:2021 14:26 : Implement private servers connect dialog and password field
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
#include "core/stdafx.h"
|
|
|
|
#include "core/init.h"
|
|
|
|
#include "core/resource.h"
|
2022-08-27 18:57:56 +02:00
|
|
|
#include "tier0/fasttimer.h"
|
2022-08-19 21:33:31 +02:00
|
|
|
#include "tier0/frametask.h"
|
2022-01-18 11:23:14 +01:00
|
|
|
#include "tier0/commandline.h"
|
2021-12-25 22:36:38 +01:00
|
|
|
#include "windows/id3dx.h"
|
|
|
|
#include "windows/console.h"
|
2022-04-26 20:24:51 +02:00
|
|
|
#include "windows/resource.h"
|
2022-04-02 02:48:54 +02:00
|
|
|
#include "engine/net.h"
|
2023-05-10 00:05:38 +02:00
|
|
|
#include "engine/cmd.h"
|
2022-05-27 02:08:51 +02:00
|
|
|
#include "engine/cmodel_bsp.h"
|
2021-12-25 22:36:38 +01:00
|
|
|
#include "engine/host_state.h"
|
2022-05-20 20:14:39 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-05-20 11:52:19 +02:00
|
|
|
#include "engine/server/server.h"
|
2022-05-20 20:14:39 +02:00
|
|
|
#endif // CLIENT_DLL
|
2022-11-23 12:30:15 +01:00
|
|
|
#include "engine/client/clientstate.h"
|
2021-12-25 22:36:38 +01:00
|
|
|
#include "networksystem/serverlisting.h"
|
2022-07-01 10:29:27 +02:00
|
|
|
#include "networksystem/pylon.h"
|
2022-08-14 15:45:08 +02:00
|
|
|
#include "networksystem/listmanager.h"
|
2022-03-04 12:22:17 +01:00
|
|
|
#include "vpc/keyvalues.h"
|
2023-05-10 00:05:38 +02:00
|
|
|
#include "common/callback.h"
|
2022-03-04 12:22:17 +01:00
|
|
|
#include "gameui/IBrowser.h"
|
2022-08-09 17:18:07 +02:00
|
|
|
#include "public/edict.h"
|
2023-05-06 16:23:56 +02:00
|
|
|
#include "game/shared/vscript_shared.h"
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-05-27 02:44:36 +02:00
|
|
|
CBrowser::CBrowser(void)
|
2022-10-21 21:28:51 +02:00
|
|
|
: m_pszBrowserLabel("Server Browser")
|
|
|
|
, m_bActivate(false)
|
|
|
|
, m_bInitialized(false)
|
|
|
|
, m_bReclaimFocus(false)
|
2023-02-04 20:04:23 +01:00
|
|
|
, m_bReclaimFocusTokenField(false)
|
2022-10-21 21:28:51 +02:00
|
|
|
, m_bQueryListNonRecursive(false)
|
2023-01-26 21:20:11 +01:00
|
|
|
, m_bQueryGlobalBanList(true)
|
2022-10-21 21:28:51 +02:00
|
|
|
, m_flFadeAlpha(0.f)
|
|
|
|
, m_HostRequestMessageColor(1.00f, 1.00f, 1.00f, 1.00f)
|
|
|
|
, m_ivHiddenServerMessageColor(0.00f, 1.00f, 0.00f, 1.00f)
|
|
|
|
, m_Style(ImGuiStyle_t::NONE)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-05-27 02:39:08 +02:00
|
|
|
memset(m_szServerAddressBuffer, '\0', sizeof(m_szServerAddressBuffer));
|
2022-10-21 21:28:51 +02:00
|
|
|
memset(m_szServerEncKeyBuffer, '\0', sizeof(m_szServerEncKeyBuffer));
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-04-26 20:24:51 +02:00
|
|
|
m_rLockedIconBlob = GetModuleResource(IDB_PNG2);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-05-27 02:44:36 +02:00
|
|
|
CBrowser::~CBrowser(void)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-04-23 20:34:36 +02:00
|
|
|
if (m_idLockedIcon)
|
|
|
|
{
|
|
|
|
m_idLockedIcon->Release();
|
|
|
|
}
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
2022-08-14 15:45:08 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool CBrowser::Init(void)
|
|
|
|
{
|
|
|
|
SetStyleVar();
|
|
|
|
m_szMatchmakingHostName = pylon_matchmaking_hostname->GetString();
|
|
|
|
|
2023-05-15 09:54:18 +02:00
|
|
|
bool ret = LoadTextureBuffer(reinterpret_cast<unsigned char*>(m_rLockedIconBlob.m_pData), int(m_rLockedIconBlob.m_nSize),
|
|
|
|
&m_idLockedIcon, &m_rLockedIconBlob.m_nWidth, &m_rLockedIconBlob.m_nHeight);
|
|
|
|
|
|
|
|
IM_ASSERT(ret && m_idLockedIcon);
|
|
|
|
return ret;
|
2022-08-14 15:45:08 +02:00
|
|
|
}
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-01-12 02:53:07 +01:00
|
|
|
// Purpose: draws the main browser front-end
|
2021-12-25 22:36:38 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-08-14 15:45:08 +02:00
|
|
|
void CBrowser::RunFrame(void)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-10-20 12:29:21 +02:00
|
|
|
// Uncomment these when adjusting the theme or layout.
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-10-20 12:29:21 +02:00
|
|
|
//ImGui::ShowStyleEditor();
|
|
|
|
//ImGui::ShowDemoWindow();
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
2022-10-20 12:29:21 +02:00
|
|
|
if (!m_bInitialized)
|
2022-01-28 12:56:51 +01:00
|
|
|
{
|
2022-10-20 12:29:21 +02:00
|
|
|
Init();
|
|
|
|
m_bInitialized = true;
|
2022-01-28 12:56:51 +01:00
|
|
|
}
|
|
|
|
|
2022-06-09 02:22:01 +02:00
|
|
|
int nVars = 0;
|
2023-02-04 01:03:18 +01:00
|
|
|
float flWidth;
|
|
|
|
float flHeight;
|
2022-08-22 01:10:18 +02:00
|
|
|
if (m_Style == ImGuiStyle_t::MODERN)
|
|
|
|
{
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 8.f, 10.f }); nVars++;
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_flFadeAlpha); nVars++;
|
2023-02-04 01:03:18 +01:00
|
|
|
|
|
|
|
flWidth = 621.f;
|
|
|
|
flHeight = 532.f;
|
2022-08-22 01:10:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-02-04 01:03:18 +01:00
|
|
|
if (m_Style == ImGuiStyle_t::LEGACY)
|
|
|
|
{
|
|
|
|
flWidth = 619.f;
|
|
|
|
flHeight = 526.f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flWidth = 618.f;
|
|
|
|
flHeight = 524.f;
|
|
|
|
}
|
|
|
|
|
2022-08-22 01:10:18 +02:00
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 6.f, 6.f }); nVars++;
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_flFadeAlpha); nVars++;
|
2022-06-24 12:22:04 +02:00
|
|
|
|
2022-06-24 12:45:47 +02:00
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 1.0f); nVars++;
|
|
|
|
}
|
2023-02-04 01:03:18 +01:00
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(flWidth, flHeight)); nVars++;
|
2022-06-24 12:45:47 +02:00
|
|
|
|
2022-10-20 14:23:14 +02:00
|
|
|
if (m_bActivate && m_bReclaimFocus) // Reclaim focus on window apparition.
|
|
|
|
{
|
|
|
|
ImGui::SetNextWindowFocus();
|
|
|
|
m_bReclaimFocus = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ImGui::Begin(m_pszBrowserLabel, &m_bActivate, ImGuiWindowFlags_NoScrollbar, &ResetInput))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-01-12 02:53:07 +01:00
|
|
|
ImGui::End();
|
2022-06-09 02:22:01 +02:00
|
|
|
ImGui::PopStyleVar(nVars);
|
2022-01-12 02:53:07 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-08-14 15:45:08 +02:00
|
|
|
|
2022-10-20 14:37:21 +02:00
|
|
|
DrawSurface();
|
2023-01-29 19:30:37 +01:00
|
|
|
|
2022-01-12 02:53:07 +01:00
|
|
|
ImGui::End();
|
2023-01-29 19:30:37 +01:00
|
|
|
ImGui::PopStyleVar(nVars);
|
2022-06-09 02:22:01 +02:00
|
|
|
}
|
|
|
|
|
2022-08-27 18:57:56 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: runs tasks for the browser while not being drawn
|
|
|
|
// (!!! RunTask and RunFrame must be called from the same thread !!!)
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CBrowser::RunTask()
|
|
|
|
{
|
|
|
|
static bool bInitialized = false;
|
|
|
|
static CFastTimer timer;
|
|
|
|
|
|
|
|
if (!bInitialized)
|
|
|
|
{
|
|
|
|
timer.Start();
|
|
|
|
bInitialized = true;
|
|
|
|
}
|
|
|
|
|
2023-09-04 09:49:15 +02:00
|
|
|
if (timer.GetDurationInProgress().GetSeconds() > pylon_host_update_interval->GetFloat())
|
2022-08-27 18:57:56 +02:00
|
|
|
{
|
|
|
|
UpdateHostingStatus();
|
|
|
|
timer.Start();
|
|
|
|
}
|
2022-09-14 02:39:55 +02:00
|
|
|
|
|
|
|
if (m_bActivate)
|
|
|
|
{
|
|
|
|
if (m_bQueryListNonRecursive)
|
|
|
|
{
|
|
|
|
std::thread refresh(&CBrowser::RefreshServerList, g_pBrowser);
|
|
|
|
refresh.detach();
|
|
|
|
|
|
|
|
m_bQueryListNonRecursive = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // Refresh server list the next time 'm_bActivate' evaluates to true.
|
|
|
|
{
|
2022-10-20 14:23:14 +02:00
|
|
|
m_bReclaimFocus = true;
|
2023-02-04 20:04:23 +01:00
|
|
|
m_bReclaimFocusTokenField = true;
|
|
|
|
m_bQueryListNonRecursive = true;
|
2022-09-14 02:39:55 +02:00
|
|
|
}
|
2022-08-27 18:57:56 +02:00
|
|
|
}
|
|
|
|
|
2022-06-09 02:22:01 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-08-21 19:35:06 +02:00
|
|
|
// Purpose: think
|
2022-06-09 02:22:01 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CBrowser::Think(void)
|
|
|
|
{
|
2022-08-29 02:21:32 +02:00
|
|
|
if (m_bActivate)
|
2022-06-09 02:22:01 +02:00
|
|
|
{
|
2023-04-16 02:45:22 +02:00
|
|
|
if (m_flFadeAlpha < 1.f)
|
2022-06-09 02:22:01 +02:00
|
|
|
{
|
2023-04-16 02:45:22 +02:00
|
|
|
m_flFadeAlpha += .05f;
|
|
|
|
m_flFadeAlpha = (std::min)(m_flFadeAlpha, 1.f);
|
2022-06-09 02:22:01 +02:00
|
|
|
}
|
2022-08-29 02:21:32 +02:00
|
|
|
}
|
|
|
|
else // Reset to full transparent.
|
|
|
|
{
|
2023-04-16 02:45:22 +02:00
|
|
|
if (m_flFadeAlpha > 0.f)
|
|
|
|
{
|
|
|
|
m_flFadeAlpha -= .05f;
|
|
|
|
m_flFadeAlpha = (std::max)(m_flFadeAlpha, 0.f);
|
|
|
|
}
|
2022-06-09 02:22:01 +02:00
|
|
|
}
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: draws the compmenu
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-08-14 15:45:08 +02:00
|
|
|
void CBrowser::DrawSurface(void)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-08-27 18:57:56 +02:00
|
|
|
std::lock_guard<std::mutex> l(m_Mutex);
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
ImGui::BeginTabBar("CompMenu");
|
2022-06-27 16:54:40 +02:00
|
|
|
if (ImGui::BeginTabItem("Browsing"))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-06-27 15:01:39 +02:00
|
|
|
BrowserPanel();
|
|
|
|
ImGui::EndTabItem();
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2022-03-27 22:17:30 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-06-27 16:54:40 +02:00
|
|
|
if (ImGui::BeginTabItem("Hosting"))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-06-27 15:01:39 +02:00
|
|
|
HostPanel();
|
|
|
|
ImGui::EndTabItem();
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2022-03-27 22:17:30 +02:00
|
|
|
#endif // !CLIENT_DLL
|
2022-06-27 15:01:39 +02:00
|
|
|
if (ImGui::BeginTabItem("Settings"))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-06-27 15:01:39 +02:00
|
|
|
SettingsPanel();
|
|
|
|
ImGui::EndTabItem();
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
ImGui::EndTabBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: draws the server browser section
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-06-27 15:01:39 +02:00
|
|
|
void CBrowser::BrowserPanel(void)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
|
|
|
ImGui::BeginGroup();
|
|
|
|
m_imServerBrowserFilter.Draw();
|
|
|
|
ImGui::SameLine();
|
2022-10-20 14:23:14 +02:00
|
|
|
|
2023-01-28 14:20:57 +01:00
|
|
|
if (ImGui::Button("Refresh"))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-08-27 18:57:56 +02:00
|
|
|
m_svServerListMessage.clear();
|
|
|
|
|
|
|
|
std::thread refresh(&CBrowser::RefreshServerList, this);
|
|
|
|
refresh.detach();
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2022-10-20 14:23:14 +02:00
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
ImGui::EndGroup();
|
2023-04-08 19:10:59 +02:00
|
|
|
ImGui::TextColored(ImVec4(1.00f, 0.00f, 0.00f, 1.00f), "%s", m_svServerListMessage.c_str());
|
2021-12-25 22:36:38 +01:00
|
|
|
ImGui::Separator();
|
|
|
|
|
2023-01-30 01:18:51 +01:00
|
|
|
int iVars = 0; // Eliminate borders around server list table.
|
2023-02-04 01:03:18 +01:00
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 1.f, 0.f }); iVars++;
|
2023-01-30 01:18:51 +01:00
|
|
|
|
2022-03-04 12:22:17 +01:00
|
|
|
const float fFooterHeight = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing();
|
2022-05-08 16:20:48 +02:00
|
|
|
ImGui::BeginChild("##ServerBrowser_ServerList", { 0, -fFooterHeight }, true, ImGuiWindowFlags_AlwaysVerticalScrollbar);
|
2022-01-22 15:51:09 +01:00
|
|
|
|
2022-07-01 02:20:47 +02:00
|
|
|
if (ImGui::BeginTable("##ServerBrowser_ServerListTable", 6, ImGuiTableFlags_Resizable))
|
2022-06-09 02:22:01 +02:00
|
|
|
{
|
2022-07-01 02:20:47 +02:00
|
|
|
int nVars = 0;
|
2022-08-22 01:10:18 +02:00
|
|
|
if (m_Style == ImGuiStyle_t::MODERN)
|
2022-07-01 02:20:47 +02:00
|
|
|
{
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{ 8.f, 0.f }); nVars++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-22 01:10:18 +02:00
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{ 4.f, 0.f }); nVars++;
|
2022-07-01 02:20:47 +02:00
|
|
|
}
|
2022-01-28 12:56:51 +01:00
|
|
|
|
2022-01-22 15:51:09 +01:00
|
|
|
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch, 25);
|
|
|
|
ImGui::TableSetupColumn("Map", ImGuiTableColumnFlags_WidthStretch, 20);
|
|
|
|
ImGui::TableSetupColumn("Playlist", ImGuiTableColumnFlags_WidthStretch, 10);
|
2022-06-27 16:54:40 +02:00
|
|
|
ImGui::TableSetupColumn("Players", ImGuiTableColumnFlags_WidthStretch, 5);
|
|
|
|
ImGui::TableSetupColumn("Port", ImGuiTableColumnFlags_WidthStretch, 5);
|
2022-07-01 02:20:47 +02:00
|
|
|
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthStretch, 5);
|
2021-12-25 22:36:38 +01:00
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
2022-08-27 18:57:56 +02:00
|
|
|
g_pServerListManager->m_Mutex.lock();
|
|
|
|
for (const NetGameServer_t& server : g_pServerListManager->m_vServerList)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-06-28 00:47:01 +02:00
|
|
|
const char* pszHostName = server.m_svHostName.c_str();
|
2022-08-27 18:57:56 +02:00
|
|
|
const char* pszHostMap = server.m_svHostMap.c_str();
|
2022-06-28 00:47:01 +02:00
|
|
|
const char* pszPlaylist = server.m_svPlaylist.c_str();
|
2023-10-15 10:47:19 +02:00
|
|
|
|
|
|
|
char pszHostPort[32];
|
|
|
|
sprintf(pszHostPort, "%d", server.m_nGamePort);
|
2022-03-04 12:22:17 +01:00
|
|
|
|
|
|
|
if (m_imServerBrowserFilter.PassFilter(pszHostName)
|
|
|
|
|| m_imServerBrowserFilter.PassFilter(pszHostMap)
|
|
|
|
|| m_imServerBrowserFilter.PassFilter(pszHostPort))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
|
|
|
ImGui::TableNextColumn();
|
2023-04-08 19:10:59 +02:00
|
|
|
ImGui::Text("%s", pszHostName);
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
2023-04-08 19:10:59 +02:00
|
|
|
ImGui::Text("%s", pszHostMap);
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-06-27 16:54:40 +02:00
|
|
|
ImGui::TableNextColumn();
|
2023-04-08 19:10:59 +02:00
|
|
|
ImGui::Text("%s", pszPlaylist);
|
2022-06-27 16:54:40 +02:00
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
ImGui::TableNextColumn();
|
2023-10-15 10:47:19 +02:00
|
|
|
ImGui::Text("%s", Format("%3d/%3d", server.m_nPlayerCount, server.m_nMaxPlayers).c_str());
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
2023-04-08 19:10:59 +02:00
|
|
|
ImGui::Text("%s", pszHostPort);
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
2022-05-27 02:39:08 +02:00
|
|
|
string svConnectBtn = "Connect##";
|
2022-08-27 18:57:56 +02:00
|
|
|
svConnectBtn.append(server.m_svHostName + server.m_svIpAddress + server.m_svHostMap);
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-03-04 12:22:17 +01:00
|
|
|
if (ImGui::Button(svConnectBtn.c_str()))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-10-15 10:47:19 +02:00
|
|
|
g_pServerListManager->ConnectToServer(server.m_svIpAddress, server.m_nGamePort, server.m_svEncryptionKey);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-27 18:57:56 +02:00
|
|
|
g_pServerListManager->m_Mutex.unlock();
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
ImGui::EndTable();
|
2022-07-01 02:20:47 +02:00
|
|
|
ImGui::PopStyleVar(nVars);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2022-07-01 02:20:47 +02:00
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
ImGui::EndChild();
|
2023-01-30 01:18:51 +01:00
|
|
|
ImGui::PopStyleVar(iVars);
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::PushItemWidth(ImGui::GetWindowContentRegionWidth() / 4);
|
|
|
|
{
|
2023-04-30 02:08:40 +02:00
|
|
|
ImGui::InputTextWithHint("##ServerBrowser_ServerCon", "Server address and port", m_szServerAddressBuffer, IM_ARRAYSIZE(m_szServerAddressBuffer));
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
ImGui::SameLine();
|
2023-04-30 02:08:40 +02:00
|
|
|
ImGui::InputTextWithHint("##ServerBrowser_ServerKey", "Encryption key", m_szServerEncKeyBuffer, IM_ARRAYSIZE(m_szServerEncKeyBuffer));
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
ImGui::SameLine();
|
2022-08-14 18:35:01 +02:00
|
|
|
if (ImGui::Button("Connect", ImVec2(ImGui::GetWindowContentRegionWidth() / 4.3f, ImGui::GetFrameHeight())))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-04-30 02:08:40 +02:00
|
|
|
if (m_szServerAddressBuffer[0])
|
|
|
|
{
|
|
|
|
g_pServerListManager->ConnectToServer(m_szServerAddressBuffer, m_szServerEncKeyBuffer);
|
|
|
|
}
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
2023-01-28 14:20:57 +01:00
|
|
|
if (ImGui::Button("Private servers", ImVec2(ImGui::GetWindowContentRegionWidth() / 4.3f, ImGui::GetFrameHeight())))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-08-31 15:45:12 +02:00
|
|
|
ImGui::OpenPopup("Private Server");
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
HiddenServersModal();
|
|
|
|
}
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
2022-01-12 02:53:07 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: refreshes the server browser list with available servers
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-05-27 02:44:36 +02:00
|
|
|
void CBrowser::RefreshServerList(void)
|
2022-01-12 02:53:07 +01:00
|
|
|
{
|
2023-08-21 19:12:29 +02:00
|
|
|
Msg(eDLL_T::CLIENT, "Refreshing server list with matchmaking host '%s'\n", pylon_matchmaking_hostname->GetString());
|
2023-07-22 21:14:04 +02:00
|
|
|
|
2022-08-27 18:57:56 +02:00
|
|
|
std::string svServerListMessage;
|
|
|
|
g_pServerListManager->RefreshServerList(svServerListMessage);
|
2022-01-12 02:53:07 +01:00
|
|
|
|
2022-08-27 18:57:56 +02:00
|
|
|
std::lock_guard<std::mutex> l(m_Mutex);
|
|
|
|
m_svServerListMessage = svServerListMessage;
|
2022-01-12 02:53:07 +01:00
|
|
|
}
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: draws the hidden private server modal
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-05-27 02:44:36 +02:00
|
|
|
void CBrowser::HiddenServersModal(void)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-01-30 01:18:51 +01:00
|
|
|
float flHeight; // Set the padding accordingly for each theme.
|
|
|
|
switch (m_Style)
|
|
|
|
{
|
|
|
|
case ImGuiStyle_t::LEGACY:
|
|
|
|
flHeight = 207.f;
|
|
|
|
break;
|
|
|
|
case ImGuiStyle_t::MODERN:
|
|
|
|
flHeight = 214.f;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
flHeight = 206.f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int nVars = 0;
|
2022-08-31 21:49:28 +02:00
|
|
|
bool bModalOpen = true;
|
2023-01-30 01:18:51 +01:00
|
|
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(408.f, flHeight)); nVars++;
|
|
|
|
|
2022-08-31 21:49:28 +02:00
|
|
|
if (ImGui::BeginPopupModal("Private Server", &bModalOpen, ImGuiWindowFlags_NoResize))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-01-30 01:18:51 +01:00
|
|
|
ImGui::SetWindowSize(ImVec2(408.f, flHeight), ImGuiCond_Always);
|
2021-12-25 22:36:38 +01:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.00f, 0.00f, 0.00f, 0.00f)); // Override the style color for child bg.
|
|
|
|
|
2023-04-02 00:59:24 +02:00
|
|
|
ImGui::BeginChild("##HiddenServersConnectModal_IconParent", ImVec2(float(m_rLockedIconBlob.m_nWidth), float(m_rLockedIconBlob.m_nHeight)));
|
|
|
|
ImGui::Image(m_idLockedIcon, ImVec2(float(m_rLockedIconBlob.m_nWidth), float(m_rLockedIconBlob.m_nHeight))); // Display texture.
|
2021-12-25 22:36:38 +01:00
|
|
|
ImGui::EndChild();
|
|
|
|
|
|
|
|
ImGui::PopStyleColor(); // Pop the override for the child bg.
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
2022-08-29 14:00:54 +02:00
|
|
|
ImGui::Text("Enter token to connect");
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
ImGui::PushItemWidth(ImGui::GetWindowContentRegionWidth()); // Override item width.
|
2023-01-28 14:20:57 +01:00
|
|
|
ImGui::InputTextWithHint("##HiddenServersConnectModal_TokenInput", "Token (required)", &m_svHiddenServerToken);
|
2021-12-25 22:36:38 +01:00
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
2023-02-04 20:04:23 +01:00
|
|
|
if (m_bReclaimFocusTokenField)
|
|
|
|
{
|
|
|
|
ImGui::SetKeyboardFocusHere(-1); // -1 means previous widget.
|
|
|
|
m_bReclaimFocusTokenField = false;
|
|
|
|
}
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
ImGui::Dummy(ImVec2(ImGui::GetWindowContentRegionWidth(), 19.f)); // Place a dummy, basically making space inserting a blank element.
|
|
|
|
|
2023-04-08 19:10:59 +02:00
|
|
|
ImGui::TextColored(m_ivHiddenServerMessageColor, "%s", m_svHiddenServerRequestMessage.c_str());
|
2021-12-25 22:36:38 +01:00
|
|
|
ImGui::Separator();
|
|
|
|
|
2022-08-31 15:45:12 +02:00
|
|
|
if (ImGui::Button("Connect", ImVec2(ImGui::GetWindowContentRegionWidth(), 24)))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-05-27 02:39:08 +02:00
|
|
|
m_svHiddenServerRequestMessage.clear();
|
2023-02-04 20:04:23 +01:00
|
|
|
m_bReclaimFocusTokenField = true;
|
|
|
|
|
2022-08-31 17:23:23 +02:00
|
|
|
if (!m_svHiddenServerToken.empty())
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-08-31 17:23:23 +02:00
|
|
|
NetGameServer_t server;
|
|
|
|
bool result = g_pMasterServer->GetServerByToken(server, m_svHiddenServerRequestMessage, m_svHiddenServerToken); // Send token connect request.
|
|
|
|
|
2023-04-02 17:14:29 +02:00
|
|
|
if (result && !server.m_svHostName.empty())
|
2022-08-31 17:23:23 +02:00
|
|
|
{
|
2023-10-15 10:47:19 +02:00
|
|
|
g_pServerListManager->ConnectToServer(server.m_svIpAddress, server.m_nGamePort, server.m_svEncryptionKey); // Connect to the server
|
2023-04-08 10:50:32 +02:00
|
|
|
m_svHiddenServerRequestMessage = Format("Found server: %s", server.m_svHostName.c_str());
|
2022-08-31 17:23:23 +02:00
|
|
|
m_ivHiddenServerMessageColor = ImVec4(0.00f, 1.00f, 0.00f, 1.00f);
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-04-02 17:14:29 +02:00
|
|
|
if (m_svHiddenServerRequestMessage.empty())
|
|
|
|
{
|
|
|
|
m_svHiddenServerRequestMessage = "Unknown error.";
|
|
|
|
}
|
|
|
|
else // Display error message.
|
|
|
|
{
|
2023-04-08 10:50:32 +02:00
|
|
|
m_svHiddenServerRequestMessage = Format("Error: %s", m_svHiddenServerRequestMessage.c_str());
|
2023-04-02 17:14:29 +02:00
|
|
|
}
|
2022-08-31 17:23:23 +02:00
|
|
|
m_ivHiddenServerMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
|
|
|
|
}
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-28 14:20:57 +01:00
|
|
|
m_svHiddenServerRequestMessage = "Token is required.";
|
2021-12-25 22:36:38 +01:00
|
|
|
m_ivHiddenServerMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
|
|
|
|
}
|
|
|
|
}
|
2022-08-31 15:45:12 +02:00
|
|
|
if (ImGui::Button("Close", ImVec2(ImGui::GetWindowContentRegionWidth(), 24)))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-08-31 21:49:28 +02:00
|
|
|
m_svHiddenServerRequestMessage.clear();
|
2023-02-04 20:04:23 +01:00
|
|
|
m_bReclaimFocusTokenField = true;
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
2023-01-30 01:18:51 +01:00
|
|
|
ImGui::PopStyleVar(nVars);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2022-08-31 21:49:28 +02:00
|
|
|
else if (!bModalOpen)
|
|
|
|
{
|
|
|
|
m_svHiddenServerRequestMessage.clear();
|
2023-02-04 20:04:23 +01:00
|
|
|
m_bReclaimFocusTokenField = true;
|
|
|
|
|
2023-01-30 01:18:51 +01:00
|
|
|
ImGui::PopStyleVar(nVars);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ImGui::PopStyleVar(nVars);
|
2022-08-31 21:49:28 +02:00
|
|
|
}
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: draws the host section
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-06-27 15:01:39 +02:00
|
|
|
void CBrowser::HostPanel(void)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-03-27 22:17:30 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-08-27 18:57:56 +02:00
|
|
|
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2023-01-28 14:20:57 +01:00
|
|
|
ImGui::InputTextWithHint("##ServerHost_ServerName", "Server name (required)", &g_pServerListManager->m_Server.m_svHostName);
|
|
|
|
ImGui::InputTextWithHint("##ServerHost_ServerDesc", "Server description (optional)", &g_pServerListManager->m_Server.m_svDescription);
|
2021-12-25 22:36:38 +01:00
|
|
|
ImGui::Spacing();
|
|
|
|
|
2023-01-30 01:18:51 +01:00
|
|
|
if (ImGui::BeginCombo("Mode", g_pServerListManager->m_Server.m_svPlaylist.c_str()))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-08-29 11:55:58 +02:00
|
|
|
g_PlaylistsVecMutex.lock();
|
2022-08-31 02:16:40 +02:00
|
|
|
for (const string& svPlaylist : g_vAllPlaylists)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-08-31 02:16:40 +02:00
|
|
|
if (ImGui::Selectable(svPlaylist.c_str(), svPlaylist == g_pServerListManager->m_Server.m_svPlaylist))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-08-31 02:16:40 +02:00
|
|
|
g_pServerListManager->m_Server.m_svPlaylist = svPlaylist;
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
}
|
2022-08-29 11:55:58 +02:00
|
|
|
|
|
|
|
g_PlaylistsVecMutex.unlock();
|
2021-12-25 22:36:38 +01:00
|
|
|
ImGui::EndCombo();
|
|
|
|
}
|
|
|
|
|
2023-01-30 01:18:51 +01:00
|
|
|
if (ImGui::BeginCombo("Map", g_pServerListManager->m_Server.m_svHostMap.c_str()))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-03-31 00:35:01 +02:00
|
|
|
g_InstalledMapsMutex.lock();
|
2023-09-05 17:34:22 +02:00
|
|
|
|
|
|
|
FOR_EACH_VEC(g_InstalledMaps, i)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-09-05 17:34:22 +02:00
|
|
|
const CUtlString& mapName = g_InstalledMaps[i];
|
|
|
|
|
|
|
|
if (ImGui::Selectable(mapName.String(),
|
|
|
|
mapName.IsEqual_CaseInsensitive(g_pServerListManager->m_Server.m_svHostMap.c_str())))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-09-05 17:34:22 +02:00
|
|
|
g_pServerListManager->m_Server.m_svHostMap = mapName.String();
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
}
|
2022-08-29 11:55:58 +02:00
|
|
|
|
2023-03-31 00:35:01 +02:00
|
|
|
g_InstalledMapsMutex.unlock();
|
2021-12-25 22:36:38 +01:00
|
|
|
ImGui::EndCombo();
|
|
|
|
}
|
|
|
|
|
2023-01-28 13:05:02 +01:00
|
|
|
m_bQueryGlobalBanList = sv_globalBanlist->GetBool(); // Sync toggle with 'sv_globalBanlist'.
|
2023-01-28 14:20:57 +01:00
|
|
|
if (ImGui::Checkbox("Load global banned list", &m_bQueryGlobalBanList))
|
2023-01-26 21:20:11 +01:00
|
|
|
{
|
|
|
|
sv_globalBanlist->SetValue(m_bQueryGlobalBanList);
|
|
|
|
}
|
|
|
|
|
2023-01-28 14:20:57 +01:00
|
|
|
ImGui::Text("Server visibility");
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2023-01-28 14:20:57 +01:00
|
|
|
if (ImGui::SameLine(); ImGui::RadioButton("offline", g_pServerListManager->m_ServerVisibility == EServerVisibility_t::OFFLINE))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-08-14 15:45:08 +02:00
|
|
|
g_pServerListManager->m_ServerVisibility = EServerVisibility_t::OFFLINE;
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2023-01-28 14:20:57 +01:00
|
|
|
if (ImGui::SameLine(); ImGui::RadioButton("hidden", g_pServerListManager->m_ServerVisibility == EServerVisibility_t::HIDDEN))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-08-14 15:45:08 +02:00
|
|
|
g_pServerListManager->m_ServerVisibility = EServerVisibility_t::HIDDEN;
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2023-01-28 14:20:57 +01:00
|
|
|
if (ImGui::SameLine(); ImGui::RadioButton("public", g_pServerListManager->m_ServerVisibility == EServerVisibility_t::PUBLIC))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-08-14 15:45:08 +02:00
|
|
|
g_pServerListManager->m_ServerVisibility = EServerVisibility_t::PUBLIC;
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
2023-04-08 19:10:59 +02:00
|
|
|
ImGui::TextColored(m_HostRequestMessageColor, "%s", m_svHostRequestMessage.c_str());
|
2022-09-07 01:12:22 +02:00
|
|
|
if (!m_svHostToken.empty())
|
|
|
|
{
|
|
|
|
ImGui::InputText("##ServerHost_HostToken", &m_svHostToken, ImGuiInputTextFlags_ReadOnly);
|
|
|
|
}
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-09-07 01:12:22 +02:00
|
|
|
ImGui::Spacing();
|
2023-07-19 02:21:58 +02:00
|
|
|
|
|
|
|
const bool bServerActive = g_pServer->IsActive();
|
|
|
|
|
2022-11-26 17:04:12 +01:00
|
|
|
if (!g_pHostState->m_bActiveGame)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-01-28 14:20:57 +01:00
|
|
|
if (ImGui::Button("Start server", ImVec2(ImGui::GetWindowContentRegionWidth(), 32)))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-09-07 01:12:22 +02:00
|
|
|
m_svHostRequestMessage.clear();
|
|
|
|
|
|
|
|
bool bEnforceField = g_pServerListManager->m_ServerVisibility == EServerVisibility_t::OFFLINE ? true : !g_pServerListManager->m_Server.m_svHostName.empty();
|
|
|
|
if (bEnforceField && !g_pServerListManager->m_Server.m_svPlaylist.empty() && !g_pServerListManager->m_Server.m_svHostMap.empty())
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-07-19 02:21:58 +02:00
|
|
|
g_pServerListManager->LaunchServer(bServerActive); // Launch server.
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-14 15:45:08 +02:00
|
|
|
if (g_pServerListManager->m_Server.m_svHostName.empty())
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-09-07 01:12:22 +02:00
|
|
|
m_svHostRequestMessage = "Server name is required.";
|
|
|
|
m_HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2022-08-14 15:45:08 +02:00
|
|
|
else if (g_pServerListManager->m_Server.m_svPlaylist.empty())
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-09-07 01:12:22 +02:00
|
|
|
m_svHostRequestMessage = "Playlist is required.";
|
|
|
|
m_HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2022-08-27 18:57:56 +02:00
|
|
|
else if (g_pServerListManager->m_Server.m_svHostMap.empty())
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-09-07 01:12:22 +02:00
|
|
|
m_svHostRequestMessage = "Level name is required.";
|
|
|
|
m_HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-28 14:20:57 +01:00
|
|
|
if (ImGui::Button("Reload playlist", ImVec2(ImGui::GetWindowContentRegionWidth(), 32)))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-09-07 01:12:22 +02:00
|
|
|
g_TaskScheduler->Dispatch([]()
|
|
|
|
{
|
2024-01-02 15:21:36 +01:00
|
|
|
v__DownloadPlaylists_f();
|
2022-09-07 01:12:22 +02:00
|
|
|
KeyValues::InitPlaylists(); // Re-Init playlist.
|
|
|
|
}, 0);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2022-09-07 01:12:22 +02:00
|
|
|
|
2023-01-28 14:20:57 +01:00
|
|
|
if (ImGui::Button("Reload banlist", ImVec2(ImGui::GetWindowContentRegionWidth(), 32)))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-09-07 01:12:22 +02:00
|
|
|
g_TaskScheduler->Dispatch([]()
|
|
|
|
{
|
2023-08-31 00:16:25 +02:00
|
|
|
g_pBanSystem->LoadList();
|
2022-09-07 01:12:22 +02:00
|
|
|
}, 0);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
}
|
2022-09-07 01:12:22 +02:00
|
|
|
else
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-01-28 14:20:57 +01:00
|
|
|
if (ImGui::Button("Stop server", ImVec2(ImGui::GetWindowContentRegionWidth(), 32)))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-09-07 01:12:22 +02:00
|
|
|
ProcessCommand("LeaveMatch"); // TODO: use script callback instead.
|
|
|
|
g_TaskScheduler->Dispatch([]()
|
|
|
|
{
|
|
|
|
// Force CHostState::FrameUpdate to shutdown the server for dedicated.
|
|
|
|
g_pHostState->m_iNextState = HostStates_t::HS_GAME_SHUTDOWN;
|
|
|
|
}, 0);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
2023-01-28 14:20:57 +01:00
|
|
|
if (ImGui::Button("Change level", ImVec2(ImGui::GetWindowContentRegionWidth(), 32)))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-08-27 18:57:56 +02:00
|
|
|
if (!g_pServerListManager->m_Server.m_svHostMap.empty())
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-07-19 02:21:58 +02:00
|
|
|
g_pServerListManager->LaunchServer(bServerActive);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-07 01:12:22 +02:00
|
|
|
m_svHostRequestMessage = "Failed to change level: 'levelname' was empty.";
|
|
|
|
m_HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-19 02:21:58 +02:00
|
|
|
if (bServerActive)
|
2022-11-14 01:04:01 +01:00
|
|
|
{
|
2022-11-26 17:04:12 +01:00
|
|
|
ImGui::Spacing();
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::Spacing();
|
2022-11-14 01:04:01 +01:00
|
|
|
|
2023-01-28 14:20:57 +01:00
|
|
|
if (ImGui::Button("AI network rebuild", ImVec2(ImGui::GetWindowContentRegionWidth(), 32)))
|
2022-11-26 17:04:12 +01:00
|
|
|
{
|
|
|
|
ProcessCommand("BuildAINFile");
|
|
|
|
}
|
2022-11-14 01:04:01 +01:00
|
|
|
|
2023-01-28 14:20:57 +01:00
|
|
|
if (ImGui::Button("NavMesh hot swap", ImVec2(ImGui::GetWindowContentRegionWidth(), 32)))
|
2022-11-26 17:04:12 +01:00
|
|
|
{
|
|
|
|
ProcessCommand("navmesh_hotswap");
|
|
|
|
}
|
2022-11-14 01:04:01 +01:00
|
|
|
|
2022-11-26 17:04:12 +01:00
|
|
|
ImGui::Spacing();
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::Spacing();
|
2022-11-23 12:30:15 +01:00
|
|
|
|
2023-01-28 14:20:57 +01:00
|
|
|
if (ImGui::Button("AI settings reparse", ImVec2(ImGui::GetWindowContentRegionWidth(), 32)))
|
2022-11-23 12:30:15 +01:00
|
|
|
{
|
2023-08-21 19:12:29 +02:00
|
|
|
Msg(eDLL_T::ENGINE, "Reparsing AI data on %s\n", g_pClientState->IsActive() ? "server and client" : "server");
|
2022-11-26 17:04:12 +01:00
|
|
|
ProcessCommand("aisettings_reparse");
|
|
|
|
|
|
|
|
if (g_pClientState->IsActive())
|
|
|
|
{
|
|
|
|
ProcessCommand("aisettings_reparse_client");
|
|
|
|
}
|
2022-11-23 12:30:15 +01:00
|
|
|
}
|
2022-11-14 01:04:01 +01:00
|
|
|
|
2023-01-28 14:20:57 +01:00
|
|
|
if (ImGui::Button("Weapon settings reparse", ImVec2(ImGui::GetWindowContentRegionWidth(), 32)))
|
2022-11-26 17:04:12 +01:00
|
|
|
{
|
2023-08-21 19:12:29 +02:00
|
|
|
Msg(eDLL_T::ENGINE, "Reparsing weapon data on %s\n", g_pClientState->IsActive() ? "server and client" : "server");
|
2022-11-26 17:04:12 +01:00
|
|
|
ProcessCommand("weapon_reparse");
|
|
|
|
}
|
2022-09-01 01:20:27 +02:00
|
|
|
}
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2022-03-27 22:17:30 +02:00
|
|
|
#endif // !CLIENT_DLL
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-09-09 19:47:31 +02:00
|
|
|
// Purpose: updates the host status
|
2021-12-25 22:36:38 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-05-27 02:44:36 +02:00
|
|
|
void CBrowser::UpdateHostingStatus(void)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-03-27 22:17:30 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-10-21 21:28:51 +02:00
|
|
|
assert(g_pHostState && g_pCVar);
|
2021-12-26 02:30:20 +01:00
|
|
|
|
2022-08-27 18:57:56 +02:00
|
|
|
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
|
2022-08-28 17:40:03 +02:00
|
|
|
g_pServerListManager->m_HostingStatus = g_pServer->IsActive() ? EHostStatus_t::HOSTING : EHostStatus_t::NOT_HOSTING; // Are we hosting a server?
|
2022-08-27 18:57:56 +02:00
|
|
|
|
2022-08-14 15:45:08 +02:00
|
|
|
switch (g_pServerListManager->m_HostingStatus)
|
2022-01-12 02:53:07 +01:00
|
|
|
{
|
2022-08-14 15:45:08 +02:00
|
|
|
case EHostStatus_t::NOT_HOSTING:
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-02-12 11:22:18 +01:00
|
|
|
std::lock_guard<std::mutex> g(m_Mutex);
|
|
|
|
if (!m_svHostToken.empty())
|
|
|
|
{
|
|
|
|
m_svHostToken.clear();
|
|
|
|
}
|
2022-09-07 01:12:22 +02:00
|
|
|
|
|
|
|
if (ImGui::ColorConvertFloat4ToU32(m_HostRequestMessageColor) == // Only clear if this is green (a valid hosting message).
|
|
|
|
ImGui::ColorConvertFloat4ToU32(ImVec4(0.00f, 1.00f, 0.00f, 1.00f)))
|
|
|
|
{
|
|
|
|
m_svHostRequestMessage.clear();
|
|
|
|
m_HostRequestMessageColor = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
|
|
|
|
}
|
|
|
|
|
2022-01-12 02:53:07 +01:00
|
|
|
break;
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2022-08-14 15:45:08 +02:00
|
|
|
case EHostStatus_t::HOSTING:
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-08-14 15:45:08 +02:00
|
|
|
if (g_pServerListManager->m_ServerVisibility == EServerVisibility_t::OFFLINE)
|
2022-01-12 02:53:07 +01:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2023-02-12 11:22:18 +01:00
|
|
|
if (*g_nServerRemoteChecksum == NULL) // Check if script checksum is valid yet.
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
|
|
|
break;
|
2022-01-12 02:53:07 +01:00
|
|
|
}
|
|
|
|
|
2022-08-14 15:45:08 +02:00
|
|
|
switch (g_pServerListManager->m_ServerVisibility)
|
2022-01-12 02:53:07 +01:00
|
|
|
{
|
|
|
|
|
2022-08-14 15:45:08 +02:00
|
|
|
case EServerVisibility_t::HIDDEN:
|
|
|
|
g_pServerListManager->m_Server.m_bHidden = true;
|
2021-12-25 22:36:38 +01:00
|
|
|
break;
|
2022-08-14 15:45:08 +02:00
|
|
|
case EServerVisibility_t::PUBLIC:
|
|
|
|
g_pServerListManager->m_Server.m_bHidden = false;
|
2021-12-25 22:36:38 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2022-01-12 02:53:07 +01:00
|
|
|
|
2023-02-12 11:22:18 +01:00
|
|
|
g_TaskScheduler->Dispatch([this]()
|
2022-03-04 12:22:17 +01:00
|
|
|
{
|
2023-02-12 11:24:34 +01:00
|
|
|
std::lock_guard<std::mutex> f(g_pServerListManager->m_Mutex);
|
2023-02-12 11:22:18 +01:00
|
|
|
NetGameServer_t netGameServer
|
|
|
|
{
|
|
|
|
g_pServerListManager->m_Server.m_svHostName,
|
|
|
|
g_pServerListManager->m_Server.m_svDescription,
|
|
|
|
g_pServerListManager->m_Server.m_bHidden,
|
|
|
|
g_pHostState->m_levelName,
|
2024-01-02 15:21:36 +01:00
|
|
|
KeyValues__GetCurrentPlaylist(),
|
2023-02-12 11:22:18 +01:00
|
|
|
hostip->GetString(),
|
2023-10-15 10:47:19 +02:00
|
|
|
hostport->GetInt(),
|
2023-02-12 11:22:18 +01:00
|
|
|
g_pNetKey->GetBase64NetKey(),
|
2023-10-15 10:47:19 +02:00
|
|
|
*g_nServerRemoteChecksum,
|
2023-02-12 11:22:18 +01:00
|
|
|
SDK_VERSION,
|
2023-10-15 10:47:19 +02:00
|
|
|
g_pServer->GetNumClients(),
|
|
|
|
g_ServerGlobalVariables->m_nMaxClients,
|
2023-02-12 11:22:18 +01:00
|
|
|
std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
|
|
std::chrono::system_clock::now().time_since_epoch()
|
|
|
|
).count()
|
|
|
|
};
|
2022-08-27 18:57:56 +02:00
|
|
|
|
2022-08-27 23:45:58 +02:00
|
|
|
std::thread post(&CBrowser::SendHostingPostRequest, this, netGameServer);
|
2022-08-27 18:57:56 +02:00
|
|
|
post.detach();
|
|
|
|
|
2023-02-12 11:22:18 +01:00
|
|
|
}, 0);
|
|
|
|
|
2022-08-27 18:57:56 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif // !CLIENT_DLL
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: sends the hosting POST request to the comp server
|
|
|
|
// Input : &gameServer -
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CBrowser::SendHostingPostRequest(const NetGameServer_t& gameServer)
|
|
|
|
{
|
|
|
|
#ifndef CLIENT_DLL
|
|
|
|
string svHostRequestMessage;
|
|
|
|
string svHostToken;
|
2023-10-15 10:40:46 +02:00
|
|
|
string svHostIp;
|
|
|
|
|
|
|
|
bool result = g_pMasterServer->PostServerHost(svHostRequestMessage, svHostToken, svHostIp, gameServer);
|
2022-08-27 18:57:56 +02:00
|
|
|
|
|
|
|
std::lock_guard<std::mutex> l(m_Mutex);
|
|
|
|
|
|
|
|
m_svHostRequestMessage = svHostRequestMessage;
|
|
|
|
m_svHostToken = svHostToken;
|
2022-01-12 02:53:07 +01:00
|
|
|
|
2023-10-15 10:40:46 +02:00
|
|
|
if(svHostIp.length() != 0)
|
|
|
|
g_pMasterServer->SetHostIP(svHostIp);
|
|
|
|
|
2022-01-12 02:53:07 +01:00
|
|
|
if (result)
|
|
|
|
{
|
2022-06-27 16:54:40 +02:00
|
|
|
m_HostRequestMessageColor = ImVec4(0.00f, 1.00f, 0.00f, 1.00f);
|
2022-05-27 02:39:08 +02:00
|
|
|
stringstream ssMessage;
|
2022-08-14 18:35:01 +02:00
|
|
|
ssMessage << "Broadcasting: ";
|
2022-05-27 02:39:08 +02:00
|
|
|
if (!m_svHostToken.empty())
|
2022-01-12 02:53:07 +01:00
|
|
|
{
|
2022-08-14 18:35:01 +02:00
|
|
|
ssMessage << "share the following token for clients to connect: ";
|
2022-01-12 02:53:07 +01:00
|
|
|
}
|
2022-07-01 02:20:47 +02:00
|
|
|
m_svHostRequestMessage = ssMessage.str();
|
2022-01-12 02:53:07 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-06-27 16:54:40 +02:00
|
|
|
m_HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2022-03-27 22:17:30 +02:00
|
|
|
#endif // !CLIENT_DLL
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-08-21 19:35:06 +02:00
|
|
|
// Purpose: processes submitted commands for the main thread
|
2022-08-09 02:35:00 +02:00
|
|
|
// Input : *pszCommand -
|
2021-12-25 22:36:38 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-08-14 15:45:08 +02:00
|
|
|
void CBrowser::ProcessCommand(const char* pszCommand) const
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-08-09 02:35:00 +02:00
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), pszCommand, cmd_source_t::kCommandSrcCode);
|
2022-08-27 18:57:56 +02:00
|
|
|
//g_TaskScheduler->Dispatch(Cbuf_Execute, 0); // Run in main thread.
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-01-12 02:53:07 +01:00
|
|
|
// Purpose: draws the settings section
|
2021-12-25 22:36:38 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-06-27 15:01:39 +02:00
|
|
|
void CBrowser::SettingsPanel(void)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-01-28 14:20:57 +01:00
|
|
|
ImGui::InputTextWithHint("Hostname", "Matchmaking host name", &m_szMatchmakingHostName);
|
|
|
|
if (ImGui::Button("Update hostname"))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2023-04-08 10:50:32 +02:00
|
|
|
ProcessCommand(Format("%s \"%s\"", pylon_matchmaking_hostname->GetName(), m_szMatchmakingHostName.c_str()).c_str());
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2022-08-30 01:22:53 +02:00
|
|
|
|
2023-02-12 02:28:03 +01:00
|
|
|
// The 'const' qualifier has been casted away, however the readonly flag is set.
|
|
|
|
// Still a hack, but better than modifying the Dear ImGui lib even more..
|
|
|
|
ImGui::InputTextWithHint("Netkey", "Network encryption key", const_cast<char*>(g_pNetKey->GetBase64NetKey()), ImGuiInputTextFlags_ReadOnly);
|
2023-01-28 14:20:57 +01:00
|
|
|
if (ImGui::Button("Regenerate encryption key"))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-08-27 18:57:56 +02:00
|
|
|
g_TaskScheduler->Dispatch(NET_GenerateKey, 0);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-27 18:57:56 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: hooked to 'MP_HostName_Changed_f' to sync hostname field with
|
|
|
|
// the 'pylon_matchmaking_hostname' ConVar (!!! DO NOT USE !!!).
|
|
|
|
// Input : *pszHostName -
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CBrowser::SetHostName(const char* pszHostName)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> l(m_Mutex);
|
|
|
|
m_szMatchmakingHostName = pszHostName;
|
|
|
|
}
|
|
|
|
|
2022-01-12 02:53:07 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: sets the browser front-end style
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-05-27 02:44:36 +02:00
|
|
|
void CBrowser::SetStyleVar(void)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-08-22 01:10:18 +02:00
|
|
|
m_Style = g_pImGuiConfig->InitStyle();
|
2022-06-24 12:22:04 +02:00
|
|
|
|
2022-08-31 15:45:12 +02:00
|
|
|
ImGui::SetNextWindowSize(ImVec2(928.f, 524.f), ImGuiCond_FirstUseEver);
|
|
|
|
ImGui::SetWindowPos(ImVec2(-500.f, 50.f), ImGuiCond_FirstUseEver);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2022-01-12 02:53:07 +01:00
|
|
|
|
2022-05-27 02:44:36 +02:00
|
|
|
CBrowser* g_pBrowser = new CBrowser();
|