diff options
author | Robert Pösel <robyer@seznam.cz> | 2014-12-04 14:00:12 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2014-12-04 14:00:12 +0000 |
commit | f16b4030068686b9f8bc1c4d22cd8c52b78a21d0 (patch) | |
tree | 020e2683044a23edd2eb0ef7db195c5220d143f9 /protocols | |
parent | 2eaa3458b74ffdae9c91b4eb6fe84f8145af3fa1 (diff) |
Steam:
- Save timestamp when user created his account ("MemberTS")
- Save timestamp when user was removed from friends ("DeletedTS")
- Save timestamp when user was added to friends ("ContactAddTime" in branch "UserInfo" - compatibility with UserInfoEx)
- Properly set info about deleted contacts at login
- Notify when user is deleted or added again to contacts
git-svn-id: http://svn.miranda-ng.org/main/trunk@11240 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Steam/src/common.h | 1 | ||||
-rw-r--r-- | protocols/Steam/src/steam_contacts.cpp | 139 | ||||
-rw-r--r-- | protocols/Steam/src/steam_pooling.cpp | 18 | ||||
-rw-r--r-- | protocols/Steam/src/steam_proto.h | 5 |
4 files changed, 123 insertions, 40 deletions
diff --git a/protocols/Steam/src/common.h b/protocols/Steam/src/common.h index 2811c9a861..4c43df32b7 100644 --- a/protocols/Steam/src/common.h +++ b/protocols/Steam/src/common.h @@ -27,6 +27,7 @@ #include <m_protoint.h>
#include <win2k.h>
+#include <map>
#include <vector>
#include <string>
diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp index 505a088038..f0498f25f6 100644 --- a/protocols/Steam/src/steam_contacts.cpp +++ b/protocols/Steam/src/steam_contacts.cpp @@ -108,6 +108,9 @@ void CSteamProto::UpdateContact(MCONTACT hContact, JSONNODE *data) else
delSetting(hContact, "Country");
+ node = json_get(data, "timecreated");
+ setDword(hContact, "MemberTS", json_as_int(node));
+
// only for contacts
if (hContact)
{
@@ -139,6 +142,44 @@ void CSteamProto::UpdateContact(MCONTACT hContact, JSONNODE *data) }
}
+void CSteamProto::ContactIsRemoved(MCONTACT hContact)
+{
+ if (!getDword(hContact, "DeletedTS", 0) && getByte(hContact, "Auth", 0) == 0)
+ {
+ setByte(hContact, "Auth", 1);
+ setDword(hContact, "DeletedTS", ::time(NULL));
+ setWord(hContact, "Status", ID_STATUS_OFFLINE);
+
+ ptrT nick(getTStringA(hContact, "Nick"));
+ TCHAR message[MAX_PATH];
+ mir_sntprintf(message, MAX_PATH, TranslateT("%s has been removed from your contact list"), nick);
+
+ ShowNotification(_T("Steam"), message);
+ }
+}
+
+void CSteamProto::ContactIsFriend(MCONTACT hContact)
+{
+ if (getDword(hContact, "DeletedTS", 0) || getByte(hContact, "Auth", 0) != 0)
+ {
+ delSetting(hContact, "Auth");
+ delSetting(hContact, "DeletedTS");
+ delSetting(hContact, "Grant");
+
+ ptrT nick(getTStringA(hContact, "Nick"));
+ TCHAR message[MAX_PATH];
+ mir_sntprintf(message, MAX_PATH, TranslateT("%s is back in your contact list"), nick);
+
+ ShowNotification(_T("Steam"), message);
+ }
+}
+
+void CSteamProto::ContactIsIgnored(MCONTACT hContact)
+{
+ // todo
+ setByte(hContact, "Block", 1);
+}
+
MCONTACT CSteamProto::AddContact(const char *steamId, bool isTemporary)
{
MCONTACT hContact = this->FindContact(steamId);
@@ -172,6 +213,34 @@ MCONTACT CSteamProto::AddContact(const char *steamId, bool isTemporary) return hContact;
}
+void CSteamProto::ProcessContact(std::map<std::string, JSONNODE*>::iterator *it, MCONTACT hContact)
+{
+ std::string steamId = (*it)->first;
+ JSONNODE *child = (*it)->second;
+
+ if (!hContact)
+ hContact = AddContact(steamId.c_str());
+
+ JSONNODE *node = json_get(child, "friend_since");
+ db_set_dw(hContact, "UserInfo", "ContactAddTime", json_as_int(node));
+
+ node = json_get(child, "relationship");
+ ptrA relationship(mir_u2a(json_as_string(node)));
+ if (!lstrcmpiA(relationship, "friend"))
+ {
+ ContactIsFriend(hContact);
+ }
+ else if (!lstrcmpiA(relationship, "ignoredfriend"))
+ {
+ ContactIsIgnored(hContact);
+ }
+ else if (!lstrcmpiA(relationship, "requestrecipient"))
+ {
+ // todo
+ //RaiseAuthRequestThread((void*)hContact);
+ }
+}
+
void CSteamProto::OnGotFriendList(const NETLIBHTTPREQUEST *response, void *arg)
{
if (response == NULL)
@@ -183,6 +252,9 @@ void CSteamProto::OnGotFriendList(const NETLIBHTTPREQUEST *response, void *arg) std::string steamIds = ptrA(getStringA("SteamID"));
+ std::map<std::string, JSONNODE*> friends;
+
+ // Remember contacts on server
JSONNODE *node = json_get(root, "friends");
JSONNODE *nroot = json_as_array(node);
if (nroot != NULL)
@@ -194,36 +266,51 @@ void CSteamProto::OnGotFriendList(const NETLIBHTTPREQUEST *response, void *arg) break;
node = json_get(child, "steamid");
- ptrA steamId(mir_u2a(json_as_string(node)));
- steamIds.append(",").append(steamId);
+ if (node == NULL)
+ continue;
- MCONTACT hContact = FindContact(steamId);
- if (!hContact)
- hContact = AddContact(steamId);
+ std::string steamId = _T2A(json_as_string(node));
+ friends.insert(std::make_pair(steamId, child));
+ }
+ }
- node = json_get(child, "relationship");
- ptrA relationship(mir_u2a(json_as_string(node)));
- /*if (!lstrcmpiA(relationship, "friend"))
- {
- if (!FindContact(steamId))
- {
- AddContact(steamId);
- steamIds.append(steamId).append(",");
- }
- }
- else */if (!lstrcmpiA(relationship, "ignoredfriend"))
- {
- // todo
- setByte(hContact, "Block", 1);
- }
- else if (!lstrcmpiA(relationship, "requestrecipient"))
- {
- // todo
- //RaiseAuthRequestThread((void*)hContact);
- }
- else continue;
+ // Check and update contacts in database
+ for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
+ {
+ if (isChatRoom(hContact))
+ continue;
+
+ ptrA id(getStringA(hContact, "SteamID"));
+ if (id == NULL)
+ continue;
+
+ std::map<std::string, JSONNODE*>::iterator it = friends.find(std::string(id));
+
+ if (it != friends.end())
+ {
+ // Contact is on server-list, update (and eventually notify) it
+ ProcessContact(&it, hContact);
+
+ steamIds.append(",").append(it->first);
+ friends.erase(it);
}
+ else
+ {
+ // Contact was removed from server-list, notify it
+ ContactIsRemoved(hContact);
+ }
+ }
+
+ // Check remaining contacts in map and add them to contact list
+ for (std::map<std::string, JSONNODE*>::iterator it = friends.begin(); it != friends.end();)
+ {
+ // Contact is on server-list, but not in database, add (but not notify) it
+ ProcessContact(&it, NULL);
+
+ steamIds.append(",").append(it->first);
+ it = friends.erase(it);
}
+ friends.clear();
if (!steamIds.empty())
{
diff --git a/protocols/Steam/src/steam_pooling.cpp b/protocols/Steam/src/steam_pooling.cpp index 1bcc29bbb5..bd0d2fa49e 100644 --- a/protocols/Steam/src/steam_pooling.cpp +++ b/protocols/Steam/src/steam_pooling.cpp @@ -104,33 +104,23 @@ void CSteamProto::ParsePollData(JSONNODE *data) MCONTACT hContact = FindContact(steamId); if (hContact) { - setByte(hContact, "Auth", 1); - - TCHAR message[MAX_PATH]; - mir_sntprintf( - message, MAX_PATH, - TranslateT("%s has been removed from your contact list"), - ptrT(mir_a2t(steamId))); - - ShowNotification(_T("Steam"), message); + ContactIsRemoved(hContact); } } break; case 1: - // ignored - // todo - { + {// ignored MCONTACT hContact = FindContact(steamId); if (hContact) { - setByte(hContact, "Block", 1); + ContactIsIgnored(hContact); } } break; case 2: - { // auth request + {// auth request /*MCONTACT hContact = FindContact(steamId); if (!hContact) hContact = AddContact(steamId, true);*/ diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index 639cefca18..cfd173c37a 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -195,6 +195,11 @@ protected: MCONTACT GetContactFromAuthEvent(HANDLE hEvent);
void UpdateContact(MCONTACT hContact, JSONNODE *data);
+ void ProcessContact(std::map<std::string, JSONNODE*>::iterator *it, MCONTACT hContact);
+
+ void ContactIsRemoved(MCONTACT hContact);
+ void ContactIsFriend(MCONTACT hContact);
+ void ContactIsIgnored(MCONTACT hContact);
MCONTACT FindContact(const char *steamId);
MCONTACT AddContact(const char *steamId, bool isTemporary = false);
|