diff options
-rw-r--r-- | testing/nTox.c | 119 |
1 files changed, 101 insertions, 18 deletions
diff --git a/testing/nTox.c b/testing/nTox.c index a227ed33..35841bbe 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -62,34 +62,43 @@ const char wrap_cont_str[] = "\n+ "; | |||
62 | /* documented: fdmnlsahxgiztq */ | 62 | /* documented: fdmnlsahxgiztq */ |
63 | /* undocumented: d (tox_do()) */ | 63 | /* undocumented: d (tox_do()) */ |
64 | 64 | ||
65 | /* 221 characters */ | 65 | /* 249 characters */ |
66 | char *help_main = | 66 | char *help_main = |
67 | "[i] Available main commands:\n+ " | 67 | "[i] Available main commands:\n+ " |
68 | "/x (to print one's own id)|" | 68 | "/x (to print one's own id)|" |
69 | "/s status (to change status, e.g. AFK)|" | 69 | "/s status (to change status, e.g. AFK)|" |
70 | "/n nick (to change your nickname)|" | 70 | "/n nick (to change your nickname)|" |
71 | "/q (to quit)|" | 71 | "/q (to quit)|" |
72 | "/cr (to reset conversation)|" | ||
72 | "/h friend (for friend related commands)|" | 73 | "/h friend (for friend related commands)|" |
73 | "/h group (for group related commands)"; | 74 | "/h group (for group related commands)"; |
74 | 75 | ||
75 | /* 229 characters */ | 76 | /* 141 characters */ |
76 | char *help_friend = | 77 | char *help_friend1 = |
77 | "[i] Available friend commands:\n+ " | 78 | "[i] Available friend commands (1/2):\n+ " |
78 | "/l list (to list friends)|" | 79 | "/l list (to list friends)|" |
79 | "/f ID (to send a friend request)|" | 80 | "/f ID (to send a friend request)|" |
80 | "/a request no. (to accept a friend request)|" | 81 | "/a request no. (to accept a friend request)"; |
82 | |||
83 | /* 184 characters */ | ||
84 | char *help_friend2 = | ||
85 | "[i] Available friend commands (2/2):\n+ " | ||
81 | "/m friend no. message (to send a message)|" | 86 | "/m friend no. message (to send a message)|" |
82 | "/t friend no. filename (to send a file to a friend)"; | 87 | "/t friend no. filename (to send a file to a friend)|" |
88 | "/cf friend no. (to talk to that friend per default)"; | ||
83 | 89 | ||
84 | /* 166 characters */ | 90 | /* 216 characters */ |
85 | char *help_group = | 91 | char *help_group = |
86 | "[i] Available group commands:\n+ " | 92 | "[i] Available group commands:\n+ " |
87 | "/g (to create a new group)|" | 93 | "/g (to create a new group)|" |
88 | "/i friend no. group no. (to invite a friend to a group)|" | 94 | "/i friend no. group no. (to invite a friend to a group)|" |
89 | "/z group no. message (to send a message to a group)"; | 95 | "/z group no. message (to send a message to a group)|" |
96 | "/cg group no. (to talk to that group per default)"; | ||
90 | 97 | ||
91 | int x, y; | 98 | int x, y; |
92 | 99 | ||
100 | int conversation_default = 0; | ||
101 | |||
93 | typedef struct { | 102 | typedef struct { |
94 | uint8_t id[TOX_CLIENT_ID_SIZE]; | 103 | uint8_t id[TOX_CLIENT_ID_SIZE]; |
95 | uint8_t accepted; | 104 | uint8_t accepted; |
@@ -462,7 +471,8 @@ void line_eval(Tox *m, char *line) | |||
462 | } else if (inpt_command == 'h') { //help | 471 | } else if (inpt_command == 'h') { //help |
463 | if (line[2] == ' ') { | 472 | if (line[2] == ' ') { |
464 | if (line[3] == 'f') { | 473 | if (line[3] == 'f') { |
465 | new_lines_mark(help_friend, 1); | 474 | new_lines_mark(help_friend1, 1); |
475 | new_lines_mark(help_friend2, 1); | ||
466 | return; | 476 | return; |
467 | } else if (line[3] == 'g') { | 477 | } else if (line[3] == 'g') { |
468 | new_lines_mark(help_group, 1); | 478 | new_lines_mark(help_group, 1); |
@@ -492,10 +502,17 @@ void line_eval(Tox *m, char *line) | |||
492 | int groupnumber = strtoul(line + prompt_offset, posi, 0); | 502 | int groupnumber = strtoul(line + prompt_offset, posi, 0); |
493 | 503 | ||
494 | if (**posi != 0) { | 504 | if (**posi != 0) { |
495 | char msg[256 + 1024]; | 505 | int res = tox_group_message_send(m, groupnumber, (uint8_t *)*posi + 1, strlen(*posi + 1) + 1); |
496 | sprintf(msg, "[g] sent message: %s to group num: %u returned: %u (0 means success)", *posi + 1, groupnumber, | 506 | |
497 | tox_group_message_send(m, groupnumber, (uint8_t *)*posi + 1, strlen(*posi + 1) + 1)); | 507 | if (res == 0) { |
498 | new_lines(msg); | 508 | char msg[32 + STRING_LENGTH]; |
509 | sprintf(msg, "[g] #%u: YOU: %s", groupnumber, *posi + 1); | ||
510 | new_lines(msg); | ||
511 | } else { | ||
512 | char msg[128]; | ||
513 | sprintf(msg, "[i] could not send message to group no. %u: %i", groupnumber, res); | ||
514 | new_lines(msg); | ||
515 | } | ||
499 | } | 516 | } |
500 | } else if (inpt_command == 't') { | 517 | } else if (inpt_command == 't') { |
501 | char msg[512]; | 518 | char msg[512]; |
@@ -511,12 +528,68 @@ void line_eval(Tox *m, char *line) | |||
511 | save_data(m); | 528 | save_data(m); |
512 | endwin(); | 529 | endwin(); |
513 | exit(EXIT_SUCCESS); | 530 | exit(EXIT_SUCCESS); |
531 | } else if (inpt_command == 'c') { //set conversation partner | ||
532 | if (line[2] == 'r') { | ||
533 | if (conversation_default != 0) { | ||
534 | conversation_default = 0; | ||
535 | new_lines("[i] default conversation reset"); | ||
536 | } else | ||
537 | new_lines("[i] default conversation wasn't set, nothing to do"); | ||
538 | } else if (line[3] != ' ') { | ||
539 | new_lines("[i] invalid command"); | ||
540 | } else { | ||
541 | int num = atoi(line + 4); | ||
542 | |||
543 | /* zero is also returned for not-a-number */ | ||
544 | if (!num && strcmp(line + 4, "0")) | ||
545 | num = -1; | ||
546 | |||
547 | if (num < 0) | ||
548 | new_lines("[i] invalid command parameter"); | ||
549 | else if (line[2] == 'f') { | ||
550 | conversation_default = num + 1; | ||
551 | char buffer[128]; | ||
552 | sprintf(buffer, "[i] default conversation is now to friend %i", num); | ||
553 | new_lines(buffer); | ||
554 | } else if (line[2] == 'g') { | ||
555 | char buffer[128]; | ||
556 | conversation_default = - (num + 1); | ||
557 | sprintf(buffer, "[i] default conversation is now to group %i", num); | ||
558 | new_lines(buffer); | ||
559 | } else | ||
560 | new_lines("[i] invalid command"); | ||
561 | } | ||
514 | } else { | 562 | } else { |
515 | new_lines("[i] invalid command"); | 563 | new_lines("[i] invalid command"); |
516 | } | 564 | } |
517 | } else { | 565 | } else { |
518 | new_lines("[i] invalid command"); | 566 | if (conversation_default != 0) { |
519 | //new_lines(line); | 567 | if (conversation_default > 0) { |
568 | int friendnumber = conversation_default - 1; | ||
569 | uint32_t res = tox_sendmessage(m, friendnumber, (uint8_t *)line, strlen(line) + 1); | ||
570 | |||
571 | if (res == 0) { | ||
572 | char sss[128]; | ||
573 | sprintf(sss, "[i] could not send message to friend no. %u", friendnumber); | ||
574 | new_lines(sss); | ||
575 | } else | ||
576 | print_formatted_message(m, line, friendnumber, 1); | ||
577 | } else { | ||
578 | int groupnumber = - conversation_default - 1; | ||
579 | int res = tox_group_message_send(m, groupnumber, (uint8_t *)line, strlen(line) + 1); | ||
580 | |||
581 | if (res == 0) { | ||
582 | char msg[32 + STRING_LENGTH]; | ||
583 | sprintf(msg, "[g] #%u: YOU: %s", groupnumber, line); | ||
584 | new_lines(msg); | ||
585 | } else { | ||
586 | char msg[128]; | ||
587 | sprintf(msg, "[i] could not send message to group no. %u: %i", groupnumber, res); | ||
588 | new_lines(msg); | ||
589 | } | ||
590 | } | ||
591 | } else | ||
592 | new_lines("[i] invalid input: neither command nor in conversation"); | ||
520 | } | 593 | } |
521 | } | 594 | } |
522 | 595 | ||
@@ -725,7 +798,12 @@ void print_nickchange(Tox *m, int friendnumber, uint8_t *string, uint16_t length | |||
725 | 798 | ||
726 | if (getfriendname_terminated(m, friendnumber, name) != -1) { | 799 | if (getfriendname_terminated(m, friendnumber, name) != -1) { |
727 | char msg[100 + length]; | 800 | char msg[100 + length]; |
728 | sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string); | 801 | |
802 | if (name[0] != 0) | ||
803 | sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string); | ||
804 | else | ||
805 | sprintf(msg, "[i] [%d] Friend's name is %s.", friendnumber, string); | ||
806 | |||
729 | new_lines(msg); | 807 | new_lines(msg); |
730 | } | 808 | } |
731 | } | 809 | } |
@@ -736,7 +814,12 @@ void print_statuschange(Tox *m, int friendnumber, uint8_t *string, uint16_t leng | |||
736 | 814 | ||
737 | if (getfriendname_terminated(m, friendnumber, name) != -1) { | 815 | if (getfriendname_terminated(m, friendnumber, name) != -1) { |
738 | char msg[100 + length + strlen(name) + 1]; | 816 | char msg[100 + length + strlen(name) + 1]; |
739 | sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string); | 817 | |
818 | if (name[0] != 0) | ||
819 | sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string); | ||
820 | else | ||
821 | sprintf(msg, "[i] [%d] Their status changed to %s.", friendnumber, string); | ||
822 | |||
740 | new_lines(msg); | 823 | new_lines(msg); |
741 | } | 824 | } |
742 | } | 825 | } |
@@ -846,7 +929,7 @@ void print_groupmessage(Tox *m, int groupnumber, int peernumber, uint8_t *messag | |||
846 | if (name[0] != 0) | 929 | if (name[0] != 0) |
847 | sprintf(msg, "[g] %u: %u <%s>: %s", groupnumber, peernumber, name, message); | 930 | sprintf(msg, "[g] %u: %u <%s>: %s", groupnumber, peernumber, name, message); |
848 | else | 931 | else |
849 | sprintf(msg, "[g] %u: %u Unknown: %s", groupnumber, peernumber, message); | 932 | sprintf(msg, "[g] #%u: %u Unknown: %s", groupnumber, peernumber, message); |
850 | 933 | ||
851 | new_lines(msg); | 934 | new_lines(msg); |
852 | } | 935 | } |