summaryrefslogtreecommitdiff
path: root/protocols/Steam/src/steam_contacts.cpp
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2016-06-30 08:29:52 +0000
committerRobert Pösel <robyer@seznam.cz>2016-06-30 08:29:52 +0000
commitff1c157a941458735ece56effc60f3ab7a88b8d8 (patch)
tree51e4d634d3376df8c489863c1dfe2529d2027f4f /protocols/Steam/src/steam_contacts.cpp
parent8b5c9ad399a7cdb1c8b4986d4289f7b2a87248c2 (diff)
Steam: Support repeated authorization from same contact
E.g., when he was deleted and drequested authorization again, while Miranda was offline and couldn't catch the deleted event. But it's not tested. git-svn-id: http://svn.miranda-ng.org/main/trunk@17051 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Steam/src/steam_contacts.cpp')
-rw-r--r--protocols/Steam/src/steam_contacts.cpp101
1 files changed, 62 insertions, 39 deletions
diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp
index b069052cbc..9d3c9a88f8 100644
--- a/protocols/Steam/src/steam_contacts.cpp
+++ b/protocols/Steam/src/steam_contacts.cpp
@@ -256,6 +256,8 @@ void CSteamProto::UpdateContact(MCONTACT hContact, JSONNode *data)
void CSteamProto::ContactIsRemoved(MCONTACT hContact)
{
+ delSetting(hContact, "AuthAsked");
+
if (!getDword(hContact, "DeletedTS", 0) && getByte(hContact, "Auth", 0) == 0)
{
setByte(hContact, "Auth", 1);
@@ -272,10 +274,12 @@ void CSteamProto::ContactIsRemoved(MCONTACT hContact)
void CSteamProto::ContactIsFriend(MCONTACT hContact)
{
+ delSetting(hContact, "AuthAsked");
+
if (getDword(hContact, "DeletedTS", 0) || getByte(hContact, "Auth", 0) != 0)
{
delSetting(hContact, "Auth");
- delSetting(hContact, "DeletedTS");
+ delSetting(hContact, "DeletedTS");
delSetting(hContact, "Grant");
ptrT nick(getTStringA(hContact, "Nick"));
@@ -292,6 +296,61 @@ void CSteamProto::ContactIsIgnored(MCONTACT hContact)
setByte(hContact, "Block", 1);
}
+void CSteamProto::ContactIsAskingAuth(MCONTACT hContact)
+{
+ if (getByte(hContact, "AuthAsked", 0) != 0) {
+ // auth request was already showed, do nothing here
+ return;
+ }
+
+ if (getByte(hContact, "Auth", 0) == 0) {
+ // user was just added or he already has authorization, but because we've just got auth request, he was probably deleted and requested again
+ ContactIsRemoved(hContact);
+ }
+
+ // create auth request event
+ ptrA steamId(getStringA(hContact, "SteamID"));
+ ptrA nickName(getStringA(hContact, "Nick"));
+ ptrA firstName(getStringA(hContact, "FirstName"));
+ if (firstName == NULL)
+ firstName = mir_strdup("");
+ ptrA lastName(getStringA(hContact, "LastName"));
+ if (lastName == NULL)
+ lastName = mir_strdup("");
+
+ char reason[MAX_PATH];
+ mir_snprintf(reason, Translate("%s has added you to his or her Friend List"), nickName);
+
+ // blob is: 0(DWORD), hContact(DWORD), nick(ASCIIZ), firstName(ASCIIZ), lastName(ASCIIZ), sid(ASCIIZ), reason(ASCIIZ)
+ DWORD cbBlob = (DWORD)(sizeof(DWORD)* 2 + mir_strlen(nickName) + mir_strlen(firstName) + mir_strlen(lastName) + mir_strlen(steamId) + mir_strlen(reason) + 5);
+
+ PBYTE pBlob, pCurBlob;
+ pCurBlob = pBlob = (PBYTE)mir_alloc(cbBlob);
+
+ *((PDWORD)pCurBlob) = 0;
+ pCurBlob += sizeof(DWORD);
+ *((PDWORD)pCurBlob) = (DWORD)hContact;
+ pCurBlob += sizeof(DWORD);
+ mir_strcpy((char*)pCurBlob, nickName);
+ pCurBlob += mir_strlen(nickName) + 1;
+ mir_strcpy((char*)pCurBlob, firstName);
+ pCurBlob += mir_strlen(firstName) + 1;
+ mir_strcpy((char*)pCurBlob, lastName);
+ pCurBlob += mir_strlen(lastName) + 1;
+ mir_strcpy((char*)pCurBlob, steamId);
+ pCurBlob += mir_strlen(steamId) + 1;
+ mir_strcpy((char*)pCurBlob, reason);
+
+ PROTORECVEVENT recv = { 0 };
+ recv.timestamp = time(NULL);
+ recv.szMessage = (char*)pBlob;
+ recv.lParam = cbBlob;
+ ProtoChainRecv(hContact, PSR_AUTH, 0, (LPARAM)&recv);
+
+ // remember to not create this event again, unless authorization status changes again
+ setByte(hContact, "AuthAsked", 1);
+}
+
MCONTACT CSteamProto::AddContact(const char *steamId, bool isTemporary)
{
MCONTACT hContact = this->FindContact(steamId);
@@ -353,8 +412,7 @@ void CSteamProto::ProcessContact(std::map<std::string, JSONNode*>::iterator *it,
}
else if (!lstrcmpiA(relationship, "requestrecipient"))
{
- // todo
- //RaiseAuthRequestThread((void*)hContact);
+ ContactIsAskingAuth(hContact);
}
}
@@ -626,42 +684,7 @@ void CSteamProto::OnAuthRequested(const HttpResponse *response, void *arg)
UpdateContact(hContact, nroot);
- ptrA nickName(getStringA(hContact, "Nick"));
- ptrA firstName(getStringA(hContact, "FirstName"));
- if (firstName == NULL)
- firstName = mir_strdup("");
- ptrA lastName(getStringA(hContact, "LastName"));
- if (lastName == NULL)
- lastName = mir_strdup("");
-
- char reason[MAX_PATH];
- mir_snprintf(reason, Translate("%s has added you to his or her Friend List"), nickName);
-
- // blob is: 0(DWORD), hContact(DWORD), nick(ASCIIZ), firstName(ASCIIZ), lastName(ASCIIZ), sid(ASCIIZ), reason(ASCIIZ)
- DWORD cbBlob = (DWORD)(sizeof(DWORD)* 2 + mir_strlen(nickName) + mir_strlen(firstName) + mir_strlen(lastName) + mir_strlen(steamId) + mir_strlen(reason) + 5);
-
- PBYTE pBlob, pCurBlob;
- pCurBlob = pBlob = (PBYTE)mir_alloc(cbBlob);
-
- *((PDWORD)pCurBlob) = 0;
- pCurBlob += sizeof(DWORD);
- *((PDWORD)pCurBlob) = (DWORD)hContact;
- pCurBlob += sizeof(DWORD);
- mir_strcpy((char*)pCurBlob, nickName);
- pCurBlob += mir_strlen(nickName) + 1;
- mir_strcpy((char*)pCurBlob, firstName);
- pCurBlob += mir_strlen(firstName) + 1;
- mir_strcpy((char*)pCurBlob, lastName);
- pCurBlob += mir_strlen(lastName) + 1;
- mir_strcpy((char*)pCurBlob, steamId);
- pCurBlob += mir_strlen(steamId) + 1;
- mir_strcpy((char*)pCurBlob, reason);
-
- PROTORECVEVENT recv = { 0 };
- recv.timestamp = time(NULL);
- recv.szMessage = (char*)pBlob;
- recv.lParam = cbBlob;
- ProtoChainRecv(hContact, PSR_AUTH, 0, (LPARAM)&recv);
+ ContactIsAskingAuth(hContact);
}
json_delete(nodes);