From 09a71f37ec3f18184364d4a6bcc93ab5c50da759 Mon Sep 17 00:00:00 2001 From: Ryan Lewon Date: Tue, 30 Jul 2013 07:19:07 +0000 Subject: [PATCH 1/2] New friend list function for nTox client. --- testing/nTox.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/testing/nTox.c b/testing/nTox.c index 960dfb27..b5fff89d 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -20,10 +20,11 @@ * along with Tox. If not, see . * */ - +#include "../core/DHT.c" #include "nTox.h" #include "misc_tools.h" + #include #include #ifdef WIN32 @@ -50,6 +51,25 @@ void new_lines(char *line) do_refresh(); } +void print_friendlist() +{ + char name[MAX_NAME_LENGTH]; + uint32_t i; + + new_lines("[i] Friend List:"); + for (i=0; i <= num_requests; i++) { + char fstring[128]; + + getname(i, (uint8_t*)name); + if (strlen(name) <= 0) { + sprintf(fstring, "[i] Friend: NULL\n\tid: %i", i); + } else { + sprintf(fstring, "[i] Friend: %s\n\tid: %i", (uint8_t*)name, i); + } + new_lines(fstring); + } +} + void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) { if (line[0] == '/') { @@ -104,6 +124,9 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) sprintf(numstring, "[i] changed nick to %s", (char*)name); new_lines(numstring); } + else if (line[1] == 'l') { + print_friendlist(); + } else if (line[1] == 's') { uint8_t status[MAX_USERSTATUS_LENGTH]; int i = 0; @@ -313,7 +336,8 @@ int main(int argc, char *argv[]) raw(); getmaxyx(stdscr,y,x); new_lines(idstring0); - new_lines("[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)"); + new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)"); + new_lines("[i] /l list (list friends), /n nick (to change nickname), /q (to quit)"); strcpy(line, ""); IP_Port bootstrap_ip_port; bootstrap_ip_port.port = htons(atoi(argv[2])); From 20aad9c73bfad93099a2614d7be1fe8a245665c7 Mon Sep 17 00:00:00 2001 From: Ryan Lewon Date: Tue, 30 Jul 2013 07:26:58 +0000 Subject: [PATCH 2/2] Removed unneeded include. Fixed formatting and cleaned up output. --- testing/nTox.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/testing/nTox.c b/testing/nTox.c index b5fff89d..b926ebca 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -20,7 +20,6 @@ * along with Tox. If not, see . * */ -#include "../core/DHT.c" #include "nTox.h" #include "misc_tools.h" @@ -62,9 +61,9 @@ void print_friendlist() getname(i, (uint8_t*)name); if (strlen(name) <= 0) { - sprintf(fstring, "[i] Friend: NULL\n\tid: %i", i); - } else { - sprintf(fstring, "[i] Friend: %s\n\tid: %i", (uint8_t*)name, i); + sprintf(fstring, "[i] Friend: NULL\n\tid: %i", i); + } else { + sprintf(fstring, "[i] Friend: %s\n\tid: %i", (uint8_t*)name, i); } new_lines(fstring); }