Skip to content

Commit

Permalink
Stop heart beating while reconnecting
Browse files Browse the repository at this point in the history
  • Loading branch information
yourWaifu committed Aug 29, 2018
1 parent 88c7604 commit 6ffa037
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions examples/hello/hello.vcxproj
Expand Up @@ -89,7 +89,7 @@
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>sleepy_discord.lib;libcurl_a.lib;libsslMT.lib;libcryptoMT.lib;crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>sleepy_discord.lib;libcurl_a.lib;libcryptoMT.lib;libsslMT.lib;crypt32.lib;Wldap32.lib;Advapi32.lib;Normaliz.lib;User32.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
Expand All @@ -100,7 +100,7 @@
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>sleepy_discord.lib;libcurl_a.lib;libsslMT.lib;libcryptoMT.lib;crypt32.lib;Wldap32.lib;Normaliz.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>sleepy_discord.lib;libcurl_a.lib;libcryptoMT.lib;libsslMT.lib;crypt32.lib;Wldap32.lib;Advapi32.lib;Normaliz.lib;User32.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand Down
1 change: 1 addition & 0 deletions include/sleepy_discord/client.h
Expand Up @@ -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; }
Expand Down
14 changes: 10 additions & 4 deletions sleepy_discord/client.cpp
Expand Up @@ -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:
Expand All @@ -438,7 +438,7 @@ namespace SleepyDiscord {
sleep(2500);
sendResume();
} else {
sessionID = "";
sessionID = {};
sendIdentity();
}
break;
Expand All @@ -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
Expand All @@ -479,6 +484,7 @@ namespace SleepyDiscord {
return quit(false, true);
break;
}
resetHeartbeatValues();
reconnect(1001);
}

Expand Down

0 comments on commit 6ffa037

Please sign in to comment.