Merge branch 'master' of https://github.com/Astonex/ProjectTox-Core into Astonex-master

Conflicts:
	testing/nTox_win32.c
This commit is contained in:
irungentoo 2013-08-02 16:36:52 -04:00
commit f9d28d3792
2 changed files with 181 additions and 98 deletions

View File

@ -28,6 +28,7 @@
uint8_t pending_requests[256][CLIENT_ID_SIZE];
uint8_t num_requests = 0;
uint32_t maxnumfriends;
char line[STRING_LENGTH];
char users_id[200];
@ -115,90 +116,121 @@ void load_key()
fclose(data_file);
}
void line_eval(char* line)
void add_friend()
{
if(line[0] == '/') {
char inpt_command = line[1];
/* Add friend */
if(inpt_command == 'f') {
int i;
char temp_id[128];
for (i = 0; i < 128; i++)
temp_id[i] = line[i+3];
int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
if (num >= 0) {
char numstring[100];
sprintf(numstring, "\n[i] Friend request sent. Wait to be accepted. Friend id: %d\n\n", num);
printf(numstring);
++maxnumfriends;
}
else if (num == -1)
printf("\n[i] Message is too long.\n\n");
else if (num == -2)
printf("\n[i] Please add a message to your friend request.\n\n");
else if (num == -3)
printf("\n[i] That appears to be your own ID.\n\n");
else if (num == -4)
printf("\n[i] Friend request already sent.\n\n");
else if (num == -5)
printf("\n[i] Undefined error when adding friend\n\n");
}
else if (inpt_command == 'r') {
do_header();
printf("\n\n");
}
else if (inpt_command == 'l') {
void list_friends()
{
int activefriends = 0;
int i;
for (i = 0; i <= maxnumfriends; i++) {
if (m_friendstatus(i) == 4)
activefriends++;
}
else if (inpt_command == 'd') {
printf("\n[i] Friend List | Total: %d\n\n", activefriends);
for (i = 0; i <= getnumfriends(); i++) {
char name[MAX_NAME_LENGTH];
getname(i, (uint8_t*)name);
if (m_friendstatus(i) == 4)
printf("[%d] %s\n\n", i, (uint8_t*)name);
}
}
void delete_friend()
{
size_t len = strlen(line);
char numstring[len-3];
int i;
for (i = 0; i < len; i++) {
if (line[i+3] != ' ') {
if (line[i+3] != ' ')
numstring[i] = line[i+3];
}
}
int num = atoi(numstring);
m_delfriend(num);
--maxnumfriends;
printf("\n\n");
}
/* Send message to friend */
else if (inpt_command == 'm') {
void message_friend()
{
size_t len = strlen(line);
char numstring[len-3];
char message[len-3];
int i;
for (i = 0; i < len; i++) {
if (line[i+3] != ' ') {
if (line[i+3] != ' ')
numstring[i] = line[i+3];
} else {
else {
int j;
for (j = (i+1); j < len; j++)
message[j-i-1] = line[j+3];
break;
}
}
int num = atoi(numstring);
if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) {
if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1)
printf("\n[i] could not send message (they may be offline): %s\n", message);
} else {
//simply for aesthetics
else
printf("\n");
}
}
else if (inpt_command == 'n') {
void change_nickname()
{
uint8_t name[MAX_NAME_LENGTH];
int i = 0;
size_t len = strlen(line);
for (i = 3; i < len; i++) {
if (line[i] == 0 || line[i] == '\n') break;
if (line[i] == 0 || line[i] == '\n')
break;
name[i-3] = line[i];
}
name[i-3] = 0;
setname(name, i);
char numstring[100];
@ -211,14 +243,19 @@ void line_eval(char* line)
fclose(name_file);
}
else if (inpt_command == 's') {
void change_status()
{
uint8_t status[MAX_USERSTATUS_LENGTH];
int i = 0;
size_t len = strlen(line);
for (i = 3; i < len; i++) {
if (line[i] == 0 || line[i] == '\n') break;
if (line[i] == 0 || line[i] == '\n')
break;
status[i-3] = line[i];
}
status[i-3] = 0;
m_set_userstatus(status, strlen((char*)status));
char numstring[100];
@ -231,7 +268,8 @@ void line_eval(char* line)
fclose(status_file);
}
else if (inpt_command == 'a') {
void accept_friend_request()
{
uint8_t numf = atoi(line + 3);
char numchar[100];
sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf);
@ -239,6 +277,46 @@ void line_eval(char* line)
int num = m_addfriend_norequest(pending_requests[numf]);
sprintf(numchar, "\n[i] added friendnumber %d\n\n", num);
printf(numchar);
++maxnumfriends;
}
void line_eval(char* line)
{
if(line[0] == '/') {
char inpt_command = line[1];
if(inpt_command == 'f') {
add_friend(line);
}
else if (inpt_command == 'r') {
do_header();
printf("\n\n");
}
else if (inpt_command == 'l') {
list_friends(line);
}
else if (inpt_command == 'd') {
delete_friend(line);
}
/* Send message to friend */
else if (inpt_command == 'm') {
message_friend(line);
}
else if (inpt_command == 'n') {
change_nickname(line);
}
else if (inpt_command == 's') {
change_status(line);
}
else if (inpt_command == 'a') {
accept_friend_request(line);
}
/* EXIT */
else if (inpt_command == 'q') {
@ -246,8 +324,6 @@ void line_eval(char* line)
m_set_userstatus(status, strlen((char*)status));
exit(EXIT_SUCCESS);
}
} else {
//nothing atm
}
}

View File

@ -34,6 +34,13 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length);
void print_nickchange(int friendnumber, uint8_t *string, uint16_t length);
void print_statuschange(int friendnumber, uint8_t *string, uint16_t length);
void load_key();
void add_friend();
void list_friends();
void delete_friend();
void message_friend();
void change_nickname();
void change_status();
void accept_friend_request();
void line_eval(char* line);
void get_input();