summaryrefslogtreecommitdiff
path: root/testing/nTox.c
diff options
context:
space:
mode:
authorTim Malte Gräfje <Tim.Graefje@gmx.de>2013-08-04 01:46:54 +0200
committerTim Malte Gräfje <Tim.Graefje@gmx.de>2013-08-04 01:46:54 +0200
commit5817c2c888ec930b8adfca78cd4fd5b026a1ccfa (patch)
tree65e776033172373d83263d4b8910be69a3839c3b /testing/nTox.c
parent68317c8d51f0cf437e018a74a2108c95c38648a2 (diff)
fix for #288
nTox will now display a message if you try to accept a not yet received or already accepted friend request
Diffstat (limited to 'testing/nTox.c')
-rw-r--r--testing/nTox.c30
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)";
43int x, y; 43int x, y;
44 44
45uint8_t pending_requests[256][CLIENT_ID_SIZE]; 45typedef struct {
46 uint8_t id[CLIENT_ID_SIZE];
47 uint8_t accepted;
48} Friend_request;
49
50Friend_request pending_requests[256];
46uint8_t num_requests = 0; 51uint8_t num_requests = 0;
47 52
48void get_id(char *data) 53void 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}