mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge pull request #155 from Astonex/master
Updating nTox_win32 and adding Messenger.c method
This commit is contained in:
commit
374a4e32cb
|
@ -71,6 +71,12 @@ int getfriend_id(uint8_t *client_id)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Returns number of friends */
|
||||||
|
int getnumfriends()
|
||||||
|
{
|
||||||
|
return numfriends;
|
||||||
|
}
|
||||||
|
|
||||||
/* copies the public key associated to that friend id into client_id buffer.
|
/* copies the public key associated to that friend id into client_id buffer.
|
||||||
make sure that client_id is of size CLIENT_ID_SIZE.
|
make sure that client_id is of size CLIENT_ID_SIZE.
|
||||||
return 0 if success
|
return 0 if success
|
||||||
|
|
|
@ -30,18 +30,23 @@ uint8_t pending_requests[256][CLIENT_ID_SIZE];
|
||||||
uint8_t num_requests;
|
uint8_t num_requests;
|
||||||
|
|
||||||
char line[STRING_LENGTH];
|
char line[STRING_LENGTH];
|
||||||
|
char users_id[200];
|
||||||
|
|
||||||
void do_header()
|
void do_header()
|
||||||
{
|
{
|
||||||
printf("\n[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /q (to quit)\n\n");
|
system("cls");
|
||||||
|
printf(users_id);
|
||||||
|
printf("\n---------------------------------");
|
||||||
|
printf("\n[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /l (lists friends), /d friendnumber (deletes friend), /q (to quit), /r (reset screen)");
|
||||||
|
printf("\n---------------------------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_request(uint8_t *public_key, uint8_t *data, uint16_t length)
|
void print_request(uint8_t *public_key, uint8_t *data, uint16_t length)
|
||||||
{
|
{
|
||||||
printf("\n[i] received friend request with message\n");
|
printf("\n\n[i] received friend request with message\n");
|
||||||
printf((char *)data);
|
printf((char *)data);
|
||||||
char numchar[100];
|
char numchar[100];
|
||||||
sprintf(numchar, "\n[i] accept request with /a %u\n", num_requests);
|
sprintf(numchar, "\n\n[i] accept request with /a %u\n\n", num_requests);
|
||||||
printf(numchar);
|
printf(numchar);
|
||||||
memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE);
|
memcpy(pending_requests[num_requests], public_key, CLIENT_ID_SIZE);
|
||||||
++num_requests;
|
++num_requests;
|
||||||
|
@ -59,7 +64,7 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length)
|
||||||
char* temp = asctime(timeinfo);
|
char* temp = asctime(timeinfo);
|
||||||
size_t len = strlen(temp);
|
size_t len = strlen(temp);
|
||||||
temp[len-1]='\0';
|
temp[len-1]='\0';
|
||||||
sprintf(msg, "\n[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp
|
sprintf(msg, "\n[%d] %s <%s> %s\n\n", friendnumber, temp, name, string); // timestamp
|
||||||
printf(msg);
|
printf(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +73,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length)
|
||||||
char name[MAX_NAME_LENGTH];
|
char name[MAX_NAME_LENGTH];
|
||||||
getname(friendnumber, (uint8_t*)name);
|
getname(friendnumber, (uint8_t*)name);
|
||||||
char msg[100+length];
|
char msg[100+length];
|
||||||
sprintf(msg, "\n[i] [%d] %s is now known as %s.", friendnumber, name, string);
|
sprintf(msg, "\n\n[i] [%d] %s is now known as %s.\n\n", friendnumber, name, string);
|
||||||
printf(msg);
|
printf(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,11 +81,10 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) {
|
||||||
char name[MAX_NAME_LENGTH];
|
char name[MAX_NAME_LENGTH];
|
||||||
getname(friendnumber, (uint8_t*)name);
|
getname(friendnumber, (uint8_t*)name);
|
||||||
char msg[100+length+strlen(name)+1];
|
char msg[100+length+strlen(name)+1];
|
||||||
sprintf(msg, "\n[i] [%d] %s's status changed to %s.", friendnumber, name, string);
|
sprintf(msg, "\n\n[i] [%d] %s's status changed to %s.\n", friendnumber, name, string);
|
||||||
printf(msg);
|
printf(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void load_key()
|
void load_key()
|
||||||
{
|
{
|
||||||
FILE *data_file = NULL;
|
FILE *data_file = NULL;
|
||||||
|
@ -127,8 +131,34 @@ void line_eval(char* line)
|
||||||
printf(numstring);
|
printf(numstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (line[1] == 'r') {
|
||||||
|
do_header();
|
||||||
|
printf("\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (line[1] == 'l') {
|
||||||
|
printf("\n[i] Friend List | Total: %d\n\n", getnumfriends());
|
||||||
|
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0; i < getnumfriends(); i++) {
|
||||||
|
char name[MAX_NAME_LENGTH];
|
||||||
|
getname(i, (uint8_t*)name);
|
||||||
|
printf("[%d] %s\n\n", i, (uint8_t*)name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else if (line[1] == 'd') {
|
else if (line[1] == 'd') {
|
||||||
doMessenger();
|
size_t len = strlen(line);
|
||||||
|
char numstring[len-3];
|
||||||
|
int i;
|
||||||
|
for (i=0; i<len; i++) {
|
||||||
|
if (line[i+3] != ' ') {
|
||||||
|
numstring[i] = line[i+3];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int num = atoi(numstring);
|
||||||
|
m_delfriend(num);
|
||||||
}
|
}
|
||||||
/* Send message to friend */
|
/* Send message to friend */
|
||||||
else if (line[1] == 'm') {
|
else if (line[1] == 'm') {
|
||||||
|
@ -148,7 +178,10 @@ 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\n", message);
|
printf("\n[i] could not send message: %s\n", message);
|
||||||
|
} else {
|
||||||
|
//simply for aesthetics
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,23 +256,18 @@ int main(int argc, char *argv[])
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (argc > 4) {
|
if (argc > 4) {
|
||||||
if(strncmp(argv[4], "nokey", 6) < 0) {
|
if(strncmp(argv[4], "nokey", 6) < 0) {
|
||||||
//nothing
|
}
|
||||||
} else {
|
} else {
|
||||||
load_key();
|
load_key();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
||||||
m_callback_userstatus(print_statuschange);
|
m_callback_userstatus(print_statuschange);
|
||||||
|
|
||||||
system("cls");
|
|
||||||
|
|
||||||
char idstring0[200];
|
|
||||||
char idstring1[32][5];
|
char idstring1[32][5];
|
||||||
char idstring2[32][5];
|
char idstring2[32][5];
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
@ -251,16 +279,14 @@ int main(int argc, char *argv[])
|
||||||
strcpy(idstring1[i], "");
|
strcpy(idstring1[i], "");
|
||||||
sprintf(idstring2[i], "%hhX",self_public_key[i]);
|
sprintf(idstring2[i], "%hhX",self_public_key[i]);
|
||||||
}
|
}
|
||||||
strcpy(idstring0,"\n[i] your ID: ");
|
strcpy(users_id,"[i] your ID: ");
|
||||||
for (i=0; i<32; i++) {
|
for (i=0; i<32; i++) {
|
||||||
strcat(idstring0,idstring1[i]);
|
strcat(users_id,idstring1[i]);
|
||||||
strcat(idstring0,idstring2[i]);
|
strcat(users_id,idstring2[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(idstring0);
|
|
||||||
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]);
|
||||||
|
@ -271,15 +297,22 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
|
if (on == 1 && DHT_isconnected() == -1) {
|
||||||
|
printf("\n---------------------------------");
|
||||||
|
printf("\n[i] Disconnected from the DHT");
|
||||||
|
printf("\n---------------------------------\n\n");
|
||||||
|
on = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (on == 0 && DHT_isconnected()) {
|
if (on == 0 && DHT_isconnected()) {
|
||||||
printf("\n[i] connected to DHT\n\n");
|
printf("\n[i] Connected to DHT");
|
||||||
|
printf("\n---------------------------------\n\n");
|
||||||
on = 1;
|
on = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user