mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Fixed friends list and deleting friends. Automatically loads name/status from last time.
This commit is contained in:
parent
f05aa30870
commit
7417dfe216
@ -126,9 +126,19 @@ void line_eval(char* line)
|
|||||||
for (i = 0; i < 128; i++)
|
for (i = 0; i < 128; i++)
|
||||||
temp_id[i] = line[i+3];
|
temp_id[i] = line[i+3];
|
||||||
int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
|
int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
|
||||||
char numstring[100];
|
if (num >= 0) {
|
||||||
sprintf(numstring, "\n[i] Friend request sent. Wait to be accepted. Friend id: %d\n\n", num);
|
char numstring[100];
|
||||||
printf(numstring);
|
sprintf(numstring, "\n[i] Friend request sent. Wait to be accepted. Friend id: %d\n\n", num);
|
||||||
|
printf(numstring);
|
||||||
|
}
|
||||||
|
else if (num == -1)
|
||||||
|
printf("\nWrong key size\n\n");
|
||||||
|
else if (num == -2)
|
||||||
|
printf("\nYou can't add yourself\n\n");
|
||||||
|
else if (num == -3)
|
||||||
|
printf("\nYou already have this person added\n\n");
|
||||||
|
else if (num == -4)
|
||||||
|
printf("\nUndefined error when adding friend");
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (inpt_command == 'r') {
|
else if (inpt_command == 'r') {
|
||||||
@ -137,15 +147,21 @@ void line_eval(char* line)
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (inpt_command == 'l') {
|
else if (inpt_command == 'l') {
|
||||||
printf("\n[i] Friend List | Total: %d\n\n", getnumfriends());
|
int activefriends = 0;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < getnumfriends(); i++) {
|
|
||||||
|
for (i = 0; i <= getnumfriends(); i++)
|
||||||
|
{
|
||||||
|
if (m_friendstatus(i) == 4)
|
||||||
|
activefriends++;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n[i] Friend List | Total: %d\n\n", activefriends);
|
||||||
|
|
||||||
|
for (i = 0; i <= getnumfriends(); i++) {
|
||||||
char name[MAX_NAME_LENGTH];
|
char name[MAX_NAME_LENGTH];
|
||||||
getname(i, (uint8_t*)name);
|
getname(i, (uint8_t*)name);
|
||||||
if (m_friendstatus(i) == 0)
|
if (m_friendstatus(i) == 4)
|
||||||
printf("[%d] No friend with this number\n\n", i);
|
|
||||||
else
|
|
||||||
printf("[%d] %s\n\n", i, (uint8_t*)name);
|
printf("[%d] %s\n\n", i, (uint8_t*)name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -181,7 +197,7 @@ void line_eval(char* line)
|
|||||||
}
|
}
|
||||||
int num = atoi(numstring);
|
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: %s\n", message);
|
printf("\n[i] could not send message (they may be offline): %s\n", message);
|
||||||
} else {
|
} else {
|
||||||
//simply for aesthetics
|
//simply for aesthetics
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@ -201,6 +217,11 @@ void line_eval(char* line)
|
|||||||
char numstring[100];
|
char numstring[100];
|
||||||
sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name);
|
sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name);
|
||||||
printf(numstring);
|
printf(numstring);
|
||||||
|
|
||||||
|
FILE *name_file = NULL;
|
||||||
|
name_file = fopen("namefile.txt", "w");
|
||||||
|
fprintf(name_file, "%s", (char*)name);
|
||||||
|
fclose(name_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (inpt_command == 's') {
|
else if (inpt_command == 's') {
|
||||||
@ -216,6 +237,11 @@ void line_eval(char* line)
|
|||||||
char numstring[100];
|
char numstring[100];
|
||||||
sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status);
|
sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status);
|
||||||
printf(numstring);
|
printf(numstring);
|
||||||
|
|
||||||
|
FILE* status_file = NULL;
|
||||||
|
status_file = fopen("statusfile.txt", "w");
|
||||||
|
fprintf(status_file, "%s", (char*)status);
|
||||||
|
fclose(status_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (inpt_command == 'a') {
|
else if (inpt_command == 'a') {
|
||||||
@ -229,6 +255,8 @@ void line_eval(char* line)
|
|||||||
}
|
}
|
||||||
/* EXIT */
|
/* EXIT */
|
||||||
else if (inpt_command == 'q') {
|
else if (inpt_command == 'q') {
|
||||||
|
uint8_t status[MAX_USERSTATUS_LENGTH] = "Offline";
|
||||||
|
m_set_userstatus(status, strlen((char*)status));
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -261,7 +289,36 @@ int main(int argc, char *argv[])
|
|||||||
} else {
|
} else {
|
||||||
load_key();
|
load_key();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int nameloaded = 0;
|
||||||
|
int statusloaded = 0;
|
||||||
|
|
||||||
|
FILE* name_file = NULL;
|
||||||
|
name_file = fopen("namefile.txt", "r");
|
||||||
|
if(name_file) {
|
||||||
|
uint8_t name[MAX_NAME_LENGTH];
|
||||||
|
while (fgets(line, MAX_NAME_LENGTH, name_file) != NULL) {
|
||||||
|
sscanf(line, "%s", (char*)name);
|
||||||
|
}
|
||||||
|
setname(name, strlen((char*)name)+1);
|
||||||
|
nameloaded = 1;
|
||||||
|
printf("%s\n", name);
|
||||||
|
}
|
||||||
|
fclose(name_file);
|
||||||
|
|
||||||
|
FILE* status_file = NULL;
|
||||||
|
status_file = fopen("statusfile.txt", "r");
|
||||||
|
if(status_file) {
|
||||||
|
uint8_t status[MAX_USERSTATUS_LENGTH];
|
||||||
|
while (fgets(line, MAX_USERSTATUS_LENGTH, status_file) != NULL) {
|
||||||
|
sscanf(line, "%s", (char*)status);
|
||||||
|
}
|
||||||
|
m_set_userstatus(status, strlen((char*)status)+1);
|
||||||
|
statusloaded = 1;
|
||||||
|
printf("%s\n", status);
|
||||||
|
}
|
||||||
|
fclose(status_file);
|
||||||
|
|
||||||
m_callback_friendrequest(print_request);
|
m_callback_friendrequest(print_request);
|
||||||
m_callback_friendmessage(print_message);
|
m_callback_friendmessage(print_message);
|
||||||
m_callback_namechange(print_nickchange);
|
m_callback_namechange(print_nickchange);
|
||||||
@ -285,6 +342,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
do_header();
|
do_header();
|
||||||
|
|
||||||
IP_Port bootstrap_ip_port;
|
IP_Port bootstrap_ip_port;
|
||||||
bootstrap_ip_port.port = htons(atoi(argv[2]));
|
bootstrap_ip_port.port = htons(atoi(argv[2]));
|
||||||
int resolved_address = resolve_addr(argv[1]);
|
int resolved_address = resolve_addr(argv[1]);
|
||||||
@ -294,9 +352,22 @@ int main(int argc, char *argv[])
|
|||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
|
DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
int on = 0;
|
int on = 0;
|
||||||
|
|
||||||
_beginthread(get_input, 0, NULL);
|
_beginthread(get_input, 0, NULL);
|
||||||
|
|
||||||
|
if (nameloaded == 1) {
|
||||||
|
printf("\nNickname automatically loaded");
|
||||||
|
printf("\n---------------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (statusloaded == 1) {
|
||||||
|
printf("\nStatus automatically loaded");
|
||||||
|
printf("\n---------------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
if (on == 1 && DHT_isconnected() == -1) {
|
if (on == 1 && DHT_isconnected() == -1) {
|
||||||
printf("\n---------------------------------");
|
printf("\n---------------------------------");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user