Пример #1
0
        private DiscordIpPort GetIPAndPortFromPacket(byte[] packet)
        {
            DiscordIpPort returnVal = new DiscordIpPort();
            //quoth thy danny
            //#the ip is ascii starting at the 4th byte and ending at the first null
            int startingIPIndex = 4;
            int endingIPIndex   = 4;

            for (int i = startingIPIndex; i < packet.Length; i++)
            {
                if (packet[i] != (byte)0)
                {
                    endingIPIndex++;
                }
                else
                {
                    break;
                }
            }

            byte[] ipArray = new byte[endingIPIndex - startingIPIndex];
            Buffer.BlockCopy(packet, startingIPIndex, ipArray, 0, ipArray.Length);
            //quoth thy wise danny part two:
            //# the port is a little endian unsigned short in the last two bytes
            //# yes, this is different endianness from everything else
            int port = packet[packet.Length - 2] | packet[packet.Length - 1] << 8;

            returnVal.Address = IPAddress.Parse(System.Text.Encoding.ASCII.GetString(ipArray));
            returnVal.port    = port;

            VoiceDebugLogger.Log($"Our IP is {returnVal.Address} and we're using port {returnVal.port}.");
            return(returnVal);
        }
Пример #2
0
        /// <summary>
        /// Sends our IP over UDP for Discord's voice server to process. Also sends op 1
        /// </summary>
        /// <param name="buffer">The byte[] returned after sending your ssrc.</param>
        /// <returns></returns>
        private async Task SendIPOverUDP(DiscordIpPort ipPort)
        {
            string msg = JsonConvert.SerializeObject(new
            {
                op = 1,
                d  = new
                {
                    protocol = "udp",
                    data     = new
                    {
                        address = ipPort.Address.ToString(),
                        port    = ipPort.port,
                        mode    = "plain"
                    }
                }
            });

            VoiceDebugLogger.Log("Sending our IP over WebSocket ( " + msg.ToString() + " ) ");
            await Task.Run(() => VoiceWebSocket.Send(msg)).ConfigureAwait(false); //idk lets try it
        }
        private DiscordIpPort GetIPAndPortFromPacket(byte[] packet)
        {
            DiscordIpPort returnVal = new DiscordIpPort();
            //quoth thy danny
                //#the ip is ascii starting at the 4th byte and ending at the first null
            int startingIPIndex = 4;
            int endingIPIndex = 4;
            for(int i = startingIPIndex; i < packet.Length; i++)
            {
                if (packet[i] != (byte)0)
                    endingIPIndex++;
                else
                    break;
            }

            byte[] ipArray = new byte[endingIPIndex - startingIPIndex];
            for(int i = 0; i < ipArray.Length; i++)
            {
                ipArray[i] = packet[i + startingIPIndex];
            }
            //quoth thy wise danny part two:
            //# the port is a little endian unsigned short in the last two bytes
            //# yes, this is different endianness from everything else
            int port = packet[packet.Length - 2] | packet[packet.Length - 1] << 8;

            returnVal.Address = IPAddress.Parse(System.Text.Encoding.ASCII.GetString(ipArray));
            returnVal.port = port;

            VoiceDebugLogger.Log($"Our IP is {returnVal.Address} and we're using port {returnVal.port}.");
            return returnVal;
        }
 private async Task SendOurIP(DiscordIpPort ipPortStruct)
 {
     string msg = JsonConvert.SerializeObject(new
     {
         op = 1,
         d = new
         {
             protocol = "udp",
             data = new
             {
                 address = ipPortStruct.Address.ToString(),
                 port = ipPortStruct.port,
                 mode = "plain"
             }
         }
     });
     VoiceDebugLogger.Log("Sending our IP over WebSocket...");
     VoiceWebSocket.SendAsync(msg, (__) => { });
 }
Пример #5
0
 /// <summary>
 /// Sends our IP over UDP for Discord's voice server to process. Also sends op 1
 /// </summary>
 /// <param name="buffer">The byte[] returned after sending your ssrc.</param>
 /// <returns></returns>
 private async Task SendIPOverUDP(DiscordIpPort ipPort)
 {
     string msg = JsonConvert.SerializeObject(new
     {
         op = 1,
         d = new
         {
             protocol = "udp",
             data = new
             {
                 address = ipPort.Address.ToString(),
                 port = ipPort.port,
                 mode = "plain"
             }
         }
     });
     VoiceDebugLogger.Log("Sending our IP over WebSocket ( " + msg.ToString() + " ) ");
     await Task.Run(() => VoiceWebSocket.Send(msg)).ConfigureAwait(false); //idk lets try it
 }