From 58f257e8686cdd89262538f85745596f682434f3 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Fri, 18 May 2018 09:40:53 -0500 Subject: [PATCH] Send empty snapshots to clients downloading using legacy protocol 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. --- code/server/server.h | 2 +- code/server/sv_client.c | 8 ++--- code/server/sv_snapshot.c | 65 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/code/server/server.h b/code/server/server.h index 3762c81d..e03609ee 100644 --- a/code/server/server.h +++ b/code/server/server.h @@ -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 // diff --git a/code/server/sv_client.c b/code/server/sv_client.c index ed486837..0f403b01 100644 --- a/code/server/sv_client.c +++ b/code/server/sv_client.c @@ -1242,6 +1242,7 @@ int SV_SendDownloadMessages(void) { MSG_InitOOB(&msg, msgBuffer, sizeof(msgBuffer)); msg.compat = qtrue; + SV_WriteDummySnapshotToClient(cl, &msg); } else #endif @@ -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); diff --git a/code/server/sv_snapshot.c b/code/server/sv_snapshot.c index f0335373..4e073ac2 100644 --- a/code/server/sv_snapshot.c +++ b/code/server/sv_snapshot.c @@ -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; @@ -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