From d4017faae95d479ac6fa9524f58975bd27f8df7c Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Thu, 11 Sep 2014 05:16:24 +0000 Subject: Tox: fixed contact adding git-svn-id: http://svn.miranda-ng.org/main/trunk@10426 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/res/resource.aps | Bin 42156 -> 0 bytes protocols/Tox/src/tox_contacts.cpp | 33 ++++++++++++------------- protocols/Tox/src/tox_proto.cpp | 49 +++++++++++++++++-------------------- 3 files changed, 38 insertions(+), 44 deletions(-) delete mode 100644 protocols/Tox/res/resource.aps (limited to 'protocols/Tox') diff --git a/protocols/Tox/res/resource.aps b/protocols/Tox/res/resource.aps deleted file mode 100644 index 1bf17c7ce1..0000000000 Binary files a/protocols/Tox/res/resource.aps and /dev/null differ diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp index e148a6ef9a..e3c2b94247 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -31,7 +31,7 @@ MCONTACT CToxProto::GetContactFromAuthEvent(HANDLE hEvent) { DWORD body[3]; DBEVENTINFO dbei = { sizeof(DBEVENTINFO) }; - dbei.cbBlob = sizeof(DWORD)*2; + dbei.cbBlob = sizeof(DWORD)* 2; dbei.pBlob = (PBYTE)&body; if (db_event_get(hEvent, &dbei)) @@ -154,27 +154,24 @@ void CToxProto::LoadFriendList() int CToxProto::OnContactDeleted(MCONTACT hContact, LPARAM lParam) { - if (hContact && IsOnline()) + DBVARIANT dbv; + std::vector id(TOX_CLIENT_ID_SIZE); + if (!db_get(hContact, m_szModuleName, TOX_SETTINGS_ID, &dbv)) { - DBVARIANT dbv; - std::vector id(TOX_CLIENT_ID_SIZE); - if (!db_get(hContact, m_szModuleName, TOX_SETTINGS_ID, &dbv)) + if (dbv.type != DBVT_BLOB) { - if (dbv.type != DBVT_BLOB) - { - return 0; - } + return 0; + } - memcpy(&id[0], dbv.pbVal, TOX_CLIENT_ID_SIZE); - db_free(&dbv); + memcpy(&id[0], dbv.pbVal, TOX_CLIENT_ID_SIZE); + db_free(&dbv); - uint32_t number = tox_get_friend_number(tox, id.data()); - if (tox_del_friend(tox, number) == 0) - { - SaveToxData(); + uint32_t number = tox_get_friend_number(tox, id.data()); + if (tox_del_friend(tox, number) == 0) + { + SaveToxData(); - return 0; - } + return 0; } } @@ -186,7 +183,7 @@ void CToxProto::OnFriendRequest(Tox *tox, const uint8_t *address, const uint8_t CToxProto *proto = (CToxProto*)arg; // trim tox address to tox id - std::vector clientId(address, address + TOX_FRIEND_ADDRESS_SIZE); + std::vector clientId(address, address + TOX_CLIENT_ID_SIZE); std::string id = proto->DataToHexString(clientId); MCONTACT hContact = proto->AddContact(clientId); diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index 33f05487ed..fa08e4f42f 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -90,28 +90,26 @@ MCONTACT __cdecl CToxProto::AddToListByEvent(int flags, int iContact, HANDLE hDb int __cdecl CToxProto::Authorize(HANDLE hDbEvent) { - if (IsOnline() && hDbEvent) + MCONTACT hContact = GetContactFromAuthEvent(hDbEvent); + if (hContact == INVALID_CONTACT_ID) { - MCONTACT hContact = GetContactFromAuthEvent(hDbEvent); - if (hContact == INVALID_CONTACT_ID) - { - return 1; - } + return 1; + } - DBVARIANT dbv; - if (!db_get(hContact, m_szModuleName, TOX_SETTINGS_ID, &dbv)) + DBVARIANT dbv; + if (!db_get(hContact, m_szModuleName, TOX_SETTINGS_ID, &dbv)) + { + std::vector id(TOX_CLIENT_ID_SIZE); + memcpy(&id[0], dbv.pbVal, TOX_CLIENT_ID_SIZE); + if (tox_add_friend_norequest(tox, id.data()) != TOX_ERROR) { - std::vector id(TOX_CLIENT_ID_SIZE); - memcpy(&id[0], dbv.pbVal, TOX_CLIENT_ID_SIZE); - if (tox_add_friend_norequest(tox, id.data()) != TOX_ERROR) - { - db_unset(hContact, m_szModuleName, "Auth"); - SaveToxData(); - db_free(&dbv); - return 0; - } + db_unset(hContact, "CList", "NotOnList"); + delSetting(hContact, "Auth"); + SaveToxData(); db_free(&dbv); + return 0; } + db_free(&dbv); } return 1; @@ -127,30 +125,29 @@ int __cdecl CToxProto::AuthRecv(MCONTACT, PROTORECVEVENT* pre) int __cdecl CToxProto::AuthRequest(MCONTACT hContact, const PROTOCHAR* szMessage) { - std::vector id; DBVARIANT dbv; - if (!db_get(NULL, m_szModuleName, TOX_SETTINGS_ID, &dbv)) + std::vector address(TOX_FRIEND_ADDRESS_SIZE); + if (!db_get(hContact, m_szModuleName, TOX_SETTINGS_ID, &dbv)) { - memcpy(&id[0], (uint8_t*)dbv.pbVal, TOX_CLIENT_ID_SIZE); + memcpy(&address[0], (uint8_t*)dbv.pbVal, TOX_FRIEND_ADDRESS_SIZE); db_free(&dbv); } ptrA reason(mir_utf8encodeW(szMessage)); - int32_t number = tox_add_friend(tox, id.data(), (uint8_t*)(char*)reason, (uint16_t)strlen(reason)); - if (number != TOX_ERROR) + int32_t number = tox_add_friend(tox, address.data(), (uint8_t*)(char*)reason, (uint16_t)strlen(reason)); + if (number > TOX_ERROR) { SaveToxData(); // change tox address in contact id by tox id - db_set_blob(hContact, m_szModuleName, TOX_SETTINGS_ID, (uint8_t*)id.data(), TOX_CLIENT_ID_SIZE); + db_set_blob(hContact, m_szModuleName, TOX_SETTINGS_ID, (uint8_t*)address.data(), TOX_CLIENT_ID_SIZE); db_unset(hContact, "CList", "NotOnList"); delSetting(hContact, "Auth"); - std::vector username(TOX_MAX_NAME_LENGTH); - tox_get_name(tox, number, &username[0]); - std::string nick(username.begin(), username.end()); + std::string nick("", TOX_MAX_NAME_LENGTH); + tox_get_name(tox, number, (uint8_t*)&nick[0]); setString(hContact, "Nick", nick.c_str()); return 0; -- cgit v1.2.3