summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
Diffstat (limited to 'testing')
-rw-r--r--testing/nTox.c153
-rw-r--r--testing/nTox.h1
-rw-r--r--testing/nTox_win32.c85
-rw-r--r--testing/nTox_win32.h1
4 files changed, 116 insertions, 124 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index 5c560079..5f184407 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -23,9 +23,9 @@
23#include "nTox.h" 23#include "nTox.h"
24#include "misc_tools.h" 24#include "misc_tools.h"
25 25
26
27#include <stdio.h> 26#include <stdio.h>
28#include <time.h> 27#include <time.h>
28
29#ifdef WIN32 29#ifdef WIN32
30#define c_sleep(x) Sleep(1*x) 30#define c_sleep(x) Sleep(1*x)
31#else 31#else
@@ -35,7 +35,7 @@
35 35
36char lines[HISTORY][STRING_LENGTH]; 36char lines[HISTORY][STRING_LENGTH];
37char line[STRING_LENGTH]; 37char line[STRING_LENGTH];
38int x,y; 38int x, y;
39 39
40uint8_t pending_requests[256][CLIENT_ID_SIZE]; 40uint8_t pending_requests[256][CLIENT_ID_SIZE];
41uint8_t num_requests; 41uint8_t num_requests;
@@ -44,9 +44,9 @@ void new_lines(char *line)
44{ 44{
45 int i; 45 int i;
46 for (i = HISTORY-1; i > 0; i--) 46 for (i = HISTORY-1; i > 0; i--)
47 strcpy(lines[i],lines[i-1]); 47 strcpy(lines[i], lines[i-1]);
48 48
49 strcpy(lines[0],line); 49 strcpy(lines[0], line);
50 do_refresh(); 50 do_refresh();
51} 51}
52 52
@@ -54,10 +54,9 @@ void new_lines(char *line)
54void print_friendlist() 54void print_friendlist()
55{ 55{
56 char name[MAX_NAME_LENGTH]; 56 char name[MAX_NAME_LENGTH];
57 uint32_t i;
58
59 new_lines("[i] Friend List:"); 57 new_lines("[i] Friend List:");
60 for (i=0; i <= num_requests; i++) { 58 uint32_t i;
59 for (i = 0; i <= num_requests; i++) {
61 char fstring[128]; 60 char fstring[128];
62 61
63 getname(i, (uint8_t*)name); 62 getname(i, (uint8_t*)name);
@@ -73,7 +72,7 @@ void print_friendlist()
73char *format_message(char *message, int friendnum) 72char *format_message(char *message, int friendnum)
74{ 73{
75 char name[MAX_NAME_LENGTH]; 74 char name[MAX_NAME_LENGTH];
76 if(friendnum != -1) { 75 if (friendnum != -1) {
77 getname(friendnum, (uint8_t*)name); 76 getname(friendnum, (uint8_t*)name);
78 } else { 77 } else {
79 getself_name((uint8_t*)name); 78 getself_name((uint8_t*)name);
@@ -85,7 +84,7 @@ char *format_message(char *message, int friendnum)
85 timeinfo = localtime ( &rawtime ); 84 timeinfo = localtime ( &rawtime );
86 char* time = asctime(timeinfo); 85 char* time = asctime(timeinfo);
87 size_t len = strlen(time); 86 size_t len = strlen(time);
88 time[len-1]='\0'; 87 time[len-1] = '\0';
89 sprintf(msg, "[%d] %s <%s> %s", friendnum, time, name, message); // timestamp 88 sprintf(msg, "[%d] %s <%s> %s", friendnum, time, name, message); // timestamp
90 return msg; 89 return msg;
91} 90}
@@ -93,13 +92,14 @@ char *format_message(char *message, int friendnum)
93void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) 92void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
94{ 93{
95 if (line[0] == '/') { 94 if (line[0] == '/') {
96 char command[STRING_LENGTH + 2] = "> "; 95 char inpt_command = line[1];
97 strcat(command, line); 96 char prompt[STRING_LENGTH + 2] = "> ";
98 new_lines(command); 97 strcat(prompt, line);
99 if (line[1] == 'f') { // add friend command: /f ID 98 new_lines(prompt);
99 if (inpt_command == 'f') { // add friend command: /f ID
100 int i; 100 int i;
101 char temp_id[128]; 101 char temp_id[128];
102 for (i=0; i<128; i++) 102 for (i = 0; i < 128; i++)
103 temp_id[i] = line[i+3]; 103 temp_id[i] = line[i+3];
104 int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); 104 int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
105 char numstring[100]; 105 char numstring[100];
@@ -107,63 +107,63 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
107 new_lines(numstring); 107 new_lines(numstring);
108 do_refresh(); 108 do_refresh();
109 } 109 }
110 else if (line[1] == 'd') { 110 else if (inpt_command == 'd') {
111 doMessenger(); 111 doMessenger();
112 } 112 }
113 else if (line[1] == 'm') { //message command: /m friendnumber messsage 113 else if (inpt_command == 'm') { //message command: /m friendnumber messsage
114 int i;
115 size_t len = strlen(line); 114 size_t len = strlen(line);
116 char numstring[len-3]; 115 char numstring[len-3];
117 char message[len-3]; 116 char message[len-3];
118 for (i=0; i<len; i++) { 117 int i;
118 for (i = 0; i < len; i++) {
119 if (line[i+3] != ' ') { 119 if (line[i+3] != ' ') {
120 numstring[i] = line[i+3]; 120 numstring[i] = line[i+3];
121 } else { 121 } else {
122 int j; 122 int j;
123 for (j=i+1; j<len; j++) 123 for (j = (i+1); j < len; j++)
124 message[j-i-1] = line[j+3]; 124 message[j-i-1] = line[j+3];
125 break; 125 break;
126 } 126 }
127 } 127 }
128 int num = atoi(numstring); 128 int num = atoi(numstring);
129 if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { 129 if (m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) {
130 new_lines("[i] could not send message"); 130 new_lines("[i] could not send message");
131 } else { 131 } else {
132 new_lines(format_message(message, -1)); 132 new_lines(format_message(message, -1));
133 } 133 }
134 } 134 }
135 else if (line[1] == 'n') { 135 else if (inpt_command == 'n') {
136 uint8_t name[MAX_NAME_LENGTH]; 136 uint8_t name[MAX_NAME_LENGTH];
137 int i = 0; 137 int i = 0;
138 size_t len = strlen(line); 138 size_t len = strlen(line);
139 for (i=3; i<len; i++) { 139 for (i = 3; i < len; i++) {
140 if (line[i] == 0 || line[i] == '\n') break; 140 if (line[i] == 0 || line[i] == '\n') break;
141 name[i - 3] = line[i]; 141 name[i-3] = line[i];
142 } 142 }
143 name[i - 3] = 0; 143 name[i-3] = 0;
144 setname(name, i); 144 setname(name, i);
145 char numstring[100]; 145 char numstring[100];
146 sprintf(numstring, "[i] changed nick to %s", (char*)name); 146 sprintf(numstring, "[i] changed nick to %s", (char*)name);
147 new_lines(numstring); 147 new_lines(numstring);
148 } 148 }
149 else if (line[1] == 'l') { 149 else if (inpt_command == 'l') {
150 print_friendlist(); 150 print_friendlist();
151 } 151 }
152 else if (line[1] == 's') { 152 else if (inpt_command == 's') {
153 uint8_t status[MAX_USERSTATUS_LENGTH]; 153 uint8_t status[MAX_USERSTATUS_LENGTH];
154 int i = 0; 154 int i = 0;
155 size_t len = strlen(line); 155 size_t len = strlen(line);
156 for (i=3; i<len; i++) { 156 for (i = 3; i < len; i++) {
157 if (line[i] == 0 || line[i] == '\n') break; 157 if (line[i] == 0 || line[i] == '\n') break;
158 status[i - 3] = line[i]; 158 status[i-3] = line[i];
159 } 159 }
160 status[i - 3] = 0; 160 status[i-3] = 0;
161 m_set_userstatus(status, strlen((char*)status)); 161 m_set_userstatus(status, strlen((char*)status));
162 char numstring[100]; 162 char numstring[100];
163 sprintf(numstring, "[i] changed status to %s", (char*)status); 163 sprintf(numstring, "[i] changed status to %s", (char*)status);
164 new_lines(numstring); 164 new_lines(numstring);
165 } 165 }
166 else if (line[1] == 'a') { 166 else if (inpt_command == 'a') {
167 uint8_t numf = atoi(line + 3); 167 uint8_t numf = atoi(line + 3);
168 char numchar[100]; 168 char numchar[100];
169 sprintf(numchar, "[i] friend request %u accepted", numf); 169 sprintf(numchar, "[i] friend request %u accepted", numf);
@@ -174,35 +174,34 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
174 do_refresh(); 174 do_refresh();
175 175
176 } 176 }
177 177 else if (inpt_command == 'h') { //help
178 else if (line[1] == 'h') { //help
179 new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)"); 178 new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)");
180 new_lines("[i] /l list (list friends), /h for help, /i for info, /n nick (to change nickname), /q (to quit)"); 179 new_lines("[i] /l list (list friends), /h for help, /i for info, /n nick (to change nickname), /q (to quit)");
181 } 180 }
182 181 else if (inpt_command == 'i') { //info
183 else if (line[1] == 'i') { //info
184 char idstring0[200]; 182 char idstring0[200];
185 char idstring1[32][5]; 183 char idstring1[PUB_KEY_BYTES][5];
186 char idstring2[32][5]; 184 char idstring2[PUB_KEY_BYTES][5];
187 uint32_t i; 185 int i;
188 for(i = 0; i < 32; i++) 186 for (i = 0; i < PUB_KEY_BYTES; i++)
189 { 187 {
190 if(self_public_key[i] < 16) 188 if (self_public_key[i] < (PUB_KEY_BYTES/2))
191 strcpy(idstring1[i],"0"); 189 strcpy(idstring1[i],"0");
192 else 190 else
193 strcpy(idstring1[i], ""); 191 strcpy(idstring1[i], "");
194 sprintf(idstring2[i], "%hhX",self_public_key[i]); 192 sprintf(idstring2[i], "%hhX", self_public_key[i]);
195 } 193 }
196 // 194 //
197 strcpy(idstring0,"[i] ID: "); 195 strcpy(idstring0,"[i] ID: ");
198 for (i=0; i<32; i++) { 196 int j;
199 strcat(idstring0,idstring1[i]); 197 for (j = 0; j < PUB_KEY_BYTES; j++) {
200 strcat(idstring0,idstring2[i]); 198 strcat(idstring0,idstring1[j]);
199 strcat(idstring0,idstring2[j]);
201 } 200 }
202 new_lines(idstring0); 201 new_lines(idstring0);
203 } 202 }
204 203
205 else if (line[1] == 'q') { //exit 204 else if (inpt_command == 'q') { //exit
206 endwin(); 205 endwin();
207 exit(EXIT_SUCCESS); 206 exit(EXIT_SUCCESS);
208 } else { 207 } else {
@@ -216,9 +215,9 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
216 215
217void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) 216void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width)
218{ 217{
219 int i = 0;
220 strcpy(output,input); 218 strcpy(output,input);
221 size_t len = strlen(output); 219 size_t len = strlen(output);
220 int i = 0;
222 for (i = line_width; i < len; i = i + line_width) { 221 for (i = line_width; i < len; i = i + line_width) {
223 while (output[i] != ' ' && i != 0) { 222 while (output[i] != ' ' && i != 0) {
224 i--; 223 i--;
@@ -232,9 +231,9 @@ void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width)
232int count_lines(char *string) 231int count_lines(char *string)
233{ 232{
234 size_t len = strlen(string); 233 size_t len = strlen(string);
235 int i;
236 int count = 1; 234 int count = 1;
237 for (i=0; i < len; i++) { 235 int i;
236 for (i = 0; i < len; i++) {
238 if (string[i] == '\n') 237 if (string[i] == '\n')
239 count++; 238 count++;
240 } 239 }
@@ -245,7 +244,7 @@ char *appender(char *str, const char c)
245{ 244{
246 size_t len = strlen(str); 245 size_t len = strlen(str);
247 if (len < STRING_LENGTH) { 246 if (len < STRING_LENGTH) {
248 str[len + 1] = str[len]; 247 str[len+1] = str[len];
249 str[len] = c; 248 str[len] = c;
250 } 249 }
251 return str; 250 return str;
@@ -253,21 +252,21 @@ char *appender(char *str, const char c)
253 252
254void do_refresh() 253void do_refresh()
255{ 254{
256 int i;
257 int count=0; 255 int count=0;
258 int l;
259 char wrap_output[STRING_LENGTH]; 256 char wrap_output[STRING_LENGTH];
260 for (i=0; i<HISTORY; i++) { 257 int L;
258 int i;
259 for (i = 0; i < HISTORY; i++) {
261 wrap(wrap_output, lines[i], x); 260 wrap(wrap_output, lines[i], x);
262 l = count_lines(wrap_output); 261 L = count_lines(wrap_output);
263 count = count + l; 262 count = count + L;
264 if (count < y) { 263 if (count < y) {
265 move(y-1-count,0); 264 move(y-1-count, 0);
266 printw(wrap_output); 265 printw(wrap_output);
267 clrtoeol(); 266 clrtoeol();
268 } 267 }
269 } 268 }
270 move(y-1,0); 269 move(y-1, 0);
271 clrtoeol(); 270 clrtoeol();
272 printw(">> "); 271 printw(">> ");
273 printw(line); 272 printw(line);
@@ -298,12 +297,13 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length)
298 timeinfo = localtime ( &rawtime ); 297 timeinfo = localtime ( &rawtime );
299 char* temp = asctime(timeinfo); 298 char* temp = asctime(timeinfo);
300 size_t len = strlen(temp); 299 size_t len = strlen(temp);
301 temp[len-1]='\0'; 300 temp[len-1] = '\0';
302 sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp 301 sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp
303 new_lines(format_message((char*)string, friendnumber)); 302 new_lines(format_message((char*)string, friendnumber));
304} 303}
305 304
306void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) { 305void print_nickchange(int friendnumber, uint8_t *string, uint16_t length)
306{
307 char name[MAX_NAME_LENGTH]; 307 char name[MAX_NAME_LENGTH];
308 getname(friendnumber, (uint8_t*)name); 308 getname(friendnumber, (uint8_t*)name);
309 char msg[100+length]; 309 char msg[100+length];
@@ -311,7 +311,8 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) {
311 new_lines(msg); 311 new_lines(msg);
312} 312}
313 313
314void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { 314void print_statuschange(int friendnumber, uint8_t *string, uint16_t length)
315{
315 char name[MAX_NAME_LENGTH]; 316 char name[MAX_NAME_LENGTH];
316 getname(friendnumber, (uint8_t*)name); 317 getname(friendnumber, (uint8_t*)name);
317 char msg[100+length+strlen(name)+1]; 318 char msg[100+length+strlen(name)+1];
@@ -319,15 +320,17 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) {
319 new_lines(msg); 320 new_lines(msg);
320} 321}
321 322
322void load_key(){ 323void load_key()
324{
323 FILE *data_file = NULL; 325 FILE *data_file = NULL;
324 if ((data_file = fopen("data","r"))) { 326 data_file = fopen("data","r");
327 if (data_file) {
325 //load keys 328 //load keys
326 fseek(data_file, 0, SEEK_END); 329 fseek(data_file, 0, SEEK_END);
327 int size = ftell(data_file); 330 int size = ftell(data_file);
328 fseek(data_file, 0, SEEK_SET); 331 fseek(data_file, 0, SEEK_SET);
329 uint8_t data[size]; 332 uint8_t data[size];
330 if(fread(data, sizeof(uint8_t), size, data_file) != size){ 333 if (fread(data, sizeof(uint8_t), size, data_file) != size){
331 printf("[i] could not read data file\n[i] exiting\n"); 334 printf("[i] could not read data file\n[i] exiting\n");
332 exit(1); 335 exit(1);
333 } 336 }
@@ -338,7 +341,7 @@ void load_key(){
338 uint8_t data[size]; 341 uint8_t data[size];
339 Messenger_save(data); 342 Messenger_save(data);
340 data_file = fopen("data","w"); 343 data_file = fopen("data","w");
341 if(fwrite(data, sizeof(uint8_t), size, data_file) != size){ 344 if (fwrite(data, sizeof(uint8_t), size, data_file) != size){
342 printf("[i] could not write data file\n[i] exiting\n"); 345 printf("[i] could not write data file\n[i] exiting\n");
343 exit(1); 346 exit(1);
344 } 347 }
@@ -368,26 +371,27 @@ int main(int argc, char *argv[])
368 m_callback_namechange(print_nickchange); 371 m_callback_namechange(print_nickchange);
369 m_callback_userstatus(print_statuschange); 372 m_callback_userstatus(print_statuschange);
370 char idstring0[200]; 373 char idstring0[200];
371 char idstring1[32][5]; 374 char idstring1[PUB_KEY_BYTES][5];
372 char idstring2[32][5]; 375 char idstring2[PUB_KEY_BYTES][5];
373 uint32_t i; 376 int i;
374 for(i = 0; i < 32; i++) 377 for(i = 0; i < PUB_KEY_BYTES; i++)
375 { 378 {
376 if(self_public_key[i] < 16) 379 if (self_public_key[i] < (PUB_KEY_BYTES / 2))
377 strcpy(idstring1[i],"0"); 380 strcpy(idstring1[i],"0");
378 else 381 else
379 strcpy(idstring1[i], ""); 382 strcpy(idstring1[i], "");
380 sprintf(idstring2[i], "%hhX",self_public_key[i]); 383 sprintf(idstring2[i], "%hhX",self_public_key[i]);
381 } 384 }
382 strcpy(idstring0,"[i] your ID: "); 385 strcpy(idstring0,"[i] your ID: ");
383 for (i=0; i<32; i++) { 386 int j;
384 strcat(idstring0,idstring1[i]); 387 for (j = 0; j < PUB_KEY_BYTES; j++) {
385 strcat(idstring0,idstring2[i]); 388 strcat(idstring0,idstring1[j]);
389 strcat(idstring0,idstring2[j]);
386 } 390 }
387 initscr(); 391 initscr();
388 noecho(); 392 noecho();
389 raw(); 393 raw();
390 getmaxyx(stdscr,y,x); 394 getmaxyx(stdscr, y, x);
391 new_lines(idstring0); 395 new_lines(idstring0);
392 new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)"); 396 new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)");
393 new_lines("[i] /l list (list friends), /h for help, /i for info, /n nick (to change nickname), /q (to quit)"); 397 new_lines("[i] /l list (list friends), /h for help, /i for info, /n nick (to change nickname), /q (to quit)");
@@ -413,7 +417,6 @@ int main(int argc, char *argv[])
413 do_refresh(); 417 do_refresh();
414 418
415 c = getch(); 419 c = getch();
416
417 if (c == ERR || c == 27) 420 if (c == ERR || c == 27)
418 continue; 421 continue;
419 422
@@ -422,7 +425,7 @@ int main(int argc, char *argv[])
422 line_eval(lines, line); 425 line_eval(lines, line);
423 strcpy(line, ""); 426 strcpy(line, "");
424 } else if (c == 127) { 427 } else if (c == 127) {
425 line[strlen(line) - 1] = '\0'; 428 line[strlen(line)-1] = '\0';
426 } else if (isalnum(c) || ispunct(c) || c == ' ') { 429 } else if (isalnum(c) || ispunct(c) || c == ' ') {
427 strcpy(line, appender(line, (char) c)); 430 strcpy(line, appender(line, (char) c));
428 } 431 }
diff --git a/testing/nTox.h b/testing/nTox.h
index 9b69d959..9d82556c 100644
--- a/testing/nTox.h
+++ b/testing/nTox.h
@@ -39,6 +39,7 @@
39#include "../core/network.h" 39#include "../core/network.h"
40#define STRING_LENGTH 256 40#define STRING_LENGTH 256
41#define HISTORY 50 41#define HISTORY 50
42#define PUB_KEY_BYTES 32
42 43
43void new_lines(char *line); 44void new_lines(char *line);
44void line_eval(char lines[HISTORY][STRING_LENGTH], char *line); 45void line_eval(char lines[HISTORY][STRING_LENGTH], char *line);
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c
index 3a9caaf5..3286bb3a 100644
--- a/testing/nTox_win32.c
+++ b/testing/nTox_win32.c
@@ -88,14 +88,13 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) {
88void load_key() 88void load_key()
89{ 89{
90 FILE *data_file = NULL; 90 FILE *data_file = NULL;
91 91 data_file = fopen("data","r");
92 if ((data_file = fopen("data", "r"))) { 92 if (data_file) {
93 fseek(data_file, 0, SEEK_END); 93 fseek(data_file, 0, SEEK_END);
94 int size = ftell(data_file); 94 int size = ftell(data_file);
95 fseek(data_file, 0, SEEK_SET); 95 fseek(data_file, 0, SEEK_SET);
96 uint8_t data[size]; 96 uint8_t data[size];
97 97 if (fread(data, sizeof(uint8_t), size, data_file) != size) {
98 if(fread(data, sizeof(uint8_t), size, data_file) != size) {
99 printf("\n[i] Could not read the data file. Exiting."); 98 printf("\n[i] Could not read the data file. Exiting.");
100 exit(1); 99 exit(1);
101 } 100 }
@@ -107,23 +106,23 @@ void load_key()
107 Messenger_save(data); 106 Messenger_save(data);
108 data_file = fopen("data", "w"); 107 data_file = fopen("data", "w");
109 108
110 if(fwrite(data, sizeof(uint8_t), size, data_file) != size) { 109 if (fwrite(data, sizeof(uint8_t), size, data_file) != size) {
111 printf("\n[i] Could not write data to file. Exiting."); 110 printf("\n[i] Could not write data to file. Exiting.");
112 exit(1); 111 exit(1);
113 } 112 }
114 } 113 }
115
116 fclose(data_file); 114 fclose(data_file);
117} 115}
118 116
119void line_eval(char* line) 117void line_eval(char* line)
120{ 118{
121 if(line[0] == '/') { 119 if(line[0] == '/') {
120 char inpt_command = line[1];
122 /* Add friend */ 121 /* Add friend */
123 if(line[1] == 'f') { 122 if(inpt_command == 'f') {
124 int i; 123 int i;
125 char temp_id[128]; 124 char temp_id[128];
126 for (i=0; i<128; i++) 125 for (i = 0; i < 128; i++)
127 temp_id[i] = line[i+3]; 126 temp_id[i] = line[i+3];
128 int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); 127 int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
129 char numstring[100]; 128 char numstring[100];
@@ -131,28 +130,27 @@ void line_eval(char* line)
131 printf(numstring); 130 printf(numstring);
132 } 131 }
133 132
134 else if (line[1] == 'r') { 133 else if (inpt_command == 'r') {
135 do_header(); 134 do_header();
136 printf("\n\n"); 135 printf("\n\n");
137 } 136 }
138 137
139 else if (line[1] == 'l') { 138 else if (inpt_command == 'l') {
140 printf("\n[i] Friend List | Total: %d\n\n", getnumfriends()); 139 printf("\n[i] Friend List | Total: %d\n\n", getnumfriends());
141 140
142 int i; 141 int i;
143 142 for (i = 0; i < getnumfriends(); i++) {
144 for (i=0; i < getnumfriends(); i++) {
145 char name[MAX_NAME_LENGTH]; 143 char name[MAX_NAME_LENGTH];
146 getname(i, (uint8_t*)name); 144 getname(i, (uint8_t*)name);
147 printf("[%d] %s\n\n", i, (uint8_t*)name); 145 printf("[%d] %s\n\n", i, (uint8_t*)name);
148 } 146 }
149 } 147 }
150 148
151 else if (line[1] == 'd') { 149 else if (inpt_command == 'd') {
152 size_t len = strlen(line); 150 size_t len = strlen(line);
153 char numstring[len-3]; 151 char numstring[len-3];
154 int i; 152 int i;
155 for (i=0; i<len; i++) { 153 for (i = 0; i < len; i++) {
156 if (line[i+3] != ' ') { 154 if (line[i+3] != ' ') {
157 numstring[i] = line[i+3]; 155 numstring[i] = line[i+3];
158 } 156 }
@@ -161,17 +159,17 @@ void line_eval(char* line)
161 m_delfriend(num); 159 m_delfriend(num);
162 } 160 }
163 /* Send message to friend */ 161 /* Send message to friend */
164 else if (line[1] == 'm') { 162 else if (inpt_command == 'm') {
165 int i;
166 size_t len = strlen(line); 163 size_t len = strlen(line);
167 char numstring[len-3]; 164 char numstring[len-3];
168 char message[len-3]; 165 char message[len-3];
169 for (i=0; i<len; i++) { 166 int i;
167 for (i = 0; i < len; i++) {
170 if (line[i+3] != ' ') { 168 if (line[i+3] != ' ') {
171 numstring[i] = line[i+3]; 169 numstring[i] = line[i+3];
172 } else { 170 } else {
173 int j; 171 int j;
174 for (j=i+1; j<len; j++) 172 for (j = (i+1); j < len; j++)
175 message[j-i-1] = line[j+3]; 173 message[j-i-1] = line[j+3];
176 break; 174 break;
177 } 175 }
@@ -185,37 +183,37 @@ void line_eval(char* line)
185 } 183 }
186 } 184 }
187 185
188 else if (line[1] == 'n') { 186 else if (inpt_command == 'n') {
189 uint8_t name[MAX_NAME_LENGTH]; 187 uint8_t name[MAX_NAME_LENGTH];
190 int i = 0; 188 int i = 0;
191 size_t len = strlen(line); 189 size_t len = strlen(line);
192 for (i=3; i<len; i++) { 190 for (i = 3; i < len; i++) {
193 if (line[i] == 0 || line[i] == '\n') break; 191 if (line[i] == 0 || line[i] == '\n') break;
194 name[i - 3] = line[i]; 192 name[i-3] = line[i];
195 } 193 }
196 name[i - 3] = 0; 194 name[i-3] = 0;
197 setname(name, i); 195 setname(name, i);
198 char numstring[100]; 196 char numstring[100];
199 sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name); 197 sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name);
200 printf(numstring); 198 printf(numstring);
201 } 199 }
202 200
203 else if (line[1] == 's') { 201 else if (inpt_command == 's') {
204 uint8_t status[MAX_USERSTATUS_LENGTH]; 202 uint8_t status[MAX_USERSTATUS_LENGTH];
205 int i = 0; 203 int i = 0;
206 size_t len = strlen(line); 204 size_t len = strlen(line);
207 for (i=3; i<len; i++) { 205 for (i = 3; i < len; i++) {
208 if (line[i] == 0 || line[i] == '\n') break; 206 if (line[i] == 0 || line[i] == '\n') break;
209 status[i - 3] = line[i]; 207 status[i-3] = line[i];
210 } 208 }
211 status[i - 3] = 0; 209 status[i-3] = 0;
212 m_set_userstatus(status, strlen((char*)status)); 210 m_set_userstatus(status, strlen((char*)status));
213 char numstring[100]; 211 char numstring[100];
214 sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status); 212 sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status);
215 printf(numstring); 213 printf(numstring);
216 } 214 }
217 215
218 else if (line[1] == 'a') { 216 else if (inpt_command == 'a') {
219 uint8_t numf = atoi(line + 3); 217 uint8_t numf = atoi(line + 3);
220 char numchar[100]; 218 char numchar[100];
221 sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf); 219 sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf);
@@ -225,12 +223,10 @@ void line_eval(char* line)
225 printf(numchar); 223 printf(numchar);
226 } 224 }
227 /* EXIT */ 225 /* EXIT */
228 else if (line[1] == 'q') { 226 else if (inpt_command == 'q') {
229 exit(EXIT_SUCCESS); 227 exit(EXIT_SUCCESS);
230 } 228 }
231 } 229 } else {
232
233 else {
234 //nothing atm 230 //nothing atm
235 } 231 }
236} 232}
@@ -250,12 +246,10 @@ int main(int argc, char *argv[])
250 printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]); 246 printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]);
251 exit(0); 247 exit(0);
252 } 248 }
253
254 if (initMessenger() == -1) { 249 if (initMessenger() == -1) {
255 printf("initMessenger failed"); 250 printf("initMessenger failed");
256 exit(0); 251 exit(0);
257 } 252 }
258
259 if (argc > 4) { 253 if (argc > 4) {
260 if(strncmp(argv[4], "nokey", 6) < 0) { 254 if(strncmp(argv[4], "nokey", 6) < 0) {
261 } 255 }
@@ -267,26 +261,25 @@ int main(int argc, char *argv[])
267 m_callback_friendmessage(print_message); 261 m_callback_friendmessage(print_message);
268 m_callback_namechange(print_nickchange); 262 m_callback_namechange(print_nickchange);
269 m_callback_userstatus(print_statuschange); 263 m_callback_userstatus(print_statuschange);
270 264 char idstring1[PUB_KEY_BYTES][5];
271 char idstring1[32][5]; 265 char idstring2[PUB_KEY_BYTES][5];
272 char idstring2[32][5]; 266 int i;
273 uint32_t i; 267 for(i = 0; i < PUB_KEY_BYTES; i++)
274 for(i = 0; i < 32; i++)
275 { 268 {
276 if(self_public_key[i] < 16) 269 if(self_public_key[i] < (PUB_KEY_BYTES/2))
277 strcpy(idstring1[i],"0"); 270 strcpy(idstring1[i],"0");
278 else 271 else
279 strcpy(idstring1[i], ""); 272 strcpy(idstring1[i], "");
280 sprintf(idstring2[i], "%hhX",self_public_key[i]); 273 sprintf(idstring2[i], "%hhX",self_public_key[i]);
281 } 274 }
282 strcpy(users_id,"[i] your ID: "); 275 strcpy(users_id,"[i] your ID: ");
283 for (i=0; i<32; i++) { 276 int j;
284 strcat(users_id,idstring1[i]); 277 for (j = 0; j < PUB_KEY_BYTES; j++) {
285 strcat(users_id,idstring2[i]); 278 strcat(users_id,idstring1[j]);
279 strcat(users_id,idstring2[j]);
286 } 280 }
287 281
288 do_header(); 282 do_header();
289
290 IP_Port bootstrap_ip_port; 283 IP_Port bootstrap_ip_port;
291 bootstrap_ip_port.port = htons(atoi(argv[2])); 284 bootstrap_ip_port.port = htons(atoi(argv[2]));
292 int resolved_address = resolve_addr(argv[1]); 285 int resolved_address = resolve_addr(argv[1]);
@@ -296,12 +289,9 @@ int main(int argc, char *argv[])
296 exit(1); 289 exit(1);
297 290
298 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); 291 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
299
300 int c; 292 int c;
301 int on = 0; 293 int on = 0;
302
303 _beginthread(get_input, 0, NULL); 294 _beginthread(get_input, 0, NULL);
304
305 while(1) { 295 while(1) {
306 if (on == 1 && DHT_isconnected() == -1) { 296 if (on == 1 && DHT_isconnected() == -1) {
307 printf("\n---------------------------------"); 297 printf("\n---------------------------------");
@@ -309,15 +299,12 @@ int main(int argc, char *argv[])
309 printf("\n---------------------------------\n\n"); 299 printf("\n---------------------------------\n\n");
310 on = 0; 300 on = 0;
311 } 301 }
312
313 if (on == 0 && DHT_isconnected()) { 302 if (on == 0 && DHT_isconnected()) {
314 printf("\n[i] Connected to DHT"); 303 printf("\n[i] Connected to DHT");
315 printf("\n---------------------------------\n\n"); 304 printf("\n---------------------------------\n\n");
316 on = 1; 305 on = 1;
317 } 306 }
318
319 doMessenger(); 307 doMessenger();
320 } 308 }
321
322 return 0; 309 return 0;
323} \ No newline at end of file 310} \ No newline at end of file
diff --git a/testing/nTox_win32.h b/testing/nTox_win32.h
index 7861be1c..84d4a778 100644
--- a/testing/nTox_win32.h
+++ b/testing/nTox_win32.h
@@ -27,5 +27,6 @@
27#include "../core/network.h" 27#include "../core/network.h"
28 28
29#define STRING_LENGTH 256 29#define STRING_LENGTH 256
30#define PUB_KEY_BYTES 32
30 31
31#endif \ No newline at end of file 32#endif \ No newline at end of file