add motd to magichat..

This commit is contained in:
Andrew Pamment 2017-09-29 22:12:11 +10:00
parent 3f837d98ba
commit e34be09ad8
2 changed files with 20 additions and 1 deletions

View File

@ -226,7 +226,7 @@ void chat_system(struct user_record *user) {
input_b = encapsulate_quote(inputbuffer); input_b = encapsulate_quote(inputbuffer);
raw("{ \"bbs\": \"%s\", \"nick\": \"%s\", \"msg\": \"%s\" }", conf.mgchat_bbstag, user->loginname, input_b); raw("{ \"bbs\": \"%s\", \"nick\": \"%s\", \"msg\": \"%s\" }", conf.mgchat_bbstag, user->loginname, input_b);
free(input_b); free(input_b);
sprintf(buffer2, "%s: %s", user->loginname, inputbuffer); sprintf(buffer2, "(%s)[%s]: %s", conf.mgchat_bbstag, user->loginname, inputbuffer);
append_screenbuffer(buffer2); append_screenbuffer(buffer2);
do_update = 1; do_update = 1;
} }

View File

@ -46,10 +46,13 @@ int main(int argc, char **argv) {
int i, j, k; int i, j, k;
char buffer[1024]; char buffer[1024];
char buf[1024]; char buf[1024];
char motd[256];
jsmn_parser parser; jsmn_parser parser;
jsmntok_t tokens[8]; jsmntok_t tokens[8];
int r; int r;
int nbytes; int nbytes;
FILE *fptr;
if (argc < 2) { if (argc < 2) {
printf("Usage: magichat [port]\n"); printf("Usage: magichat [port]\n");
return 0; return 0;
@ -207,6 +210,22 @@ int main(int argc, char **argv) {
} }
} }
} }
fptr = fopen("motd.txt", "r");
if (fptr) {
fgets(motd, 256, fptr);
while (!feof(fptr)) {
if (motd[strlen(buffer) - 1] == '\n') {
motd[strlen(buffer) - 1] = '\0';
}
snprintf(buffer, 1024, "{\"bbs\": \"SYSTEM\", \"nick\": \"SYSTEM\", \"msg\": \"%s\" }", motd);
send(clients[j]->fd, buffer, strlen(buffer) + 1, 0);
fgets(motd, 256, fptr);
}
fclose(fptr);
}
break; break;
} }
} }