mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
commit
2b8d86ebe2
|
@ -48,10 +48,9 @@ void manage_keys()
|
||||||
if (read_size != KEYS_SIZE) {
|
if (read_size != KEYS_SIZE) {
|
||||||
printf("Error while reading the key file\nExiting.\n");
|
printf("Error while reading the key file\nExiting.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
|
||||||
printf("Keys loaded successfully\n");
|
|
||||||
}
|
}
|
||||||
load_keys(keys);
|
load_keys(keys);
|
||||||
|
printf("Keys loaded successfully\n");
|
||||||
} else {
|
} else {
|
||||||
//otherwise save new keys
|
//otherwise save new keys
|
||||||
new_keys();
|
new_keys();
|
||||||
|
@ -60,9 +59,8 @@ void manage_keys()
|
||||||
if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) {
|
if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) {
|
||||||
printf("Error while writing the key file.\nExiting.\n");
|
printf("Error while writing the key file.\nExiting.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
|
||||||
printf("Keys saved successfully\n");
|
|
||||||
}
|
}
|
||||||
|
printf("Keys saved successfully\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(keys_file);
|
fclose(keys_file);
|
||||||
|
|
|
@ -184,7 +184,7 @@ void print_request(uint8_t * public_key, uint8_t * data, uint16_t length)
|
||||||
}
|
}
|
||||||
void print_message(int friendnumber, uint8_t * string, uint16_t length)
|
void print_message(int friendnumber, uint8_t * string, uint16_t length)
|
||||||
{
|
{
|
||||||
char *name = malloc(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];
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
|
@ -195,26 +195,23 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length)
|
||||||
int len = strlen(temp);
|
int len = strlen(temp);
|
||||||
temp[len-1]='\0';
|
temp[len-1]='\0';
|
||||||
sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // someone please fix this
|
sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // someone please fix this
|
||||||
free(name);
|
|
||||||
new_lines(msg);
|
new_lines(msg);
|
||||||
}
|
}
|
||||||
void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) {
|
void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) {
|
||||||
char *name = malloc(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, "[i] [%d] %s is now known as %s.", friendnumber, name, string);
|
sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string);
|
||||||
free(name);
|
|
||||||
new_lines(msg);
|
new_lines(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 = malloc(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, "[i] [%d] %s's status changed to %s.", friendnumber, name, string);
|
sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string);
|
||||||
free(name);
|
|
||||||
new_lines(msg);
|
new_lines(msg);
|
||||||
}
|
}
|
||||||
int load_key(){
|
void load_key(){
|
||||||
FILE *data_file = NULL;
|
FILE *data_file = NULL;
|
||||||
if ((data_file = fopen("data","r"))) {
|
if ((data_file = fopen("data","r"))) {
|
||||||
//load keys
|
//load keys
|
||||||
|
@ -223,8 +220,8 @@ int load_key(){
|
||||||
fseek(data_file, 0, SEEK_SET);
|
fseek(data_file, 0, SEEK_SET);
|
||||||
uint8_t data[size];
|
uint8_t data[size];
|
||||||
if(fread(data, sizeof(uint8_t), size, data_file) != size){
|
if(fread(data, sizeof(uint8_t), size, data_file) != size){
|
||||||
printf("Error reading file\n");
|
printf("Error reading data file\nExiting.\n");
|
||||||
exit(0);
|
exit(1);
|
||||||
}
|
}
|
||||||
Messenger_load(data, size);
|
Messenger_load(data, size);
|
||||||
} else {
|
} else {
|
||||||
|
@ -234,12 +231,11 @@ int load_key(){
|
||||||
Messenger_save(data);
|
Messenger_save(data);
|
||||||
data_file = fopen("data","w");
|
data_file = fopen("data","w");
|
||||||
if(fwrite(data, sizeof(uint8_t), size, data_file) != size){
|
if(fwrite(data, sizeof(uint8_t), size, data_file) != size){
|
||||||
printf("Error writing file\n");
|
printf("Error writing data file\nExiting.\n");
|
||||||
exit(0);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(data_file);
|
fclose(data_file);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -298,9 +294,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]));
|
||||||
nodelay(stdscr, TRUE);
|
nodelay(stdscr, TRUE);
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
|
if (on == 0 && DHT_isconnected())
|
||||||
|
{
|
||||||
|
new_lines("[i] connected to DHT\n[i] define username with /n");
|
||||||
|
on = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
doMessenger();
|
||||||
|
c_sleep(1);
|
||||||
|
do_refresh();
|
||||||
|
|
||||||
c = getch();
|
c = getch();
|
||||||
if (c != ERR) {
|
|
||||||
if (c != 27) {
|
if (c == ERR || c == 27)
|
||||||
|
continue;
|
||||||
|
|
||||||
getmaxyx(stdscr, y, x);
|
getmaxyx(stdscr, y, x);
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
line_eval(lines, line);
|
line_eval(lines, line);
|
||||||
|
@ -311,19 +320,6 @@ int main(int argc, char *argv[])
|
||||||
strcpy(line, appender(line, (char) c));
|
strcpy(line, appender(line, (char) c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(on == 0)
|
|
||||||
{
|
|
||||||
if(DHT_isconnected())
|
|
||||||
{
|
|
||||||
new_lines("[i] connected to DHT\n[i] define username with /n");
|
|
||||||
on = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
doMessenger();
|
|
||||||
c_sleep(1);
|
|
||||||
do_refresh();
|
|
||||||
}
|
|
||||||
endwin();
|
endwin();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user