From c3e3c5f2e3412ce9f67d52023ad37a38118255d0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 20 Sep 2017 11:42:29 +0300 Subject: Discord: gateway opcode 9 processing added --- protocols/Discord/src/gateway.cpp | 21 +++++++++++++++++++++ protocols/Discord/src/proto.h | 1 + 2 files changed, 22 insertions(+) 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 void GatewaySendHeartbeat(void); void GatewaySendIdentify(void); void GatewaySendGuildInfo(SnowFlake id); + void GatewaySendResume(void); GatewayHandlerFunc GetHandler(const wchar_t*); -- cgit v1.2.3