diff options
Diffstat (limited to 'testing')
-rw-r--r-- | testing/nTox.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/testing/nTox.c b/testing/nTox.c index 15e209a9..f76c6c2a 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -42,7 +42,12 @@ char *help = "[i] commands:\n/f ID (to add friend)\n/m friendnumber message " | |||
42 | "name)\n/q (to quit)"; | 42 | "name)\n/q (to quit)"; |
43 | int x, y; | 43 | int x, y; |
44 | 44 | ||
45 | uint8_t pending_requests[256][CLIENT_ID_SIZE]; | 45 | typedef struct { |
46 | uint8_t id[CLIENT_ID_SIZE]; | ||
47 | uint8_t accepted; | ||
48 | } Friend_request; | ||
49 | |||
50 | Friend_request pending_requests[256]; | ||
46 | uint8_t num_requests = 0; | 51 | uint8_t num_requests = 0; |
47 | 52 | ||
48 | void get_id(char *data) | 53 | void get_id(char *data) |
@@ -229,15 +234,21 @@ void line_eval(char *line) | |||
229 | else if (inpt_command == 'a') { | 234 | else if (inpt_command == 'a') { |
230 | uint8_t numf = atoi(line + 3); | 235 | uint8_t numf = atoi(line + 3); |
231 | char numchar[100]; | 236 | char numchar[100]; |
232 | int num = m_addfriend_norequest(pending_requests[numf]); | 237 | if(numf >= num_requests || pending_requests[numf].accepted) { |
233 | if (num != -1) { | 238 | sprintf(numchar,"[i] you either didn't receive that request or you already accepted it"); |
234 | sprintf(numchar, "[i] friend request %u accepted", numf); | ||
235 | new_lines(numchar); | ||
236 | sprintf(numchar, "[i] added friendnumber %d", num); | ||
237 | new_lines(numchar); | 239 | new_lines(numchar); |
238 | } else { | 240 | } else { |
239 | sprintf(numchar, "[i] failed to add friend"); | 241 | int num = m_addfriend_norequest(pending_requests[numf].id); |
240 | new_lines(numchar); | 242 | if (num != -1) { |
243 | pending_requests[numf].accepted = 1; | ||
244 | sprintf(numchar, "[i] friend request %u accepted", numf); | ||
245 | new_lines(numchar); | ||
246 | sprintf(numchar, "[i] added friendnumber %d", num); | ||
247 | new_lines(numchar); | ||
248 | } else { | ||
249 | sprintf(numchar, "[i] failed to add friend"); | ||
250 | new_lines(numchar); | ||
251 | } | ||
241 | } | 252 | } |
242 | do_refresh(); | 253 | do_refresh(); |
243 | } | 254 | } |
@@ -330,7 +341,8 @@ void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) | |||
330 | char numchar[100]; | 341 | char numchar[100]; |
331 | sprintf(numchar, "[i] accept request with /a %u", num_requests); | 342 | sprintf(numchar, "[i] accept request with /a %u", num_requests); |
332 | new_lines(numchar); | 343 | new_lines(numchar); |
333 | memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE); | 344 | memcpy(pending_requests[num_requests].id, public_key, CLIENT_ID_SIZE); |
345 | pending_requests[num_requests].accepted = 0; | ||
334 | ++num_requests; | 346 | ++num_requests; |
335 | do_refresh(); | 347 | do_refresh(); |
336 | } | 348 | } |