From 8de29326182c5c21a6a28573dfa3b2fca5e3c2f4 Mon Sep 17 00:00:00 2001 From: BotoX Date: Wed, 12 May 2021 20:09:30 +0200 Subject: [PATCH] fix some bugs: clients can be in the server "unconnected" lol silk ignores the outbuffer size, make it twice as big I guess --- demboyz/game/logic.cpp | 9 +++++---- demboyz/game/sourcecontext.cpp | 10 +++++++--- demboyz/io/voicewriter/voicedatawriter.cpp | 17 ++++++++++++----- demboyz/io/voicewriter/voicedatawriter.h | 2 +- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/demboyz/game/logic.cpp b/demboyz/game/logic.cpp index 1d0f587..6e1258f 100644 --- a/demboyz/game/logic.cpp +++ b/demboyz/game/logic.cpp @@ -243,8 +243,10 @@ void Logic::OnClientDeath(int client, int attacker, bool headshot, const char* w void Logic::OnClientChat(int client, bool bWantsToChat, const char* msgName, const char* msgSender, const char* msgText) { - assert(client >= 0 && client < MAX_PLAYERS); - assert(clients[client].connected != -1); + //assert(client >= 0 && client < MAX_PLAYERS); + //assert(clients[client].connected != -1); + if(client < 0 || client > MAX_PLAYERS || clients[client].connected == -1) + return; clients[client].chats++; @@ -262,8 +264,7 @@ void Logic::OnClientChat(int client, bool bWantsToChat, const char* msgName, con void Logic::OnClientVoiceChat(int client, float length) { - assert(client >= 0 && client < MAX_PLAYERS); - if (clients[client].connected == -1) + if(client < 0 || client > MAX_PLAYERS || clients[client].connected == -1) return; clients[client].voiceTime += length; diff --git a/demboyz/game/sourcecontext.cpp b/demboyz/game/sourcecontext.cpp index 5bcada7..15eb9ba 100644 --- a/demboyz/game/sourcecontext.cpp +++ b/demboyz/game/sourcecontext.cpp @@ -130,7 +130,7 @@ void SourceGameContext::OnNetPacket(NetPacket& packet) void SourceGameContext::OnGameEvent(const char *name, GameEvents::EventDataMap &data) { - // GameEvents::PrintEvent(name, data); + //GameEvents::PrintEvent(name, data); if (strcmp(name, "player_disconnect") == 0) { @@ -153,13 +153,17 @@ void SourceGameContext::OnGameEvent(const char *name, GameEvents::EventDataMap & else if (strcmp(name, "player_death") == 0) { int client = userIdLookUp[data["userid"].i16Value]; - assert(client >= 0 && client < MAX_PLAYERS); + //assert(client >= 0 && client < MAX_PLAYERS); + if(client < 0 || client > MAX_PLAYERS) + return; int attacker = data["attacker"].i16Value; if(attacker > 0) { attacker = userIdLookUp[attacker]; - assert(attacker >= 0 && attacker < MAX_PLAYERS); + //assert(attacker >= 0 && attacker < MAX_PLAYERS); + if(attacker < 0 || attacker > MAX_PLAYERS) + attacker = -1; } else attacker = -1; diff --git a/demboyz/io/voicewriter/voicedatawriter.cpp b/demboyz/io/voicewriter/voicedatawriter.cpp index 7731947..9d3067b 100644 --- a/demboyz/io/voicewriter/voicedatawriter.cpp +++ b/demboyz/io/voicewriter/voicedatawriter.cpp @@ -266,11 +266,14 @@ int VoiceDataWriter::ParseSteamVoicePacket(const uint8_t* bytes, int numBytes, P return numDecompressedSamples; int freeSamples = (sizeof(m_decodeBuffer) / sizeof(int16_t)) - numDecompressedSamples; + if(freeSamples <= 0) + return numDecompressedSamples; + if(payloadType == 3) { - length = MIN(freeSamples * 2, length); - memcpy(&m_decodeBuffer[numDecompressedSamples], &bytes[pos], length); - numDecompressedSamples += length / sizeof(int16_t); + int vlen = MIN(freeSamples * 2, length); + memcpy(&m_decodeBuffer[numDecompressedSamples], &bytes[pos], vlen); + numDecompressedSamples += vlen / sizeof(int16_t); } else if(payloadType == 4) { @@ -293,6 +296,7 @@ int VoiceDataWriter::ParseSteamVoicePacket(const uint8_t* bytes, int numBytes, P numEmptySamples = MIN(freeSamples, numEmptySamples); memset(&m_decodeBuffer[numDecompressedSamples], 0, numEmptySamples * sizeof(int16_t)); numDecompressedSamples += numEmptySamples; + freeSamples -= numEmptySamples; continue; } @@ -301,6 +305,7 @@ int VoiceDataWriter::ParseSteamVoicePacket(const uint8_t* bytes, int numBytes, P int ret = state.silk_decoder.Decompress(&bytes[tpos], chunkLength, &m_decodeBuffer[numDecompressedSamples], freeSamples); numDecompressedSamples += ret; + freeSamples -= ret; tpos += chunkLength; } } @@ -348,7 +353,9 @@ void VoiceDataWriter::OnNetPacket(NetPacket& packet) else if(packet.type == NetMsg::svc_VoiceData) { NetMsg::SVC_VoiceData* voiceData = static_cast(packet.data); - assert(voiceData->fromClientIndex < MAX_PLAYERS); + if(voiceData->fromClientIndex < 0 || voiceData->fromClientIndex >= MAX_PLAYERS) + return; + const char* guid = context->players[voiceData->fromClientIndex].info.guid; const uint8_t* bytes = voiceData->data.get(); @@ -381,7 +388,7 @@ void VoiceDataWriter::OnNetPacket(NetPacket& packet) } } - if(numDecompressedSamples <= 0) + if(numDecompressedSamples <= 0 || state.sampleRate <= 0) return; if(state.lastVoiceDataTick == -1) diff --git a/demboyz/io/voicewriter/voicedatawriter.h b/demboyz/io/voicewriter/voicedatawriter.h index 443312a..cd41814 100644 --- a/demboyz/io/voicewriter/voicedatawriter.h +++ b/demboyz/io/voicewriter/voicedatawriter.h @@ -88,7 +88,7 @@ private: int32_t m_silenceTicks = 0; const char* m_outputPath = nullptr; - int16_t m_decodeBuffer[16384]; + int16_t m_decodeBuffer[32768]; static const int sQuality = 3; eCodec m_Codec = CODEC_NONE;