fix some bugs: clients can be in the server "unconnected" lol
silk ignores the outbuffer size, make it twice as big I guess
This commit is contained in:
parent
b727f5c904
commit
8de2932618
@ -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)
|
void Logic::OnClientChat(int client, bool bWantsToChat, const char* msgName, const char* msgSender, const char* msgText)
|
||||||
{
|
{
|
||||||
assert(client >= 0 && client < MAX_PLAYERS);
|
//assert(client >= 0 && client < MAX_PLAYERS);
|
||||||
assert(clients[client].connected != -1);
|
//assert(clients[client].connected != -1);
|
||||||
|
if(client < 0 || client > MAX_PLAYERS || clients[client].connected == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
clients[client].chats++;
|
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)
|
void Logic::OnClientVoiceChat(int client, float length)
|
||||||
{
|
{
|
||||||
assert(client >= 0 && client < MAX_PLAYERS);
|
if(client < 0 || client > MAX_PLAYERS || clients[client].connected == -1)
|
||||||
if (clients[client].connected == -1)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
clients[client].voiceTime += length;
|
clients[client].voiceTime += length;
|
||||||
|
@ -130,7 +130,7 @@ void SourceGameContext::OnNetPacket(NetPacket& packet)
|
|||||||
|
|
||||||
void SourceGameContext::OnGameEvent(const char *name, GameEvents::EventDataMap &data)
|
void SourceGameContext::OnGameEvent(const char *name, GameEvents::EventDataMap &data)
|
||||||
{
|
{
|
||||||
// GameEvents::PrintEvent(name, data);
|
//GameEvents::PrintEvent(name, data);
|
||||||
|
|
||||||
if (strcmp(name, "player_disconnect") == 0)
|
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)
|
else if (strcmp(name, "player_death") == 0)
|
||||||
{
|
{
|
||||||
int client = userIdLookUp[data["userid"].i16Value];
|
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;
|
int attacker = data["attacker"].i16Value;
|
||||||
if(attacker > 0)
|
if(attacker > 0)
|
||||||
{
|
{
|
||||||
attacker = userIdLookUp[attacker];
|
attacker = userIdLookUp[attacker];
|
||||||
assert(attacker >= 0 && attacker < MAX_PLAYERS);
|
//assert(attacker >= 0 && attacker < MAX_PLAYERS);
|
||||||
|
if(attacker < 0 || attacker > MAX_PLAYERS)
|
||||||
|
attacker = -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
attacker = -1;
|
attacker = -1;
|
||||||
|
@ -266,11 +266,14 @@ int VoiceDataWriter::ParseSteamVoicePacket(const uint8_t* bytes, int numBytes, P
|
|||||||
return numDecompressedSamples;
|
return numDecompressedSamples;
|
||||||
|
|
||||||
int freeSamples = (sizeof(m_decodeBuffer) / sizeof(int16_t)) - numDecompressedSamples;
|
int freeSamples = (sizeof(m_decodeBuffer) / sizeof(int16_t)) - numDecompressedSamples;
|
||||||
|
if(freeSamples <= 0)
|
||||||
|
return numDecompressedSamples;
|
||||||
|
|
||||||
if(payloadType == 3)
|
if(payloadType == 3)
|
||||||
{
|
{
|
||||||
length = MIN(freeSamples * 2, length);
|
int vlen = MIN(freeSamples * 2, length);
|
||||||
memcpy(&m_decodeBuffer[numDecompressedSamples], &bytes[pos], length);
|
memcpy(&m_decodeBuffer[numDecompressedSamples], &bytes[pos], vlen);
|
||||||
numDecompressedSamples += length / sizeof(int16_t);
|
numDecompressedSamples += vlen / sizeof(int16_t);
|
||||||
}
|
}
|
||||||
else if(payloadType == 4)
|
else if(payloadType == 4)
|
||||||
{
|
{
|
||||||
@ -293,6 +296,7 @@ int VoiceDataWriter::ParseSteamVoicePacket(const uint8_t* bytes, int numBytes, P
|
|||||||
numEmptySamples = MIN(freeSamples, numEmptySamples);
|
numEmptySamples = MIN(freeSamples, numEmptySamples);
|
||||||
memset(&m_decodeBuffer[numDecompressedSamples], 0, numEmptySamples * sizeof(int16_t));
|
memset(&m_decodeBuffer[numDecompressedSamples], 0, numEmptySamples * sizeof(int16_t));
|
||||||
numDecompressedSamples += numEmptySamples;
|
numDecompressedSamples += numEmptySamples;
|
||||||
|
freeSamples -= numEmptySamples;
|
||||||
continue;
|
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);
|
int ret = state.silk_decoder.Decompress(&bytes[tpos], chunkLength, &m_decodeBuffer[numDecompressedSamples], freeSamples);
|
||||||
numDecompressedSamples += ret;
|
numDecompressedSamples += ret;
|
||||||
|
freeSamples -= ret;
|
||||||
tpos += chunkLength;
|
tpos += chunkLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -348,7 +353,9 @@ void VoiceDataWriter::OnNetPacket(NetPacket& packet)
|
|||||||
else if(packet.type == NetMsg::svc_VoiceData)
|
else if(packet.type == NetMsg::svc_VoiceData)
|
||||||
{
|
{
|
||||||
NetMsg::SVC_VoiceData* voiceData = static_cast<NetMsg::SVC_VoiceData*>(packet.data);
|
NetMsg::SVC_VoiceData* voiceData = static_cast<NetMsg::SVC_VoiceData*>(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 char* guid = context->players[voiceData->fromClientIndex].info.guid;
|
||||||
|
|
||||||
const uint8_t* bytes = voiceData->data.get();
|
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;
|
return;
|
||||||
|
|
||||||
if(state.lastVoiceDataTick == -1)
|
if(state.lastVoiceDataTick == -1)
|
||||||
|
@ -88,7 +88,7 @@ private:
|
|||||||
int32_t m_silenceTicks = 0;
|
int32_t m_silenceTicks = 0;
|
||||||
const char* m_outputPath = nullptr;
|
const char* m_outputPath = nullptr;
|
||||||
|
|
||||||
int16_t m_decodeBuffer[16384];
|
int16_t m_decodeBuffer[32768];
|
||||||
|
|
||||||
static const int sQuality = 3;
|
static const int sQuality = 3;
|
||||||
eCodec m_Codec = CODEC_NONE;
|
eCodec m_Codec = CODEC_NONE;
|
||||||
|
Loading…
Reference in New Issue
Block a user