From 0a641111470bf1910bed3fe1cd57f31c6c1ecfce Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 27 Oct 2024 17:42:04 +0300 Subject: fixes #4761 (Ability to use third party discord reimplementations) --- protocols/Discord/src/http.cpp | 2 +- protocols/Discord/src/proto.cpp | 3 +++ protocols/Discord/src/proto.h | 1 + protocols/Discord/src/server.cpp | 27 ++++++++++++--------------- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/protocols/Discord/src/http.cpp b/protocols/Discord/src/http.cpp index b349eac36b..c5d5e1e0c0 100644 --- a/protocols/Discord/src/http.cpp +++ b/protocols/Discord/src/http.cpp @@ -41,7 +41,7 @@ static LONG g_reqNum = 0; AsyncHttpRequest::AsyncHttpRequest(CDiscordProto *ppro, int iRequestType, LPCSTR _url, MTHttpRequestHandler pFunc, JSONNode *pRoot) { if (*_url == '/') { // relative url leads to a site - m_szUrl = "https://discord.com/api/v9"; + m_szUrl = ppro->m_szApiUrl; m_szUrl += _url; m_bMainSite = true; } diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index 96ba582377..f1df2c2a12 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -62,6 +62,9 @@ CDiscordProto::CDiscordProto(const char *proto_name, const wchar_t *username) : m_bSyncDeleteMsgs(this, "DeleteServerMsgs", true), m_bSyncDeleteUsers(this, "DeleteServerUsers", true) { + // Hidden setting! + m_szApiUrl = getMStringA("ApiUrl", "https://discord.com/api/v9"); + // Services CreateProtoService(PS_GETAVATARINFO, &CDiscordProto::GetAvatarInfo); CreateProtoService(PS_GETAVATARCAPS, &CDiscordProto::GetAvatarCaps); diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index fac698111d..8342ba5724 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -372,6 +372,7 @@ class CDiscordProto : public PROTO // gateway CMStringA + m_szApiUrl, // Discord API url m_szGateway, // gateway url m_szGatewaySessionId, // current session id m_szCookie, // cookie used for all http queries diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp index 172faebe47..beef589e30 100644 --- a/protocols/Discord/src/server.cpp +++ b/protocols/Discord/src/server.cpp @@ -143,9 +143,17 @@ void CDiscordProto::OnReceiveHistory(MHttpResponse *pReply, AsyncHttpRequest *pR ///////////////////////////////////////////////////////////////////////////////////////// // retrieves user info -void CDiscordProto::RetrieveMyInfo() +void CDiscordProto::OnReceiveGateway(MHttpResponse *pReply, AsyncHttpRequest *) { - Push(new AsyncHttpRequest(this, REQUEST_GET, "/users/@me", &CDiscordProto::OnReceiveMyInfo)); + JsonReply root(pReply); + if (!root) { + ShutdownSession(); + return; + } + + auto &data = root.data(); + m_szGateway = data["url"].as_mstring(); + ForkThread(&CDiscordProto::GatewayThread, nullptr); } void CDiscordProto::OnReceiveMyInfo(MHttpResponse *pReply, AsyncHttpRequest*) @@ -178,20 +186,9 @@ void CDiscordProto::OnReceiveMyInfo(MHttpResponse *pReply, AsyncHttpRequest*) CheckAvatarChange(0, data["avatar"].as_mstring()); } -///////////////////////////////////////////////////////////////////////////////////////// -// finds a gateway address - -void CDiscordProto::OnReceiveGateway(MHttpResponse *pReply, AsyncHttpRequest*) +void CDiscordProto::RetrieveMyInfo() { - JsonReply root(pReply); - if (!root) { - ShutdownSession(); - return; - } - - auto &data = root.data(); - m_szGateway = data["url"].as_mstring(); - ForkThread(&CDiscordProto::GatewayThread, nullptr); + Push(new AsyncHttpRequest(this, REQUEST_GET, "/users/@me", &CDiscordProto::OnReceiveMyInfo)); } ///////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3