diff options
Diffstat (limited to 'testing/nTox.c')
-rw-r--r-- | testing/nTox.c | 52 |
1 files changed, 22 insertions, 30 deletions
diff --git a/testing/nTox.c b/testing/nTox.c index e87b4b83..33c8ab85 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -137,6 +137,7 @@ void get_id(Tox *m, char *data) | |||
137 | tox_getaddress(m, address); | 137 | tox_getaddress(m, address); |
138 | 138 | ||
139 | uint32_t i = 0; | 139 | uint32_t i = 0; |
140 | |||
140 | for (; i < TOX_FRIEND_ADDRESS_SIZE; i++) { | 141 | for (; i < TOX_FRIEND_ADDRESS_SIZE; i++) { |
141 | sprintf(data + 2 * i + offset, "%02X ", address[i]); | 142 | sprintf(data + 2 * i + offset, "%02X ", address[i]); |
142 | } | 143 | } |
@@ -257,9 +258,9 @@ void line_eval(Tox *m, char *line) | |||
257 | if (num >= 0) { | 258 | if (num >= 0) { |
258 | sprintf(numstring, "[i] Added friend as %d.", num); | 259 | sprintf(numstring, "[i] Added friend as %d.", num); |
259 | save_data(m); | 260 | save_data(m); |
260 | } | 261 | } else |
261 | else | ||
262 | sprintf(numstring, "[i] Unknown error %i.", num); | 262 | sprintf(numstring, "[i] Unknown error %i.", num); |
263 | |||
263 | break; | 264 | break; |
264 | } | 265 | } |
265 | 266 | ||
@@ -268,35 +269,19 @@ void line_eval(Tox *m, char *line) | |||
268 | } else if (inpt_command == 'd') { | 269 | } else if (inpt_command == 'd') { |
269 | tox_do(m); | 270 | tox_do(m); |
270 | } else if (inpt_command == 'm') { //message command: /m friendnumber messsage | 271 | } else if (inpt_command == 'm') { //message command: /m friendnumber messsage |
271 | size_t len = strlen(line); | 272 | char *posi[1]; |
272 | 273 | int num = strtoul(line + prompt_offset, posi, 0); | |
273 | if (len < 3) | ||
274 | return; | ||
275 | |||
276 | char numstring[len - 3]; | ||
277 | char message[len - 3]; | ||
278 | uint32_t i; | ||
279 | 274 | ||
280 | for (i = 0; i < len; i++) { | 275 | if (**posi != 0) { |
281 | if (line[i + 3] != ' ') { | 276 | if (tox_sendmessage(m, num, (uint8_t *) *posi + 1, strlen(*posi + 1) + 1) < 1) { |
282 | numstring[i] = line[i + 3]; | 277 | char sss[256]; |
278 | sprintf(sss, "[i] could not send message to friend num %u", num); | ||
279 | new_lines(sss); | ||
283 | } else { | 280 | } else { |
284 | uint32_t j; | 281 | new_lines(format_message(m, *posi + 1, -1)); |
285 | |||
286 | for (j = (i + 1); j < (len + 1); j++) | ||
287 | message[j - i - 1] = line[j + 3]; | ||
288 | |||
289 | break; | ||
290 | } | 282 | } |
291 | } | 283 | } else |
292 | 284 | new_lines("Error, bad input."); | |
293 | int num = atoi(numstring); | ||
294 | |||
295 | if (tox_sendmessage(m, num, (uint8_t *) message, strlen(message) + 1) < 1) { | ||
296 | new_lines("[i] could not send message"); | ||
297 | } else { | ||
298 | new_lines(format_message(m, message, -1)); | ||
299 | } | ||
300 | } else if (inpt_command == 'n') { | 285 | } else if (inpt_command == 'n') { |
301 | uint8_t name[TOX_MAX_NAME_LENGTH]; | 286 | uint8_t name[TOX_MAX_NAME_LENGTH]; |
302 | size_t i, len = strlen(line); | 287 | size_t i, len = strlen(line); |
@@ -508,12 +493,14 @@ static int load_data(Tox *m) | |||
508 | { | 493 | { |
509 | FILE *data_file = fopen(data_file_name, "r"); | 494 | FILE *data_file = fopen(data_file_name, "r"); |
510 | size_t size = 0; | 495 | size_t size = 0; |
496 | |||
511 | if (data_file) { | 497 | if (data_file) { |
512 | fseek(data_file, 0, SEEK_END); | 498 | fseek(data_file, 0, SEEK_END); |
513 | size = ftell(data_file); | 499 | size = ftell(data_file); |
514 | rewind(data_file); | 500 | rewind(data_file); |
515 | 501 | ||
516 | uint8_t data[size]; | 502 | uint8_t data[size]; |
503 | |||
517 | if (fread(data, sizeof(uint8_t), size, data_file) != size) { | 504 | if (fread(data, sizeof(uint8_t), size, data_file) != size) { |
518 | fputs("[!] could not read data file!\n", stderr); | 505 | fputs("[!] could not read data file!\n", stderr); |
519 | fclose(data_file); | 506 | fclose(data_file); |
@@ -537,6 +524,7 @@ static int load_data(Tox *m) | |||
537 | static int save_data(Tox *m) | 524 | static int save_data(Tox *m) |
538 | { | 525 | { |
539 | FILE *data_file = fopen(data_file_name, "w"); | 526 | FILE *data_file = fopen(data_file_name, "w"); |
527 | |||
540 | if (!data_file) { | 528 | if (!data_file) { |
541 | perror("[!] load_key"); | 529 | perror("[!] load_key"); |
542 | return 0; | 530 | return 0; |
@@ -563,6 +551,7 @@ static int save_data(Tox *m) | |||
563 | static int load_data_or_init(Tox *m, char *path) | 551 | static int load_data_or_init(Tox *m, char *path) |
564 | { | 552 | { |
565 | data_file_name = path; | 553 | data_file_name = path; |
554 | |||
566 | if (load_data(m)) | 555 | if (load_data(m)) |
567 | return 1; | 556 | return 1; |
568 | 557 | ||
@@ -588,10 +577,12 @@ void print_invite(Tox *m, int friendnumber, uint8_t *group_public_key, void *use | |||
588 | new_lines(msg); | 577 | new_lines(msg); |
589 | } | 578 | } |
590 | 579 | ||
591 | void print_groupmessage(Tox *m, int groupnumber, uint8_t *message, uint16_t length, void *userdata) | 580 | void print_groupmessage(Tox *m, int groupnumber, int peernumber, uint8_t *message, uint16_t length, void *userdata) |
592 | { | 581 | { |
593 | char msg[256 + length]; | 582 | char msg[256 + length]; |
594 | sprintf(msg, "[g] %u: %s", groupnumber, message); | 583 | uint8_t name[TOX_MAX_NAME_LENGTH]; |
584 | tox_group_peername(m, groupnumber, peernumber, name); | ||
585 | sprintf(msg, "[g] %u: <%s>: %s", groupnumber, name, message); | ||
595 | new_lines(msg); | 586 | new_lines(msg); |
596 | } | 587 | } |
597 | 588 | ||
@@ -669,6 +660,7 @@ int main(int argc, char *argv[]) | |||
669 | new_lines("[i] change username with /n"); | 660 | new_lines("[i] change username with /n"); |
670 | uint8_t name[TOX_MAX_NAME_LENGTH]; | 661 | uint8_t name[TOX_MAX_NAME_LENGTH]; |
671 | uint16_t namelen = tox_getselfname(m, name, sizeof(name)); | 662 | uint16_t namelen = tox_getselfname(m, name, sizeof(name)); |
663 | |||
672 | if (namelen > 0) { | 664 | if (namelen > 0) { |
673 | char whoami[128 + TOX_MAX_NAME_LENGTH]; | 665 | char whoami[128 + TOX_MAX_NAME_LENGTH]; |
674 | snprintf(whoami, sizeof(whoami), "[i] your current username is: %s", name); | 666 | snprintf(whoami, sizeof(whoami), "[i] your current username is: %s", name); |