From 8f6e1d8fbf047bf491cbd93dcfcf19d6789c688e Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Wed, 31 Jul 2013 17:30:16 -0400 Subject: partially fixed friend add bug (key length test still broken) --- testing/nTox.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'testing/nTox.c') diff --git a/testing/nTox.c b/testing/nTox.c index 7c84871f..f00ea498 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -97,17 +97,34 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) { if (line[0] == '/') { char inpt_command = line[1]; - char prompt[STRING_LENGTH + 2] = "> "; + char prompt[STRING_LENGTH+2] = "> "; + int prompt_offset = 3; strcat(prompt, line); new_lines(prompt); if (inpt_command == 'f') { // add friend command: /f ID int i; char temp_id[128]; for (i = 0; i < 128; i++) - temp_id[i] = line[i+3]; + temp_id[i] = line[i+prompt_offset]; int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); char numstring[100]; - sprintf(numstring, "[i] added friend %d", num); + switch (num) { + case -1: + sprintf(numstring, "[i] Incorrect key length"); + break; + case -2: + sprintf(numstring, "[i] That appears to be your own key"); + break; + case -3: + sprintf(numstring, "[i] Friend request already sent"); + break; + case -4: + sprintf(numstring, "[i] Could not add friend"); + break; + default: + sprintf(numstring, "[i] Added friend %d", num); + break; + } new_lines(numstring); do_refresh(); } @@ -171,7 +188,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) uint8_t numf = atoi(line + 3); char numchar[100]; int num = m_addfriend_norequest(pending_requests[numf]); - if (num != -1) { + if (num >= 0) { sprintf(numchar, "[i] friend request %u accepted", numf); new_lines(numchar); sprintf(numchar, "[i] added friendnumber %d", num); -- cgit v1.2.3 From 44d9e248551d03e0dd94609471eaefa6d347f76b Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Wed, 31 Jul 2013 17:38:39 -0400 Subject: small fix --- testing/nTox.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'testing/nTox.c') diff --git a/testing/nTox.c b/testing/nTox.c index f00ea498..17f4b0e7 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -188,7 +188,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) uint8_t numf = atoi(line + 3); char numchar[100]; int num = m_addfriend_norequest(pending_requests[numf]); - if (num >= 0) { + if (num != -1) { sprintf(numchar, "[i] friend request %u accepted", numf); new_lines(numchar); sprintf(numchar, "[i] added friendnumber %d", num); -- cgit v1.2.3