summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-08-02 16:36:52 -0400
committerirungentoo <irungentoo@gmail.com>2013-08-02 16:36:52 -0400
commitf9d28d379227ff830f4baac60f4db07c5ebd1677 (patch)
treee87ed342c80856204aad3fb09a984e0983393469 /testing
parent61f41474e39e151ce657c17566606227e7155632 (diff)
parent58ef293ca4fa7f58b0ba9b80cfeb1dfe124c5bff (diff)
Merge branch 'master' of https://github.com/Astonex/ProjectTox-Core into Astonex-master
Conflicts: testing/nTox_win32.c
Diffstat (limited to 'testing')
-rw-r--r--testing/nTox_win32.c272
-rw-r--r--testing/nTox_win32.h7
2 files changed, 181 insertions, 98 deletions
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c
index 27fc6ff3..cccd44df 100644
--- a/testing/nTox_win32.c
+++ b/testing/nTox_win32.c
@@ -28,6 +28,7 @@
28 28
29uint8_t pending_requests[256][CLIENT_ID_SIZE]; 29uint8_t pending_requests[256][CLIENT_ID_SIZE];
30uint8_t num_requests = 0; 30uint8_t num_requests = 0;
31uint32_t maxnumfriends;
31 32
32char line[STRING_LENGTH]; 33char line[STRING_LENGTH];
33char users_id[200]; 34char users_id[200];
@@ -115,32 +116,178 @@ void load_key()
115 fclose(data_file); 116 fclose(data_file);
116} 117}
117 118
119void add_friend()
120{
121 int i;
122 char temp_id[128];
123
124 for (i = 0; i < 128; i++)
125 temp_id[i] = line[i+3];
126
127 int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
128
129 if (num >= 0) {
130 char numstring[100];
131 sprintf(numstring, "\n[i] Friend request sent. Wait to be accepted. Friend id: %d\n\n", num);
132 printf(numstring);
133 ++maxnumfriends;
134 }
135 else if (num == -1)
136 printf("\n[i] Message is too long.\n\n");
137
138 else if (num == -2)
139 printf("\n[i] Please add a message to your friend request.\n\n");
140
141 else if (num == -3)
142 printf("\n[i] That appears to be your own ID.\n\n");
143
144 else if (num == -4)
145 printf("\n[i] Friend request already sent.\n\n");
146
147 else if (num == -5)
148 printf("\n[i] Undefined error when adding friend\n\n");
149}
150
151void list_friends()
152{
153 int activefriends = 0;
154 int i;
155
156 for (i = 0; i <= maxnumfriends; i++) {
157 if (m_friendstatus(i) == 4)
158 activefriends++;
159 }
160
161 printf("\n[i] Friend List | Total: %d\n\n", activefriends);
162
163 for (i = 0; i <= getnumfriends(); i++) {
164 char name[MAX_NAME_LENGTH];
165 getname(i, (uint8_t*)name);
166
167 if (m_friendstatus(i) == 4)
168 printf("[%d] %s\n\n", i, (uint8_t*)name);
169 }
170}
171
172void delete_friend()
173{
174 size_t len = strlen(line);
175 char numstring[len-3];
176 int i;
177
178 for (i = 0; i < len; i++) {
179 if (line[i+3] != ' ')
180 numstring[i] = line[i+3];
181 }
182
183 int num = atoi(numstring);
184 m_delfriend(num);
185 --maxnumfriends;
186 printf("\n\n");
187}
188
189void message_friend()
190{
191 size_t len = strlen(line);
192 char numstring[len-3];
193 char message[len-3];
194 int i;
195
196 for (i = 0; i < len; i++) {
197
198 if (line[i+3] != ' ')
199 numstring[i] = line[i+3];
200
201 else {
202 int j;
203
204 for (j = (i+1); j < len; j++)
205 message[j-i-1] = line[j+3];
206
207 break;
208 }
209 }
210
211 int num = atoi(numstring);
212
213 if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1)
214 printf("\n[i] could not send message (they may be offline): %s\n", message);
215
216 else
217 printf("\n");
218}
219
220void change_nickname()
221{
222 uint8_t name[MAX_NAME_LENGTH];
223 int i = 0;
224 size_t len = strlen(line);
225
226 for (i = 3; i < len; i++) {
227
228 if (line[i] == 0 || line[i] == '\n')
229 break;
230
231 name[i-3] = line[i];
232 }
233
234 name[i-3] = 0;
235 setname(name, i);
236 char numstring[100];
237 sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name);
238 printf(numstring);
239
240 FILE *name_file = NULL;
241 name_file = fopen("namefile.txt", "w");
242 fprintf(name_file, "%s", (char*)name);
243 fclose(name_file);
244}
245
246void change_status()
247{
248 uint8_t status[MAX_USERSTATUS_LENGTH];
249 int i = 0;
250 size_t len = strlen(line);
251
252 for (i = 3; i < len; i++) {
253 if (line[i] == 0 || line[i] == '\n')
254 break;
255
256 status[i-3] = line[i];
257 }
258
259 status[i-3] = 0;
260 m_set_userstatus(status, strlen((char*)status));
261 char numstring[100];
262 sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status);
263 printf(numstring);
264
265 FILE* status_file = NULL;
266 status_file = fopen("statusfile.txt", "w");
267 fprintf(status_file, "%s", (char*)status);
268 fclose(status_file);
269}
270
271void accept_friend_request()
272{
273 uint8_t numf = atoi(line + 3);
274 char numchar[100];
275 sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf);
276 printf(numchar);
277 int num = m_addfriend_norequest(pending_requests[numf]);
278 sprintf(numchar, "\n[i] added friendnumber %d\n\n", num);
279 printf(numchar);
280 ++maxnumfriends;
281}
282
118void line_eval(char* line) 283void line_eval(char* line)
119{ 284{
120 if(line[0] == '/') { 285 if(line[0] == '/') {
286
121 char inpt_command = line[1]; 287 char inpt_command = line[1];
122 /* Add friend */ 288
123 if(inpt_command == 'f') { 289 if(inpt_command == 'f') {
124 int i; 290 add_friend(line);
125 char temp_id[128];
126 for (i = 0; i < 128; i++)
127 temp_id[i] = line[i+3];
128 int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
129 if (num >= 0) {
130 char numstring[100];
131 sprintf(numstring, "\n[i] Friend request sent. Wait to be accepted. Friend id: %d\n\n", num);
132 printf(numstring);
133 }
134 else if (num == -1)
135 printf("\n[i] Message is too long.\n\n");
136 else if (num == -2)
137 printf("\n[i] Please add a message to your friend request.\n\n");
138 else if (num == -3)
139 printf("\n[i] That appears to be your own ID.\n\n");
140 else if (num == -4)
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");
144 } 291 }
145 292
146 else if (inpt_command == 'r') { 293 else if (inpt_command == 'r') {
@@ -149,96 +296,27 @@ void line_eval(char* line)
149 } 296 }
150 297
151 else if (inpt_command == 'l') { 298 else if (inpt_command == 'l') {
152 int activefriends = 0; 299 list_friends(line);
153 int i;
154 } 300 }
155 301
156 else if (inpt_command == 'd') { 302 else if (inpt_command == 'd') {
157 size_t len = strlen(line); 303 delete_friend(line);
158 char numstring[len-3];
159 int i;
160 for (i = 0; i < len; i++) {
161 if (line[i+3] != ' ') {
162 numstring[i] = line[i+3];
163 }
164 }
165 int num = atoi(numstring);
166 m_delfriend(num);
167 printf("\n\n");
168 } 304 }
169 /* Send message to friend */ 305 /* Send message to friend */
170 else if (inpt_command == 'm') { 306 else if (inpt_command == 'm') {
171 size_t len = strlen(line); 307 message_friend(line);
172 char numstring[len-3];
173 char message[len-3];
174 int i;
175 for (i = 0; i < len; i++) {
176 if (line[i+3] != ' ') {
177 numstring[i] = line[i+3];
178 } else {
179 int j;
180 for (j = (i+1); j < len; j++)
181 message[j-i-1] = line[j+3];
182 break;
183 }
184 }
185 int num = atoi(numstring);
186 if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) {
187 printf("\n[i] could not send message (they may be offline): %s\n", message);
188 } else {
189 //simply for aesthetics
190 printf("\n");
191 }
192 } 308 }
193 309
194 else if (inpt_command == 'n') { 310 else if (inpt_command == 'n') {
195 uint8_t name[MAX_NAME_LENGTH]; 311 change_nickname(line);
196 int i = 0;
197 size_t len = strlen(line);
198 for (i = 3; i < len; i++) {
199 if (line[i] == 0 || line[i] == '\n') break;
200 name[i-3] = line[i];
201 }
202 name[i-3] = 0;
203 setname(name, i);
204 char numstring[100];
205 sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name);
206 printf(numstring);
207
208 FILE *name_file = NULL;
209 name_file = fopen("namefile.txt", "w");
210 fprintf(name_file, "%s", (char*)name);
211 fclose(name_file);
212 } 312 }
213 313
214 else if (inpt_command == 's') { 314 else if (inpt_command == 's') {
215 uint8_t status[MAX_USERSTATUS_LENGTH]; 315 change_status(line);
216 int i = 0;
217 size_t len = strlen(line);
218 for (i = 3; i < len; i++) {
219 if (line[i] == 0 || line[i] == '\n') break;
220 status[i-3] = line[i];
221 }
222 status[i-3] = 0;
223 m_set_userstatus(status, strlen((char*)status));
224 char numstring[100];
225 sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status);
226 printf(numstring);
227
228 FILE* status_file = NULL;
229 status_file = fopen("statusfile.txt", "w");
230 fprintf(status_file, "%s", (char*)status);
231 fclose(status_file);
232 } 316 }
233 317
234 else if (inpt_command == 'a') { 318 else if (inpt_command == 'a') {
235 uint8_t numf = atoi(line + 3); 319 accept_friend_request(line);
236 char numchar[100];
237 sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf);
238 printf(numchar);
239 int num = m_addfriend_norequest(pending_requests[numf]);
240 sprintf(numchar, "\n[i] added friendnumber %d\n\n", num);
241 printf(numchar);
242 } 320 }
243 /* EXIT */ 321 /* EXIT */
244 else if (inpt_command == 'q') { 322 else if (inpt_command == 'q') {
@@ -246,8 +324,6 @@ void line_eval(char* line)
246 m_set_userstatus(status, strlen((char*)status)); 324 m_set_userstatus(status, strlen((char*)status));
247 exit(EXIT_SUCCESS); 325 exit(EXIT_SUCCESS);
248 } 326 }
249 } else {
250 //nothing atm
251 } 327 }
252} 328}
253 329
diff --git a/testing/nTox_win32.h b/testing/nTox_win32.h
index 374348a4..211ac95f 100644
--- a/testing/nTox_win32.h
+++ b/testing/nTox_win32.h
@@ -34,6 +34,13 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length);
34void print_nickchange(int friendnumber, uint8_t *string, uint16_t length); 34void print_nickchange(int friendnumber, uint8_t *string, uint16_t length);
35void print_statuschange(int friendnumber, uint8_t *string, uint16_t length); 35void print_statuschange(int friendnumber, uint8_t *string, uint16_t length);
36void load_key(); 36void load_key();
37void add_friend();
38void list_friends();
39void delete_friend();
40void message_friend();
41void change_nickname();
42void change_status();
43void accept_friend_request();
37void line_eval(char* line); 44void line_eval(char* line);
38void get_input(); 45void get_input();
39 46