summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-08-02 10:41:03 -0400
committerirungentoo <irungentoo@gmail.com>2013-08-02 10:41:03 -0400
commitb9176974a84ccf3b3baa8b4519ed9ea6ab75a629 (patch)
tree32b0a997e3fbf4eb7ee6864550e881c7ade6a021 /testing
parent67efb67f963e66412c4aca38debd8c20af9f7ba8 (diff)
parent20951dda7dfc0625fcbaccde4ec049ef6f2caeb6 (diff)
Merge branch 'master' into Jeffail-master
Conflicts: core/DHT.c
Diffstat (limited to 'testing')
-rw-r--r--testing/nTox.c63
-rw-r--r--testing/nTox_win32.c10
-rw-r--r--testing/toxic/main.c21
-rw-r--r--testing/toxic/prompt.c24
4 files changed, 80 insertions, 38 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index f87a2a25..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
@@ -106,24 +111,28 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
106 char temp_id[128]; 111 char temp_id[128];
107 for (i = 0; i < 128; i++) 112 for (i = 0; i < 128; i++)
108 temp_id[i] = line[i+prompt_offset]; 113 temp_id[i] = line[i+prompt_offset];
114
109 int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo")); 115 int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
110 char numstring[100]; 116 char numstring[100];
111 switch (num) { 117 switch (num) {
112 case -1: 118 case -1:
113 sprintf(numstring, "[i] Incorrect key length"); 119 sprintf(numstring, "[i] Message is too long.");
114 break; 120 break;
115 case -2: 121 case -2:
116 sprintf(numstring, "[i] That appears to be your own key"); 122 sprintf(numstring, "[i] Please add a message to your request.");
117 break; 123 break;
118 case -3: 124 case -3:
119 sprintf(numstring, "[i] Friend request already sent"); 125 sprintf(numstring, "[i] That appears to be your own ID.");
120 break; 126 break;
121 case -4: 127 case -4:
122 sprintf(numstring, "[i] Could not add friend"); 128 sprintf(numstring, "[i] Friend request already sent.");
123 break; 129 break;
124 default: 130 case -5:
125 sprintf(numstring, "[i] Added friend %d", num); 131 sprintf(numstring, "[i] Undefined error when adding friend.");
126 break; 132 break;
133 default:
134 sprintf(numstring, "[i] Added friend as %d.", num);
135 break;
127 } 136 }
128 new_lines(numstring); 137 new_lines(numstring);
129 do_refresh(); 138 do_refresh();
@@ -133,6 +142,9 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
133 } 142 }
134 else if (inpt_command == 'm') { //message command: /m friendnumber messsage 143 else if (inpt_command == 'm') { //message command: /m friendnumber messsage
135 size_t len = strlen(line); 144 size_t len = strlen(line);
145 if(len < 3)
146 return;
147
136 char numstring[len-3]; 148 char numstring[len-3];
137 char message[len-3]; 149 char message[len-3];
138 int i; 150 int i;
@@ -141,13 +153,13 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
141 numstring[i] = line[i+3]; 153 numstring[i] = line[i+3];
142 } else { 154 } else {
143 int j; 155 int j;
144 for (j = (i+1); j < len; j++) 156 for (j = (i+1); j < (len+1); j++)
145 message[j-i-1] = line[j+3]; 157 message[j-i-1] = line[j+3];
146 break; 158 break;
147 } 159 }
148 } 160 }
149 int num = atoi(numstring); 161 int num = atoi(numstring);
150 if (m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { 162 if (m_sendmessage(num, (uint8_t*) message, strlen(message) + 1) != 1) {
151 new_lines("[i] could not send message"); 163 new_lines("[i] could not send message");
152 } else { 164 } else {
153 new_lines(format_message(message, -1)); 165 new_lines(format_message(message, -1));
@@ -162,7 +174,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
162 name[i-3] = line[i]; 174 name[i-3] = line[i];
163 } 175 }
164 name[i-3] = 0; 176 name[i-3] = 0;
165 setname(name, i); 177 setname(name, i - 2);
166 char numstring[100]; 178 char numstring[100];
167 sprintf(numstring, "[i] changed nick to %s", (char*)name); 179 sprintf(numstring, "[i] changed nick to %s", (char*)name);
168 new_lines(numstring); 180 new_lines(numstring);
@@ -179,7 +191,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
179 status[i-3] = line[i]; 191 status[i-3] = line[i];
180 } 192 }
181 status[i-3] = 0; 193 status[i-3] = 0;
182 m_set_userstatus(status, strlen((char*)status)); 194 m_set_userstatus(status, strlen((char*)status) + 1);
183 char numstring[100]; 195 char numstring[100];
184 sprintf(numstring, "[i] changed status to %s", (char*)status); 196 sprintf(numstring, "[i] changed status to %s", (char*)status);
185 new_lines(numstring); 197 new_lines(numstring);
@@ -313,17 +325,6 @@ void print_request(uint8_t *public_key, uint8_t *data, uint16_t length)
313 325
314void print_message(int friendnumber, uint8_t * string, uint16_t length) 326void print_message(int friendnumber, uint8_t * string, uint16_t length)
315{ 327{
316 char name[MAX_NAME_LENGTH];
317 getname(friendnumber, (uint8_t*)name);
318 char msg[100+length+strlen(name)+1];
319 time_t rawtime;
320 struct tm * timeinfo;
321 time ( &rawtime );
322 timeinfo = localtime ( &rawtime );
323 char* temp = asctime(timeinfo);
324 size_t len = strlen(temp);
325 temp[len-1] = '\0';
326 sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp
327 new_lines(format_message((char*)string, friendnumber)); 328 new_lines(format_message((char*)string, friendnumber));
328} 329}
329 330
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c
index 2394877f..42780923 100644
--- a/testing/nTox_win32.c
+++ b/testing/nTox_win32.c
@@ -132,13 +132,15 @@ void line_eval(char* line)
132 printf(numstring); 132 printf(numstring);
133 } 133 }
134 else if (num == -1) 134 else if (num == -1)
135 printf("\nWrong key size\n\n"); 135 printf("\n[i] Message is too long.\n\n");
136 else if (num == -2) 136 else if (num == -2)
137 printf("\nYou can't add yourself\n\n"); 137 printf("\n[i] Please add a message to your friend request.\n\n");
138 else if (num == -3) 138 else if (num == -3)
139 printf("\nYou already have this person added\n\n"); 139 printf("\n[i] That appears to be your own ID.\n\n");
140 else if (num == -4) 140 else if (num == -4)
141 printf("\nUndefined error when adding friend"); 141 printf("\n[i] Friend request already sent.\n\n");
142 else if (num == -5)
143 printf("\n[i] Undefined error when adding friend\n\n");
142 } 144 }
143 145
144 else if (inpt_command == 'r') { 146 else if (inpt_command == 'r') {
diff --git a/testing/toxic/main.c b/testing/toxic/main.c
index cdc6dc16..c596b708 100644
--- a/testing/toxic/main.c
+++ b/testing/toxic/main.c
@@ -280,6 +280,26 @@ void prepare_window(WINDOW* w) {
280 wresize(w, LINES-2, COLS); 280 wresize(w, LINES-2, COLS);
281} 281}
282 282
283/*
284 * Draws cursor relative to input on prompt window.
285 * Removes cursor on friends window and chat windows.
286 *
287 * TODO: Make it work for chat windows
288 */
289void position_cursor(WINDOW* w, char* title)
290{
291 curs_set(1);
292 if (strcmp(title, "[prompt]") == 0) { // main/prompt window
293 int x, y;
294 getyx(w, y, x);
295 move(y, x);
296 }
297 else if (strcmp(title, "[friends]") == 0) // friends window
298 curs_set(0);
299 else // any other window (i.e chat)
300 curs_set(0);
301}
302
283int main(int argc, char* argv[]) { 303int main(int argc, char* argv[]) {
284 int ch; 304 int ch;
285 ToxWindow* a; 305 ToxWindow* a;
@@ -299,6 +319,7 @@ int main(int argc, char* argv[]) {
299 a->blink = false; 319 a->blink = false;
300 a->onDraw(a); 320 a->onDraw(a);
301 draw_bar(); 321 draw_bar();
322 position_cursor(a->window, a->title);
302 323
303 // Handle input. 324 // Handle input.
304 ch = getch(); 325 ch = getch();
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c
index a3cf2d94..b0f83811 100644
--- a/testing/toxic/prompt.c
+++ b/testing/toxic/prompt.c
@@ -134,10 +134,28 @@ static void execute(ToxWindow* self, char* cmd) {
134 } 134 }
135 135
136 num = m_addfriend(id_bin, (uint8_t*) msg, strlen(msg)+1); 136 num = m_addfriend(id_bin, (uint8_t*) msg, strlen(msg)+1);
137 137 switch (num) {
138 wprintw(self->window, "Friend added as %d.\n", num); 138 case -1:
139 on_friendadded(num); 139 wprintw(self->window, "Message is too long.\n");
140 break;
141 case -2:
142 wprintw(self->window, "Please add a message to your request.\n");
143 case -3:
144 wprintw(self->window, "That appears to be your own ID.\n");
145 break;
146 case -4:
147 wprintw(self->window, "Friend request already sent.\n");
148 break;
149 case -5:
150 wprintw(self->window, "[i] Undefined error when adding friend.\n");
151 break;
152 default:
153 wprintw(self->window, "Friend added as %d.\n", num);
154 on_friendadded(num);
155 break;
156 }
140 } 157 }
158
141 else if(!strcmp(cmd, "help")) { 159 else if(!strcmp(cmd, "help")) {
142 print_usage(self); 160 print_usage(self);
143 } 161 }