From 2331374d1ffe2432496e484443a58e859a7f560f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 16 Feb 2025 16:56:14 +0300 Subject: Discord: the safer way of handling web sockets --- protocols/Discord/src/gateway.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'protocols/Discord/src/gateway.cpp') diff --git a/protocols/Discord/src/gateway.cpp b/protocols/Discord/src/gateway.cpp index d6b7846eeb..eb29043394 100644 --- a/protocols/Discord/src/gateway.cpp +++ b/protocols/Discord/src/gateway.cpp @@ -22,12 +22,12 @@ along with this program. If not, see . bool CDiscordProto::GatewaySend(const JSONNode &pRoot) { - if (m_ws == nullptr) + if (!m_bConnected) return false; json_string szText = pRoot.write(); debugLogA("Gateway send: %s", szText.c_str()); - m_ws->sendText(szText.c_str()); + m_ws.sendText(szText.c_str()); return true; } @@ -51,8 +51,7 @@ bool CDiscordProto::GatewayThreadWorker() hdrs.AddHeader("Cookie", m_szWSCookie); } - JsonWebSocket ws(this); - NLHR_PTR pReply(ws.connect(m_hGatewayNetlibUser, m_szGateway + "/?encoding=json&v=8", &hdrs)); + NLHR_PTR pReply(m_ws.connect(m_hGatewayNetlibUser, m_szGateway + "/?encoding=json&v=8", &hdrs)); if (pReply == nullptr) { debugLogA("Gateway connection failed, exiting"); return false; @@ -74,10 +73,9 @@ bool CDiscordProto::GatewayThreadWorker() // succeeded! debugLogA("Gateway connection succeeded"); - m_ws = &ws; - ws.run(); - - m_ws = nullptr; + m_bConnected = true; + m_ws.run(); + m_bConnected = false; return true; } -- cgit v1.2.3