- Apply parts of Ben Millwood's target bitfield patch (#3787)

- Fix Ryan's FIXME and have voip packet buffer on the server dynamically allocated via Z_Malloc and store pointers in a circular buffer
- Improve voip target parsing on top of Ben Millwood's patch
- Add new "spatial" target where speaker is spatialized in 3d space and can be heard by all clients in hearing range (s_alMaxDistance)
  (#4467)
- Decrease voip sound lengths from 240ms to 80ms per voip packet to mitigate udp packet loss and decrease latency
- Protocol version incremented to 71
This commit is contained in:
Thilo Schulz 2011-07-27 15:47:29 +00:00
parent 41ac8a232a
commit 2349148cf1
19 changed files with 403 additions and 241 deletions

View file

@ -1176,56 +1176,6 @@ int SV_SendDownloadMessages(void)
return numDLs;
}
#ifdef USE_VOIP
/*
==================
SV_WriteVoipToClient
Check to see if there is any VoIP queued for a client, and send if there is.
==================
*/
void SV_WriteVoipToClient( client_t *cl, msg_t *msg )
{
if(*cl->downloadName)
{
cl->queuedVoipPackets = 0;
return; // no VoIP allowed if download is going, to save bandwidth.
}
if(cl->queuedVoipPackets)
{
int totalbytes = 0;
int i;
voipServerPacket_t *packet;
// Write as many VoIP packets as we reasonably can...
for(i = cl->queuedVoipIndex; i < cl->queuedVoipPackets; i++)
{
packet = cl->voipPacket[i % ARRAY_LEN(cl->voipPacket)];
totalbytes += packet->len;
if (totalbytes > (msg->maxsize - msg->cursize) / 2)
break;
MSG_WriteByte(msg, svc_voip);
MSG_WriteShort(msg, packet->sender);
MSG_WriteByte(msg, (byte) packet->generation);
MSG_WriteLong(msg, packet->sequence);
MSG_WriteByte(msg, packet->frames);
MSG_WriteShort(msg, packet->len);
MSG_WriteData(msg, packet->data, packet->len);
Z_Free(packet);
}
cl->queuedVoipPackets -= i;
cl->queuedVoipIndex += i;
cl->queuedVoipIndex %= ARRAY_LEN(cl->voipPacket);
}
}
#endif
/*
=================
SV_Disconnect_f
@ -1800,8 +1750,15 @@ static void SV_UserMove( client_t *cl, msg_t *msg, qboolean delta ) {
#ifdef USE_VOIP
static
qboolean SV_ShouldIgnoreVoipSender(const client_t *cl)
/*
==================
SV_ShouldIgnoreVoipSender
Blocking of voip packets based on source client
==================
*/
static qboolean SV_ShouldIgnoreVoipSender(const client_t *cl)
{
if (!sv_voip->integer)
return qtrue; // VoIP disabled on this server.
@ -1814,33 +1771,25 @@ qboolean SV_ShouldIgnoreVoipSender(const client_t *cl)
}
static
void SV_UserVoip( client_t *cl, msg_t *msg ) {
const int sender = (int) (cl - svs.clients);
const int generation = MSG_ReadByte(msg);
const int sequence = MSG_ReadLong(msg);
const int frames = MSG_ReadByte(msg);
const int recip1 = MSG_ReadLong(msg);
const int recip2 = MSG_ReadLong(msg);
const int recip3 = MSG_ReadLong(msg);
const int packetsize = MSG_ReadShort(msg);
void SV_UserVoip(client_t *cl, msg_t *msg)
{
int sender, generation, sequence, frames, packetsize;
uint8_t recips[(MAX_CLIENTS + 7) / 8];
int flags;
byte encoded[sizeof(cl->voipPacket[0]->data)];
client_t *client = NULL;
voipServerPacket_t *packet = NULL;
int i;
if (generation < 0)
return; // short/invalid packet, bail.
else if (sequence < 0)
return; // short/invalid packet, bail.
else if (frames < 0)
return; // short/invalid packet, bail.
else if (recip1 < 0)
return; // short/invalid packet, bail.
else if (recip2 < 0)
return; // short/invalid packet, bail.
else if (recip3 < 0)
return; // short/invalid packet, bail.
else if (packetsize < 0)
sender = cl - svs.clients;
generation = MSG_ReadByte(msg);
sequence = MSG_ReadLong(msg);
frames = MSG_ReadByte(msg);
MSG_ReadData(msg, recips, sizeof(recips));
flags = MSG_ReadByte(msg);
packetsize = MSG_ReadShort(msg);
if (msg->readcount > msg->cursize)
return; // short/invalid packet, bail.
if (packetsize > sizeof (encoded)) { // overlarge packet?
@ -1865,10 +1814,6 @@ void SV_UserVoip( client_t *cl, msg_t *msg ) {
// !!! FIXME: reject if not speex narrowband codec.
// !!! FIXME: decide if this is bogus data?
// (the three recip* values are 31 bits each (ignores sign bit so we can
// get a -1 error from MSG_ReadLong() ... ), allowing for 93 clients.)
assert( sv_maxclients->integer < 93 );
// decide who needs this VoIP packet sent to them...
for (i = 0, client = svs.clients; i < sv_maxclients->integer ; i++, client++) {
if (client->state != CS_ACTIVE)
@ -1876,18 +1821,20 @@ void SV_UserVoip( client_t *cl, msg_t *msg ) {
else if (i == sender)
continue; // don't send voice packet back to original author.
else if (!client->hasVoip)
continue; // no VoIP support, or support disabled.
continue; // no VoIP support, or unsupported protocol
else if (client->muteAllVoip)
continue; // client is ignoring everyone.
else if (client->ignoreVoipFromClient[sender])
continue; // client is ignoring this talker.
else if (*cl->downloadName) // !!! FIXME: possible to DoS?
continue; // no VoIP allowed if downloading, to save bandwidth.
else if ( ((i >= 0) && (i < 31)) && ((recip1 & (1 << (i-0))) == 0) )
continue; // not addressed to this player.
else if ( ((i >= 31) && (i < 62)) && ((recip2 & (1 << (i-31))) == 0) )
continue; // not addressed to this player.
else if ( ((i >= 62) && (i < 93)) && ((recip3 & (1 << (i-62))) == 0) )
if(Com_IsVoipTarget(recips, sizeof(recips), i))
flags |= VOIP_DIRECT;
else
flags &= ~VOIP_DIRECT;
if (!(flags & (VOIP_SPATIAL | VOIP_DIRECT)))
continue; // not addressed to this player.
// Transmit this packet to the client.
@ -1902,6 +1849,7 @@ void SV_UserVoip( client_t *cl, msg_t *msg ) {
packet->len = packetsize;
packet->generation = generation;
packet->sequence = sequence;
packet->flags = flags;
memcpy(packet->data, encoded, packetsize);
client->voipPacket[(client->queuedVoipIndex + client->queuedVoipPackets) % ARRAY_LEN(client->voipPacket)] = packet;