summaryrefslogtreecommitdiff
path: root/testing/nTox.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/nTox.c')
-rw-r--r--testing/nTox.c47
1 files changed, 40 insertions, 7 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index 3d410f19..9876f4ba 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -20,10 +20,10 @@
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
24#include "nTox.h" 23#include "nTox.h"
25#include "misc_tools.h" 24#include "misc_tools.h"
26 25
26
27#include <stdio.h> 27#include <stdio.h>
28#include <time.h> 28#include <time.h>
29#ifdef WIN32 29#ifdef WIN32
@@ -50,13 +50,33 @@ void new_lines(char *line)
50 do_refresh(); 50 do_refresh();
51} 51}
52 52
53
54void print_friendlist()
55{
56 char name[MAX_NAME_LENGTH];
57 uint32_t i;
58
59 new_lines("[i] Friend List:");
60 for (i=0; i <= num_requests; i++) {
61 char fstring[128];
62
63 getname(i, (uint8_t*)name);
64 if (strlen(name) <= 0) {
65 sprintf(fstring, "[i] Friend: NULL\n\tid: %i", i);
66 } else {
67 sprintf(fstring, "[i] Friend: %s\n\tid: %i", (uint8_t*)name, i);
68 }
69 new_lines(fstring);
70 }
71}
72
53char *format_message(char *message, int friendnum) 73char *format_message(char *message, int friendnum)
54{ 74{
55 char name[MAX_NAME_LENGTH]; 75 char name[MAX_NAME_LENGTH];
56 if(friendnum != -1) { 76 if(friendnum != -1) {
57 getfriendname(friendnum, (uint8_t*)name); 77 getname(friendnum, (uint8_t*)name);
58 } else { 78 } else {
59 getname((uint8_t*)name); 79 getself_name((uint8_t*)name);
60 } 80 }
61 char *msg = malloc(100+strlen(message)+strlen(name)+1); 81 char *msg = malloc(100+strlen(message)+strlen(name)+1);
62 time_t rawtime; 82 time_t rawtime;
@@ -126,6 +146,9 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
126 sprintf(numstring, "[i] changed nick to %s", (char*)name); 146 sprintf(numstring, "[i] changed nick to %s", (char*)name);
127 new_lines(numstring); 147 new_lines(numstring);
128 } 148 }
149 else if (line[1] == 'l') {
150 print_friendlist();
151 }
129 else if (line[1] == 's') { 152 else if (line[1] == 's') {
130 uint8_t status[MAX_USERSTATUS_LENGTH]; 153 uint8_t status[MAX_USERSTATUS_LENGTH];
131 int i = 0; 154 int i = 0;
@@ -151,11 +174,20 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
151 do_refresh(); 174 do_refresh();
152 175
153 } 176 }
177
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)");
180 new_lines("[i] /l list (list friends), /h for help, /n nick (to change nickname), /q (to quit)");
181 }
182
154 else if (line[1] == 'q') { //exit 183 else if (line[1] == 'q') { //exit
155 endwin(); 184 endwin();
156 exit(EXIT_SUCCESS); 185 exit(EXIT_SUCCESS);
186 } else {
187 new_lines("[i] invalid command");
157 } 188 }
158 } else { 189 } else {
190 new_lines("[i] invalid command");
159 //new_lines(line); 191 //new_lines(line);
160 } 192 }
161} 193}
@@ -236,7 +268,7 @@ void print_request(uint8_t *public_key, uint8_t *data, uint16_t length)
236void print_message(int friendnumber, uint8_t * string, uint16_t length) 268void print_message(int friendnumber, uint8_t * string, uint16_t length)
237{ 269{
238 char name[MAX_NAME_LENGTH]; 270 char name[MAX_NAME_LENGTH];
239 getfriendname(friendnumber, (uint8_t*)name); 271 getname(friendnumber, (uint8_t*)name);
240 char msg[100+length+strlen(name)+1]; 272 char msg[100+length+strlen(name)+1];
241 time_t rawtime; 273 time_t rawtime;
242 struct tm * timeinfo; 274 struct tm * timeinfo;
@@ -251,7 +283,7 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length)
251 283
252void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) { 284void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) {
253 char name[MAX_NAME_LENGTH]; 285 char name[MAX_NAME_LENGTH];
254 getfriendname(friendnumber, (uint8_t*)name); 286 getname(friendnumber, (uint8_t*)name);
255 char msg[100+length]; 287 char msg[100+length];
256 sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string); 288 sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string);
257 new_lines(msg); 289 new_lines(msg);
@@ -259,7 +291,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) {
259 291
260void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { 292void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) {
261 char name[MAX_NAME_LENGTH]; 293 char name[MAX_NAME_LENGTH];
262 getfriendname(friendnumber, (uint8_t*)name); 294 getname(friendnumber, (uint8_t*)name);
263 char msg[100+length+strlen(name)+1]; 295 char msg[100+length+strlen(name)+1];
264 sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string); 296 sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string);
265 new_lines(msg); 297 new_lines(msg);
@@ -335,7 +367,8 @@ int main(int argc, char *argv[])
335 raw(); 367 raw();
336 getmaxyx(stdscr,y,x); 368 getmaxyx(stdscr,y,x);
337 new_lines(idstring0); 369 new_lines(idstring0);
338 new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /q (to quit)"); 370 new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status)");
371 new_lines("[i] /l list (list friends), /n nick (to change nickname), /q (to quit)");
339 strcpy(line, ""); 372 strcpy(line, "");
340 IP_Port bootstrap_ip_port; 373 IP_Port bootstrap_ip_port;
341 bootstrap_ip_port.port = htons(atoi(argv[2])); 374 bootstrap_ip_port.port = htons(atoi(argv[2]));