diff options
-rw-r--r-- | testing/nTox.c | 30 | ||||
-rw-r--r-- | testing/toxic/chat.c | 34 |
2 files changed, 19 insertions, 45 deletions
diff --git a/testing/nTox.c b/testing/nTox.c index 24d40ead..13db58d7 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -18,7 +18,7 @@ | |||
18 | * | 18 | * |
19 | * You should have received a copy of the GNU General Public License | 19 | * You should have received a copy of the GNU General Public License |
20 | * along with Tox. If not, see <http://www.gnu.org/licenses/>. | 20 | * along with Tox. If not, see <http://www.gnu.org/licenses/>. |
21 | * | 21 | * |
22 | */ | 22 | */ |
23 | #include "nTox.h" | 23 | #include "nTox.h" |
24 | #include "misc_tools.h" | 24 | #include "misc_tools.h" |
@@ -54,7 +54,7 @@ void get_id(char *data) | |||
54 | { | 54 | { |
55 | if (self_public_key[i] < (PUB_KEY_BYTES / 2)) | 55 | if (self_public_key[i] < (PUB_KEY_BYTES / 2)) |
56 | strcpy(idstring1[i],"0"); | 56 | strcpy(idstring1[i],"0"); |
57 | else | 57 | else |
58 | strcpy(idstring1[i], ""); | 58 | strcpy(idstring1[i], ""); |
59 | sprintf(idstring2[i], "%hhX",self_public_key[i]); | 59 | sprintf(idstring2[i], "%hhX",self_public_key[i]); |
60 | } | 60 | } |
@@ -71,9 +71,9 @@ void get_id(char *data) | |||
71 | void new_lines(char *line) | 71 | void new_lines(char *line) |
72 | { | 72 | { |
73 | int i = 0; | 73 | int i = 0; |
74 | for (i = HISTORY-1; i > 0; i--) | 74 | for (i = HISTORY-1; i > 0; i--) |
75 | strncpy(lines[i], lines[i-1], STRING_LENGTH - 1); | 75 | strncpy(lines[i], lines[i-1], STRING_LENGTH - 1); |
76 | 76 | ||
77 | strncpy(lines[0], line, STRING_LENGTH - 1); | 77 | strncpy(lines[0], line, STRING_LENGTH - 1); |
78 | do_refresh(); | 78 | do_refresh(); |
79 | } | 79 | } |
@@ -133,7 +133,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
133 | if (inpt_command == 'f') { // add friend command: /f ID | 133 | if (inpt_command == 'f') { // add friend command: /f ID |
134 | int i; | 134 | int i; |
135 | char temp_id[128]; | 135 | char temp_id[128]; |
136 | for (i = 0; i < 128; i++) | 136 | for (i = 0; i < 128; i++) |
137 | temp_id[i] = line[i+prompt_offset]; | 137 | temp_id[i] = line[i+prompt_offset]; |
138 | 138 | ||
139 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); | 139 | int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); |
@@ -166,8 +166,8 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
166 | } | 166 | } |
167 | else if (inpt_command == 'm') { //message command: /m friendnumber messsage | 167 | else if (inpt_command == 'm') { //message command: /m friendnumber messsage |
168 | size_t len = strlen(line); | 168 | size_t len = strlen(line); |
169 | if(len < 3) | 169 | if(len < 3) |
170 | return; | 170 | return; |
171 | 171 | ||
172 | char numstring[len-3]; | 172 | char numstring[len-3]; |
173 | char message[len-3]; | 173 | char message[len-3]; |
@@ -248,7 +248,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
248 | else if (inpt_command == 'q') { //exit | 248 | else if (inpt_command == 'q') { //exit |
249 | endwin(); | 249 | endwin(); |
250 | exit(EXIT_SUCCESS); | 250 | exit(EXIT_SUCCESS); |
251 | } else { | 251 | } else { |
252 | new_lines("[i] invalid command"); | 252 | new_lines("[i] invalid command"); |
253 | } | 253 | } |
254 | } else { | 254 | } else { |
@@ -335,7 +335,7 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length) | |||
335 | new_lines(format_message((char*)string, friendnumber)); | 335 | new_lines(format_message((char*)string, friendnumber)); |
336 | } | 336 | } |
337 | 337 | ||
338 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) | 338 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) |
339 | { | 339 | { |
340 | char name[MAX_NAME_LENGTH]; | 340 | char name[MAX_NAME_LENGTH]; |
341 | getname(friendnumber, (uint8_t*)name); | 341 | getname(friendnumber, (uint8_t*)name); |
@@ -344,7 +344,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) | |||
344 | new_lines(msg); | 344 | new_lines(msg); |
345 | } | 345 | } |
346 | 346 | ||
347 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) | 347 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) |
348 | { | 348 | { |
349 | char name[MAX_NAME_LENGTH]; | 349 | char name[MAX_NAME_LENGTH]; |
350 | getname(friendnumber, (uint8_t*)name); | 350 | getname(friendnumber, (uint8_t*)name); |
@@ -353,7 +353,7 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) | |||
353 | new_lines(msg); | 353 | new_lines(msg); |
354 | } | 354 | } |
355 | 355 | ||
356 | void load_key() | 356 | void load_key() |
357 | { | 357 | { |
358 | FILE *data_file = NULL; | 358 | FILE *data_file = NULL; |
359 | data_file = fopen("data","r"); | 359 | data_file = fopen("data","r"); |
@@ -368,7 +368,7 @@ void load_key() | |||
368 | exit(1); | 368 | exit(1); |
369 | } | 369 | } |
370 | Messenger_load(data, size); | 370 | Messenger_load(data, size); |
371 | } else { | 371 | } else { |
372 | //else save new keys | 372 | //else save new keys |
373 | int size = Messenger_size(); | 373 | int size = Messenger_size(); |
374 | uint8_t data[size]; | 374 | uint8_t data[size]; |
@@ -418,9 +418,9 @@ int main(int argc, char *argv[]) | |||
418 | int resolved_address = resolve_addr(argv[1]); | 418 | int resolved_address = resolve_addr(argv[1]); |
419 | if (resolved_address != 0) | 419 | if (resolved_address != 0) |
420 | bootstrap_ip_port.ip.i = resolved_address; | 420 | bootstrap_ip_port.ip.i = resolved_address; |
421 | else | 421 | else |
422 | exit(1); | 422 | exit(1); |
423 | 423 | ||
424 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); | 424 | DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); |
425 | nodelay(stdscr, TRUE); | 425 | nodelay(stdscr, TRUE); |
426 | while(true) { | 426 | while(true) { |
@@ -441,7 +441,7 @@ int main(int argc, char *argv[]) | |||
441 | if (c == '\n') { | 441 | if (c == '\n') { |
442 | line_eval(lines, line); | 442 | line_eval(lines, line); |
443 | strcpy(line, ""); | 443 | strcpy(line, ""); |
444 | } else if (c == 127) { | 444 | } else if (c == 8 || c == 127) { |
445 | line[strlen(line)-1] = '\0'; | 445 | line[strlen(line)-1] = '\0'; |
446 | } else if (isalnum(c) || ispunct(c) || c == ' ') { | 446 | } else if (isalnum(c) || ispunct(c) || c == ' ') { |
447 | strcpy(line, appender(line, (char) c)); | 447 | strcpy(line, appender(line, (char) c)); |
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index 19f5c972..7cae1c0a 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c | |||
@@ -47,21 +47,8 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) | |||
47 | fix_name(msg); | 47 | fix_name(msg); |
48 | fix_name(nick); | 48 | fix_name(nick); |
49 | 49 | ||
50 | int inthour = timeinfo->tm_hour; | ||
51 | int intmin = timeinfo->tm_min; | ||
52 | char min[2]; | ||
53 | char hour[2]; | ||
54 | sprintf(hour,"%d",inthour); | ||
55 | if (intmin < 10) { | ||
56 | sprintf(min,"0%d",intmin); | ||
57 | } else { | ||
58 | sprintf(min,"%d",intmin); | ||
59 | } | ||
60 | |||
61 | |||
62 | wattron(ctx->history, COLOR_PAIR(2)); | 50 | wattron(ctx->history, COLOR_PAIR(2)); |
63 | wprintw(ctx->history,"%s",hour); | 51 | wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); |
64 | wprintw(ctx->history,":%s ",min); | ||
65 | wattron(ctx->history, COLOR_PAIR(4)); | 52 | wattron(ctx->history, COLOR_PAIR(4)); |
66 | wprintw(ctx->history, "%s: ", nick); | 53 | wprintw(ctx->history, "%s: ", nick); |
67 | wattroff(ctx->history, COLOR_PAIR(4)); | 54 | wattroff(ctx->history, COLOR_PAIR(4)); |
@@ -106,24 +93,11 @@ static void chat_onKey(ToxWindow* self, int key) { | |||
106 | } | 93 | } |
107 | } | 94 | } |
108 | else if(key == '\n') { | 95 | else if(key == '\n') { |
109 | |||
110 | int inthour = timeinfo->tm_hour; //Pretty bad, but it gets the job done | ||
111 | int intmin = timeinfo->tm_min; | ||
112 | char min[2]; | ||
113 | char hour[2]; | ||
114 | sprintf(hour,"%d",inthour); | ||
115 | if (intmin < 10) { | ||
116 | sprintf(min,"0%d",intmin); | ||
117 | } else { | ||
118 | sprintf(min,"%d",intmin); | ||
119 | } | ||
120 | wattron(ctx->history, COLOR_PAIR(2)); | 96 | wattron(ctx->history, COLOR_PAIR(2)); |
121 | wprintw(ctx->history,"%s",hour); | 97 | wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); |
122 | wprintw(ctx->history,":%s ",min); | ||
123 | wattron(ctx->history, COLOR_PAIR(1)); | 98 | wattron(ctx->history, COLOR_PAIR(1)); |
124 | wprintw(ctx->history, "you: ", ctx->line); | 99 | wprintw(ctx->history, "you: ", ctx->line); |
125 | wattroff(ctx->history, COLOR_PAIR(1)); | 100 | wattroff(ctx->history, COLOR_PAIR(1)); |
126 | |||
127 | wprintw(ctx->history, "%s\n", ctx->line); | 101 | wprintw(ctx->history, "%s\n", ctx->line); |
128 | 102 | ||
129 | if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) { | 103 | if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) { |
@@ -140,7 +114,7 @@ static void chat_onKey(ToxWindow* self, int key) { | |||
140 | ctx->line[--ctx->pos] = '\0'; | 114 | ctx->line[--ctx->pos] = '\0'; |
141 | } | 115 | } |
142 | } | 116 | } |
143 | 117 | ||
144 | } | 118 | } |
145 | 119 | ||
146 | static void chat_onDraw(ToxWindow* self) { | 120 | static void chat_onDraw(ToxWindow* self) { |
@@ -188,7 +162,7 @@ ToxWindow new_chat(int friendnum) { | |||
188 | uint8_t nick[MAX_NAME_LENGTH] = {0}; | 162 | uint8_t nick[MAX_NAME_LENGTH] = {0}; |
189 | getname(friendnum, (uint8_t*) &nick); | 163 | getname(friendnum, (uint8_t*) &nick); |
190 | fix_name(nick); | 164 | fix_name(nick); |
191 | 165 | ||
192 | snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum); | 166 | snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum); |
193 | 167 | ||
194 | ChatContext* x = calloc(1, sizeof(ChatContext)); | 168 | ChatContext* x = calloc(1, sizeof(ChatContext)); |