diff options
-rw-r--r-- | core/Messenger.c | 9 | ||||
-rw-r--r-- | core/Messenger.h | 5 | ||||
-rw-r--r-- | testing/nTox.c | 25 |
3 files changed, 38 insertions, 1 deletions
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) | |||
240 | return 0; | 240 | return 0; |
241 | } | 241 | } |
242 | 242 | ||
243 | /* get our nickname | ||
244 | put it in name | ||
245 | return the length of the name */ | ||
246 | uint16_t getself_name(uint8_t *name) | ||
247 | { | ||
248 | memcpy(name, self_name, self_name_length); | ||
249 | return self_name_length; | ||
250 | } | ||
251 | |||
243 | /* get name of friendnumber | 252 | /* get name of friendnumber |
244 | put it in name | 253 | put it in name |
245 | name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes. | 254 | 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); | |||
92 | return -1 if failure */ | 92 | return -1 if failure */ |
93 | int setname(uint8_t *name, uint16_t length); | 93 | int setname(uint8_t *name, uint16_t length); |
94 | 94 | ||
95 | /* get our nickname | ||
96 | put it in name | ||
97 | return the length of the name*/ | ||
98 | uint16_t getself_name(uint8_t *name); | ||
99 | |||
95 | /* get name of friendnumber | 100 | /* get name of friendnumber |
96 | put it in name | 101 | put it in name |
97 | name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. | 102 | 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) | |||
50 | do_refresh(); | 50 | do_refresh(); |
51 | } | 51 | } |
52 | 52 | ||
53 | |||
53 | void print_friendlist() | 54 | void print_friendlist() |
54 | { | 55 | { |
55 | char name[MAX_NAME_LENGTH]; | 56 | char name[MAX_NAME_LENGTH]; |
@@ -69,6 +70,26 @@ void print_friendlist() | |||
69 | } | 70 | } |
70 | } | 71 | } |
71 | 72 | ||
73 | char *format_message(char *message, int friendnum) | ||
74 | { | ||
75 | char name[MAX_NAME_LENGTH]; | ||
76 | if(friendnum != -1) { | ||
77 | getname(friendnum, (uint8_t*)name); | ||
78 | } else { | ||
79 | getself_name((uint8_t*)name); | ||
80 | } | ||
81 | char *msg = malloc(100+strlen(message)+strlen(name)+1); | ||
82 | time_t rawtime; | ||
83 | struct tm * timeinfo; | ||
84 | time ( &rawtime ); | ||
85 | timeinfo = localtime ( &rawtime ); | ||
86 | char* time = asctime(timeinfo); | ||
87 | size_t len = strlen(time); | ||
88 | time[len-1]='\0'; | ||
89 | sprintf(msg, "[%d] %s <%s> %s", friendnum, time, name, message); // timestamp | ||
90 | return msg; | ||
91 | } | ||
92 | |||
72 | void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | 93 | void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) |
73 | { | 94 | { |
74 | if (line[0] == '/') { | 95 | if (line[0] == '/') { |
@@ -107,6 +128,8 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
107 | int num = atoi(numstring); | 128 | int num = atoi(numstring); |
108 | if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { | 129 | if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { |
109 | new_lines("[i] could not send message"); | 130 | new_lines("[i] could not send message"); |
131 | } else { | ||
132 | new_lines(format_message(message, -1)); | ||
110 | } | 133 | } |
111 | } | 134 | } |
112 | else if (line[1] == 'n') { | 135 | else if (line[1] == 'n') { |
@@ -255,7 +278,7 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length) | |||
255 | size_t len = strlen(temp); | 278 | size_t len = strlen(temp); |
256 | temp[len-1]='\0'; | 279 | temp[len-1]='\0'; |
257 | sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp | 280 | sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp |
258 | new_lines(msg); | 281 | new_lines(format_message((char*)string, friendnumber)); |
259 | } | 282 | } |
260 | 283 | ||
261 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) { | 284 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) { |