2013-07-30 06:00:56 +08:00
|
|
|
/* nTox_win32.c
|
|
|
|
*
|
|
|
|
* Textual frontend for Tox - Windows version
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Tox project All Rights Reserved.
|
|
|
|
*
|
|
|
|
* This file is part of Tox.
|
|
|
|
*
|
|
|
|
* Tox is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Tox is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
|
2013-08-06 08:20:41 +08:00
|
|
|
*
|
2013-07-30 06:00:56 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nTox_win32.h"
|
|
|
|
#include "misc_tools.h"
|
|
|
|
|
2013-07-30 08:27:48 +08:00
|
|
|
#include <process.h>
|
|
|
|
|
2013-08-04 19:01:20 +08:00
|
|
|
typedef struct {
|
|
|
|
uint8_t id[CLIENT_ID_SIZE];
|
|
|
|
uint8_t accepted;
|
|
|
|
} Friend_request;
|
|
|
|
|
|
|
|
Friend_request pending_requests[256];
|
2013-07-31 17:52:08 +08:00
|
|
|
uint8_t num_requests = 0;
|
2013-08-03 02:50:32 +08:00
|
|
|
uint32_t maxnumfriends;
|
2013-07-30 06:00:56 +08:00
|
|
|
|
|
|
|
char line[STRING_LENGTH];
|
2013-07-30 15:52:18 +08:00
|
|
|
char users_id[200];
|
2013-08-03 18:32:58 +08:00
|
|
|
int friend_request_received;
|
2013-07-30 06:00:56 +08:00
|
|
|
|
|
|
|
void do_header()
|
|
|
|
{
|
2013-07-30 15:52:18 +08:00
|
|
|
system("cls");
|
|
|
|
printf(users_id);
|
|
|
|
printf("\n---------------------------------");
|
2013-07-30 16:56:39 +08:00
|
|
|
printf("\n[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /l (lists friends), /d friendnumber (deletes friend), /q (to quit), /r (reset screen)");
|
2013-07-30 15:52:18 +08:00
|
|
|
printf("\n---------------------------------");
|
2013-07-30 06:00:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_request(uint8_t *public_key, uint8_t *data, uint16_t length)
|
|
|
|
{
|
2013-08-03 18:32:58 +08:00
|
|
|
friend_request_received = 1;
|
2013-07-30 15:52:18 +08:00
|
|
|
printf("\n\n[i] received friend request with message\n");
|
2013-08-03 18:32:58 +08:00
|
|
|
printf("'%s'",(char *)data);
|
2013-07-30 06:00:56 +08:00
|
|
|
char numchar[100];
|
2013-08-03 18:32:58 +08:00
|
|
|
sprintf(numchar, "\n[i] accept request with /a %u\n\n", num_requests);
|
2013-07-30 06:00:56 +08:00
|
|
|
printf(numchar);
|
2013-08-04 19:01:20 +08:00
|
|
|
memcpy(pending_requests[num_requests].id, public_key, CLIENT_ID_SIZE);
|
|
|
|
pending_requests[num_requests].accepted = 0;
|
2013-07-30 06:00:56 +08:00
|
|
|
++num_requests;
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_message(int friendnumber, uint8_t * string, uint16_t length)
|
|
|
|
{
|
|
|
|
char name[MAX_NAME_LENGTH];
|
|
|
|
getname(friendnumber, (uint8_t*)name);
|
|
|
|
char msg[100+length+strlen(name)+1];
|
|
|
|
time_t rawtime;
|
|
|
|
struct tm * timeinfo;
|
|
|
|
time (&rawtime);
|
|
|
|
timeinfo = localtime (&rawtime);
|
|
|
|
char* temp = asctime(timeinfo);
|
|
|
|
size_t len = strlen(temp);
|
|
|
|
temp[len-1]='\0';
|
2013-07-30 15:52:18 +08:00
|
|
|
sprintf(msg, "\n[%d] %s <%s> %s\n\n", friendnumber, temp, name, string); // timestamp
|
2013-07-30 06:00:56 +08:00
|
|
|
printf(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_nickchange(int friendnumber, uint8_t *string, uint16_t length)
|
|
|
|
{
|
|
|
|
char name[MAX_NAME_LENGTH];
|
|
|
|
getname(friendnumber, (uint8_t*)name);
|
|
|
|
char msg[100+length];
|
2013-07-30 15:52:18 +08:00
|
|
|
sprintf(msg, "\n\n[i] [%d] %s is now known as %s.\n\n", friendnumber, name, string);
|
2013-07-30 06:00:56 +08:00
|
|
|
printf(msg);
|
|
|
|
}
|
|
|
|
|
2013-08-07 04:06:17 +08:00
|
|
|
void print_statuschange(int friendnumber, uint8_t *string, uint16_t length)
|
2013-08-01 06:01:59 +08:00
|
|
|
{
|
2013-07-30 06:00:56 +08:00
|
|
|
char name[MAX_NAME_LENGTH];
|
|
|
|
getname(friendnumber, (uint8_t*)name);
|
|
|
|
char msg[100+length+strlen(name)+1];
|
2013-08-01 06:01:59 +08:00
|
|
|
sprintf(msg, "\n\n[i] [%d] %s's status changed to %s.\n\n", friendnumber, name, string);
|
2013-07-30 06:00:56 +08:00
|
|
|
printf(msg);
|
|
|
|
}
|
|
|
|
|
2013-08-06 08:20:41 +08:00
|
|
|
void load_key()
|
2013-07-30 06:00:56 +08:00
|
|
|
{
|
|
|
|
FILE *data_file = NULL;
|
2013-07-31 14:15:01 +08:00
|
|
|
data_file = fopen("data","r");
|
|
|
|
if (data_file) {
|
2013-07-30 06:00:56 +08:00
|
|
|
fseek(data_file, 0, SEEK_END);
|
|
|
|
int size = ftell(data_file);
|
|
|
|
fseek(data_file, 0, SEEK_SET);
|
|
|
|
uint8_t data[size];
|
2013-07-31 14:15:01 +08:00
|
|
|
if (fread(data, sizeof(uint8_t), size, data_file) != size) {
|
2013-07-30 06:00:56 +08:00
|
|
|
printf("\n[i] Could not read the data file. Exiting.");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Messenger_load(data, size);
|
|
|
|
} else {
|
|
|
|
int size = Messenger_size();
|
|
|
|
uint8_t data[size];
|
|
|
|
Messenger_save(data);
|
2013-08-03 04:56:53 +08:00
|
|
|
fclose(data_file);
|
2013-07-30 06:00:56 +08:00
|
|
|
data_file = fopen("data", "w");
|
|
|
|
|
2013-07-31 14:15:01 +08:00
|
|
|
if (fwrite(data, sizeof(uint8_t), size, data_file) != size) {
|
2013-07-30 06:00:56 +08:00
|
|
|
printf("\n[i] Could not write data to file. Exiting.");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(data_file);
|
|
|
|
}
|
|
|
|
|
2013-08-03 02:46:43 +08:00
|
|
|
void add_friend()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char temp_id[128];
|
|
|
|
|
2013-08-06 08:20:41 +08:00
|
|
|
for (i = 0; i < 128; i++)
|
2013-08-03 02:46:43 +08:00
|
|
|
temp_id[i] = line[i+3];
|
|
|
|
|
|
|
|
int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
|
|
|
|
|
|
|
|
if (num >= 0) {
|
|
|
|
char numstring[100];
|
|
|
|
sprintf(numstring, "\n[i] Friend request sent. Wait to be accepted. Friend id: %d\n\n", num);
|
|
|
|
printf(numstring);
|
|
|
|
++maxnumfriends;
|
|
|
|
}
|
2013-08-06 08:20:41 +08:00
|
|
|
else if (num == -1)
|
2013-08-03 04:36:52 +08:00
|
|
|
printf("\n[i] Message is too long.\n\n");
|
2013-08-03 02:46:43 +08:00
|
|
|
|
|
|
|
else if (num == -2)
|
2013-08-03 04:36:52 +08:00
|
|
|
printf("\n[i] Please add a message to your friend request.\n\n");
|
2013-08-03 02:46:43 +08:00
|
|
|
|
|
|
|
else if (num == -3)
|
2013-08-03 04:36:52 +08:00
|
|
|
printf("\n[i] That appears to be your own ID.\n\n");
|
2013-08-03 02:46:43 +08:00
|
|
|
|
|
|
|
else if (num == -4)
|
2013-08-03 04:36:52 +08:00
|
|
|
printf("\n[i] Friend request already sent.\n\n");
|
|
|
|
|
|
|
|
else if (num == -5)
|
|
|
|
printf("\n[i] Undefined error when adding friend\n\n");
|
2013-08-03 02:46:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void list_friends()
|
|
|
|
{
|
|
|
|
int i;
|
2013-08-03 21:14:33 +08:00
|
|
|
|
|
|
|
printf("\n[i] Friend List");
|
|
|
|
|
|
|
|
printf("----- PENDING -----\n\n");
|
2013-08-03 02:46:43 +08:00
|
|
|
|
|
|
|
for (i = 0; i <= maxnumfriends; i++) {
|
2013-08-03 21:14:33 +08:00
|
|
|
char name[MAX_NAME_LENGTH];
|
|
|
|
getname(i, (uint8_t*)name);
|
|
|
|
if (m_friendstatus(i) > 0 && m_friendstatus(i) < 4)
|
|
|
|
printf("[%d] %s\n", i, (uint8_t*)name);
|
2013-08-03 02:46:43 +08:00
|
|
|
}
|
2013-08-03 21:14:33 +08:00
|
|
|
|
|
|
|
printf("\n");
|
2013-08-03 02:46:43 +08:00
|
|
|
|
2013-08-03 21:14:33 +08:00
|
|
|
printf("----- ACTIVE -----\n\n");
|
2013-08-03 02:46:43 +08:00
|
|
|
|
2013-08-03 21:14:33 +08:00
|
|
|
for (i = 0; i <= maxnumfriends; i++) {
|
2013-08-03 02:46:43 +08:00
|
|
|
char name[MAX_NAME_LENGTH];
|
|
|
|
getname(i, (uint8_t*)name);
|
|
|
|
|
2013-08-06 08:20:41 +08:00
|
|
|
if (m_friendstatus(i) == 4)
|
2013-08-03 21:14:33 +08:00
|
|
|
printf("[%d] %s\n", i, (uint8_t*)name);
|
2013-08-03 02:46:43 +08:00
|
|
|
}
|
2013-08-03 21:14:33 +08:00
|
|
|
|
|
|
|
printf("\n");
|
2013-08-03 02:46:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void delete_friend()
|
|
|
|
{
|
|
|
|
size_t len = strlen(line);
|
|
|
|
char numstring[len-3];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if (line[i+3] != ' ')
|
|
|
|
numstring[i] = line[i+3];
|
|
|
|
}
|
|
|
|
|
|
|
|
int num = atoi(numstring);
|
|
|
|
m_delfriend(num);
|
|
|
|
--maxnumfriends;
|
|
|
|
printf("\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void message_friend()
|
|
|
|
{
|
|
|
|
size_t len = strlen(line);
|
|
|
|
char numstring[len-3];
|
|
|
|
char message[len-3];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
|
2013-08-06 08:20:41 +08:00
|
|
|
if (line[i+3] != ' ')
|
2013-08-03 02:46:43 +08:00
|
|
|
numstring[i] = line[i+3];
|
|
|
|
|
|
|
|
else {
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = (i+1); j < len; j++)
|
|
|
|
message[j-i-1] = line[j+3];
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int num = atoi(numstring);
|
|
|
|
|
|
|
|
if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1)
|
|
|
|
printf("\n[i] could not send message (they may be offline): %s\n", message);
|
|
|
|
|
|
|
|
else
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void change_nickname()
|
|
|
|
{
|
|
|
|
uint8_t name[MAX_NAME_LENGTH];
|
|
|
|
int i = 0;
|
|
|
|
size_t len = strlen(line);
|
|
|
|
|
|
|
|
for (i = 3; i < len; i++) {
|
|
|
|
|
2013-08-06 08:20:41 +08:00
|
|
|
if (line[i] == 0 || line[i] == '\n')
|
2013-08-03 02:46:43 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
name[i-3] = line[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
name[i-3] = 0;
|
|
|
|
setname(name, i);
|
|
|
|
char numstring[100];
|
|
|
|
sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name);
|
|
|
|
printf(numstring);
|
|
|
|
|
|
|
|
FILE *name_file = NULL;
|
|
|
|
name_file = fopen("namefile.txt", "w");
|
|
|
|
fprintf(name_file, "%s", (char*)name);
|
|
|
|
fclose(name_file);
|
|
|
|
}
|
|
|
|
|
2013-08-03 22:12:22 +08:00
|
|
|
void change_status(int savetofile)
|
2013-08-03 02:46:43 +08:00
|
|
|
{
|
|
|
|
uint8_t status[MAX_USERSTATUS_LENGTH];
|
|
|
|
int i = 0;
|
|
|
|
size_t len = strlen(line);
|
|
|
|
|
|
|
|
for (i = 3; i < len; i++) {
|
2013-08-06 08:20:41 +08:00
|
|
|
if (line[i] == 0 || line[i] == '\n')
|
2013-08-03 02:46:43 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
status[i-3] = line[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
status[i-3] = 0;
|
2013-08-07 15:43:05 +08:00
|
|
|
m_set_userstatus(USERSTATUS_KIND_RETAIN, status, strlen((char*)status));
|
2013-08-03 02:46:43 +08:00
|
|
|
char numstring[100];
|
|
|
|
sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status);
|
|
|
|
printf(numstring);
|
|
|
|
|
2013-08-03 22:12:22 +08:00
|
|
|
if (savetofile == 1) {
|
|
|
|
FILE* status_file = NULL;
|
|
|
|
status_file = fopen("statusfile.txt", "w");
|
|
|
|
fprintf(status_file, "%s", (char*)status);
|
|
|
|
fclose(status_file);
|
|
|
|
}
|
2013-08-03 02:46:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void accept_friend_request()
|
|
|
|
{
|
2013-08-03 18:32:58 +08:00
|
|
|
friend_request_received = 0;
|
2013-08-03 02:46:43 +08:00
|
|
|
uint8_t numf = atoi(line + 3);
|
|
|
|
char numchar[100];
|
2013-08-04 19:01:20 +08:00
|
|
|
if (numf >= num_requests || pending_requests[numf].accepted) {
|
|
|
|
sprintf(numchar, "\n[i] you either didn't receive that request or you already accepted it");
|
|
|
|
printf(numchar);
|
|
|
|
} else {
|
|
|
|
int num = m_addfriend_norequest(pending_requests[numf].id);
|
|
|
|
if (num != -1) {
|
|
|
|
pending_requests[numf].accepted = 1;
|
|
|
|
sprintf(numchar, "\n[i] Added friendnumber: %d\n\n", num);
|
|
|
|
printf(numchar);
|
|
|
|
++maxnumfriends;
|
|
|
|
} else {
|
|
|
|
sprintf(numchar, "[i] failed to add friend");
|
|
|
|
printf(numchar);
|
|
|
|
}
|
|
|
|
}
|
2013-08-03 02:46:43 +08:00
|
|
|
}
|
|
|
|
|
2013-07-30 06:00:56 +08:00
|
|
|
void line_eval(char* line)
|
|
|
|
{
|
|
|
|
if(line[0] == '/') {
|
2013-08-03 02:46:43 +08:00
|
|
|
|
2013-07-31 14:15:01 +08:00
|
|
|
char inpt_command = line[1];
|
2013-08-03 02:46:43 +08:00
|
|
|
|
2013-07-31 14:15:01 +08:00
|
|
|
if(inpt_command == 'f') {
|
2013-08-03 22:12:22 +08:00
|
|
|
add_friend();
|
2013-07-30 06:00:56 +08:00
|
|
|
}
|
|
|
|
|
2013-07-31 14:15:01 +08:00
|
|
|
else if (inpt_command == 'r') {
|
2013-07-30 15:52:18 +08:00
|
|
|
do_header();
|
|
|
|
printf("\n\n");
|
|
|
|
}
|
|
|
|
|
2013-07-31 14:15:01 +08:00
|
|
|
else if (inpt_command == 'l') {
|
2013-08-03 22:12:22 +08:00
|
|
|
list_friends();
|
2013-07-30 15:52:18 +08:00
|
|
|
}
|
|
|
|
|
2013-07-31 14:15:01 +08:00
|
|
|
else if (inpt_command == 'd') {
|
2013-08-03 22:12:22 +08:00
|
|
|
delete_friend();
|
2013-07-30 06:00:56 +08:00
|
|
|
}
|
|
|
|
/* Send message to friend */
|
2013-07-31 14:15:01 +08:00
|
|
|
else if (inpt_command == 'm') {
|
2013-08-03 22:12:22 +08:00
|
|
|
message_friend();
|
2013-07-30 06:00:56 +08:00
|
|
|
}
|
|
|
|
|
2013-07-31 14:15:01 +08:00
|
|
|
else if (inpt_command == 'n') {
|
2013-08-03 22:12:22 +08:00
|
|
|
change_nickname();
|
2013-07-30 06:00:56 +08:00
|
|
|
}
|
|
|
|
|
2013-07-31 14:15:01 +08:00
|
|
|
else if (inpt_command == 's') {
|
2013-08-03 22:12:22 +08:00
|
|
|
change_status(1);
|
2013-07-30 06:00:56 +08:00
|
|
|
}
|
|
|
|
|
2013-07-31 14:15:01 +08:00
|
|
|
else if (inpt_command == 'a') {
|
2013-08-03 18:32:58 +08:00
|
|
|
if (friend_request_received == 1)
|
|
|
|
accept_friend_request(line);
|
2013-07-30 06:00:56 +08:00
|
|
|
}
|
|
|
|
/* EXIT */
|
2013-08-06 08:20:41 +08:00
|
|
|
else if (inpt_command == 'q') {
|
2013-08-03 22:12:22 +08:00
|
|
|
strcpy(line, "---Offline");
|
|
|
|
change_status(0);
|
2013-07-30 06:00:56 +08:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-30 08:27:48 +08:00
|
|
|
void get_input()
|
|
|
|
{
|
|
|
|
while(1) {
|
|
|
|
fgets(line, STRING_LENGTH, stdin);
|
|
|
|
line_eval(line);
|
|
|
|
strcpy(line, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-30 06:00:56 +08:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
if (argc < 4) {
|
|
|
|
printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
if (initMessenger() == -1) {
|
|
|
|
printf("initMessenger failed");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
if (argc > 4) {
|
|
|
|
if(strncmp(argv[4], "nokey", 6) < 0) {
|
|
|
|
}
|
2013-07-30 15:52:18 +08:00
|
|
|
} else {
|
|
|
|
load_key();
|
2013-07-30 06:00:56 +08:00
|
|
|
}
|
2013-08-01 08:14:02 +08:00
|
|
|
|
|
|
|
int nameloaded = 0;
|
|
|
|
int statusloaded = 0;
|
|
|
|
|
|
|
|
FILE* name_file = NULL;
|
|
|
|
name_file = fopen("namefile.txt", "r");
|
|
|
|
if(name_file) {
|
|
|
|
uint8_t name[MAX_NAME_LENGTH];
|
|
|
|
while (fgets(line, MAX_NAME_LENGTH, name_file) != NULL) {
|
|
|
|
sscanf(line, "%s", (char*)name);
|
|
|
|
}
|
|
|
|
setname(name, strlen((char*)name)+1);
|
|
|
|
nameloaded = 1;
|
|
|
|
printf("%s\n", name);
|
2013-08-03 04:56:53 +08:00
|
|
|
fclose(name_file);
|
2013-08-06 08:20:41 +08:00
|
|
|
}
|
2013-08-01 08:14:02 +08:00
|
|
|
|
|
|
|
FILE* status_file = NULL;
|
|
|
|
status_file = fopen("statusfile.txt", "r");
|
|
|
|
if(status_file) {
|
|
|
|
uint8_t status[MAX_USERSTATUS_LENGTH];
|
|
|
|
while (fgets(line, MAX_USERSTATUS_LENGTH, status_file) != NULL) {
|
|
|
|
sscanf(line, "%s", (char*)status);
|
|
|
|
}
|
2013-08-07 15:43:05 +08:00
|
|
|
m_set_userstatus(USERSTATUS_KIND_RETAIN, status, strlen((char*)status)+1);
|
2013-08-01 08:14:02 +08:00
|
|
|
statusloaded = 1;
|
|
|
|
printf("%s\n", status);
|
2013-08-03 04:56:53 +08:00
|
|
|
fclose(status_file);
|
2013-08-01 08:14:02 +08:00
|
|
|
}
|
|
|
|
|
2013-07-30 06:00:56 +08:00
|
|
|
m_callback_friendrequest(print_request);
|
|
|
|
m_callback_friendmessage(print_message);
|
|
|
|
m_callback_namechange(print_nickchange);
|
|
|
|
m_callback_userstatus(print_statuschange);
|
2013-07-31 14:15:01 +08:00
|
|
|
char idstring1[PUB_KEY_BYTES][5];
|
|
|
|
char idstring2[PUB_KEY_BYTES][5];
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < PUB_KEY_BYTES; i++)
|
2013-07-30 06:00:56 +08:00
|
|
|
{
|
2013-07-31 14:15:01 +08:00
|
|
|
if(self_public_key[i] < (PUB_KEY_BYTES/2))
|
2013-07-30 06:00:56 +08:00
|
|
|
strcpy(idstring1[i],"0");
|
2013-08-06 08:20:41 +08:00
|
|
|
else
|
2013-07-30 06:00:56 +08:00
|
|
|
strcpy(idstring1[i], "");
|
|
|
|
sprintf(idstring2[i], "%hhX",self_public_key[i]);
|
|
|
|
}
|
2013-07-30 15:52:18 +08:00
|
|
|
strcpy(users_id,"[i] your ID: ");
|
2013-07-31 14:15:01 +08:00
|
|
|
int j;
|
|
|
|
for (j = 0; j < PUB_KEY_BYTES; j++) {
|
|
|
|
strcat(users_id,idstring1[j]);
|
|
|
|
strcat(users_id,idstring2[j]);
|
2013-07-30 06:00:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
do_header();
|
2013-08-01 08:14:02 +08:00
|
|
|
|
2013-07-30 06:00:56 +08:00
|
|
|
IP_Port bootstrap_ip_port;
|
|
|
|
bootstrap_ip_port.port = htons(atoi(argv[2]));
|
|
|
|
int resolved_address = resolve_addr(argv[1]);
|
2013-08-02 02:52:13 +08:00
|
|
|
if (resolved_address != 0)
|
2013-07-30 06:00:56 +08:00
|
|
|
bootstrap_ip_port.ip.i = resolved_address;
|
2013-08-06 08:20:41 +08:00
|
|
|
else
|
2013-07-30 06:00:56 +08:00
|
|
|
exit(1);
|
|
|
|
|
|
|
|
DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
|
2013-08-01 08:14:02 +08:00
|
|
|
|
2013-07-30 06:00:56 +08:00
|
|
|
int c;
|
|
|
|
int on = 0;
|
2013-08-01 08:14:02 +08:00
|
|
|
|
2013-07-30 08:27:48 +08:00
|
|
|
_beginthread(get_input, 0, NULL);
|
2013-08-01 08:14:02 +08:00
|
|
|
|
|
|
|
if (nameloaded == 1) {
|
|
|
|
printf("\nNickname automatically loaded");
|
|
|
|
printf("\n---------------------------------");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (statusloaded == 1) {
|
|
|
|
printf("\nStatus automatically loaded");
|
|
|
|
printf("\n---------------------------------");
|
|
|
|
}
|
|
|
|
|
2013-07-30 06:00:56 +08:00
|
|
|
while(1) {
|
2013-07-30 15:52:18 +08:00
|
|
|
if (on == 1 && DHT_isconnected() == -1) {
|
|
|
|
printf("\n---------------------------------");
|
|
|
|
printf("\n[i] Disconnected from the DHT");
|
|
|
|
printf("\n---------------------------------\n\n");
|
|
|
|
on = 0;
|
|
|
|
}
|
2013-07-30 06:00:56 +08:00
|
|
|
if (on == 0 && DHT_isconnected()) {
|
2013-07-30 15:52:18 +08:00
|
|
|
printf("\n[i] Connected to DHT");
|
|
|
|
printf("\n---------------------------------\n\n");
|
2013-07-30 06:00:56 +08:00
|
|
|
on = 1;
|
|
|
|
}
|
|
|
|
doMessenger();
|
2013-07-31 11:32:18 +08:00
|
|
|
Sleep(1);
|
2013-07-30 06:00:56 +08:00
|
|
|
}
|
|
|
|
return 0;
|
2013-08-02 02:52:13 +08:00
|
|
|
}
|