summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAstonex <softukitu@gmail.com>2013-08-01 01:14:02 +0100
committerAstonex <softukitu@gmail.com>2013-08-01 01:14:02 +0100
commit7417dfe21646956aca7861fe79c1b4d207b12443 (patch)
treedbace83e161b3770f0850f7703beccbbb1fe8a2a
parentf05aa308701f33f3bf9df022a4b376deeedef235 (diff)
Fixed friends list and deleting friends. Automatically loads name/status from last time.
-rw-r--r--testing/nTox_win32.c93
1 files changed, 82 insertions, 11 deletions
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c
index ad114f46..b9208d4f 100644
--- a/testing/nTox_win32.c
+++ b/testing/nTox_win32.c
@@ -126,9 +126,19 @@ void line_eval(char* line)
126 for (i = 0; i < 128; i++) 126 for (i = 0; i < 128; i++)
127 temp_id[i] = line[i+3]; 127 temp_id[i] = line[i+3];
128 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"));
129 char numstring[100]; 129 if (num >= 0) {
130 sprintf(numstring, "\n[i] Friend request sent. Wait to be accepted. Friend id: %d\n\n", num); 130 char numstring[100];
131 printf(numstring); 131 sprintf(numstring, "\n[i] Friend request sent. Wait to be accepted. Friend id: %d\n\n", num);
132 printf(numstring);
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");
132 } 142 }
133 143
134 else if (inpt_command == 'r') { 144 else if (inpt_command == 'r') {
@@ -137,15 +147,21 @@ void line_eval(char* line)
137 } 147 }
138 148
139 else if (inpt_command == 'l') { 149 else if (inpt_command == 'l') {
140 printf("\n[i] Friend List | Total: %d\n\n", getnumfriends()); 150 int activefriends = 0;
141
142 int i; 151 int i;
143 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++) {
144 char name[MAX_NAME_LENGTH]; 162 char name[MAX_NAME_LENGTH];
145 getname(i, (uint8_t*)name); 163 getname(i, (uint8_t*)name);
146 if (m_friendstatus(i) == 0) 164 if (m_friendstatus(i) == 4)
147 printf("[%d] No friend with this number\n\n", i);
148 else
149 printf("[%d] %s\n\n", i, (uint8_t*)name); 165 printf("[%d] %s\n\n", i, (uint8_t*)name);
150 } 166 }
151 } 167 }
@@ -181,7 +197,7 @@ void line_eval(char* line)
181 } 197 }
182 int num = atoi(numstring); 198 int num = atoi(numstring);
183 if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { 199 if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) {
184 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);
185 } else { 201 } else {
186 //simply for aesthetics 202 //simply for aesthetics
187 printf("\n"); 203 printf("\n");
@@ -201,6 +217,11 @@ void line_eval(char* line)
201 char numstring[100]; 217 char numstring[100];
202 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);
203 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);
204 } 225 }
205 226
206 else if (inpt_command == 's') { 227 else if (inpt_command == 's') {
@@ -216,6 +237,11 @@ void line_eval(char* line)
216 char numstring[100]; 237 char numstring[100];
217 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);
218 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);
219 } 245 }
220 246
221 else if (inpt_command == 'a') { 247 else if (inpt_command == 'a') {
@@ -229,6 +255,8 @@ void line_eval(char* line)
229 } 255 }
230 /* EXIT */ 256 /* EXIT */
231 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));
232 exit(EXIT_SUCCESS); 260 exit(EXIT_SUCCESS);
233 } 261 }
234 } else { 262 } else {
@@ -261,7 +289,36 @@ int main(int argc, char *argv[])
261 } else { 289 } else {
262 load_key(); 290 load_key();
263 } 291 }
264 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
265 m_callback_friendrequest(print_request); 322 m_callback_friendrequest(print_request);
266 m_callback_friendmessage(print_message); 323 m_callback_friendmessage(print_message);
267 m_callback_namechange(print_nickchange); 324 m_callback_namechange(print_nickchange);
@@ -285,6 +342,7 @@ int main(int argc, char *argv[])
285 } 342 }
286 343
287 do_header(); 344 do_header();
345
288 IP_Port bootstrap_ip_port; 346 IP_Port bootstrap_ip_port;
289 bootstrap_ip_port.port = htons(atoi(argv[2])); 347 bootstrap_ip_port.port = htons(atoi(argv[2]));
290 int resolved_address = resolve_addr(argv[1]); 348 int resolved_address = resolve_addr(argv[1]);
@@ -294,9 +352,22 @@ int main(int argc, char *argv[])
294 exit(1); 352 exit(1);
295 353
296 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); 354 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
355
297 int c; 356 int c;
298 int on = 0; 357 int on = 0;
358
299 _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
300 while(1) { 371 while(1) {
301 if (on == 1 && DHT_isconnected() == -1) { 372 if (on == 1 && DHT_isconnected() == -1) {
302 printf("\n---------------------------------"); 373 printf("\n---------------------------------");