engine: server: sv_main: added status line for dedicated server console

This commit is contained in:
SNMetamorph 2022-04-06 16:06:16 +04:00 committed by a1batross
parent 95ee88720c
commit 22815d2784
4 changed files with 71 additions and 15 deletions

View File

@ -45,6 +45,12 @@ const char *Android_LoadID( void );
void Android_SaveID( const char *id );
#endif
#if XASH_WIN32
void Platform_UpdateStatusLine( void );
#else
static inline void Platform_UpdateStatusLine( void ) { }
#endif
/*
==============================================================================

View File

@ -15,6 +15,7 @@ GNU General Public License for more details.
#include "platform/platform.h"
#include "menu_int.h"
#include "server.h"
#include <shellapi.h>
#if XASH_TIMER == TIMER_WIN32
@ -53,6 +54,27 @@ void Platform_ShellExecute( const char *path, const char *parms )
ShellExecute( NULL, "open", path, parms, NULL, SW_SHOW );
}
void Platform_UpdateStatusLine( void )
{
int clientsCount;
char szStatus[128];
static double lastTime;
if( host.type != HOST_DEDICATED )
return;
// update only every 1/2 seconds
if(( sv.time - lastTime ) < 0.5f )
return;
clientsCount = SV_GetConnectedClientsCount( NULL );
Q_snprintf( szStatus, sizeof( szStatus ) - 1, "%.1f fps %2i/%2i on %16s", 1.f / sv.frametime, clientsCount, svs.maxclients, host.game.levelName );
#ifdef XASH_WIN32
Wcon_SetStatus( szStatus );
#endif
lastTime = sv.time;
}
#if XASH_MESSAGEBOX == MSGBOX_WIN32
void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow )
{

View File

@ -470,6 +470,7 @@ void SV_SendResource( resource_t *pResource, sizebuf_t *msg );
void SV_SendResourceList( sv_client_t *cl );
void SV_AddToMaster( netadr_t from, sizebuf_t *msg );
qboolean SV_ProcessUserAgent( netadr_t from, const char *useragent );
int SV_GetConnectedClientsCount( int *bots );
void Host_SetServerState( int state );
qboolean SV_IsSimulating( void );
void SV_FreeClients( void );

View File

@ -16,6 +16,7 @@ GNU General Public License for more details.
#include "common.h"
#include "server.h"
#include "net_encode.h"
#include "platform/platform.h"
#define HEARTBEAT_SECONDS 300.0f // 300 seconds
@ -153,6 +154,41 @@ qboolean SV_HasActivePlayers( void )
return false;
}
/*
================
SV_GetConnectedClientsCount
returns connected clients count (and optionally bots count)
================
*/
int SV_GetConnectedClientsCount(int *bots)
{
int index;
int clients;
clients = 0;
if( svs.clients )
{
if( bots )
*bots = 0;
for( index = 0; index < svs.maxclients; index++ )
{
if( svs.clients[index].state >= cs_connected )
{
if( FBitSet( svs.clients[index].flags, FCL_FAKECLIENT ))
{
if( bots )
*bots++;
}
else
clients++;
}
}
}
return clients;
}
/*
===================
SV_UpdateMovevars
@ -650,6 +686,9 @@ void Host_ServerFrame( void )
// clear edict flags for next frame
SV_PrepWorldFrame ();
// update dedicated server status line in console
Platform_UpdateStatusLine ();
// send a heartbeat to the master if needed
Master_Heartbeat ();
}
@ -738,22 +777,10 @@ void SV_AddToMaster( netadr_t from, sizebuf_t *msg )
{
uint challenge;
char s[MAX_INFO_STRING] = "0\n"; // skip 2 bytes of header
int clients = 0, bots = 0, index;
int clients = 0, bots = 0;
int len = sizeof( s );
if( svs.clients )
{
for( index = 0; index < svs.maxclients; index++ )
{
if( svs.clients[index].state >= cs_connected )
{
if( FBitSet( svs.clients[index].flags, FCL_FAKECLIENT ))
bots++;
else clients++;
}
}
}
clients = SV_GetConnectedClientsCount( &bots );
challenge = MSG_ReadUBitLong( msg, sizeof( uint ) << 3 );
Info_SetValueForKey( s, "protocol", va( "%d", PROTOCOL_VERSION ), len ); // protocol version