diff options
-rw-r--r-- | protocols/Discord/src/connection.cpp | 4 | ||||
-rw-r--r-- | protocols/Discord/src/gateway.cpp | 14 | ||||
-rw-r--r-- | protocols/Discord/src/proto.cpp | 5 | ||||
-rw-r--r-- | protocols/Discord/src/proto.h | 7 | ||||
-rw-r--r-- | src/mir_app/src/netlib_websocket.cpp | 7 |
5 files changed, 20 insertions, 17 deletions
diff --git a/protocols/Discord/src/connection.cpp b/protocols/Discord/src/connection.cpp index ff7e765ecb..4ac9cead47 100644 --- a/protocols/Discord/src/connection.cpp +++ b/protocols/Discord/src/connection.cpp @@ -93,8 +93,8 @@ void CDiscordProto::ShutdownSession() pMfaDialog->Close();
if (m_hWorkerThread)
SetEvent(m_evRequestsQueue);
- if (m_ws)
- m_ws->terminate();
+ if (m_bConnected)
+ m_ws.terminate();
if (m_hAPIConnection)
Netlib_Shutdown(m_hAPIConnection);
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 <http://www.gnu.org/licenses/>. 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<CDiscordProto> 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;
}
diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index f1df2c2a12..5a33a9d6f5 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -44,6 +44,7 @@ static int compareCalls(const CDiscordVoiceCall *p1, const CDiscordVoiceCall *p2 CDiscordProto::CDiscordProto(const char *proto_name, const wchar_t *username) :
PROTO<CDiscordProto>(proto_name, username),
+ m_ws(this),
m_impl(*this),
m_arHttpQueue(10, compareRequests),
m_evRequestsQueue(CreateEvent(nullptr, FALSE, FALSE, nullptr)),
@@ -174,8 +175,8 @@ void CDiscordProto::OnShutdown() for (auto &it : arGuilds)
it->SaveToFile();
- if (m_ws)
- m_ws->terminate();
+ if (m_bConnected)
+ m_ws.terminate();
if (g_plugin.bVoiceService)
CallService(MS_VOICESERVICE_UNREGISTER, (WPARAM)m_szModuleName, 0);
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index 8342ba5724..a147124a43 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -364,9 +364,10 @@ class CDiscordProto : public PROTO<CDiscordProto> HANDLE m_hWorkerThread; // worker thread handle
HNETLIBCONN m_hAPIConnection; // working connection
- bool
+ bool
m_bOnline, // protocol is online
- m_bTerminated; // Miranda's going down
+ m_bTerminated, // Miranda's going down
+ m_bConnected; // web socket is connected
//////////////////////////////////////////////////////////////////////////////////////
// gateway
@@ -380,7 +381,7 @@ class CDiscordProto : public PROTO<CDiscordProto> m_szWSCookie; // cookie used for establishing websocket connection
HNETLIBUSER m_hGatewayNetlibUser; // the separate netlib user handle for gateways
- JsonWebSocket<CDiscordProto> *m_ws;
+ JsonWebSocket<CDiscordProto> m_ws;
void __cdecl GatewayThread(void*);
bool GatewayThreadWorker(void);
diff --git a/src/mir_app/src/netlib_websocket.cpp b/src/mir_app/src/netlib_websocket.cpp index d869664a69..185e320636 100644 --- a/src/mir_app/src/netlib_websocket.cpp +++ b/src/mir_app/src/netlib_websocket.cpp @@ -93,6 +93,7 @@ MWebSocket::~MWebSocket() MHttpResponse* MWebSocket::connect(HANDLE nlu, const char *szHost, const MHttpHeaders *pHeaders)
{
m_nlu = (HNETLIBUSER)nlu;
+ m_bTerminated = false;
CMStringA tmpHost(szHost);
@@ -205,8 +206,10 @@ void MWebSocket::terminate() {
m_bTerminated = true;
- if (m_hConn)
+ if (m_hConn) {
Netlib_Shutdown(m_hConn);
+ m_hConn = nullptr;
+ }
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -275,7 +278,7 @@ void MWebSocket::run() case 9: // ping
Netlib_Logf(m_nlu, "ping received: %d bytes", int(hdr.payloadSize));
if (hdr.payloadSize)
- Netlib_Send(m_hConn, (char *)buf + hdr.headerSize, hdr.payloadSize, MSG_NODUMP);
+ Netlib_Send(m_hConn, (char *)buf + hdr.headerSize, (int)hdr.payloadSize, MSG_NODUMP);
break;
}
|