summaryrefslogtreecommitdiff
path: root/src/server/sv_net_chan.c
diff options
context:
space:
mode:
authorThilo Schulz <arny@ats.s.bawue.de>2011-07-13 17:11:30 +0000
committerTim Angus <tim@ngus.net>2013-01-10 22:27:30 +0000
commit2bf2118d79994cfd805c3ffb5b421c6a65658b84 (patch)
tree867a9c4ac0d975e7aca4ee20714de8c97646ccde /src/server/sv_net_chan.c
parent5038ffeb97413a867d0bdadf761e2ba727781742 (diff)
- Improve snapshot rate and data rate control - Make server send packet fragments and queued packets when server is idle - Voip protocol detection is tied to com_protocol making past-end-of-message reading unncessary - Use Hunk_AllocateTempMemory() for buffering VOIP packets and fix buffering scheme that ryan hates so much - Disable packet scrambling for new protocol as it is useless now - Get rid of the old packet scrambling functions predating latest point release - Use Hunk_AllocateTempMemory() for netchan packet queue to fix memory leak when client gets disconnected with packets in the queue - Use Hunk_AllocateTempMemory() for download blocks to fix memory leak when client gets disconnected with download blocks in the queue - Fix SV_RateMsec to account for udp/udp6 packet lengths
Diffstat (limited to 'src/server/sv_net_chan.c')
-rw-r--r--src/server/sv_net_chan.c103
1 files changed, 70 insertions, 33 deletions
diff --git a/src/server/sv_net_chan.c b/src/server/sv_net_chan.c
index 33d04b3f..79e294f0 100644
--- a/src/server/sv_net_chan.c
+++ b/src/server/sv_net_chan.c
@@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../qcommon/qcommon.h"
#include "server.h"
+#ifdef LEGACY_PROTOCOL
/*
==============
SV_Netchan_Encode
@@ -128,38 +129,63 @@ static void SV_Netchan_Decode( client_t *client, msg_t *msg ) {
*(msg->data + i) = *(msg->data + i) ^ key;
}
}
+#endif
+
+/*
+=================
+SV_Netchan_TransmitNextInQueue
+=================
+*/
+void SV_Netchan_TransmitNextInQueue(client_t *client)
+{
+ netchan_buffer_t *netbuf;
+
+ Com_DPrintf("#462 Netchan_TransmitNextFragment: popping a queued message for transmit\n");
+ netbuf = client->netchan_start_queue;
+
+#ifdef LEGACY_PROTOCOL
+ if(client->compat)
+ SV_Netchan_Encode(client, &netbuf->msg);
+#endif
+
+ Netchan_Transmit(&client->netchan, netbuf->msg.cursize, netbuf->msg.data);
+
+ // pop from queue
+ client->netchan_start_queue = netbuf->next;
+ if(!client->netchan_start_queue)
+ {
+ Com_DPrintf("#462 Netchan_TransmitNextFragment: emptied queue\n");
+ client->netchan_end_queue = &client->netchan_start_queue;
+ }
+ else
+ Com_DPrintf("#462 Netchan_TransmitNextFragment: remaining queued message\n");
+
+ Hunk_FreeTempMemory(netbuf);
+}
/*
=================
SV_Netchan_TransmitNextFragment
+Transmit the next fragment and the next queued packet
+Return number of ms until next message can be sent based on throughput given by client rate,
+-1 if no packet was sent.
=================
*/
-void SV_Netchan_TransmitNextFragment( client_t *client ) {
- Netchan_TransmitNextFragment( &client->netchan );
- if (!client->netchan.unsentFragments)
+
+int SV_Netchan_TransmitNextFragment(client_t *client)
+{
+ if(client->netchan.unsentFragments)
{
- // make sure the netchan queue has been properly initialized (you never know)
- if ((!client->netchan_end_queue) && (client->state >= CS_CONNECTED)) {
- Com_Error(ERR_DROP, "netchan queue is not properly initialized in SV_Netchan_TransmitNextFragment");
- }
- // the last fragment was transmitted, check wether we have queued messages
- if (client->netchan_start_queue) {
- netchan_buffer_t *netbuf;
- Com_DPrintf("#462 Netchan_TransmitNextFragment: popping a queued message for transmit\n");
- netbuf = client->netchan_start_queue;
- SV_Netchan_Encode( client, &netbuf->msg );
- Netchan_Transmit( &client->netchan, netbuf->msg.cursize, netbuf->msg.data );
- // pop from queue
- client->netchan_start_queue = netbuf->next;
- if (!client->netchan_start_queue) {
- Com_DPrintf("#462 Netchan_TransmitNextFragment: emptied queue\n");
- client->netchan_end_queue = &client->netchan_start_queue;
- }
- else
- Com_DPrintf("#462 Netchan_TransmitNextFragment: remaining queued message\n");
- Z_Free(netbuf);
- }
- }
+ Netchan_TransmitNextFragment(&client->netchan);
+ return SV_RateMsec(client);
+ }
+ else if(client->netchan_start_queue)
+ {
+ SV_Netchan_TransmitNextInQueue(client);
+ return SV_RateMsec(client);
+ }
+
+ return -1;
}
@@ -174,22 +200,28 @@ then buffer them and make sure they get sent in correct order
================
*/
-void SV_Netchan_Transmit( client_t *client, msg_t *msg) { //int length, const byte *data ) {
+void SV_Netchan_Transmit( client_t *client, msg_t *msg)
+{
MSG_WriteByte( msg, svc_EOF );
- if (client->netchan.unsentFragments) {
+
+ if(client->netchan.unsentFragments || client->netchan_start_queue)
+ {
netchan_buffer_t *netbuf;
Com_DPrintf("#462 SV_Netchan_Transmit: unsent fragments, stacked\n");
- netbuf = (netchan_buffer_t *)Z_Malloc(sizeof(netchan_buffer_t));
+ netbuf = (netchan_buffer_t *) Hunk_AllocateTempMemory(sizeof(netchan_buffer_t));
// store the msg, we can't store it encoded, as the encoding depends on stuff we still have to finish sending
MSG_Copy(&netbuf->msg, netbuf->msgBuffer, sizeof( netbuf->msgBuffer ), msg);
netbuf->next = NULL;
// insert it in the queue, the message will be encoded and sent later
*client->netchan_end_queue = netbuf;
client->netchan_end_queue = &(*client->netchan_end_queue)->next;
- // emit the next fragment of the current message for now
- Netchan_TransmitNextFragment(&client->netchan);
- } else {
- SV_Netchan_Encode( client, msg );
+ }
+ else
+ {
+#ifdef LEGACY_PROTOCOL
+ if(client->compat)
+ SV_Netchan_Encode(client, msg);
+#endif
Netchan_Transmit( &client->netchan, msg->cursize, msg->data );
}
}
@@ -204,7 +236,12 @@ qboolean SV_Netchan_Process( client_t *client, msg_t *msg ) {
ret = Netchan_Process( &client->netchan, msg );
if (!ret)
return qfalse;
- SV_Netchan_Decode( client, msg );
+
+#ifdef LEGACY_PROTOCOL
+ if(client->compat)
+ SV_Netchan_Decode(client, msg);
+#endif
+
return qtrue;
}