Add users command to magichat

This commit is contained in:
Andrew Pamment 2017-09-30 18:57:18 +10:00
parent 49d61a93df
commit 450270bf65

View File

@ -197,6 +197,7 @@ int main(int argc, char **argv) {
if (strcmp(msg.msg, "LOGIN") == 0) {
for (j=0;j<client_count;j++) {
if (clients[j]->fd == i) {
if (strcmp(clients[j]->nick, "UNKNOWN") == 0) {
strncpy(clients[j]->bbstag, msg.bbstag, 16);
strncpy(clients[j]->nick, msg.nick, 16);
clients[j]->bbstag[15] = '\0';
@ -233,10 +234,20 @@ int main(int argc, char **argv) {
}
fclose(fptr);
}
}
break;
}
}
} else if (strcmp(msg.msg, "USERS") == 0) {
for (j=0;j<client_count;j++) {
if (strcmp(clients[j]->nick, "UNKNOWN") != 0) {
snprintf(buffer, 1024, "{\"bbs\": \"SYSTEM\", \"nick\": \"SYSTEM\", \"msg\": \"(%s)[%s] is online.\" }\n", clients[j]->bbstag, clients[j]->nick);
if (send(i, buffer, strlen(buffer), 0) == -1) {
perror("send");
}
}
}
} else {
for (j=0;j<client_count;j++) {
if (clients[j]->fd == i) {