Merge branch 'master' of https://github.com/JFreegman/ProjectTox-Core into JFreegman-master

Conflicts:
	testing/nTox.c
This commit is contained in:
irungentoo 2013-07-31 10:25:29 -04:00
commit bdd13d1954
4 changed files with 125 additions and 128 deletions

View File

@ -23,9 +23,9 @@
#include "nTox.h" #include "nTox.h"
#include "misc_tools.h" #include "misc_tools.h"
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#ifdef WIN32 #ifdef WIN32
#define c_sleep(x) Sleep(1*x) #define c_sleep(x) Sleep(1*x)
#else #else
@ -35,20 +35,22 @@
char lines[HISTORY][STRING_LENGTH]; char lines[HISTORY][STRING_LENGTH];
char line[STRING_LENGTH]; char line[STRING_LENGTH];
char *help = "[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)\n" char *help = "[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)\n"
"[i] /l list (list friends), /h for help, /i for info, /n nick (to change nickname), /q (to quit)"; "[i] /l list (list friends), /h for help, /i for info, /n nick (to change nickname), /q (to quit)";
int x,y; int x, y;
uint8_t pending_requests[256][CLIENT_ID_SIZE]; uint8_t pending_requests[256][CLIENT_ID_SIZE];
uint8_t num_requests; uint8_t num_requests = 0;
void new_lines(char *line) void new_lines(char *line)
{ {
int i; int i;
for (i = HISTORY-1; i > 0; i--) for (i = HISTORY-1; i > 0; i--)
strcpy(lines[i],lines[i-1]); strcpy(lines[i], lines[i-1]);
strcpy(lines[0],line); strcpy(lines[0], line);
do_refresh(); do_refresh();
} }
@ -56,10 +58,10 @@ void new_lines(char *line)
void print_friendlist() void print_friendlist()
{ {
char name[MAX_NAME_LENGTH]; char name[MAX_NAME_LENGTH];
uint32_t i;
new_lines("[i] Friend List:"); new_lines("[i] Friend List:");
for (i=0; i <= num_requests; i++) { uint32_t i;
for (i = 0; i <= num_requests; i++) {
printf ("num_resusts: %d\n", num_requests);
char fstring[128]; char fstring[128];
getname(i, (uint8_t*)name); getname(i, (uint8_t*)name);
@ -75,19 +77,20 @@ void print_friendlist()
char *format_message(char *message, int friendnum) char *format_message(char *message, int friendnum)
{ {
char name[MAX_NAME_LENGTH]; char name[MAX_NAME_LENGTH];
if(friendnum != -1) { if (friendnum != -1) {
getname(friendnum, (uint8_t*)name); getname(friendnum, (uint8_t*)name);
} else { } else {
getself_name((uint8_t*)name); getself_name((uint8_t*)name);
} }
char *msg = malloc(100+strlen(message)+strlen(name)+1); char *msg = malloc(100+strlen(message)+strlen(name)+1);
time_t rawtime; time_t rawtime;
struct tm * timeinfo; struct tm * timeinfo;
time ( &rawtime ); time ( &rawtime );
timeinfo = localtime ( &rawtime ); timeinfo = localtime ( &rawtime );
char* time = asctime(timeinfo); char* time = asctime(timeinfo);
size_t len = strlen(time); size_t len = strlen(time);
time[len-1]='\0'; time[len-1] = '\0';
sprintf(msg, "[%d] %s <%s> %s", friendnum, time, name, message); // timestamp sprintf(msg, "[%d] %s <%s> %s", friendnum, time, name, message); // timestamp
return msg; return msg;
} }
@ -95,13 +98,14 @@ char *format_message(char *message, int friendnum)
void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
{ {
if (line[0] == '/') { if (line[0] == '/') {
char command[STRING_LENGTH + 2] = "> "; char inpt_command = line[1];
strcat(command, line); char prompt[STRING_LENGTH + 2] = "> ";
new_lines(command); strcat(prompt, line);
if (line[1] == 'f') { // add friend command: /f ID new_lines(prompt);
if (inpt_command == 'f') { // add friend command: /f ID
int i; int i;
char temp_id[128]; char temp_id[128];
for (i=0; i<128; i++) for (i = 0; i < 128; i++)
temp_id[i] = line[i+3]; temp_id[i] = line[i+3];
int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
char numstring[100]; char numstring[100];
@ -109,63 +113,63 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
new_lines(numstring); new_lines(numstring);
do_refresh(); do_refresh();
} }
else if (line[1] == 'd') { else if (inpt_command == 'd') {
doMessenger(); doMessenger();
} }
else if (line[1] == 'm') { //message command: /m friendnumber messsage else if (inpt_command == 'm') { //message command: /m friendnumber messsage
int i;
size_t len = strlen(line); size_t len = strlen(line);
char numstring[len-3]; char numstring[len-3];
char message[len-3]; char message[len-3];
for (i=0; i<len; i++) { int i;
for (i = 0; i < len; i++) {
if (line[i+3] != ' ') { if (line[i+3] != ' ') {
numstring[i] = line[i+3]; numstring[i] = line[i+3];
} else { } else {
int j; int j;
for (j=i+1; j<len; j++) for (j = (i+1); j < len; j++)
message[j-i-1] = line[j+3]; message[j-i-1] = line[j+3];
break; break;
} }
} }
int num = atoi(numstring); int num = atoi(numstring);
if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { if (m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) {
new_lines("[i] could not send message"); new_lines("[i] could not send message");
} else { } else {
new_lines(format_message(message, -1)); new_lines(format_message(message, -1));
} }
} }
else if (line[1] == 'n') { else if (inpt_command == 'n') {
uint8_t name[MAX_NAME_LENGTH]; uint8_t name[MAX_NAME_LENGTH];
int i = 0; int i = 0;
size_t len = strlen(line); size_t len = strlen(line);
for (i=3; i<len; i++) { for (i = 3; i < len; i++) {
if (line[i] == 0 || line[i] == '\n') break; if (line[i] == 0 || line[i] == '\n') break;
name[i - 3] = line[i]; name[i-3] = line[i];
} }
name[i - 3] = 0; name[i-3] = 0;
setname(name, i); setname(name, i);
char numstring[100]; char numstring[100];
sprintf(numstring, "[i] changed nick to %s", (char*)name); sprintf(numstring, "[i] changed nick to %s", (char*)name);
new_lines(numstring); new_lines(numstring);
} }
else if (line[1] == 'l') { else if (inpt_command == 'l') {
print_friendlist(); print_friendlist();
} }
else if (line[1] == 's') { else if (inpt_command == 's') {
uint8_t status[MAX_USERSTATUS_LENGTH]; uint8_t status[MAX_USERSTATUS_LENGTH];
int i = 0; int i = 0;
size_t len = strlen(line); size_t len = strlen(line);
for (i=3; i<len; i++) { for (i = 3; i < len; i++) {
if (line[i] == 0 || line[i] == '\n') break; if (line[i] == 0 || line[i] == '\n') break;
status[i - 3] = line[i]; status[i-3] = line[i];
} }
status[i - 3] = 0; status[i-3] = 0;
m_set_userstatus(status, strlen((char*)status)); m_set_userstatus(status, strlen((char*)status));
char numstring[100]; char numstring[100];
sprintf(numstring, "[i] changed status to %s", (char*)status); sprintf(numstring, "[i] changed status to %s", (char*)status);
new_lines(numstring); new_lines(numstring);
} }
else if (line[1] == 'a') { else if (inpt_command == 'a') {
uint8_t numf = atoi(line + 3); uint8_t numf = atoi(line + 3);
char numchar[100]; char numchar[100];
sprintf(numchar, "[i] friend request %u accepted", numf); sprintf(numchar, "[i] friend request %u accepted", numf);
@ -176,34 +180,34 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
do_refresh(); do_refresh();
} }
else if (inpt_command == 'h') { //help
else if (line[1] == 'h') { //help new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)");
new_lines(help); new_lines("[i] /l list (list friends), /h for help, /i for info, /n nick (to change nickname), /q (to quit)");
} }
else if (inpt_command == 'i') { //info
else if (line[1] == 'i') { //info
char idstring0[200]; char idstring0[200];
char idstring1[32][5]; char idstring1[PUB_KEY_BYTES][5];
char idstring2[32][5]; char idstring2[PUB_KEY_BYTES][5];
uint32_t i; int i;
for(i = 0; i < 32; i++) for (i = 0; i < PUB_KEY_BYTES; i++)
{ {
if(self_public_key[i] < 16) if (self_public_key[i] < (PUB_KEY_BYTES/2))
strcpy(idstring1[i],"0"); strcpy(idstring1[i],"0");
else else
strcpy(idstring1[i], ""); strcpy(idstring1[i], "");
sprintf(idstring2[i], "%hhX",self_public_key[i]); sprintf(idstring2[i], "%hhX", self_public_key[i]);
} }
// //
strcpy(idstring0,"[i] ID: "); strcpy(idstring0,"[i] ID: ");
for (i=0; i<32; i++) { int j;
strcat(idstring0,idstring1[i]); for (j = 0; j < PUB_KEY_BYTES; j++) {
strcat(idstring0,idstring2[i]); strcat(idstring0,idstring1[j]);
strcat(idstring0,idstring2[j]);
} }
new_lines(idstring0); new_lines(idstring0);
} }
else if (line[1] == 'q') { //exit else if (inpt_command == 'q') { //exit
endwin(); endwin();
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} else { } else {
@ -217,9 +221,9 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width)
{ {
int i = 0;
strcpy(output,input); strcpy(output,input);
size_t len = strlen(output); size_t len = strlen(output);
int i = 0;
for (i = line_width; i < len; i = i + line_width) { for (i = line_width; i < len; i = i + line_width) {
while (output[i] != ' ' && i != 0) { while (output[i] != ' ' && i != 0) {
i--; i--;
@ -233,9 +237,9 @@ void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width)
int count_lines(char *string) int count_lines(char *string)
{ {
size_t len = strlen(string); size_t len = strlen(string);
int i;
int count = 1; int count = 1;
for (i=0; i < len; i++) { int i;
for (i = 0; i < len; i++) {
if (string[i] == '\n') if (string[i] == '\n')
count++; count++;
} }
@ -246,7 +250,7 @@ char *appender(char *str, const char c)
{ {
size_t len = strlen(str); size_t len = strlen(str);
if (len < STRING_LENGTH) { if (len < STRING_LENGTH) {
str[len + 1] = str[len]; str[len+1] = str[len];
str[len] = c; str[len] = c;
} }
return str; return str;
@ -254,21 +258,21 @@ char *appender(char *str, const char c)
void do_refresh() void do_refresh()
{ {
int i;
int count=0; int count=0;
int l;
char wrap_output[STRING_LENGTH]; char wrap_output[STRING_LENGTH];
for (i=0; i<HISTORY; i++) { int L;
int i;
for (i = 0; i < HISTORY; i++) {
wrap(wrap_output, lines[i], x); wrap(wrap_output, lines[i], x);
l = count_lines(wrap_output); L = count_lines(wrap_output);
count = count + l; count = count + L;
if (count < y) { if (count < y) {
move(y-1-count,0); move(y-1-count, 0);
printw(wrap_output); printw(wrap_output);
clrtoeol(); clrtoeol();
} }
} }
move(y-1,0); move(y-1, 0);
clrtoeol(); clrtoeol();
printw(">> "); printw(">> ");
printw(line); printw(line);
@ -299,12 +303,13 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length)
timeinfo = localtime ( &rawtime ); timeinfo = localtime ( &rawtime );
char* temp = asctime(timeinfo); char* temp = asctime(timeinfo);
size_t len = strlen(temp); size_t len = strlen(temp);
temp[len-1]='\0'; temp[len-1] = '\0';
sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp
new_lines(format_message((char*)string, friendnumber)); new_lines(format_message((char*)string, friendnumber));
} }
void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) { void print_nickchange(int friendnumber, uint8_t *string, uint16_t length)
{
char name[MAX_NAME_LENGTH]; char name[MAX_NAME_LENGTH];
getname(friendnumber, (uint8_t*)name); getname(friendnumber, (uint8_t*)name);
char msg[100+length]; char msg[100+length];
@ -312,7 +317,8 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) {
new_lines(msg); new_lines(msg);
} }
void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { void print_statuschange(int friendnumber, uint8_t *string, uint16_t length)
{
char name[MAX_NAME_LENGTH]; char name[MAX_NAME_LENGTH];
getname(friendnumber, (uint8_t*)name); getname(friendnumber, (uint8_t*)name);
char msg[100+length+strlen(name)+1]; char msg[100+length+strlen(name)+1];
@ -320,15 +326,17 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) {
new_lines(msg); new_lines(msg);
} }
void load_key(){ void load_key()
{
FILE *data_file = NULL; FILE *data_file = NULL;
if ((data_file = fopen("data","r"))) { data_file = fopen("data","r");
if (data_file) {
//load keys //load keys
fseek(data_file, 0, SEEK_END); fseek(data_file, 0, SEEK_END);
int size = ftell(data_file); int size = ftell(data_file);
fseek(data_file, 0, SEEK_SET); fseek(data_file, 0, SEEK_SET);
uint8_t data[size]; uint8_t data[size];
if(fread(data, sizeof(uint8_t), size, data_file) != size){ if (fread(data, sizeof(uint8_t), size, data_file) != size){
printf("[i] could not read data file\n[i] exiting\n"); printf("[i] could not read data file\n[i] exiting\n");
exit(1); exit(1);
} }
@ -339,7 +347,7 @@ void load_key(){
uint8_t data[size]; uint8_t data[size];
Messenger_save(data); Messenger_save(data);
data_file = fopen("data","w"); data_file = fopen("data","w");
if(fwrite(data, sizeof(uint8_t), size, data_file) != size){ if (fwrite(data, sizeof(uint8_t), size, data_file) != size){
printf("[i] could not write data file\n[i] exiting\n"); printf("[i] could not write data file\n[i] exiting\n");
exit(1); exit(1);
} }
@ -369,26 +377,27 @@ int main(int argc, char *argv[])
m_callback_namechange(print_nickchange); m_callback_namechange(print_nickchange);
m_callback_userstatus(print_statuschange); m_callback_userstatus(print_statuschange);
char idstring0[200]; char idstring0[200];
char idstring1[32][5]; char idstring1[PUB_KEY_BYTES][5];
char idstring2[32][5]; char idstring2[PUB_KEY_BYTES][5];
uint32_t i; int i;
for(i = 0; i < 32; i++) for(i = 0; i < PUB_KEY_BYTES; i++)
{ {
if(self_public_key[i] < 16) if (self_public_key[i] < (PUB_KEY_BYTES / 2))
strcpy(idstring1[i],"0"); strcpy(idstring1[i],"0");
else else
strcpy(idstring1[i], ""); strcpy(idstring1[i], "");
sprintf(idstring2[i], "%hhX",self_public_key[i]); sprintf(idstring2[i], "%hhX",self_public_key[i]);
} }
strcpy(idstring0,"[i] your ID: "); strcpy(idstring0,"[i] your ID: ");
for (i=0; i<32; i++) { int j;
strcat(idstring0,idstring1[i]); for (j = 0; j < PUB_KEY_BYTES; j++) {
strcat(idstring0,idstring2[i]); strcat(idstring0,idstring1[j]);
strcat(idstring0,idstring2[j]);
} }
initscr(); initscr();
noecho(); noecho();
raw(); raw();
getmaxyx(stdscr,y,x); getmaxyx(stdscr, y, x);
new_lines(idstring0); new_lines(idstring0);
new_lines(help); new_lines(help);
strcpy(line, ""); strcpy(line, "");
@ -413,7 +422,6 @@ int main(int argc, char *argv[])
do_refresh(); do_refresh();
c = getch(); c = getch();
if (c == ERR || c == 27) if (c == ERR || c == 27)
continue; continue;
@ -422,7 +430,7 @@ int main(int argc, char *argv[])
line_eval(lines, line); line_eval(lines, line);
strcpy(line, ""); strcpy(line, "");
} else if (c == 127) { } else if (c == 127) {
line[strlen(line) - 1] = '\0'; line[strlen(line)-1] = '\0';
} else if (isalnum(c) || ispunct(c) || c == ' ') { } else if (isalnum(c) || ispunct(c) || c == ' ') {
strcpy(line, appender(line, (char) c)); strcpy(line, appender(line, (char) c));
} }

View File

@ -39,6 +39,7 @@
#include "../core/network.h" #include "../core/network.h"
#define STRING_LENGTH 256 #define STRING_LENGTH 256
#define HISTORY 50 #define HISTORY 50
#define PUB_KEY_BYTES 32
void new_lines(char *line); void new_lines(char *line);
void line_eval(char lines[HISTORY][STRING_LENGTH], char *line); void line_eval(char lines[HISTORY][STRING_LENGTH], char *line);

View File

@ -27,7 +27,7 @@
#include <process.h> #include <process.h>
uint8_t pending_requests[256][CLIENT_ID_SIZE]; uint8_t pending_requests[256][CLIENT_ID_SIZE];
uint8_t num_requests; uint8_t num_requests = 0;
char line[STRING_LENGTH]; char line[STRING_LENGTH];
char users_id[200]; char users_id[200];
@ -88,14 +88,13 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) {
void load_key() void load_key()
{ {
FILE *data_file = NULL; FILE *data_file = NULL;
data_file = fopen("data","r");
if ((data_file = fopen("data", "r"))) { if (data_file) {
fseek(data_file, 0, SEEK_END); fseek(data_file, 0, SEEK_END);
int size = ftell(data_file); int size = ftell(data_file);
fseek(data_file, 0, SEEK_SET); fseek(data_file, 0, SEEK_SET);
uint8_t data[size]; uint8_t data[size];
if (fread(data, sizeof(uint8_t), size, data_file) != size) {
if(fread(data, sizeof(uint8_t), size, data_file) != size) {
printf("\n[i] Could not read the data file. Exiting."); printf("\n[i] Could not read the data file. Exiting.");
exit(1); exit(1);
} }
@ -107,23 +106,23 @@ void load_key()
Messenger_save(data); Messenger_save(data);
data_file = fopen("data", "w"); data_file = fopen("data", "w");
if(fwrite(data, sizeof(uint8_t), size, data_file) != size) { if (fwrite(data, sizeof(uint8_t), size, data_file) != size) {
printf("\n[i] Could not write data to file. Exiting."); printf("\n[i] Could not write data to file. Exiting.");
exit(1); exit(1);
} }
} }
fclose(data_file); fclose(data_file);
} }
void line_eval(char* line) void line_eval(char* line)
{ {
if(line[0] == '/') { if(line[0] == '/') {
char inpt_command = line[1];
/* Add friend */ /* Add friend */
if(line[1] == 'f') { if(inpt_command == 'f') {
int i; int i;
char temp_id[128]; char temp_id[128];
for (i=0; i<128; i++) for (i = 0; i < 128; i++)
temp_id[i] = line[i+3]; temp_id[i] = line[i+3];
int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
char numstring[100]; char numstring[100];
@ -131,28 +130,27 @@ void line_eval(char* line)
printf(numstring); printf(numstring);
} }
else if (line[1] == 'r') { else if (inpt_command == 'r') {
do_header(); do_header();
printf("\n\n"); printf("\n\n");
} }
else if (line[1] == 'l') { else if (inpt_command == 'l') {
printf("\n[i] Friend List | Total: %d\n\n", getnumfriends()); printf("\n[i] Friend List | Total: %d\n\n", getnumfriends());
int i; int i;
for (i = 0; i < getnumfriends(); i++) {
for (i=0; i < getnumfriends(); i++) {
char name[MAX_NAME_LENGTH]; char name[MAX_NAME_LENGTH];
getname(i, (uint8_t*)name); getname(i, (uint8_t*)name);
printf("[%d] %s\n\n", i, (uint8_t*)name); printf("[%d] %s\n\n", i, (uint8_t*)name);
} }
} }
else if (line[1] == 'd') { else if (inpt_command == 'd') {
size_t len = strlen(line); size_t len = strlen(line);
char numstring[len-3]; char numstring[len-3];
int i; int i;
for (i=0; i<len; i++) { for (i = 0; i < len; i++) {
if (line[i+3] != ' ') { if (line[i+3] != ' ') {
numstring[i] = line[i+3]; numstring[i] = line[i+3];
} }
@ -161,17 +159,17 @@ void line_eval(char* line)
m_delfriend(num); m_delfriend(num);
} }
/* Send message to friend */ /* Send message to friend */
else if (line[1] == 'm') { else if (inpt_command == 'm') {
int i;
size_t len = strlen(line); size_t len = strlen(line);
char numstring[len-3]; char numstring[len-3];
char message[len-3]; char message[len-3];
for (i=0; i<len; i++) { int i;
for (i = 0; i < len; i++) {
if (line[i+3] != ' ') { if (line[i+3] != ' ') {
numstring[i] = line[i+3]; numstring[i] = line[i+3];
} else { } else {
int j; int j;
for (j=i+1; j<len; j++) for (j = (i+1); j < len; j++)
message[j-i-1] = line[j+3]; message[j-i-1] = line[j+3];
break; break;
} }
@ -185,37 +183,37 @@ void line_eval(char* line)
} }
} }
else if (line[1] == 'n') { else if (inpt_command == 'n') {
uint8_t name[MAX_NAME_LENGTH]; uint8_t name[MAX_NAME_LENGTH];
int i = 0; int i = 0;
size_t len = strlen(line); size_t len = strlen(line);
for (i=3; i<len; i++) { for (i = 3; i < len; i++) {
if (line[i] == 0 || line[i] == '\n') break; if (line[i] == 0 || line[i] == '\n') break;
name[i - 3] = line[i]; name[i-3] = line[i];
} }
name[i - 3] = 0; name[i-3] = 0;
setname(name, i); setname(name, i);
char numstring[100]; char numstring[100];
sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name); sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name);
printf(numstring); printf(numstring);
} }
else if (line[1] == 's') { else if (inpt_command == 's') {
uint8_t status[MAX_USERSTATUS_LENGTH]; uint8_t status[MAX_USERSTATUS_LENGTH];
int i = 0; int i = 0;
size_t len = strlen(line); size_t len = strlen(line);
for (i=3; i<len; i++) { for (i = 3; i < len; i++) {
if (line[i] == 0 || line[i] == '\n') break; if (line[i] == 0 || line[i] == '\n') break;
status[i - 3] = line[i]; status[i-3] = line[i];
} }
status[i - 3] = 0; status[i-3] = 0;
m_set_userstatus(status, strlen((char*)status)); m_set_userstatus(status, strlen((char*)status));
char numstring[100]; char numstring[100];
sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status);
printf(numstring); printf(numstring);
} }
else if (line[1] == 'a') { else if (inpt_command == 'a') {
uint8_t numf = atoi(line + 3); uint8_t numf = atoi(line + 3);
char numchar[100]; char numchar[100];
sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf); sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf);
@ -225,12 +223,10 @@ void line_eval(char* line)
printf(numchar); printf(numchar);
} }
/* EXIT */ /* EXIT */
else if (line[1] == 'q') { else if (inpt_command == 'q') {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
} } else {
else {
//nothing atm //nothing atm
} }
} }
@ -250,12 +246,10 @@ int main(int argc, char *argv[])
printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]); printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]);
exit(0); exit(0);
} }
if (initMessenger() == -1) { if (initMessenger() == -1) {
printf("initMessenger failed"); printf("initMessenger failed");
exit(0); exit(0);
} }
if (argc > 4) { if (argc > 4) {
if(strncmp(argv[4], "nokey", 6) < 0) { if(strncmp(argv[4], "nokey", 6) < 0) {
} }
@ -267,26 +261,25 @@ int main(int argc, char *argv[])
m_callback_friendmessage(print_message); m_callback_friendmessage(print_message);
m_callback_namechange(print_nickchange); m_callback_namechange(print_nickchange);
m_callback_userstatus(print_statuschange); m_callback_userstatus(print_statuschange);
char idstring1[PUB_KEY_BYTES][5];
char idstring1[32][5]; char idstring2[PUB_KEY_BYTES][5];
char idstring2[32][5]; int i;
uint32_t i; for(i = 0; i < PUB_KEY_BYTES; i++)
for(i = 0; i < 32; i++)
{ {
if(self_public_key[i] < 16) if(self_public_key[i] < (PUB_KEY_BYTES/2))
strcpy(idstring1[i],"0"); strcpy(idstring1[i],"0");
else else
strcpy(idstring1[i], ""); strcpy(idstring1[i], "");
sprintf(idstring2[i], "%hhX",self_public_key[i]); sprintf(idstring2[i], "%hhX",self_public_key[i]);
} }
strcpy(users_id,"[i] your ID: "); strcpy(users_id,"[i] your ID: ");
for (i=0; i<32; i++) { int j;
strcat(users_id,idstring1[i]); for (j = 0; j < PUB_KEY_BYTES; j++) {
strcat(users_id,idstring2[i]); strcat(users_id,idstring1[j]);
strcat(users_id,idstring2[j]);
} }
do_header(); do_header();
IP_Port bootstrap_ip_port; IP_Port bootstrap_ip_port;
bootstrap_ip_port.port = htons(atoi(argv[2])); bootstrap_ip_port.port = htons(atoi(argv[2]));
int resolved_address = resolve_addr(argv[1]); int resolved_address = resolve_addr(argv[1]);
@ -296,12 +289,9 @@ int main(int argc, char *argv[])
exit(1); exit(1);
DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
int c; int c;
int on = 0; int on = 0;
_beginthread(get_input, 0, NULL); _beginthread(get_input, 0, NULL);
while(1) { while(1) {
if (on == 1 && DHT_isconnected() == -1) { if (on == 1 && DHT_isconnected() == -1) {
printf("\n---------------------------------"); printf("\n---------------------------------");
@ -309,16 +299,13 @@ int main(int argc, char *argv[])
printf("\n---------------------------------\n\n"); printf("\n---------------------------------\n\n");
on = 0; on = 0;
} }
if (on == 0 && DHT_isconnected()) { if (on == 0 && DHT_isconnected()) {
printf("\n[i] Connected to DHT"); printf("\n[i] Connected to DHT");
printf("\n---------------------------------\n\n"); printf("\n---------------------------------\n\n");
on = 1; on = 1;
} }
doMessenger(); doMessenger();
Sleep(1); Sleep(1);
} }
return 0; return 0;
} }

View File

@ -27,5 +27,6 @@
#include "../core/network.h" #include "../core/network.h"
#define STRING_LENGTH 256 #define STRING_LENGTH 256
#define PUB_KEY_BYTES 32
#endif #endif