diff options
-rw-r--r-- | core/Messenger.c | 2 | ||||
-rw-r--r-- | testing/cmake/nTox_win32.cmake | 2 | ||||
-rw-r--r-- | testing/nTox_win32.c | 116 | ||||
-rw-r--r-- | testing/nTox_win32.h | 8 |
4 files changed, 97 insertions, 31 deletions
diff --git a/core/Messenger.c b/core/Messenger.c index 872d7407..eb59b81a 100644 --- a/core/Messenger.c +++ b/core/Messenger.c | |||
@@ -166,11 +166,13 @@ int m_delfriend(int friendnumber) | |||
166 | free(friendlist[friendnumber].userstatus); | 166 | free(friendlist[friendnumber].userstatus); |
167 | memset(&friendlist[friendnumber], 0, sizeof(Friend)); | 167 | memset(&friendlist[friendnumber], 0, sizeof(Friend)); |
168 | uint32_t i; | 168 | uint32_t i; |
169 | |||
169 | for (i = numfriends; i != 0; --i) { | 170 | for (i = numfriends; i != 0; --i) { |
170 | if (friendlist[i-1].status != 0) | 171 | if (friendlist[i-1].status != 0) |
171 | break; | 172 | break; |
172 | } | 173 | } |
173 | numfriends = i; | 174 | numfriends = i; |
175 | |||
174 | return 0; | 176 | return 0; |
175 | } | 177 | } |
176 | 178 | ||
diff --git a/testing/cmake/nTox_win32.cmake b/testing/cmake/nTox_win32.cmake index 5acfb411..0e33913f 100644 --- a/testing/cmake/nTox_win32.cmake +++ b/testing/cmake/nTox_win32.cmake | |||
@@ -5,5 +5,5 @@ set(exe_name nTox_win32) | |||
5 | 5 | ||
6 | add_executable(${exe_name} | 6 | add_executable(${exe_name} |
7 | nTox_win32.c misc_tools.c) | 7 | nTox_win32.c misc_tools.c) |
8 | 8 | ||
9 | linkCoreLibraries(${exe_name}) | 9 | linkCoreLibraries(${exe_name}) |
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 50f551de..b9208d4f 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c | |||
@@ -77,11 +77,12 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) | |||
77 | printf(msg); | 77 | printf(msg); |
78 | } | 78 | } |
79 | 79 | ||
80 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { | 80 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) |
81 | { | ||
81 | char name[MAX_NAME_LENGTH]; | 82 | char name[MAX_NAME_LENGTH]; |
82 | getname(friendnumber, (uint8_t*)name); | 83 | getname(friendnumber, (uint8_t*)name); |
83 | char msg[100+length+strlen(name)+1]; | 84 | char msg[100+length+strlen(name)+1]; |
84 | sprintf(msg, "\n\n[i] [%d] %s's status changed to %s.\n", friendnumber, name, string); | 85 | sprintf(msg, "\n\n[i] [%d] %s's status changed to %s.\n\n", friendnumber, name, string); |
85 | printf(msg); | 86 | printf(msg); |
86 | } | 87 | } |
87 | 88 | ||
@@ -125,29 +126,19 @@ void line_eval(char* line) | |||
125 | for (i = 0; i < 128; i++) | 126 | for (i = 0; i < 128; i++) |
126 | temp_id[i] = line[i+3]; | 127 | temp_id[i] = line[i+3]; |
127 | 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")); |
128 | char numstring[100]; | 129 | if (num >= 0) { |
129 | switch (num) { | 130 | char numstring[100]; |
130 | case -1: | 131 | sprintf(numstring, "\n[i] Friend request sent. Wait to be accepted. Friend id: %d\n\n", num); |
131 | sprintf(numstring, "[i] Incorrect key length"); | 132 | printf(numstring); |
132 | printf(numstring); | ||
133 | break; | ||
134 | case -2: | ||
135 | sprintf(numstring, "[i] That appears to be your own key"); | ||
136 | printf(numstring); | ||
137 | break; | ||
138 | case -3: | ||
139 | sprintf(numstring, "[i] Friend request already sent"); | ||
140 | printf(numstring); | ||
141 | break; | ||
142 | case -4: | ||
143 | sprintf(numstring, "[i] Could not add friend"); | ||
144 | printf(numstring); | ||
145 | break; | ||
146 | default: | ||
147 | sprintf(numstring, "\n[i] added friend %d\n\n", num); | ||
148 | printf(numstring); | ||
149 | break; | ||
150 | } | 133 | } |
134 | else if (num == -1) | ||
135 | printf("\nWrong key size\n\n"); | ||
136 | else if (num == -2) | ||
137 | printf("\nYou can't add yourself\n\n"); | ||
138 | else if (num == -3) | ||
139 | printf("\nYou already have this person added\n\n"); | ||
140 | else if (num == -4) | ||
141 | printf("\nUndefined error when adding friend"); | ||
151 | } | 142 | } |
152 | 143 | ||
153 | else if (inpt_command == 'r') { | 144 | else if (inpt_command == 'r') { |
@@ -156,13 +147,22 @@ void line_eval(char* line) | |||
156 | } | 147 | } |
157 | 148 | ||
158 | else if (inpt_command == 'l') { | 149 | else if (inpt_command == 'l') { |
159 | printf("\n[i] Friend List | Total: %d\n\n", getnumfriends()); | 150 | int activefriends = 0; |
160 | |||
161 | int i; | 151 | int i; |
162 | for (i = 0; i < getnumfriends(); i++) { | 152 | |
153 | for (i = 0; i <= getnumfriends(); i++) | ||
154 | { | ||
155 | if (m_friendstatus(i) == 4) | ||
156 | activefriends++; | ||
157 | } | ||
158 | |||
159 | printf("\n[i] Friend List | Total: %d\n\n", activefriends); | ||
160 | |||
161 | for (i = 0; i <= getnumfriends(); i++) { | ||
163 | char name[MAX_NAME_LENGTH]; | 162 | char name[MAX_NAME_LENGTH]; |
164 | getname(i, (uint8_t*)name); | 163 | getname(i, (uint8_t*)name); |
165 | printf("[%d] %s\n\n", i, (uint8_t*)name); | 164 | if (m_friendstatus(i) == 4) |
165 | printf("[%d] %s\n\n", i, (uint8_t*)name); | ||
166 | } | 166 | } |
167 | } | 167 | } |
168 | 168 | ||
@@ -177,6 +177,7 @@ void line_eval(char* line) | |||
177 | } | 177 | } |
178 | int num = atoi(numstring); | 178 | int num = atoi(numstring); |
179 | m_delfriend(num); | 179 | m_delfriend(num); |
180 | printf("\n\n"); | ||
180 | } | 181 | } |
181 | /* Send message to friend */ | 182 | /* Send message to friend */ |
182 | else if (inpt_command == 'm') { | 183 | else if (inpt_command == 'm') { |
@@ -196,7 +197,7 @@ void line_eval(char* line) | |||
196 | } | 197 | } |
197 | int num = atoi(numstring); | 198 | int num = atoi(numstring); |
198 | if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { | 199 | if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { |
199 | printf("\n[i] could not send message: %s\n", message); | 200 | printf("\n[i] could not send message (they may be offline): %s\n", message); |
200 | } else { | 201 | } else { |
201 | //simply for aesthetics | 202 | //simply for aesthetics |
202 | printf("\n"); | 203 | printf("\n"); |
@@ -216,6 +217,11 @@ void line_eval(char* line) | |||
216 | char numstring[100]; | 217 | char numstring[100]; |
217 | sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name); | 218 | sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name); |
218 | printf(numstring); | 219 | printf(numstring); |
220 | |||
221 | FILE *name_file = NULL; | ||
222 | name_file = fopen("namefile.txt", "w"); | ||
223 | fprintf(name_file, "%s", (char*)name); | ||
224 | fclose(name_file); | ||
219 | } | 225 | } |
220 | 226 | ||
221 | else if (inpt_command == 's') { | 227 | else if (inpt_command == 's') { |
@@ -231,6 +237,11 @@ void line_eval(char* line) | |||
231 | char numstring[100]; | 237 | char numstring[100]; |
232 | sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); | 238 | sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); |
233 | printf(numstring); | 239 | printf(numstring); |
240 | |||
241 | FILE* status_file = NULL; | ||
242 | status_file = fopen("statusfile.txt", "w"); | ||
243 | fprintf(status_file, "%s", (char*)status); | ||
244 | fclose(status_file); | ||
234 | } | 245 | } |
235 | 246 | ||
236 | else if (inpt_command == 'a') { | 247 | else if (inpt_command == 'a') { |
@@ -244,6 +255,8 @@ void line_eval(char* line) | |||
244 | } | 255 | } |
245 | /* EXIT */ | 256 | /* EXIT */ |
246 | else if (inpt_command == 'q') { | 257 | else if (inpt_command == 'q') { |
258 | uint8_t status[MAX_USERSTATUS_LENGTH] = "Offline"; | ||
259 | m_set_userstatus(status, strlen((char*)status)); | ||
247 | exit(EXIT_SUCCESS); | 260 | exit(EXIT_SUCCESS); |
248 | } | 261 | } |
249 | } else { | 262 | } else { |
@@ -276,7 +289,36 @@ int main(int argc, char *argv[]) | |||
276 | } else { | 289 | } else { |
277 | load_key(); | 290 | load_key(); |
278 | } | 291 | } |
279 | 292 | ||
293 | int nameloaded = 0; | ||
294 | int statusloaded = 0; | ||
295 | |||
296 | FILE* name_file = NULL; | ||
297 | name_file = fopen("namefile.txt", "r"); | ||
298 | if(name_file) { | ||
299 | uint8_t name[MAX_NAME_LENGTH]; | ||
300 | while (fgets(line, MAX_NAME_LENGTH, name_file) != NULL) { | ||
301 | sscanf(line, "%s", (char*)name); | ||
302 | } | ||
303 | setname(name, strlen((char*)name)+1); | ||
304 | nameloaded = 1; | ||
305 | printf("%s\n", name); | ||
306 | } | ||
307 | fclose(name_file); | ||
308 | |||
309 | FILE* status_file = NULL; | ||
310 | status_file = fopen("statusfile.txt", "r"); | ||
311 | if(status_file) { | ||
312 | uint8_t status[MAX_USERSTATUS_LENGTH]; | ||
313 | while (fgets(line, MAX_USERSTATUS_LENGTH, status_file) != NULL) { | ||
314 | sscanf(line, "%s", (char*)status); | ||
315 | } | ||
316 | m_set_userstatus(status, strlen((char*)status)+1); | ||
317 | statusloaded = 1; | ||
318 | printf("%s\n", status); | ||
319 | } | ||
320 | fclose(status_file); | ||
321 | |||
280 | m_callback_friendrequest(print_request); | 322 | m_callback_friendrequest(print_request); |
281 | m_callback_friendmessage(print_message); | 323 | m_callback_friendmessage(print_message); |
282 | m_callback_namechange(print_nickchange); | 324 | m_callback_namechange(print_nickchange); |
@@ -300,6 +342,7 @@ int main(int argc, char *argv[]) | |||
300 | } | 342 | } |
301 | 343 | ||
302 | do_header(); | 344 | do_header(); |
345 | |||
303 | IP_Port bootstrap_ip_port; | 346 | IP_Port bootstrap_ip_port; |
304 | bootstrap_ip_port.port = htons(atoi(argv[2])); | 347 | bootstrap_ip_port.port = htons(atoi(argv[2])); |
305 | int resolved_address = resolve_addr(argv[1]); | 348 | int resolved_address = resolve_addr(argv[1]); |
@@ -309,9 +352,22 @@ int main(int argc, char *argv[]) | |||
309 | exit(1); | 352 | exit(1); |
310 | 353 | ||
311 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); | 354 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); |
355 | |||
312 | int c; | 356 | int c; |
313 | int on = 0; | 357 | int on = 0; |
358 | |||
314 | _beginthread(get_input, 0, NULL); | 359 | _beginthread(get_input, 0, NULL); |
360 | |||
361 | if (nameloaded == 1) { | ||
362 | printf("\nNickname automatically loaded"); | ||
363 | printf("\n---------------------------------"); | ||
364 | } | ||
365 | |||
366 | if (statusloaded == 1) { | ||
367 | printf("\nStatus automatically loaded"); | ||
368 | printf("\n---------------------------------"); | ||
369 | } | ||
370 | |||
315 | while(1) { | 371 | while(1) { |
316 | if (on == 1 && DHT_isconnected() == -1) { | 372 | if (on == 1 && DHT_isconnected() == -1) { |
317 | printf("\n---------------------------------"); | 373 | printf("\n---------------------------------"); |
diff --git a/testing/nTox_win32.h b/testing/nTox_win32.h index 84d4a778..374348a4 100644 --- a/testing/nTox_win32.h +++ b/testing/nTox_win32.h | |||
@@ -29,4 +29,12 @@ | |||
29 | #define STRING_LENGTH 256 | 29 | #define STRING_LENGTH 256 |
30 | #define PUB_KEY_BYTES 32 | 30 | #define PUB_KEY_BYTES 32 |
31 | 31 | ||
32 | void do_header(); | ||
33 | void print_message(int friendnumber, uint8_t * string, uint16_t length); | ||
34 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length); | ||
35 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length); | ||
36 | void load_key(); | ||
37 | void line_eval(char* line); | ||
38 | void get_input(); | ||
39 | |||
32 | #endif \ No newline at end of file | 40 | #endif \ No newline at end of file |