summaryrefslogtreecommitdiff
path: root/testing/nTox.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-08-03 16:46:58 -0400
committerirungentoo <irungentoo@gmail.com>2013-08-03 16:46:58 -0400
commit09a6d2d351840edbe8defd7c209c312c226bedef (patch)
tree756675c389334413d8b5113fc649c6f24baffa8a /testing/nTox.c
parent1ddd28f52b86951d6ca0aed267ebdc8775e8c74b (diff)
parent9b6283c084d1c109be1319d8d325c01322b2cfc5 (diff)
Merge branch 'nTox' of https://github.com/CharmlessCoin/ProjectTox-Core into CharmlessCoin-nTox
Conflicts: testing/nTox.c
Diffstat (limited to 'testing/nTox.c')
-rw-r--r--testing/nTox.c97
1 files changed, 66 insertions, 31 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index 13db58d7..15e209a9 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -36,11 +36,12 @@
36char lines[HISTORY][STRING_LENGTH]; 36char lines[HISTORY][STRING_LENGTH];
37char line[STRING_LENGTH]; 37char line[STRING_LENGTH];
38 38
39char *help = "[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)\n" 39char *help = "[i] commands:\n/f ID (to add friend)\n/m friendnumber message "
40 "[i] /l list (list friends), /h for help, /i for info, /n nick (to change nickname), /q (to quit)"; 40 "(to send message)\n/s status (to change status)\n[i] /l list (l"
41 "ist friends)\n/h for help\n/i for info\n/n nick (to change nick"
42 "name)\n/q (to quit)";
41int x, y; 43int x, y;
42 44
43
44uint8_t pending_requests[256][CLIENT_ID_SIZE]; 45uint8_t pending_requests[256][CLIENT_ID_SIZE];
45uint8_t num_requests = 0; 46uint8_t num_requests = 0;
46 47
@@ -82,18 +83,23 @@ void new_lines(char *line)
82void print_friendlist() 83void print_friendlist()
83{ 84{
84 char name[MAX_NAME_LENGTH]; 85 char name[MAX_NAME_LENGTH];
86 int i = 0;
85 new_lines("[i] Friend List:"); 87 new_lines("[i] Friend List:");
86 uint32_t i; 88 while(getname(i, (uint8_t *)name) != -1) {
87 for (i = 0; i <= num_requests; i++) { 89 /* account for the longest name and the longest "base" string */
88 char fstring[128]; 90 char fstring[MAX_NAME_LENGTH + strlen("[i] Friend: NULL\n\tid: ")];
89 getname(i, (uint8_t*)name); 91
90 if (strlen(name) <= 0) { 92 if (strlen(name) <= 0) {
91 sprintf(fstring, "[i] Friend: NULL\n\tid: %i", i); 93 sprintf(fstring, "[i] Friend: No Friend!\n\tid: %i", i);
92 } else { 94 } else {
93 sprintf(fstring, "[i] Friend: %s\n\tid: %i", (uint8_t*)name, i); 95 sprintf(fstring, "[i] Friend: %s\n\tid: %i", (uint8_t*)name, i);
94 } 96 }
97 i++;
95 new_lines(fstring); 98 new_lines(fstring);
96 } 99 }
100
101 if(i == 0)
102 new_lines("\tno friends! D:");
97} 103}
98 104
99char *format_message(char *message, int friendnum) 105char *format_message(char *message, int friendnum)
@@ -122,7 +128,7 @@ char *format_message(char *message, int friendnum)
122 return msg; 128 return msg;
123} 129}
124 130
125void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) 131void line_eval(char *line)
126{ 132{
127 if (line[0] == '/') { 133 if (line[0] == '/') {
128 char inpt_command = line[1]; 134 char inpt_command = line[1];
@@ -236,8 +242,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
236 do_refresh(); 242 do_refresh();
237 } 243 }
238 else if (inpt_command == 'h') { //help 244 else if (inpt_command == 'h') { //help
239 new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)"); 245 new_lines(help);
240 new_lines("[i] /l list (list friends), /h for help, /i for info, /n nick (to change nickname), /q (to quit)");
241 } 246 }
242 else if (inpt_command == 'i') { //info 247 else if (inpt_command == 'i') { //info
243 char idstring[200]; 248 char idstring[200];
@@ -353,10 +358,10 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length)
353 new_lines(msg); 358 new_lines(msg);
354} 359}
355 360
356void load_key() 361void load_key(char *path)
357{ 362{
358 FILE *data_file = NULL; 363 FILE *data_file = fopen(path, "r");
359 data_file = fopen("data","r"); 364
360 if (data_file) { 365 if (data_file) {
361 //load keys 366 //load keys
362 fseek(data_file, 0, SEEK_END); 367 fseek(data_file, 0, SEEK_END);
@@ -368,51 +373,81 @@ void load_key()
368 exit(1); 373 exit(1);
369 } 374 }
370 Messenger_load(data, size); 375 Messenger_load(data, size);
371 } else { 376
377 } else {
372 //else save new keys 378 //else save new keys
373 int size = Messenger_size(); 379 int size = Messenger_size();
374 uint8_t data[size]; 380 uint8_t data[size];
375 Messenger_save(data); 381 Messenger_save(data);
376 data_file = fopen("data","w"); 382 data_file = fopen(path, "w");
383
384 if(!data_file) {
385 perror("[!] load_key");
386 exit(1);
387 }
388
377 if (fwrite(data, sizeof(uint8_t), size, data_file) != size){ 389 if (fwrite(data, sizeof(uint8_t), size, data_file) != size){
378 printf("[i] could not write data file\n[i] exiting\n"); 390 puts("[i] could not write data file! exiting...");
379 exit(1); 391 exit(1);
380 } 392 }
381 } 393 }
382 fclose(data_file); 394 fclose(data_file);
383} 395}
384 396
397void print_help(void)
398{
399 printf("nTox %.1f - Command-line tox-core client\n", 0.1);
400 puts("Options:");
401 puts("\t-h\t-\tPrint this help and exit.");
402 puts("\t-f\t-\tSpecify a keyfile to read (or write to) from.");
403}
404
385int main(int argc, char *argv[]) 405int main(int argc, char *argv[])
386{ 406{
407 int on = 0;
408 int c = 0;
409 int i = 0;
410 char *filename = "data";
411 char idstring[200] = {0};
412
387 if (argc < 4) { 413 if (argc < 4) {
388 printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]); 414 printf("[!] Usage: %s [IP] [port] [public_key] <keyfile>\n", argv[0]);
389 exit(0); 415 exit(0);
390 } 416 }
391 int c; 417
392 int on = 0; 418 for(i = 0; i < argc; i++) {
393 initMessenger(); 419 if(argv[i][0] == '-') {
394 //if keyfiles exist 420 if(argv[i][1] == 'h') {
395 if(argc > 4){ 421 print_help();
396 if(strncmp(argv[4], "nokey", 6) < 0){ 422 exit(0);
397 //load_key(); 423 } else if(argv[i][1] == 'f') {
424 if(argv[i + 1] != NULL)
425 filename = argv[i + 1];
426 else {
427 fputs("[!] you passed '-f' without giving an argument!\n", stderr);
428 }
429 }
398 } 430 }
399 } else {
400 load_key();
401 } 431 }
432
433 initMessenger();
434 load_key(filename);
435
402 m_callback_friendrequest(print_request); 436 m_callback_friendrequest(print_request);
403 m_callback_friendmessage(print_message); 437 m_callback_friendmessage(print_message);
404 m_callback_namechange(print_nickchange); 438 m_callback_namechange(print_nickchange);
405 m_callback_userstatus(print_statuschange); 439 m_callback_userstatus(print_statuschange);
406 440
407 char idstring[200];
408 get_id(idstring);
409 initscr(); 441 initscr();
410 noecho(); 442 noecho();
411 raw(); 443 raw();
412 getmaxyx(stdscr, y, x); 444 getmaxyx(stdscr, y, x);
445
446 new_lines("/h for list of commands");
447 get_id(idstring);
413 new_lines(idstring); 448 new_lines(idstring);
414 new_lines(help);
415 strcpy(line, ""); 449 strcpy(line, "");
450
416 IP_Port bootstrap_ip_port; 451 IP_Port bootstrap_ip_port;
417 bootstrap_ip_port.port = htons(atoi(argv[2])); 452 bootstrap_ip_port.port = htons(atoi(argv[2]));
418 int resolved_address = resolve_addr(argv[1]); 453 int resolved_address = resolve_addr(argv[1]);
@@ -439,7 +474,7 @@ int main(int argc, char *argv[])
439 474
440 getmaxyx(stdscr, y, x); 475 getmaxyx(stdscr, y, x);
441 if (c == '\n') { 476 if (c == '\n') {
442 line_eval(lines, line); 477 line_eval(line);
443 strcpy(line, ""); 478 strcpy(line, "");
444 } else if (c == 8 || c == 127) { 479 } else if (c == 8 || c == 127) {
445 line[strlen(line)-1] = '\0'; 480 line[strlen(line)-1] = '\0';