summaryrefslogtreecommitdiff
path: root/protocols/Discord/src/proto.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-01-17 20:57:02 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-01-17 20:57:02 +0300
commitad61413a521ea9cebd849b659653a21c2c33ff8a (patch)
tree9029a623fbbe1491f86a68cbaa92b6b45c786521 /protocols/Discord/src/proto.cpp
parentb327ed7872ca83c3a4249039ba1a3d8dd3ece630 (diff)
Discord: auth support
Diffstat (limited to 'protocols/Discord/src/proto.cpp')
-rw-r--r--protocols/Discord/src/proto.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp
index 31a12fbdac..814ca19c0d 100644
--- a/protocols/Discord/src/proto.cpp
+++ b/protocols/Discord/src/proto.cpp
@@ -228,6 +228,9 @@ HANDLE CDiscordProto::SearchBasic(const wchar_t *wszId)
return (HANDLE)1; // Success
}
+////////////////////////////////////////////////////////////////////////////////////////
+// Authorization
+
int CDiscordProto::AuthRequest(MCONTACT hContact, const wchar_t*)
{
ptrW wszUsername(getWStringA(hContact, DB_KEY_NICK));
@@ -242,6 +245,42 @@ int CDiscordProto::AuthRequest(MCONTACT hContact, const wchar_t*)
return 0;
}
+int CDiscordProto::AuthRecv(MCONTACT, PROTORECVEVENT *pre)
+{
+ return Proto_AuthRecv(m_szModuleName, pre);
+}
+
+int CDiscordProto::Authorize(MEVENT hDbEvent)
+{
+ DBEVENTINFO dbei = {};
+ if ((dbei.cbBlob = db_event_getBlobSize(hDbEvent)) == (DWORD)(-1)) return 1;
+ if ((dbei.pBlob = (PBYTE)alloca(dbei.cbBlob)) == NULL) return 1;
+ if (db_event_get(hDbEvent, &dbei)) return 1;
+ if (dbei.eventType != EVENTTYPE_AUTHREQUEST) return 1;
+ if (mir_strcmp(dbei.szModule, m_szModuleName)) return 1;
+
+ MCONTACT hContact = DbGetAuthEventContact(&dbei);
+ CMStringA szUrl(FORMAT, "/users/@me/relationships/%lld", getId(hContact, DB_KEY_ID));
+ Push(new AsyncHttpRequest(this, REQUEST_PUT, szUrl, NULL));
+ return 0;
+}
+
+int CDiscordProto::AuthDeny(MEVENT hDbEvent, const wchar_t*)
+{
+ DBEVENTINFO dbei = {};
+ if ((dbei.cbBlob = db_event_getBlobSize(hDbEvent)) == (DWORD)(-1)) return 1;
+ if ((dbei.pBlob = (PBYTE)alloca(dbei.cbBlob)) == NULL) return 1;
+ if (db_event_get(hDbEvent, &dbei)) return 1;
+ if (dbei.eventType != EVENTTYPE_AUTHREQUEST) return 1;
+ if (mir_strcmp(dbei.szModule, m_szModuleName)) return 1;
+
+ MCONTACT hContact = DbGetAuthEventContact(&dbei);
+ RemoveFriend(getId(hContact, DB_KEY_ID));
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////
+
MCONTACT CDiscordProto::AddToList(int flags, PROTOSEARCHRESULT *psr)
{
if (psr->id.w == NULL)
@@ -367,7 +406,7 @@ int CDiscordProto::OnDeleteContact(MCONTACT hContact)
Push(new AsyncHttpRequest(this, REQUEST_DELETE, CMStringA(FORMAT, "/channels/%lld", pUser->channelId), NULL));
if (pUser->id)
- Push(new AsyncHttpRequest(this, REQUEST_DELETE, CMStringA(FORMAT, "/users/@me/relationships/%lld", pUser->id), NULL));
+ RemoveFriend(pUser->id);
return 0;
}