diff --git a/core/Messenger.c b/core/Messenger.c index 4c76dd30..3a287363 100644 --- a/core/Messenger.c +++ b/core/Messenger.c @@ -240,6 +240,15 @@ int setname(uint8_t * name, uint16_t length) return 0; } +/* get our nickname + put it in name + return the length of the name */ +uint16_t getself_name(uint8_t *name) +{ + memcpy(name, self_name, self_name_length); + return self_name_length; +} + /* get name of friendnumber put it in name name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes. diff --git a/core/Messenger.h b/core/Messenger.h index 7263901c..6ab50175 100644 --- a/core/Messenger.h +++ b/core/Messenger.h @@ -92,6 +92,11 @@ int m_sendmessage(int friendnumber, uint8_t *message, uint32_t length); return -1 if failure */ int setname(uint8_t *name, uint16_t length); +/* get our nickname + put it in name + return the length of the name*/ +uint16_t getself_name(uint8_t *name); + /* get name of friendnumber put it in name name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. diff --git a/testing/nTox.c b/testing/nTox.c index 97a39a12..9876f4ba 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -50,6 +50,7 @@ void new_lines(char *line) do_refresh(); } + void print_friendlist() { char name[MAX_NAME_LENGTH]; @@ -69,6 +70,26 @@ void print_friendlist() } } +char *format_message(char *message, int friendnum) +{ + char name[MAX_NAME_LENGTH]; + if(friendnum != -1) { + getname(friendnum, (uint8_t*)name); + } else { + getself_name((uint8_t*)name); + } + char *msg = malloc(100+strlen(message)+strlen(name)+1); + time_t rawtime; + struct tm * timeinfo; + time ( &rawtime ); + timeinfo = localtime ( &rawtime ); + char* time = asctime(timeinfo); + size_t len = strlen(time); + time[len-1]='\0'; + sprintf(msg, "[%d] %s <%s> %s", friendnum, time, name, message); // timestamp + return msg; +} + void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) { if (line[0] == '/') { @@ -107,6 +128,8 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) int num = atoi(numstring); if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { new_lines("[i] could not send message"); + } else { + new_lines(format_message(message, -1)); } } else if (line[1] == 'n') { @@ -255,7 +278,7 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length) size_t len = strlen(temp); temp[len-1]='\0'; sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp - new_lines(msg); + new_lines(format_message((char*)string, friendnumber)); } void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) {