diff options
-rw-r--r-- | testing/nTox_win32.c | 68 |
1 files changed, 46 insertions, 22 deletions
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 51f31001..6faae31d 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c | |||
@@ -30,18 +30,23 @@ uint8_t pending_requests[256][CLIENT_ID_SIZE]; | |||
30 | uint8_t num_requests; | 30 | uint8_t num_requests; |
31 | 31 | ||
32 | char line[STRING_LENGTH]; | 32 | char line[STRING_LENGTH]; |
33 | char users_id[200]; | ||
33 | 34 | ||
34 | void do_header() | 35 | void do_header() |
35 | { | 36 | { |
36 | printf("\n[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /q (to quit)\n\n"); | 37 | system("cls"); |
38 | printf(users_id); | ||
39 | printf("\n---------------------------------"); | ||
40 | printf("\n[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /l (lists friends), /q (to quit), /r (reset screen)"); | ||
41 | printf("\n---------------------------------"); | ||
37 | } | 42 | } |
38 | 43 | ||
39 | void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) | 44 | void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) |
40 | { | 45 | { |
41 | printf("\n[i] received friend request with message\n"); | 46 | printf("\n\n[i] received friend request with message\n"); |
42 | printf((char *)data); | 47 | printf((char *)data); |
43 | char numchar[100]; | 48 | char numchar[100]; |
44 | sprintf(numchar, "\n[i] accept request with /a %u\n", num_requests); | 49 | sprintf(numchar, "\n\n[i] accept request with /a %u\n\n", num_requests); |
45 | printf(numchar); | 50 | printf(numchar); |
46 | memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE); | 51 | memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE); |
47 | ++num_requests; | 52 | ++num_requests; |
@@ -59,7 +64,7 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length) | |||
59 | char* temp = asctime(timeinfo); | 64 | char* temp = asctime(timeinfo); |
60 | size_t len = strlen(temp); | 65 | size_t len = strlen(temp); |
61 | temp[len-1]='\0'; | 66 | temp[len-1]='\0'; |
62 | sprintf(msg, "\n[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp | 67 | sprintf(msg, "\n[%d] %s <%s> %s\n\n", friendnumber, temp, name, string); // timestamp |
63 | printf(msg); | 68 | printf(msg); |
64 | } | 69 | } |
65 | 70 | ||
@@ -68,7 +73,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) | |||
68 | char name[MAX_NAME_LENGTH]; | 73 | char name[MAX_NAME_LENGTH]; |
69 | getname(friendnumber, (uint8_t*)name); | 74 | getname(friendnumber, (uint8_t*)name); |
70 | char msg[100+length]; | 75 | char msg[100+length]; |
71 | sprintf(msg, "\n[i] [%d] %s is now known as %s.", friendnumber, name, string); | 76 | sprintf(msg, "\n\n[i] [%d] %s is now known as %s.\n\n", friendnumber, name, string); |
72 | printf(msg); | 77 | printf(msg); |
73 | } | 78 | } |
74 | 79 | ||
@@ -76,11 +81,10 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { | |||
76 | char name[MAX_NAME_LENGTH]; | 81 | char name[MAX_NAME_LENGTH]; |
77 | getname(friendnumber, (uint8_t*)name); | 82 | getname(friendnumber, (uint8_t*)name); |
78 | char msg[100+length+strlen(name)+1]; | 83 | char msg[100+length+strlen(name)+1]; |
79 | sprintf(msg, "\n[i] [%d] %s's status changed to %s.", friendnumber, name, string); | 84 | sprintf(msg, "\n\n[i] [%d] %s's status changed to %s.\n", friendnumber, name, string); |
80 | printf(msg); | 85 | printf(msg); |
81 | } | 86 | } |
82 | 87 | ||
83 | |||
84 | void load_key() | 88 | void load_key() |
85 | { | 89 | { |
86 | FILE *data_file = NULL; | 90 | FILE *data_file = NULL; |
@@ -127,6 +131,23 @@ void line_eval(char* line) | |||
127 | printf(numstring); | 131 | printf(numstring); |
128 | } | 132 | } |
129 | 133 | ||
134 | else if (line[1] == 'r') { | ||
135 | do_header(); | ||
136 | printf("\n\n"); | ||
137 | } | ||
138 | |||
139 | else if (line[1] == 'l') { | ||
140 | printf("\n[i] Friend List\n\n"); | ||
141 | |||
142 | int i; | ||
143 | |||
144 | for (i=0; i <= num_requests; i++) { | ||
145 | char name[MAX_NAME_LENGTH]; | ||
146 | getname(i, (uint8_t*)name); | ||
147 | printf("[%d] %s\n\n", i, (uint8_t*)name); | ||
148 | } | ||
149 | } | ||
150 | |||
130 | else if (line[1] == 'd') { | 151 | else if (line[1] == 'd') { |
131 | doMessenger(); | 152 | doMessenger(); |
132 | } | 153 | } |
@@ -148,7 +169,10 @@ void line_eval(char* line) | |||
148 | } | 169 | } |
149 | int num = atoi(numstring); | 170 | int num = atoi(numstring); |
150 | if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { | 171 | if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { |
151 | printf("\n[i] could not send message: %s\n\n", message); | 172 | printf("\n[i] could not send message: %s\n", message); |
173 | } else { | ||
174 | //simply for aesthetics | ||
175 | printf("\n"); | ||
152 | } | 176 | } |
153 | } | 177 | } |
154 | 178 | ||
@@ -222,14 +246,12 @@ int main(int argc, char *argv[]) | |||
222 | printf("initMessenger failed"); | 246 | printf("initMessenger failed"); |
223 | exit(0); | 247 | exit(0); |
224 | } | 248 | } |
225 | |||
226 | 249 | ||
227 | if (argc > 4) { | 250 | if (argc > 4) { |
228 | if(strncmp(argv[4], "nokey", 6) < 0) { | 251 | if(strncmp(argv[4], "nokey", 6) < 0) { |
229 | //nothing | ||
230 | } else { | ||
231 | load_key(); | ||
232 | } | 252 | } |
253 | } else { | ||
254 | load_key(); | ||
233 | } | 255 | } |
234 | 256 | ||
235 | m_callback_friendrequest(print_request); | 257 | m_callback_friendrequest(print_request); |
@@ -237,9 +259,6 @@ int main(int argc, char *argv[]) | |||
237 | m_callback_namechange(print_nickchange); | 259 | m_callback_namechange(print_nickchange); |
238 | m_callback_userstatus(print_statuschange); | 260 | m_callback_userstatus(print_statuschange); |
239 | 261 | ||
240 | system("cls"); | ||
241 | |||
242 | char idstring0[200]; | ||
243 | char idstring1[32][5]; | 262 | char idstring1[32][5]; |
244 | char idstring2[32][5]; | 263 | char idstring2[32][5]; |
245 | uint32_t i; | 264 | uint32_t i; |
@@ -251,15 +270,13 @@ int main(int argc, char *argv[]) | |||
251 | strcpy(idstring1[i], ""); | 270 | strcpy(idstring1[i], ""); |
252 | sprintf(idstring2[i], "%hhX",self_public_key[i]); | 271 | sprintf(idstring2[i], "%hhX",self_public_key[i]); |
253 | } | 272 | } |
254 | strcpy(idstring0,"\n[i] your ID: "); | 273 | strcpy(users_id,"[i] your ID: "); |
255 | for (i=0; i<32; i++) { | 274 | for (i=0; i<32; i++) { |
256 | strcat(idstring0,idstring1[i]); | 275 | strcat(users_id,idstring1[i]); |
257 | strcat(idstring0,idstring2[i]); | 276 | strcat(users_id,idstring2[i]); |
258 | } | 277 | } |
259 | 278 | ||
260 | printf(idstring0); | ||
261 | do_header(); | 279 | do_header(); |
262 | |||
263 | 280 | ||
264 | IP_Port bootstrap_ip_port; | 281 | IP_Port bootstrap_ip_port; |
265 | bootstrap_ip_port.port = htons(atoi(argv[2])); | 282 | bootstrap_ip_port.port = htons(atoi(argv[2])); |
@@ -271,15 +288,22 @@ int main(int argc, char *argv[]) | |||
271 | 288 | ||
272 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); | 289 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); |
273 | 290 | ||
274 | |||
275 | int c; | 291 | int c; |
276 | int on = 0; | 292 | int on = 0; |
277 | 293 | ||
278 | _beginthread(get_input, 0, NULL); | 294 | _beginthread(get_input, 0, NULL); |
279 | 295 | ||
280 | while(1) { | 296 | while(1) { |
297 | if (on == 1 && DHT_isconnected() == -1) { | ||
298 | printf("\n---------------------------------"); | ||
299 | printf("\n[i] Disconnected from the DHT"); | ||
300 | printf("\n---------------------------------\n\n"); | ||
301 | on = 0; | ||
302 | } | ||
303 | |||
281 | if (on == 0 && DHT_isconnected()) { | 304 | if (on == 0 && DHT_isconnected()) { |
282 | printf("\n[i] connected to DHT\n\n"); | 305 | printf("\n[i] Connected to DHT"); |
306 | printf("\n---------------------------------\n\n"); | ||
283 | on = 1; | 307 | on = 1; |
284 | } | 308 | } |
285 | 309 | ||