summaryrefslogtreecommitdiff
path: root/src/sv_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sv_main.c')
-rw-r--r--src/sv_main.c1261
1 files changed, 649 insertions, 612 deletions
diff --git a/src/sv_main.c b/src/sv_main.c
index 671acf6..9c9b503 100644
--- a/src/sv_main.c
+++ b/src/sv_main.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -22,13 +22,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
pmoveParams_t sv_pmp;
-LIST_DECL( sv_masterlist ); // address of group servers
-LIST_DECL( sv_banlist );
-LIST_DECL( sv_blacklist );
-LIST_DECL( sv_cmdlist_connect );
-LIST_DECL( sv_cmdlist_begin );
-LIST_DECL( sv_filterlist );
-LIST_DECL( sv_clientlist ); // linked list of non-free clients
+LIST_DECL(sv_masterlist); // address of group servers
+LIST_DECL(sv_banlist);
+LIST_DECL(sv_blacklist);
+LIST_DECL(sv_cmdlist_connect);
+LIST_DECL(sv_cmdlist_begin);
+LIST_DECL(sv_filterlist);
+LIST_DECL(sv_clientlist); // linked list of non-free clients
client_t *sv_client; // current client
edict_t *sv_player; // current client edict
@@ -100,57 +100,59 @@ qboolean sv_registered;
//============================================================================
-void SV_RemoveClient( client_t *client ) {
- if( client->msg_pool ) {
- SV_ShutdownClientSend( client );
+void SV_RemoveClient(client_t *client)
+{
+ if (client->msg_pool) {
+ SV_ShutdownClientSend(client);
}
- if( client->netchan ) {
- Netchan_Close( client->netchan );
+ if (client->netchan) {
+ Netchan_Close(client->netchan);
client->netchan = NULL;
}
// unlink them from active client list, but don't clear the list entry
// itself to make code that traverses client list in a loop happy!
- List_Remove( &client->entry );
+ List_Remove(&client->entry);
#if USE_MVD_CLIENT
// unlink them from MVD client list
- if( sv.state == ss_broadcast ) {
- MVD_RemoveClient( client );
+ if (sv.state == ss_broadcast) {
+ MVD_RemoveClient(client);
}
#endif
- Com_DPrintf( "Going from cs_zombie to cs_free for %s\n", client->name );
+ Com_DPrintf("Going from cs_zombie to cs_free for %s\n", client->name);
client->state = cs_free; // can now be reused
client->name[0] = 0;
}
-void SV_CleanClient( client_t *client ) {
+void SV_CleanClient(client_t *client)
+{
int i;
#if USE_AC_SERVER
string_entry_t *bad, *next;
- for( bad = client->ac_bad_files; bad; bad = next ) {
+ for (bad = client->ac_bad_files; bad; bad = next) {
next = bad->next;
- Z_Free( bad );
+ Z_Free(bad);
}
client->ac_bad_files = NULL;
#endif
// close any existing donwload
- SV_CloseDownload( client );
+ SV_CloseDownload(client);
- if( client->versionString ) {
- Z_Free( client->versionString );
+ if (client->versionString) {
+ Z_Free(client->versionString);
client->versionString = NULL;
}
// free baselines allocated for this client
- for( i = 0; i < SV_BASELINES_CHUNKS; i++ ) {
- if( client->baselines[i] ) {
- Z_Free( client->baselines[i] );
+ for (i = 0; i < SV_BASELINES_CHUNKS; i++) {
+ if (client->baselines[i]) {
+ Z_Free(client->baselines[i]);
client->baselines[i] = NULL;
}
}
@@ -165,73 +167,74 @@ or unwillingly. This is NOT called if the entire server is quiting
or crashing.
=====================
*/
-void SV_DropClient( client_t *client, const char *reason ) {
+void SV_DropClient(client_t *client, const char *reason)
+{
int oldstate = client->state;
- if( client->state <= cs_zombie ) {
+ if (client->state <= cs_zombie) {
return; // called recursively?
}
client->state = cs_zombie; // become free in a few seconds
client->lastmessage = svs.realtime;
- if( reason ) {
+ if (reason) {
qboolean announce = oldstate == cs_spawned ? 2 : 1;
const char *prefix = " was dropped: ";
// parse flags
- if( *reason == '!' ) {
+ if (*reason == '!') {
reason++;
announce = 0;
}
- if( *reason == '?' ) {
+ if (*reason == '?') {
reason++;
prefix = " ";
}
- if( announce == 2 ) {
+ if (announce == 2) {
// announce to others
#if USE_MVD_CLIENT
- if( sv.state == ss_broadcast )
- MVD_GameClientDrop( client->edict, prefix, reason );
+ if (sv.state == ss_broadcast)
+ MVD_GameClientDrop(client->edict, prefix, reason);
else
#endif
- SV_BroadcastPrintf( PRINT_HIGH, "%s%s%s\n",
- client->name, prefix, reason );
+ SV_BroadcastPrintf(PRINT_HIGH, "%s%s%s\n",
+ client->name, prefix, reason);
}
- if( announce )
+ if (announce)
// print this to client as they will not receive broadcast
- SV_ClientPrintf( client, PRINT_HIGH, "%s%s%s\n",
- client->name, prefix, reason );
+ SV_ClientPrintf(client, PRINT_HIGH, "%s%s%s\n",
+ client->name, prefix, reason);
// print to server console
- if( Com_IsDedicated() && client->netchan )
- Com_Printf( "%s[%s]%s%s\n", client->name,
- NET_AdrToString( &client->netchan->remote_address ), prefix, reason );
+ if (Com_IsDedicated() && client->netchan)
+ Com_Printf("%s[%s]%s%s\n", client->name,
+ NET_AdrToString(&client->netchan->remote_address), prefix, reason);
}
// add the disconnect
- MSG_WriteByte( svc_disconnect );
- SV_ClientAddMessage( client, MSG_RELIABLE|MSG_CLEAR );
+ MSG_WriteByte(svc_disconnect);
+ SV_ClientAddMessage(client, MSG_RELIABLE | MSG_CLEAR);
- if( oldstate == cs_spawned || ( g_features->integer & GMF_WANT_ALL_DISCONNECTS ) ) {
+ if (oldstate == cs_spawned || (g_features->integer & GMF_WANT_ALL_DISCONNECTS)) {
// call the prog function for removing a client
// this will remove the body, among other things
- ge->ClientDisconnect( client->edict );
+ ge->ClientDisconnect(client->edict);
}
#if USE_AC_SERVER
- AC_ClientDisconnect( client );
+ AC_ClientDisconnect(client);
#endif
- SV_CleanClient( client );
+ SV_CleanClient(client);
- Com_DPrintf( "Going to cs_zombie for %s\n", client->name );
+ Com_DPrintf("Going to cs_zombie for %s\n", client->name);
#if USE_MVD_SERVER
// give MVD server a chance to detect if it's dummy client was dropped
- SV_MvdClientDropped( client );
+ SV_MvdClientDropped(client);
#endif
}
@@ -244,17 +247,18 @@ CONNECTIONLESS COMMANDS
==============================================================================
*/
-static qboolean SV_RateLimited( ratelimit_t *r ) {
- if( !r->limit ) {
+static qboolean SV_RateLimited(ratelimit_t *r)
+{
+ if (!r->limit) {
return qfalse;
}
- if( svs.realtime - r->time > r->period ) {
+ if (svs.realtime - r->time > r->period) {
r->count = 0;
r->time = svs.realtime;
return qfalse;
}
- if( r->count < r->limit ) {
+ if (r->count < r->limit) {
return qfalse;
}
@@ -262,28 +266,29 @@ static qboolean SV_RateLimited( ratelimit_t *r ) {
}
// <limit>[/<period>[sec|min|hour]]
-static void SV_RateInit( ratelimit_t *r, const char *s ) {
+static void SV_RateInit(ratelimit_t *r, const char *s)
+{
unsigned limit;
unsigned period, scale;
char *p;
- limit = strtoul( s, &p, 10 );
- if( *p == '/' ) {
- period = strtoul( p + 1, &p, 10 );
- if( *p == 0 || *p == 's' || *p == 'S' ) {
+ limit = strtoul(s, &p, 10);
+ if (*p == '/') {
+ period = strtoul(p + 1, &p, 10);
+ if (*p == 0 || *p == 's' || *p == 'S') {
scale = 1000;
- } else if( *p == 'm' || *p == 'M' ) {
- scale = 60*1000;
- } else if( *p == 'h' || *p == 'H' ) {
- scale = 60*60*1000;
+ } else if (*p == 'm' || *p == 'M') {
+ scale = 60 * 1000;
+ } else if (*p == 'h' || *p == 'H') {
+ scale = 60 * 60 * 1000;
} else {
// everything else is milliseconds
scale = 1;
}
- if( period > UINT_MAX / scale ) {
+ if (period > UINT_MAX / scale) {
period = UINT_MAX;
} else {
- if( !period ) {
+ if (!period) {
period = 1;
}
period *= scale;
@@ -299,13 +304,14 @@ static void SV_RateInit( ratelimit_t *r, const char *s ) {
r->period = period;
}
-addrmatch_t *SV_MatchAddress( list_t *list, netadr_t *addr ) {
+addrmatch_t *SV_MatchAddress(list_t *list, netadr_t *addr)
+{
addrmatch_t *match;
- LIST_FOR_EACH( addrmatch_t, match, list, entry ) {
- if( ( addr->ip.u32 & match->mask ) == ( match->addr.u32 & match->mask ) ) {
+ LIST_FOR_EACH(addrmatch_t, match, list, entry) {
+ if ((addr->ip.u32 & match->mask) == (match->addr.u32 & match->mask)) {
match->hits++;
- match->time = time( NULL );
+ match->time = time(NULL);
return match;
}
}
@@ -321,34 +327,35 @@ Builds the string that is sent as heartbeats and status replies.
It is assumed that size of status buffer is at least SV_OUTPUTBUF_LENGTH!
===============
*/
-static size_t SV_StatusString( char *status ) {
+static size_t SV_StatusString(char *status)
+{
char entry[MAX_STRING_CHARS];
client_t *cl;
size_t total, len;
char *tmp = sv_maxclients->string;
// XXX: ugly hack to hide reserved slots
- if( sv_reserved_slots->integer ) {
- Q_snprintf( entry, sizeof( entry ), "%d",
- sv_maxclients->integer - sv_reserved_slots->integer );
+ if (sv_reserved_slots->integer) {
+ Q_snprintf(entry, sizeof(entry), "%d",
+ sv_maxclients->integer - sv_reserved_slots->integer);
sv_maxclients->string = entry;
}
// add server info
- total = Cvar_BitInfo( status, CVAR_SERVERINFO );
+ total = Cvar_BitInfo(status, CVAR_SERVERINFO);
sv_maxclients->string = tmp;
// add uptime
- if( sv_uptime->integer > 0 ) {
- if( sv_uptime->integer > 1 ) {
- len = Com_UptimeLong_m( entry, MAX_INFO_VALUE );
+ if (sv_uptime->integer > 0) {
+ if (sv_uptime->integer > 1) {
+ len = Com_UptimeLong_m(entry, MAX_INFO_VALUE);
} else {
- len = Com_Uptime_m( entry, MAX_INFO_VALUE );
+ len = Com_Uptime_m(entry, MAX_INFO_VALUE);
}
- if( total + 8 + len < MAX_INFO_STRING ) {
- memcpy( status + total, "\\uptime\\", 8 );
- memcpy( status + total + 8, entry, len );
+ if (total + 8 + len < MAX_INFO_STRING) {
+ memcpy(status + total, "\\uptime\\", 8);
+ memcpy(status + total + 8, entry, len);
total += 8 + len;
}
}
@@ -356,22 +363,22 @@ static size_t SV_StatusString( char *status ) {
status[total++] = '\n';
// add player list
- if( sv_status_show->integer > 1 ) {
- FOR_EACH_CLIENT( cl ) {
- if( cl->state == cs_zombie ) {
+ if (sv_status_show->integer > 1) {
+ FOR_EACH_CLIENT(cl) {
+ if (cl->state == cs_zombie) {
continue;
}
- len = Q_snprintf( entry, sizeof( entry ),
- "%i %i \"%s\"\n",
- cl->edict->client->ps.stats[STAT_FRAGS],
- cl->ping, cl->name );
- if( len >= sizeof( entry ) ) {
+ len = Q_snprintf(entry, sizeof(entry),
+ "%i %i \"%s\"\n",
+ cl->edict->client->ps.stats[STAT_FRAGS],
+ cl->ping, cl->name);
+ if (len >= sizeof(entry)) {
continue;
}
- if( total + len >= SV_OUTPUTBUF_LENGTH ) {
+ if (total + len >= SV_OUTPUTBUF_LENGTH) {
break; // can't hold any more
}
- memcpy( status + total, entry, len );
+ memcpy(status + total, entry, len);
total += len;
}
}
@@ -388,30 +395,31 @@ SVC_Status
Responds with all the info that qplug or qspy can see
================
*/
-static void SVC_Status( void ) {
+static void SVC_Status(void)
+{
char buffer[MAX_PACKETLEN_DEFAULT];
size_t len;
- if( !sv_status_show->integer ) {
+ if (!sv_status_show->integer) {
return;
}
- if( SV_RateLimited( &svs.ratelimit_status ) ) {
- Com_DPrintf( "Dropping status request from %s\n",
- NET_AdrToString( &net_from ) );
+ if (SV_RateLimited(&svs.ratelimit_status)) {
+ Com_DPrintf("Dropping status request from %s\n",
+ NET_AdrToString(&net_from));
return;
}
svs.ratelimit_status.count++;
// write the packet header
- memcpy( buffer, "\xff\xff\xff\xffprint\n", 10 );
+ memcpy(buffer, "\xff\xff\xff\xffprint\n", 10);
len = 10;
- len += SV_StatusString( buffer + len );
+ len += SV_StatusString(buffer + len);
// send the datagram
- NET_SendPacket( NS_SERVER, &net_from, len, buffer );
+ NET_SendPacket(NS_SERVER, &net_from, len, buffer);
}
/*
@@ -420,16 +428,17 @@ SVC_Ack
================
*/
-static void SVC_Ack( void ) {
+static void SVC_Ack(void)
+{
master_t *m;
- FOR_EACH_MASTER( m ) {
- if( !m->adr.port ) {
+ FOR_EACH_MASTER(m) {
+ if (!m->adr.port) {
continue;
}
- if( NET_IsEqualBaseAdr( &m->adr, &net_from ) ) {
- Com_DPrintf( "Ping acknowledge from %s\n",
- NET_AdrToString( &net_from ) );
+ if (NET_IsEqualBaseAdr(&m->adr, &net_from)) {
+ Com_DPrintf("Ping acknowledge from %s\n",
+ NET_AdrToString(&net_from));
m->last_ack = svs.realtime;
break;
}
@@ -444,7 +453,8 @@ Responds with short info for broadcast scans
The second parameter should be the current protocol version number.
================
*/
-static void SVC_Info( void ) {
+static void SVC_Info(void)
+{
char string[MAX_QPATH];
size_t len;
int count;
@@ -453,23 +463,23 @@ static void SVC_Info( void ) {
if (sv_maxclients->integer == 1)
return; // ignore in single player
- version = atoi (Cmd_Argv(1));
+ version = atoi(Cmd_Argv(1));
if (version != PROTOCOL_VERSION_DEFAULT) {
return;
}
-
+
count = SV_CountClients();
- len = Q_snprintf (string, sizeof(string),
- "\xff\xff\xff\xffinfo\n%16s %8s %2i/%2i\n",
- sv_hostname->string, sv.name, count, sv_maxclients->integer -
- sv_reserved_slots->integer );
- if( len >= sizeof( string ) ) {
+ len = Q_snprintf(string, sizeof(string),
+ "\xff\xff\xff\xffinfo\n%16s %8s %2i/%2i\n",
+ sv_hostname->string, sv.name, count, sv_maxclients->integer -
+ sv_reserved_slots->integer);
+ if (len >= sizeof(string)) {
return;
}
-
- NET_SendPacket( NS_SERVER, &net_from, len, string );
+
+ NET_SendPacket(NS_SERVER, &net_from, len, string);
}
/*
@@ -479,8 +489,9 @@ SVC_Ping
Just responds with an acknowledgement
================
*/
-static void SVC_Ping( void ) {
- OOB_PRINT( NS_SERVER, &net_from, "ack" );
+static void SVC_Ping(void)
+{
+ OOB_PRINT(NS_SERVER, &net_from, "ack");
}
/*
@@ -494,7 +505,8 @@ flood the server with invalid connection IPs. With a
challenge, they must give a valid IP address.
=================
*/
-static void SVC_GetChallenge( void ) {
+static void SVC_GetChallenge(void)
+{
int i, oldest;
unsigned challenge;
unsigned oldestTime;
@@ -503,20 +515,20 @@ static void SVC_GetChallenge( void ) {
oldestTime = 0xffffffff;
// see if we already have a challenge for this ip
- for( i = 0; i < MAX_CHALLENGES; i++ ) {
- if( NET_IsEqualBaseAdr( &net_from, &svs.challenges[i].adr ) )
+ for (i = 0; i < MAX_CHALLENGES; i++) {
+ if (NET_IsEqualBaseAdr(&net_from, &svs.challenges[i].adr))
break;
- if( svs.challenges[i].time > com_eventTime ) {
+ if (svs.challenges[i].time > com_eventTime) {
svs.challenges[i].time = com_eventTime;
}
- if( svs.challenges[i].time < oldestTime ) {
+ if (svs.challenges[i].time < oldestTime) {
oldestTime = svs.challenges[i].time;
oldest = i;
}
}
- challenge = ( ( rand() << 16 ) | rand() ) & 0x7fffffff;
- if( i == MAX_CHALLENGES ) {
+ challenge = ((rand() << 16) | rand()) & 0x7fffffff;
+ if (i == MAX_CHALLENGES) {
// overwrite the oldest
svs.challenges[oldest].challenge = challenge;
svs.challenges[oldest].adr = net_from;
@@ -527,23 +539,24 @@ static void SVC_GetChallenge( void ) {
}
// send it back
- Netchan_OutOfBand( NS_SERVER, &net_from,
- "challenge %u p=34,35,36", challenge );
+ Netchan_OutOfBand(NS_SERVER, &net_from,
+ "challenge %u p=34,35,36", challenge);
}
-static void send_redirect_hack( const char *addr ) {
- Netchan_OutOfBand( NS_SERVER, &net_from, "client_connect" );
-
- MSG_WriteLong( 1 );
- MSG_WriteLong( 0 );
- MSG_WriteByte( svc_print );
- MSG_WriteByte( PRINT_HIGH );
- MSG_WriteString( va( "Server is full. Redirecting you to %s...\n", addr ) );
- MSG_WriteByte( svc_stufftext );
- MSG_WriteString( va( "connect %s\n", addr ) );
-
- NET_SendPacket( NS_SERVER, &net_from, msg_write.cursize, msg_write.data );
- SZ_Clear( &msg_write );
+static void send_redirect_hack(const char *addr)
+{
+ Netchan_OutOfBand(NS_SERVER, &net_from, "client_connect");
+
+ MSG_WriteLong(1);
+ MSG_WriteLong(0);
+ MSG_WriteByte(svc_print);
+ MSG_WriteByte(PRINT_HIGH);
+ MSG_WriteString(va("Server is full. Redirecting you to %s...\n", addr));
+ MSG_WriteByte(svc_stufftext);
+ MSG_WriteString(va("connect %s\n", addr));
+
+ NET_SendPacket(NS_SERVER, &net_from, msg_write.cursize, msg_write.data);
+ SZ_Clear(&msg_write);
}
#define SV_OobPrintf(...) \
@@ -556,7 +569,8 @@ SVC_DirectConnect
A connection request that did not come from the master
==================
*/
-static void SVC_DirectConnect( void ) {
+static void SVC_DirectConnect(void)
+{
char userinfo[MAX_INFO_STRING];
char reconnect_var[16];
char reconnect_val[16];
@@ -574,69 +588,67 @@ static void SVC_DirectConnect( void ) {
int reserved;
qboolean has_zlib;
- protocol = atoi( Cmd_Argv( 1 ) );
- qport = atoi( Cmd_Argv( 2 ) ) ;
- challenge = atoi( Cmd_Argv( 3 ) );
+ protocol = atoi(Cmd_Argv(1));
+ qport = atoi(Cmd_Argv(2)) ;
+ challenge = atoi(Cmd_Argv(3));
- Com_DPrintf( "%s: protocol=%i, qport=%i, challenge=%i\n",
- __func__, protocol, qport, challenge );
+ Com_DPrintf("%s: protocol=%i, qport=%i, challenge=%i\n",
+ __func__, protocol, qport, challenge);
- if( protocol < PROTOCOL_VERSION_DEFAULT ||
- protocol > PROTOCOL_VERSION_Q2PRO )
- {
- SV_OobPrintf( "Unsupported protocol version %d.\n", protocol );
- Com_DPrintf( " rejected connect with protocol %i\n", protocol );
+ if (protocol < PROTOCOL_VERSION_DEFAULT ||
+ protocol > PROTOCOL_VERSION_Q2PRO) {
+ SV_OobPrintf("Unsupported protocol version %d.\n", protocol);
+ Com_DPrintf(" rejected connect with protocol %i\n", protocol);
return;
}
- if( !NET_IsLocalAddress( &net_from ) ) {
+ if (!NET_IsLocalAddress(&net_from)) {
addrmatch_t *match;
// see if the challenge is valid
- for( i = 0; i < MAX_CHALLENGES; i++ ) {
- if( !svs.challenges[i].challenge ) {
+ for (i = 0; i < MAX_CHALLENGES; i++) {
+ if (!svs.challenges[i].challenge) {
continue;
}
- if( NET_IsEqualBaseAdr( &net_from, &svs.challenges[i].adr ) ) {
- if( svs.challenges[i].challenge == challenge )
+ if (NET_IsEqualBaseAdr(&net_from, &svs.challenges[i].adr)) {
+ if (svs.challenges[i].challenge == challenge)
break; // good
- SV_OobPrintf( "Bad challenge.\n" );
- Com_DPrintf( " rejected - bad challenge.\n" );
+ SV_OobPrintf("Bad challenge.\n");
+ Com_DPrintf(" rejected - bad challenge.\n");
return;
}
}
- if( i == MAX_CHALLENGES ) {
- SV_OobPrintf( "No challenge for address.\n" );
- Com_DPrintf( " rejected - no challenge.\n" );
+ if (i == MAX_CHALLENGES) {
+ SV_OobPrintf("No challenge for address.\n");
+ Com_DPrintf(" rejected - no challenge.\n");
return;
}
svs.challenges[i].challenge = 0;
// check for banned address
- if( ( match = SV_MatchAddress( &sv_banlist, &net_from ) ) != NULL ) {
+ if ((match = SV_MatchAddress(&sv_banlist, &net_from)) != NULL) {
s = match->comment;
- if( !*s ) {
+ if (!*s) {
s = "Your IP address is banned from this server.";
}
- SV_OobPrintf( "%s\nConnection refused.\n", s );
- Com_DPrintf( " rejected connect from banned IP\n" );
+ SV_OobPrintf("%s\nConnection refused.\n", s);
+ Com_DPrintf(" rejected connect from banned IP\n");
return;
}
- if( sv_locked->integer ) {
- SV_OobPrintf( "Server is locked.\n" );
- Com_DPrintf( " rejected - server is locked.\n" );
+ if (sv_locked->integer) {
+ SV_OobPrintf("Server is locked.\n");
+ Com_DPrintf(" rejected - server is locked.\n");
return;
}
// limit number of connections from single IP
- if( sv_iplimit->integer > 0 ) {
+ if (sv_iplimit->integer > 0) {
count = 0;
- FOR_EACH_CLIENT( cl ) {
- if( NET_IsEqualBaseAdr( &net_from,
- &cl->netchan->remote_address ) )
- {
- if( cl->state == cs_zombie ) {
+ FOR_EACH_CLIENT(cl) {
+ if (NET_IsEqualBaseAdr(&net_from,
+ &cl->netchan->remote_address)) {
+ if (cl->state == cs_zombie) {
count++;
} else {
count += 2;
@@ -644,9 +656,9 @@ static void SVC_DirectConnect( void ) {
}
}
count >>= 1;
- if( count >= sv_iplimit->integer ) {
- SV_OobPrintf( "Too many connections from your IP address.\n" );
- Com_DPrintf( " rejected - %d connections from this IP.\n", count );
+ if (count >= sv_iplimit->integer) {
+ SV_OobPrintf("Too many connections from your IP address.\n");
+ Com_DPrintf(" rejected - %d connections from this IP.\n", count);
return;
}
}
@@ -655,55 +667,55 @@ static void SVC_DirectConnect( void ) {
// set maximum message length
maxlength = MAX_PACKETLEN_WRITABLE_DEFAULT;
has_zlib = qfalse;
- if( protocol >= PROTOCOL_VERSION_R1Q2 ) {
+ if (protocol >= PROTOCOL_VERSION_R1Q2) {
has_zlib = qtrue;
- s = Cmd_Argv( 5 );
- if( *s ) {
- maxlength = atoi( s );
- if( maxlength < 0 || maxlength > MAX_PACKETLEN_WRITABLE ) {
- SV_OobPrintf( "Invalid maximum message length.\n" );
- Com_DPrintf( " rejected - bad maxmsglen.\n" );
+ s = Cmd_Argv(5);
+ if (*s) {
+ maxlength = atoi(s);
+ if (maxlength < 0 || maxlength > MAX_PACKETLEN_WRITABLE) {
+ SV_OobPrintf("Invalid maximum message length.\n");
+ Com_DPrintf(" rejected - bad maxmsglen.\n");
return;
}
- if( !maxlength ) {
+ if (!maxlength) {
maxlength = MAX_PACKETLEN_WRITABLE;
- } else if( maxlength < MIN_PACKETLEN ) {
+ } else if (maxlength < MIN_PACKETLEN) {
maxlength = MIN_PACKETLEN;
}
}
}
- if( !NET_IsLocalAddress( &net_from ) ) {
+ if (!NET_IsLocalAddress(&net_from)) {
// cap maximum message length for real connections
- if( net_maxmsglen->integer > 0 && maxlength > net_maxmsglen->integer ) {
+ if (net_maxmsglen->integer > 0 && maxlength > net_maxmsglen->integer) {
maxlength = net_maxmsglen->integer;
}
}
- if( protocol == PROTOCOL_VERSION_R1Q2 ) {
+ if (protocol == PROTOCOL_VERSION_R1Q2) {
// set minor protocol version
- s = Cmd_Argv( 6 );
- if( *s ) {
- version = atoi( s );
- clamp( version, PROTOCOL_VERSION_R1Q2_MINIMUM,
- PROTOCOL_VERSION_R1Q2_CURRENT );
+ s = Cmd_Argv(6);
+ if (*s) {
+ version = atoi(s);
+ clamp(version, PROTOCOL_VERSION_R1Q2_MINIMUM,
+ PROTOCOL_VERSION_R1Q2_CURRENT);
} else {
version = PROTOCOL_VERSION_R1Q2_MINIMUM;
}
nctype = NETCHAN_OLD;
ncstring = "";
- } else if( protocol == PROTOCOL_VERSION_Q2PRO ) {
+ } else if (protocol == PROTOCOL_VERSION_Q2PRO) {
// set netchan type
- s = Cmd_Argv( 6 );
- if( *s ) {
- nctype = atoi( s );
- if( nctype == NETCHAN_OLD ) {
+ s = Cmd_Argv(6);
+ if (*s) {
+ nctype = atoi(s);
+ if (nctype == NETCHAN_OLD) {
ncstring = " nc=0";
- } else if( nctype == NETCHAN_NEW ) {
+ } else if (nctype == NETCHAN_NEW) {
ncstring = " nc=1";
} else {
- SV_OobPrintf( "Invalid netchan type.\n" );
- Com_DPrintf( " rejected - bad nctype.\n" );
+ SV_OobPrintf("Invalid netchan type.\n");
+ Com_DPrintf(" rejected - bad nctype.\n");
return;
}
} else {
@@ -712,18 +724,18 @@ static void SVC_DirectConnect( void ) {
}
// set zlib
- s = Cmd_Argv( 7 );
- if( *s && !atoi( s ) ) {
+ s = Cmd_Argv(7);
+ if (*s && !atoi(s)) {
has_zlib = qfalse;
}
// set minor protocol version
- s = Cmd_Argv( 8 );
- if( *s ) {
- version = atoi( s );
- clamp( version, PROTOCOL_VERSION_Q2PRO_MINIMUM,
- PROTOCOL_VERSION_Q2PRO_CURRENT );
- if( version == PROTOCOL_VERSION_Q2PRO_RESERVED ) {
+ s = Cmd_Argv(8);
+ if (*s) {
+ version = atoi(s);
+ clamp(version, PROTOCOL_VERSION_Q2PRO_MINIMUM,
+ PROTOCOL_VERSION_Q2PRO_CURRENT);
+ if (version == PROTOCOL_VERSION_Q2PRO_RESERVED) {
version--; // never use this version
}
} else {
@@ -736,70 +748,69 @@ static void SVC_DirectConnect( void ) {
}
// validate userinfo
- info = Cmd_Argv( 4 );
- if( !info[0] ) {
- SV_OobPrintf( "Empty userinfo string.\n" );
- Com_DPrintf( " rejected - empty userinfo.\n" );
+ info = Cmd_Argv(4);
+ if (!info[0]) {
+ SV_OobPrintf("Empty userinfo string.\n");
+ Com_DPrintf(" rejected - empty userinfo.\n");
return;
}
- if( !Info_Validate( info ) ) {
- SV_OobPrintf( "Malformed userinfo string.\n" );
- Com_DPrintf( " rejected - malformed userinfo.\n" );
+ if (!Info_Validate(info)) {
+ SV_OobPrintf("Malformed userinfo string.\n");
+ Com_DPrintf(" rejected - malformed userinfo.\n");
return;
}
- s = Info_ValueForKey( info, "name" );
- if( COM_IsWhite( s ) ) {
- SV_OobPrintf( "Please set your name before connecting.\n" );
- Com_DPrintf( " rejected - empty name.\n" );
+ s = Info_ValueForKey(info, "name");
+ if (COM_IsWhite(s)) {
+ SV_OobPrintf("Please set your name before connecting.\n");
+ Com_DPrintf(" rejected - empty name.\n");
return;
}
// check password
- s = Info_ValueForKey( info, "password" );
+ s = Info_ValueForKey(info, "password");
reserved = 0;
- if( sv_password->string[0] ) {
- if( !s[0] ) {
- SV_OobPrintf( "Please set your password before connecting.\n" );
- Com_DPrintf( " rejected - empty password.\n" );
+ if (sv_password->string[0]) {
+ if (!s[0]) {
+ SV_OobPrintf("Please set your password before connecting.\n");
+ Com_DPrintf(" rejected - empty password.\n");
return;
}
- if( SV_RateLimited( &svs.ratelimit_auth ) ) {
- SV_OobPrintf( "Invalid password.\n" );
- Com_DPrintf( " rejected - auth attempt limit exceeded.\n" );
+ if (SV_RateLimited(&svs.ratelimit_auth)) {
+ SV_OobPrintf("Invalid password.\n");
+ Com_DPrintf(" rejected - auth attempt limit exceeded.\n");
return;
}
- if( strcmp( sv_password->string, s ) ) {
+ if (strcmp(sv_password->string, s)) {
svs.ratelimit_auth.count++;
- SV_OobPrintf( "Invalid password.\n" );
- Com_DPrintf( " rejected - invalid password.\n" );
+ SV_OobPrintf("Invalid password.\n");
+ Com_DPrintf(" rejected - invalid password.\n");
return;
}
// allow them to use reserved slots
- } else if( !sv_reserved_password->string[0] ||
- strcmp( sv_reserved_password->string, s ) )
- {
+ } else if (!sv_reserved_password->string[0] ||
+ strcmp(sv_reserved_password->string, s)) {
// in no reserved password is set on the server, do not allow
// anyone to access reserved slots at all
reserved = sv_reserved_slots->integer;
}
- Q_strlcpy( userinfo, info, sizeof( userinfo ) );
+ Q_strlcpy(userinfo, info, sizeof(userinfo));
// make sure mvdspec key is not set
- Info_RemoveKey( userinfo, "mvdspec" );
+ Info_RemoveKey(userinfo, "mvdspec");
- if( sv_password->string[0] || sv_reserved_password->string[0] ) {
+ if (sv_password->string[0] || sv_reserved_password->string[0]) {
// unset password key to make game mod happy
- Info_RemoveKey( userinfo, "password" );
+ Info_RemoveKey(userinfo, "password");
}
// force the IP key/value pair so the game can filter based on ip
- s = NET_AdrToString( &net_from );
- if( !Info_SetValueForKey( userinfo, "ip", s ) ) {
- SV_OobPrintf( "Oversize userinfo string.\n" );
- Com_DPrintf( " rejected - oversize userinfo.\n" );
+ s = NET_AdrToString(&net_from);
+ if (!Info_SetValueForKey(userinfo, "ip", s)) {
+ SV_OobPrintf("Oversize userinfo string.\n");
+ Com_DPrintf(" rejected - oversize userinfo.\n");
return;
}
@@ -808,50 +819,49 @@ static void SVC_DirectConnect( void ) {
reconnect_val[0] = 0;
// if there is already a slot for this ip, reuse it
- FOR_EACH_CLIENT( cl ) {
- if( NET_IsEqualAdr( &net_from, &cl->netchan->remote_address ) ) {
- if( cl->state == cs_zombie ) {
- strcpy( reconnect_var, cl->reconnect_var );
- strcpy( reconnect_val, cl->reconnect_val );
+ FOR_EACH_CLIENT(cl) {
+ if (NET_IsEqualAdr(&net_from, &cl->netchan->remote_address)) {
+ if (cl->state == cs_zombie) {
+ strcpy(reconnect_var, cl->reconnect_var);
+ strcpy(reconnect_val, cl->reconnect_val);
} else {
- SV_DropClient( cl, "reconnected" );
+ SV_DropClient(cl, "reconnected");
}
- Com_DPrintf( "%s: reconnect\n", NET_AdrToString( &net_from ) );
- SV_RemoveClient( cl );
+ Com_DPrintf("%s: reconnect\n", NET_AdrToString(&net_from));
+ SV_RemoveClient(cl);
newcl = cl;
break;
}
}
// find a client slot
- if( !newcl ) {
+ if (!newcl) {
// check for forced redirect to a different address
- if( sv_redirect_address->string[0] == '!' &&
- ( !sv_reserved_slots->integer || reserved ) )
- {
- send_redirect_hack( sv_redirect_address->string + 1 );
- Com_DPrintf( " rejected - forced redirect.\n" );
+ if (sv_redirect_address->string[0] == '!' &&
+ (!sv_reserved_slots->integer || reserved)) {
+ send_redirect_hack(sv_redirect_address->string + 1);
+ Com_DPrintf(" rejected - forced redirect.\n");
return;
}
lastcl = svs.client_pool + sv_maxclients->integer - reserved;
- for( newcl = svs.client_pool; newcl < lastcl; newcl++ ) {
- if( !newcl->state ) {
+ for (newcl = svs.client_pool; newcl < lastcl; newcl++) {
+ if (!newcl->state) {
break;
}
}
- if( newcl == lastcl ) {
- if( sv_reserved_slots->integer && !reserved ) {
- SV_OobPrintf( "Server and reserved slots are full.\n" );
- Com_DPrintf( " rejected - reserved slots are full.\n" );
+ if (newcl == lastcl) {
+ if (sv_reserved_slots->integer && !reserved) {
+ SV_OobPrintf("Server and reserved slots are full.\n");
+ Com_DPrintf(" rejected - reserved slots are full.\n");
} else {
// optionally redirect them to a different address
- if( sv_redirect_address->string[0] ) {
- send_redirect_hack( sv_redirect_address->string );
+ if (sv_redirect_address->string[0]) {
+ send_redirect_hack(sv_redirect_address->string);
} else {
- SV_OobPrintf( "Server is full.\n" );
+ SV_OobPrintf("Server is full.\n");
}
- Com_DPrintf( " rejected - server is full.\n" );
+ Com_DPrintf(" rejected - server is full.\n");
}
return;
}
@@ -860,23 +870,23 @@ static void SVC_DirectConnect( void ) {
// build a new connection
// accept the new client
// this is the only place a client_t is ever initialized
- memset( newcl, 0, sizeof( *newcl ) );
+ memset(newcl, 0, sizeof(*newcl));
number = newcl - svs.client_pool;
newcl->number = newcl->slot = number;
newcl->challenge = challenge; // save challenge for checksumming
newcl->protocol = protocol;
newcl->version = version;
newcl->has_zlib = has_zlib;
- newcl->edict = EDICT_NUM( number + 1 );
+ newcl->edict = EDICT_NUM(number + 1);
newcl->gamedir = fs_game->string;
newcl->mapname = sv.name;
- newcl->configstrings = ( char * )sv.configstrings;
- newcl->pool = ( edict_pool_t * )&ge->edicts;
+ newcl->configstrings = (char *)sv.configstrings;
+ newcl->pool = (edict_pool_t *)&ge->edicts;
newcl->cm = &sv.cm;
newcl->spawncount = sv.spawncount;
newcl->maxclients = sv_maxclients->integer;
- strcpy( newcl->reconnect_var, reconnect_var );
- strcpy( newcl->reconnect_val, reconnect_val );
+ strcpy(newcl->reconnect_var, reconnect_var);
+ strcpy(newcl->reconnect_val, reconnect_val);
#if USE_FPS
newcl->framediv = sv.framediv;
newcl->settings[CLS_FPS] = BASE_FRAMERATE;
@@ -888,37 +898,36 @@ static void SVC_DirectConnect( void ) {
// r1q2 extensions
i = 2;
- if( protocol == PROTOCOL_VERSION_R1Q2 ||
- protocol == PROTOCOL_VERSION_Q2PRO )
- {
+ if (protocol == PROTOCOL_VERSION_R1Q2 ||
+ protocol == PROTOCOL_VERSION_Q2PRO) {
newcl->pmp.speedmult = 2;
i = 1;
}
newcl->pmp.strafehack = sv_strafejump_hack->integer >= i ? qtrue : qfalse;
- if( protocol == PROTOCOL_VERSION_R1Q2 ) {
+ if (protocol == PROTOCOL_VERSION_R1Q2) {
newcl->esFlags |= MSG_ES_BEAMORIGIN;
- if( version >= PROTOCOL_VERSION_R1Q2_LONG_SOLID ) {
+ if (version >= PROTOCOL_VERSION_R1Q2_LONG_SOLID) {
newcl->esFlags |= MSG_ES_LONGSOLID;
}
}
// q2pro extensions
i = 2;
- if( protocol == PROTOCOL_VERSION_Q2PRO ) {
- if( sv_qwmod->integer ) {
- PmoveEnableQW( &newcl->pmp );
+ if (protocol == PROTOCOL_VERSION_Q2PRO) {
+ if (sv_qwmod->integer) {
+ PmoveEnableQW(&newcl->pmp);
}
newcl->pmp.flyhack = qtrue;
newcl->pmp.flyfriction = 4;
newcl->esFlags |= MSG_ES_UMASK;
- if( version >= PROTOCOL_VERSION_Q2PRO_LONG_SOLID ) {
+ if (version >= PROTOCOL_VERSION_Q2PRO_LONG_SOLID) {
newcl->esFlags |= MSG_ES_LONGSOLID;
}
- if( version >= PROTOCOL_VERSION_Q2PRO_BEAM_ORIGIN ) {
+ if (version >= PROTOCOL_VERSION_Q2PRO_BEAM_ORIGIN) {
newcl->esFlags |= MSG_ES_BEAMORIGIN;
}
- if( version >= PROTOCOL_VERSION_Q2PRO_WATERJUMP_HACK ) {
+ if (version >= PROTOCOL_VERSION_Q2PRO_WATERJUMP_HACK) {
i = 1;
}
}
@@ -927,68 +936,68 @@ static void SVC_DirectConnect( void ) {
// get the game a chance to reject this connection or modify the userinfo
sv_client = newcl;
sv_player = newcl->edict;
- allow = ge->ClientConnect( newcl->edict, userinfo );
+ allow = ge->ClientConnect(newcl->edict, userinfo);
sv_client = NULL;
sv_player = NULL;
- if ( !allow ) {
+ if (!allow) {
char *reason;
- reason = Info_ValueForKey( userinfo, "rejmsg" );
- if( *reason ) {
- SV_OobPrintf( "%s\nConnection refused.\n", reason );
+ reason = Info_ValueForKey(userinfo, "rejmsg");
+ if (*reason) {
+ SV_OobPrintf("%s\nConnection refused.\n", reason);
} else {
- SV_OobPrintf( "Connection refused.\n" );
+ SV_OobPrintf("Connection refused.\n");
}
- Com_DPrintf( " game rejected a connection.\n" );
+ Com_DPrintf(" game rejected a connection.\n");
return;
}
-
+
// setup netchan
- newcl->netchan = Netchan_Setup( NS_SERVER, nctype, &net_from,
- qport, maxlength, protocol );
+ newcl->netchan = Netchan_Setup(NS_SERVER, nctype, &net_from,
+ qport, maxlength, protocol);
newcl->numpackets = 1;
// parse some info from the info strings
- Q_strlcpy( newcl->userinfo, userinfo, sizeof( newcl->userinfo ) );
- SV_UserinfoChanged( newcl );
+ Q_strlcpy(newcl->userinfo, userinfo, sizeof(newcl->userinfo));
+ SV_UserinfoChanged(newcl);
#if USE_AC_SERVER
- if( !sv_force_reconnect->string[0] || reconnect_var[0] ) {
- acstring = AC_ClientConnect( newcl );
+ if (!sv_force_reconnect->string[0] || reconnect_var[0]) {
+ acstring = AC_ClientConnect(newcl);
} else
#endif
{
acstring = "";
}
- if( sv_downloadserver->string[0] ) {
- Q_snprintf( dlstring, sizeof( dlstring ), " dlserver=%s",
- sv_downloadserver->string );
+ if (sv_downloadserver->string[0]) {
+ Q_snprintf(dlstring, sizeof(dlstring), " dlserver=%s",
+ sv_downloadserver->string);
} else {
dlstring[0] = 0;
}
// send the connect packet to the client
- Netchan_OutOfBand( NS_SERVER, &net_from, "client_connect%s%s%s map=%s",
- ncstring, acstring, dlstring, newcl->mapname );
+ Netchan_OutOfBand(NS_SERVER, &net_from, "client_connect%s%s%s map=%s",
+ ncstring, acstring, dlstring, newcl->mapname);
- SV_InitClientSend( newcl );
+ SV_InitClientSend(newcl);
- if( protocol == PROTOCOL_VERSION_DEFAULT ) {
+ if (protocol == PROTOCOL_VERSION_DEFAULT) {
newcl->WriteFrame = SV_WriteFrameToClient_Default;
} else {
newcl->WriteFrame = SV_WriteFrameToClient_Enhanced;
}
// loopback client doesn't need to reconnect
- if( NET_IsLocalAddress( &net_from ) ) {
+ if (NET_IsLocalAddress(&net_from)) {
newcl->reconnected = qtrue;
}
// add them to the linked list of connected clients
- List_SeqAdd( &sv_clientlist, &newcl->entry );
+ List_SeqAdd(&sv_clientlist, &newcl->entry);
- Com_DPrintf( "Going from cs_free to cs_assigned for %s\n", newcl->name );
+ Com_DPrintf("Going from cs_free to cs_assigned for %s\n", newcl->name);
newcl->state = cs_assigned;
newcl->framenum = 1; // frame 0 can't be used
newcl->lastframe = -1;
@@ -996,12 +1005,12 @@ static void SVC_DirectConnect( void ) {
newcl->min_ping = 9999;
}
-static int Rcon_Validate (void)
+static int Rcon_Validate(void)
{
if (!rcon_password->string[0])
return 0;
- if (strcmp (Cmd_Argv(1), rcon_password->string) )
+ if (strcmp(Cmd_Argv(1), rcon_password->string))
return 0;
return 1;
@@ -1015,32 +1024,33 @@ A client issued an rcon command.
Redirect all printfs.
===============
*/
-static void SVC_RemoteCommand( void ) {
+static void SVC_RemoteCommand(void)
+{
int i;
char *string;
- if( SV_RateLimited( &svs.ratelimit_rcon ) ) {
- Com_DPrintf( "Dropping rcon from %s\n",
- NET_AdrToString( &net_from ) );
+ if (SV_RateLimited(&svs.ratelimit_rcon)) {
+ Com_DPrintf("Dropping rcon from %s\n",
+ NET_AdrToString(&net_from));
return;
}
i = Rcon_Validate();
- string = Cmd_RawArgsFrom( 2 );
- if( i == 0 ) {
- Com_Printf( "Invalid rcon from %s:\n%s\n",
- NET_AdrToString( &net_from ), string );
- SV_OobPrintf( "Bad rcon_password.\n" );
+ string = Cmd_RawArgsFrom(2);
+ if (i == 0) {
+ Com_Printf("Invalid rcon from %s:\n%s\n",
+ NET_AdrToString(&net_from), string);
+ SV_OobPrintf("Bad rcon_password.\n");
svs.ratelimit_rcon.count++;
return;
}
- Com_Printf( "Rcon from %s:\n%s\n",
- NET_AdrToString( &net_from ), string );
+ Com_Printf("Rcon from %s:\n%s\n",
+ NET_AdrToString(&net_from), string);
- SV_BeginRedirect( RD_PACKET );
+ SV_BeginRedirect(RD_PACKET);
- Cmd_ExecuteString( &cmd_buffer, string );
+ Cmd_ExecuteString(&cmd_buffer, string);
Com_EndRedirect();
}
@@ -1065,60 +1075,62 @@ Clients that are in the game can still send
connectionless packets.
=================
*/
-static void SV_ConnectionlessPacket( void ) {
+static void SV_ConnectionlessPacket(void)
+{
char string[MAX_STRING_CHARS];
char *c;
int i;
size_t len;
- if( SV_MatchAddress( &sv_blacklist, &net_from ) ) {
- Com_DPrintf( "ignored blackholed connectionless packet\n" );
+ if (SV_MatchAddress(&sv_blacklist, &net_from)) {
+ Com_DPrintf("ignored blackholed connectionless packet\n");
return;
}
MSG_BeginReading();
MSG_ReadLong(); // skip the -1 marker
- len = MSG_ReadStringLine( string, sizeof( string ) );
- if( len >= sizeof( string ) ) {
- Com_DPrintf( "ignored oversize connectionless packet\n" );
+ len = MSG_ReadStringLine(string, sizeof(string));
+ if (len >= sizeof(string)) {
+ Com_DPrintf("ignored oversize connectionless packet\n");
return;
}
- Cmd_TokenizeString( string, qfalse );
+ Cmd_TokenizeString(string, qfalse);
- c = Cmd_Argv( 0 );
- Com_DPrintf( "ServerPacket[%s]: %s\n", NET_AdrToString( &net_from ), c );
+ c = Cmd_Argv(0);
+ Com_DPrintf("ServerPacket[%s]: %s\n", NET_AdrToString(&net_from), c);
- if( !strcmp( c, "rcon" ) ) {
+ if (!strcmp(c, "rcon")) {
SVC_RemoteCommand();
return; // accept rcon commands even if not active
}
- if( !svs.initialized ) {
- Com_DPrintf( "ignored connectionless packet\n" );
+ if (!svs.initialized) {
+ Com_DPrintf("ignored connectionless packet\n");
return;
}
- for( i = 0; svcmds[i].name; i++ ) {
- if( !strcmp( c, svcmds[i].name ) ) {
+ for (i = 0; svcmds[i].name; i++) {
+ if (!strcmp(c, svcmds[i].name)) {
svcmds[i].func();
return;
}
}
- Com_DPrintf( "bad connectionless packet\n" );
+ Com_DPrintf("bad connectionless packet\n");
}
//============================================================================
-int SV_CountClients( void ) {
+int SV_CountClients(void)
+{
client_t *cl;
int count = 0;
- FOR_EACH_CLIENT( cl ) {
- if( cl->state > cs_zombie ) {
+ FOR_EACH_CLIENT(cl) {
+ if (cl->state > cs_zombie) {
count++;
}
}
@@ -1126,38 +1138,41 @@ int SV_CountClients( void ) {
return count;
}
-static int ping_nop( client_t *cl ) {
+static int ping_nop(client_t *cl)
+{
return 0;
}
-static int ping_min( client_t *cl ) {
+static int ping_min(client_t *cl)
+{
client_frame_t *frame;
int i, j, count = INT_MAX;
- for( i = 0; i < UPDATE_BACKUP; i++ ) {
+ for (i = 0; i < UPDATE_BACKUP; i++) {
j = cl->framenum - i - 1;
frame = &cl->frames[j & UPDATE_MASK];
- if( frame->number != j )
+ if (frame->number != j)
continue;
- if( frame->latency == -1 )
+ if (frame->latency == -1)
continue;
- if( count > frame->latency )
+ if (count > frame->latency)
count = frame->latency;
}
return count == INT_MAX ? 0 : count;
}
-static int ping_avg( client_t *cl ) {
+static int ping_avg(client_t *cl)
+{
client_frame_t *frame;
int i, j, total = 0, count = 0;
- for( i = 0; i < UPDATE_BACKUP; i++ ) {
+ for (i = 0; i < UPDATE_BACKUP; i++) {
j = cl->framenum - i - 1;
frame = &cl->frames[j & UPDATE_MASK];
- if( frame->number != j )
+ if (frame->number != j)
continue;
- if( frame->latency == -1 )
+ if (frame->latency == -1)
continue;
count++;
total += frame->latency;
@@ -1173,35 +1188,36 @@ SV_CalcPings
Updates the cl->ping and cl->fps variables
===================
*/
-static void SV_CalcPings( void ) {
+static void SV_CalcPings(void)
+{
client_t *cl;
- int (*calc)( client_t * );
+ int (*calc)(client_t *);
int res;
- switch( sv_calcpings_method->integer ) {
+ switch (sv_calcpings_method->integer) {
case 0: calc = ping_nop; break;
case 2: calc = ping_min; break;
default: calc = ping_avg; break;
}
// update avg ping and fps every 10 seconds
- res = sv.framenum % ( 10 * SV_FRAMERATE );
+ res = sv.framenum % (10 * SV_FRAMERATE);
- FOR_EACH_CLIENT( cl ) {
- if( cl->state == cs_spawned ) {
- cl->ping = calc( cl );
- if( cl->ping ) {
- if( cl->ping < cl->min_ping ) {
+ FOR_EACH_CLIENT(cl) {
+ if (cl->state == cs_spawned) {
+ cl->ping = calc(cl);
+ if (cl->ping) {
+ if (cl->ping < cl->min_ping) {
cl->min_ping = cl->ping;
- } else if( cl->ping > cl->max_ping ) {
+ } else if (cl->ping > cl->max_ping) {
cl->max_ping = cl->ping;
}
- if( !res ) {
+ if (!res) {
cl->avg_ping_time += cl->ping;
cl->avg_ping_count++;
}
}
- if( !res ) {
+ if (!res) {
cl->fps = cl->numMoves / 10;
cl->numMoves = 0;
}
@@ -1225,13 +1241,14 @@ Every few frames, gives all clients an allotment of milliseconds
for their command moves. If they exceed it, assume cheating.
===================
*/
-static void SV_GiveMsec( void ) {
+static void SV_GiveMsec(void)
+{
client_t *cl;
- if( sv.framenum % ( 16 * SV_FRAMEDIV ) )
+ if (sv.framenum % (16 * SV_FRAMEDIV))
return;
- FOR_EACH_CLIENT( cl ) {
+ FOR_EACH_CLIENT(cl) {
cl->commandMsec = 1800; // 1600 + some slop
}
}
@@ -1242,57 +1259,58 @@ static void SV_GiveMsec( void ) {
SV_PacketEvent
=================
*/
-static void SV_PacketEvent( void ) {
+static void SV_PacketEvent(void)
+{
client_t *client;
netchan_t *netchan;
int qport;
-
+
// check for connectionless packet (0xffffffff) first
// connectionless packets are processed even if the server is down
- if( *( int * )msg_read.data == -1 ) {
+ if (*(int *)msg_read.data == -1) {
SV_ConnectionlessPacket();
return;
}
- if( !svs.initialized ) {
+ if (!svs.initialized) {
return;
}
// check for packets from connected clients
- FOR_EACH_CLIENT( client ) {
+ FOR_EACH_CLIENT(client) {
netchan = client->netchan;
- if( !NET_IsEqualBaseAdr( &net_from, &netchan->remote_address ) ) {
+ if (!NET_IsEqualBaseAdr(&net_from, &netchan->remote_address)) {
continue;
}
// read the qport out of the message so we can fix up
// stupid address translating routers
- if( client->protocol == PROTOCOL_VERSION_DEFAULT ) {
- qport = msg_read.data[8] | ( msg_read.data[9] << 8 );
- if( netchan->qport != qport ) {
+ if (client->protocol == PROTOCOL_VERSION_DEFAULT) {
+ qport = msg_read.data[8] | (msg_read.data[9] << 8);
+ if (netchan->qport != qport) {
continue;
}
- } else if( netchan->qport ) {
+ } else if (netchan->qport) {
qport = msg_read.data[8];
- if( netchan->qport != qport ) {
+ if (netchan->qport != qport) {
continue;
}
} else {
- if( netchan->remote_address.port != net_from.port ) {
+ if (netchan->remote_address.port != net_from.port) {
continue;
}
}
- if( netchan->remote_address.port != net_from.port ) {
- Com_DPrintf( "Fixing up a translated port for %s: %d --> %d\n",
- client->name, netchan->remote_address.port, net_from.port );
+ if (netchan->remote_address.port != net_from.port) {
+ Com_DPrintf("Fixing up a translated port for %s: %d --> %d\n",
+ client->name, netchan->remote_address.port, net_from.port);
netchan->remote_address.port = net_from.port;
}
- if( !netchan->Process( netchan ) )
+ if (!netchan->Process(netchan))
break;
- if( client->state == cs_zombie )
+ if (client->state == cs_zombie)
break;
// this is a valid, sequenced packet, so process it
@@ -1300,10 +1318,10 @@ static void SV_PacketEvent( void ) {
#if USE_ICMP
client->unreachable = qfalse; // don't drop
#endif
- if( netchan->dropped > 0 )
+ if (netchan->dropped > 0)
client->frameflags |= FF_CLIENTDROP;
- SV_ExecuteClientMessage( client );
+ SV_ExecuteClientMessage(client);
break;
}
}
@@ -1314,42 +1332,42 @@ static void SV_PacketEvent( void ) {
SV_ErrorEvent
=================
*/
-void SV_ErrorEvent( int info ) {
+void SV_ErrorEvent(int info)
+{
client_t *client;
netchan_t *netchan;
- if( !svs.initialized ) {
+ if (!svs.initialized) {
return;
}
// check for errors from connected clients
- FOR_EACH_CLIENT( client ) {
- if( client->state == cs_zombie ) {
+ FOR_EACH_CLIENT(client) {
+ if (client->state == cs_zombie) {
continue; // already a zombie
}
netchan = client->netchan;
- if( !NET_IsEqualBaseAdr( &net_from, &netchan->remote_address ) ) {
+ if (!NET_IsEqualBaseAdr(&net_from, &netchan->remote_address)) {
continue;
}
- if( net_from.port && netchan->remote_address.port != net_from.port ) {
+ if (net_from.port && netchan->remote_address.port != net_from.port) {
continue;
}
#if USE_PMTUDISC
- if( info ) {
+ if (info) {
// we are doing path MTU discovery and got ICMP fragmentation-needed
// update MTU only for connecting clients to minimize spoofed ICMP interference
// MTU info has already been sanity checked for us by network code
// assume total 64 bytes of headers
- if( client->state == cs_primed &&
+ if (client->state == cs_primed &&
netchan->reliable_length &&
- info < netchan->maxpacketlen + 64 )
- {
- if( netchan->type == NETCHAN_OLD ) {
+ info < netchan->maxpacketlen + 64) {
+ if (netchan->type == NETCHAN_OLD) {
// TODO: old clients require entire queue flush :(
continue;
}
- Com_Printf( "Fixing up maxmsglen for %s: %d --> %d\n",
- client->name, (int)netchan->maxpacketlen, info - 64 );
+ Com_Printf("Fixing up maxmsglen for %s: %d --> %d\n",
+ client->name, (int)netchan->maxpacketlen, info - 64);
netchan->maxpacketlen = info - 64;
}
continue;
@@ -1361,19 +1379,20 @@ void SV_ErrorEvent( int info ) {
}
#endif
-static void SV_ReadPackets( void ) {
+static void SV_ReadPackets(void)
+{
#if USE_CLIENT
- memset( &net_from, 0, sizeof( net_from ) );
+ memset(&net_from, 0, sizeof(net_from));
net_from.type = NA_LOOPBACK;
// process loopback packets
- while( NET_GetLoopPacket( NS_SERVER ) ) {
+ while (NET_GetLoopPacket(NS_SERVER)) {
SV_PacketEvent();
}
#endif
// process network packets
- while( NET_GetPacket( NS_SERVER ) ) {
+ while (NET_GetPacket(NS_SERVER)) {
SV_PacketEvent();
}
}
@@ -1391,47 +1410,48 @@ for a few seconds to make sure any final reliable message gets resent
if necessary
==================
*/
-static void SV_CheckTimeouts( void ) {
+static void SV_CheckTimeouts(void)
+{
client_t *client;
unsigned zombie_time = 1000 * sv_zombietime->value;
unsigned drop_time = 1000 * sv_timeout->value;
unsigned ghost_time = 1000 * sv_ghostime->value;
unsigned delta;
- FOR_EACH_CLIENT( client ) {
+ FOR_EACH_CLIENT(client) {
// never timeout local clients
- if( NET_IsLocalAddress( &client->netchan->remote_address ) ) {
+ if (NET_IsLocalAddress(&client->netchan->remote_address)) {
continue;
}
// NOTE: delta calculated this way is not sensitive to overflow
delta = svs.realtime - client->lastmessage;
- if( client->state == cs_zombie ) {
- if( delta > zombie_time ) {
- SV_RemoveClient( client );
+ if (client->state == cs_zombie) {
+ if (delta > zombie_time) {
+ SV_RemoveClient(client);
}
continue;
}
- if( client->drop_hack ) {
- SV_DropClient( client, NULL );
+ if (client->drop_hack) {
+ SV_DropClient(client, NULL);
continue;
}
#if USE_ICMP
- if( client->unreachable ) {
- if( delta > ghost_time ) {
- SV_DropClient( client, "connection reset by peer" );
- SV_RemoveClient( client ); // don't bother with zombie state
+ if (client->unreachable) {
+ if (delta > ghost_time) {
+ SV_DropClient(client, "connection reset by peer");
+ SV_RemoveClient(client); // don't bother with zombie state
continue;
}
}
#endif
- if( delta > drop_time || ( client->state == cs_assigned && delta > ghost_time ) ) {
- SV_DropClient( client, "?timed out" );
- SV_RemoveClient( client ); // don't bother with zombie state
+ if (delta > drop_time || (client->state == cs_assigned && delta > ghost_time)) {
+ SV_DropClient(client, "?timed out");
+ SV_RemoveClient(client); // don't bother with zombie state
continue;
}
- if( client->frames_nodelta > 64 && !sv_allow_nodelta->integer ) {
- SV_DropClient( client, "too many nodelta frames" );
+ if (client->frames_nodelta > 64 && !sv_allow_nodelta->integer) {
+ SV_DropClient(client, "too many nodelta frames");
continue;
}
}
@@ -1445,12 +1465,13 @@ This has to be done before the world logic, because
player processing happens outside RunWorldFrame
================
*/
-static void SV_PrepWorldFrame( void ) {
+static void SV_PrepWorldFrame(void)
+{
edict_t *ent;
int i;
#if USE_MVD_CLIENT
- if( sv.state == ss_broadcast ) {
+ if (sv.state == ss_broadcast) {
MVD_PrepWorldFrame();
return;
}
@@ -1458,47 +1479,48 @@ static void SV_PrepWorldFrame( void ) {
sv.tracecount = 0;
- if( !SV_FRAMESYNC )
+ if (!SV_FRAMESYNC)
return;
- for( i = 1; i < ge->num_edicts; i++ ) {
- ent = EDICT_NUM( i );
+ for (i = 1; i < ge->num_edicts; i++) {
+ ent = EDICT_NUM(i);
// events only last for a single keyframe
ent->s.event = 0;
- }
+ }
}
// pause if there is only local client on the server
-static inline qboolean check_paused( void ) {
+static inline qboolean check_paused(void)
+{
#if USE_CLIENT
- if( dedicated->integer )
+ if (dedicated->integer)
goto resume;
- if( !cl_paused->integer )
+ if (!cl_paused->integer)
goto resume;
- if( com_timedemo->integer )
+ if (com_timedemo->integer)
goto resume;
- if( !LIST_SINGLE( &sv_clientlist ) )
+ if (!LIST_SINGLE(&sv_clientlist))
goto resume;
#if USE_MVD_CLIENT
- if( !LIST_EMPTY( &mvd_gtv_list ) )
+ if (!LIST_EMPTY(&mvd_gtv_list))
goto resume;
#endif
- if( !sv_paused->integer ) {
- Cvar_Set( "sv_paused", "1" );
+ if (!sv_paused->integer) {
+ Cvar_Set("sv_paused", "1");
IN_Activate();
}
return qtrue; // don't run if paused
resume:
- if( sv_paused->integer ) {
- Cvar_Set( "sv_paused", "0" );
+ if (sv_paused->integer) {
+ Cvar_Set("sv_paused", "0");
IN_Activate();
}
#endif
@@ -1511,14 +1533,15 @@ resume:
SV_RunGameFrame
=================
*/
-static void SV_RunGameFrame( void ) {
+static void SV_RunGameFrame(void)
+{
#if USE_MVD_SERVER
// save the entire world state if recording a serverdemo
SV_MvdBeginFrame();
#endif
#if USE_CLIENT
- if( host_speeds->integer )
+ if (host_speeds->integer)
time_before_game = Sys_Milliseconds();
#endif
@@ -1530,15 +1553,15 @@ static void SV_RunGameFrame( void ) {
X86_POP_FPCW;
#if USE_CLIENT
- if( host_speeds->integer )
+ if (host_speeds->integer)
time_after_game = Sys_Milliseconds();
#endif
- if( msg_write.cursize ) {
- Com_WPrintf( "Game left %"PRIz" bytes "
- "in multicast buffer, cleared.\n",
- msg_write.cursize );
- SZ_Clear( &msg_write );
+ if (msg_write.cursize) {
+ Com_WPrintf("Game left %"PRIz" bytes "
+ "in multicast buffer, cleared.\n",
+ msg_write.cursize);
+ SZ_Clear(&msg_write);
}
#if USE_MVD_SERVER
@@ -1555,35 +1578,36 @@ Send a message to the master every few minutes to
let it know we are alive, and log information
================
*/
-static void SV_MasterHeartbeat( void ) {
+static void SV_MasterHeartbeat(void)
+{
char buffer[MAX_PACKETLEN_DEFAULT];
size_t len;
master_t *m;
- if( !Com_IsDedicated() )
+ if (!Com_IsDedicated())
return; // only dedicated servers send heartbeats
- if( !sv_public->integer )
+ if (!sv_public->integer)
return; // a private dedicated game
- if( svs.realtime - svs.last_heartbeat < HEARTBEAT_SECONDS*1000 )
+ if (svs.realtime - svs.last_heartbeat < HEARTBEAT_SECONDS * 1000)
return; // not time to send yet
svs.last_heartbeat = svs.realtime;
// write the packet header
- memcpy( buffer, "\xff\xff\xff\xffheartbeat\n", 14 );
+ memcpy(buffer, "\xff\xff\xff\xffheartbeat\n", 14);
len = 14;
// send the same string that we would give for a status OOB command
- len += SV_StatusString( buffer + len );
+ len += SV_StatusString(buffer + len);
// send to group master
- FOR_EACH_MASTER( m ) {
- if( m->adr.port ) {
- Com_DPrintf( "Sending heartbeat to %s\n",
- NET_AdrToString( &m->adr ) );
- NET_SendPacket( NS_SERVER, &m->adr, len, buffer );
+ FOR_EACH_MASTER(m) {
+ if (m->adr.port) {
+ Com_DPrintf("Sending heartbeat to %s\n",
+ NET_AdrToString(&m->adr));
+ NET_SendPacket(NS_SERVER, &m->adr, len, buffer);
}
}
}
@@ -1595,26 +1619,27 @@ SV_MasterShutdown
Informs all masters that this server is going down
=================
*/
-static void SV_MasterShutdown( void ) {
+static void SV_MasterShutdown(void)
+{
master_t *m;
// reset ack times
- FOR_EACH_MASTER( m ) {
+ FOR_EACH_MASTER(m) {
m->last_ack = 0;
}
- if( !Com_IsDedicated() )
+ if (!Com_IsDedicated())
return; // only dedicated servers send heartbeats
- if( !sv_public || !sv_public->integer )
+ if (!sv_public || !sv_public->integer)
return; // a private dedicated game
// send to group master
- FOR_EACH_MASTER( m ) {
- if( m->adr.port ) {
- Com_DPrintf( "Sending shutdown to %s\n",
- NET_AdrToString( &m->adr ) );
- OOB_PRINT( NS_SERVER, &m->adr, "shutdown" );
+ FOR_EACH_MASTER(m) {
+ if (m->adr.port) {
+ Com_DPrintf("Sending shutdown to %s\n",
+ NET_AdrToString(&m->adr));
+ OOB_PRINT(NS_SERVER, &m->adr, "shutdown");
}
}
}
@@ -1629,7 +1654,8 @@ processing are run even when server is not yet initalized.
Returns amount of extra frametime available for sleeping on IO.
==================
*/
-unsigned SV_Frame( unsigned msec ) {
+unsigned SV_Frame(unsigned msec)
+{
#if USE_CLIENT
time_before_game = time_after_game = 0;
#endif
@@ -1637,9 +1663,9 @@ unsigned SV_Frame( unsigned msec ) {
// advance local server time
svs.realtime += msec;
- if( Com_IsDedicated() ) {
+ if (Com_IsDedicated()) {
// process console commands if not running a client
- Cbuf_Execute( &cmd_buffer );
+ Cbuf_Execute(&cmd_buffer);
}
#if USE_MVD_CLIENT
@@ -1650,7 +1676,7 @@ unsigned SV_Frame( unsigned msec ) {
// read packets from UDP clients
SV_ReadPackets();
- if( svs.initialized ) {
+ if (svs.initialized) {
#if USE_AC_SERVER
// run connection to the anticheat server
AC_Run();
@@ -1667,11 +1693,11 @@ unsigned SV_Frame( unsigned msec ) {
// move autonomous things around if enough time has passed
sv.frameresidual += msec;
- if( sv.frameresidual < SV_FRAMETIME ) {
+ if (sv.frameresidual < SV_FRAMETIME) {
return SV_FRAMETIME - sv.frameresidual;
}
- if( svs.initialized && !check_paused() ) {
+ if (svs.initialized && !check_paused()) {
// check timeouts
SV_CheckTimeouts();
@@ -1697,22 +1723,22 @@ unsigned SV_Frame( unsigned msec ) {
sv.framenum++;
}
- if( Com_IsDedicated() ) {
+ if (Com_IsDedicated()) {
// run cmd buffer in dedicated mode
- if( cmd_buffer.waitCount > 0 ) {
+ if (cmd_buffer.waitCount > 0) {
cmd_buffer.waitCount--;
}
}
// decide how long to sleep next frame
sv.frameresidual -= SV_FRAMETIME;
- if( sv.frameresidual < SV_FRAMETIME ) {
+ if (sv.frameresidual < SV_FRAMETIME) {
return SV_FRAMETIME - sv.frameresidual;
}
// don't accumulate bogus residual
- if( sv.frameresidual > 250 ) {
- Com_DDDPrintf( "Reset residual %u\n", sv.frameresidual );
+ if (sv.frameresidual > 250) {
+ Com_DDDPrintf("Reset residual %u\n", sv.frameresidual);
sv.frameresidual = 100;
}
@@ -1729,67 +1755,67 @@ Pull specific info from a newly changed userinfo string
into a more C freindly form.
=================
*/
-void SV_UserinfoChanged( client_t *cl ) {
+void SV_UserinfoChanged(client_t *cl)
+{
char name[MAX_CLIENT_NAME];
char *val;
size_t len;
int i;
// call prog code to allow overrides
- ge->ClientUserinfoChanged( cl->edict, cl->userinfo );
+ ge->ClientUserinfoChanged(cl->edict, cl->userinfo);
// name for C code
- val = Info_ValueForKey( cl->userinfo, "name" );
- len = Q_strlcpy( name, val, sizeof( name ) );
- if( len >= sizeof( name ) ) {
- len = sizeof( name ) - 1;
+ val = Info_ValueForKey(cl->userinfo, "name");
+ len = Q_strlcpy(name, val, sizeof(name));
+ if (len >= sizeof(name)) {
+ len = sizeof(name) - 1;
}
// mask off high bit
- for( i = 0; i < len; i++ )
+ for (i = 0; i < len; i++)
name[i] &= 127;
- if( cl->name[0] && strcmp( cl->name, name ) ) {
- if( Com_IsDedicated() ) {
- Com_Printf( "%s[%s] changed name to %s\n", cl->name,
- NET_AdrToString( &cl->netchan->remote_address ), name );
+ if (cl->name[0] && strcmp(cl->name, name)) {
+ if (Com_IsDedicated()) {
+ Com_Printf("%s[%s] changed name to %s\n", cl->name,
+ NET_AdrToString(&cl->netchan->remote_address), name);
}
#if USE_MVD_CLIENT
- if( sv.state == ss_broadcast ) {
- MVD_GameClientNameChanged( cl->edict, name );
+ if (sv.state == ss_broadcast) {
+ MVD_GameClientNameChanged(cl->edict, name);
} else
#endif
- if( sv_show_name_changes->integer ) {
- SV_BroadcastPrintf( PRINT_HIGH, "%s changed name to %s\n",
- cl->name, name );
- }
+ if (sv_show_name_changes->integer) {
+ SV_BroadcastPrintf(PRINT_HIGH, "%s changed name to %s\n",
+ cl->name, name);
+ }
}
- memcpy( cl->name, name, len + 1 );
+ memcpy(cl->name, name, len + 1);
// rate command
- val = Info_ValueForKey( cl->userinfo, "rate" );
- if( *val ) {
- cl->rate = atoi( val );
- clamp( cl->rate, 100, 15000 );
+ val = Info_ValueForKey(cl->userinfo, "rate");
+ if (*val) {
+ cl->rate = atoi(val);
+ clamp(cl->rate, 100, 15000);
} else {
cl->rate = 5000;
}
// never drop over the loopback
- if( NET_IsLocalAddress( &cl->netchan->remote_address ) ) {
+ if (NET_IsLocalAddress(&cl->netchan->remote_address)) {
cl->rate = 0;
}
// don't drop over LAN connections
- if( sv_lan_force_rate->integer &&
- NET_IsLanAddress( &cl->netchan->remote_address ) )
- {
+ if (sv_lan_force_rate->integer &&
+ NET_IsLanAddress(&cl->netchan->remote_address)) {
cl->rate = 0;
}
// msg command
- val = Info_ValueForKey( cl->userinfo, "msg" );
- if( *val ) {
- cl->messagelevel = atoi( val );
- clamp( cl->messagelevel, PRINT_LOW, PRINT_CHAT + 1 );
+ val = Info_ValueForKey(cl->userinfo, "msg");
+ if (*val) {
+ cl->messagelevel = atoi(val);
+ clamp(cl->messagelevel, PRINT_LOW, PRINT_CHAT + 1);
}
}
@@ -1797,45 +1823,53 @@ void SV_UserinfoChanged( client_t *cl ) {
//============================================================================
#if USE_SYSCON
-void SV_SetConsoleTitle( void ) {
+void SV_SetConsoleTitle(void)
+{
char buffer[MAX_STRING_CHARS];
- Q_snprintf( buffer, sizeof( buffer ), "%s (port %d%s)",
- sv_hostname->string, net_port->integer,
- sv_running->integer ? "" : ", down" );
+ Q_snprintf(buffer, sizeof(buffer), "%s (port %d%s)",
+ sv_hostname->string, net_port->integer,
+ sv_running->integer ? "" : ", down");
- Sys_SetConsoleTitle( buffer );
+ Sys_SetConsoleTitle(buffer);
}
#endif
-static void sv_status_limit_changed( cvar_t *self ) {
- SV_RateInit( &svs.ratelimit_status, self->string );
+static void sv_status_limit_changed(cvar_t *self)
+{
+ SV_RateInit(&svs.ratelimit_status, self->string);
}
-static void sv_auth_limit_changed( cvar_t *self ) {
- SV_RateInit( &svs.ratelimit_auth, self->string );
+static void sv_auth_limit_changed(cvar_t *self)
+{
+ SV_RateInit(&svs.ratelimit_auth, self->string);
}
-static void sv_rcon_limit_changed( cvar_t *self ) {
- SV_RateInit( &svs.ratelimit_rcon, self->string );
+static void sv_rcon_limit_changed(cvar_t *self)
+{
+ SV_RateInit(&svs.ratelimit_rcon, self->string);
}
-static void init_rate_limits( void ) {
- SV_RateInit( &svs.ratelimit_status, sv_status_limit->string );
- SV_RateInit( &svs.ratelimit_auth, sv_auth_limit->string );
- SV_RateInit( &svs.ratelimit_rcon, sv_rcon_limit->string );
+static void init_rate_limits(void)
+{
+ SV_RateInit(&svs.ratelimit_status, sv_status_limit->string);
+ SV_RateInit(&svs.ratelimit_auth, sv_auth_limit->string);
+ SV_RateInit(&svs.ratelimit_rcon, sv_rcon_limit->string);
}
#if USE_SYSCON
-static void sv_hostname_changed( cvar_t *self ) {
+static void sv_hostname_changed(cvar_t *self)
+{
SV_SetConsoleTitle();
}
#endif
#if USE_ZLIB
-voidpf SV_Zalloc OF(( voidpf opaque, uInt items, uInt size )) {
- return SV_Malloc( items * size );
+voidpf SV_Zalloc OF((voidpf opaque, uInt items, uInt size))
+{
+ return SV_Malloc(items * size);
}
-void SV_Zfree OF(( voidpf opaque, voidpf address )) {
- Z_Free( address );
+void SV_Zfree OF((voidpf opaque, voidpf address))
+{
+ Z_Free(address);
}
#endif
@@ -1846,7 +1880,8 @@ SV_Init
Only called at quake2.exe startup, not for each game
===============
*/
-void SV_Init( void ) {
+void SV_Init(void)
+{
SV_InitOperatorCommands();
#if USE_MVD_SERVER
@@ -1861,89 +1896,89 @@ void SV_Init( void ) {
AC_Register();
#endif
- Cvar_Get( "protocol", va( "%i", PROTOCOL_VERSION_DEFAULT ), CVAR_SERVERINFO|CVAR_ROM );
-
- Cvar_Get( "skill", "1", CVAR_LATCH );
- Cvar_Get( "deathmatch", "1", CVAR_SERVERINFO|CVAR_LATCH );
- Cvar_Get( "coop", "0", /*CVAR_SERVERINFO|*/CVAR_LATCH );
- Cvar_Get( "cheats", "0", CVAR_SERVERINFO|CVAR_LATCH );
- Cvar_Get( "dmflags", va( "%i", DF_INSTANT_ITEMS ), CVAR_SERVERINFO );
- Cvar_Get( "fraglimit", "0", CVAR_SERVERINFO );
- Cvar_Get( "timelimit", "0", CVAR_SERVERINFO );
-
- sv_maxclients = Cvar_Get( "maxclients", "8", CVAR_SERVERINFO|CVAR_LATCH );
- sv_reserved_slots = Cvar_Get( "sv_reserved_slots", "0", CVAR_LATCH );
- sv_hostname = Cvar_Get( "hostname", "noname", CVAR_SERVERINFO|CVAR_ARCHIVE );
+ Cvar_Get("protocol", va("%i", PROTOCOL_VERSION_DEFAULT), CVAR_SERVERINFO | CVAR_ROM);
+
+ Cvar_Get("skill", "1", CVAR_LATCH);
+ Cvar_Get("deathmatch", "1", CVAR_SERVERINFO | CVAR_LATCH);
+ Cvar_Get("coop", "0", /*CVAR_SERVERINFO|*/CVAR_LATCH);
+ Cvar_Get("cheats", "0", CVAR_SERVERINFO | CVAR_LATCH);
+ Cvar_Get("dmflags", va("%i", DF_INSTANT_ITEMS), CVAR_SERVERINFO);
+ Cvar_Get("fraglimit", "0", CVAR_SERVERINFO);
+ Cvar_Get("timelimit", "0", CVAR_SERVERINFO);
+
+ sv_maxclients = Cvar_Get("maxclients", "8", CVAR_SERVERINFO | CVAR_LATCH);
+ sv_reserved_slots = Cvar_Get("sv_reserved_slots", "0", CVAR_LATCH);
+ sv_hostname = Cvar_Get("hostname", "noname", CVAR_SERVERINFO | CVAR_ARCHIVE);
#if USE_SYSCON
sv_hostname->changed = sv_hostname_changed;
#endif
- sv_timeout = Cvar_Get( "timeout", "90", 0 );
- sv_zombietime = Cvar_Get( "zombietime", "2", 0 );
- sv_ghostime = Cvar_Get( "sv_ghostime", "6", 0 );
- sv_showclamp = Cvar_Get( "showclamp", "0", 0 );
- sv_enforcetime = Cvar_Get( "sv_enforcetime", "1", 0 );
- sv_allow_nodelta = Cvar_Get( "sv_allow_nodelta", "1", 0 );
+ sv_timeout = Cvar_Get("timeout", "90", 0);
+ sv_zombietime = Cvar_Get("zombietime", "2", 0);
+ sv_ghostime = Cvar_Get("sv_ghostime", "6", 0);
+ sv_showclamp = Cvar_Get("showclamp", "0", 0);
+ sv_enforcetime = Cvar_Get("sv_enforcetime", "1", 0);
+ sv_allow_nodelta = Cvar_Get("sv_allow_nodelta", "1", 0);
#if USE_FPS
- sv_fps = Cvar_Get( "sv_fps", "10", CVAR_LATCH );
+ sv_fps = Cvar_Get("sv_fps", "10", CVAR_LATCH);
#endif
- sv_force_reconnect = Cvar_Get( "sv_force_reconnect", "", CVAR_LATCH );
- sv_show_name_changes = Cvar_Get( "sv_show_name_changes", "0", 0 );
+ sv_force_reconnect = Cvar_Get("sv_force_reconnect", "", CVAR_LATCH);
+ sv_show_name_changes = Cvar_Get("sv_show_name_changes", "0", 0);
sv_airaccelerate = Cvar_Get("sv_airaccelerate", "0", CVAR_LATCH);
- sv_qwmod = Cvar_Get( "sv_qwmod", "0", CVAR_LATCH ); //atu QWMod
- sv_public = Cvar_Get( "public", "0", CVAR_LATCH );
- sv_password = Cvar_Get( "sv_password", "", CVAR_PRIVATE );
- sv_reserved_password = Cvar_Get( "sv_reserved_password", "", CVAR_PRIVATE );
- sv_locked = Cvar_Get( "sv_locked", "0", 0 );
- sv_novis = Cvar_Get ("sv_novis", "0", 0);
- sv_downloadserver = Cvar_Get( "sv_downloadserver", "", 0 );
- sv_redirect_address = Cvar_Get( "sv_redirect_address", "", 0 );
+ sv_qwmod = Cvar_Get("sv_qwmod", "0", CVAR_LATCH); //atu QWMod
+ sv_public = Cvar_Get("public", "0", CVAR_LATCH);
+ sv_password = Cvar_Get("sv_password", "", CVAR_PRIVATE);
+ sv_reserved_password = Cvar_Get("sv_reserved_password", "", CVAR_PRIVATE);
+ sv_locked = Cvar_Get("sv_locked", "0", 0);
+ sv_novis = Cvar_Get("sv_novis", "0", 0);
+ sv_downloadserver = Cvar_Get("sv_downloadserver", "", 0);
+ sv_redirect_address = Cvar_Get("sv_redirect_address", "", 0);
#ifdef _DEBUG
- sv_debug = Cvar_Get( "sv_debug", "0", 0 );
- sv_pad_packets = Cvar_Get( "sv_pad_packets", "0", 0 );
+ sv_debug = Cvar_Get("sv_debug", "0", 0);
+ sv_pad_packets = Cvar_Get("sv_pad_packets", "0", 0);
#endif
- sv_lan_force_rate = Cvar_Get( "sv_lan_force_rate", "0", CVAR_LATCH );
- sv_calcpings_method = Cvar_Get( "sv_calcpings_method", "1", 0 );
- sv_changemapcmd = Cvar_Get( "sv_changemapcmd", "", 0 );
+ sv_lan_force_rate = Cvar_Get("sv_lan_force_rate", "0", CVAR_LATCH);
+ sv_calcpings_method = Cvar_Get("sv_calcpings_method", "1", 0);
+ sv_changemapcmd = Cvar_Get("sv_changemapcmd", "", 0);
- sv_strafejump_hack = Cvar_Get( "sv_strafejump_hack", "1", CVAR_LATCH );
- sv_waterjump_hack = Cvar_Get( "sv_waterjump_hack", "0", CVAR_LATCH );
+ sv_strafejump_hack = Cvar_Get("sv_strafejump_hack", "1", CVAR_LATCH);
+ sv_waterjump_hack = Cvar_Get("sv_waterjump_hack", "0", CVAR_LATCH);
#ifndef _WIN32
- sv_oldgame_hack = Cvar_Get( "sv_oldgame_hack", "0", CVAR_LATCH );
+ sv_oldgame_hack = Cvar_Get("sv_oldgame_hack", "0", CVAR_LATCH);
#endif
#if USE_PACKETDUP
- sv_packetdup_hack = Cvar_Get( "sv_packetdup_hack", "0", 0 );
+ sv_packetdup_hack = Cvar_Get("sv_packetdup_hack", "0", 0);
#endif
- sv_allow_map = Cvar_Get( "sv_allow_map", "0", 0 );
+ sv_allow_map = Cvar_Get("sv_allow_map", "0", 0);
#if !USE_CLIENT
- sv_recycle = Cvar_Get( "sv_recycle", "0", 0 );
+ sv_recycle = Cvar_Get("sv_recycle", "0", 0);
#endif
- sv_enhanced_setplayer = Cvar_Get( "sv_enhanced_setplayer", "0", 0 );
+ sv_enhanced_setplayer = Cvar_Get("sv_enhanced_setplayer", "0", 0);
- sv_iplimit = Cvar_Get( "sv_iplimit", "3", 0 );
+ sv_iplimit = Cvar_Get("sv_iplimit", "3", 0);
- sv_status_show = Cvar_Get( "sv_status_show", "2", 0 );
+ sv_status_show = Cvar_Get("sv_status_show", "2", 0);
- sv_status_limit = Cvar_Get( "sv_status_limit", "15", 0 );
+ sv_status_limit = Cvar_Get("sv_status_limit", "15", 0);
sv_status_limit->changed = sv_status_limit_changed;
- sv_uptime = Cvar_Get( "sv_uptime", "0", 0 );
+ sv_uptime = Cvar_Get("sv_uptime", "0", 0);
- sv_auth_limit = Cvar_Get( "sv_auth_limit", "1", 0 );
+ sv_auth_limit = Cvar_Get("sv_auth_limit", "1", 0);
sv_auth_limit->changed = sv_auth_limit_changed;
- sv_rcon_limit = Cvar_Get( "sv_rcon_limit", "1", 0 );
+ sv_rcon_limit = Cvar_Get("sv_rcon_limit", "1", 0);
sv_rcon_limit->changed = sv_rcon_limit_changed;
- Cvar_Get( "sv_features", va( "%d", SV_FEATURES ), CVAR_ROM );
- g_features = Cvar_Get( "g_features", "0", CVAR_ROM );
+ Cvar_Get("sv_features", va("%d", SV_FEATURES), CVAR_ROM);
+ g_features = Cvar_Get("g_features", "0", CVAR_ROM);
- map_override_path = Cvar_Get( "map_override_path", "", 0 );
+ map_override_path = Cvar_Get("map_override_path", "", 0);
init_rate_limits();
@@ -1953,7 +1988,7 @@ void SV_Init( void ) {
#endif
// set up default pmove parameters
- PmoveInit( &sv_pmp );
+ PmoveInit(&sv_pmp);
#if USE_SYSCON
SV_SetConsoleTitle();
@@ -1974,51 +2009,52 @@ server is going to totally exit after returning from this function.
Also resposible for freeing all clients.
==================
*/
-static void SV_FinalMessage( const char *message, error_type_t type ) {
+static void SV_FinalMessage(const char *message, error_type_t type)
+{
client_t *client;
netchan_t *netchan;
int i;
- if( LIST_EMPTY( &sv_clientlist ) )
+ if (LIST_EMPTY(&sv_clientlist))
return;
- if( message ) {
- MSG_WriteByte( svc_print );
- MSG_WriteByte( PRINT_HIGH );
- MSG_WriteString( message );
+ if (message) {
+ MSG_WriteByte(svc_print);
+ MSG_WriteByte(PRINT_HIGH);
+ MSG_WriteString(message);
}
- if( type == ERR_RECONNECT )
- MSG_WriteByte( svc_reconnect );
+ if (type == ERR_RECONNECT)
+ MSG_WriteByte(svc_reconnect);
else
- MSG_WriteByte( svc_disconnect );
+ MSG_WriteByte(svc_disconnect);
// send it twice
// stagger the packets to crutch operating system limited buffers
- for( i = 0; i < 2; i++ ) {
- FOR_EACH_CLIENT( client ) {
- if( client->state == cs_zombie ) {
+ for (i = 0; i < 2; i++) {
+ FOR_EACH_CLIENT(client) {
+ if (client->state == cs_zombie) {
continue;
}
netchan = client->netchan;
- while( netchan->fragment_pending ) {
- netchan->TransmitNextFragment( netchan );
+ while (netchan->fragment_pending) {
+ netchan->TransmitNextFragment(netchan);
}
- netchan->Transmit( netchan, msg_write.cursize, msg_write.data, 1 );
+ netchan->Transmit(netchan, msg_write.cursize, msg_write.data, 1);
}
}
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
// free any data dynamically allocated
- FOR_EACH_CLIENT( client ) {
- if( client->state != cs_zombie ) {
- SV_CleanClient( client );
+ FOR_EACH_CLIENT(client) {
+ if (client->state != cs_zombie) {
+ SV_CleanClient(client);
}
- SV_RemoveClient( client );
+ SV_RemoveClient(client);
}
- List_Init( &sv_clientlist );
+ List_Init(&sv_clientlist);
}
/*
@@ -2029,12 +2065,13 @@ Called when each game quits, from Com_Quit or Com_Error.
Should be safe to call even if server is not fully initalized yet.
================
*/
-void SV_Shutdown( const char *finalmsg, error_type_t type ) {
- if( !sv_registered )
+void SV_Shutdown(const char *finalmsg, error_type_t type)
+{
+ if (!sv_registered)
return;
#if USE_MVD_CLIENT
- if( ge != &mvd_ge && !(type & MVD_SPAWN_INTERNAL) ) {
+ if (ge != &mvd_ge && !(type & MVD_SPAWN_INTERNAL)) {
// shutdown MVD client now if not already running the built-in MVD game module
// don't shutdown if called from internal MVD spawn function (ugly hack)!
MVD_Shutdown();
@@ -2047,25 +2084,25 @@ void SV_Shutdown( const char *finalmsg, error_type_t type ) {
#endif
#if USE_MVD_SERVER
- SV_MvdShutdown( type );
+ SV_MvdShutdown(type);
#endif
- SV_FinalMessage( finalmsg, type );
+ SV_FinalMessage(finalmsg, type);
SV_MasterShutdown();
SV_ShutdownGameProgs();
// free current level
- CM_FreeMap( &sv.cm );
- SV_FreeFile( sv.entitystring );
- memset( &sv, 0, sizeof( sv ) );
+ CM_FreeMap(&sv.cm);
+ SV_FreeFile(sv.entitystring);
+ memset(&sv, 0, sizeof(sv));
// free server static data
- Z_Free( svs.client_pool );
- Z_Free( svs.entities );
+ Z_Free(svs.client_pool);
+ Z_Free(svs.entities);
#if USE_ZLIB
- deflateEnd( &svs.z );
+ deflateEnd(&svs.z);
#endif
- memset( &svs, 0, sizeof( svs ) );
+ memset(&svs, 0, sizeof(svs));
// reset rate limits
init_rate_limits();
@@ -2078,13 +2115,13 @@ void SV_Shutdown( const char *finalmsg, error_type_t type ) {
sv_client = NULL;
sv_player = NULL;
- Cvar_Set( "sv_running", "0" );
- Cvar_Set( "sv_paused", "0" );
+ Cvar_Set("sv_running", "0");
+ Cvar_Set("sv_paused", "0");
#if USE_SYSCON
SV_SetConsoleTitle();
#endif
- Z_LeakTest( TAG_SERVER );
+ Z_LeakTest(TAG_SERVER);
}