Skip to content

Commit

Permalink
server: ported the udp download code from ioq3 with fixes, refs #330
Browse files Browse the repository at this point in the history
  • Loading branch information
jackeri committed Dec 30, 2014
1 parent 8ec70bc commit 108ca85
Show file tree
Hide file tree
Showing 9 changed files with 335 additions and 176 deletions.
7 changes: 3 additions & 4 deletions src/client/cl_parse.c
Expand Up @@ -644,7 +644,7 @@ void CL_SystemInfoChanged(void)
if (Q_stricmp(key, "g_synchronousClients") && Q_stricmp(key, "pmove_fixed") &&
Q_stricmp(key, "pmove_msec"))
{
Com_Printf(S_COLOR_YELLOW "WARNING: server is not allowed to set %s=%s\n", key, value);
Com_DPrintf(S_COLOR_YELLOW "WARNING: server is not allowed to set %s=%s\n", key, value);
continue;
}
}
Expand Down Expand Up @@ -799,8 +799,7 @@ void CL_ParseDownload(msg_t *msg)
// read the data
block = MSG_ReadShort(msg);

// www dl
// if we haven't acked the download redirect yet
// www dl, if we haven't acknowledged the download redirect yet
if (block == -1)
{
if (!cls.download.bWWWDl)
Expand Down Expand Up @@ -854,7 +853,7 @@ void CL_ParseDownload(msg_t *msg)
}
else
{
// server keeps sending that message till we ack it, eat and ignore
// server keeps sending that message till we acknowledge it, eat and ignore
//MSG_ReadLong( msg );
MSG_ReadString(msg);
MSG_ReadLong(msg);
Expand Down
8 changes: 8 additions & 0 deletions src/qcommon/net_chan.c
Expand Up @@ -142,6 +142,10 @@ void Netchan_TransmitNextFragment(netchan_t *chan)
// send the datagram
NET_SendPacket(chan->sock, send.cursize, send.data, chan->remoteAddress);

// Store send time and size of this packet for rate control
chan->lastSentTime = Sys_Milliseconds();
chan->lastSentSize = send.cursize;

if (showpackets->integer)
{
Com_Printf("%s send %4i : s=%i fragment=%i,%i\n"
Expand Down Expand Up @@ -214,6 +218,10 @@ void Netchan_Transmit(netchan_t *chan, int length, const byte *data)
// send the datagram
NET_SendPacket(chan->sock, send.cursize, send.data, chan->remoteAddress);

// Store send time and size of this packet for rate control
chan->lastSentTime = Sys_Milliseconds();
chan->lastSentSize = send.cursize;

if (showpackets->integer)
{
Com_Printf("%s send %4i : s=%i ack=%i\n"
Expand Down
9 changes: 6 additions & 3 deletions src/qcommon/qcommon.h
Expand Up @@ -229,9 +229,10 @@ void NET_Sleep(int msec);
* @brief max length of a message, which may be fragmented into multiple packets
*/
#define MAX_MSGLEN 32768
#define MAX_DOWNLOAD_WINDOW 8 // max of eight download frames
#define MAX_DOWNLOAD_BLKSIZE 2048 // 2048 byte block chunks

// ACK window of 48 download chunks.Cannot set this higher, or clients will overflow the reliable commands buffer
#define MAX_DOWNLOAD_WINDOW 48
// 896 byte block chunks
#define MAX_DOWNLOAD_BLKSIZE 1024
/*
Netchan handles packet fragmentation and out of order / duplicate suppression
*/
Expand Down Expand Up @@ -261,6 +262,8 @@ typedef struct
int unsentLength;
byte unsentBuffer[MAX_MSGLEN];

int lastSentTime;
int lastSentSize;
} netchan_t;

void Netchan_Init(int qport);
Expand Down
15 changes: 10 additions & 5 deletions src/server/server.h
Expand Up @@ -151,7 +151,7 @@ typedef struct

typedef enum
{
CS_FREE, // can be reused for a new connection
CS_FREE = 0, // can be reused for a new connection
CS_ZOMBIE, // client has been disconnected, but don't reuse connection for a couple seconds
CS_CONNECTED, // has been assigned to a client_t, but no gamestate yet
CS_PRIMED, // gamestate has been sent, but client hasn't sent a usercmd
Expand Down Expand Up @@ -232,7 +232,7 @@ typedef struct client_s
// in case large fragmented messages are stacking up
// buffer them into this queue, and hand them out to netchan as needed
netchan_buffer_t *netchan_start_queue;
netchan_buffer_t *netchan_end_queue;
netchan_buffer_t **netchan_end_queue;

int downloadnotify;

Expand Down Expand Up @@ -368,6 +368,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;
Expand All @@ -380,7 +381,6 @@ extern cvar_t *sv_onlyVisibleClients;
extern cvar_t *sv_showAverageBPS; // net debugging

// autodl
extern cvar_t *sv_dl_maxRate;
extern cvar_t *sv_dl_timeout;

extern cvar_t *sv_wwwDownload; // general flag to enable/disable www download redirects
Expand All @@ -393,6 +393,8 @@ extern cvar_t *sv_wwwFallbackURL;
extern cvar_t *sv_cheats;
extern cvar_t *sv_packetdelay;

extern cvar_t *sv_dlRate;

extern cvar_t *sv_fullmsg;

extern cvar_t *sv_advert;
Expand Down Expand Up @@ -469,6 +471,7 @@ void SV_RemoveOperatorCommands(void);
void SV_MasterHeartbeat(const char *hbname);
void SV_MasterShutdown(void);
void SV_MasterGameCompleteStatus(void);
int SV_RateMsec(client_t *client);

typedef struct leakyBucket_s leakyBucket_t;
struct leakyBucket_s
Expand Down Expand Up @@ -525,7 +528,9 @@ void SV_FreeClientNetChan(client_t *client);
void SV_DropClient(client_t *drop, const char *reason);
void SV_ExecuteClientCommand(client_t *cl, const char *s, qboolean clientOK, qboolean premaprestart);
void SV_ClientThink(client_t *cl, usercmd_t *cmd);
void SV_WriteDownloadToClient(client_t *cl, msg_t *msg);
int SV_WriteDownloadToClient(client_t *cl, msg_t *msg);
int SV_SendDownloadMessages(void);
int SV_SendQueuedMessages(void);
void SV_UpdateUserinfo_f(client_t *cl);

// sv_ccmds.c
Expand Down Expand Up @@ -624,7 +629,7 @@ void SV_ClipToEntity(trace_t *trace, const vec3_t start, const vec3_t mins, cons

// sv_net_chan.c
void SV_Netchan_Transmit(client_t *client, msg_t *msg);
void SV_Netchan_TransmitNextFragment(client_t *client);
int SV_Netchan_TransmitNextFragment(client_t *client);
qboolean SV_Netchan_Process(client_t *client, msg_t *msg);

// cl->downloadnotify
Expand Down

0 comments on commit 108ca85

Please sign in to comment.