summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testing/nTox.c73
1 files changed, 51 insertions, 22 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index a498e9a1..319002fd 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -85,7 +85,7 @@ void print_friendlist()
85 char name[MAX_NAME_LENGTH]; 85 char name[MAX_NAME_LENGTH];
86 int i = 0; 86 int i = 0;
87 new_lines("[i] Friend List:"); 87 new_lines("[i] Friend List:");
88 while(getname(i++, (uint8_t *)name) != -1) { 88 while(getname(i, (uint8_t *)name) != -1) {
89 /* account for the longest name and the longest "base" string */ 89 /* account for the longest name and the longest "base" string */
90 char fstring[MAX_NAME_LENGTH + strlen("[i] Friend: NULL\n\tid: ")]; 90 char fstring[MAX_NAME_LENGTH + strlen("[i] Friend: NULL\n\tid: ")];
91 91
@@ -94,10 +94,11 @@ void print_friendlist()
94 } else { 94 } else {
95 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);
96 } 96 }
97 i++;
97 new_lines(fstring); 98 new_lines(fstring);
98 } 99 }
99 100
100 if(i == 1) 101 if(i == 0)
101 new_lines("\tno friends! D:"); 102 new_lines("\tno friends! D:");
102} 103}
103 104
@@ -241,8 +242,7 @@ void line_eval(char *line)
241 do_refresh(); 242 do_refresh();
242 } 243 }
243 else if (inpt_command == 'h') { //help 244 else if (inpt_command == 'h') { //help
244 new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)"); 245 new_lines(help);
245 new_lines("[i] /l list (list friends), /h for help, /i for info, /n nick (to change nickname), /q (to quit)");
246 } 246 }
247 else if (inpt_command == 'i') { //info 247 else if (inpt_command == 'i') { //info
248 char idstring[200]; 248 char idstring[200];
@@ -358,10 +358,10 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length)
358 new_lines(msg); 358 new_lines(msg);
359} 359}
360 360
361void load_key() 361void load_key(char *path)
362{ 362{
363 FILE *data_file = NULL; 363 FILE *data_file = fopen(path, "r");
364 data_file = fopen("data","r"); 364
365 if (data_file) { 365 if (data_file) {
366 //load keys 366 //load keys
367 fseek(data_file, 0, SEEK_END); 367 fseek(data_file, 0, SEEK_END);
@@ -373,12 +373,21 @@ void load_key()
373 exit(1); 373 exit(1);
374 } 374 }
375 Messenger_load(data, size); 375 Messenger_load(data, size);
376
376 } else { 377 } else {
378 fputs("(saving new keys now)\n", stderr);
379
377 //else save new keys 380 //else save new keys
378 int size = Messenger_size(); 381 int size = Messenger_size();
379 uint8_t data[size]; 382 uint8_t data[size];
380 Messenger_save(data); 383 Messenger_save(data);
381 data_file = fopen("data","w"); 384 data_file = fopen(path, "w");
385
386 if(!data_file) {
387 perror("[!] load_key");
388 exit(1);
389 }
390
382 if (fwrite(data, sizeof(uint8_t), size, data_file) != size){ 391 if (fwrite(data, sizeof(uint8_t), size, data_file) != size){
383 printf("[i] could not write data file\n[i] exiting\n"); 392 printf("[i] could not write data file\n[i] exiting\n");
384 exit(1); 393 exit(1);
@@ -387,38 +396,58 @@ void load_key()
387 fclose(data_file); 396 fclose(data_file);
388} 397}
389 398
399void print_help(void)
400{
401 printf("nTox %.1f - Command-line tox-core client\n", 0.1);
402 puts("Options:");
403 puts("\t-h\t-\tPrint this help and exit.");
404 puts("\t-f\t-\tSpecify a keyfile to read from.");
405}
406
390int main(int argc, char *argv[]) 407int main(int argc, char *argv[])
391{ 408{
409 int on = 0;
410 int c = 0;
411 int i = 0;
412 char *filename = "data";
413 char idstring[200] = {0};
414
392 if (argc < 4) { 415 if (argc < 4) {
393 printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]); 416 printf("[!] Usage: %s [IP] [port] [public_key] <keyfile>\n", argv[0]);
394 exit(0); 417 exit(0);
395 } 418 }
396 int c; 419
397 int on = 0; 420 for(i = 0; i < argc; i++) {
398 initMessenger(); 421 if(argv[i][0] == '-') {
399 //if keyfiles exist 422 if(argv[i][1] == 'h') {
400 if(argc > 4){ 423 print_help();
401 if(strncmp(argv[4], "nokey", 6) < 0){ 424 exit(0);
402 //load_key(); 425 } else if(argv[i][1] == 'f') {
426 if(argv[i + 1] != NULL)
427 filename = argv[i + 1];
428 else {
429 fputs("[!] you passed '-f' without giving an argument!\n", stderr);
430 }
431 }
403 } 432 }
404 } else {
405 load_key();
406 } 433 }
434
435 initMessenger();
436 load_key(filename);
437
407 m_callback_friendrequest(print_request); 438 m_callback_friendrequest(print_request);
408 m_callback_friendmessage(print_message); 439 m_callback_friendmessage(print_message);
409 m_callback_namechange(print_nickchange); 440 m_callback_namechange(print_nickchange);
410 m_callback_userstatus(print_statuschange); 441 m_callback_userstatus(print_statuschange);
411 442
412 char idstring[200];
413 get_id(idstring);
414
415 initscr(); 443 initscr();
416 noecho(); 444 noecho();
417 raw(); 445 raw();
418 getmaxyx(stdscr, y, x); 446 getmaxyx(stdscr, y, x);
419 447
420 new_lines("/h for list of commands"); 448 new_lines("/h for list of commands");
421 new_lines(idstring); 449 get_id(idstring);
450 puts(idstring);
422 strcpy(line, ""); 451 strcpy(line, "");
423 452
424 IP_Port bootstrap_ip_port; 453 IP_Port bootstrap_ip_port;