mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
commit
5c136b116d
|
@ -18,7 +18,7 @@
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
|
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include "nTox.h"
|
#include "nTox.h"
|
||||||
#include "misc_tools.h"
|
#include "misc_tools.h"
|
||||||
|
@ -54,7 +54,7 @@ void get_id(char *data)
|
||||||
{
|
{
|
||||||
if (self_public_key[i] < (PUB_KEY_BYTES / 2))
|
if (self_public_key[i] < (PUB_KEY_BYTES / 2))
|
||||||
strcpy(idstring1[i],"0");
|
strcpy(idstring1[i],"0");
|
||||||
else
|
else
|
||||||
strcpy(idstring1[i], "");
|
strcpy(idstring1[i], "");
|
||||||
sprintf(idstring2[i], "%hhX",self_public_key[i]);
|
sprintf(idstring2[i], "%hhX",self_public_key[i]);
|
||||||
}
|
}
|
||||||
|
@ -71,9 +71,9 @@ void get_id(char *data)
|
||||||
void new_lines(char *line)
|
void new_lines(char *line)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (i = HISTORY-1; i > 0; i--)
|
for (i = HISTORY-1; i > 0; i--)
|
||||||
strncpy(lines[i], lines[i-1], STRING_LENGTH - 1);
|
strncpy(lines[i], lines[i-1], STRING_LENGTH - 1);
|
||||||
|
|
||||||
strncpy(lines[0], line, STRING_LENGTH - 1);
|
strncpy(lines[0], line, STRING_LENGTH - 1);
|
||||||
do_refresh();
|
do_refresh();
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
|
||||||
if (inpt_command == 'f') { // add friend command: /f ID
|
if (inpt_command == 'f') { // add friend command: /f ID
|
||||||
int i;
|
int i;
|
||||||
char temp_id[128];
|
char temp_id[128];
|
||||||
for (i = 0; i < 128; i++)
|
for (i = 0; i < 128; i++)
|
||||||
temp_id[i] = line[i+prompt_offset];
|
temp_id[i] = line[i+prompt_offset];
|
||||||
|
|
||||||
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"));
|
||||||
|
@ -166,8 +166,8 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
|
||||||
}
|
}
|
||||||
else if (inpt_command == 'm') { //message command: /m friendnumber messsage
|
else if (inpt_command == 'm') { //message command: /m friendnumber messsage
|
||||||
size_t len = strlen(line);
|
size_t len = strlen(line);
|
||||||
if(len < 3)
|
if(len < 3)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char numstring[len-3];
|
char numstring[len-3];
|
||||||
char message[len-3];
|
char message[len-3];
|
||||||
|
@ -248,7 +248,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
|
||||||
else if (inpt_command == 'q') { //exit
|
else if (inpt_command == 'q') { //exit
|
||||||
endwin();
|
endwin();
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
} else {
|
} else {
|
||||||
new_lines("[i] invalid command");
|
new_lines("[i] invalid command");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -335,7 +335,7 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length)
|
||||||
new_lines(format_message((char*)string, friendnumber));
|
new_lines(format_message((char*)string, friendnumber));
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_nickchange(int friendnumber, uint8_t *string, uint16_t length)
|
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);
|
||||||
|
@ -344,7 +344,7 @@ void print_nickchange(int friendnumber, uint8_t *string, uint16_t length)
|
||||||
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[MAX_NAME_LENGTH];
|
char name[MAX_NAME_LENGTH];
|
||||||
getname(friendnumber, (uint8_t*)name);
|
getname(friendnumber, (uint8_t*)name);
|
||||||
|
@ -353,7 +353,7 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length)
|
||||||
new_lines(msg);
|
new_lines(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_key()
|
void load_key()
|
||||||
{
|
{
|
||||||
FILE *data_file = NULL;
|
FILE *data_file = NULL;
|
||||||
data_file = fopen("data","r");
|
data_file = fopen("data","r");
|
||||||
|
@ -368,7 +368,7 @@ void load_key()
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
Messenger_load(data, size);
|
Messenger_load(data, size);
|
||||||
} else {
|
} else {
|
||||||
//else save new keys
|
//else save new keys
|
||||||
int size = Messenger_size();
|
int size = Messenger_size();
|
||||||
uint8_t data[size];
|
uint8_t data[size];
|
||||||
|
@ -418,9 +418,9 @@ int main(int argc, char *argv[])
|
||||||
int resolved_address = resolve_addr(argv[1]);
|
int resolved_address = resolve_addr(argv[1]);
|
||||||
if (resolved_address != 0)
|
if (resolved_address != 0)
|
||||||
bootstrap_ip_port.ip.i = resolved_address;
|
bootstrap_ip_port.ip.i = resolved_address;
|
||||||
else
|
else
|
||||||
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]));
|
||||||
nodelay(stdscr, TRUE);
|
nodelay(stdscr, TRUE);
|
||||||
while(true) {
|
while(true) {
|
||||||
|
@ -441,7 +441,7 @@ int main(int argc, char *argv[])
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
line_eval(lines, line);
|
line_eval(lines, line);
|
||||||
strcpy(line, "");
|
strcpy(line, "");
|
||||||
} else if (c == 127) {
|
} else if (c == 8 || c == 127) {
|
||||||
line[strlen(line)-1] = '\0';
|
line[strlen(line)-1] = '\0';
|
||||||
} else if (isalnum(c) || ispunct(c) || c == ' ') {
|
} else if (isalnum(c) || ispunct(c) || c == ' ') {
|
||||||
strcpy(line, appender(line, (char) c));
|
strcpy(line, appender(line, (char) c));
|
||||||
|
|
|
@ -47,21 +47,8 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len)
|
||||||
fix_name(msg);
|
fix_name(msg);
|
||||||
fix_name(nick);
|
fix_name(nick);
|
||||||
|
|
||||||
int inthour = timeinfo->tm_hour;
|
|
||||||
int intmin = timeinfo->tm_min;
|
|
||||||
char min[2];
|
|
||||||
char hour[2];
|
|
||||||
sprintf(hour,"%d",inthour);
|
|
||||||
if (intmin < 10) {
|
|
||||||
sprintf(min,"0%d",intmin);
|
|
||||||
} else {
|
|
||||||
sprintf(min,"%d",intmin);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
wattron(ctx->history, COLOR_PAIR(2));
|
wattron(ctx->history, COLOR_PAIR(2));
|
||||||
wprintw(ctx->history,"%s",hour);
|
wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
|
||||||
wprintw(ctx->history,":%s ",min);
|
|
||||||
wattron(ctx->history, COLOR_PAIR(4));
|
wattron(ctx->history, COLOR_PAIR(4));
|
||||||
wprintw(ctx->history, "%s: ", nick);
|
wprintw(ctx->history, "%s: ", nick);
|
||||||
wattroff(ctx->history, COLOR_PAIR(4));
|
wattroff(ctx->history, COLOR_PAIR(4));
|
||||||
|
@ -106,24 +93,11 @@ static void chat_onKey(ToxWindow* self, int key) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(key == '\n') {
|
else if(key == '\n') {
|
||||||
|
|
||||||
int inthour = timeinfo->tm_hour; //Pretty bad, but it gets the job done
|
|
||||||
int intmin = timeinfo->tm_min;
|
|
||||||
char min[2];
|
|
||||||
char hour[2];
|
|
||||||
sprintf(hour,"%d",inthour);
|
|
||||||
if (intmin < 10) {
|
|
||||||
sprintf(min,"0%d",intmin);
|
|
||||||
} else {
|
|
||||||
sprintf(min,"%d",intmin);
|
|
||||||
}
|
|
||||||
wattron(ctx->history, COLOR_PAIR(2));
|
wattron(ctx->history, COLOR_PAIR(2));
|
||||||
wprintw(ctx->history,"%s",hour);
|
wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
|
||||||
wprintw(ctx->history,":%s ",min);
|
|
||||||
wattron(ctx->history, COLOR_PAIR(1));
|
wattron(ctx->history, COLOR_PAIR(1));
|
||||||
wprintw(ctx->history, "you: ", ctx->line);
|
wprintw(ctx->history, "you: ", ctx->line);
|
||||||
wattroff(ctx->history, COLOR_PAIR(1));
|
wattroff(ctx->history, COLOR_PAIR(1));
|
||||||
|
|
||||||
wprintw(ctx->history, "%s\n", ctx->line);
|
wprintw(ctx->history, "%s\n", ctx->line);
|
||||||
|
|
||||||
if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) {
|
if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) {
|
||||||
|
@ -140,7 +114,7 @@ static void chat_onKey(ToxWindow* self, int key) {
|
||||||
ctx->line[--ctx->pos] = '\0';
|
ctx->line[--ctx->pos] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void chat_onDraw(ToxWindow* self) {
|
static void chat_onDraw(ToxWindow* self) {
|
||||||
|
@ -188,7 +162,7 @@ ToxWindow new_chat(int friendnum) {
|
||||||
uint8_t nick[MAX_NAME_LENGTH] = {0};
|
uint8_t nick[MAX_NAME_LENGTH] = {0};
|
||||||
getname(friendnum, (uint8_t*) &nick);
|
getname(friendnum, (uint8_t*) &nick);
|
||||||
fix_name(nick);
|
fix_name(nick);
|
||||||
|
|
||||||
snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum);
|
snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum);
|
||||||
|
|
||||||
ChatContext* x = calloc(1, sizeof(ChatContext));
|
ChatContext* x = calloc(1, sizeof(ChatContext));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user