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"
2022-04-09 16:16:40 +02:00
# include "tier1/cvar.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"
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
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"
2021-12-25 22:36:38 +01:00
# include "squirrel/sqinit.h"
2022-03-04 12:22:17 +01:00
# include "vpc/keyvalues.h"
2022-05-16 21:15:25 +02:00
# include "vstdlib/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"
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
{
2022-05-27 02:39:08 +02:00
memset ( m_szServerAddressBuffer , ' \0 ' , sizeof ( m_szServerAddressBuffer ) ) ;
2021-12-25 22:36:38 +01:00
2022-08-27 18:57:56 +02:00
std : : thread refresh ( & CBrowser : : RefreshServerList , this ) ;
refresh . detach ( ) ;
2022-06-09 02:22:01 +02:00
m_pszBrowserTitle = " Server Browser " ;
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
{
//delete r5net;
}
2022-08-14 15:45:08 +02:00
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CBrowser : : Init ( void )
{
SetStyleVar ( ) ;
m_szMatchmakingHostName = pylon_matchmaking_hostname - > GetString ( ) ;
return true ;
}
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-01-12 02:53:07 +01:00
if ( ! m_bInitialized )
2021-12-25 22:36:38 +01:00
{
2022-08-14 15:45:08 +02:00
Init ( ) ;
2022-01-12 02:53:07 +01:00
m_bInitialized = true ;
2021-12-25 22:36:38 +01:00
}
2022-01-28 12:56:51 +01:00
{
//ImGui::ShowStyleEditor();
//ImGui::ShowDemoWindow();
}
2022-06-09 02:22:01 +02:00
int nVars = 0 ;
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 + + ;
}
else
{
ImGui : : PushStyleVar ( ImGuiStyleVar_WindowPadding , ImVec2 { 6.f , 6.f } ) ; nVars + + ;
ImGui : : PushStyleVar ( ImGuiStyleVar_Alpha , m_flFadeAlpha ) ; nVars + + ;
}
2022-08-31 15:45:12 +02:00
ImGui : : PushStyleVar ( ImGuiStyleVar_WindowMinSize , ImVec2 ( 928.f , 524.f ) ) ; nVars + + ;
2022-06-24 12:22:04 +02:00
2022-08-22 01:10:18 +02:00
if ( m_Style ! = ImGuiStyle_t : : MODERN )
2022-06-24 12:45:47 +02:00
{
ImGui : : PushStyleVar ( ImGuiStyleVar_ChildBorderSize , 1.0f ) ; nVars + + ;
}
2022-06-27 16:54:40 +02:00
if ( ! ImGui : : Begin ( m_pszBrowserTitle , & m_bActivate , ImGuiWindowFlags_NoScrollbar ) )
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-08-31 15:45:12 +02:00
ImGui : : PopStyleVar ( nVars ) ;
2022-08-14 15:45:08 +02:00
DrawSurface ( ) ;
2022-01-12 02:53:07 +01:00
ImGui : : End ( ) ;
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 ;
}
if ( timer . GetDurationInProgress ( ) . GetSeconds ( ) > pylon_host_update_interval - > GetDouble ( ) )
{
UpdateHostingStatus ( ) ;
timer . Start ( ) ;
}
}
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
{
2022-08-29 02:21:32 +02:00
if ( m_flFadeAlpha < = 1.f )
2022-06-09 02:22:01 +02:00
{
2022-08-29 14:00:54 +02:00
m_flFadeAlpha + = .1f ;
2022-06-09 02:22:01 +02:00
}
2022-08-29 02:21:32 +02:00
}
else // Reset to full transparent.
{
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 ( ) ;
if ( ImGui : : Button ( " Refresh List " ) )
{
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
}
ImGui : : EndGroup ( ) ;
2022-05-27 02:39:08 +02:00
ImGui : : TextColored ( ImVec4 ( 1.00f , 0.00f , 0.00f , 1.00f ) , m_svServerListMessage . c_str ( ) ) ;
2021-12-25 22:36:38 +01:00
ImGui : : Separator ( ) ;
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 ( ) ;
2022-07-01 02:20:47 +02:00
const char * pszHostPort = server . m_svGamePort . c_str ( ) ;
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 ( ) ;
2022-03-04 12:22:17 +01:00
ImGui : : Text ( pszHostName ) ;
2021-12-25 22:36:38 +01:00
ImGui : : TableNextColumn ( ) ;
2022-03-04 12:22:17 +01:00
ImGui : : Text ( pszHostMap ) ;
2021-12-25 22:36:38 +01:00
2022-06-27 16:54:40 +02:00
ImGui : : TableNextColumn ( ) ;
ImGui : : Text ( pszPlaylist ) ;
2021-12-25 22:36:38 +01:00
ImGui : : TableNextColumn ( ) ;
2022-07-01 02:20:47 +02:00
ImGui : : Text ( fmt : : format ( " {:3d}/{:3d} " , strtol ( server . m_svPlayerCount . c_str ( ) , NULL , NULL ) , strtol ( server . m_svMaxPlayers . c_str ( ) , NULL , NULL ) ) . c_str ( ) ) ;
2021-12-25 22:36:38 +01:00
ImGui : : TableNextColumn ( ) ;
2022-07-01 02:20:47 +02:00
ImGui : : Text ( 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
{
2022-08-14 15:45:08 +02:00
g_pServerListManager - > ConnectToServer ( server . m_svIpAddress , pszHostPort , 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 ( ) ;
ImGui : : Separator ( ) ;
ImGui : : PushItemWidth ( ImGui : : GetWindowContentRegionWidth ( ) / 4 ) ;
{
2022-08-14 15:45:08 +02:00
ImGui : : InputTextWithHint ( " ##ServerBrowser_ServerConnString " , " Enter ip-address and port " , m_szServerAddressBuffer , IM_ARRAYSIZE ( m_szServerAddressBuffer ) ) ;
2021-12-25 22:36:38 +01:00
ImGui : : SameLine ( ) ;
2022-05-27 02:39:08 +02:00
ImGui : : InputTextWithHint ( " ##ServerBrowser_ServerEncKey " , " Enter 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
{
2022-08-14 15:45:08 +02:00
g_pServerListManager - > ConnectToServer ( m_szServerAddressBuffer , m_szServerEncKeyBuffer ) ;
2021-12-25 22:36:38 +01:00
}
ImGui : : SameLine ( ) ;
2022-08-14 18:35:01 +02: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
{
2022-08-27 18:57:56 +02:00
DevMsg ( eDLL_T : : CLIENT , " Refreshing server list with matchmaking host '%s' \n " , pylon_matchmaking_hostname - > GetString ( ) ) ;
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
{
bool modalOpen = true ;
2022-08-31 15:45:12 +02:00
if ( ImGui : : BeginPopupModal ( " Private Server " , & modalOpen , ImGuiWindowFlags_NoResize ) )
2021-12-25 22:36:38 +01:00
{
2022-08-31 15:45:12 +02:00
ImGui : : SetWindowSize ( ImVec2 ( 408.f , 204.f ) , ImGuiCond_Always ) ;
2021-12-25 22:36:38 +01:00
if ( ! m_idLockedIcon )
{
2022-04-26 20:24:51 +02:00
bool ret = LoadTextureBuffer ( reinterpret_cast < unsigned char * > ( m_rLockedIconBlob . m_pData ) , static_cast < int > ( m_rLockedIconBlob . m_nSize ) ,
& m_idLockedIcon , & m_rLockedIconBlob . m_nWidth , & m_rLockedIconBlob . m_nHeight ) ;
2021-12-25 22:36:38 +01:00
IM_ASSERT ( ret ) ;
}
ImGui : : PushStyleColor ( ImGuiCol_ChildBg , ImVec4 ( 0.00f , 0.00f , 0.00f , 0.00f ) ) ; // Override the style color for child bg.
2022-04-26 20:24:51 +02:00
ImGui : : BeginChild ( " ##HiddenServersConnectModal_IconParent " , ImVec2 ( m_rLockedIconBlob . m_nWidth , m_rLockedIconBlob . m_nHeight ) ) ;
ImGui : : Image ( m_idLockedIcon , ImVec2 ( m_rLockedIconBlob . m_nWidth , 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.
2022-08-31 17:23:23 +02:00
ImGui : : InputTextWithHint ( " ##HiddenServersConnectModal_TokenInput " , " Token (Required) " , & m_svHiddenServerToken ) ;
2021-12-25 22:36:38 +01:00
ImGui : : PopItemWidth ( ) ;
ImGui : : Dummy ( ImVec2 ( ImGui : : GetWindowContentRegionWidth ( ) , 19.f ) ) ; // Place a dummy, basically making space inserting a blank element.
2022-05-27 02:39:08 +02:00
ImGui : : TextColored ( m_ivHiddenServerMessageColor , 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 ( ) ;
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.
if ( ! server . m_svHostName . empty ( ) )
{
g_pServerListManager - > ConnectToServer ( server . m_svIpAddress , server . m_svGamePort , server . m_svEncryptionKey ) ; // Connect to the server
m_svHiddenServerRequestMessage = " Found Server: " + server . m_svHostName ;
m_ivHiddenServerMessageColor = ImVec4 ( 0.00f , 1.00f , 0.00f , 1.00f ) ;
ImGui : : CloseCurrentPopup ( ) ;
}
else
{
m_svHiddenServerRequestMessage = " Error: " + m_svHiddenServerRequestMessage ;
m_ivHiddenServerMessageColor = ImVec4 ( 1.00f , 0.00f , 0.00f , 1.00f ) ;
}
2021-12-25 22:36:38 +01:00
}
else
{
2022-08-31 17:23:23 +02:00
m_svHiddenServerRequestMessage = " Token is required. " + m_svHiddenServerRequestMessage ;
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
{
ImGui : : CloseCurrentPopup ( ) ;
}
ImGui : : EndPopup ( ) ;
}
}
//-----------------------------------------------------------------------------
// 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
2022-08-14 15:45:08 +02: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 ( ) ;
2022-08-14 15:45:08 +02:00
if ( ImGui : : BeginCombo ( " Playlist " , 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 ( ) ;
}
2022-08-27 18:57:56 +02:00
if ( ImGui : : BeginCombo ( " Map##ServerHost_MapListBox " , g_pServerListManager - > m_Server . m_svHostMap . c_str ( ) ) )
2021-12-25 22:36:38 +01:00
{
2022-08-29 11:55:58 +02:00
g_MapVecMutex . lock ( ) ;
2022-08-31 02:16:40 +02:00
for ( const string & svMap : g_vAllMaps )
2021-12-25 22:36:38 +01:00
{
2022-08-31 02:16:40 +02:00
if ( ImGui : : Selectable ( svMap . c_str ( ) , svMap = = g_pServerListManager - > m_Server . m_svHostMap ) )
2021-12-25 22:36:38 +01:00
{
2022-08-31 02:16:40 +02:00
g_pServerListManager - > m_Server . m_svHostMap = svMap ;
2021-12-25 22:36:38 +01:00
}
}
2022-08-29 11:55:58 +02:00
g_MapVecMutex . unlock ( ) ;
2021-12-25 22:36:38 +01:00
ImGui : : EndCombo ( ) ;
}
2022-05-08 16:20:48 +02:00
ImGui : : Checkbox ( " Load Global Ban List " , & g_bCheckCompBanDB ) ;
2021-12-25 22:36:38 +01:00
ImGui : : Spacing ( ) ;
ImGui : : SameLine ( ) ;
ImGui : : Text ( " Server Visiblity " ) ;
2022-08-14 15:45:08 +02: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
}
2022-08-14 15:45:08 +02: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
}
2022-08-14 15:45:08 +02: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
}
ImGui : : Spacing ( ) ;
ImGui : : Separator ( ) ;
2022-08-28 17:40:03 +02:00
if ( ! g_pServer - > IsActive ( ) )
2021-12-25 22:36:38 +01:00
{
2022-08-31 15:45:12 +02:00
if ( ImGui : : Button ( " Start Server " , ImVec2 ( ImGui : : GetWindowContentRegionWidth ( ) , 32 ) ) )
2021-12-25 22:36:38 +01:00
{
2022-08-29 02:38:19 +02:00
m_svHostInvalidCriteria . clear ( ) ;
2022-08-27 18:57:56 +02:00
if ( ! g_pServerListManager - > m_Server . m_svHostName . empty ( ) & & ! g_pServerListManager - > m_Server . m_svPlaylist . empty ( ) & & ! g_pServerListManager - > m_Server . m_svHostMap . empty ( ) )
2021-12-25 22:36:38 +01:00
{
2022-08-14 15:45:08 +02:00
g_pServerListManager - > LaunchServer ( ) ; // 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-08-29 02:38:19 +02:00
m_svHostInvalidCriteria = " Server name is required. " ;
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-08-29 02:38:19 +02:00
m_svHostInvalidCriteria = " Playlist is required. " ;
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-08-29 02:38:19 +02:00
m_svHostInvalidCriteria = " Level name is required. " ;
2021-12-25 22:36:38 +01:00
}
}
}
}
2022-08-31 15:45:12 +02:00
if ( ImGui : : Button ( " Force Start " , ImVec2 ( ImGui : : GetWindowContentRegionWidth ( ) , 32 ) ) )
2021-12-25 22:36:38 +01:00
{
2022-08-29 02:38:19 +02:00
m_svHostInvalidCriteria . clear ( ) ;
2022-08-27 18:57:56 +02:00
if ( ! g_pServerListManager - > m_Server . m_svPlaylist . empty ( ) & & ! g_pServerListManager - > m_Server . m_svHostMap . empty ( ) )
2021-12-25 22:36:38 +01:00
{
2022-08-14 15:45:08 +02:00
g_pServerListManager - > LaunchServer ( ) ; // 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_svPlaylist . empty ( ) )
2021-12-25 22:36:38 +01:00
{
2022-08-29 02:38:19 +02:00
m_svHostInvalidCriteria = " Playlist is required. " ;
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-08-29 02:38:19 +02:00
m_svHostInvalidCriteria = " Level name is required. " ;
2021-12-25 22:36:38 +01:00
}
}
}
2022-08-29 02:38:19 +02:00
ImGui : : TextColored ( ImVec4 ( 1.00f , 0.00f , 0.00f , 1.00f ) , m_svHostInvalidCriteria . c_str ( ) ) ;
2022-06-27 16:54:40 +02:00
ImGui : : TextColored ( m_HostRequestMessageColor , m_svHostRequestMessage . c_str ( ) ) ;
2022-08-29 02:38:19 +02:00
2022-05-27 02:39:08 +02:00
if ( ! m_svHostToken . empty ( ) )
2021-12-25 22:36:38 +01:00
{
2022-05-27 02:39:08 +02:00
ImGui : : InputText ( " ##ServerHost_HostToken " , & m_svHostToken , ImGuiInputTextFlags_ReadOnly ) ;
2021-12-25 22:36:38 +01:00
}
2022-08-28 17:40:03 +02:00
if ( g_pServer - > IsActive ( ) )
2021-12-25 22:36:38 +01:00
{
2022-08-31 15:45:12 +02:00
if ( ImGui : : Button ( " Weapon Reparse " , ImVec2 ( ImGui : : GetWindowContentRegionWidth ( ) , 32 ) ) )
2021-12-25 22:36:38 +01:00
{
2022-05-08 16:20:48 +02:00
DevMsg ( eDLL_T : : ENGINE , " Reparsing weapon data on %s \n " , " server and client " ) ;
2022-04-08 23:03:09 +02:00
ProcessCommand ( " weapon_reparse " ) ;
2021-12-25 22:36:38 +01:00
}
2022-08-31 15:45:12 +02: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
{
2022-08-27 18:57:56 +02:00
g_pServerListManager - > LaunchServer ( ) ;
2021-12-25 22:36:38 +01:00
}
else
{
2022-08-29 02:38:19 +02:00
m_svHostInvalidCriteria = " Failed to change level: 'levelname' was empty. " ;
2021-12-25 22:36:38 +01:00
}
}
2022-08-31 15:45:12 +02:00
if ( ImGui : : Button ( " Stop Server " , ImVec2 ( ImGui : : GetWindowContentRegionWidth ( ) , 32 ) ) )
2021-12-25 22:36:38 +01:00
{
ProcessCommand ( " LeaveMatch " ) ; // TODO: use script callback instead.
2022-08-27 18:57:56 +02:00
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
}
}
else
{
2022-08-31 15:45:12 +02:00
if ( ImGui : : Button ( " Reload Playlist " , ImVec2 ( ImGui : : GetWindowContentRegionWidth ( ) , 32 ) ) )
2021-12-25 22:36:38 +01:00
{
2022-08-27 18:57:56 +02:00
g_TaskScheduler - > Dispatch ( [ ] ( )
{
_DownloadPlaylists_f ( ) ;
KeyValues : : InitPlaylists ( ) ; // Re-Init playlist.
} , 0 ) ;
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-01-12 02:53:07 +01:00
// Purpose: updates the hoster's 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-01-12 02:53:07 +01:00
if ( ! g_pHostState | | ! g_pCVar )
2021-12-25 22:36:38 +01:00
{
return ;
}
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
{
2022-05-27 02:39:08 +02:00
m_svHostRequestMessage . clear ( ) ;
2022-08-04 22:44:23 +02:00
m_svHostToken . clear ( ) ;
2022-06-27 16:54:40 +02:00
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
2022-01-20 16:04:10 +01:00
if ( * g_nClientRemoteChecksum = = 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
2022-08-30 01:22:53 +02:00
std : : lock_guard < std : : mutex > l ( g_NetKeyMutex ) ;
2022-08-27 23:45:58 +02:00
NetGameServer_t netGameServer // !FIXME: create from main thread.
2022-03-04 12:22:17 +01:00
{
2022-08-14 15:45:08 +02:00
g_pServerListManager - > m_Server . m_svHostName ,
g_pServerListManager - > m_Server . m_svDescription ,
g_pServerListManager - > m_Server . m_bHidden ,
2022-06-28 00:47:01 +02:00
g_pHostState - > m_levelName ,
2022-03-26 18:06:54 +01:00
mp_gamemode - > GetString ( ) ,
2022-06-28 00:47:01 +02:00
hostip - > GetString ( ) ,
2022-07-01 02:20:47 +02:00
hostport - > GetString ( ) ,
g_svNetKey ,
2022-06-28 00:47:01 +02:00
std : : to_string ( * g_nServerRemoteChecksum ) ,
SDK_VERSION ,
2022-07-01 02:20:47 +02:00
std : : to_string ( g_pServer - > GetNumHumanPlayers ( ) + g_pServer - > GetNumFakeClients ( ) ) ,
std : : to_string ( g_ServerGlobalVariables - > m_nMaxClients ) ,
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 ( ) ;
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 ;
bool result = g_pMasterServer - > PostServerHost ( svHostRequestMessage , svHostToken , gameServer ) ;
std : : lock_guard < std : : mutex > l ( m_Mutex ) ;
m_svHostRequestMessage = svHostRequestMessage ;
m_svHostToken = svHostToken ;
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
{
2022-05-08 16:20:48 +02:00
ImGui : : InputTextWithHint ( " Hostname " , " Matchmaking Server String " , & m_szMatchmakingHostName ) ;
2022-01-12 02:53:07 +01:00
if ( ImGui : : Button ( " Update Hostname " ) )
2021-12-25 22:36:38 +01:00
{
2022-08-29 03:03:53 +02:00
ProcessCommand ( fmt : : format ( " {:s} \" {:s} \" " , " pylon_matchmaking_hostname " , m_szMatchmakingHostName ) . c_str ( ) ) ;
2021-12-25 22:36:38 +01:00
}
2022-08-30 01:22:53 +02:00
std : : lock_guard < std : : mutex > l ( g_NetKeyMutex ) ;
2022-06-27 16:54:40 +02:00
ImGui : : InputText ( " Netkey " , const_cast < char * > ( g_svNetKey . c_str ( ) ) , ImGuiInputTextFlags_ReadOnly ) ;
2022-05-08 16:20:48 +02: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 ( ) ;