summaryrefslogtreecommitdiff
path: root/testing/toxic/chat.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/toxic/chat.c')
-rw-r--r--testing/toxic/chat.c50
1 files changed, 41 insertions, 9 deletions
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c
index 28c5de6c..83765777 100644
--- a/testing/toxic/chat.c
+++ b/testing/toxic/chat.c
@@ -16,7 +16,7 @@
16 16
17typedef struct { 17typedef struct {
18 int friendnum; 18 int friendnum;
19 char line[256]; 19 char line[MAX_STR_SIZE];
20 size_t pos; 20 size_t pos;
21 WINDOW* history; 21 WINDOW* history;
22 WINDOW* linewin; 22 WINDOW* linewin;
@@ -154,15 +154,47 @@ void execute(ToxWindow *self, ChatContext *ctx, char *cmd)
154 } 154 }
155 155
156 else if (!strncmp(cmd, "/status ", strlen("/status "))) { 156 else if (!strncmp(cmd, "/status ", strlen("/status "))) {
157 char *status = strchr(cmd, ' ');
157 char *msg; 158 char *msg;
158 msg = strchr(cmd, ' '); 159 char *status_text;
159 if (msg == NULL) { 160 if (status == NULL) {
160 wprintw(ctx->history, "Invalid syntax.\n"); 161 wprintw(ctx->history, "Invalid syntax.\n");
161 return; 162 return;
162 } 163 }
163 msg++; 164 status++;
164 m_set_statusmessage((uint8_t*) msg, strlen(msg)+1); 165 USERSTATUS status_kind;
165 wprintw(ctx->history, "Status set to: %s\n", msg); 166 if (!strncmp(status, "online", strlen("online"))) {
167 status_kind = USERSTATUS_NONE;
168 status_text = "ONLINE";
169 }
170
171 else if (!strncmp(status, "away", strlen("away"))) {
172 status_kind = USERSTATUS_AWAY;
173 status_text = "AWAY";
174 }
175
176 else if (!strncmp(status, "busy", strlen("busy"))) {
177 status_kind = USERSTATUS_BUSY;
178 status_text = "BUSY";
179 }
180
181 else
182 {
183 wprintw(ctx->history, "Invalid status.\n");
184 return;
185 }
186
187 msg = strchr(status, ' ');
188 if (msg == NULL) {
189 m_set_userstatus(status_kind);
190 wprintw(ctx->history, "Status set to: %s\n", status_text);
191 }
192 else {
193 msg++;
194 m_set_userstatus(status_kind);
195 m_set_statusmessage((uint8_t*) msg, strlen(msg)+1);
196 wprintw(ctx->history, "Status set to: %s, %s\n", status_text, msg);
197 }
166 } 198 }
167 199
168 else if (!strncmp(cmd, "/nick ", strlen("/nick "))) { 200 else if (!strncmp(cmd, "/nick ", strlen("/nick "))) {
@@ -178,9 +210,9 @@ void execute(ToxWindow *self, ChatContext *ctx, char *cmd)
178 } 210 }
179 211
180 else if (!strcmp(cmd, "/myid")) { 212 else if (!strcmp(cmd, "/myid")) {
181 char id[32*2 + 1] = {0}; 213 char id[KEY_SIZE_BYTES*2+1] = {0};
182 int i; 214 int i;
183 for (i = 0; i < 32; i++) { 215 for (i = 0; i < KEY_SIZE_BYTES; i++) {
184 char xx[3]; 216 char xx[3];
185 snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff); 217 snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff);
186 strcat(id, xx); 218 strcat(id, xx);
@@ -231,7 +263,7 @@ void print_help(ChatContext *self)
231 wprintw(self->history, "Commands:\n"); 263 wprintw(self->history, "Commands:\n");
232 wattroff(self->history, A_BOLD); 264 wattroff(self->history, A_BOLD);
233 265
234 wprintw(self->history, " /status <message> : Set your status\n"); 266 wprintw(self->history, " /status <type> <message> : Set your status\n");
235 wprintw(self->history, " /nick <nickname> : Set your nickname\n"); 267 wprintw(self->history, " /nick <nickname> : Set your nickname\n");
236 wprintw(self->history, " /myid : Print your ID\n"); 268 wprintw(self->history, " /myid : Print your ID\n");
237 wprintw(self->history, " /clear : Clear the screen\n"); 269 wprintw(self->history, " /clear : Clear the screen\n");