From df1139ff3c50f0cffc7dc7a8a4e7310eb7e55e2d Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sat, 23 Aug 2014 18:49:59 +0000 Subject: Tox: - fixed own status changing - refactored contacts adding git-svn-id: http://svn.miranda-ng.org/main/trunk@10315 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_account.cpp | 22 ++++++---- protocols/Tox/src/tox_contacts.cpp | 71 +++++++++++++++----------------- protocols/Tox/src/tox_events.cpp | 84 ++++++++++++-------------------------- protocols/Tox/src/tox_proto.cpp | 75 +++++++++++++++++++++------------- protocols/Tox/src/tox_proto.h | 24 ++++++----- protocols/Tox/src/tox_utils.cpp | 9 ++++ 6 files changed, 145 insertions(+), 140 deletions(-) diff --git a/protocols/Tox/src/tox_account.cpp b/protocols/Tox/src/tox_account.cpp index 2b2d2c2837..8118149cdb 100644 --- a/protocols/Tox/src/tox_account.cpp +++ b/protocols/Tox/src/tox_account.cpp @@ -27,8 +27,7 @@ void CToxProto::InitToxCore() tox = tox_new(&options); tox_callback_friend_request(tox, OnFriendRequest, this); tox_callback_friend_message(tox, OnFriendMessage, this); - tox_callback_typing_change(tox, OnFriendTyping, this); - //tox_callback_friend_action(tox, OnAction, this); + tox_callback_typing_change(tox, OnTypingChanged, this); tox_callback_name_change(tox, OnFriendNameChange, this); tox_callback_status_message(tox, OnStatusMessageChanged, this); tox_callback_user_status(tox, OnUserStatusChanged, this); @@ -87,7 +86,11 @@ void CToxProto::DoTox() void CToxProto::PollingThread(void*) { debugLogA("CToxProto::PollingThread: entering"); - + + isConnected = false; + time_t timestamp0 = time(NULL); + DoBootstrap(); + while (!isTerminated) { DoTox(); @@ -97,20 +100,25 @@ void CToxProto::PollingThread(void*) if (tox_isconnected(tox)) { isConnected = true; + debugLogA("CToxProto::PollingThread: successfuly connected to DHT"); LoadContactList(); - m_iStatus = m_iDesiredStatus = ID_STATUS_ONLINE; + m_iStatus = ID_STATUS_ONLINE; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus); - - debugLogA("CToxProto::PollingThread: successfuly connected to DHT"); } else { - DoBootstrap(); + time_t timestamp1 = time(NULL); + if (timestamp0 + 250 < timestamp1) { + timestamp0 = timestamp1; + DoBootstrap(); + } } } } + isConnected = false; + debugLogA("CToxProto::PollingThread: leaving"); } \ No newline at end of file diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp index c5bc9890b2..0806bc7b24 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -34,7 +34,7 @@ MCONTACT CToxProto::GetContactFromAuthEvent(HANDLE hEvent) dbei.cbBlob = sizeof(DWORD)* 2; dbei.pBlob = (PBYTE)&body; - if (::db_event_get(hEvent, &dbei)) + if (db_event_get(hEvent, &dbei)) return INVALID_CONTACT_ID; if (dbei.eventType != EVENTTYPE_AUTHREQUEST) @@ -52,7 +52,7 @@ bool CToxProto::IsProtoContact(MCONTACT hContact) return lstrcmpiA(GetContactProto(hContact), m_szModuleName) == 0; } -MCONTACT CToxProto::FindContact(const char *clientId) +MCONTACT CToxProto::FindContact(const std::string &id) { MCONTACT hContact = NULL; @@ -60,9 +60,11 @@ MCONTACT CToxProto::FindContact(const char *clientId) for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { - ptrA contactId(getStringA(hContact, TOX_SETTINGS_ID)); - if (lstrcmpiA(contactId, clientId) == 0) + std::string contactId = ToxAddressToId(getStringA(hContact, TOX_SETTINGS_ID)); + if (id.compare(contactId)) + { break; + } } //LeaveCriticalSection(&contact_search_lock); @@ -70,26 +72,25 @@ MCONTACT CToxProto::FindContact(const char *clientId) return hContact; } -MCONTACT CToxProto::AddContact(const char *clientId, bool isTemporary) +MCONTACT CToxProto::FindContact(const int friendNumber) { - std::string toxId = clientId; - if (toxId.length() > TOX_CLIENT_ID_SIZE * 2) - { - toxId.erase(toxId.begin() + TOX_CLIENT_ID_SIZE * 2, toxId.end()); - } - MCONTACT hContact = FindContact(toxId.c_str()); + std::vector clientId(TOX_CLIENT_ID_SIZE); + tox_get_client_id(tox, friendNumber, &clientId[0]); + std::string id = DataToHexString(clientId); + + return FindContact(id); +} + +MCONTACT CToxProto::AddContact(const std::string &id, bool isTemporary) +{ + MCONTACT hContact = FindContact(id); if (!hContact) { hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); CallService(MS_PROTO_ADDTOCONTACT, hContact, (LPARAM)m_szModuleName); - if (isTemporary) - { - db_set_b(hContact, "CList", "NotOnList", 1); - db_set_b(hContact, "CList", "Auth", 1); - } - - setString(hContact, TOX_SETTINGS_ID, toxId.c_str()); + setString(hContact, TOX_SETTINGS_ID, id.c_str()); + setByte(hContact, "Auth", 1); DBVARIANT dbv; if (!getTString(TOX_SETTINGS_GROUP, &dbv)) @@ -97,8 +98,12 @@ MCONTACT CToxProto::AddContact(const char *clientId, bool isTemporary) db_set_ts(hContact, "CList", "Group", dbv.ptszVal); db_free(&dbv); } - } + if (isTemporary) + { + db_set_b(hContact, "CList", "NotOnList", 1); + } + } return hContact; } @@ -109,13 +114,14 @@ void CToxProto::LoadContactList() { int32_t *friends = (int32_t*)mir_alloc(count * sizeof(int32_t)); tox_get_friendlist(tox, friends, count); + std::vector clientId(TOX_CLIENT_ID_SIZE); for (uint32_t i = 0; i < count; ++i) { tox_get_client_id(tox, friends[i], &clientId[0]); - std::string toxId = DataToHexString(clientId); + std::string id = DataToHexString(clientId); - MCONTACT hContact = AddContact(toxId.c_str()); + MCONTACT hContact = AddContact(id.c_str()); if (hContact) { int size = tox_get_name_size(tox, friends[i]); @@ -132,24 +138,15 @@ void CToxProto::LoadContactList() } } } -} - -void CToxProto::SearchByIdAsync(void* arg) -{ - std::string toxId = (char*)arg; - toxId.erase(toxId.begin() + TOX_CLIENT_ID_SIZE * 2, toxId.end()); - - MCONTACT hContact = FindContact(toxId.c_str()); - if (hContact) + else { - ShowNotification(TranslateT("Contact already in your contact list"), 0, hContact); - ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HWND)1, 0); - mir_free(arg); - return; + debugLogA("CToxProto::LoadContactList: your friend list is empty"); } +} +void CToxProto::SearchByIdAsync(void*) +{ ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HWND)1, 0); - mir_free(arg); } void CToxProto::SearchByNameAsync(void* arg) @@ -158,8 +155,8 @@ void CToxProto::SearchByNameAsync(void* arg) request.requestType = REQUEST_POST; request.szUrl = "https://toxme.se/api"; request.flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP; - - request.headers = (NETLIBHTTPHEADER*)mir_alloc(sizeof(NETLIBHTTPHEADER)*2); + + request.headers = (NETLIBHTTPHEADER*)mir_alloc(sizeof(NETLIBHTTPHEADER)* 2); request.headers[0].szName = "Content-Type"; request.headers[0].szValue = "text/plain; charset=utf-8"; request.headersCount = 1; diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp index bf1274e812..39824f1038 100644 --- a/protocols/Tox/src/tox_events.cpp +++ b/protocols/Tox/src/tox_events.cpp @@ -117,27 +117,24 @@ int CToxProto::OnSettingsChanged(void *obj, WPARAM hContact, LPARAM lParam) return 0; } -void CToxProto::OnFriendRequest(Tox *tox, const uint8_t *userId, const uint8_t *message, const uint16_t messageSize, void *arg) +void CToxProto::OnFriendRequest(Tox *tox, const uint8_t *address, const uint8_t *message, const uint16_t messageSize, void *arg) { CToxProto *proto = (CToxProto*)arg; - std::vector clientId(userId, userId + TOX_CLIENT_ID_SIZE); - std::string toxId = proto->DataToHexString(clientId); + // trim tox address to tox id + std::vector clientId(address, address + TOX_CLIENT_ID_SIZE); + std::string id = proto->DataToHexString(clientId); - proto->RaiseAuthRequestEvent(time(NULL), toxId.c_str(), (char*)message); + proto->RaiseAuthRequestEvent(time(NULL), id.c_str(), (char*)message); proto->SaveToxData(); } -void CToxProto::OnFriendMessage(Tox *tox, const int friendnumber, const uint8_t *message, const uint16_t messageSize, void *arg) +void CToxProto::OnFriendMessage(Tox *tox, const int number, const uint8_t *message, const uint16_t messageSize, void *arg) { CToxProto *proto = (CToxProto*)arg; - std::vector clientId(TOX_CLIENT_ID_SIZE); - tox_get_client_id(tox, friendnumber, &clientId[0]); - std::string toxId = proto->DataToHexString(clientId); - - MCONTACT hContact = proto->FindContact(toxId.c_str()); + MCONTACT hContact = proto->FindContact(number); if (hContact) { PROTORECVEVENT recv = { 0 }; @@ -149,45 +146,33 @@ void CToxProto::OnFriendMessage(Tox *tox, const int friendnumber, const uint8_t } } -void CToxProto::OnFriendTyping(Tox *tox, const int friendnumber, uint8_t isTyping, void *arg) +void CToxProto::OnTypingChanged(Tox *tox, const int number, uint8_t isTyping, void *arg) { CToxProto *proto = (CToxProto*)arg; - std::vector clientId(TOX_CLIENT_ID_SIZE); - tox_get_client_id(tox, friendnumber, &clientId[0]); - std::string toxId = proto->DataToHexString(clientId); - - MCONTACT hContact = proto->FindContact(toxId.c_str()); + MCONTACT hContact = proto->FindContact(number); if (hContact) { CallService(MS_PROTO_CONTACTISTYPING, hContact, (LPARAM)isTyping); } } -void CToxProto::OnFriendNameChange(Tox *tox, const int friendnumber, const uint8_t *name, const uint16_t nameSize, void *arg) +void CToxProto::OnFriendNameChange(Tox *tox, const int number, const uint8_t *name, const uint16_t nameSize, void *arg) { CToxProto *proto = (CToxProto*)arg; - std::vector clientId(TOX_CLIENT_ID_SIZE); - tox_get_client_id(tox, friendnumber, &clientId[0]); - std::string toxId = proto->DataToHexString(clientId); - - MCONTACT hContact = proto->FindContact(toxId.c_str()); + MCONTACT hContact = proto->FindContact(number); if (hContact) { proto->setString(hContact, "Nick", (char*)name); } } -void CToxProto::OnStatusMessageChanged(Tox *tox, const int friendnumber, const uint8_t* message, const uint16_t messageSize, void *arg) +void CToxProto::OnStatusMessageChanged(Tox *tox, const int number, const uint8_t* message, const uint16_t messageSize, void *arg) { CToxProto *proto = (CToxProto*)arg; - std::vector clientId(TOX_CLIENT_ID_SIZE); - tox_get_client_id(tox, friendnumber, &clientId[0]); - std::string toxId = proto->DataToHexString(clientId); - - MCONTACT hContact = proto->FindContact(toxId.c_str()); + MCONTACT hContact = proto->FindContact(number); if (hContact) { ptrW statusMessage(mir_utf8decodeW((char*)message)); @@ -195,15 +180,11 @@ void CToxProto::OnStatusMessageChanged(Tox *tox, const int friendnumber, const u } } -void CToxProto::OnUserStatusChanged(Tox *tox, int32_t friendnumber, uint8_t usertatus, void *arg) +void CToxProto::OnUserStatusChanged(Tox *tox, int32_t number, uint8_t usertatus, void *arg) { CToxProto *proto = (CToxProto*)arg; - std::vector clientId(TOX_CLIENT_ID_SIZE); - tox_get_client_id(tox, friendnumber, &clientId[0]); - std::string toxId = proto->DataToHexString(clientId); - - MCONTACT hContact = proto->FindContact(toxId.c_str()); + MCONTACT hContact = proto->FindContact(number); if (hContact) { TOX_USERSTATUS userstatus = (TOX_USERSTATUS)usertatus; @@ -212,15 +193,11 @@ void CToxProto::OnUserStatusChanged(Tox *tox, int32_t friendnumber, uint8_t user } } -void CToxProto::OnConnectionStatusChanged(Tox *tox, const int friendnumber, const uint8_t status, void *arg) +void CToxProto::OnConnectionStatusChanged(Tox *tox, const int number, const uint8_t status, void *arg) { CToxProto *proto = (CToxProto*)arg; - std::vector clientId(TOX_CLIENT_ID_SIZE); - tox_get_client_id(tox, friendnumber, &clientId[0]); - std::string toxId = proto->DataToHexString(clientId); - - MCONTACT hContact = proto->FindContact(toxId.c_str()); + MCONTACT hContact = proto->FindContact(number); if (hContact) { int newStatus = status ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE; @@ -228,24 +205,17 @@ void CToxProto::OnConnectionStatusChanged(Tox *tox, const int friendnumber, cons } } -void CToxProto::OnAction(Tox *tox, const int friendnumber, const uint8_t *message, const uint16_t messageSize, void *arg) -{ - -} - -void CToxProto::OnReadReceipt(Tox *tox, int32_t friendnumber, uint32_t receipt, void *arg) +void CToxProto::OnReadReceipt(Tox *tox, int32_t number, uint32_t receipt, void *arg) { CToxProto *proto = (CToxProto*)arg; - std::vector clientId(TOX_CLIENT_ID_SIZE); - tox_get_client_id(tox, friendnumber, &clientId[0]); - std::string toxId = proto->DataToHexString(clientId); - - MCONTACT hContact = proto->FindContact(toxId.c_str()); - - proto->ProtoBroadcastAck( - hContact, - ACKTYPE_MESSAGE, - ACKRESULT_SUCCESS, - (HANDLE)receipt, 0); + MCONTACT hContact = proto->FindContact(number); + if (hContact) + { + proto->ProtoBroadcastAck( + hContact, + ACKTYPE_MESSAGE, + ACKRESULT_SUCCESS, + (HANDLE)receipt, 0); + } } \ No newline at end of file diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index 69880a64b7..769679cdf8 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -58,18 +58,29 @@ DWORD_PTR __cdecl CToxProto::GetCaps(int type, MCONTACT hContact) MCONTACT __cdecl CToxProto::AddToList(int flags, PROTOSEARCHRESULT* psr) { - return AddContact(_T2A(psr->id), true); + std::string address(mir_t2a(psr->id)); + std::string id = ToxAddressToId(address); + std::string myId = ToxAddressToId(getStringA(TOX_SETTINGS_ID)); + if (myId.compare(id)) + { + debugLogA("CToxProto::AddToList: you cannot add yourself to friend list"); + return NULL; + } + // we set tox address as contact id + return AddContact(address, flags & PALF_TEMPORARY); } MCONTACT __cdecl CToxProto::AddToListByEvent(int flags, int iContact, HANDLE hDbEvent) { return 0; } int __cdecl CToxProto::Authorize(HANDLE hDbEvent) { - if (this->IsOnline() && hDbEvent) + if (IsOnline() && hDbEvent) { MCONTACT hContact = GetContactFromAuthEvent(hDbEvent); if (hContact == INVALID_CONTACT_ID) + { return 1; + } std::string toxId = getStringA(hContact, TOX_SETTINGS_ID); std::vector clientId = HexStringToData(toxId); @@ -90,8 +101,8 @@ int __cdecl CToxProto::AuthRecv(MCONTACT hContact, PROTORECVEVENT*) { return 0; int __cdecl CToxProto::AuthRequest(MCONTACT hContact, const PROTOCHAR* szMessage) { - std::string toxId = getStringA(hContact, TOX_SETTINGS_ID); - std::vector clientId = HexStringToData(toxId); + std::string address = getStringA(hContact, TOX_SETTINGS_ID); + std::vector clientId = HexStringToData(address); ptrA reason(mir_utf8encodeW(szMessage)); @@ -100,14 +111,12 @@ int __cdecl CToxProto::AuthRequest(MCONTACT hContact, const PROTOCHAR* szMessage { SaveToxData(); - clientId.resize(TOX_CLIENT_ID_SIZE); - tox_get_client_id(tox, friendnumber, &clientId[0]); - std::string toxId = DataToHexString(clientId); - - setString(hContact, TOX_SETTINGS_ID, toxId.c_str()); + // change tox address in contact id by tox id + std::string id = ToxAddressToId(address); + setString(hContact, TOX_SETTINGS_ID, id.c_str()); db_unset(hContact, "CList", "NotOnList"); - db_unset(hContact, "CList", "Auth"); + delSetting(hContact, "Auth"); std::vector username(TOX_MAX_NAME_LENGTH); tox_get_name(tox, friendnumber, &username[0]); @@ -137,6 +146,12 @@ HANDLE __cdecl CToxProto::SearchByName(const PROTOCHAR* nick, const PROTOCHAR* f HWND __cdecl CToxProto::SearchAdvanced(HWND owner) { + if (!IsOnline()) + { + // we cannot add someone to friend list while tox is offline + return NULL; + } + std::smatch match; std::regex regex("^\\s*([A-Fa-f0-9]{76})\\s*$"); @@ -146,33 +161,36 @@ HWND __cdecl CToxProto::SearchAdvanced(HWND owner) const std::string query = text; if (std::regex_search(query, match, regex)) { - std::string clientId = match[1]; - - ADDCONTACTSTRUCT acs = { 0 }; - - PROTOSEARCHRESULT psr = { 0 }; - psr.cbSize = sizeof(psr); - psr.flags = PSR_TCHAR; - psr.id = mir_a2t(query.c_str()); - - acs.psr = &psr; - acs.szProto = m_szModuleName; + std::string address = match[1]; + std::string id = ToxAddressToId(address); + MCONTACT hContact = FindContact(id); + if (!hContact) + { + PROTOSEARCHRESULT psr = { sizeof(psr) }; + psr.flags = PSR_TCHAR; + psr.id = mir_a2t(query.c_str()); - acs.handleType = HANDLE_SEARCHRESULT; - CallService(MS_ADDCONTACT_SHOW, (WPARAM)owner, (LPARAM)&acs); + ADDCONTACTSTRUCT acs = { HANDLE_SEARCHRESULT }; + acs.szProto = m_szModuleName; + acs.psr = &psr; + CallService(MS_ADDCONTACT_SHOW, (WPARAM)owner, (LPARAM)&acs); + } + else + { + ShowNotification(TranslateT("Contact already in your contact list"), 0, hContact); + } ForkThread(&CToxProto::SearchByIdAsync, mir_strdup(query.c_str())); } else { - regex = "^\\s*([A-Za-z]+)(@toxme.se)?\\s*$"; + regex = "^\\s*([^ @/:;()\"']+)(@toxme.se)?\\s*$"; if (std::regex_search(query, match, regex)) { std::string query = match[1]; ForkThread(&CToxProto::SearchByNameAsync, mir_strdup(query.c_str())); } } - return (HWND)1; } @@ -224,6 +242,8 @@ int __cdecl CToxProto::SetStatus(int iNewStatus) if (iNewStatus == m_iDesiredStatus) return 0; + debugLogA("CToxProto::SetStatus: changing status from %i to %i", m_iStatus, iNewStatus); + int old_status = m_iStatus; m_iDesiredStatus = iNewStatus; @@ -231,14 +251,13 @@ int __cdecl CToxProto::SetStatus(int iNewStatus) { // logout isTerminated = true; - isConnected = false; if (!Miranda_Terminated()) { SetAllContactsStatus(ID_STATUS_OFFLINE); } - m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; + m_iStatus = ID_STATUS_OFFLINE; } else { @@ -246,7 +265,7 @@ int __cdecl CToxProto::SetStatus(int iNewStatus) { m_iStatus = ID_STATUS_CONNECTING; - isTerminated = isConnected = false; + isTerminated = false; hPollingThread = ForkThreadEx(&CToxProto::PollingThread, 0, NULL); } else diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 243b4625af..1154f58a59 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -107,15 +107,14 @@ private: INT_PTR __cdecl OnAccountManagerInit(WPARAM, LPARAM); - static void OnFriendRequest(Tox *tox, const uint8_t *userId, const uint8_t *message, const uint16_t messageSize, void *arg); - static void OnFriendMessage(Tox *tox, const int friendnumber, const uint8_t *message, const uint16_t messageSize, void *arg); - static void OnFriendTyping(Tox *tox, const int friendnumber, uint8_t isTyping, void *arg); - static void OnFriendNameChange(Tox *tox, const int friendnumber, const uint8_t *name, const uint16_t nameSize, void *arg); - static void OnStatusMessageChanged(Tox *tox, const int friendnumber, const uint8_t* message, const uint16_t messageSize, void *arg); - static void OnUserStatusChanged(Tox *tox, int32_t friendnumber, uint8_t usertatus, void *arg); - static void OnConnectionStatusChanged(Tox *tox, const int friendnumber, const uint8_t status, void *arg); - static void OnAction(Tox *tox, const int friendnumber, const uint8_t *message, const uint16_t messageSize, void *arg); - static void OnReadReceipt(Tox *tox, int32_t friendnumber, uint32_t receipt, void *arg); + static void OnFriendRequest(Tox *tox, const uint8_t *address, const uint8_t *message, const uint16_t messageSize, void *arg); + static void OnFriendMessage(Tox *tox, const int number, const uint8_t *message, const uint16_t messageSize, void *arg); + static void OnTypingChanged(Tox *tox, const int number, uint8_t isTyping, void *arg); + static void OnFriendNameChange(Tox *tox, const int number, const uint8_t *name, const uint16_t nameSize, void *arg); + static void OnStatusMessageChanged(Tox *tox, const int number, const uint8_t* message, const uint16_t messageSize, void *arg); + static void OnUserStatusChanged(Tox *tox, int32_t number, uint8_t usertatus, void *arg); + static void OnConnectionStatusChanged(Tox *tox, const int number, const uint8_t status, void *arg); + static void OnReadReceipt(Tox *tox, int32_t number, uint32_t receipt, void *arg); // contacts WORD GetContactStatus(MCONTACT hContact); @@ -123,8 +122,9 @@ private: void SetContactStatus(MCONTACT hContact, WORD status); void SetAllContactsStatus(WORD status); bool IsProtoContact(MCONTACT hContact); - MCONTACT FindContact(const char *clientId); - MCONTACT AddContact(const char *clientId, bool isTemporary = false); + MCONTACT FindContact(const std::string &id); + MCONTACT FindContact(const int friendNumber); + MCONTACT AddContact(const std::string &id, bool isTemporary = false); MCONTACT GetContactFromAuthEvent(HANDLE hEvent); @@ -146,6 +146,8 @@ private: std::vector HexStringToData(std::string hex); std::string DataToHexString(std::vector); + std::string ToxAddressToId(std::string); + static bool IsFileExists(std::tstring path); std::tstring GetToxProfilePath(); diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp index 6745bedb71..5964177965 100644 --- a/protocols/Tox/src/tox_utils.cpp +++ b/protocols/Tox/src/tox_utils.cpp @@ -125,6 +125,15 @@ std::string CToxProto::DataToHexString(std::vector data) return oss.str(); } +std::string CToxProto::ToxAddressToId(std::string address) +{ + if (address.length() > TOX_CLIENT_ID_SIZE * 2) + { + address.erase(address.begin() + TOX_CLIENT_ID_SIZE * 2, address.end()); + } + return address; +} + bool CToxProto::IsFileExists(std::tstring path) { //return ::GetFileAttributes(fileName) != DWORD(-1) -- cgit v1.2.3