diff options
author | Astonex <softukitu@gmail.com> | 2013-07-24 00:32:09 +0100 |
---|---|---|
committer | Astonex <softukitu@gmail.com> | 2013-07-24 00:32:09 +0100 |
commit | b7a4c20279ba32e89119c78c2e78ee279358d338 (patch) | |
tree | 1c6200a5d85ebbf730bb673d422ea6b96d8c20cc /testing | |
parent | 4aeded2d0eb735c1b8c7529c7ca9edf924208769 (diff) | |
parent | ff9e6822ec2518e14cc274407c506fe49f9cbddc (diff) |
Merge remote-tracking branch 'ProjectTox/master'
Diffstat (limited to 'testing')
-rw-r--r-- | testing/nTox.c | 98 |
1 files changed, 47 insertions, 51 deletions
diff --git a/testing/nTox.c b/testing/nTox.c index 8e9a5456..097c73af 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -99,8 +99,8 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
99 | sprintf(numstring, "[i] changed status to %s", (char*)status); | 99 | sprintf(numstring, "[i] changed status to %s", (char*)status); |
100 | new_lines(numstring); | 100 | new_lines(numstring); |
101 | } else if (line[1] == 'q') { //exit | 101 | } else if (line[1] == 'q') { //exit |
102 | endwin(); | 102 | endwin(); |
103 | exit(EXIT_SUCCESS); | 103 | exit(EXIT_SUCCESS); |
104 | } | 104 | } |
105 | } else { | 105 | } else { |
106 | //new_lines(line); | 106 | //new_lines(line); |
@@ -184,7 +184,7 @@ void print_request(uint8_t * public_key, uint8_t * data, uint16_t length) | |||
184 | } | 184 | } |
185 | void print_message(int friendnumber, uint8_t * string, uint16_t length) | 185 | void print_message(int friendnumber, uint8_t * string, uint16_t length) |
186 | { | 186 | { |
187 | char *name = malloc(MAX_NAME_LENGTH); | 187 | char name[MAX_NAME_LENGTH]; |
188 | getname(friendnumber, (uint8_t*)name); | 188 | getname(friendnumber, (uint8_t*)name); |
189 | char msg[100+length+strlen(name)+1]; | 189 | char msg[100+length+strlen(name)+1]; |
190 | time_t rawtime; | 190 | time_t rawtime; |
@@ -195,51 +195,47 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length) | |||
195 | int len = strlen(temp); | 195 | int len = strlen(temp); |
196 | temp[len-1]='\0'; | 196 | temp[len-1]='\0'; |
197 | sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // someone please fix this | 197 | sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // someone please fix this |
198 | free(name); | ||
199 | new_lines(msg); | 198 | new_lines(msg); |
200 | } | 199 | } |
201 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) { | 200 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) { |
202 | char *name = malloc(MAX_NAME_LENGTH); | 201 | char name[MAX_NAME_LENGTH]; |
203 | getname(friendnumber, (uint8_t*)name); | 202 | getname(friendnumber, (uint8_t*)name); |
204 | char msg[100+length]; | 203 | char msg[100+length]; |
205 | sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string); | 204 | sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string); |
206 | free(name); | ||
207 | new_lines(msg); | 205 | new_lines(msg); |
208 | } | 206 | } |
209 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { | 207 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { |
210 | char *name = malloc(MAX_NAME_LENGTH); | 208 | char name[MAX_NAME_LENGTH]; |
211 | getname(friendnumber, (uint8_t*)name); | 209 | getname(friendnumber, (uint8_t*)name); |
212 | char msg[100+length+strlen(name)+1]; | 210 | char msg[100+length+strlen(name)+1]; |
213 | sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string); | 211 | sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string); |
214 | free(name); | ||
215 | new_lines(msg); | 212 | new_lines(msg); |
216 | } | 213 | } |
217 | int load_key(){ | 214 | void load_key(){ |
218 | FILE *data_file = NULL; | 215 | FILE *data_file = NULL; |
219 | if ((data_file = fopen("data","r"))) { | 216 | if ((data_file = fopen("data","r"))) { |
220 | //load keys | 217 | //load keys |
221 | fseek(data_file, 0, SEEK_END); | 218 | fseek(data_file, 0, SEEK_END); |
222 | int size = ftell(data_file); | 219 | int size = ftell(data_file); |
223 | fseek(data_file, 0, SEEK_SET); | 220 | fseek(data_file, 0, SEEK_SET); |
224 | uint8_t data[size]; | 221 | uint8_t data[size]; |
225 | if(fread(data, sizeof(uint8_t), size, data_file) != size){ | 222 | if(fread(data, sizeof(uint8_t), size, data_file) != size){ |
226 | printf("Error reading file\n"); | 223 | printf("Error reading data file\nExiting.\n"); |
227 | exit(0); | 224 | exit(1); |
228 | } | 225 | } |
229 | Messenger_load(data, size); | 226 | Messenger_load(data, size); |
230 | } else { | 227 | } else { |
231 | //else save new keys | 228 | //else save new keys |
232 | int size = Messenger_size(); | 229 | int size = Messenger_size(); |
233 | uint8_t data[size]; | 230 | uint8_t data[size]; |
234 | Messenger_save(data); | 231 | Messenger_save(data); |
235 | data_file = fopen("data","w"); | 232 | data_file = fopen("data","w"); |
236 | if(fwrite(data, sizeof(uint8_t), size, data_file) != size){ | 233 | if(fwrite(data, sizeof(uint8_t), size, data_file) != size){ |
237 | printf("Error writing file\n"); | 234 | printf("Error writing data file\nExiting.\n"); |
238 | exit(0); | 235 | exit(1); |
239 | } | 236 | } |
240 | } | 237 | } |
241 | fclose(data_file); | 238 | fclose(data_file); |
242 | return 0; | ||
243 | } | 239 | } |
244 | int main(int argc, char *argv[]) | 240 | int main(int argc, char *argv[]) |
245 | { | 241 | { |
@@ -298,31 +294,31 @@ int main(int argc, char *argv[]) | |||
298 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); | 294 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); |
299 | nodelay(stdscr, TRUE); | 295 | nodelay(stdscr, TRUE); |
300 | while(true) { | 296 | while(true) { |
301 | c=getch(); | 297 | |
302 | if (c != ERR) { | 298 | if (on == 0 && DHT_isconnected()) |
303 | if (c != 27) { | ||
304 | getmaxyx(stdscr,y,x); | ||
305 | if (c == '\n') { | ||
306 | line_eval(lines, line); | ||
307 | strcpy(line, ""); | ||
308 | } else if (c == 127) { | ||
309 | line[strlen(line)-1] = '\0'; | ||
310 | } else if (isalnum(c) || ispunct(c) || c == ' ') { | ||
311 | strcpy(line,appender(line, (char) c)); | ||
312 | } | ||
313 | } | ||
314 | } | ||
315 | if(on == 0) | ||
316 | { | 299 | { |
317 | if(DHT_isconnected()) | 300 | new_lines("[i] connected to DHT\n[i] define username with /n"); |
318 | { | 301 | on = 1; |
319 | new_lines("[i] connected to DHT\n[i] define username with /n"); | ||
320 | on = 1; | ||
321 | } | ||
322 | } | 302 | } |
303 | |||
323 | doMessenger(); | 304 | doMessenger(); |
324 | c_sleep(1); | 305 | c_sleep(1); |
325 | do_refresh(); | 306 | do_refresh(); |
307 | |||
308 | c = getch(); | ||
309 | |||
310 | if (c == ERR || c == 27) | ||
311 | continue; | ||
312 | |||
313 | getmaxyx(stdscr, y, x); | ||
314 | if (c == '\n') { | ||
315 | line_eval(lines, line); | ||
316 | strcpy(line, ""); | ||
317 | } else if (c == 127) { | ||
318 | line[strlen(line) - 1] = '\0'; | ||
319 | } else if (isalnum(c) || ispunct(c) || c == ' ') { | ||
320 | strcpy(line, appender(line, (char) c)); | ||
321 | } | ||
326 | } | 322 | } |
327 | endwin(); | 323 | endwin(); |
328 | return 0; | 324 | return 0; |