summaryrefslogtreecommitdiff
path: root/protocols/Discord
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-09-20 11:42:29 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-09-20 11:42:29 +0300
commitc3e3c5f2e3412ce9f67d52023ad37a38118255d0 (patch)
treeae4b09068540a68172c729bec89df21635abc9e3 /protocols/Discord
parent9149988db38b64a55b624de030d224b5bb97ab80 (diff)
Discord: gateway opcode 9 processing added
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*);