diff --git a/src/Discord.Net.Core/Net/Udp/IUdpSocket.cs b/src/Discord.Net.Core/Net/Udp/IUdpSocket.cs index 8da948d1a..feb94b683 100644 --- a/src/Discord.Net.Core/Net/Udp/IUdpSocket.cs +++ b/src/Discord.Net.Core/Net/Udp/IUdpSocket.cs @@ -9,7 +9,7 @@ namespace Discord.Net.Udp event Func ReceivedDatagram; void SetCancelToken(CancellationToken cancelToken); - void SetDestination(string host, int port); + void SetDestination(string ip, int port); Task StartAsync(); Task StopAsync(); diff --git a/src/Discord.Net.WebSocket/API/Voice/ReadyEvent.cs b/src/Discord.Net.WebSocket/API/Voice/ReadyEvent.cs index e4446f814..2a134ced1 100644 --- a/src/Discord.Net.WebSocket/API/Voice/ReadyEvent.cs +++ b/src/Discord.Net.WebSocket/API/Voice/ReadyEvent.cs @@ -7,6 +7,8 @@ namespace Discord.API.Voice { [JsonProperty("ssrc")] public uint SSRC { get; set; } + [JsonProperty("ip")] + public string Ip { get; set; } [JsonProperty("port")] public ushort Port { get; set; } [JsonProperty("modes")] diff --git a/src/Discord.Net.WebSocket/Audio/AudioClient.cs b/src/Discord.Net.WebSocket/Audio/AudioClient.cs index 3e11fa463..2030ed477 100644 --- a/src/Discord.Net.WebSocket/Audio/AudioClient.cs +++ b/src/Discord.Net.WebSocket/Audio/AudioClient.cs @@ -248,7 +248,7 @@ namespace Discord.Audio _heartbeatTask = RunHeartbeatAsync(data.HeartbeatInterval, _connection.CancelToken); - ApiClient.SetUdpEndpoint(_url, data.Port); + ApiClient.SetUdpEndpoint(data.Ip, data.Port); await ApiClient.SendDiscoveryAsync(_ssrc).ConfigureAwait(false); } break; @@ -302,7 +302,7 @@ namespace Discord.Audio } private async Task ProcessPacketAsync(byte[] packet) { - if (!_connection.IsCompleted) + if (_connection.State == ConnectionState.Connecting) { if (packet.Length != 70) { @@ -314,7 +314,7 @@ namespace Discord.Audio try { ip = Encoding.UTF8.GetString(packet, 4, 70 - 6).TrimEnd('\0'); - port = packet[69] | (packet[68] << 8); + port = (packet[69] << 8) | packet[68]; } catch (Exception ex) { @@ -325,7 +325,7 @@ namespace Discord.Audio await _audioLogger.DebugAsync("Received Discovery").ConfigureAwait(false); await ApiClient.SendSelectProtocol(ip, port).ConfigureAwait(false); } - else + else if (_connection.State == ConnectionState.Connected) { uint ssrc; ulong userId; diff --git a/src/Discord.Net.WebSocket/ConnectionManager.cs b/src/Discord.Net.WebSocket/ConnectionManager.cs index 8e40beab4..decae4163 100644 --- a/src/Discord.Net.WebSocket/ConnectionManager.cs +++ b/src/Discord.Net.WebSocket/ConnectionManager.cs @@ -26,8 +26,6 @@ namespace Discord public ConnectionState State { get; private set; } public CancellationToken CancelToken { get; private set; } - public bool IsCompleted => _readyPromise.Task.IsCompleted; - internal ConnectionManager(SemaphoreSlim stateLock, Logger logger, int connectionTimeout, Func onConnecting, Func onDisconnecting, Action> clientDisconnectHandler) { diff --git a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj index b41cc84b4..4e252795b 100644 --- a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj +++ b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj @@ -16,7 +16,6 @@ - diff --git a/src/Discord.Net.WebSocket/DiscordVoiceApiClient.cs b/src/Discord.Net.WebSocket/DiscordVoiceApiClient.cs index fa619b58c..fe5283ef3 100644 --- a/src/Discord.Net.WebSocket/DiscordVoiceApiClient.cs +++ b/src/Discord.Net.WebSocket/DiscordVoiceApiClient.cs @@ -228,9 +228,9 @@ namespace Discord.Audio await _sentDiscoveryEvent.InvokeAsync().ConfigureAwait(false); } - public void SetUdpEndpoint(string host, int port) + public void SetUdpEndpoint(string ip, int port) { - _udp.SetDestination(host, port); + _udp.SetDestination(ip, port); } //Helpers diff --git a/src/Discord.Net.WebSocket/Net/DefaultUdpSocket.cs b/src/Discord.Net.WebSocket/Net/DefaultUdpSocket.cs index eb184e345..3366250cc 100644 --- a/src/Discord.Net.WebSocket/Net/DefaultUdpSocket.cs +++ b/src/Discord.Net.WebSocket/Net/DefaultUdpSocket.cs @@ -89,10 +89,9 @@ namespace Discord.Net.Udp } } - public void SetDestination(string host, int port) + public void SetDestination(string ip, int port) { - var entry = Dns.GetHostEntryAsync(host).GetAwaiter().GetResult(); - _destination = new IPEndPoint(entry.AddressList[0], port); + _destination = new IPEndPoint(IPAddress.Parse(ip), port); } public void SetCancelToken(CancellationToken cancelToken) {