mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge branch 'master' of https://github.com/Astonex/ProjectTox-Core into Astonex-master
Conflicts: testing/nTox_win32.c
This commit is contained in:
commit
b5b28e43f8
|
@ -166,11 +166,13 @@ int m_delfriend(int friendnumber)
|
|||
free(friendlist[friendnumber].userstatus);
|
||||
memset(&friendlist[friendnumber], 0, sizeof(Friend));
|
||||
uint32_t i;
|
||||
|
||||
for (i = numfriends; i != 0; --i) {
|
||||
if (friendlist[i-1].status != 0)
|
||||
break;
|
||||
}
|
||||
numfriends = i;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -77,11 +77,12 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length)
|
|||
printf(msg);
|
||||
}
|
||||
|
||||
void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) {
|
||||
void print_statuschange(int friendnumber, uint8_t *string, uint16_t length)
|
||||
{
|
||||
char name[MAX_NAME_LENGTH];
|
||||
getname(friendnumber, (uint8_t*)name);
|
||||
char msg[100+length+strlen(name)+1];
|
||||
sprintf(msg, "\n\n[i] [%d] %s's status changed to %s.\n", friendnumber, name, string);
|
||||
sprintf(msg, "\n\n[i] [%d] %s's status changed to %s.\n\n", friendnumber, name, string);
|
||||
printf(msg);
|
||||
}
|
||||
|
||||
|
@ -125,29 +126,19 @@ void line_eval(char* line)
|
|||
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];
|
||||
switch (num) {
|
||||
case -1:
|
||||
sprintf(numstring, "[i] Incorrect key length");
|
||||
sprintf(numstring, "\n[i] Friend request sent. Wait to be accepted. Friend id: %d\n\n", num);
|
||||
printf(numstring);
|
||||
break;
|
||||
case -2:
|
||||
sprintf(numstring, "[i] That appears to be your own key");
|
||||
printf(numstring);
|
||||
break;
|
||||
case -3:
|
||||
sprintf(numstring, "[i] Friend request already sent");
|
||||
printf(numstring);
|
||||
break;
|
||||
case -4:
|
||||
sprintf(numstring, "[i] Could not add friend");
|
||||
printf(numstring);
|
||||
break;
|
||||
default:
|
||||
sprintf(numstring, "\n[i] added friend %d\n\n", num);
|
||||
printf(numstring);
|
||||
break;
|
||||
}
|
||||
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') {
|
||||
|
@ -156,12 +147,21 @@ void line_eval(char* line)
|
|||
}
|
||||
|
||||
else if (inpt_command == 'l') {
|
||||
printf("\n[i] Friend List | Total: %d\n\n", getnumfriends());
|
||||
|
||||
int activefriends = 0;
|
||||
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];
|
||||
getname(i, (uint8_t*)name);
|
||||
if (m_friendstatus(i) == 4)
|
||||
printf("[%d] %s\n\n", i, (uint8_t*)name);
|
||||
}
|
||||
}
|
||||
|
@ -177,6 +177,7 @@ void line_eval(char* line)
|
|||
}
|
||||
int num = atoi(numstring);
|
||||
m_delfriend(num);
|
||||
printf("\n\n");
|
||||
}
|
||||
/* Send message to friend */
|
||||
else if (inpt_command == 'm') {
|
||||
|
@ -196,7 +197,7 @@ void line_eval(char* line)
|
|||
}
|
||||
int num = atoi(numstring);
|
||||
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 {
|
||||
//simply for aesthetics
|
||||
printf("\n");
|
||||
|
@ -216,6 +217,11 @@ void line_eval(char* line)
|
|||
char numstring[100];
|
||||
sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name);
|
||||
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') {
|
||||
|
@ -231,6 +237,11 @@ void line_eval(char* line)
|
|||
char numstring[100];
|
||||
sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status);
|
||||
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') {
|
||||
|
@ -244,6 +255,8 @@ void line_eval(char* line)
|
|||
}
|
||||
/* EXIT */
|
||||
else if (inpt_command == 'q') {
|
||||
uint8_t status[MAX_USERSTATUS_LENGTH] = "Offline";
|
||||
m_set_userstatus(status, strlen((char*)status));
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
} else {
|
||||
|
@ -277,6 +290,35 @@ int main(int argc, char *argv[])
|
|||
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_friendmessage(print_message);
|
||||
m_callback_namechange(print_nickchange);
|
||||
|
@ -300,6 +342,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
do_header();
|
||||
|
||||
IP_Port bootstrap_ip_port;
|
||||
bootstrap_ip_port.port = htons(atoi(argv[2]));
|
||||
int resolved_address = resolve_addr(argv[1]);
|
||||
|
@ -309,9 +352,22 @@ int main(int argc, char *argv[])
|
|||
exit(1);
|
||||
|
||||
DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3]));
|
||||
|
||||
int c;
|
||||
int on = 0;
|
||||
|
||||
_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) {
|
||||
if (on == 1 && DHT_isconnected() == -1) {
|
||||
printf("\n---------------------------------");
|
||||
|
|
|
@ -29,4 +29,12 @@
|
|||
#define STRING_LENGTH 256
|
||||
#define PUB_KEY_BYTES 32
|
||||
|
||||
void do_header();
|
||||
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 line_eval(char* line);
|
||||
void get_input();
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user