diff options
author | Sebastian Stal <stal@pyboard.net> | 2013-07-18 10:56:50 -0700 |
---|---|---|
committer | Sebastian Stal <stal@pyboard.net> | 2013-07-18 10:56:50 -0700 |
commit | b190dc6fbed142231d7c36d9d4195ec0946442d4 (patch) | |
tree | 0d5b68281e7cc628bfc92816f3e3ffc9a49dd905 /testing | |
parent | 7611ca810f9af9f0f534a85869cd36e35137ec6f (diff) |
Add custom user statuses to core, updated nTox to support nicknames and user statuses.
Diffstat (limited to 'testing')
-rw-r--r-- | testing/nTox.c | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/testing/nTox.c b/testing/nTox.c index d3f6e6a8..ac82d021 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -72,6 +72,30 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
72 | } | 72 | } |
73 | int num = atoi(numstring); | 73 | int num = atoi(numstring); |
74 | m_sendmessage(num, (uint8_t*) message, sizeof(message)); | 74 | m_sendmessage(num, (uint8_t*) message, sizeof(message)); |
75 | } else if (line[1] == 'n') { | ||
76 | uint8_t name[MAX_NAME_LENGTH]; | ||
77 | int i = 0; | ||
78 | for (i=3; i<strlen(line); i++) { | ||
79 | if (line[i] == 0 || line[i] == '\n') break; | ||
80 | name[i - 3] = line[i]; | ||
81 | } | ||
82 | name[i - 3] = 0; | ||
83 | setname(name, i); | ||
84 | char numstring[100]; | ||
85 | sprintf(numstring, "Changed nick to: %s", (char*)name); | ||
86 | new_lines(numstring); | ||
87 | } else if (line[1] == 's') { | ||
88 | uint8_t status[MAX_USERSTATUS_LENGTH]; | ||
89 | int i = 0; | ||
90 | for (i=3; i<strlen(line); i++) { | ||
91 | if (line[i] == 0 || line[i] == '\n') break; | ||
92 | status[i - 3] = line[i]; | ||
93 | } | ||
94 | status[i - 3] = 0; | ||
95 | m_set_userstatus(status, strlen((char*)status)); | ||
96 | char numstring[100]; | ||
97 | sprintf(numstring, "Changed status to: %s", (char*)status); | ||
98 | new_lines(numstring); | ||
75 | } else if (line[1] == 'q') { //exit | 99 | } else if (line[1] == 'q') { //exit |
76 | endwin(); | 100 | endwin(); |
77 | exit(EXIT_SUCCESS); | 101 | exit(EXIT_SUCCESS); |
@@ -81,7 +105,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) | |||
81 | } | 105 | } |
82 | } | 106 | } |
83 | 107 | ||
84 | void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) | 108 | void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) |
85 | { | 109 | { |
86 | int i = 0; | 110 | int i = 0; |
87 | strcpy(output,input); | 111 | strcpy(output,input); |
@@ -95,7 +119,7 @@ void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) | |||
95 | } | 119 | } |
96 | } | 120 | } |
97 | 121 | ||
98 | int count_lines(char *string) | 122 | int count_lines(char *string) |
99 | { | 123 | { |
100 | int len = strlen(string); | 124 | int len = strlen(string); |
101 | int i; | 125 | int i; |
@@ -158,8 +182,27 @@ void print_request(uint8_t * public_key, uint8_t * data, uint16_t length) | |||
158 | } | 182 | } |
159 | void print_message(int friendnumber, uint8_t * string, uint16_t length) | 183 | void print_message(int friendnumber, uint8_t * string, uint16_t length) |
160 | { | 184 | { |
185 | char *name = malloc(MAX_NAME_LENGTH); | ||
186 | getname(friendnumber, (uint8_t*)name); | ||
187 | char msg[100+length+strlen(name)+1]; | ||
188 | sprintf(msg, "[%d] <%s> %s", friendnumber, name, string); | ||
189 | free(name); | ||
190 | new_lines(msg); | ||
191 | } | ||
192 | void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) { | ||
193 | char *name = malloc(MAX_NAME_LENGTH); | ||
194 | getname(friendnumber, (uint8_t*)name); | ||
161 | char msg[100+length]; | 195 | char msg[100+length]; |
162 | sprintf(msg, "Message [%d]: %s", friendnumber, string); | 196 | sprintf(msg, "[%d] %s is now known as %s.", friendnumber, name, string); |
197 | free(name); | ||
198 | new_lines(msg); | ||
199 | } | ||
200 | void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) { | ||
201 | char *name = malloc(MAX_NAME_LENGTH); | ||
202 | getname(friendnumber, (uint8_t*)name); | ||
203 | char msg[100+length+strlen(name)+1]; | ||
204 | sprintf(msg, "[%d] %s's status changed to %s.", friendnumber, name, string); | ||
205 | free(name); | ||
163 | new_lines(msg); | 206 | new_lines(msg); |
164 | } | 207 | } |
165 | int main(int argc, char *argv[]) | 208 | int main(int argc, char *argv[]) |
@@ -173,6 +216,8 @@ int main(int argc, char *argv[]) | |||
173 | initMessenger(); | 216 | initMessenger(); |
174 | m_callback_friendrequest(print_request); | 217 | m_callback_friendrequest(print_request); |
175 | m_callback_friendmessage(print_message); | 218 | m_callback_friendmessage(print_message); |
219 | m_callback_namechange(print_nickchange); | ||
220 | m_callback_userstatus(print_statuschange); | ||
176 | char idstring0[200]; | 221 | char idstring0[200]; |
177 | char idstring1[32][5]; | 222 | char idstring1[32][5]; |
178 | char idstring2[32][5]; | 223 | char idstring2[32][5]; |