diff options
Diffstat (limited to 'testing/nTox.c')
-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 ec597bc3..fe91b1fa 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) |
@@ -231,15 +236,21 @@ void line_eval(char *line) | |||
231 | else if (inpt_command == 'a') { | 236 | else if (inpt_command == 'a') { |
232 | uint8_t numf = atoi(line + 3); | 237 | uint8_t numf = atoi(line + 3); |
233 | char numchar[100]; | 238 | char numchar[100]; |
234 | int num = m_addfriend_norequest(pending_requests[numf]); | 239 | if (numf >= num_requests || pending_requests[numf].accepted) { |
235 | if (num != -1) { | 240 | sprintf(numchar,"[i] you either didn't receive that request or you already accepted it"); |
236 | sprintf(numchar, "[i] friend request %u accepted", numf); | ||
237 | new_lines(numchar); | ||
238 | sprintf(numchar, "[i] added friendnumber %d", num); | ||
239 | new_lines(numchar); | 241 | new_lines(numchar); |
240 | } else { | 242 | } else { |
241 | sprintf(numchar, "[i] failed to add friend"); | 243 | int num = m_addfriend_norequest(pending_requests[numf].id); |
242 | new_lines(numchar); | 244 | if (num != -1) { |
245 | pending_requests[numf].accepted = 1; | ||
246 | sprintf(numchar, "[i] friend request %u accepted", numf); | ||
247 | new_lines(numchar); | ||
248 | sprintf(numchar, "[i] added friendnumber %d", num); | ||
249 | new_lines(numchar); | ||
250 | } else { | ||
251 | sprintf(numchar, "[i] failed to add friend"); | ||
252 | new_lines(numchar); | ||
253 | } | ||
243 | } | 254 | } |
244 | do_refresh(); | 255 | do_refresh(); |
245 | } | 256 | } |
@@ -332,7 +343,8 @@ void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) | |||
332 | char numchar[100]; | 343 | char numchar[100]; |
333 | sprintf(numchar, "[i] accept request with /a %u", num_requests); | 344 | sprintf(numchar, "[i] accept request with /a %u", num_requests); |
334 | new_lines(numchar); | 345 | new_lines(numchar); |
335 | memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE); | 346 | memcpy(pending_requests[num_requests].id, public_key, CLIENT_ID_SIZE); |
347 | pending_requests[num_requests].accepted = 0; | ||
336 | ++num_requests; | 348 | ++num_requests; |
337 | do_refresh(); | 349 | do_refresh(); |
338 | } | 350 | } |