summaryrefslogtreecommitdiff
path: root/protocols/Discord/src/gateway.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-12-23 20:21:40 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-12-23 20:21:40 +0300
commit16c0b34f73ad2c54defd9e2791bd8c15e27e35e0 (patch)
tree9bbb42f76b38d74e6ae64d446bfa1aaf1523b995 /protocols/Discord/src/gateway.cpp
parented35a5d6e9dd02b3f88f34dc07dc7c9f29666fe7 (diff)
Discord: finally fixes #2499 (Discord: Error establishing WebSocket connection to gateway.discord.gg)
Diffstat (limited to 'protocols/Discord/src/gateway.cpp')
-rw-r--r--protocols/Discord/src/gateway.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/protocols/Discord/src/gateway.cpp b/protocols/Discord/src/gateway.cpp
index 01fefac5db..c65492569d 100644
--- a/protocols/Discord/src/gateway.cpp
+++ b/protocols/Discord/src/gateway.cpp
@@ -45,18 +45,35 @@ bool CDiscordProto::GatewayThreadWorker()
NETLIBHTTPHEADER hdrs[] =
{
{ "Origin", "https://discord.com" },
- { 0, 0 }
+ { 0, 0 },
+ { 0, 0 },
};
- auto *pReply = WebSocket_Connect(m_hGatewayNetlibUser, m_szGateway + "/?encoding=json&v=8", hdrs);
+ CMStringA szCookie(getMStringA("WSCookie"));
+ if (!szCookie.IsEmpty()) {
+ hdrs[1].szName = "Cookie";
+ hdrs[1].szValue = szCookie.GetBuffer();
+ }
+
+ NLHR_PTR pReply(WebSocket_Connect(m_hGatewayNetlibUser, m_szGateway + "/?encoding=json&v=8", hdrs));
if (pReply == nullptr) {
debugLogA("Gateway connection failed, exiting");
return false;
}
-
+
+ if (auto *pszNewCookie = Netlib_GetHeader(pReply, "Set-Cookie")) {
+ char *p = strchr(pszNewCookie, ';');
+ if (p) *p = 0;
+
+ setString("WSCookie", pszNewCookie);
+ }
+
+ if (pReply->resultCode != 101)
+ return false;
+
+ // succeeded!
debugLogA("Gateway connection succeeded");
m_hGatewayConnection = pReply->nlc;
- Netlib_FreeHttpRequest(pReply);
bool bExit = false;
int offset = 0;