From 5b9f31a4455eaaec3615939ce847b2000ce3377c Mon Sep 17 00:00:00 2001 From: RogueException Date: Wed, 16 Sep 2015 11:18:16 -0300 Subject: [PATCH] Fixed a few voice crashes --- src/Discord.Net/DiscordClient.Voice.cs | 11 +++++++---- src/Discord.Net/Net/WebSockets/VoiceWebSocket.cs | 15 +++------------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/Discord.Net/DiscordClient.Voice.cs b/src/Discord.Net/DiscordClient.Voice.cs index 62e59cb74..a0f1d84ff 100644 --- a/src/Discord.Net/DiscordClient.Voice.cs +++ b/src/Discord.Net/DiscordClient.Voice.cs @@ -22,10 +22,13 @@ namespace Discord public async Task LeaveVoiceServer() { CheckReady(checkVoice: true); - - await _voiceSocket.Disconnect().ConfigureAwait(false); - await TaskHelper.CompletedTask.ConfigureAwait(false); - _dataSocket.SendLeaveVoice(); + + if (_voiceSocket.CurrentVoiceServerId != null) + { + await _voiceSocket.Disconnect().ConfigureAwait(false); + await TaskHelper.CompletedTask.ConfigureAwait(false); + _dataSocket.SendLeaveVoice(); + } } /// Sends a PCM frame to the voice server. diff --git a/src/Discord.Net/Net/WebSockets/VoiceWebSocket.cs b/src/Discord.Net/Net/WebSockets/VoiceWebSocket.cs index 7244a2d26..9c484b433 100644 --- a/src/Discord.Net/Net/WebSockets/VoiceWebSocket.cs +++ b/src/Discord.Net/Net/WebSockets/VoiceWebSocket.cs @@ -52,23 +52,14 @@ namespace Discord.Net.WebSockets _targetAudioBufferLength = client.Config.VoiceBufferLength / 20; //20 ms frames } - public async Task Login(string host, string serverId, string userId, string sessionId, string token) + public Task Login(string host, string serverId, string userId, string sessionId, string token) { _serverId = serverId; _userId = userId; _sessionId = sessionId; _token = token; - await base.Connect(host); - - Commands.Login msg = new Commands.Login(); - msg.Payload.Token = token; - //msg.Payload.Properties["$os"] = ""; - //msg.Payload.Properties["$browser"] = ""; - msg.Payload.Properties["$device"] = "Discord.Net"; - //msg.Payload.Properties["$referrer"] = ""; - //msg.Payload.Properties["$referring_domain"] = ""; - QueueMessage(msg); + return base.Connect(host); } protected override Task[] Run() @@ -405,7 +396,7 @@ namespace Discord.Net.WebSockets int frameSize = _encoder.FrameSize; int frames = bytes / frameSize; int expectedBytes = frames * frameSize; - int lastFrameSize = expectedBytes - bytes; + int lastFrameSize = bytes - expectedBytes; //If this only consists of a partial frame and the buffer is too small to pad the end, make a new one if (data.Length < frameSize)