Skip to content

Commit

Permalink
Send empty snapshots to clients downloading using legacy protocol
Browse files Browse the repository at this point in the history
Save bandwidth by excluding entity and player state changes from
snapshots sent to clients downloading using the legacy protocol. The
snapshots are mainly needed to update the reliableAcknowledge.

The idea is from Noah "Chomenor" Metzger's ioef-cmod project. Though I
implemented the dummy snapshot code closer to the real snapshot code.
  • Loading branch information
zturtleman committed May 18, 2018
1 parent 457b794 commit 58f257e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 11 deletions.
2 changes: 1 addition & 1 deletion code/server/server.h
Expand Up @@ -401,7 +401,7 @@ void SV_SendMessageToClient( msg_t *msg, client_t *client );
void SV_SendClientMessages( void );
void SV_SendClientSnapshot( client_t *client );
#ifdef ELITEFORCE
void SV_WriteSnapshotToClient( client_t *client, msg_t *msg );
void SV_WriteDummySnapshotToClient( client_t *client, msg_t *msg );
#endif

//
Expand Down
8 changes: 2 additions & 6 deletions code/server/sv_client.c
Expand Up @@ -1242,6 +1242,7 @@ int SV_SendDownloadMessages(void)
{
MSG_InitOOB(&msg, msgBuffer, sizeof(msgBuffer));
msg.compat = qtrue;
SV_WriteDummySnapshotToClient(cl, &msg);
}
else
#endif
Expand All @@ -1255,12 +1256,7 @@ int SV_SendDownloadMessages(void)
if(retval)
{
#ifdef ELITEFORCE
if(msg.compat)
{
// compat clients need svc_snapshot to update reliableAcknowledge
SV_WriteSnapshotToClient(cl, &msg);
}
else
if(!msg.compat)
#endif
MSG_WriteByte(&msg, svc_EOF);
SV_Netchan_Transmit(cl, &msg);
Expand Down
65 changes: 61 additions & 4 deletions code/server/sv_snapshot.c
Expand Up @@ -119,10 +119,7 @@ static void SV_EmitPacketEntities( clientSnapshot_t *from, clientSnapshot_t *to,
SV_WriteSnapshotToClient
==================
*/
#ifndef ELITEFORCE
static
#endif
void SV_WriteSnapshotToClient( client_t *client, msg_t *msg ) {
static void SV_WriteSnapshotToClient( client_t *client, msg_t *msg ) {
clientSnapshot_t *frame, *oldframe;
int lastframe;
int i;
Expand Down Expand Up @@ -216,6 +213,66 @@ void SV_WriteSnapshotToClient( client_t *client, msg_t *msg ) {
}


#ifdef ELITEFORCE
/*
==================
SV_WriteDummySnapshotToClient
While a client downloads a pk3 using the legacy protocol they need
a snapshot to update the reliableAcknowledge. This dummy snapshot
does not include areabits, entities, or player state updates.
==================
*/
void SV_WriteDummySnapshotToClient( client_t *client, msg_t *msg ) {
int snapFlags;
playerState_t ps;

MSG_WriteByte (msg, svc_snapshot);

// NOTE, MRE: now sent at the start of every message from server to client
// let the client know which reliable clientCommands we have received
#ifdef ELITEFORCE
if(msg->compat)
MSG_WriteLong( msg, client->lastClientCommand );
#else
//MSG_WriteLong( msg, client->lastClientCommand );
#endif

// send over the current server time so the client can drift
// its view of time to try to match
if( client->oldServerTime ) {
MSG_WriteLong (msg, sv.time + client->oldServerTime);
} else {
MSG_WriteLong (msg, sv.time);
}

// what we are delta'ing from
MSG_WriteByte (msg, 0);

snapFlags = svs.snapFlagServerBit;
if ( client->rateDelayed ) {
snapFlags |= SNAPFLAG_RATE_DELAYED;
}
if ( client->state != CS_ACTIVE ) {
snapFlags |= SNAPFLAG_NOT_ACTIVE;
}

MSG_WriteByte (msg, snapFlags);

// send over the areabits
MSG_WriteByte (msg, 0);
MSG_WriteData (msg, NULL, 0);

// delta encode the playerstate
Com_Memset (&ps, 0, sizeof(ps));
MSG_WriteDeltaPlayerstate( msg, &ps, &ps );

// delta encode the entities
MSG_WriteBits( msg, (MAX_GENTITIES-1), GENTITYNUM_BITS );
}
#endif


/*
==================
SV_UpdateServerCommandsToClient
Expand Down

0 comments on commit 58f257e

Please sign in to comment.