diff options
Diffstat (limited to 'testing')
-rw-r--r-- | testing/nTox.c | 31 | ||||
-rw-r--r-- | testing/nTox_win32.c | 4 | ||||
-rw-r--r-- | testing/toxic/chat.c | 8 | ||||
-rw-r--r-- | testing/toxic/main.c | 3 | ||||
-rw-r--r-- | testing/toxic/prompt.c | 24 |
5 files changed, 30 insertions, 40 deletions
diff --git a/testing/nTox.c b/testing/nTox.c index f7d929f2..81cac0b6 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -89,7 +89,12 @@ char *format_message(char *message, int friendnum) | |||
89 | char* time = asctime(timeinfo); | 89 | char* time = asctime(timeinfo); |
90 | size_t len = strlen(time); | 90 | size_t len = strlen(time); |
91 | time[len-1] = '\0'; | 91 | time[len-1] = '\0'; |
92 | sprintf(msg, "[%d] %s <%s> %s", friendnum, time, name, message); // timestamp | 92 | if (friendnum != -1) { |
93 | sprintf(msg, "[%d] %s <%s> %s", friendnum, time, name, message); | ||
94 | } else { | ||
95 | // This message came from ourselves | ||
96 | sprintf(msg, "%s <%s> %s", time, name, message); | ||
97 | } | ||
93 | return msg; | 98 | return msg; |
94 | } | 99 | } |
95 | 100 | ||
@@ -137,6 +142,9 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
137 | } | 142 | } |
138 | else if (inpt_command == 'm') { //message command: /m friendnumber messsage | 143 | else if (inpt_command == 'm') { //message command: /m friendnumber messsage |
139 | size_t len = strlen(line); | 144 | size_t len = strlen(line); |
145 | if(len < 3) | ||
146 | return; | ||
147 | |||
140 | char numstring[len-3]; | 148 | char numstring[len-3]; |
141 | char message[len-3]; | 149 | char message[len-3]; |
142 | int i; | 150 | int i; |
@@ -145,13 +153,13 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
145 | numstring[i] = line[i+3]; | 153 | numstring[i] = line[i+3]; |
146 | } else { | 154 | } else { |
147 | int j; | 155 | int j; |
148 | for (j = (i+1); j < len; j++) | 156 | for (j = (i+1); j < (len+1); j++) |
149 | message[j-i-1] = line[j+3]; | 157 | message[j-i-1] = line[j+3]; |
150 | break; | 158 | break; |
151 | } | 159 | } |
152 | } | 160 | } |
153 | int num = atoi(numstring); | 161 | int num = atoi(numstring); |
154 | if (m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { | 162 | if (m_sendmessage(num, (uint8_t*) message, strlen(message) + 1) != 1) { |
155 | new_lines("[i] could not send message"); | 163 | new_lines("[i] could not send message"); |
156 | } else { | 164 | } else { |
157 | new_lines(format_message(message, -1)); | 165 | new_lines(format_message(message, -1)); |
@@ -166,7 +174,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
166 | name[i-3] = line[i]; | 174 | name[i-3] = line[i]; |
167 | } | 175 | } |
168 | name[i-3] = 0; | 176 | name[i-3] = 0; |
169 | setname(name, i); | 177 | setname(name, i - 2); |
170 | char numstring[100]; | 178 | char numstring[100]; |
171 | sprintf(numstring, "[i] changed nick to %s", (char*)name); | 179 | sprintf(numstring, "[i] changed nick to %s", (char*)name); |
172 | new_lines(numstring); | 180 | new_lines(numstring); |
@@ -183,7 +191,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
183 | status[i-3] = line[i]; | 191 | status[i-3] = line[i]; |
184 | } | 192 | } |
185 | status[i-3] = 0; | 193 | status[i-3] = 0; |
186 | m_set_userstatus(status, strlen((char*)status)); | 194 | m_set_userstatus(status, strlen((char*)status) + 1); |
187 | char numstring[100]; | 195 | char numstring[100]; |
188 | sprintf(numstring, "[i] changed status to %s", (char*)status); | 196 | sprintf(numstring, "[i] changed status to %s", (char*)status); |
189 | new_lines(numstring); | 197 | new_lines(numstring); |
@@ -317,17 +325,6 @@ void print_request(uint8_t *public_key, uint8_t *data, uint16_t length) | |||
317 | 325 | ||
318 | void print_message(int friendnumber, uint8_t * string, uint16_t length) | 326 | void print_message(int friendnumber, uint8_t * string, uint16_t length) |
319 | { | 327 | { |
320 | char name[MAX_NAME_LENGTH]; | ||
321 | getname(friendnumber, (uint8_t*)name); | ||
322 | char msg[100+length+strlen(name)+1]; | ||
323 | time_t rawtime; | ||
324 | struct tm * timeinfo; | ||
325 | time ( &rawtime ); | ||
326 | timeinfo = localtime ( &rawtime ); | ||
327 | char* temp = asctime(timeinfo); | ||
328 | size_t len = strlen(temp); | ||
329 | temp[len-1] = '\0'; | ||
330 | sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp | ||
331 | new_lines(format_message((char*)string, friendnumber)); | 328 | new_lines(format_message((char*)string, friendnumber)); |
332 | } | 329 | } |
333 | 330 | ||
@@ -427,7 +424,7 @@ int main(int argc, char *argv[]) | |||
427 | IP_Port bootstrap_ip_port; | 424 | IP_Port bootstrap_ip_port; |
428 | bootstrap_ip_port.port = htons(atoi(argv[2])); | 425 | bootstrap_ip_port.port = htons(atoi(argv[2])); |
429 | int resolved_address = resolve_addr(argv[1]); | 426 | int resolved_address = resolve_addr(argv[1]); |
430 | if (resolved_address != -1) | 427 | if (resolved_address != 0) |
431 | bootstrap_ip_port.ip.i = resolved_address; | 428 | bootstrap_ip_port.ip.i = resolved_address; |
432 | else | 429 | else |
433 | exit(1); | 430 | exit(1); |
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c index 8d9f3547..42780923 100644 --- a/testing/nTox_win32.c +++ b/testing/nTox_win32.c | |||
@@ -348,7 +348,7 @@ int main(int argc, char *argv[]) | |||
348 | IP_Port bootstrap_ip_port; | 348 | IP_Port bootstrap_ip_port; |
349 | bootstrap_ip_port.port = htons(atoi(argv[2])); | 349 | bootstrap_ip_port.port = htons(atoi(argv[2])); |
350 | int resolved_address = resolve_addr(argv[1]); | 350 | int resolved_address = resolve_addr(argv[1]); |
351 | if (resolved_address != -1) | 351 | if (resolved_address != 0) |
352 | bootstrap_ip_port.ip.i = resolved_address; | 352 | bootstrap_ip_port.ip.i = resolved_address; |
353 | else | 353 | else |
354 | exit(1); | 354 | exit(1); |
@@ -386,4 +386,4 @@ int main(int argc, char *argv[]) | |||
386 | Sleep(1); | 386 | Sleep(1); |
387 | } | 387 | } |
388 | return 0; | 388 | return 0; |
389 | } \ No newline at end of file | 389 | } |
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index dceb1d7b..854d3817 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c | |||
@@ -60,6 +60,8 @@ static void chat_onNickChange(ToxWindow* self, int num, uint8_t* nick, uint16_t | |||
60 | nick[len-1] = '\0'; | 60 | nick[len-1] = '\0'; |
61 | fix_name(nick); | 61 | fix_name(nick); |
62 | 62 | ||
63 | snprintf(self->title, sizeof(self->title), "[%s (%d)]", nick, num); | ||
64 | |||
63 | wattron(ctx->history, COLOR_PAIR(3)); | 65 | wattron(ctx->history, COLOR_PAIR(3)); |
64 | wprintw(ctx->history, " * Your partner changed nick to '%s'\n", nick); | 66 | wprintw(ctx->history, " * Your partner changed nick to '%s'\n", nick); |
65 | wattroff(ctx->history, COLOR_PAIR(3)); | 67 | wattroff(ctx->history, COLOR_PAIR(3)); |
@@ -144,7 +146,11 @@ ToxWindow new_chat(int friendnum) { | |||
144 | ret.onNickChange = &chat_onNickChange; | 146 | ret.onNickChange = &chat_onNickChange; |
145 | ret.onStatusChange = &chat_onStatusChange; | 147 | ret.onStatusChange = &chat_onStatusChange; |
146 | 148 | ||
147 | snprintf(ret.title, sizeof(ret.title), "[chat %d]", friendnum); | 149 | uint8_t nick[MAX_NAME_LENGTH] = {0}; |
150 | getname(friendnum, (uint8_t*) &nick); | ||
151 | fix_name(nick); | ||
152 | |||
153 | snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum); | ||
148 | 154 | ||
149 | ChatContext* x = calloc(1, sizeof(ChatContext)); | 155 | ChatContext* x = calloc(1, sizeof(ChatContext)); |
150 | x->friendnum = friendnum; | 156 | x->friendnum = friendnum; |
diff --git a/testing/toxic/main.c b/testing/toxic/main.c index fffc3f84..cdc6dc16 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c | |||
@@ -305,6 +305,9 @@ int main(int argc, char* argv[]) { | |||
305 | if(ch == '\t') { | 305 | if(ch == '\t') { |
306 | w_active = (w_active + 1) % w_num; | 306 | w_active = (w_active + 1) % w_num; |
307 | } | 307 | } |
308 | else if(ch == KEY_BTAB) { | ||
309 | w_active = (w_active + w_num - 1) % w_num; | ||
310 | } | ||
308 | else if(ch != ERR) { | 311 | else if(ch != ERR) { |
309 | a->onKey(a, ch); | 312 | a->onKey(a, ch); |
310 | } | 313 | } |
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index 21c1f52a..b0f83811 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c | |||
@@ -16,6 +16,7 @@ uint8_t pending_requests[256][CLIENT_ID_SIZE]; // XXX | |||
16 | uint8_t num_requests=0; // XXX | 16 | uint8_t num_requests=0; // XXX |
17 | 17 | ||
18 | extern void on_friendadded(int friendnumber); | 18 | extern void on_friendadded(int friendnumber); |
19 | static void print_usage(ToxWindow* self); | ||
19 | 20 | ||
20 | // XXX: | 21 | // XXX: |
21 | int add_req(uint8_t* public_key) { | 22 | int add_req(uint8_t* public_key) { |
@@ -82,8 +83,8 @@ static void execute(ToxWindow* self, char* cmd) { | |||
82 | 83 | ||
83 | dht.port = htons(atoi(port)); | 84 | dht.port = htons(atoi(port)); |
84 | 85 | ||
85 | int resolved_address = resolve_addr(ip); | 86 | uint32_t resolved_address = resolve_addr(ip); |
86 | if (resolved_address == -1) { | 87 | if (resolved_address == 0) { |
87 | return; | 88 | return; |
88 | } | 89 | } |
89 | 90 | ||
@@ -156,24 +157,7 @@ static void execute(ToxWindow* self, char* cmd) { | |||
156 | } | 157 | } |
157 | 158 | ||
158 | else if(!strcmp(cmd, "help")) { | 159 | else if(!strcmp(cmd, "help")) { |
159 | wattron(self->window, COLOR_PAIR(2) | A_BOLD); | 160 | print_usage(self); |
160 | wprintw(self->window, "Commands:\n"); | ||
161 | wattroff(self->window, A_BOLD); | ||
162 | |||
163 | wprintw(self->window, " connect <ip> <port> <key> : Connect to DHT server\n"); | ||
164 | wprintw(self->window, " add <id> <message> : Add friend\n"); | ||
165 | wprintw(self->window, " status <message> : Set your status\n"); | ||
166 | wprintw(self->window, " nick <nickname> : Set your nickname\n"); | ||
167 | wprintw(self->window, " accept <number> : Accept friend request\n"); | ||
168 | wprintw(self->window, " myid : Print your ID\n"); | ||
169 | wprintw(self->window, " quit/exit : Exit program\n"); | ||
170 | |||
171 | |||
172 | wattron(self->window, A_BOLD); | ||
173 | wprintw(self->window, "TIP: Use the TAB key to navigate through the tabs.\n\n"); | ||
174 | wattroff(self->window, A_BOLD); | ||
175 | |||
176 | wattroff(self->window, COLOR_PAIR(2)); | ||
177 | } | 161 | } |
178 | else if(!strncmp(cmd, "status ", strlen("status "))) { | 162 | else if(!strncmp(cmd, "status ", strlen("status "))) { |
179 | char* msg; | 163 | char* msg; |