From 3a45e9ec87da6dccd021b44170a1df2aeabebf3d Mon Sep 17 00:00:00 2001 From: RogueException Date: Mon, 20 Mar 2017 23:49:17 -0300 Subject: [PATCH] Support InvalidSession(true) --- src/Discord.Net.WebSocket/ConnectionManager.cs | 6 ++++++ src/Discord.Net.WebSocket/DiscordSocketClient.cs | 6 +++++- test/Discord.Net.Tests/Net/CachedRestClient.cs | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Discord.Net.WebSocket/ConnectionManager.cs b/src/Discord.Net.WebSocket/ConnectionManager.cs index 72926e2e3..8e40beab4 100644 --- a/src/Discord.Net.WebSocket/ConnectionManager.cs +++ b/src/Discord.Net.WebSocket/ConnectionManager.cs @@ -193,6 +193,12 @@ namespace Discord _reconnectCancelToken?.Cancel(); Error(ex); } + public void Reconnect() + { + _readyPromise.TrySetCanceled(); + _connectionPromise.TrySetCanceled(); + _connectionCancelToken?.Cancel(); + } private async Task AcquireConnectionLock() { while (true) diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index 4f2f70321..9fb172612 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -433,7 +433,11 @@ namespace Discord.WebSocket _sessionId = null; _lastSeq = 0; - await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards).ConfigureAwait(false); + bool retry = (bool)payload; + if (retry) + _connection.Reconnect(); //TODO: Untested + else + await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards).ConfigureAwait(false); } break; case GatewayOpCode.Reconnect: diff --git a/test/Discord.Net.Tests/Net/CachedRestClient.cs b/test/Discord.Net.Tests/Net/CachedRestClient.cs index 324510688..f4b3bb279 100644 --- a/test/Discord.Net.Tests/Net/CachedRestClient.cs +++ b/test/Discord.Net.Tests/Net/CachedRestClient.cs @@ -5,11 +5,11 @@ using System; using System.Collections.Generic; using System.IO; using System.Net; +using System.Reactive.Concurrency; using System.Reactive.Linq; using System.Threading; using System.Threading.Tasks; using Splat; -using System.Reactive.Concurrency; namespace Discord.Net {