diff options
Diffstat (limited to 'protocols/Tox/src')
| -rw-r--r-- | protocols/Tox/src/tox_contacts.cpp | 33 | ||||
| -rw-r--r-- | protocols/Tox/src/tox_proto.cpp | 49 | 
2 files changed, 38 insertions, 44 deletions
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<uint8_t> id(TOX_CLIENT_ID_SIZE);
 +	if (!db_get(hContact, m_szModuleName, TOX_SETTINGS_ID, &dbv))
  	{
 -		DBVARIANT dbv;
 -		std::vector<uint8_t> 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<uint8_t> clientId(address, address + TOX_FRIEND_ADDRESS_SIZE);
 +	std::vector<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> id;
  	DBVARIANT dbv;
 -	if (!db_get(NULL, m_szModuleName, TOX_SETTINGS_ID, &dbv))
 +	std::vector<uint8_t> 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<uint8_t> 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;
  | 
