diff options
Diffstat (limited to 'protocols/Discord/src')
| -rw-r--r-- | protocols/Discord/src/gateway.cpp | 16 | ||||
| -rw-r--r-- | protocols/Discord/src/http.cpp | 3 | ||||
| -rw-r--r-- | protocols/Discord/src/proto.cpp | 8 | ||||
| -rw-r--r-- | protocols/Discord/src/proto.h | 3 | 
4 files changed, 24 insertions, 6 deletions
diff --git a/protocols/Discord/src/gateway.cpp b/protocols/Discord/src/gateway.cpp index 414979ad20..fae8eef7cc 100644 --- a/protocols/Discord/src/gateway.cpp +++ b/protocols/Discord/src/gateway.cpp @@ -47,13 +47,25 @@ bool CDiscordProto::GatewayThreadWorker()  		{ 0, 0 }  	}; -	m_hGatewayConnection = WebSocket_Connect(m_hGatewayNetlibUser, m_szGateway + "/?encoding=json&v=6", hdrs); -	if (m_hGatewayConnection == nullptr) { +	auto *pReply = WebSocket_Connect(m_hGatewayNetlibUser, m_szGateway + "/?encoding=json&v=6", hdrs); +	if (pReply == nullptr) {  		debugLogA("Gateway connection failed, exiting");  		return false;  	}  	debugLogA("Gateway connection succeeded"); +	m_hGatewayConnection = pReply->nlc; + +	for (int i=0; i < pReply->headersCount; i++) +		if (!mir_strcmp(pReply->headers[i].szName, "Set-Cookie")) { +			m_szCookie = pReply->headers[i].szValue; +			 +			int idx = m_szCookie.Find(';'); +			if (idx != -1) +				m_szCookie.Truncate(idx); +			break; +		} +	Netlib_FreeHttpRequest(pReply);  	bool bExit = false;  	int offset = 0; diff --git a/protocols/Discord/src/http.cpp b/protocols/Discord/src/http.cpp index 54b90ec668..215df90e92 100644 --- a/protocols/Discord/src/http.cpp +++ b/protocols/Discord/src/http.cpp @@ -55,6 +55,9 @@ AsyncHttpRequest::AsyncHttpRequest(CDiscordProto *ppro, int iRequestType, LPCSTR  		pData = mir_utf8encodeW(text);  		dataLength = (int)mir_strlen(pData);  	} + +	if (!ppro->m_szCookie.IsEmpty()) +		AddHeader("Cookie", ppro->m_szCookie);  	AddHeader("Content-Type", "application/json");  	m_pFunc = pFunc; diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index bc15c1b22e..1051b57005 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -451,9 +451,11 @@ int CDiscordProto::SetAwayMsg(int iStatus, const wchar_t *msg)  	replaceStrW(pwszMessage, msg); -	JSONNode status; status.set_name("custom_status"); status << WCHAR_PARAM("text", (msg) ? msg : L""); -	JSONNode root; root << status; -	Push(new AsyncHttpRequest(this, REQUEST_PATCH, "/users/@me/settings", nullptr, &root)); +	if (m_bOnline) { +		JSONNode status; status.set_name("custom_status"); status << WCHAR_PARAM("text", (msg) ? msg : L""); +		JSONNode root; root << status; +		Push(new AsyncHttpRequest(this, REQUEST_PATCH, "/users/@me/settings", nullptr, &root)); +	}  	return 0;  } diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index f68383b1d7..a25da70c5d 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -182,7 +182,8 @@ class CDiscordProto : public PROTO<CDiscordProto>  	CMStringA  		m_szGateway,           // gateway url -		m_szGatewaySessionId;  // current session id +		m_szGatewaySessionId,  // current session id +		m_szCookie;				  // a cookie to be passed into all http queries  	HNETLIBUSER m_hGatewayNetlibUser; // the separate netlib user handle for gateways  	HNETLIBCONN m_hGatewayConnection;      // gateway connection  | 
