From 1279ffffeaadbac1e57073b61bf2da05577af23b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Sun, 20 Aug 2017 12:51:56 +0200 Subject: Rename UpdateContact to UpdateContactDetails --- protocols/Steam/src/steam_contacts.cpp | 6 +++--- protocols/Steam/src/steam_proto.cpp | 2 +- protocols/Steam/src/steam_proto.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'protocols/Steam/src') diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp index 5ed053fecb..c1f2bc68d3 100644 --- a/protocols/Steam/src/steam_contacts.cpp +++ b/protocols/Steam/src/steam_contacts.cpp @@ -94,7 +94,7 @@ MCONTACT CSteamProto::FindContact(const char *steamId) return hContact; } -void CSteamProto::UpdateContact(MCONTACT hContact, JSONNode *data) +void CSteamProto::UpdateContactDetails(MCONTACT hContact, JSONNode *data) { // set common data JSONNode *node = json_get(data, "personaname"); @@ -573,7 +573,7 @@ void CSteamProto::OnGotUserSummaries(const HttpResponse *response) hContact = AddContact(steamId); } - UpdateContact(hContact, item); + UpdateContactDetails(hContact, item); } json_delete(nroot); } @@ -680,7 +680,7 @@ void CSteamProto::OnAuthRequested(const HttpResponse *response, void *arg) if (!hContact) hContact = AddContact(steamId); - UpdateContact(hContact, nroot); + UpdateContactDetails(hContact, nroot); ContactIsAskingAuth(hContact); } diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp index aef0747f81..5ea69328b8 100644 --- a/protocols/Steam/src/steam_proto.cpp +++ b/protocols/Steam/src/steam_proto.cpp @@ -104,7 +104,7 @@ MCONTACT CSteamProto::AddToList(int, PROTOSEARCHRESULT* psr) { STEAM_SEARCH_RESULT *ssr = (STEAM_SEARCH_RESULT*)psr; hContact = AddContact(steamId, true); - UpdateContact(hContact, ssr->data); + UpdateContactDetails(hContact, ssr->data); } return hContact; diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index b9d4ca8556..249fd7a9de 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -137,7 +137,7 @@ protected: MCONTACT GetContactFromAuthEvent(MEVENT hEvent); - void UpdateContact(MCONTACT hContact, JSONNode *data); + void UpdateContactDetails(MCONTACT hContact, JSONNode *data); void ProcessContact(std::map::iterator *it, MCONTACT hContact); void ContactIsRemoved(MCONTACT hContact); -- cgit v1.2.3 From de78aa477e08a177b1abd3c28869ed434374223c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Sun, 20 Aug 2017 13:18:06 +0200 Subject: Rework ProcessContact method --- protocols/Steam/src/steam_contacts.cpp | 17 ++++++----------- protocols/Steam/src/steam_proto.h | 4 ++-- 2 files changed, 8 insertions(+), 13 deletions(-) (limited to 'protocols/Steam/src') diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp index c1f2bc68d3..6815af9f59 100644 --- a/protocols/Steam/src/steam_contacts.cpp +++ b/protocols/Steam/src/steam_contacts.cpp @@ -378,19 +378,13 @@ MCONTACT CSteamProto::AddContact(const char *steamId, bool isTemporary) return hContact; } -void CSteamProto::ProcessContact(std::map::iterator *it, MCONTACT hContact) +void CSteamProto::UpdateContactRelationship(MCONTACT hContact, JSONNode *data) { - std::string steamId = (*it)->first; - JSONNode *child = (*it)->second; - - if (!hContact) - hContact = AddContact(steamId.c_str()); - - JSONNode *node = json_get(child, "friend_since"); + JSONNode *node = json_get(data, "friend_since"); if (node) db_set_dw(hContact, "UserInfo", "ContactAddTime", json_as_int(node)); - node = json_get(child, "relationship"); + node = json_get(data, "relationship"); if (node == NULL) return; @@ -457,7 +451,7 @@ void CSteamProto::OnGotFriendList(const HttpResponse *response) if (it != friends.end()) { // Contact is on server-list, update (and eventually notify) it - ProcessContact(&it, hContact); + UpdateContactRelationship(hContact, it->second); steamIds.append(",").append(it->first); friends.erase(it); @@ -473,7 +467,8 @@ void CSteamProto::OnGotFriendList(const HttpResponse *response) for (std::map::iterator it = friends.begin(); it != friends.end();) { // Contact is on server-list, but not in database, add (but not notify) it - ProcessContact(&it, NULL); + MCONTACT hContact = AddContact(it->first.c_str()); + UpdateContactRelationship(hContact, it->second); steamIds.append(",").append(it->first); it = friends.erase(it); diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index 249fd7a9de..4a2aff8d47 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -138,8 +138,8 @@ protected: MCONTACT GetContactFromAuthEvent(MEVENT hEvent); void UpdateContactDetails(MCONTACT hContact, JSONNode *data); - void ProcessContact(std::map::iterator *it, MCONTACT hContact); - + void UpdateContactRelationship(MCONTACT hContact, JSONNode *data); + void ContactIsRemoved(MCONTACT hContact); void ContactIsFriend(MCONTACT hContact); void ContactIsIgnored(MCONTACT hContact); -- cgit v1.2.3 From ab6b80d2ba56b4df04090c35f42dd2179f0267a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Sun, 20 Aug 2017 13:36:58 +0200 Subject: Lock whole adding/finding contact --- protocols/Steam/src/steam_contacts.cpp | 62 ++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 26 deletions(-) (limited to 'protocols/Steam/src') diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp index 6815af9f59..1b3620e736 100644 --- a/protocols/Steam/src/steam_contacts.cpp +++ b/protocols/Steam/src/steam_contacts.cpp @@ -346,7 +346,17 @@ void CSteamProto::ContactIsAskingAuth(MCONTACT hContact) MCONTACT CSteamProto::AddContact(const char *steamId, bool isTemporary) { - MCONTACT hContact = this->FindContact(steamId); + MCONTACT hContact = NULL; + + mir_cslock lck(this->contact_search_lock); + + for (hContact = db_find_first(this->m_szModuleName); hContact; hContact = db_find_next(hContact, this->m_szModuleName)) + { + ptrA cSteamId(db_get_sa(hContact, this->m_szModuleName, "SteamID")); + if (!lstrcmpA(cSteamId, steamId)) + break; + } + if (!hContact) { // create contact @@ -436,30 +446,34 @@ void CSteamProto::OnGotFriendList(const HttpResponse *response) } } - // 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; + // Check and update contacts in database + mir_cslock lck(this->contact_search_lock); - ptrA id(getStringA(hContact, "SteamID")); - if (id == NULL) - continue; + for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) + { + if (isChatRoom(hContact)) + continue; - std::map::iterator it = friends.find(std::string(id)); + ptrA id(getStringA(hContact, "SteamID")); + if (id == NULL) + continue; - if (it != friends.end()) - { - // Contact is on server-list, update (and eventually notify) it - UpdateContactRelationship(hContact, it->second); + std::map::iterator it = friends.find(std::string(id)); - steamIds.append(",").append(it->first); - friends.erase(it); - } - else - { - // Contact was removed from server-list, notify it - ContactIsRemoved(hContact); + if (it != friends.end()) + { + // Contact is on server-list, update (and eventually notify) it + UpdateContactRelationship(hContact, it->second); + + steamIds.append(",").append(it->first); + friends.erase(it); + } + else + { + // Contact was removed from server-list, notify it + ContactIsRemoved(hContact); + } } } @@ -563,9 +577,7 @@ void CSteamProto::OnGotUserSummaries(const HttpResponse *response) MCONTACT hContact = NULL; if (!IsMe(steamId)) { - hContact = FindContact(steamId); - if (!hContact) - hContact = AddContact(steamId); + hContact = AddContact(steamId); } UpdateContactDetails(hContact, item); @@ -671,9 +683,7 @@ void CSteamProto::OnAuthRequested(const HttpResponse *response, void *arg) node = json_get(nroot, "steamid"); ptrA steamId(mir_u2a(ptrW(json_as_string(node)))); - MCONTACT hContact = FindContact(steamId); - if (!hContact) - hContact = AddContact(steamId); + MCONTACT hContact = AddContact(steamId); UpdateContactDetails(hContact, nroot); -- cgit v1.2.3