diff options
Diffstat (limited to 'testing')
-rw-r--r-- | testing/nTox_win32.c | 67 | ||||
-rw-r--r-- | testing/nTox_win32.h | 2 | ||||
-rw-r--r-- | testing/toxic/main.c | 2 |
3 files changed, 41 insertions, 30 deletions
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 3b6fb043..5501ecf5 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c | |||
@@ -32,6 +32,7 @@ uint32_t maxnumfriends; | |||
32 | 32 | ||
33 | char line[STRING_LENGTH]; | 33 | char line[STRING_LENGTH]; |
34 | char users_id[200]; | 34 | char users_id[200]; |
35 | int friend_request_received; | ||
35 | 36 | ||
36 | void do_header() | 37 | void do_header() |
37 | { | 38 | { |
@@ -44,10 +45,11 @@ void do_header() | |||
44 | 45 | ||
45 | void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) | 46 | void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) |
46 | { | 47 | { |
48 | friend_request_received = 1; | ||
47 | printf("\n\n[i] received friend request with message\n"); | 49 | printf("\n\n[i] received friend request with message\n"); |
48 | printf((char *)data); | 50 | printf("'%s'",(char *)data); |
49 | char numchar[100]; | 51 | char numchar[100]; |
50 | sprintf(numchar, "\n\n[i] accept request with /a %u\n\n", num_requests); | 52 | sprintf(numchar, "\n[i] accept request with /a %u\n\n", num_requests); |
51 | printf(numchar); | 53 | printf(numchar); |
52 | memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE); | 54 | memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE); |
53 | ++num_requests; | 55 | ++num_requests; |
@@ -151,23 +153,32 @@ void add_friend() | |||
151 | 153 | ||
152 | void list_friends() | 154 | void list_friends() |
153 | { | 155 | { |
154 | int activefriends = 0; | ||
155 | int i; | 156 | int i; |
157 | |||
158 | printf("\n[i] Friend List"); | ||
159 | |||
160 | printf("----- PENDING -----\n\n"); | ||
156 | 161 | ||
157 | for (i = 0; i <= maxnumfriends; i++) { | 162 | for (i = 0; i <= maxnumfriends; i++) { |
158 | if (m_friendstatus(i) == 4) | 163 | char name[MAX_NAME_LENGTH]; |
159 | activefriends++; | 164 | getname(i, (uint8_t*)name); |
165 | if (m_friendstatus(i) > 0 && m_friendstatus(i) < 4) | ||
166 | printf("[%d] %s\n", i, (uint8_t*)name); | ||
160 | } | 167 | } |
168 | |||
169 | printf("\n"); | ||
161 | 170 | ||
162 | printf("\n[i] Friend List | Total: %d\n\n", activefriends); | 171 | printf("----- ACTIVE -----\n\n"); |
163 | 172 | ||
164 | for (i = 0; i <= 256; i++) {/* TODO: fix this properly*/ | 173 | for (i = 0; i <= maxnumfriends; i++) { |
165 | char name[MAX_NAME_LENGTH]; | 174 | char name[MAX_NAME_LENGTH]; |
166 | getname(i, (uint8_t*)name); | 175 | getname(i, (uint8_t*)name); |
167 | 176 | ||
168 | if (m_friendstatus(i) == 4) | 177 | if (m_friendstatus(i) == 4) |
169 | printf("[%d] %s\n\n", i, (uint8_t*)name); | 178 | printf("[%d] %s\n", i, (uint8_t*)name); |
170 | } | 179 | } |
180 | |||
181 | printf("\n"); | ||
171 | } | 182 | } |
172 | 183 | ||
173 | void delete_friend() | 184 | void delete_friend() |
@@ -244,7 +255,7 @@ void change_nickname() | |||
244 | fclose(name_file); | 255 | fclose(name_file); |
245 | } | 256 | } |
246 | 257 | ||
247 | void change_status() | 258 | void change_status(int savetofile) |
248 | { | 259 | { |
249 | uint8_t status[MAX_USERSTATUS_LENGTH]; | 260 | uint8_t status[MAX_USERSTATUS_LENGTH]; |
250 | int i = 0; | 261 | int i = 0; |
@@ -263,20 +274,21 @@ void change_status() | |||
263 | sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); | 274 | sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); |
264 | printf(numstring); | 275 | printf(numstring); |
265 | 276 | ||
266 | FILE* status_file = NULL; | 277 | if (savetofile == 1) { |
267 | status_file = fopen("statusfile.txt", "w"); | 278 | FILE* status_file = NULL; |
268 | fprintf(status_file, "%s", (char*)status); | 279 | status_file = fopen("statusfile.txt", "w"); |
269 | fclose(status_file); | 280 | fprintf(status_file, "%s", (char*)status); |
281 | fclose(status_file); | ||
282 | } | ||
270 | } | 283 | } |
271 | 284 | ||
272 | void accept_friend_request() | 285 | void accept_friend_request() |
273 | { | 286 | { |
287 | friend_request_received = 0; | ||
274 | uint8_t numf = atoi(line + 3); | 288 | uint8_t numf = atoi(line + 3); |
275 | char numchar[100]; | 289 | char numchar[100]; |
276 | sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf); | ||
277 | printf(numchar); | ||
278 | int num = m_addfriend_norequest(pending_requests[numf]); | 290 | int num = m_addfriend_norequest(pending_requests[numf]); |
279 | sprintf(numchar, "\n[i] added friendnumber %d\n\n", num); | 291 | sprintf(numchar, "\n[i] Added friendnumber: %d\n\n", num); |
280 | printf(numchar); | 292 | printf(numchar); |
281 | ++maxnumfriends; | 293 | ++maxnumfriends; |
282 | } | 294 | } |
@@ -288,7 +300,7 @@ void line_eval(char* line) | |||
288 | char inpt_command = line[1]; | 300 | char inpt_command = line[1]; |
289 | 301 | ||
290 | if(inpt_command == 'f') { | 302 | if(inpt_command == 'f') { |
291 | add_friend(line); | 303 | add_friend(); |
292 | } | 304 | } |
293 | 305 | ||
294 | else if (inpt_command == 'r') { | 306 | else if (inpt_command == 'r') { |
@@ -297,32 +309,33 @@ void line_eval(char* line) | |||
297 | } | 309 | } |
298 | 310 | ||
299 | else if (inpt_command == 'l') { | 311 | else if (inpt_command == 'l') { |
300 | list_friends(line); | 312 | list_friends(); |
301 | } | 313 | } |
302 | 314 | ||
303 | else if (inpt_command == 'd') { | 315 | else if (inpt_command == 'd') { |
304 | delete_friend(line); | 316 | delete_friend(); |
305 | } | 317 | } |
306 | /* Send message to friend */ | 318 | /* Send message to friend */ |
307 | else if (inpt_command == 'm') { | 319 | else if (inpt_command == 'm') { |
308 | message_friend(line); | 320 | message_friend(); |
309 | } | 321 | } |
310 | 322 | ||
311 | else if (inpt_command == 'n') { | 323 | else if (inpt_command == 'n') { |
312 | change_nickname(line); | 324 | change_nickname(); |
313 | } | 325 | } |
314 | 326 | ||
315 | else if (inpt_command == 's') { | 327 | else if (inpt_command == 's') { |
316 | change_status(line); | 328 | change_status(1); |
317 | } | 329 | } |
318 | 330 | ||
319 | else if (inpt_command == 'a') { | 331 | else if (inpt_command == 'a') { |
320 | accept_friend_request(line); | 332 | if (friend_request_received == 1) |
333 | accept_friend_request(line); | ||
321 | } | 334 | } |
322 | /* EXIT */ | 335 | /* EXIT */ |
323 | else if (inpt_command == 'q') { | 336 | else if (inpt_command == 'q') { |
324 | uint8_t status[MAX_USERSTATUS_LENGTH] = "Offline"; | 337 | strcpy(line, "---Offline"); |
325 | m_set_userstatus(status, strlen((char*)status)); | 338 | change_status(0); |
326 | exit(EXIT_SUCCESS); | 339 | exit(EXIT_SUCCESS); |
327 | } | 340 | } |
328 | } | 341 | } |
@@ -368,8 +381,7 @@ int main(int argc, char *argv[]) | |||
368 | nameloaded = 1; | 381 | nameloaded = 1; |
369 | printf("%s\n", name); | 382 | printf("%s\n", name); |
370 | fclose(name_file); | 383 | fclose(name_file); |
371 | } | 384 | } |
372 | |||
373 | 385 | ||
374 | FILE* status_file = NULL; | 386 | FILE* status_file = NULL; |
375 | status_file = fopen("statusfile.txt", "r"); | 387 | status_file = fopen("statusfile.txt", "r"); |
@@ -383,7 +395,6 @@ int main(int argc, char *argv[]) | |||
383 | printf("%s\n", status); | 395 | printf("%s\n", status); |
384 | fclose(status_file); | 396 | fclose(status_file); |
385 | } | 397 | } |
386 | |||
387 | 398 | ||
388 | m_callback_friendrequest(print_request); | 399 | m_callback_friendrequest(print_request); |
389 | m_callback_friendmessage(print_message); | 400 | m_callback_friendmessage(print_message); |
diff --git a/testing/nTox_win32.h b/testing/nTox_win32.h index 211ac95f..271403b8 100644 --- a/testing/nTox_win32.h +++ b/testing/nTox_win32.h | |||
@@ -39,7 +39,7 @@ void list_friends(); | |||
39 | void delete_friend(); | 39 | void delete_friend(); |
40 | void message_friend(); | 40 | void message_friend(); |
41 | void change_nickname(); | 41 | void change_nickname(); |
42 | void change_status(); | 42 | void change_status(int savetofile); |
43 | void accept_friend_request(); | 43 | void accept_friend_request(); |
44 | void line_eval(char* line); | 44 | void line_eval(char* line); |
45 | void get_input(); | 45 | void get_input(); |
diff --git a/testing/toxic/main.c b/testing/toxic/main.c index bcfc487f..391b0b39 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c | |||
@@ -50,7 +50,7 @@ void on_request(uint8_t* public_key, uint8_t* data, uint16_t length) { | |||
50 | void on_message(int friendnumber, uint8_t* string, uint16_t length) { | 50 | void on_message(int friendnumber, uint8_t* string, uint16_t length) { |
51 | size_t i; | 51 | size_t i; |
52 | 52 | ||
53 | wprintw(prompt->window, "\n(message) %d: %s!\n", friendnumber, string); | 53 | wprintw(prompt->window, "\n(message) %d: %s\n", friendnumber, string); |
54 | 54 | ||
55 | for(i=0; i<w_num; i++) { | 55 | for(i=0; i<w_num; i++) { |
56 | if(windows[i].onMessage != NULL) | 56 | if(windows[i].onMessage != NULL) |