summaryrefslogtreecommitdiff
path: root/testing/nTox.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/nTox.c')
-rw-r--r--testing/nTox.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index 3a5e9bb3..27654191 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -39,9 +39,9 @@ int nick_before;
39void new_lines(char *line) 39void new_lines(char *line)
40{ 40{
41 int i; 41 int i;
42 for (i = HISTORY-1; i > 0; i--) { 42 for (i = HISTORY-1; i > 0; i--)
43 strcpy(lines[i],lines[i-1]); 43 strcpy(lines[i],lines[i-1]);
44 } 44
45 strcpy(lines[0],line); 45 strcpy(lines[0],line);
46 do_refresh(); 46 do_refresh();
47} 47}
@@ -53,8 +53,7 @@ unsigned char * hex_string_to_bin(char hex_string[])
53 unsigned char * val = malloc(len); 53 unsigned char * val = malloc(len);
54 char * pos = hex_string; 54 char * pos = hex_string;
55 int i=0; 55 int i=0;
56 while(i < len) 56 while(i < len) {
57 {
58 sscanf(pos,"%2hhx",&val[i]); 57 sscanf(pos,"%2hhx",&val[i]);
59 pos+=2; 58 pos+=2;
60 i++; 59 i++;
@@ -71,17 +70,18 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
71 if (line[1] == 'f') { // add friend command: /f ID 70 if (line[1] == 'f') { // add friend command: /f ID
72 int i; 71 int i;
73 char temp_id[128]; 72 char temp_id[128];
74 for (i=0; i<128; i++) { 73 for (i=0; i<128; i++)
75 temp_id[i] = line[i+3]; 74 temp_id[i] = line[i+3];
76 }
77 int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); 75 int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
78 char numstring[100]; 76 char numstring[100];
79 sprintf(numstring, "[i] added friend %d", num); 77 sprintf(numstring, "[i] added friend %d", num);
80 new_lines(numstring); 78 new_lines(numstring);
81 do_refresh(); 79 do_refresh();
82 } else if (line[1] == 'd') { 80 }
81 else if (line[1] == 'd') {
83 doMessenger(); 82 doMessenger();
84 } else if (line[1] == 'm') { //message command: /m friendnumber messsage 83 }
84 else if (line[1] == 'm') { //message command: /m friendnumber messsage
85 int i; 85 int i;
86 size_t len = strlen(line); 86 size_t len = strlen(line);
87 char numstring[len-3]; 87 char numstring[len-3];
@@ -91,15 +91,15 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
91 numstring[i] = line[i+3]; 91 numstring[i] = line[i+3];
92 } else { 92 } else {
93 int j; 93 int j;
94 for (j=i+1; j<len; j++) { 94 for (j=i+1; j<len; j++)
95 message[j-i-1] = line[j+3]; 95 message[j-i-1] = line[j+3];
96 }
97 break; 96 break;
98 } 97 }
99 } 98 }
100 int num = atoi(numstring); 99 int num = atoi(numstring);
101 m_sendmessage(num, (uint8_t*) message, sizeof(message)); 100 m_sendmessage(num, (uint8_t*) message, sizeof(message));
102 } else if (line[1] == 'n') { 101 }
102 else if (line[1] == 'n') {
103 uint8_t name[MAX_NAME_LENGTH]; 103 uint8_t name[MAX_NAME_LENGTH];
104 int i = 0; 104 int i = 0;
105 size_t len = strlen(line); 105 size_t len = strlen(line);
@@ -112,7 +112,8 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
112 char numstring[100]; 112 char numstring[100];
113 sprintf(numstring, "[i] changed nick to %s", (char*)name); 113 sprintf(numstring, "[i] changed nick to %s", (char*)name);
114 new_lines(numstring); 114 new_lines(numstring);
115 } else if (line[1] == 's') { 115 }
116 else if (line[1] == 's') {
116 uint8_t status[MAX_USERSTATUS_LENGTH]; 117 uint8_t status[MAX_USERSTATUS_LENGTH];
117 int i = 0; 118 int i = 0;
118 size_t len = strlen(line); 119 size_t len = strlen(line);
@@ -125,7 +126,8 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
125 char numstring[100]; 126 char numstring[100];
126 sprintf(numstring, "[i] changed status to %s", (char*)status); 127 sprintf(numstring, "[i] changed status to %s", (char*)status);
127 new_lines(numstring); 128 new_lines(numstring);
128 } else if (line[1] == 'q') { //exit 129 }
130 else if (line[1] == 'q') { //exit
129 endwin(); 131 endwin();
130 exit(EXIT_SUCCESS); 132 exit(EXIT_SUCCESS);
131 } 133 }
@@ -139,7 +141,7 @@ void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width)
139 int i = 0; 141 int i = 0;
140 strcpy(output,input); 142 strcpy(output,input);
141 size_t len = strlen(output); 143 size_t len = strlen(output);
142 for (i=line_width; i < len; i = i + line_width) { 144 for (i = line_width; i < len; i = i + line_width) {
143 while (output[i] != ' ' && i != 0) { 145 while (output[i] != ' ' && i != 0) {
144 i--; 146 i--;
145 } 147 }
@@ -155,9 +157,8 @@ int count_lines(char *string)
155 int i; 157 int i;
156 int count = 1; 158 int count = 1;
157 for (i=0; i < len; i++) { 159 for (i=0; i < len; i++) {
158 if (string[i] == '\n') { 160 if (string[i] == '\n')
159 count++; 161 count++;
160 }
161 } 162 }
162 return count; 163 return count;
163} 164}
@@ -196,11 +197,11 @@ void do_refresh()
196 refresh(); 197 refresh();
197} 198}
198 199
199void print_request(uint8_t * public_key, uint8_t * data, uint16_t length) 200void print_request(uint8_t *public_key, uint8_t *data, uint16_t length)
200{ 201{
201 new_lines("[i] received friend request"); 202 new_lines("[i] received friend request");
202 do_refresh(); 203 do_refresh();
203 if(memcmp(data , "Install Gentoo", sizeof("Install Gentoo")) == 0 ) 204 if (memcmp(data , "Install Gentoo", sizeof("Install Gentoo")) == 0)
204 //if the request contained the message of peace the person is obviously a friend so we add him. 205 //if the request contained the message of peace the person is obviously a friend so we add him.
205 { 206 {
206 new_lines("[i] friend request accepted"); 207 new_lines("[i] friend request accepted");
@@ -298,15 +299,14 @@ int main(int argc, char *argv[])
298 uint32_t i; 299 uint32_t i;
299 for(i = 0; i < 32; i++) 300 for(i = 0; i < 32; i++)
300 { 301 {
301 if(self_public_key[i] < 16) { 302 if(self_public_key[i] < 16)
302 strcpy(idstring1[i],"0"); 303 strcpy(idstring1[i],"0");
303 } else { 304 else
304 strcpy(idstring1[i], ""); 305 strcpy(idstring1[i], "");
305 }
306 sprintf(idstring2[i], "%hhX",self_public_key[i]); 306 sprintf(idstring2[i], "%hhX",self_public_key[i]);
307 } 307 }
308 strcpy(idstring0,"[i] your ID: "); 308 strcpy(idstring0,"[i] your ID: ");
309 for(i=0; i<32; i++) { 309 for (i=0; i<32; i++) {
310 strcat(idstring0,idstring1[i]); 310 strcat(idstring0,idstring1[i]);
311 strcat(idstring0,idstring2[i]); 311 strcat(idstring0,idstring2[i]);
312 } 312 }
@@ -320,11 +320,11 @@ int main(int argc, char *argv[])
320 IP_Port bootstrap_ip_port; 320 IP_Port bootstrap_ip_port;
321 bootstrap_ip_port.port = htons(atoi(argv[2])); 321 bootstrap_ip_port.port = htons(atoi(argv[2]));
322 int resolved_address = resolve_addr(argv[1]); 322 int resolved_address = resolve_addr(argv[1]);
323 if (resolved_address != -1) { 323 if (resolved_address != -1)
324 bootstrap_ip_port.ip.i = resolved_address; 324 bootstrap_ip_port.ip.i = resolved_address;
325 } else { 325 else
326 exit(1); 326 exit(1);
327 } 327
328 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); 328 DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
329 nodelay(stdscr, TRUE); 329 nodelay(stdscr, TRUE);
330 while(true) { 330 while(true) {