summaryrefslogtreecommitdiff
path: root/protocols/Discord
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Discord')
-rw-r--r--protocols/Discord/src/gateway.cpp21
-rw-r--r--protocols/Discord/src/proto.h1
2 files changed, 22 insertions, 0 deletions
diff --git a/protocols/Discord/src/gateway.cpp b/protocols/Discord/src/gateway.cpp
index 561dbf035e..df07cfbe2c 100644
--- a/protocols/Discord/src/gateway.cpp
+++ b/protocols/Discord/src/gateway.cpp
@@ -317,6 +317,15 @@ void CDiscordProto::GatewayProcess(const JSONNode &pRoot)
}
break;
+ case 9: // session invalidated
+ if (pRoot["d"].as_bool()) // session can be resumed
+ GatewaySendResume();
+ else {
+ Sleep(5000); // 5 seconds - recommended timeout
+ GatewaySendIdentify();
+ }
+ break;
+
case 10: // hello
m_iHartbeatInterval = pRoot["d"]["heartbeat_interval"].as_int();
@@ -374,3 +383,15 @@ void CDiscordProto::GatewaySendGuildInfo(SnowFlake id)
root << INT_PARAM("op", 12) << payload;
GatewaySend(root);
}
+
+void CDiscordProto::GatewaySendResume()
+{
+ char szRandom[40];
+ uint8_t random[16];
+ Utils_GetRandom(random, _countof(random));
+ bin2hex(random, _countof(random), szRandom);
+
+ JSONNode root;
+ root << CHAR_PARAM("token", szRandom) << CHAR_PARAM("session_id", m_szGatewaySessionId) << INT_PARAM("seq", m_iGatewaySeq);
+ GatewaySend(root);
+}
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index f3f2a2a9bb..3b11a71f2e 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -219,6 +219,7 @@ class CDiscordProto : public PROTO<CDiscordProto>
void GatewaySendHeartbeat(void);
void GatewaySendIdentify(void);
void GatewaySendGuildInfo(SnowFlake id);
+ void GatewaySendResume(void);
GatewayHandlerFunc GetHandler(const wchar_t*);