2008-05-18 22:00:00 +02:00
|
|
|
|
//=======================================================================
|
|
|
|
|
// Copyright XashXT Group 2007 <20>
|
2009-09-16 22:00:00 +02:00
|
|
|
|
// sv_utils.c - server vm utils
|
2008-05-18 22:00:00 +02:00
|
|
|
|
//=======================================================================
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-06-09 22:00:00 +02:00
|
|
|
|
#include "common.h"
|
2007-06-21 22:00:00 +02:00
|
|
|
|
#include "server.h"
|
|
|
|
|
|
2009-09-17 22:00:00 +02:00
|
|
|
|
#define HEARTBEAT_SECONDS 300 * 1000 // 300 seconds
|
|
|
|
|
|
2007-06-21 22:00:00 +02:00
|
|
|
|
netadr_t master_adr[MAX_MASTERS]; // address of group servers
|
|
|
|
|
|
|
|
|
|
cvar_t *sv_paused;
|
2008-07-03 22:00:00 +02:00
|
|
|
|
cvar_t *sv_fps;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
cvar_t *sv_enforcetime;
|
|
|
|
|
cvar_t *timeout; // seconds without any message
|
|
|
|
|
cvar_t *zombietime; // seconds to sink messages after disconnect
|
|
|
|
|
cvar_t *rcon_password; // password for remote server commands
|
|
|
|
|
cvar_t *allow_download;
|
2007-09-02 22:00:00 +02:00
|
|
|
|
cvar_t *sv_airaccelerate;
|
2009-09-13 22:00:00 +02:00
|
|
|
|
cvar_t *sv_idealpitchscale;
|
2007-09-02 22:00:00 +02:00
|
|
|
|
cvar_t *sv_maxvelocity;
|
|
|
|
|
cvar_t *sv_gravity;
|
2008-07-30 22:00:00 +02:00
|
|
|
|
cvar_t *sv_stepheight;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
cvar_t *sv_noreload; // don't reload level state when reentering
|
2008-07-30 22:00:00 +02:00
|
|
|
|
cvar_t *sv_playersonly;
|
|
|
|
|
cvar_t *sv_rollangle;
|
|
|
|
|
cvar_t *sv_rollspeed;
|
|
|
|
|
cvar_t *sv_maxspeed;
|
|
|
|
|
cvar_t *sv_accelerate;
|
|
|
|
|
cvar_t *sv_friction;
|
2008-11-28 22:00:00 +01:00
|
|
|
|
cvar_t *sv_physics;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
cvar_t *hostname;
|
2009-06-24 22:00:00 +02:00
|
|
|
|
cvar_t *sv_showclamp;
|
2007-09-10 22:00:00 +02:00
|
|
|
|
cvar_t *public_server; // should heartbeats be sent
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2007-09-10 22:00:00 +02:00
|
|
|
|
cvar_t *sv_reconnect_limit;// minimum seconds between connect messages
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
void Master_Shutdown (void);
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
===================
|
|
|
|
|
SV_CalcPings
|
|
|
|
|
|
|
|
|
|
Updates the cl->ping variables
|
|
|
|
|
===================
|
|
|
|
|
*/
|
2008-08-01 22:00:00 +02:00
|
|
|
|
void SV_CalcPings( void )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-07-31 22:00:00 +02:00
|
|
|
|
int i, j;
|
2008-07-09 22:00:00 +02:00
|
|
|
|
sv_client_t *cl;
|
2008-07-31 22:00:00 +02:00
|
|
|
|
int total, count;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2009-09-16 22:00:00 +02:00
|
|
|
|
// clamp fps counter
|
2008-07-31 22:00:00 +02:00
|
|
|
|
for( i = 0; i < Host_MaxClients(); i++ )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
cl = &svs.clients[i];
|
2009-09-16 22:00:00 +02:00
|
|
|
|
if( cl->state != cs_spawned ) continue;
|
2009-09-15 22:00:00 +02:00
|
|
|
|
|
2009-09-16 22:00:00 +02:00
|
|
|
|
total = count = 0;
|
|
|
|
|
for( j = 0; j < LATENCY_COUNTS; j++ )
|
2009-09-15 22:00:00 +02:00
|
|
|
|
{
|
2009-09-16 22:00:00 +02:00
|
|
|
|
if( cl->frame_latency > 0 )
|
|
|
|
|
{
|
|
|
|
|
count++;
|
|
|
|
|
total += cl->frame_latency[j];
|
|
|
|
|
}
|
2009-09-15 22:00:00 +02:00
|
|
|
|
}
|
2009-09-16 22:00:00 +02:00
|
|
|
|
if( !count ) cl->ping = 0;
|
|
|
|
|
else cl->ping = total / count;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// let the game dll know about the ping
|
2008-12-26 22:00:00 +01:00
|
|
|
|
cl->edict->pvServerData->client->ping = cl->ping;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2009-06-24 22:00:00 +02:00
|
|
|
|
===================
|
|
|
|
|
SV_GiveMsec
|
|
|
|
|
|
|
|
|
|
Every few frames, gives all clients an allotment of milliseconds
|
|
|
|
|
for their command moves. If they exceed it, assume cheating.
|
|
|
|
|
===================
|
2007-06-21 22:00:00 +02:00
|
|
|
|
*/
|
2009-06-24 22:00:00 +02:00
|
|
|
|
void SV_GiveMsec( void )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-07-12 22:00:00 +02:00
|
|
|
|
int i;
|
2008-07-09 22:00:00 +02:00
|
|
|
|
sv_client_t *cl;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2009-06-24 22:00:00 +02:00
|
|
|
|
if( sv.framenum & 15 )
|
|
|
|
|
return;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2009-06-24 22:00:00 +02:00
|
|
|
|
for( i = 0; i < Host_MaxClients(); i++ )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2009-06-24 22:00:00 +02:00
|
|
|
|
cl = &svs.clients[i];
|
|
|
|
|
if( cl->state == cs_free )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
cl->commandMsec = 1800; // 1600 + some slop
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
2009-06-24 22:00:00 +02:00
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2009-06-24 22:00:00 +02:00
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
SV_ReadPackets
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
void SV_ReadPackets( void )
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
sv_client_t *cl;
|
|
|
|
|
int qport;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2009-06-24 22:00:00 +02:00
|
|
|
|
while( NET_GetPacket( NS_SERVER, &net_from, &net_message ))
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2009-06-24 22:00:00 +02:00
|
|
|
|
// check for connectionless packet (0xffffffff) first
|
|
|
|
|
if( net_message.cursize >= 4 && *(int *)net_message.data == -1 )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2009-06-24 22:00:00 +02:00
|
|
|
|
SV_ConnectionlessPacket( net_from, &net_message );
|
|
|
|
|
continue;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
2009-06-24 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// read the qport out of the message so we can fix up
|
|
|
|
|
// stupid address translating routers
|
|
|
|
|
MSG_BeginReading( &net_message );
|
|
|
|
|
MSG_ReadLong( &net_message ); // sequence number
|
|
|
|
|
MSG_ReadLong( &net_message ); // sequence number
|
|
|
|
|
qport = (int)MSG_ReadShort( &net_message ) & 0xffff;
|
|
|
|
|
|
|
|
|
|
// check for packets from connected clients
|
|
|
|
|
for( i = 0, cl = svs.clients; i < Host_MaxClients(); i++, cl++ )
|
|
|
|
|
{
|
|
|
|
|
if( cl->state == cs_free ) continue;
|
|
|
|
|
if( cl->edict && (cl->edict->v.flags & FL_FAKECLIENT )) continue;
|
|
|
|
|
if( !NET_CompareBaseAdr( net_from, cl->netchan.remote_address )) continue;
|
|
|
|
|
if( cl->netchan.qport != qport ) continue;
|
|
|
|
|
if( cl->netchan.remote_address.port != net_from.port )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2009-06-24 22:00:00 +02:00
|
|
|
|
MsgDev( D_INFO, "SV_ReadPackets: fixing up a translated port\n");
|
|
|
|
|
cl->netchan.remote_address.port = net_from.port;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
2009-06-24 22:00:00 +02:00
|
|
|
|
if( Netchan_Process( &cl->netchan, &net_message ))
|
|
|
|
|
{
|
|
|
|
|
// this is a valid, sequenced packet, so process it
|
|
|
|
|
if( cl->state != cs_zombie )
|
|
|
|
|
{
|
|
|
|
|
cl->lastmessage = svs.realtime; // don't timeout
|
|
|
|
|
SV_ExecuteClientMessage( cl, &net_message );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
2009-06-24 22:00:00 +02:00
|
|
|
|
if( i != Host_MaxClients()) continue;
|
2009-06-22 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-21 22:00:00 +02:00
|
|
|
|
/*
|
|
|
|
|
==================
|
|
|
|
|
SV_CheckTimeouts
|
|
|
|
|
|
|
|
|
|
If a packet has not been received from a client for timeout->value
|
|
|
|
|
seconds, drop the conneciton. Server frames are used instead of
|
|
|
|
|
realtime to avoid dropping the local client while debugging.
|
|
|
|
|
|
2008-07-09 22:00:00 +02:00
|
|
|
|
When a client is normally dropped, the sv_client_t goes into a zombie state
|
2007-06-21 22:00:00 +02:00
|
|
|
|
for a few seconds to make sure any final reliable message gets resent
|
|
|
|
|
if necessary
|
|
|
|
|
==================
|
|
|
|
|
*/
|
2008-07-12 22:00:00 +02:00
|
|
|
|
void SV_CheckTimeouts( void )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
int i;
|
2008-07-09 22:00:00 +02:00
|
|
|
|
sv_client_t *cl;
|
2008-07-12 22:00:00 +02:00
|
|
|
|
float droppoint;
|
|
|
|
|
float zombiepoint;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2009-09-16 22:00:00 +02:00
|
|
|
|
if( sv_fps->modified )
|
|
|
|
|
{
|
|
|
|
|
if( sv_fps->value < 10 ) Cvar_Set( "sv_fps", "10" ); // too slow, also, netcode uses a byte
|
|
|
|
|
else if( sv_fps->value > 90 ) Cvar_Set( "sv_fps", "90" ); // abusive
|
|
|
|
|
sv_fps->modified = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// calc sv.frametime
|
2009-09-17 22:00:00 +02:00
|
|
|
|
sv.frametime = ( 1000 / sv_fps->integer );
|
2009-09-16 22:00:00 +02:00
|
|
|
|
|
2009-09-17 22:00:00 +02:00
|
|
|
|
droppoint = svs.realtime - (timeout->value * 1000);
|
|
|
|
|
zombiepoint = svs.realtime - (zombietime->value * 1000);
|
2008-07-31 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
for( i = 0, cl = svs.clients; i < Host_MaxClients(); i++, cl++ )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2009-06-24 22:00:00 +02:00
|
|
|
|
// fake clients do not timeout
|
|
|
|
|
if( cl->edict && (cl->edict->v.flags & FL_FAKECLIENT))
|
|
|
|
|
cl->lastmessage = svs.realtime;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
// message times may be wrong across a changelevel
|
2009-06-24 22:00:00 +02:00
|
|
|
|
if( cl->lastmessage > svs.realtime ) cl->lastmessage = svs.realtime;
|
2008-07-12 22:00:00 +02:00
|
|
|
|
if( cl->state == cs_zombie && cl->lastmessage < zombiepoint )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-07-12 22:00:00 +02:00
|
|
|
|
cl->state = cs_free; // can now be reused
|
2007-06-21 22:00:00 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2008-07-12 22:00:00 +02:00
|
|
|
|
if(( cl->state == cs_connected || cl->state == cs_spawned) && cl->lastmessage < droppoint )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2009-06-24 22:00:00 +02:00
|
|
|
|
SV_BroadcastPrintf( PRINT_HIGH, "%s timed out\n", cl->name );
|
2008-07-12 22:00:00 +02:00
|
|
|
|
SV_DropClient( cl );
|
|
|
|
|
cl->state = cs_free; // don't bother with zombie state
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 22:00:00 +01:00
|
|
|
|
/*
|
|
|
|
|
================
|
|
|
|
|
SV_PrepWorldFrame
|
|
|
|
|
|
|
|
|
|
This has to be done before the world logic, because
|
|
|
|
|
player processing happens outside RunWorldFrame
|
|
|
|
|
================
|
|
|
|
|
*/
|
|
|
|
|
void SV_PrepWorldFrame( void )
|
|
|
|
|
{
|
|
|
|
|
edict_t *ent;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for( i = 0; i < svgame.globals->numEntities; i++ )
|
|
|
|
|
{
|
|
|
|
|
ent = EDICT_NUM( i );
|
|
|
|
|
if( ent->free ) continue;
|
|
|
|
|
ent->pvServerData->s.ed_flags = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-07-31 22:00:00 +02:00
|
|
|
|
|
2009-09-15 22:00:00 +02:00
|
|
|
|
/*
|
|
|
|
|
==================
|
|
|
|
|
SV_CheckPaused
|
|
|
|
|
==================
|
|
|
|
|
*/
|
|
|
|
|
bool SV_CheckPaused( void )
|
|
|
|
|
{
|
|
|
|
|
int i, count;
|
|
|
|
|
sv_client_t *cl;
|
|
|
|
|
|
|
|
|
|
if( !sv_paused->integer )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// only pause if there is just a single client connected
|
|
|
|
|
for( i = count = 0, cl = svs.clients; i < Host_MaxClients(); i++, cl++ )
|
|
|
|
|
{
|
|
|
|
|
if( cl->state >= cs_connected && !(cl->edict && cl->edict->v.flags & FL_FAKECLIENT))
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( count > 1 )
|
|
|
|
|
{
|
|
|
|
|
// don't pause
|
|
|
|
|
if( sv_paused->integer )
|
2009-09-16 22:00:00 +02:00
|
|
|
|
Cvar_Set( "paused", "0" );
|
2009-09-15 22:00:00 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !sv_paused->integer )
|
2009-09-16 22:00:00 +02:00
|
|
|
|
Cvar_Set( "paused", "1" );
|
2009-09-15 22:00:00 +02:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-06 22:00:00 +02:00
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
SV_RunGameFrame
|
|
|
|
|
=================
|
|
|
|
|
*/
|
2009-02-02 22:00:00 +01:00
|
|
|
|
void SV_RunGameFrame( void )
|
2007-09-06 22:00:00 +02:00
|
|
|
|
{
|
2009-06-24 22:00:00 +02:00
|
|
|
|
// don't run if paused
|
2009-09-16 22:00:00 +02:00
|
|
|
|
if( SV_CheckPaused( )) return;
|
2009-06-24 22:00:00 +02:00
|
|
|
|
|
2009-09-16 22:00:00 +02:00
|
|
|
|
sv.framenum++;
|
|
|
|
|
if( sv.frametime ) SV_Physics();
|
|
|
|
|
|
|
|
|
|
// never get more than one tic behind
|
|
|
|
|
if( sv.time < svs.realtime )
|
|
|
|
|
{
|
|
|
|
|
if( sv_showclamp->integer )
|
|
|
|
|
MsgDev( D_INFO, "sv highclamp\n" );
|
|
|
|
|
svs.realtime = sv.time;
|
2009-06-24 22:00:00 +02:00
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
==================
|
|
|
|
|
SV_Frame
|
|
|
|
|
|
|
|
|
|
==================
|
|
|
|
|
*/
|
2009-09-17 22:00:00 +02:00
|
|
|
|
void SV_Frame( long time )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
// if server is not active, do nothing
|
2008-07-03 22:00:00 +02:00
|
|
|
|
if( !svs.initialized ) return;
|
2009-02-03 22:00:00 +01:00
|
|
|
|
|
2009-09-16 22:00:00 +02:00
|
|
|
|
svs.realtime += time;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// keep the random time dependent
|
|
|
|
|
rand ();
|
|
|
|
|
|
|
|
|
|
// check timeouts
|
|
|
|
|
SV_CheckTimeouts ();
|
2007-09-06 22:00:00 +02:00
|
|
|
|
|
2009-06-22 22:00:00 +02:00
|
|
|
|
// read packets from clients
|
|
|
|
|
SV_ReadPackets ();
|
|
|
|
|
|
2009-09-16 22:00:00 +02:00
|
|
|
|
// move autonomous things around if enough time has passed
|
|
|
|
|
if( svs.realtime < sv.time )
|
2009-09-15 22:00:00 +02:00
|
|
|
|
{
|
2009-09-16 22:00:00 +02:00
|
|
|
|
// never let the time get too far off
|
|
|
|
|
if( sv.time - svs.realtime > sv.frametime )
|
|
|
|
|
{
|
|
|
|
|
if( sv_showclamp->integer )
|
|
|
|
|
MsgDev( D_INFO, "sv lowclamp\n" );
|
|
|
|
|
svs.realtime = sv.time - sv.frametime;
|
|
|
|
|
}
|
|
|
|
|
NET_Sleep( sv.time - svs.realtime );
|
2009-06-24 22:00:00 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-21 22:00:00 +02:00
|
|
|
|
// update ping based on the last known frame from all clients
|
|
|
|
|
SV_CalcPings ();
|
|
|
|
|
|
2009-06-24 22:00:00 +02:00
|
|
|
|
// give the clients some timeslices
|
|
|
|
|
SV_GiveMsec ();
|
|
|
|
|
|
2009-09-16 22:00:00 +02:00
|
|
|
|
// let everything in the world think and move
|
|
|
|
|
SV_RunGameFrame ();
|
|
|
|
|
|
2007-06-21 22:00:00 +02:00
|
|
|
|
// send messages back to the clients that had packets read this frame
|
|
|
|
|
SV_SendClientMessages ();
|
|
|
|
|
|
|
|
|
|
// send a heartbeat to the master if needed
|
|
|
|
|
Master_Heartbeat ();
|
2009-01-14 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
// clear edict flags for next frame
|
|
|
|
|
SV_PrepWorldFrame ();
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
================
|
|
|
|
|
Master_Heartbeat
|
|
|
|
|
|
|
|
|
|
Send a message to the master every few minutes to
|
|
|
|
|
let it know we are alive, and log information
|
|
|
|
|
================
|
|
|
|
|
*/
|
2008-12-20 22:00:00 +01:00
|
|
|
|
void Master_Heartbeat( void )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-12-20 22:00:00 +01:00
|
|
|
|
char *string;
|
|
|
|
|
int i;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-07-11 22:00:00 +02:00
|
|
|
|
if( host.type != HOST_DEDICATED )
|
|
|
|
|
return; // only dedicated servers send heartbeats
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// pgm post3.19 change, cvar pointer not validated before dereferencing
|
2009-02-03 22:00:00 +01:00
|
|
|
|
if( !public_server || !public_server->value )
|
2007-09-09 22:00:00 +02:00
|
|
|
|
return; // a private dedicated game
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// check for time wraparound
|
2009-06-24 22:00:00 +02:00
|
|
|
|
if( svs.last_heartbeat > svs.realtime )
|
|
|
|
|
svs.last_heartbeat = svs.realtime;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2009-06-24 22:00:00 +02:00
|
|
|
|
if(( svs.realtime - svs.last_heartbeat ) < HEARTBEAT_SECONDS )
|
2009-02-03 22:00:00 +01:00
|
|
|
|
return; // not time to send yet
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2009-06-24 22:00:00 +02:00
|
|
|
|
svs.last_heartbeat = svs.realtime;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// send the same string that we would give for a status OOB command
|
|
|
|
|
string = SV_StatusString();
|
|
|
|
|
|
|
|
|
|
// send to group master
|
2009-02-03 22:00:00 +01:00
|
|
|
|
for( i = 0; i < MAX_MASTERS; i++ )
|
2007-09-09 22:00:00 +02:00
|
|
|
|
{
|
2009-02-03 22:00:00 +01:00
|
|
|
|
if( master_adr[i].port )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2009-02-03 22:00:00 +01:00
|
|
|
|
Msg( "Sending heartbeat to %s\n", NET_AdrToString( master_adr[i] ));
|
|
|
|
|
Netchan_OutOfBandPrint( NS_SERVER, master_adr[i], "heartbeat\n%s", string );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
2007-09-09 22:00:00 +02:00
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
=================
|
|
|
|
|
Master_Shutdown
|
|
|
|
|
|
|
|
|
|
Informs all masters that this server is going down
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
void Master_Shutdown (void)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2008-07-11 22:00:00 +02:00
|
|
|
|
if( host.type != HOST_DEDICATED )
|
|
|
|
|
return; // only dedicated servers send heartbeats
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// pgm post3.19 change, cvar pointer not validated before dereferencing
|
|
|
|
|
if (!public_server || !public_server->value)
|
|
|
|
|
return; // a private dedicated game
|
|
|
|
|
|
|
|
|
|
// send to group master
|
2008-01-13 22:00:00 +01:00
|
|
|
|
for(i = 0; i < MAX_MASTERS; i++)
|
|
|
|
|
{
|
2007-06-21 22:00:00 +02:00
|
|
|
|
if (master_adr[i].port)
|
|
|
|
|
{
|
2008-01-13 22:00:00 +01:00
|
|
|
|
if( i ) Msg ("Sending heartbeat to %s\n", NET_AdrToString (master_adr[i]));
|
|
|
|
|
Netchan_OutOfBandPrint( NS_SERVER, master_adr[i], "shutdown" );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
2008-01-13 22:00:00 +01:00
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
===============
|
|
|
|
|
SV_Init
|
|
|
|
|
|
2008-12-15 22:00:00 +01:00
|
|
|
|
Only called at startup, not for each game
|
2007-06-21 22:00:00 +02:00
|
|
|
|
===============
|
|
|
|
|
*/
|
2008-08-04 22:00:00 +02:00
|
|
|
|
void SV_Init( void )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2007-12-11 22:00:00 +01:00
|
|
|
|
SV_InitOperatorCommands();
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-06-29 22:00:00 +02:00
|
|
|
|
rcon_password = Cvar_Get( "rcon_password", "", 0, "remote connect password" );
|
|
|
|
|
Cvar_Get ("skill", "1", 0, "game skill level" );
|
2009-01-09 22:00:00 +01:00
|
|
|
|
Cvar_Get ("deathmatch", "0", CVAR_SERVERINFO|CVAR_LATCH, "displays deathmatch state" );
|
|
|
|
|
Cvar_Get ("teamplay", "0", CVAR_SERVERINFO|CVAR_LATCH, "displays teamplay state" );
|
|
|
|
|
Cvar_Get ("coop", "0", CVAR_SERVERINFO|CVAR_LATCH, "displays cooperative state" );
|
2008-07-16 22:00:00 +02:00
|
|
|
|
Cvar_Get ("dmflags", "0", CVAR_SERVERINFO, "setup deathmatch flags" );
|
2008-06-29 22:00:00 +02:00
|
|
|
|
Cvar_Get ("fraglimit", "0", CVAR_SERVERINFO, "multiplayer fraglimit" );
|
|
|
|
|
Cvar_Get ("timelimit", "0", CVAR_SERVERINFO, "multiplayer timelimit" );
|
|
|
|
|
Cvar_Get ("protocol", va("%i", PROTOCOL_VERSION), CVAR_SERVERINFO|CVAR_INIT, "displays server protocol version" );
|
2009-01-23 22:00:00 +01:00
|
|
|
|
Cvar_Get ("sv_aim", "1", 0, "enable auto-aiming" );
|
2008-07-03 22:00:00 +02:00
|
|
|
|
|
2009-09-16 22:00:00 +02:00
|
|
|
|
sv_fps = Cvar_Get( "sv_fps", "72.1", CVAR_ARCHIVE, "running server physics at" );
|
2009-01-22 22:00:00 +01:00
|
|
|
|
sv_stepheight = Cvar_Get( "sv_stepheight", DEFAULT_STEPHEIGHT, CVAR_ARCHIVE|CVAR_LATCH, "how high you can step up" );
|
2008-07-30 22:00:00 +02:00
|
|
|
|
sv_playersonly = Cvar_Get( "playersonly", "0", 0, "freezes time, except for players" );
|
2008-08-01 22:00:00 +02:00
|
|
|
|
hostname = Cvar_Get ("sv_hostname", "unnamed", CVAR_SERVERINFO | CVAR_ARCHIVE, "host name" );
|
2008-06-29 22:00:00 +02:00
|
|
|
|
timeout = Cvar_Get ("timeout", "125", 0, "connection timeout" );
|
|
|
|
|
zombietime = Cvar_Get ("zombietime", "2", 0, "timeout for clients-zombie (who died but not respawned)" );
|
|
|
|
|
sv_paused = Cvar_Get ("paused", "0", 0, "server pause" );
|
|
|
|
|
sv_enforcetime = Cvar_Get ("sv_enforcetime", "0", 0, "client enforce time" );
|
|
|
|
|
allow_download = Cvar_Get ("allow_download", "1", CVAR_ARCHIVE, "allow download resources" );
|
2009-01-22 22:00:00 +01:00
|
|
|
|
sv_noreload = Cvar_Get( "sv_noreload", "0", 0, "ignore savepoints for singleplayer" );
|
|
|
|
|
sv_rollangle = Cvar_Get( "sv_rollangle", DEFAULT_ROLLANGLE, 0, "how much to tilt the view when strafing" );
|
|
|
|
|
sv_rollspeed = Cvar_Get( "sv_rollspeed", DEFAULT_ROLLSPEED, 0, "how much strafing is necessary to tilt the view" );
|
|
|
|
|
sv_airaccelerate = Cvar_Get("sv_airaccelerate", DEFAULT_AIRACCEL, CVAR_LATCH, "player accellerate in air" );
|
2009-09-13 22:00:00 +02:00
|
|
|
|
sv_idealpitchscale = Cvar_Get( "sv_idealpitchscale", "0.8", 0, "how much to look up/down slopes and stairs when not using freelook" );
|
2009-01-11 22:00:00 +01:00
|
|
|
|
sv_maxvelocity = Cvar_Get("sv_maxvelocity", DEFAULT_MAXVELOCITY, CVAR_LATCH, "max world velocity" );
|
|
|
|
|
sv_gravity = Cvar_Get("sv_gravity", DEFAULT_GRAVITY, CVAR_LATCH, "world gravity" );
|
2009-01-22 22:00:00 +01:00
|
|
|
|
sv_maxspeed = Cvar_Get("sv_maxspeed", DEFAULT_MAXSPEED, 0, "maximum speed a player can accelerate to when on ground");
|
|
|
|
|
sv_accelerate = Cvar_Get( "sv_accelerate", DEFAULT_ACCEL, 0, "rate at which a player accelerates to sv_maxspeed" );
|
|
|
|
|
sv_friction = Cvar_Get( "sv_friction", DEFAULT_FRICTION, 0, "how fast you slow down" );
|
2008-11-28 22:00:00 +01:00
|
|
|
|
sv_physics = Cvar_Get( "cm_physic", "1", CVAR_ARCHIVE|CVAR_LATCH, "change physic model: 0 - Classic Quake Physic, 1 - Physics Engine" );
|
2009-09-17 22:00:00 +02:00
|
|
|
|
sv_showclamp = Cvar_Get( "sv_showclamp", "1", 0, "show server time clamping" );
|
2007-09-06 22:00:00 +02:00
|
|
|
|
|
2008-06-29 22:00:00 +02:00
|
|
|
|
public_server = Cvar_Get ("public", "0", 0, "change server type from private to public" );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-07-11 22:00:00 +02:00
|
|
|
|
sv_reconnect_limit = Cvar_Get ("sv_reconnect_limit", "3", CVAR_ARCHIVE, "max reconnect attempts" );
|
2008-12-26 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
// init game
|
|
|
|
|
SV_LoadProgs( "server" );
|
2009-06-22 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
MSG_Init( &net_message, net_message_buffer, sizeof( net_message_buffer ));
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
==================
|
|
|
|
|
SV_FinalMessage
|
|
|
|
|
|
|
|
|
|
Used by SV_Shutdown to send a final message to all
|
|
|
|
|
connected clients before the server goes down. The messages are sent immediately,
|
|
|
|
|
not just stuck on the outgoing message list, because the server is going
|
|
|
|
|
to totally exit after returning from this function.
|
|
|
|
|
==================
|
|
|
|
|
*/
|
2008-08-02 22:00:00 +02:00
|
|
|
|
void SV_FinalMessage( char *message, bool reconnect )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2008-07-09 22:00:00 +02:00
|
|
|
|
sv_client_t *cl;
|
2008-07-12 22:00:00 +02:00
|
|
|
|
byte msg_buf[MAX_MSGLEN];
|
|
|
|
|
sizebuf_t msg;
|
|
|
|
|
int i;
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-12-25 22:00:00 +01:00
|
|
|
|
MSG_Init( &msg, msg_buf, sizeof( msg_buf ));
|
2008-07-12 22:00:00 +02:00
|
|
|
|
MSG_WriteByte( &msg, svc_print );
|
|
|
|
|
MSG_WriteString( &msg, message );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-07-12 22:00:00 +02:00
|
|
|
|
if( reconnect )
|
2007-08-01 22:00:00 +02:00
|
|
|
|
{
|
2008-07-12 22:00:00 +02:00
|
|
|
|
MSG_WriteByte( &msg, svc_reconnect );
|
2007-08-01 22:00:00 +02:00
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
else
|
2007-08-01 22:00:00 +02:00
|
|
|
|
{
|
2008-07-12 22:00:00 +02:00
|
|
|
|
MSG_WriteByte( &msg, svc_disconnect );
|
2007-08-01 22:00:00 +02:00
|
|
|
|
}
|
2008-07-12 22:00:00 +02:00
|
|
|
|
|
2007-06-21 22:00:00 +02:00
|
|
|
|
// send it twice
|
|
|
|
|
// stagger the packets to crutch operating system limited buffers
|
2008-07-31 22:00:00 +02:00
|
|
|
|
for( i = 0, cl = svs.clients; i < Host_MaxClients(); i++, cl++ )
|
2009-06-24 22:00:00 +02:00
|
|
|
|
if( cl->state >= cs_connected && !(cl->edict && cl->edict->v.flags & FL_FAKECLIENT ))
|
2008-07-12 22:00:00 +02:00
|
|
|
|
Netchan_Transmit( &cl->netchan, msg.cursize, msg.data );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2008-07-31 22:00:00 +02:00
|
|
|
|
for( i = 0, cl = svs.clients; i < Host_MaxClients(); i++, cl++ )
|
2009-06-24 22:00:00 +02:00
|
|
|
|
if( cl->state >= cs_connected && !(cl->edict && cl->edict->v.flags & FL_FAKECLIENT ))
|
2008-07-12 22:00:00 +02:00
|
|
|
|
Netchan_Transmit( &cl->netchan, msg.cursize, msg.data );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
================
|
|
|
|
|
SV_Shutdown
|
|
|
|
|
|
|
|
|
|
Called when each game quits,
|
|
|
|
|
before Sys_Quit or Sys_Error
|
|
|
|
|
================
|
|
|
|
|
*/
|
2007-11-21 22:00:00 +01:00
|
|
|
|
void SV_Shutdown( bool reconnect )
|
2007-06-21 22:00:00 +02:00
|
|
|
|
{
|
2007-10-29 22:00:00 +01:00
|
|
|
|
// already freed
|
2008-08-04 22:00:00 +02:00
|
|
|
|
if( host.state == HOST_ERROR ) return;
|
|
|
|
|
if( !svs.initialized ) return;
|
2007-10-29 22:00:00 +01:00
|
|
|
|
|
2008-08-02 22:00:00 +02:00
|
|
|
|
MsgDev( D_INFO, "SV_Shutdown: %s\n", host.finalmsg );
|
2008-12-15 22:00:00 +01:00
|
|
|
|
if( svs.clients ) SV_FinalMessage( host.finalmsg, reconnect );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
2007-11-21 22:00:00 +01:00
|
|
|
|
Master_Shutdown();
|
2009-01-09 22:00:00 +01:00
|
|
|
|
if( reconnect )
|
2008-12-26 22:00:00 +01:00
|
|
|
|
SV_FreeEdicts();
|
|
|
|
|
else SV_UnloadProgs();
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// free current level
|
2008-12-15 22:00:00 +01:00
|
|
|
|
Mem_Set( &sv, 0, sizeof( sv ));
|
2008-08-04 22:00:00 +02:00
|
|
|
|
Host_SetServerState( sv.state );
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// free server static data
|
2008-07-17 22:00:00 +02:00
|
|
|
|
if( svs.clients ) Mem_Free( svs.clients );
|
|
|
|
|
if( svs.baselines ) Mem_Free( svs.baselines );
|
|
|
|
|
if( svs.client_entities ) Mem_Free( svs.client_entities );
|
2008-12-15 22:00:00 +01:00
|
|
|
|
Mem_Set( &svs, 0, sizeof( svs ));
|
2009-01-02 22:00:00 +01:00
|
|
|
|
}
|