aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--code/qcommon/common.c5
-rw-r--r--code/qcommon/net_chan.c66
-rw-r--r--code/qcommon/qcommon.h5
-rw-r--r--code/server/server.h1
-rw-r--r--code/server/sv_client.c6
-rw-r--r--code/server/sv_init.c1
-rw-r--r--code/server/sv_main.c1
-rw-r--r--code/server/sv_snapshot.c7
8 files changed, 90 insertions, 2 deletions
diff --git a/code/qcommon/common.c b/code/qcommon/common.c
index 1980edc..d1d40a9 100644
--- a/code/qcommon/common.c
+++ b/code/qcommon/common.c
@@ -77,6 +77,8 @@ cvar_t *com_buildScript; // for automated data building scripts
cvar_t *com_introPlayed;
cvar_t *cl_paused;
cvar_t *sv_paused;
+cvar_t *cl_packetdelay;
+cvar_t *sv_packetdelay;
cvar_t *com_cameraMode;
#if defined(_WIN32) && defined(_DEBUG)
cvar_t *com_noErrorInterrupt;
@@ -2085,6 +2087,7 @@ int Com_EventLoop( void ) {
MSG_Init( &buf, bufData, sizeof( bufData ) );
while ( 1 ) {
+ NET_FlushPacketQueue();
ev = Com_GetEvent();
// if no more events are available
@@ -2477,6 +2480,8 @@ void Com_Init( char *commandLine ) {
cl_paused = Cvar_Get ("cl_paused", "0", CVAR_ROM);
sv_paused = Cvar_Get ("sv_paused", "0", CVAR_ROM);
+ cl_packetdelay = Cvar_Get ("cl_packetdelay", "0", CVAR_CHEAT);
+ sv_packetdelay = Cvar_Get ("sv_packetdelay", "0", CVAR_CHEAT);
com_sv_running = Cvar_Get ("sv_running", "0", CVAR_ROM);
com_cl_running = Cvar_Get ("cl_running", "0", CVAR_ROM);
com_buildScript = Cvar_Get( "com_buildScript", "0", 0 );
diff --git a/code/qcommon/net_chan.c b/code/qcommon/net_chan.c
index 2ca1bfd..5c92c5d 100644
--- a/code/qcommon/net_chan.c
+++ b/code/qcommon/net_chan.c
@@ -615,6 +615,62 @@ void NET_SendLoopPacket (netsrc_t sock, int length, const void *data, netadr_t t
//=============================================================================
+typedef struct packetQueue_s {
+ struct packetQueue_s *next;
+ int length;
+ byte *data;
+ netadr_t to;
+ int release;
+} packetQueue_t;
+
+packetQueue_t *packetQueue = NULL;
+
+static void NET_QueuePacket( int length, const void *data, netadr_t to,
+ int offset )
+{
+ packetQueue_t *new, *next = packetQueue;
+
+ if(offset > 999)
+ offset = 999;
+
+ new = S_Malloc(sizeof(packetQueue_t));
+ new->data = S_Malloc(length);
+ Com_Memcpy(new->data, data, length);
+ new->length = length;
+ new->to = to;
+ new->release = Sys_Milliseconds() + offset;
+ new->next = NULL;
+
+ if(!packetQueue) {
+ packetQueue = new;
+ return;
+ }
+ while(next) {
+ if(!next->next) {
+ next->next = new;
+ return;
+ }
+ next = next->next;
+ }
+}
+
+void NET_FlushPacketQueue(void)
+{
+ packetQueue_t *last;
+ int now;
+
+ while(packetQueue) {
+ now = Sys_Milliseconds();
+ if(packetQueue->release >= now)
+ break;
+ Sys_SendPacket(packetQueue->length, packetQueue->data,
+ packetQueue->to);
+ last = packetQueue;
+ packetQueue = packetQueue->next;
+ Z_Free(last->data);
+ Z_Free(last);
+ }
+}
void NET_SendPacket( netsrc_t sock, int length, const void *data, netadr_t to ) {
@@ -634,7 +690,15 @@ void NET_SendPacket( netsrc_t sock, int length, const void *data, netadr_t to )
return;
}
- Sys_SendPacket( length, data, to );
+ if ( sock == NS_CLIENT && cl_packetdelay->integer > 0 ) {
+ NET_QueuePacket( length, data, to, cl_packetdelay->integer );
+ }
+ else if ( sock == NS_SERVER && sv_packetdelay->integer > 0 ) {
+ NET_QueuePacket( length, data, to, sv_packetdelay->integer );
+ }
+ else {
+ Sys_SendPacket( length, data, to );
+ }
}
/*
diff --git a/code/qcommon/qcommon.h b/code/qcommon/qcommon.h
index ada4fe0..202775f 100644
--- a/code/qcommon/qcommon.h
+++ b/code/qcommon/qcommon.h
@@ -159,7 +159,7 @@ void NET_Init( void );
void NET_Shutdown( void );
void NET_Restart( void );
void NET_Config( qboolean enableNetworking );
-
+void NET_FlushPacketQueue(void);
void NET_SendPacket (netsrc_t sock, int length, const void *data, netadr_t to);
void QDECL NET_OutOfBandPrint( netsrc_t net_socket, netadr_t adr, const char *format, ...);
void QDECL NET_OutOfBandData( netsrc_t sock, netadr_t adr, byte *format, int len );
@@ -758,6 +758,9 @@ extern cvar_t *com_altivec;
extern cvar_t *cl_paused;
extern cvar_t *sv_paused;
+extern cvar_t *cl_packetdelay;
+extern cvar_t *sv_packetdelay;
+
// com_speeds times
extern int time_game;
extern int time_frontend;
diff --git a/code/server/server.h b/code/server/server.h
index 31fd411..94bde88 100644
--- a/code/server/server.h
+++ b/code/server/server.h
@@ -238,6 +238,7 @@ extern cvar_t *sv_killserver;
extern cvar_t *sv_mapname;
extern cvar_t *sv_mapChecksum;
extern cvar_t *sv_serverid;
+extern cvar_t *sv_minRate;
extern cvar_t *sv_maxRate;
extern cvar_t *sv_minPing;
extern cvar_t *sv_maxPing;
diff --git a/code/server/sv_client.c b/code/server/sv_client.c
index 91e2123..2cb6c05 100644
--- a/code/server/sv_client.c
+++ b/code/server/sv_client.c
@@ -901,6 +901,12 @@ void SV_WriteDownloadToClient( client_t *cl , msg_t *msg )
rate = sv_maxRate->integer;
}
}
+ if ( sv_minRate->integer ) {
+ if ( sv_minRate->integer < 1000 )
+ Cvar_Set( "sv_minRate", "1000" );
+ if ( sv_minRate->integer > rate )
+ rate = sv_minRate->integer;
+ }
if (!rate) {
blockspersnap = 1;
diff --git a/code/server/sv_init.c b/code/server/sv_init.c
index 8472adf..e9f257b 100644
--- a/code/server/sv_init.c
+++ b/code/server/sv_init.c
@@ -582,6 +582,7 @@ void SV_Init (void) {
sv_hostname = Cvar_Get ("sv_hostname", "noname", CVAR_SERVERINFO | CVAR_ARCHIVE );
sv_maxclients = Cvar_Get ("sv_maxclients", "8", CVAR_SERVERINFO | CVAR_LATCH);
+ sv_minRate = Cvar_Get ("sv_minRate", "0", CVAR_ARCHIVE | CVAR_SERVERINFO );
sv_maxRate = Cvar_Get ("sv_maxRate", "0", CVAR_ARCHIVE | CVAR_SERVERINFO );
sv_minPing = Cvar_Get ("sv_minPing", "0", CVAR_ARCHIVE | CVAR_SERVERINFO );
sv_maxPing = Cvar_Get ("sv_maxPing", "0", CVAR_ARCHIVE | CVAR_SERVERINFO );
diff --git a/code/server/sv_main.c b/code/server/sv_main.c
index e7c6eb7..c2ae710 100644
--- a/code/server/sv_main.c
+++ b/code/server/sv_main.c
@@ -44,6 +44,7 @@ cvar_t *sv_killserver; // menu system can set to 1 to shut server down
cvar_t *sv_mapname;
cvar_t *sv_mapChecksum;
cvar_t *sv_serverid;
+cvar_t *sv_minRate;
cvar_t *sv_maxRate;
cvar_t *sv_minPing;
cvar_t *sv_maxPing;
diff --git a/code/server/sv_snapshot.c b/code/server/sv_snapshot.c
index db5164b..2786b84 100644
--- a/code/server/sv_snapshot.c
+++ b/code/server/sv_snapshot.c
@@ -551,6 +551,13 @@ static int SV_RateMsec( client_t *client, int messageSize ) {
rate = sv_maxRate->integer;
}
}
+ if ( sv_minRate->integer ) {
+ if ( sv_minRate->integer < 1000 )
+ Cvar_Set( "sv_minRate", "1000" );
+ if ( sv_minRate->integer > rate )
+ rate = sv_minRate->integer;
+ }
+
rateMsec = ( messageSize + HEADER_RATE_BYTES ) * 1000 / rate;
return rateMsec;