From ea929a619d8fa704aa974c060c8253a7edbf431f Mon Sep 17 00:00:00 2001 From: RogueException Date: Mon, 11 Jan 2016 20:22:51 -0400 Subject: [PATCH] Switched to new voice keepalives --- src/Discord.Net.Audio/Net/VoiceWebSocket.cs | 30 +++++++++------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/Discord.Net.Audio/Net/VoiceWebSocket.cs b/src/Discord.Net.Audio/Net/VoiceWebSocket.cs index 561a4cb8a..c7c4ee0e2 100644 --- a/src/Discord.Net.Audio/Net/VoiceWebSocket.cs +++ b/src/Discord.Net.Audio/Net/VoiceWebSocket.cs @@ -272,24 +272,6 @@ namespace Discord.Net.WebSockets voicePacket = new byte[MaxOpusSize + 12]; pingPacket = new byte[8]; - pingPacket[0] = 0x80; //Flags; - pingPacket[1] = 0xC9; //Payload Type - pingPacket[2] = 0x00; //Length - pingPacket[3] = 0x01; //Length (1*8 bytes) - pingPacket[4] = (byte)((_ssrc >> 24) & 0xFF); - pingPacket[5] = (byte)((_ssrc >> 16) & 0xFF); - pingPacket[6] = (byte)((_ssrc >> 8) & 0xFF); - pingPacket[7] = (byte)((_ssrc >> 0) & 0xFF); - if (_isEncrypted) - { - Buffer.BlockCopy(pingPacket, 0, nonce, 0, 8); - int ret = SecretBox.Encrypt(pingPacket, 8, encodedFrame, 0, nonce, _secretKey); - if (ret != 0) - throw new InvalidOperationException("Failed to encrypt ping packet"); - pingPacket = new byte[pingPacket.Length + 16]; - Buffer.BlockCopy(encodedFrame, 0, pingPacket, 0, pingPacket.Length); - Array.Clear(nonce, 0, nonce.Length); - } int rtpPacketLength = 0; voicePacket[0] = 0x80; //Flags; @@ -358,6 +340,18 @@ namespace Discord.Net.WebSockets //Is it time to send out another ping? if (currentTicks > nextPingTicks) { + //Increment in LE + for (int i = 0; i < 8; i++) + { + var b = pingPacket[i]; + if (b == byte.MaxValue) + pingPacket[i] = 0; + else + { + pingPacket[i] = (byte)(b + 1); + break; + } + } _udp.Send(pingPacket, pingPacket.Length); nextPingTicks = currentTicks + 5 * ticksPerSeconds; }