From 84a0871cf6afad74441087939cec9c0e55d39961 Mon Sep 17 00:00:00 2001 From: Astonex Date: Tue, 30 Jul 2013 08:52:18 +0100 Subject: [PATCH 1/4] Fixed bugs, added friend listing (slightly buggy), and changed the general aesthetics --- testing/nTox_win32.c | 68 ++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 51f310012..6faae31d9 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -30,18 +30,23 @@ uint8_t pending_requests[256][CLIENT_ID_SIZE]; uint8_t num_requests; char line[STRING_LENGTH]; +char users_id[200]; void do_header() { - 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), /q (to quit)\n\n"); + system("cls"); + printf(users_id); + printf("\n---------------------------------"); + 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), /q (to quit), /r (reset screen)"); + printf("\n---------------------------------"); } void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) { - printf("\n[i] received friend request with message\n"); + printf("\n\n[i] received friend request with message\n"); printf((char *)data); char numchar[100]; - sprintf(numchar, "\n[i] accept request with /a %u\n", num_requests); + sprintf(numchar, "\n\n[i] accept request with /a %u\n\n", num_requests); printf(numchar); memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE); ++num_requests; @@ -59,7 +64,7 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length) char* temp = asctime(timeinfo); size_t len = strlen(temp); temp[len-1]='\0'; - sprintf(msg, "\n[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp + sprintf(msg, "\n[%d] %s <%s> %s\n\n", friendnumber, temp, name, string); // timestamp printf(msg); } @@ -68,7 +73,7 @@ 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]; - sprintf(msg, "\n[i] [%d] %s is now known as %s.", friendnumber, name, string); + sprintf(msg, "\n\n[i] [%d] %s is now known as %s.\n\n", friendnumber, name, string); printf(msg); } @@ -76,11 +81,10 @@ void print_statuschange(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]; - sprintf(msg, "\n[i] [%d] %s's status changed to %s.", friendnumber, name, string); + sprintf(msg, "\n\n[i] [%d] %s's status changed to %s.\n", friendnumber, name, string); printf(msg); } - void load_key() { FILE *data_file = NULL; @@ -127,6 +131,23 @@ void line_eval(char* line) printf(numstring); } + else if (line[1] == 'r') { + do_header(); + printf("\n\n"); + } + + else if (line[1] == 'l') { + printf("\n[i] Friend List\n\n"); + + int i; + + for (i=0; i <= num_requests; i++) { + char name[MAX_NAME_LENGTH]; + getname(i, (uint8_t*)name); + printf("[%d] %s\n\n", i, (uint8_t*)name); + } + } + else if (line[1] == 'd') { doMessenger(); } @@ -148,7 +169,10 @@ void line_eval(char* line) } int num = atoi(numstring); if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { - printf("\n[i] could not send message: %s\n\n", message); + printf("\n[i] could not send message: %s\n", message); + } else { + //simply for aesthetics + printf("\n"); } } @@ -222,14 +246,12 @@ int main(int argc, char *argv[]) printf("initMessenger failed"); exit(0); } - if (argc > 4) { if(strncmp(argv[4], "nokey", 6) < 0) { - //nothing - } else { - load_key(); } + } else { + load_key(); } m_callback_friendrequest(print_request); @@ -237,9 +259,6 @@ int main(int argc, char *argv[]) m_callback_namechange(print_nickchange); m_callback_userstatus(print_statuschange); - system("cls"); - - char idstring0[200]; char idstring1[32][5]; char idstring2[32][5]; uint32_t i; @@ -251,15 +270,13 @@ int main(int argc, char *argv[]) strcpy(idstring1[i], ""); sprintf(idstring2[i], "%hhX",self_public_key[i]); } - strcpy(idstring0,"\n[i] your ID: "); + strcpy(users_id,"[i] your ID: "); for (i=0; i<32; i++) { - strcat(idstring0,idstring1[i]); - strcat(idstring0,idstring2[i]); + strcat(users_id,idstring1[i]); + strcat(users_id,idstring2[i]); } - printf(idstring0); do_header(); - IP_Port bootstrap_ip_port; bootstrap_ip_port.port = htons(atoi(argv[2])); @@ -271,15 +288,22 @@ int main(int argc, char *argv[]) DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); - int c; int on = 0; _beginthread(get_input, 0, NULL); while(1) { + if (on == 1 && DHT_isconnected() == -1) { + printf("\n---------------------------------"); + printf("\n[i] Disconnected from the DHT"); + printf("\n---------------------------------\n\n"); + on = 0; + } + if (on == 0 && DHT_isconnected()) { - printf("\n[i] connected to DHT\n\n"); + printf("\n[i] Connected to DHT"); + printf("\n---------------------------------\n\n"); on = 1; } From e920be4c01c3cb5493aab71268b763bea77e5104 Mon Sep 17 00:00:00 2001 From: Astonex Date: Tue, 30 Jul 2013 09:21:22 +0100 Subject: [PATCH 2/4] Fixed the friends listing --- core/Messenger.c | 6 ++++++ testing/nTox_win32.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/Messenger.c b/core/Messenger.c index f77b4491a..4c76dd300 100644 --- a/core/Messenger.c +++ b/core/Messenger.c @@ -71,6 +71,12 @@ int getfriend_id(uint8_t *client_id) return -1; } +/* Returns number of friends */ +int getnumfriends() +{ + return numfriends; +} + /* copies the public key associated to that friend id into client_id buffer. make sure that client_id is of size CLIENT_ID_SIZE. return 0 if success diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 6faae31d9..9e9a5b1a9 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -137,11 +137,11 @@ void line_eval(char* line) } else if (line[1] == 'l') { - printf("\n[i] Friend List\n\n"); + printf("\n[i] Friend List - %d\n\n", getnumfriends()); int i; - for (i=0; i <= num_requests; i++) { + for (i=0; i < getnumfriends(); i++) { char name[MAX_NAME_LENGTH]; getname(i, (uint8_t*)name); printf("[%d] %s\n\n", i, (uint8_t*)name); From d5e5412cb3b416efe40ba9ba053a0b0fd2894c1c Mon Sep 17 00:00:00 2001 From: Astonex Date: Tue, 30 Jul 2013 09:23:15 +0100 Subject: [PATCH 3/4] Slight aesthetic change --- testing/nTox_win32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 9e9a5b1a9..71a291c6c 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -137,7 +137,7 @@ void line_eval(char* line) } else if (line[1] == 'l') { - printf("\n[i] Friend List - %d\n\n", getnumfriends()); + printf("\n[i] Friend List | Total: %d\n\n", getnumfriends()); int i; From 6ea5420a070ea58e910992cfaf890839a5dbc561 Mon Sep 17 00:00:00 2001 From: Astonex Date: Tue, 30 Jul 2013 09:56:39 +0100 Subject: [PATCH 4/4] Implemented m_delfriend() --- testing/nTox_win32.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 71a291c6c..3a9caaf5e 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c @@ -37,7 +37,7 @@ void do_header() system("cls"); printf(users_id); printf("\n---------------------------------"); - 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), /q (to quit), /r (reset screen)"); + 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)"); printf("\n---------------------------------"); } @@ -149,7 +149,16 @@ void line_eval(char* line) } else if (line[1] == 'd') { - doMessenger(); + size_t len = strlen(line); + char numstring[len-3]; + int i; + for (i=0; i