diff options
author | Robert Pösel <robyer@seznam.cz> | 2017-08-20 13:36:58 +0200 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2017-08-20 13:37:14 +0200 |
commit | ab6b80d2ba56b4df04090c35f42dd2179f0267a2 (patch) | |
tree | 6e2613cc52304d1213ed536c63aeabe7223e9a23 /protocols/Steam/src | |
parent | de78aa477e08a177b1abd3c28869ed434374223c (diff) |
Lock whole adding/finding contact
Diffstat (limited to 'protocols/Steam/src')
-rw-r--r-- | protocols/Steam/src/steam_contacts.cpp | 62 |
1 files changed, 36 insertions, 26 deletions
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<std::string, JSONNode*>::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<std::string, JSONNode*>::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); |