summaryrefslogtreecommitdiff
path: root/protocols/Discord/src/connection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Discord/src/connection.cpp')
-rw-r--r--protocols/Discord/src/connection.cpp37
1 files changed, 22 insertions, 15 deletions
diff --git a/protocols/Discord/src/connection.cpp b/protocols/Discord/src/connection.cpp
index bc48d402e4..969e85fb05 100644
--- a/protocols/Discord/src/connection.cpp
+++ b/protocols/Discord/src/connection.cpp
@@ -33,8 +33,10 @@ void CDiscordProto::ExecuteRequest(AsyncHttpRequest *pReq)
}
}
- pReq->flags |= NLHRF_PERSISTENT;
- pReq->nlc = m_hAPIConnection;
+ if (pReq->m_bMainSite) {
+ pReq->flags |= NLHRF_PERSISTENT;
+ pReq->nlc = m_hAPIConnection;
+ }
debugLogA("Executing request #%d:\n%s", pReq->m_iReqNum, pReq->szUrl);
NETLIBHTTPREQUEST *reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)pReq);
@@ -49,11 +51,11 @@ void CDiscordProto::ExecuteRequest(AsyncHttpRequest *pReq)
else {
debugLogA("Request %d failed", pReq->m_iReqNum);
- if (IsStatusConnecting(m_iStatus))
- ConnectionFailed(LOGINERR_NONETWORK);
- else
- ShutdownSession();
- m_hAPIConnection = NULL;
+ if (pReq->m_bMainSite) {
+ if (IsStatusConnecting(m_iStatus))
+ ConnectionFailed(LOGINERR_NONETWORK);
+ m_hAPIConnection = NULL;
+ }
}
delete pReq;
}
@@ -64,10 +66,6 @@ void CDiscordProto::OnLoggedIn()
m_bOnline = true;
SetServerStatus(m_iDesiredStatus);
- Push(new AsyncHttpRequest(this, REQUEST_GET, "/users/@me/guilds", &CDiscordProto::OnReceiveGuilds));
- Push(new AsyncHttpRequest(this, REQUEST_GET, "/users/@me/channels", &CDiscordProto::OnReceiveChannels));
- Push(new AsyncHttpRequest(this, REQUEST_GET, "/users/@me/relationships", &CDiscordProto::OnReceiveFriends));
-
if (m_szGateway.IsEmpty())
Push(new AsyncHttpRequest(this, REQUEST_GET, "/gateway", &CDiscordProto::OnReceiveGateway));
else
@@ -78,10 +76,10 @@ void CDiscordProto::OnLoggedOut()
{
debugLogA("CDiscordProto::OnLoggedOut");
m_bOnline = false;
- m_hWorkerThread = NULL;
+ m_bTerminated = true;
+ m_iGatewaySeq = 0;
- if (m_hAPIConnection)
- Netlib_CloseHandle(m_hAPIConnection);
+ KillTimer(g_hwndHeartbeat, (UINT_PTR)this);
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, ID_STATUS_OFFLINE);
m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
@@ -89,10 +87,19 @@ void CDiscordProto::OnLoggedOut()
void CDiscordProto::ShutdownSession()
{
+ if (m_bTerminated)
+ return;
+
debugLogA("CDiscordProto::ShutdownSession");
- m_bTerminated = true;
+
+ // shutdown all resources
if (m_hWorkerThread)
SetEvent(m_evRequestsQueue);
+ if (m_hGatewayConnection)
+ Netlib_Shutdown(m_hGatewayConnection);
+ if (m_hAPIConnection)
+ Netlib_Shutdown(m_hAPIConnection);
+
OnLoggedOut();
}