From 1236c85fba697e140164ec06f2388799e300b3ca Mon Sep 17 00:00:00 2001 From: Brandon Smith Date: Thu, 3 Sep 2015 21:11:35 -0300 Subject: [PATCH] Clean up state during disconnect better. Don't allow UDP disposed errors to trigger the DisconnectReason. --- src/Discord.Net/DiscordClient.cs | 2 +- src/Discord.Net/DiscordVoiceSocket.cs | 4 +++- src/Discord.Net/DiscordWebSocket.cs | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net/DiscordClient.cs b/src/Discord.Net/DiscordClient.cs index dbc5a8618..d14767f9a 100644 --- a/src/Discord.Net/DiscordClient.cs +++ b/src/Discord.Net/DiscordClient.cs @@ -429,7 +429,7 @@ namespace Discord { _currentVoiceToken = data.Token; await _voiceWebSocket.ConnectAsync("wss://" + data.Endpoint.Split(':')[0]); - await _voiceWebSocket.Login(_currentVoiceServerId, _myId, _myId, data.Token); + await _voiceWebSocket.Login(_currentVoiceServerId, _myId, _sessionId, data.Token); } #endif } diff --git a/src/Discord.Net/DiscordVoiceSocket.cs b/src/Discord.Net/DiscordVoiceSocket.cs index 53ffb1b1d..15c275067 100644 --- a/src/Discord.Net/DiscordVoiceSocket.cs +++ b/src/Discord.Net/DiscordVoiceSocket.cs @@ -130,6 +130,7 @@ namespace Discord } } catch (OperationCanceledException) { } + catch (ObjectDisposedException) { } catch (Exception ex) { DisconnectInternal(ex); } finally { DisconnectInternal(); } } @@ -210,6 +211,7 @@ namespace Discord } } catch (OperationCanceledException) { } + catch (ObjectDisposedException) { } catch (Exception ex) { DisconnectInternal(ex); } finally { DisconnectInternal(); } } @@ -238,7 +240,7 @@ namespace Discord var payload = (msg.Payload as JToken).ToObject(); _heartbeatInterval = payload.HeartbeatInterval; _ssrc = payload.SSRC; - _endpoint = new IPEndPoint((await Dns.GetHostAddressesAsync(_host)).FirstOrDefault(), payload.Port); + _endpoint = new IPEndPoint((await Dns.GetHostAddressesAsync(_host.Replace("wss://", ""))).FirstOrDefault(), payload.Port); //_mode = payload.Modes.LastOrDefault(); _mode = "plain"; _udp.Connect(_endpoint); diff --git a/src/Discord.Net/DiscordWebSocket.cs b/src/Discord.Net/DiscordWebSocket.cs index a7be2234d..e2c67d17b 100644 --- a/src/Discord.Net/DiscordWebSocket.cs +++ b/src/Discord.Net/DiscordWebSocket.cs @@ -78,13 +78,13 @@ namespace Discord byte[] ignored; while (_sendQueue.TryDequeue(out ignored)) { } + _disconnectReason = null; + _task = null; if (_isConnected) { _isConnected = false; RaiseDisconnected(wasUnexpected); } - - _task = null; }); } public Task ReconnectAsync()