From 6ffa0377ef3001e0c954373e6e7d551aef5fc29c Mon Sep 17 00:00:00 2001 From: Sleepy Flower Girl Date: Wed, 29 Aug 2018 16:13:44 -0400 Subject: [PATCH] Stop heart beating while reconnecting --- examples/hello/hello.vcxproj | 4 ++-- include/sleepy_discord/client.h | 1 + sleepy_discord/client.cpp | 14 ++++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/examples/hello/hello.vcxproj b/examples/hello/hello.vcxproj index b2720cd46..b7956978f 100644 --- a/examples/hello/hello.vcxproj +++ b/examples/hello/hello.vcxproj @@ -89,7 +89,7 @@ true true - sleepy_discord.lib;libcurl_a.lib;libsslMT.lib;libcryptoMT.lib;crypt32.lib;%(AdditionalDependencies) + sleepy_discord.lib;libcurl_a.lib;libcryptoMT.lib;libsslMT.lib;crypt32.lib;Wldap32.lib;Advapi32.lib;Normaliz.lib;User32.lib @@ -100,7 +100,7 @@ _SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - sleepy_discord.lib;libcurl_a.lib;libsslMT.lib;libcryptoMT.lib;crypt32.lib;Wldap32.lib;Normaliz.lib;%(AdditionalDependencies) + sleepy_discord.lib;libcurl_a.lib;libcryptoMT.lib;libsslMT.lib;crypt32.lib;Wldap32.lib;Advapi32.lib;Normaliz.lib;User32.lib diff --git a/include/sleepy_discord/client.h b/include/sleepy_discord/client.h index eba19c8d2..76eb1b0c8 100644 --- a/include/sleepy_discord/client.h +++ b/include/sleepy_discord/client.h @@ -322,6 +322,7 @@ namespace SleepyDiscord { void processCloseCode(const int16_t code); void heartbeat(); void sendHeartbeat(); + void resetHeartbeatValues(); inline std::string getToken() { return *token.get(); } void start(const std::string _token, const char maxNumOfThreads = 2, int _shardID = 0, int _shardCount = 0); virtual bool connect(const std::string & uri) { return false; } diff --git a/sleepy_discord/client.cpp b/sleepy_discord/client.cpp index d021ed56d..6a5c403fd 100644 --- a/sleepy_discord/client.cpp +++ b/sleepy_discord/client.cpp @@ -427,7 +427,7 @@ namespace SleepyDiscord { case HELLO: heartbeatInterval = std::stoi(json::getValue(d->c_str(), "heartbeat_interval")); heartbeat(); - if (!ready) sendIdentity(); + if (sessionID.empty()) sendIdentity(); else sendResume(); break; case RECONNECT: @@ -438,7 +438,7 @@ namespace SleepyDiscord { sleep(2500); sendResume(); } else { - sessionID = ""; + sessionID = {}; sendIdentity(); } break; @@ -460,15 +460,20 @@ namespace SleepyDiscord { case DECODE_ERROR: case NOT_AUTHENTICATED: case ALREADY_AUTHENTICATED: - case INVALID_SEQ: case RATE_LIMITED: case SESSION_TIMEOUT: default: break; + case SESSION_NO_LONGER_VALID: + case INVALID_SEQ: case 1000: - if (!isQuiting()) + if (!isQuiting()) { + //restart with new session + sessionID = {}; + lastSReceived = 0; break; + } //else fall through //Might be Unrecoveralbe @@ -479,6 +484,7 @@ namespace SleepyDiscord { return quit(false, true); break; } + resetHeartbeatValues(); reconnect(1001); }