From ce49c84f3a26f016f9232d2bffdc830d7fd6169f Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sat, 30 Aug 2014 11:37:47 +0000 Subject: Tox: - switch to offline when connection is lost - file transfer support - code refactoring - project reordering - version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@10340 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_account.cpp | 45 +++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 14 deletions(-) (limited to 'protocols/Tox/src/tox_account.cpp') diff --git a/protocols/Tox/src/tox_account.cpp b/protocols/Tox/src/tox_account.cpp index 886bf70f7b..3648bb4dbf 100644 --- a/protocols/Tox/src/tox_account.cpp +++ b/protocols/Tox/src/tox_account.cpp @@ -1,16 +1,33 @@ #include "common.h" #include "tox_bootstrap.h" +bool CToxProto::IsOnline() +{ + return isConnected && m_iStatus > ID_STATUS_OFFLINE; +} + +int CToxProto::OnAccountLoaded(WPARAM, LPARAM) +{ + HookProtoEvent(ME_OPT_INITIALISE, &CToxProto::OnOptionsInit); + HookProtoEvent(ME_PROTO_ACCLISTCHANGED, &CToxProto::OnAccountListChanged); + HookProtoEvent(ME_DB_CONTACT_SETTINGCHANGED, &CToxProto::OnSettingsChanged); + HookProtoEvent(ME_MSG_PRECREATEEVENT, &CToxProto::OnPreCreateMessage); + + InitNetlib(); + + return 0; +} + void CToxProto::InitToxCore() { Tox_Options options = { 0 }; options.udp_disabled = getByte("DisableUDP", 0); options.ipv6enabled = !getByte("DisableIPv6", 0); - if (hNetlibUser) + if (hNetlib) { NETLIBUSERSETTINGS nlus = { sizeof(NETLIBUSERSETTINGS) }; - CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM)hNetlibUser, (LPARAM)&nlus); + CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM)hNetlib, (LPARAM)&nlus); if (nlus.useProxy) { @@ -58,11 +75,6 @@ void CToxProto::UninitToxCore() tox_kill(tox); } -bool CToxProto::IsOnline() -{ - return isConnected && m_iStatus > ID_STATUS_OFFLINE; -} - void CToxProto::DoBootstrap() { static int j = 0; @@ -77,13 +89,10 @@ void CToxProto::DoBootstrap() void CToxProto::DoTox() { - uint32_t interval = 50; - { - mir_cs(tox_lock); + mir_cslock((CRITICAL_SECTION&)toxLock); - tox_do(tox); - interval = tox_do_interval(tox); - } + tox_do(tox); + uint32_t interval = tox_do_interval(tox); Sleep(interval); } @@ -105,7 +114,7 @@ void CToxProto::PollingThread(void*) isConnected = true; debugLogA("CToxProto::PollingThread: successfuly connected to DHT"); - LoadContactList(); + LoadFriendList(); debugLogA("CToxProto::PollingThread: changing status from %i to %i", ID_STATUS_CONNECTING, m_iDesiredStatus); m_iStatus = m_iDesiredStatus; @@ -116,6 +125,14 @@ void CToxProto::PollingThread(void*) DoBootstrap(); } } + else + { + if (!tox_isconnected(tox)) + { + debugLogA("CToxProto::PollingThread: disconnected from DHT"); + SetStatus(ID_STATUS_OFFLINE); + } + } } isConnected = false; -- cgit v1.2.3