diff options
-rw-r--r-- | protocols/Tox/Tox_12.vcxproj | 3 | ||||
-rw-r--r-- | protocols/Tox/Tox_12.vcxproj.filters | 9 | ||||
-rw-r--r-- | protocols/Tox/docs/TOX_nodes.ini | 149 | ||||
-rw-r--r-- | protocols/Tox/src/common.h | 8 | ||||
-rw-r--r-- | protocols/Tox/src/tox_accounts.cpp | 23 | ||||
-rw-r--r-- | protocols/Tox/src/tox_core.cpp | 108 | ||||
-rw-r--r-- | protocols/Tox/src/tox_network.cpp | 117 | ||||
-rw-r--r-- | protocols/Tox/src/tox_options.cpp | 265 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.h | 33 | ||||
-rw-r--r-- | protocols/Tox/src/tox_transfer.cpp | 11 | ||||
-rw-r--r-- | protocols/Tox/src/tox_transfer.h | 2 |
11 files changed, 478 insertions, 250 deletions
diff --git a/protocols/Tox/Tox_12.vcxproj b/protocols/Tox/Tox_12.vcxproj index 8a824034c7..92496d50fa 100644 --- a/protocols/Tox/Tox_12.vcxproj +++ b/protocols/Tox/Tox_12.vcxproj @@ -220,12 +220,13 @@ <ClCompile Include="src\stdafx.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
- <ClCompile Include="src\tox_account.cpp" />
+ <ClCompile Include="src\tox_core.cpp" />
<ClCompile Include="src\tox_accounts.cpp" />
<ClCompile Include="src\tox_avatars.cpp" />
<ClCompile Include="src\tox_events.cpp" />
<ClCompile Include="src\tox_messages.cpp" />
<ClCompile Include="src\tox_netlib.cpp" />
+ <ClCompile Include="src\tox_network.cpp" />
<ClCompile Include="src\tox_options.cpp" />
<ClCompile Include="src\tox_profile.cpp" />
<ClCompile Include="src\tox_proto.cpp" />
diff --git a/protocols/Tox/Tox_12.vcxproj.filters b/protocols/Tox/Tox_12.vcxproj.filters index 2cf9a075dc..605ba7bc4f 100644 --- a/protocols/Tox/Tox_12.vcxproj.filters +++ b/protocols/Tox/Tox_12.vcxproj.filters @@ -68,9 +68,6 @@ <ClCompile Include="src\tox_utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\tox_account.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="src\tox_options.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -119,6 +116,12 @@ <ClCompile Include="src\api_transfer.cpp">
<Filter>Source Files\api</Filter>
</ClCompile>
+ <ClCompile Include="src\tox_network.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\tox_core.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\resource.rc">
diff --git a/protocols/Tox/docs/TOX_nodes.ini b/protocols/Tox/docs/TOX_nodes.ini index e93960b5e0..e856814943 100644 --- a/protocols/Tox/docs/TOX_nodes.ini +++ b/protocols/Tox/docs/TOX_nodes.ini @@ -2,83 +2,72 @@ SETTINGS: [TOX]
NodeCount=b20
-Node_1_IPv4=u192.254.75.102
-Node_1_IPv6=u2607:5600:284::2
-Node_1_ClientID=u951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F
-Node_1_Port=d33445
-Node_2_IPv4=u144.76.60.215
-Node_2_IPv6=u2a01:4f8:191:64d6::1
-Node_2_ClientID=u04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F
-Node_2_Port=d33445
-Node_3_IPv4=u23.226.230.47
-Node_3_IPv6=u2604:180:1::3ded:b280
-Node_3_ClientID=uA09162D68618E742FFBCA1C2C70385E6679604B2D80EA6E84AD0996A1AC8A074
-Node_3_Port=d33445
-Node_4_IPv4=u178.62.125.224
-Node_4_IPv6=u2a03:b0c0:1:d0::178:6001
-Node_4_ClientID=u10B20C49ACBD968D7C80F2E8438F92EA51F189F4E70CFBBB2C2C8C799E97F03E
-Node_4_Port=d33445
-Node_5_IPv4=u178.21.112.187
-Node_5_IPv6=u2a02:2308::216:3eff:fe82:eaef
-Node_5_ClientID=u4B2C19E924972CB9B57732FB172F8A8604DE13EEDA2A6234E348983344B23057
-Node_5_Port=d33445
-Node_6_IPv4=u195.154.119.113
-Node_6_IPv6=u2001:bc8:3698:101::1
-Node_6_ClientID=uE398A69646B8CEACA9F0B84F553726C1C49270558C57DF5F3C368F05A7D71354
-Node_6_Port=d33445
-Node_7_IPv4=u192.210.149.121
-Node_7_IPv6=u-
-Node_7_ClientID=uF404ABAA1C99A9D37D61AB54898F56793E1DEF8BD46B1038B9D822E8460FAB67
-Node_7_Port=d33445
-Node_8_IPv4=u104.219.184.206
-Node_8_IPv6=u-
-Node_8_ClientID=u8CD087E31C67568103E8C2A28653337E90E6B8EDA0D765D57C6B5172B4F1F04C
-Node_8_Port=d443
-Node_9_IPv4=u76.191.23.96
-Node_9_IPv6=u-
-Node_9_ClientID=u93574A3FAB7D612FEA29FD8D67D3DD10DFD07A075A5D62E8AF3DD9F5D0932E11
-Node_9_Port=d33445
-Node_10_IPv4=u46.38.239.179
-Node_10_IPv6=u-
-Node_10_ClientID=uF5A1A38EFB6BD3C2C8AF8B10D85F0F89E931704D349F1D0720C3C4059AF2440A
-Node_10_Port=d33445
-Node_11_IPv4=u178.62.250.138
-Node_11_IPv6=u2a03:b0c0:2:d0::16:1
-Node_11_ClientID=u788236D34978D1D5BD822F0A5BEBD2C53C64CC31CD3149350EE27D4D9A2F9B6B
-Node_11_Port=d33445
-Node_12_IPv4=u78.225.128.39
-Node_12_IPv6=u-
-Node_12_ClientID=u7A2306BFBA665E5480AE59B31E116BE9C04DCEFE04D9FE25082316FA34B4DA0C
-Node_12_Port=d33445
-Node_13_IPv4=u130.133.110.14
-Node_13_IPv6=u2001:6f8:1c3c:babe::14:1
-Node_13_ClientID=u461FA3776EF0FA655F1A05477DF1B3B614F7D6B124F7DB1DD4FE3C08B03B640F
-Node_13_Port=d33445
-Node_14_IPv4=u104.167.101.29
-Node_14_IPv6=u-
-Node_14_ClientID=u5918AC3C06955962A75AD7DF4F80A5D7C34F7DB9E1498D2E0495DE35B3FE8A57
-Node_14_Port=d33445
-Node_15_IPv4=u195.154.109.148
-Node_15_IPv6=u-
-Node_15_ClientID=u391C96CB67AE893D4782B8E4495EB9D89CF1031F48460C06075AA8CE76D50A21
-Node_15_Port=d33445
-Node_16_IPv4=u192.3.173.88
-Node_16_IPv6=u-
-Node_16_ClientID=u3E1FFDEB667BFF549F619EC6737834762124F50A89C8D0DBF1DDF64A2DD6CD1B
-Node_16_Port=d33445
-Node_17_IPv4=u205.185.116.116
-Node_17_IPv6=u-
-Node_17_ClientID=uA179B09749AC826FF01F37A9613F6B57118AE014D4196A0E1105A98F93A54702
-Node_17_Port=d33445
-Node_18_IPv4=u198.98.51.198
-Node_18_IPv6=u2605:6400:1:fed5:22:45af:ec10:f329
-Node_18_ClientID=u1D5A5F2F5D6233058BF0259B09622FB40B482E4FA0931EB8FD3AB8E7BF7DAF6F
-Node_18_Port=d33445
-Node_19_IPv4=u80.232.246.79
-Node_19_IPv6=u-
-Node_19_ClientID=u0B8DCEAA7BDDC44BB11173F987CAE3566A2D7057D8DD3CC642BD472B9391002A
-Node_19_Port=d33445
-Node_20_IPv4=u108.61.165.198
-Node_20_IPv6=u-
-Node_20_ClientID=u8E7D0B859922EF569298B4D261A8CCB5FEA14FB91ED412A7603A585A25698832
-Node_20_Port=d33445
+Node_1_IPv4=s192.254.75.102
+Node_1_IPv6=s2607:5600:284::2
+Node_1_PubKey=s951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F
+Node_1_Port=w33445
+Node_2_IPv4=s144.76.60.215
+Node_2_IPv6=s2a01:4f8:191:64d6::1
+Node_2_PubKey=s04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F
+Node_2_Port=w33445
+Node_3_IPv4=s23.226.230.47
+Node_3_IPv6=s2604:180:1::3ded:b280
+Node_3_PubKey=sA09162D68618E742FFBCA1C2C70385E6679604B2D80EA6E84AD0996A1AC8A074
+Node_3_Port=w33445
+Node_4_IPv4=s178.62.125.224
+Node_4_IPv6=s2a03:b0c0:1:d0::178:6001
+Node_4_PubKey=s10B20C49ACBD968D7C80F2E8438F92EA51F189F4E70CFBBB2C2C8C799E97F03E
+Node_4_Port=w33445
+Node_5_IPv4=s178.21.112.187
+Node_5_IPv6=s2a02:2308::216:3eff:fe82:eaef
+Node_5_PubKey=s4B2C19E924972CB9B57732FB172F8A8604DE13EEDA2A6234E348983344B23057
+Node_5_Port=w33445
+Node_6_IPv4=s195.154.119.113
+Node_6_IPv6=s2001:bc8:3698:101::1
+Node_6_PubKey=sE398A69646B8CEACA9F0B84F553726C1C49270558C57DF5F3C368F05A7D71354
+Node_6_Port=w33445
+Node_7_IPv4=s192.210.149.121
+Node_7_PubKey=sF404ABAA1C99A9D37D61AB54898F56793E1DEF8BD46B1038B9D822E8460FAB67
+Node_7_Port=w33445
+Node_8_IPv4=s104.219.184.206
+Node_8_PubKey=s8CD087E31C67568103E8C2A28653337E90E6B8EDA0D765D57C6B5172B4F1F04C
+Node_8_Port=w443
+Node_9_IPv4=s76.191.23.96
+Node_9_PubKey=s93574A3FAB7D612FEA29FD8D67D3DD10DFD07A075A5D62E8AF3DD9F5D0932E11
+Node_9_Port=w33445
+Node_10_IPv4=s46.38.239.179
+Node_10_PubKey=sF5A1A38EFB6BD3C2C8AF8B10D85F0F89E931704D349F1D0720C3C4059AF2440A
+Node_10_Port=w33445
+Node_11_IPv4=s178.62.250.138
+Node_11_IPv6=s2a03:b0c0:2:d0::16:1
+Node_11_PubKey=s788236D34978D1D5BD822F0A5BEBD2C53C64CC31CD3149350EE27D4D9A2F9B6B
+Node_11_Port=w33445
+Node_12_IPv4=s78.225.128.39
+Node_12_PubKey=s7A2306BFBA665E5480AE59B31E116BE9C04DCEFE04D9FE25082316FA34B4DA0C
+Node_12_Port=w33445
+Node_13_IPv4=s130.133.110.14
+Node_13_IPv6=s2001:6f8:1c3c:babe::14:1
+Node_13_PubKey=s461FA3776EF0FA655F1A05477DF1B3B614F7D6B124F7DB1DD4FE3C08B03B640F
+Node_13_Port=w33445
+Node_14_IPv4=s104.167.101.29
+Node_14_PubKey=s5918AC3C06955962A75AD7DF4F80A5D7C34F7DB9E1498D2E0495DE35B3FE8A57
+Node_14_Port=w33445
+Node_15_IPv4=s195.154.109.148
+Node_15_PubKey=s391C96CB67AE893D4782B8E4495EB9D89CF1031F48460C06075AA8CE76D50A21
+Node_15_Port=w33445
+Node_16_IPv4=s192.3.173.88
+Node_16_PubKey=s3E1FFDEB667BFF549F619EC6737834762124F50A89C8D0DBF1DDF64A2DD6CD1B
+Node_16_Port=w33445
+Node_17_IPv4=s205.185.116.116
+Node_17_PubKey=sA179B09749AC826FF01F37A9613F6B57118AE014D4196A0E1105A98F93A54702
+Node_17_Port=w33445
+Node_18_IPv4=s198.98.51.198
+Node_18_IPv6=s2605:6400:1:fed5:22:45af:ec10:f329
+Node_18_PubKey=s1D5A5F2F5D6233058BF0259B09622FB40B482E4FA0931EB8FD3AB8E7BF7DAF6F
+Node_18_Port=w33445
+Node_19_IPv4=s80.232.246.79
+Node_19_PubKey=s0B8DCEAA7BDDC44BB11173F987CAE3566A2D7057D8DD3CC642BD472B9391002A
+Node_19_Port=w33445
+Node_20_IPv4=s108.61.165.198
+Node_20_PubKey=s8E7D0B859922EF569298B4D261A8CCB5FEA14FB91ED412A7603A585A25698832
+Node_20_Port=w33445
diff --git a/protocols/Tox/src/common.h b/protocols/Tox/src/common.h index 24ff0df963..878f9e4d09 100644 --- a/protocols/Tox/src/common.h +++ b/protocols/Tox/src/common.h @@ -48,11 +48,19 @@ extern HINSTANCE g_hInstance; #define TOX_ERROR -1
+#define TOX_MAX_DISCONNECT_RETRIES 100
+
#define TOX_SETTINGS_ID "ToxID"
#define TOX_SETTINGS_DNS "DnsID"
#define TOX_SETTINGS_GROUP "DefaultGroup"
#define TOX_SETTINGS_AVATAR_HASH "AvatarHash"
+#define TOX_SETTINGS_NODE_IPV4 "Node_%d_IPv4"
+#define TOX_SETTINGS_NODE_IPV6 "Node_%d_IPv6"
+#define TOX_SETTINGS_NODE_PORT "Node_%d_Port"
+#define TOX_SETTINGS_NODE_PKEY "Node_%d_PubKey"
+#define TOX_SETTINGS_NODE_COUNT "NodeCount"
+
#define TOX_DB_EVENT_TYPE_ACTION 10001
#define TOX_FILE_BLOCK_SIZE 1024 * 1024
diff --git a/protocols/Tox/src/tox_accounts.cpp b/protocols/Tox/src/tox_accounts.cpp index afcac8e4a6..edefe94051 100644 --- a/protocols/Tox/src/tox_accounts.cpp +++ b/protocols/Tox/src/tox_accounts.cpp @@ -30,4 +30,27 @@ int CToxProto::UninitAccount(CToxProto *proto) delete proto;
return 0;
+}
+
+int CToxProto::OnAccountLoaded(WPARAM, LPARAM)
+{
+ HookProtoEvent(ME_OPT_INITIALISE, &CToxProto::OnOptionsInit);
+ HookProtoEvent(ME_USERINFO_INITIALISE, &CToxProto::OnUserInfoInit);
+ HookProtoEvent(ME_MSG_PRECREATEEVENT, &CToxProto::OnPreCreateMessage);
+
+ return 0;
+}
+
+int CToxProto::OnAccountRenamed(WPARAM, LPARAM lParam)
+{
+ PROTOACCOUNT *account = (PROTOACCOUNT*)lParam;
+
+ std::tstring newPath = GetToxProfilePath();
+ TCHAR oldPath[MAX_PATH];
+ mir_sntprintf(oldPath, MAX_PATH, _T("%s\\%s.tox"), VARST(_T("%miranda_userdata%")), accountName);
+ _trename(oldPath, newPath.c_str());
+ mir_free(accountName);
+ accountName = mir_tstrdup(m_tszUserName);
+
+ return 0;
}
\ No newline at end of file diff --git a/protocols/Tox/src/tox_core.cpp b/protocols/Tox/src/tox_core.cpp new file mode 100644 index 0000000000..7d97b875f0 --- /dev/null +++ b/protocols/Tox/src/tox_core.cpp @@ -0,0 +1,108 @@ +#include "common.h"
+
+bool CToxProto::InitToxCore()
+{
+ debugLogA("CToxProto::InitToxCore: initializing tox profile");
+
+ Tox_Options options = { 0 };
+ options.udp_disabled = getBool("DisableUDP", 0);
+ options.ipv6enabled = !getBool("DisableIPv6", 0);
+
+ if (hNetlib != NULL)
+ {
+ NETLIBUSERSETTINGS nlus = { sizeof(NETLIBUSERSETTINGS) };
+ CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM)hNetlib, (LPARAM)&nlus);
+
+ if (nlus.useProxy)
+ {
+ if (nlus.proxyType == PROXYTYPE_HTTP || nlus.proxyType == PROXYTYPE_HTTPS)
+ {
+ debugLogA("CToxProto::InitToxCore: setting http user proxy config");
+ options.proxy_type = TOX_PROXY_HTTP;
+ strcpy(&options.proxy_address[0], nlus.szProxyServer);
+ options.proxy_port = nlus.wProxyPort;
+ }
+
+ if (nlus.proxyType == PROXYTYPE_SOCKS4 || nlus.proxyType == PROXYTYPE_SOCKS5)
+ {
+ debugLogA("CToxProto::InitToxCore: setting socks user proxy config");
+ options.proxy_type = TOX_PROXY_SOCKS5;
+ strcpy(&options.proxy_address[0], nlus.szProxyServer);
+ options.proxy_port = nlus.wProxyPort;
+ }
+ }
+ }
+
+ tox = tox_new(&options);
+ password = mir_utf8encodeW(ptrT(getTStringA("Password")));
+ bool isProfileLoaded = LoadToxProfile();
+ if (isProfileLoaded)
+ {
+ tox_callback_friend_request(tox, OnFriendRequest, this);
+ tox_callback_friend_message(tox, OnFriendMessage, this);
+ tox_callback_friend_action(tox, OnFriendAction, 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);
+ tox_callback_read_receipt(tox, OnReadReceipt, this);
+ tox_callback_connection_status(tox, OnConnectionStatusChanged, this);
+ // file transfers
+ tox_callback_file_control(tox, OnFileRequest, this);
+ tox_callback_file_send_request(tox, OnFriendFile, this);
+ tox_callback_file_data(tox, OnFileData, this);
+ // avatars
+ tox_callback_avatar_info(tox, OnGotFriendAvatarInfo, this);
+ tox_callback_avatar_data(tox, OnGotFriendAvatarData, this);
+
+ uint8_t data[TOX_FRIEND_ADDRESS_SIZE];
+ tox_get_address(tox, data);
+ ToxHexAddress address(data, TOX_FRIEND_ADDRESS_SIZE);
+ setString(NULL, TOX_SETTINGS_ID, address);
+
+ int size = tox_get_self_name_size(tox);
+ std::string nick(size, 0);
+ tox_get_self_name(tox, (uint8_t*)nick.data());
+ setWString("Nick", ptrW(Utf8DecodeW(nick.c_str())));
+
+ std::tstring avatarPath = GetAvatarFilePath();
+ if (IsFileExists(avatarPath))
+ {
+ SetToxAvatar(avatarPath);
+ }
+ }
+ else
+ {
+ if (password != NULL)
+ {
+ mir_free(password);
+ password = NULL;
+ }
+ tox_kill(tox);
+ }
+
+ return isProfileLoaded;
+}
+
+void CToxProto::UninitToxCore()
+{
+ for (size_t i = 0; i < transfers->Count(); i++)
+ {
+ FileTransferParam *transfer = transfers->GetAt(i);
+ transfer->status = CANCELED;
+ tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_KILL, NULL, 0);
+ ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DENIED, (HANDLE)transfer, 0);
+ transfers->Remove(transfer);
+ }
+
+ ptrA nickname(mir_utf8encodeW(ptrT(getTStringA("Nick"))));
+ tox_set_name(tox, (uint8_t*)(char*)nickname, mir_strlen(nickname));
+
+ SaveToxProfile();
+ if (password != NULL)
+ {
+ mir_free(password);
+ password = NULL;
+ }
+ tox_kill(tox);
+}
\ No newline at end of file diff --git a/protocols/Tox/src/tox_network.cpp b/protocols/Tox/src/tox_network.cpp new file mode 100644 index 0000000000..834f438304 --- /dev/null +++ b/protocols/Tox/src/tox_network.cpp @@ -0,0 +1,117 @@ +#include "common.h"
+
+bool CToxProto::IsOnline()
+{
+ return isConnected && m_iStatus > ID_STATUS_OFFLINE;
+}
+
+void CToxProto::BootstrapNode(int index)
+{
+ bool isIPv4 = getBool("DisableIPv6", 0);
+ int nodeCount = db_get_w(NULL, "TOX", TOX_SETTINGS_NODE_COUNT, 0);
+ if (!nodeCount)
+ {
+ tox_bootstrap_from_address(
+ tox, isIPv4 ? "192.254.75.102" : "2607:5600:284::2", 33445,
+ ToxBinAddress("951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F"));
+ tox_bootstrap_from_address(
+ tox, "104.219.184.206", 443,
+ ToxBinAddress("8CD087E31C67568103E8C2A28653337E90E6B8EDA0D765D57C6B5172B4F1F04C"));
+ return;
+ }
+ int i = index % nodeCount;
+ char setting[MAX_PATH];
+ mir_snprintf(setting, SIZEOF(setting), isIPv4 ? TOX_SETTINGS_NODE_IPV4 : TOX_SETTINGS_NODE_IPV6, i);
+ ptrA address(db_get_sa(NULL, "TOX", setting));
+ if (address == NULL && !isIPv4)
+ {
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV4, i);
+ address = db_get_sa(NULL, "TOX", setting);
+ }
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PORT, i);
+ int port = db_get_w(NULL, "TOX", setting, 0);
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PKEY, i);
+ ptrA pubKey(db_get_sa(NULL, "TOX", setting));
+ tox_bootstrap_from_address(tox, address, port, ToxBinAddress(pubKey));
+}
+
+void CToxProto::TryConnect()
+{
+ if (tox_isconnected(tox))
+ {
+ isConnected = true;
+ debugLogA("CToxProto::PollingThread: successfuly connected to DHT");
+ m_iStatus = m_iDesiredStatus;
+ ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus);
+ tox_set_user_status(tox, MirandaToToxStatus(m_iStatus));
+ debugLogA("CToxProto::PollingThread: changing status from %i to %i", ID_STATUS_CONNECTING, m_iDesiredStatus);
+ }
+ else
+ {
+ BootstrapNode(m_iStatus);
+ if (m_iStatus++ > MAX_CONNECT_RETRIES)
+ {
+ SetStatus(ID_STATUS_OFFLINE);
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, (HANDLE)NULL, LOGINERR_NONETWORK);
+ debugLogA("CToxProto::PollingThread: failed to connect to DHT");
+ }
+ }
+}
+
+void CToxProto::CheckConnection(int &retriesCount)
+{
+ if (!isConnected)
+ {
+ TryConnect();
+ }
+ else
+ {
+ if (tox_isconnected(tox))
+ {
+ retriesCount = TOX_MAX_DISCONNECT_RETRIES;
+ }
+ else if (!(--retriesCount))
+ {
+ isConnected = false;
+ debugLogA("CToxProto::PollingThread: disconnected from DHT");
+ SetStatus(ID_STATUS_OFFLINE);
+ }
+ }
+}
+
+void CToxProto::DoTox()
+{
+ {
+ mir_cslock lock(toxLock);
+ tox_do(tox);
+ }
+ uint32_t interval = tox_do_interval(tox);
+ Sleep(interval);
+}
+
+void CToxProto::PollingThread(void*)
+{
+ debugLogA("CToxProto::PollingThread: entering");
+
+ if (!InitToxCore())
+ {
+ SetStatus(ID_STATUS_OFFLINE);
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, (HANDLE)NULL, LOGINERR_WRONGPASSWORD);
+ debugLogA("CToxProto::PollingThread: leaving");
+ return;
+ }
+
+ int retriesCount = TOX_MAX_DISCONNECT_RETRIES;
+ isConnected = false;
+
+ while (!isTerminated)
+ {
+ CheckConnection(retriesCount);
+ DoTox();
+ }
+
+ UninitToxCore();
+ isConnected = false;
+
+ debugLogA("CToxProto::PollingThread: leaving");
+}
\ No newline at end of file diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index 49b4ddb06a..518f87afde 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -121,78 +121,67 @@ INT_PTR CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l void CreateList(HWND hwndList)
{
- SendMessage(hwndList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
-
- LVCOLUMN lvc = { 0 };
- // Initialize the LVCOLUMN structure.
- // The mask specifies that the format, width, text, and
- // subitem members of the structure are valid.
+ LVCOLUMNA lvc = { 0 };
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvc.fmt = LVCFMT_LEFT;
lvc.iSubItem = 0;
- lvc.pszText = TranslateT("IPv4");
- lvc.cx = 100; // width of column in pixels
- ListView_InsertColumn(hwndList, 0, &lvc);
+ lvc.pszText = Translate("IPv4");
+ lvc.cx = 100;
+ SendMessage(hwndList, LVM_INSERTCOLUMNA, 0, (LPARAM)&lvc);
lvc.iSubItem = 1;
- lvc.pszText = TranslateT("IPv6");
- lvc.cx = 100; // width of column in pixels
- ListView_InsertColumn(hwndList, 1, &lvc);
+ lvc.pszText = Translate("IPv6");
+ lvc.cx = 100;
+ SendMessage(hwndList, LVM_INSERTCOLUMNA, 1, (LPARAM)&lvc);
lvc.iSubItem = 2;
- lvc.pszText = TranslateT("Port");
- lvc.cx = 100; // width of column in pixels
- ListView_InsertColumn(hwndList, 2, &lvc);
+ lvc.pszText = Translate("Port");
+ lvc.cx = 50;
+ SendMessage(hwndList, LVM_INSERTCOLUMNA, 2, (LPARAM)&lvc);
lvc.iSubItem = 3;
- lvc.pszText = TranslateT("Client ID");
- lvc.cx = 100; // width of column in pixels
- ListView_InsertColumn(hwndList, 3, &lvc);
+ lvc.pszText = Translate("Public key");
+ lvc.cx = 150;
+ SendMessage(hwndList, LVM_INSERTCOLUMNA, 3, (LPARAM)&lvc);
+
+ SendMessage(hwndList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
}
void UpdateList(HWND hwndList)
{
- LVITEM lvI = { 0 };
+ LVITEMA lvI = { 0 };
+ char setting[MAX_PATH];
- int NodeCount = db_get_b(NULL, "TOX", "NodeCount", 0);
-
- for (int i = 0; i < NodeCount; i++) {
+ int nodeCount = db_get_w(NULL, "TOX", TOX_SETTINGS_NODE_COUNT, 0);
+ for (int i = 0; i < nodeCount; i++)
+ {
UpdateListFlag = true;
lvI.mask = LVIF_TEXT;
+
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV4, i + 1);
+ lvI.pszText = db_get_sa(NULL, "TOX", setting);
lvI.iSubItem = 0;
- char buff[MAX_PATH];
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_IPv4", i + 1);
- TCHAR *ptszIPv4 = db_get_tsa(NULL, "TOX", buff);
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_IPv6", i + 1);
- TCHAR *ptszIPv6 = db_get_tsa(NULL, "TOX", buff);
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_ClientID", i + 1);
- TCHAR *ptszClientID = db_get_tsa(NULL, "TOX", buff);
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_Port", i + 1);
- DWORD PortNum = db_get_dw(NULL, "TOX", buff, 0);
- TCHAR ptszPort[10];
- _itot(PortNum, ptszPort, 10);
- if (ptszIPv4 && ptszIPv6 && ptszClientID && ptszPort) {
- lvI.pszText = ptszIPv4;
- lvI.iItem = i;
- ListView_InsertItem(hwndList, &lvI);
-
- lvI.iSubItem = 1;
- lvI.pszText = ptszIPv6;
- ListView_SetItem(hwndList, &lvI);
-
- lvI.iSubItem = 2;
- lvI.pszText = ptszPort;
- ListView_SetItem(hwndList, &lvI);
-
- lvI.iSubItem = 3;
- lvI.pszText = ptszClientID;
- ListView_SetItem(hwndList, &lvI);
-
- mir_free(ptszIPv4);
- mir_free(ptszIPv6);
- mir_free(ptszClientID);
- }
+ lvI.iItem = i;
+ SendMessage(hwndList, LVM_INSERTITEMA, 0, (LPARAM)&lvI);
+
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV6, i + 1);
+ lvI.iSubItem = 1;
+ lvI.pszText = db_get_sa(NULL, "TOX", setting);
+ SendMessage(hwndList, LVM_SETITEMA, 0, (LPARAM)&lvI);
+
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PORT, i + 1);
+ int port = db_get_w(NULL, "TOX", setting, 0);
+ char portNum[10];
+ _itoa(port, portNum, 10);
+ lvI.iSubItem = 2;
+ lvI.pszText = portNum;
+ SendMessage(hwndList, LVM_SETITEMA, 0, (LPARAM)&lvI);
+
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PKEY, i + 1);
+ lvI.iSubItem = 3;
+ lvI.pszText = db_get_sa(NULL, "TOX", setting);
+ SendMessage(hwndList, LVM_SETITEMA, 0, (LPARAM)&lvI);
}
UpdateListFlag = false;
}
@@ -215,43 +204,45 @@ INT_PTR CALLBACK AddNodeDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
- TCHAR str[MAX_PATH];
{
- if (!GetDlgItemText(hwndDlg, IDC_IPV4, str, SIZEOF(str))) {
+ char value[MAX_PATH];
+
+ if (!GetDlgItemTextA(hwndDlg, IDC_IPV4, value, SIZEOF(value))) {
MessageBox(hwndDlg, TranslateT("Enter IPv4"), TranslateT("Error"), MB_OK);
break;
}
- if (!GetDlgItemText(hwndDlg, IDC_IPV6, str, SIZEOF(str))) {
+ /*if (!GetDlgItemTextA(hwndDlg, IDC_IPV6, str, SIZEOF(str))) {
MessageBox(hwndDlg, TranslateT("Enter IPv6"), TranslateT("Error"), MB_OK);
break;
- }
+ }*/
if (!GetDlgItemInt(hwndDlg, IDC_PORT, NULL, false)) {
MessageBox(hwndDlg, TranslateT("Enter port"), TranslateT("Error"), MB_OK);
break;
}
- if (!GetDlgItemText(hwndDlg, IDC_CLIENTID, str, SIZEOF(str))) {
- MessageBox(hwndDlg, TranslateT("Enter client ID"), TranslateT("Error"), MB_OK);
+ if (!GetDlgItemTextA(hwndDlg, IDC_CLIENTID, value, SIZEOF(value))) {
+ MessageBox(hwndDlg, TranslateT("Enter public key"), TranslateT("Error"), MB_OK);
break;
}
- int NodeCount = db_get_b(NULL, "TOX", "NodeCount", 0);
- char buff[MAX_PATH];
- GetDlgItemText(hwndDlg, IDC_IPV4, str, SIZEOF(str));
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_IPv4", NodeCount + 1);
- db_set_ts(NULL, "TOX", buff, str);
+ char setting[MAX_PATH];
+ int nodeCount = db_get_b(NULL, "TOX", "NodeCount", 0);
- GetDlgItemText(hwndDlg, IDC_IPV6, str, SIZEOF(str));
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_IPv6", NodeCount + 1);
- db_set_ts(NULL, "TOX", buff, str);
+ GetDlgItemTextA(hwndDlg, IDC_IPV4, value, SIZEOF(value));
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV4, nodeCount + 1);
+ db_set_s(NULL, "TOX", setting, value);
- GetDlgItemText(hwndDlg, IDC_CLIENTID, str, SIZEOF(str));
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_ClientID", NodeCount + 1);
- db_set_ts(NULL, "TOX", buff, str);
+ GetDlgItemTextA(hwndDlg, IDC_IPV6, value, SIZEOF(value));
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV6, nodeCount + 1);
+ db_set_s(NULL, "TOX", setting, value);
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_Port", NodeCount + 1);
- db_set_dw(NULL, "TOX", buff, (DWORD)GetDlgItemInt(hwndDlg, IDC_PORT, NULL, false));
+ GetDlgItemTextA(hwndDlg, IDC_CLIENTID, value, SIZEOF(value));
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PKEY, nodeCount + 1);
+ db_set_s(NULL, "TOX", setting, value);
+
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PORT, nodeCount + 1);
+ db_set_w(NULL, "TOX", setting, (DWORD)GetDlgItemInt(hwndDlg, IDC_PORT, NULL, false));
- db_set_b(NULL, "TOX", "NodeCount", NodeCount + 1);
+ db_set_w(NULL, "TOX", TOX_SETTINGS_NODE_COUNT, nodeCount + 1);
HWND hwndList = (HWND)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
DeleteAllItems(hwndList);
@@ -289,30 +280,27 @@ INT_PTR CALLBACK ChangeNodeDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)nSelItem);
SetWindowText(hwndDlg, TranslateT("Change node"));
- char buff[MAX_PATH];
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_IPv4", SelItem.SelNumber + 1);
- ptrT dbIPv4(db_get_tsa(NULL, "TOX", buff));
- if (dbIPv4 == NULL)
+ char setting[MAX_PATH];
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV4, SelItem.SelNumber + 1);
+ ptrA addressIPv4(db_get_sa(NULL, "TOX", setting));
+ if (addressIPv4 == NULL)
break;
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_IPv6", SelItem.SelNumber + 1);
- ptrT dbIPv6(db_get_tsa(NULL, "TOX", buff));
- if (dbIPv6 == NULL)
- break;
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV6, SelItem.SelNumber + 1);
+ ptrA addressIPv6(db_get_sa(NULL, "TOX", setting));
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_ClientID", SelItem.SelNumber + 1);
- ptrT dbClientID(db_get_tsa(NULL, "TOX", buff));
- if (dbClientID == NULL)
- break;
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PORT, SelItem.SelNumber + 1);
+ int port = db_get_dw(NULL, "TOX", setting, 33445);
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_Port", SelItem.SelNumber + 1);
- DWORD Port = db_get_dw(NULL, "TOX", buff, 0);
- if (Port == 0)
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PKEY, SelItem.SelNumber + 1);
+ ptrA pubKey(db_get_sa(NULL, "TOX", setting));
+ if (pubKey == NULL)
break;
- SetDlgItemText(hwndDlg, IDC_IPV4, dbIPv4);
- SetDlgItemText(hwndDlg, IDC_IPV6, dbIPv6);
- SetDlgItemText(hwndDlg, IDC_CLIENTID, dbClientID);
- SetDlgItemInt(hwndDlg, IDC_PORT, Port, TRUE);
+
+ SetDlgItemTextA(hwndDlg, IDC_IPV4, addressIPv4);
+ SetDlgItemTextA(hwndDlg, IDC_IPV6, addressIPv6);
+ SetDlgItemInt(hwndDlg, IDC_PORT, port, TRUE);
+ SetDlgItemTextA(hwndDlg, IDC_CLIENTID, pubKey);
Utils_RestoreWindowPositionNoSize(hwndDlg, NULL, MODULE, "ChangeNodeDlg");
}
@@ -329,33 +317,33 @@ INT_PTR CALLBACK ChangeNodeDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM MessageBox(hwndDlg, TranslateT("Enter IPv4"), TranslateT("Error"), MB_OK);
break;
}
- if (!GetDlgItemText(hwndDlg, IDC_IPV6, str, SIZEOF(str))) {
+ /*if (!GetDlgItemText(hwndDlg, IDC_IPV6, str, SIZEOF(str))) {
MessageBox(hwndDlg, TranslateT("Enter IPv6"), TranslateT("Error"), MB_OK);
break;
- }
+ }*/
if (!GetDlgItemInt(hwndDlg, IDC_PORT, NULL, false)) {
MessageBox(hwndDlg, TranslateT("Enter port"), TranslateT("Error"), MB_OK);
break;
}
if (!GetDlgItemText(hwndDlg, IDC_CLIENTID, str, SIZEOF(str))) {
- MessageBox(hwndDlg, TranslateT("Enter client ID"), TranslateT("Error"), MB_OK);
+ MessageBox(hwndDlg, TranslateT("Enter public key"), TranslateT("Error"), MB_OK);
break;
}
char buff[MAX_PATH];
GetDlgItemText(hwndDlg, IDC_IPV4, str, SIZEOF(str));
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_IPv4", SelItem->SelNumber + 1);
+ mir_snprintf(buff, SIZEOF(buff), TOX_SETTINGS_NODE_IPV4, SelItem->SelNumber + 1);
db_set_ts(NULL, "TOX", buff, str);
GetDlgItemText(hwndDlg, IDC_IPV6, str, SIZEOF(str));
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_IPv6", SelItem->SelNumber + 1);
+ mir_snprintf(buff, SIZEOF(buff), TOX_SETTINGS_NODE_IPV6, SelItem->SelNumber + 1);
db_set_ts(NULL, "TOX", buff, str);
GetDlgItemText(hwndDlg, IDC_CLIENTID, str, SIZEOF(str));
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_ClientID", SelItem->SelNumber + 1);
+ mir_snprintf(buff, SIZEOF(buff), TOX_SETTINGS_NODE_PKEY, SelItem->SelNumber + 1);
db_set_ts(NULL, "TOX", buff, str);
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_Port", SelItem->SelNumber + 1);
+ mir_snprintf(buff, SIZEOF(buff), TOX_SETTINGS_NODE_PORT, SelItem->SelNumber + 1);
db_set_dw(NULL, "TOX", buff, (DWORD)GetDlgItemInt(hwndDlg, IDC_PORT, NULL, false));
DeleteAllItems(SelItem->hwndList);
@@ -414,50 +402,43 @@ INT_PTR CALLBACK ToxNodesOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR return FALSE;
case IDC_REMOVE:
- if (MessageBox(hwndDlg, TranslateT("Are you sure?"), TranslateT("Node deleting"), MB_YESNO | MB_ICONWARNING) == IDYES) {
+ if (MessageBox(hwndDlg, TranslateT("Are you sure?"), TranslateT("Node deleting"), MB_YESNO | MB_ICONWARNING) == IDYES)
+ {
+ char setting[MAX_PATH];
int sel = ListView_GetSelectionMark(hwndList);
- char buff[MAX_PATH];
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_IPv4", sel + 1);
- db_unset(NULL, "TOX", buff);
-
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_IPv6", sel + 1);
- db_unset(NULL, "TOX", buff);
-
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_ClientID", sel + 1);
- db_unset(NULL, "TOX", buff);
-
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_Port", sel + 1);
- db_unset(NULL, "TOX", buff);
-
- int NodeCount = db_get_b(NULL, "TOX", "NodeCount", 0);
-
- for (int i = sel + 1; i < NodeCount; i++) {
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_IPv4", i + 1);
- TCHAR *ptszIPv4 = db_get_tsa(NULL, "TOX", buff);
- db_unset(NULL, "TOX", buff);
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_IPv4", i);
- db_set_ts(NULL, "TOX", buff, ptszIPv4);
-
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_IPv6", i + 1);
- TCHAR *ptszIPv6 = db_get_tsa(NULL, "TOX", buff);
- db_unset(NULL, "TOX", buff);
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_IPv6", i);
- db_set_ts(NULL, "TOX", buff, ptszIPv6);
-
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_ClientID", i + 1);
- TCHAR *ptszClientID = db_get_tsa(NULL, "TOX", buff);
- db_unset(NULL, "TOX", buff);
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_ClientID", i);
- db_set_ts(NULL, "TOX", buff, ptszClientID);
-
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_Port", i + 1);
- DWORD Port = db_get_dw(NULL, "TOX", buff, 0);
- db_unset(NULL, "TOX", buff);
- mir_snprintf(buff, SIZEOF(buff), "Node_%d_Port", i);
- db_set_dw(NULL, "TOX", buff, Port);
+ int nodeCount = db_get_b(NULL, "TOX", "NodeCount", 0);
+ for (int i = sel + 1; i < nodeCount; i++)
+ {
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV4, i + 1);
+ ptrA addressIPv4(db_get_sa(NULL, "TOX", setting));
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV4, i);
+ db_set_s(NULL, "TOX", setting, addressIPv4);
+
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV6, i + 1);
+ ptrA addressIPv6(db_get_sa(NULL, "TOX", setting));
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV6, i);
+ db_set_s(NULL, "TOX", setting, addressIPv6);
+
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PORT, i + 1);
+ int port = db_get_w(NULL, "TOX", setting, 0);
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PORT, i);
+ db_set_w(NULL, "TOX", setting, port);
+
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PKEY, i + 1);
+ ptrA pubKey(db_get_sa(NULL, "TOX", setting));
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PKEY, i);
+ db_set_s(NULL, "TOX", setting, setting);
}
-
- db_set_b(NULL, "TOX", "NodeCount", NodeCount - 1);
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV4, nodeCount);
+ db_unset(NULL, "TOX", setting);
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV6, nodeCount);
+ db_unset(NULL, "TOX", setting);
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PORT, nodeCount);
+ db_unset(NULL, "TOX", setting);
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PKEY, nodeCount);
+ db_unset(NULL, "TOX", setting);
+
+ db_set_b(NULL, "TOX", TOX_SETTINGS_NODE_COUNT, nodeCount - 1);
ListView_DeleteItem(hwndList, sel);
}
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 03fdfa1a78..404b037350 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -72,39 +72,40 @@ private: bool isTerminated, isConnected;
CTransferList *transfers;
- // tox
- bool InitToxCore();
- void UninitToxCore();
-
- // ???
- void DoBootstrap();
- void DoTox();
-
- void __cdecl PollingThread(void*);
-
// tox profile
std::tstring GetToxProfilePath();
static std::tstring CToxProto::GetToxProfilePath(const TCHAR *accountName);
bool LoadToxProfile();
void SaveToxProfile();
-
+
static INT_PTR CALLBACK ToxProfileImportProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static INT_PTR CALLBACK ToxProfilePasswordProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+ // tox core
+ bool InitToxCore();
+ void UninitToxCore();
+
+ // tox network
+ bool IsOnline();
+ void BootstrapNode(int index);
+ void TryConnect();
+ void CheckConnection(int &retriesCount);
+ void DoTox();
+
+ void __cdecl PollingThread(void*);
+
// accounts
static LIST<CToxProto> accounts;
static int CompareAccounts(const CToxProto *p1, const CToxProto *p2);
+ int __cdecl OnAccountLoaded(WPARAM, LPARAM);
+ int __cdecl OnAccountRenamed(WPARAM, LPARAM);
+
// netlib
void InitNetlib();
void UninitNetlib();
- // account
- bool IsOnline();
- int __cdecl OnAccountLoaded(WPARAM, LPARAM);
- int __cdecl OnAccountRenamed(WPARAM, LPARAM);
-
// options
static INT_PTR CALLBACK MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int __cdecl OnOptionsInit(WPARAM wParam, LPARAM lParam);
diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp index be0159dcdc..16e6694b5f 100644 --- a/protocols/Tox/src/tox_transfer.cpp +++ b/protocols/Tox/src/tox_transfer.cpp @@ -50,7 +50,7 @@ HANDLE __cdecl CToxProto::FileAllow(MCONTACT hContact, HANDLE hTransfer, const P {
if (!transfer->OpenFile(_T("wb")))
{
- debugLogA("CToxProto::FileAllow: cannot to open file (%d)", transfer->fileNumber);
+ debugLogA("CToxProto::FileAllow: failed to open file (%d)", transfer->fileNumber);
transfer->status = FAILED;
tox_file_send_control(tox, transfer->friendNumber, transfer->GetDirection(), transfer->fileNumber, TOX_FILECONTROL_KILL, NULL, 0);
transfers->Remove(transfer);
@@ -79,20 +79,17 @@ int __cdecl CToxProto::FileResume(HANDLE hTransfer, int *action, const PROTOCHAR {
case FILERESUME_RENAME:
transfer->ChangeName(*szFilename);
+ case FILERESUME_OVERWRITE:
result = transfer->OpenFile(_T("wb"));
break;
- case FILERESUME_OVERWRITE:
- result = transfer->OpenFile(_T("wb"));
+ case FILERESUME_RESUME:
+ result = transfer->OpenFile(_T("ab"));
break;
case FILERESUME_SKIP:
result = false;
break;
-
- case FILERESUME_RESUME:
- result = transfer->OpenFile(_T("ab"));
- break;
}
if (result)
diff --git a/protocols/Tox/src/tox_transfer.h b/protocols/Tox/src/tox_transfer.h index a73b86bef6..643dc418f9 100644 --- a/protocols/Tox/src/tox_transfer.h +++ b/protocols/Tox/src/tox_transfer.h @@ -21,7 +21,7 @@ struct FileTransferParam int friendNumber;
int fileNumber;
- FileTransferParam(int friendNumber, int fileNumber, const TCHAR* fileName, uint64_t fileSize)
+ FileTransferParam(int friendNumber, int fileNumber, const TCHAR *fileName, uint64_t fileSize)
{
status = NONE;
hFile = NULL;
|