summaryrefslogtreecommitdiff
path: root/protocols/Discord
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Discord')
-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;