summaryrefslogtreecommitdiff
path: root/protocols/Steam/src
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Steam/src')
-rw-r--r--protocols/Steam/src/steam_contacts.cpp101
-rw-r--r--protocols/Steam/src/steam_polling.cpp29
-rw-r--r--protocols/Steam/src/steam_proto.h1
3 files changed, 79 insertions, 52 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);
diff --git a/protocols/Steam/src/steam_polling.cpp b/protocols/Steam/src/steam_polling.cpp
index a008c359cb..6b53d31763 100644
--- a/protocols/Steam/src/steam_polling.cpp
+++ b/protocols/Steam/src/steam_polling.cpp
@@ -119,19 +119,22 @@ void CSteamProto::ParsePollData(JSONNode *data)
case 2:
{// auth request
- /*MCONTACT hContact = FindContact(steamId);
- if (!hContact)
- hContact = AddContact(steamId, true);*/
-
- //RaiseAuthRequestThread((void*)hContact);
-
- ptrA token(getStringA("TokenSecret"));
-
- PushRequest(
- new GetUserSummariesRequest(token, steamId),
- &CSteamProto::OnAuthRequested,
- mir_strdup(steamId),
- MirFreeArg);
+ MCONTACT hContact = FindContact(steamId);
+ if (hContact)
+ {
+ ContactIsAskingAuth(hContact);
+ }
+ else
+ {
+ // load info about this user from server
+ ptrA token(getStringA("TokenSecret"));
+
+ PushRequest(
+ new GetUserSummariesRequest(token, steamId),
+ &CSteamProto::OnAuthRequested,
+ mir_strdup(steamId),
+ MirFreeArg);
+ }
}
break;
diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h
index 88fb947eab..4f47883aa2 100644
--- a/protocols/Steam/src/steam_proto.h
+++ b/protocols/Steam/src/steam_proto.h
@@ -142,6 +142,7 @@ protected:
void ContactIsRemoved(MCONTACT hContact);
void ContactIsFriend(MCONTACT hContact);
void ContactIsIgnored(MCONTACT hContact);
+ void ContactIsAskingAuth(MCONTACT hContact);
MCONTACT FindContact(const char *steamId);
MCONTACT AddContact(const char *steamId, bool isTemporary = false);