From 1a9ee5c95f1864957a25e32c9198f637f7db2032 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Wed, 18 Sep 2013 11:11:10 -0400 Subject: Fixed bad code in nTox. --- testing/nTox.c | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/testing/nTox.c b/testing/nTox.c index 2e394528..a1eea94c 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -269,34 +269,18 @@ void line_eval(Tox *m, char *line) } else if (inpt_command == 'd') { tox_do(m); } else if (inpt_command == 'm') { //message command: /m friendnumber messsage - size_t len = strlen(line); - - if (len < 3) - return; - - char numstring[len - 3]; - char message[len - 3]; - uint32_t i; + char *posi[1]; + int num = strtoul(line + prompt_offset, posi, 0); - for (i = 0; i < len; i++) { - if (line[i + 3] != ' ') { - numstring[i] = line[i + 3]; + if (**posi != 0) { + if (tox_sendmessage(m, num, (uint8_t *) *posi + 1, strlen(*posi + 1) + 1) < 1) { + char sss[256]; + sprintf(sss, "[i] could not send message to friend num %u", num); + new_lines(sss); } else { - uint32_t j; - - for (j = (i + 1); j < (len + 1); j++) - message[j - i - 1] = line[j + 3]; - - break; + new_lines(format_message(m, *posi + 1, -1)); } - } - - int num = atoi(numstring); - - if (tox_sendmessage(m, num, (uint8_t *) message, strlen(message) + 1) < 1) { - new_lines("[i] could not send message"); - } else { - new_lines(format_message(m, message, -1)); + new_lines("Error, bad input."); } } else if (inpt_command == 'n') { uint8_t name[TOX_MAX_NAME_LENGTH]; -- cgit v1.2.3