summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_proto.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2014-08-10 14:20:09 +0000
committerAlexander Lantsev <aunsane@gmail.com>2014-08-10 14:20:09 +0000
commitb3a63d4e727b8552f8cf2b321cc68d2631ef3179 (patch)
treea533d09af6f41f06a383fb9b703dabc09d7b92d7 /protocols/Tox/src/tox_proto.cpp
parent254f7c0601c1972e016e0afb7989b27c9e432239 (diff)
Tox: refactoring
git-svn-id: http://svn.miranda-ng.org/main/trunk@10144 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox/src/tox_proto.cpp')
-rw-r--r--protocols/Tox/src/tox_proto.cpp95
1 files changed, 3 insertions, 92 deletions
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp
index b5bd446cb5..3123640ec2 100644
--- a/protocols/Tox/src/tox_proto.cpp
+++ b/protocols/Tox/src/tox_proto.cpp
@@ -1,44 +1,9 @@
#include "common.h"
-#define FRADDR_TOSTR_CHUNK_LEN 8
-
-static void fraddr_to_str(uint8_t *id_bin, char *id_str)
-{
- uint32_t i, delta = 0, pos_extra, sum_extra = 0;
-
- for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; i++) {
- sprintf(&id_str[2 * i + delta], "%02hhX", id_bin[i]);
-
- if ((i + 1) == TOX_CLIENT_ID_SIZE)
- pos_extra = 2 * (i + 1) + delta;
-
- if (i >= TOX_CLIENT_ID_SIZE)
- sum_extra |= id_bin[i];
-
- if (!((i + 1) % FRADDR_TOSTR_CHUNK_LEN)) {
- id_str[2 * (i + 1) + delta] = ' ';
- delta++;
- }
- }
-
- id_str[2 * i + delta] = 0;
-
- if (!sum_extra)
- id_str[pos_extra] = 0;
-}
-
-void get_id(Tox *m, char *data)
-{
- int offset = strlen(data);
- uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
- tox_get_address(m, address);
- fraddr_to_str(address, data + offset);
-}
-
CToxProto::CToxProto(const char* protoName, const TCHAR* userName) :
PROTO<CToxProto>(protoName, userName)
{
- tox = tox_new(1);
+ tox = tox_new(TOX_ENABLE_IPV6_DEFAULT);
tox_callback_friend_request(tox, OnFriendRequest, this);
tox_callback_friend_message(tox, OnFriendMessage, this);
@@ -48,9 +13,6 @@ CToxProto::CToxProto(const char* protoName, const TCHAR* userName) :
tox_callback_user_status(tox, OnUserStatusChanged, this);
tox_callback_connection_status(tox, OnConnectionStatusChanged, this);
- char idstring[200] = { 0 };
- get_id(tox, idstring);
-
CreateProtoService(PS_CREATEACCMGRUI, &CToxProto::CreateAccMgrUI);
}
@@ -152,63 +114,12 @@ int __cdecl CToxProto::SetStatus(int iNewStatus)
{
m_iStatus = ID_STATUS_CONNECTING;
- // login
- isTerminated = false;
- char *name = "my_nickname";
- int res = tox_set_name(tox, (uint8_t*)name, strlen(name));
-
- do_bootstrap(tox);
-
- time_t timestamp0 = time(NULL);
- int on = 0;
-
- while (1) {
- tox_do(tox);
-
- if (on == 0) {
- if (tox_isconnected(tox)) {
- on = 1;
- }
- else {
- time_t timestamp1 = time(NULL);
-
- if (timestamp0 + 10 < timestamp1) {
- timestamp0 = timestamp1;
- do_bootstrap(tox);
- }
- }
- }
- }
-
- res = tox_isconnected(tox);
- if (!res)
- {
- SetStatus(ID_STATUS_OFFLINE);
- return 0;
- }
-
- poolingThread = ForkThreadEx(&CToxProto::PollingThread, 0, NULL);
+ connectionThread = ForkThreadEx(&CToxProto::ConnectionThread, 0, NULL);
}
else
{
// set tox status
- TOX_USERSTATUS userstatus;
- switch (iNewStatus)
- {
- case ID_STATUS_ONLINE:
- userstatus = TOX_USERSTATUS_NONE;
- break;
- case ID_STATUS_AWAY:
- userstatus = TOX_USERSTATUS_AWAY;
- break;
- case ID_STATUS_OCCUPIED:
- userstatus = TOX_USERSTATUS_BUSY;
- break;
- default:
- userstatus = TOX_USERSTATUS_INVALID;
- break;
- }
- tox_set_user_status(tox, userstatus);
+ tox_set_user_status(tox, MirandaToToxStatus(iNewStatus));
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);