diff options
-rw-r--r-- | protocols/Tox/src/tox_account.cpp | 48 | ||||
-rw-r--r-- | protocols/Tox/src/tox_contacts.cpp | 3 | ||||
-rw-r--r-- | protocols/Tox/src/tox_events.cpp | 2 | ||||
-rw-r--r-- | protocols/Tox/src/tox_options.cpp | 12 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.cpp | 11 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.h | 7 | ||||
-rw-r--r-- | protocols/Tox/src/tox_utils.cpp | 30 |
7 files changed, 54 insertions, 59 deletions
diff --git a/protocols/Tox/src/tox_account.cpp b/protocols/Tox/src/tox_account.cpp index a517673398..b4871425d2 100644 --- a/protocols/Tox/src/tox_account.cpp +++ b/protocols/Tox/src/tox_account.cpp @@ -49,6 +49,8 @@ void CToxProto::InitToxCore() void CToxProto::UninitToxCore()
{
+ isTerminated = isConnected = false;
+
SaveToxData();
tox_kill(tox);
@@ -68,10 +70,8 @@ void CToxProto::DoBootstrap() void CToxProto::DoTox()
{
- uint32_t interval = 1000;
+ uint32_t interval = 50;
{
- //mir_cslock lock(tox_lock);
-
tox_do(tox);
interval = tox_do_interval(tox);
}
@@ -81,42 +81,30 @@ void CToxProto::DoTox() void CToxProto::PollingThread(void*)
{
debugLogA("CToxProto::PollingThread: entering");
-
+
while (!isTerminated)
{
DoTox();
- }
-
- debugLogA("CToxProto::PollingThread: leaving");
-}
-
-void CToxProto::ConnectionThread(void*)
-{
- debugLogA("CToxProto::ConnectionThread: entering");
-
- while (!isTerminated && !isConnected)
- {
- DoBootstrap();
- if (tox_isconnected(tox))
+ if (!isConnected)
{
- isConnected = true;
+ if (tox_isconnected(tox))
+ {
+ isConnected = true;
- LoadContactList();
+ LoadContactList();
- m_iStatus = m_iDesiredStatus = ID_STATUS_ONLINE;
- ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus);
+ m_iStatus = m_iDesiredStatus = ID_STATUS_ONLINE;
+ ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus);
- break;
+ debugLogA("CToxProto::PollingThread: successfuly connected to DHT");
+ }
+ else
+ {
+ DoBootstrap();
+ }
}
-
- DoTox();
}
- debugLogA("CToxProto::ConnectionThread: leaving");
-
- if (!isTerminated && isConnected)
- {
- poolingThread = ForkThreadEx(&CToxProto::PollingThread, 0, NULL);
- }
+ 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 fe02760f78..37a5cc1f11 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -111,6 +111,9 @@ void CToxProto::LoadContactList() tox_get_client_id(tox, friends[i], &clientId[0]);
std::string toxId = DataToHexString(clientId);
+ debugLogA("CToxProto::SendMsg: friend id is %s", toxId.c_str());
+ debugLogA("CToxProto::SendMsg: friend number is %d", friends[i]);
+
MCONTACT hContact = AddContact(toxId.c_str());
if (hContact)
{
diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp index 10f3c29701..84193c059e 100644 --- a/protocols/Tox/src/tox_events.cpp +++ b/protocols/Tox/src/tox_events.cpp @@ -81,6 +81,8 @@ void CToxProto::OnFriendMessage(Tox *tox, const int friendnumber, const uint8_t {
CToxProto *proto = (CToxProto*)arg;
+ proto->debugLogA("CToxProto::OnFriendMessage: friend number is %d", friendnumber);
+
std::vector<uint8_t> clientId(TOX_CLIENT_ID_SIZE);
tox_get_client_id(tox, friendnumber, &clientId[0]);
std::string toxId = proto->DataToHexString(clientId);
diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index 975a59a241..719d30cbc5 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -15,14 +15,8 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, ptrA username(proto->getStringA("Username"));
SetDlgItemTextA(hwnd, IDC_USERNAME, username);
- ptrA dataPath(proto->getStringA("DataPath"));
- if (!dataPath)
- {
- char defaultPath[MAX_PATH];
- mir_snprintf(defaultPath, MAX_PATH, "%s\\%s.tox", VARS("%miranda_userdata%"), _T2A(proto->m_tszUserName));
- dataPath = mir_strdup(defaultPath);
- }
- SetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath);
+ std::string toxProfilePath = proto->GetToxProfilePath();
+ SetDlgItemTextA(hwnd, IDC_DATAPATH, toxProfilePath.c_str());
ptrW groupName(proto->getTStringA(TOX_SETTINGS_GROUP));
SetDlgItemText(hwnd, IDC_GROUP, groupName);
@@ -80,7 +74,7 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, ofn.hwndOwner = 0;
ofn.lpstrFilter = filter;
ofn.nFilterIndex = 1;
- ofn.lpstrFile = dataPath;
+ ofn.lpstrFile = strrchr(dataPath, '\\') + 1;
ofn.lpstrTitle = Translate("Select data file");
ofn.nMaxFile = SIZEOF(dataPath);
ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR;
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index 12601b43da..91f6eca7cc 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -10,8 +10,6 @@ CToxProto::CToxProto(const char* protoName, const TCHAR* userName) : SetAllContactsStatus(ID_STATUS_OFFLINE);
- hMessageProcess = 1;
-
// icons
wchar_t filePath[MAX_PATH];
GetModuleFileName(g_hInstance, filePath, MAX_PATH);
@@ -170,8 +168,6 @@ int __cdecl CToxProto::SendMsg(MCONTACT hContact, int flags, const char* msg) uint32_t number = tox_get_friend_number(tox, clientId.data());
- //ULONG messageId = InterlockedIncrement(&hMessageProcess);
-
int result = tox_send_message(tox, number, (uint8_t*)msg, strlen(msg));
if (result == 0)
{
@@ -196,7 +192,7 @@ int __cdecl CToxProto::SetStatus(int iNewStatus) if (iNewStatus == ID_STATUS_OFFLINE)
{
// logout
- isTerminated = true;
+ isTerminated = isConnected = false;
m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
@@ -210,11 +206,12 @@ int __cdecl CToxProto::SetStatus(int iNewStatus) }
else
{
- if (old_status == ID_STATUS_OFFLINE/* && !this->IsOnline()*/)
+ if (old_status == ID_STATUS_OFFLINE && !IsOnline())
{
m_iStatus = ID_STATUS_CONNECTING;
- connectionThread = ForkThreadEx(&CToxProto::ConnectionThread, 0, NULL);
+ DoBootstrap();
+ hPollingThread = ForkThreadEx(&CToxProto::PollingThread, 0, NULL);
}
else
{
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index b19a5b9f74..537e001cdb 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -71,11 +71,9 @@ public: private:
Tox *tox;
mir_cs tox_lock;
- HANDLE connectionThread;
- HANDLE poolingThread;
+ HANDLE hPollingThread;
bool isTerminated;
bool isConnected;
- ULONG hMessageProcess;
HANDLE hNetlibUser;
// tox
@@ -96,7 +94,6 @@ private: void DoBootstrap();
void DoTox();
- void __cdecl ConnectionThread(void*);
void __cdecl PollingThread(void*);
//events
@@ -145,6 +142,8 @@ private: std::vector<uint8_t> HexStringToData(std::string hex);
std::string DataToHexString(std::vector<uint8_t>);
+ std::string GetToxProfilePath();
+
int LoadToxData();
int SaveToxData();
diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp index 9f47d67de1..71efde31d1 100644 --- a/protocols/Tox/src/tox_utils.cpp +++ b/protocols/Tox/src/tox_utils.cpp @@ -116,24 +116,36 @@ std::vector<uint8_t> CToxProto::HexStringToData(std::string hex) std::string CToxProto::DataToHexString(std::vector<uint8_t> data)
{
- std::stringstream ss;
- ss << std::hex << std::uppercase;
- for (uint32_t i = 0; i < data.size(); i++)
+ std::ostringstream oss;
+ oss << std::setfill('0');
+ for (int i = 0; i < data.size(); i++)
{
- ss << (int)data[i];
+ oss << std::setw(2) << std::hex << std::uppercase << static_cast<int>(data[i]);
}
- return ss.str();
+ return oss.str();
}
-int CToxProto::LoadToxData()
+std::string CToxProto::GetToxProfilePath()
{
+ std::string profilePath;
ptrA path(getStringA("DataPath"));
- if (!path)
+ if (path)
{
- return 0;
+ profilePath = path;
}
+ if (profilePath.empty())
+ {
+ char defaultPath[MAX_PATH];
+ mir_snprintf(defaultPath, MAX_PATH, "%s\\%s.tox", VARS("%miranda_userdata%"), _T2A(m_tszUserName));
+ profilePath = defaultPath;
+ }
+ return profilePath;
+}
- FILE *hFile = fopen(path, "rb");
+int CToxProto::LoadToxData()
+{
+ std::string toxProfilePath = GetToxProfilePath();
+ FILE *hFile = fopen(toxProfilePath.c_str(), "rb");
if (hFile)
{
|