diff options
author | Astonex <softukitu@gmail.com> | 2013-07-31 23:02:09 +0100 |
---|---|---|
committer | Astonex <softukitu@gmail.com> | 2013-07-31 23:02:09 +0100 |
commit | f05aa308701f33f3bf9df022a4b376deeedef235 (patch) | |
tree | c10b8a3cca6822400853bfd3bc2c5fd1cca73f83 /testing/nTox_win32.c | |
parent | 8dfba27242ca23fca5de852541f2101568dbf7cb (diff) | |
parent | c558cb63f6db35bd51f2f2331e21df03105ee82a (diff) |
Merge remote-tracking branch 'ProjectTox/master'
Diffstat (limited to 'testing/nTox_win32.c')
-rw-r--r-- | testing/nTox_win32.c | 87 |
1 files changed, 37 insertions, 50 deletions
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 514ce463..ad114f46 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c | |||
@@ -27,7 +27,7 @@ | |||
27 | #include <process.h> | 27 | #include <process.h> |
28 | 28 | ||
29 | uint8_t pending_requests[256][CLIENT_ID_SIZE]; | 29 | uint8_t pending_requests[256][CLIENT_ID_SIZE]; |
30 | uint8_t num_requests; | 30 | uint8_t num_requests = 0; |
31 | 31 | ||
32 | char line[STRING_LENGTH]; | 32 | char line[STRING_LENGTH]; |
33 | char users_id[200]; | 33 | char users_id[200]; |
@@ -89,14 +89,13 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) | |||
89 | void load_key() | 89 | void load_key() |
90 | { | 90 | { |
91 | FILE *data_file = NULL; | 91 | FILE *data_file = NULL; |
92 | 92 | data_file = fopen("data","r"); | |
93 | if ((data_file = fopen("data", "r"))) { | 93 | if (data_file) { |
94 | fseek(data_file, 0, SEEK_END); | 94 | fseek(data_file, 0, SEEK_END); |
95 | int size = ftell(data_file); | 95 | int size = ftell(data_file); |
96 | fseek(data_file, 0, SEEK_SET); | 96 | fseek(data_file, 0, SEEK_SET); |
97 | uint8_t data[size]; | 97 | uint8_t data[size]; |
98 | 98 | if (fread(data, sizeof(uint8_t), size, data_file) != size) { | |
99 | if(fread(data, sizeof(uint8_t), size, data_file) != size) { | ||
100 | printf("\n[i] Could not read the data file. Exiting."); | 99 | printf("\n[i] Could not read the data file. Exiting."); |
101 | exit(1); | 100 | exit(1); |
102 | } | 101 | } |
@@ -108,23 +107,23 @@ void load_key() | |||
108 | Messenger_save(data); | 107 | Messenger_save(data); |
109 | data_file = fopen("data", "w"); | 108 | data_file = fopen("data", "w"); |
110 | 109 | ||
111 | if(fwrite(data, sizeof(uint8_t), size, data_file) != size) { | 110 | if (fwrite(data, sizeof(uint8_t), size, data_file) != size) { |
112 | printf("\n[i] Could not write data to file. Exiting."); | 111 | printf("\n[i] Could not write data to file. Exiting."); |
113 | exit(1); | 112 | exit(1); |
114 | } | 113 | } |
115 | } | 114 | } |
116 | |||
117 | fclose(data_file); | 115 | fclose(data_file); |
118 | } | 116 | } |
119 | 117 | ||
120 | void line_eval(char* line) | 118 | void line_eval(char* line) |
121 | { | 119 | { |
122 | if(line[0] == '/') { | 120 | if(line[0] == '/') { |
121 | char inpt_command = line[1]; | ||
123 | /* Add friend */ | 122 | /* Add friend */ |
124 | if(line[1] == 'f') { | 123 | if(inpt_command == 'f') { |
125 | int i; | 124 | int i; |
126 | char temp_id[128]; | 125 | char temp_id[128]; |
127 | for (i=0; i<128; i++) | 126 | for (i = 0; i < 128; i++) |
128 | temp_id[i] = line[i+3]; | 127 | temp_id[i] = line[i+3]; |
129 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); | 128 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); |
130 | char numstring[100]; | 129 | char numstring[100]; |
@@ -132,17 +131,16 @@ void line_eval(char* line) | |||
132 | printf(numstring); | 131 | printf(numstring); |
133 | } | 132 | } |
134 | 133 | ||
135 | else if (line[1] == 'r') { | 134 | else if (inpt_command == 'r') { |
136 | do_header(); | 135 | do_header(); |
137 | printf("\n\n"); | 136 | printf("\n\n"); |
138 | } | 137 | } |
139 | 138 | ||
140 | else if (line[1] == 'l') { | 139 | else if (inpt_command == 'l') { |
141 | printf("\n[i] Friend List | Total: %d\n\n", getnumfriends()); | 140 | printf("\n[i] Friend List | Total: %d\n\n", getnumfriends()); |
142 | 141 | ||
143 | int i; | 142 | int i; |
144 | 143 | for (i = 0; i < getnumfriends(); i++) { | |
145 | for (i=0; i < getnumfriends(); i++) { | ||
146 | char name[MAX_NAME_LENGTH]; | 144 | char name[MAX_NAME_LENGTH]; |
147 | getname(i, (uint8_t*)name); | 145 | getname(i, (uint8_t*)name); |
148 | if (m_friendstatus(i) == 0) | 146 | if (m_friendstatus(i) == 0) |
@@ -152,11 +150,11 @@ void line_eval(char* line) | |||
152 | } | 150 | } |
153 | } | 151 | } |
154 | 152 | ||
155 | else if (line[1] == 'd') { | 153 | else if (inpt_command == 'd') { |
156 | size_t len = strlen(line); | 154 | size_t len = strlen(line); |
157 | char numstring[len-3]; | 155 | char numstring[len-3]; |
158 | int i; | 156 | int i; |
159 | for (i=0; i<len; i++) { | 157 | for (i = 0; i < len; i++) { |
160 | if (line[i+3] != ' ') { | 158 | if (line[i+3] != ' ') { |
161 | numstring[i] = line[i+3]; | 159 | numstring[i] = line[i+3]; |
162 | } | 160 | } |
@@ -166,17 +164,17 @@ void line_eval(char* line) | |||
166 | printf("\n\n"); | 164 | printf("\n\n"); |
167 | } | 165 | } |
168 | /* Send message to friend */ | 166 | /* Send message to friend */ |
169 | else if (line[1] == 'm') { | 167 | else if (inpt_command == 'm') { |
170 | int i; | ||
171 | size_t len = strlen(line); | 168 | size_t len = strlen(line); |
172 | char numstring[len-3]; | 169 | char numstring[len-3]; |
173 | char message[len-3]; | 170 | char message[len-3]; |
174 | for (i=0; i<len; i++) { | 171 | int i; |
172 | for (i = 0; i < len; i++) { | ||
175 | if (line[i+3] != ' ') { | 173 | if (line[i+3] != ' ') { |
176 | numstring[i] = line[i+3]; | 174 | numstring[i] = line[i+3]; |
177 | } else { | 175 | } else { |
178 | int j; | 176 | int j; |
179 | for (j=i+1; j<len; j++) | 177 | for (j = (i+1); j < len; j++) |
180 | message[j-i-1] = line[j+3]; | 178 | message[j-i-1] = line[j+3]; |
181 | break; | 179 | break; |
182 | } | 180 | } |
@@ -190,37 +188,37 @@ void line_eval(char* line) | |||
190 | } | 188 | } |
191 | } | 189 | } |
192 | 190 | ||
193 | else if (line[1] == 'n') { | 191 | else if (inpt_command == 'n') { |
194 | uint8_t name[MAX_NAME_LENGTH]; | 192 | uint8_t name[MAX_NAME_LENGTH]; |
195 | int i = 0; | 193 | int i = 0; |
196 | size_t len = strlen(line); | 194 | size_t len = strlen(line); |
197 | for (i=3; i<len; i++) { | 195 | for (i = 3; i < len; i++) { |
198 | if (line[i] == 0 || line[i] == '\n') break; | 196 | if (line[i] == 0 || line[i] == '\n') break; |
199 | name[i - 3] = line[i]; | 197 | name[i-3] = line[i]; |
200 | } | 198 | } |
201 | name[i - 3] = 0; | 199 | name[i-3] = 0; |
202 | setname(name, i); | 200 | setname(name, i); |
203 | char numstring[100]; | 201 | char numstring[100]; |
204 | sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name); | 202 | sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name); |
205 | printf(numstring); | 203 | printf(numstring); |
206 | } | 204 | } |
207 | 205 | ||
208 | else if (line[1] == 's') { | 206 | else if (inpt_command == 's') { |
209 | uint8_t status[MAX_USERSTATUS_LENGTH]; | 207 | uint8_t status[MAX_USERSTATUS_LENGTH]; |
210 | int i = 0; | 208 | int i = 0; |
211 | size_t len = strlen(line); | 209 | size_t len = strlen(line); |
212 | for (i=3; i<len; i++) { | 210 | for (i = 3; i < len; i++) { |
213 | if (line[i] == 0 || line[i] == '\n') break; | 211 | if (line[i] == 0 || line[i] == '\n') break; |
214 | status[i - 3] = line[i]; | 212 | status[i-3] = line[i]; |
215 | } | 213 | } |
216 | status[i - 3] = 0; | 214 | status[i-3] = 0; |
217 | m_set_userstatus(status, strlen((char*)status)); | 215 | m_set_userstatus(status, strlen((char*)status)); |
218 | char numstring[100]; | 216 | char numstring[100]; |
219 | sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); | 217 | sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); |
220 | printf(numstring); | 218 | printf(numstring); |
221 | } | 219 | } |
222 | 220 | ||
223 | else if (line[1] == 'a') { | 221 | else if (inpt_command == 'a') { |
224 | uint8_t numf = atoi(line + 3); | 222 | uint8_t numf = atoi(line + 3); |
225 | char numchar[100]; | 223 | char numchar[100]; |
226 | sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf); | 224 | sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf); |
@@ -230,12 +228,10 @@ void line_eval(char* line) | |||
230 | printf(numchar); | 228 | printf(numchar); |
231 | } | 229 | } |
232 | /* EXIT */ | 230 | /* EXIT */ |
233 | else if (line[1] == 'q') { | 231 | else if (inpt_command == 'q') { |
234 | exit(EXIT_SUCCESS); | 232 | exit(EXIT_SUCCESS); |
235 | } | 233 | } |
236 | } | 234 | } else { |
237 | |||
238 | else { | ||
239 | //nothing atm | 235 | //nothing atm |
240 | } | 236 | } |
241 | } | 237 | } |
@@ -255,12 +251,10 @@ int main(int argc, char *argv[]) | |||
255 | printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]); | 251 | printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]); |
256 | exit(0); | 252 | exit(0); |
257 | } | 253 | } |
258 | |||
259 | if (initMessenger() == -1) { | 254 | if (initMessenger() == -1) { |
260 | printf("initMessenger failed"); | 255 | printf("initMessenger failed"); |
261 | exit(0); | 256 | exit(0); |
262 | } | 257 | } |
263 | |||
264 | if (argc > 4) { | 258 | if (argc > 4) { |
265 | if(strncmp(argv[4], "nokey", 6) < 0) { | 259 | if(strncmp(argv[4], "nokey", 6) < 0) { |
266 | } | 260 | } |
@@ -272,26 +266,25 @@ int main(int argc, char *argv[]) | |||
272 | m_callback_friendmessage(print_message); | 266 | m_callback_friendmessage(print_message); |
273 | m_callback_namechange(print_nickchange); | 267 | m_callback_namechange(print_nickchange); |
274 | m_callback_userstatus(print_statuschange); | 268 | m_callback_userstatus(print_statuschange); |
275 | 269 | char idstring1[PUB_KEY_BYTES][5]; | |
276 | char idstring1[32][5]; | 270 | char idstring2[PUB_KEY_BYTES][5]; |
277 | char idstring2[32][5]; | 271 | int i; |
278 | uint32_t i; | 272 | for(i = 0; i < PUB_KEY_BYTES; i++) |
279 | for(i = 0; i < 32; i++) | ||
280 | { | 273 | { |
281 | if(self_public_key[i] < 16) | 274 | if(self_public_key[i] < (PUB_KEY_BYTES/2)) |
282 | strcpy(idstring1[i],"0"); | 275 | strcpy(idstring1[i],"0"); |
283 | else | 276 | else |
284 | strcpy(idstring1[i], ""); | 277 | strcpy(idstring1[i], ""); |
285 | sprintf(idstring2[i], "%hhX",self_public_key[i]); | 278 | sprintf(idstring2[i], "%hhX",self_public_key[i]); |
286 | } | 279 | } |
287 | strcpy(users_id,"[i] your ID: "); | 280 | strcpy(users_id,"[i] your ID: "); |
288 | for (i=0; i<32; i++) { | 281 | int j; |
289 | strcat(users_id,idstring1[i]); | 282 | for (j = 0; j < PUB_KEY_BYTES; j++) { |
290 | strcat(users_id,idstring2[i]); | 283 | strcat(users_id,idstring1[j]); |
284 | strcat(users_id,idstring2[j]); | ||
291 | } | 285 | } |
292 | 286 | ||
293 | do_header(); | 287 | do_header(); |
294 | |||
295 | IP_Port bootstrap_ip_port; | 288 | IP_Port bootstrap_ip_port; |
296 | bootstrap_ip_port.port = htons(atoi(argv[2])); | 289 | bootstrap_ip_port.port = htons(atoi(argv[2])); |
297 | int resolved_address = resolve_addr(argv[1]); | 290 | int resolved_address = resolve_addr(argv[1]); |
@@ -301,12 +294,9 @@ int main(int argc, char *argv[]) | |||
301 | exit(1); | 294 | exit(1); |
302 | 295 | ||
303 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); | 296 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); |
304 | |||
305 | int c; | 297 | int c; |
306 | int on = 0; | 298 | int on = 0; |
307 | |||
308 | _beginthread(get_input, 0, NULL); | 299 | _beginthread(get_input, 0, NULL); |
309 | |||
310 | while(1) { | 300 | while(1) { |
311 | if (on == 1 && DHT_isconnected() == -1) { | 301 | if (on == 1 && DHT_isconnected() == -1) { |
312 | printf("\n---------------------------------"); | 302 | printf("\n---------------------------------"); |
@@ -314,16 +304,13 @@ int main(int argc, char *argv[]) | |||
314 | printf("\n---------------------------------\n\n"); | 304 | printf("\n---------------------------------\n\n"); |
315 | on = 0; | 305 | on = 0; |
316 | } | 306 | } |
317 | |||
318 | if (on == 0 && DHT_isconnected()) { | 307 | if (on == 0 && DHT_isconnected()) { |
319 | printf("\n[i] Connected to DHT"); | 308 | printf("\n[i] Connected to DHT"); |
320 | printf("\n---------------------------------\n\n"); | 309 | printf("\n---------------------------------\n\n"); |
321 | on = 1; | 310 | on = 1; |
322 | } | 311 | } |
323 | |||
324 | doMessenger(); | 312 | doMessenger(); |
325 | Sleep(1); | 313 | Sleep(1); |
326 | } | 314 | } |
327 | |||
328 | return 0; | 315 | return 0; |
329 | } \ No newline at end of file | 316 | } \ No newline at end of file |