summaryrefslogtreecommitdiff
path: root/protocols/Discord/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-10-29 12:25:45 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-10-29 12:25:45 +0300
commit3217ab9478e5f2a304e44cebd2e6ea7825a42f8c (patch)
treec5e6ec810fc20b9d94654358d36dbcad4e0a836b /protocols/Discord/src
parent60abc2fbd6fc10083e821340f9edc3593de5637e (diff)
Discord:
- crash fix on exit; - fix for calling KillTimer from the worker process; - fix for disconnecting whole account when server orders to reset the gateway connection
Diffstat (limited to 'protocols/Discord/src')
-rw-r--r--protocols/Discord/src/connection.cpp7
-rw-r--r--protocols/Discord/src/gateway.cpp16
-rw-r--r--protocols/Discord/src/proto.cpp2
-rw-r--r--protocols/Discord/src/proto.h2
4 files changed, 18 insertions, 9 deletions
diff --git a/protocols/Discord/src/connection.cpp b/protocols/Discord/src/connection.cpp
index d23ad64041..80ec0c172a 100644
--- a/protocols/Discord/src/connection.cpp
+++ b/protocols/Discord/src/connection.cpp
@@ -75,6 +75,11 @@ void CDiscordProto::OnLoggedIn()
ForkThread(&CDiscordProto::GatewayThread, nullptr);
}
+static void __stdcall sttKillTimer(void *param)
+{
+ KillTimer(g_hwndHeartbeat, (UINT_PTR)param);
+}
+
void CDiscordProto::OnLoggedOut()
{
debugLogA("CDiscordProto::OnLoggedOut");
@@ -82,7 +87,7 @@ void CDiscordProto::OnLoggedOut()
m_bTerminated = true;
m_iGatewaySeq = 0;
- KillTimer(g_hwndHeartbeat, (UINT_PTR)this);
+ CallFunctionAsync(sttKillTimer, this);
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, ID_STATUS_OFFLINE);
m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
diff --git a/protocols/Discord/src/gateway.cpp b/protocols/Discord/src/gateway.cpp
index ffd66f6d0a..4c801c32ce 100644
--- a/protocols/Discord/src/gateway.cpp
+++ b/protocols/Discord/src/gateway.cpp
@@ -129,11 +129,12 @@ void CDiscordProto::GatewaySend(const JSONNode &pRoot, int opCode)
void CDiscordProto::GatewayThread(void*)
{
- GatewayThreadWorker();
+ while (GatewayThreadWorker())
+ ;
ShutdownSession();
}
-void CDiscordProto::GatewayThreadWorker()
+bool CDiscordProto::GatewayThreadWorker()
{
// connect to the gateway server
if (!mir_strncmp(m_szGateway, "wss://", 6))
@@ -155,7 +156,7 @@ void CDiscordProto::GatewayThreadWorker()
m_hGatewayConnection = Netlib_OpenConnection(m_hGatewayNetlibUser, &conn);
if (m_hGatewayConnection == nullptr) {
debugLogA("Gateway connection failed to connect to %s:%d, exiting", m_szGateway.c_str(), conn.wPort);
- return;
+ return false;
}
{
CMStringA szBuf;
@@ -171,7 +172,7 @@ void CDiscordProto::GatewayThreadWorker()
szBuf.AppendFormat("\r\n");
if (Netlib_Send(m_hGatewayConnection, szBuf, szBuf.GetLength(), MSG_DUMPASTEXT) == SOCKET_ERROR) {
debugLogA("Error establishing gateway connection to %s:%d, send failed", m_szGateway.c_str(), conn.wPort);
- return;
+ return false;
}
}
{
@@ -179,13 +180,13 @@ void CDiscordProto::GatewayThreadWorker()
int bufSize = Netlib_Recv(m_hGatewayConnection, buf, _countof(buf), MSG_DUMPASTEXT);
if (bufSize <= 0) {
debugLogA("Error establishing gateway connection to %s:%d, read failed", m_szGateway.c_str(), conn.wPort);
- return;
+ return false;
}
int status = 0;
if (sscanf(buf, "HTTP/1.1 %d", &status) != 1 || status != 101) {
debugLogA("Error establishing gateway connection to %s:%d, status %d", m_szGateway.c_str(), conn.wPort, status);
- return;
+ return false;
}
}
@@ -257,7 +258,7 @@ void CDiscordProto::GatewayThreadWorker()
case 8: // close
debugLogA("server required to exit");
- bExit = true;
+ bExit = true; // simply reconnect, don't exit
break;
case 9: // ping
@@ -293,6 +294,7 @@ void CDiscordProto::GatewayThreadWorker()
Netlib_CloseHandle(m_hGatewayConnection);
m_hGatewayConnection = nullptr;
+ return bExit;
}
//////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp
index 55df6c34c5..6ef95ffbd3 100644
--- a/protocols/Discord/src/proto.cpp
+++ b/protocols/Discord/src/proto.cpp
@@ -88,6 +88,8 @@ CDiscordProto::~CDiscordProto()
Netlib_CloseHandle(m_hNetlibUser);
m_hNetlibUser = nullptr;
+ arUsers.destroy();
+
m_arHttpQueue.destroy();
::CloseHandle(m_evRequestsQueue);
}
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index debd6db7e7..5789cebbb3 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -183,7 +183,7 @@ class CDiscordProto : public PROTO<CDiscordProto>
HNETLIBCONN m_hGatewayConnection; // gateway connection
void __cdecl GatewayThread(void*);
- void GatewayThreadWorker(void);
+ bool GatewayThreadWorker(void);
void GatewaySend(const JSONNode&, int opCode = 1);
void GatewayProcess(const JSONNode&);