diff options
author | George Hazan <ghazan@miranda.im> | 2020-12-23 20:21:40 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-12-23 20:21:40 +0300 |
commit | 16c0b34f73ad2c54defd9e2791bd8c15e27e35e0 (patch) | |
tree | 9bbb42f76b38d74e6ae64d446bfa1aaf1523b995 | |
parent | ed35a5d6e9dd02b3f88f34dc07dc7c9f29666fe7 (diff) |
Discord: finally fixes #2499 (Discord: Error establishing WebSocket connection to gateway.discord.gg)
-rw-r--r-- | protocols/Discord/src/gateway.cpp | 25 | ||||
-rw-r--r-- | src/mir_app/src/netlib_websocket.cpp | 5 |
2 files changed, 22 insertions, 8 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; diff --git a/src/mir_app/src/netlib_websocket.cpp b/src/mir_app/src/netlib_websocket.cpp index 23b30957dd..a8a36018b4 100644 --- a/src/mir_app/src/netlib_websocket.cpp +++ b/src/mir_app/src/netlib_websocket.cpp @@ -65,11 +65,8 @@ MIR_APP_DLL(NETLIBHTTPREQUEST*) WebSocket_Connect(HNETLIBUSER nlu, const char *s return nullptr; } - if (pReply->resultCode != 101) { + if (pReply->resultCode != 101) Netlib_Logf(nlu, "Error establishing WebSocket connection to %s, status %d", tmpHost.c_str(), pReply->resultCode); - Netlib_FreeHttpRequest(pReply); - return nullptr; - } return pReply; } |