Skip to content

Commit

Permalink
[Server] Added IsValidClientSnapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDushan committed May 4, 2024
1 parent c6057f1 commit 035d3dd
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/docs/Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* [Engine] Fixed compiling
* [Engine] Misc fixes
* [Engine] Added debug CRT heap for Windows platform
* [Server] Added IsValidClientSnapshot

2023-06-17 Dusan Jocic <dusanjocic@msn>
* [Engine] Misc fixes
Expand Down
35 changes: 35 additions & 0 deletions src/engine/server/serverSnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,16 @@ void idServerSnapshotSystemLocal::SendClientMessages(void) {
continue;
}

if(!IsValidClientSnapshot(c)) {
// not valid snapshot
continue;
}

// Client is downloading, don't send snapshots
if(*c->downloadName) {
continue;
}

// rain - changed <= CS_ZOMBIE to < CS_ZOMBIE so that the
// disconnect reason is properly sent in the network stream
if(c->state < CS_ZOMBIE) {
Expand Down Expand Up @@ -1248,3 +1258,28 @@ void idServerSnapshotSystemLocal::CheckClientUserinfoTimer(void) {
}
}
}

/*
=======================
idServerSnapshotSystemLocal::IsValidClientSnapshot
=======================
*/
bool idServerSnapshotSystemLocal::IsValidClientSnapshot(client_t *client) {
if(client->deltaMessage <= 0) {
return true;
}

if(client->state != CS_ACTIVE) {
return true;
}

if(client->lastPacketTime >= svs.time) {
return true;
}

if(client->netchan.outgoingSequence - client->deltaMessage < 29) {
return true;
}

return false;
}
1 change: 1 addition & 0 deletions src/engine/server/serverSnapshot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class idServerSnapshotSystemLocal : public idServerSnapshotSystem {
static sint RateMsec(client_t *client, sint messageSize);
static bool UpdateServerCommandsToClients(client_t *client, msg_t *msg,
bool allowPartial);
static bool IsValidClientSnapshot(client_t *client);
};

extern idServerSnapshotSystemLocal serverSnapshotSystemLocal;
Expand Down
44 changes: 22 additions & 22 deletions src/engine/soundSystem/sndSystem_adpcm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void S_AdpcmEncode(schar16 indata[], valueType outdata[], sint len,
struct adpcm_state *state) {
schar16 *inp;
schar8 *outp;
sint val, sign, delta, diff, step, valpred, vpdiff, index, outputbuffer,
sint val, sign, _delta, diff, step, valpred, vpdiff, index, outputbuffer,
bufferstep;

outp = reinterpret_cast<schar8 *>(outdata);
Expand All @@ -88,33 +88,33 @@ void S_AdpcmEncode(schar16 indata[], valueType outdata[], sint len,
/* Step 2 - Divide and clamp */
/* Note:
** This code *approximately* computes:
** delta = diff*4/step;
** vpdiff = (delta+0.5)*step/4;
** _delta = diff*4/step;
** vpdiff = (_delta+0.5)*step/4;
** but in shift step bits are dropped. The net result of this is
** that even if you have fast mul/div hardware you cannot put it to
** good use since the fixup would be too expensive.
*/
delta = 0;
_delta = 0;
vpdiff = (step >> 3);

if(diff >= step) {
delta = 4;
_delta = 4;
diff -= step;
vpdiff += step;
}

step >>= 1;

if(diff >= step) {
delta |= 2;
_delta |= 2;
diff -= step;
vpdiff += step;
}

step >>= 1;

if(diff >= step) {
delta |= 1;
_delta |= 1;
vpdiff += step;
}

Expand All @@ -133,9 +133,9 @@ void S_AdpcmEncode(schar16 indata[], valueType outdata[], sint len,
}

/* Step 5 - Assemble value, update index and step values */
delta |= sign;
_delta |= sign;

index += indexTable[delta];
index += indexTable[_delta];

if(index < 0) {
index = 0;
Expand All @@ -149,9 +149,9 @@ void S_AdpcmEncode(schar16 indata[], valueType outdata[], sint len,

/* Step 6 - Output value */
if(bufferstep) {
outputbuffer = (delta << 4) & 0xf0;
outputbuffer = (_delta << 4) & 0xf0;
} else {
*outp++ = (delta & 0x0f) | outputbuffer;
*outp++ = (_delta & 0x0f) | outputbuffer;
}

bufferstep = !bufferstep;
Expand All @@ -174,7 +174,7 @@ S_AdpcmDecode
void S_AdpcmDecode(const valueType indata[], schar16 *outdata, sint len,
struct adpcm_state *state) {
schar8 *inp;
sint outp, sign, delta, step, valpred, vpdiff, index, inputbuffer,
sint outp, sign, _delta, step, valpred, vpdiff, index, inputbuffer,
bufferstep;

outp = 0;
Expand All @@ -189,18 +189,18 @@ void S_AdpcmDecode(const valueType indata[], schar16 *outdata, sint len,

for(; len > 0 ; len--) {

/* Step 1 - get the delta value */
/* Step 1 - get the _delta value */
if(bufferstep) {
delta = inputbuffer & 0xf;
_delta = inputbuffer & 0xf;
} else {
inputbuffer = *inp++;
delta = (inputbuffer >> 4) & 0xf;
_delta = (inputbuffer >> 4) & 0xf;
}

bufferstep = !bufferstep;

/* Step 2 - Find new index value (for later) */
index += indexTable[delta];
index += indexTable[_delta];

if(index < 0) {
index = 0;
Expand All @@ -211,25 +211,25 @@ void S_AdpcmDecode(const valueType indata[], schar16 *outdata, sint len,
}

/* Step 3 - Separate sign and magnitude */
sign = delta & 8;
delta = delta & 7;
sign = _delta & 8;
_delta = _delta & 7;

/* Step 4 - Compute difference and new predicted value */
/*
** Computes 'vpdiff = (delta+0.5)*step/4', but see comment
** Computes 'vpdiff = (_delta+0.5)*step/4', but see comment
** in adpcm_coder.
*/
vpdiff = step >> 3;

if(delta & 4) {
if(_delta & 4) {
vpdiff += step;
}

if(delta & 2) {
if(_delta & 2) {
vpdiff += step >> 1;
}

if(delta & 1) {
if(_delta & 1) {
vpdiff += step >> 2;
}

Expand Down

0 comments on commit 035d3dd

Please sign in to comment.