From e34be09ad8c3bef8b856004cab0ed94445dd569d Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Fri, 29 Sep 2017 22:12:11 +1000 Subject: [PATCH] add motd to magichat.. --- src/chat_system.c | 2 +- utils/magichat/main.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/chat_system.c b/src/chat_system.c index 632eb83..c13cc71 100644 --- a/src/chat_system.c +++ b/src/chat_system.c @@ -226,7 +226,7 @@ void chat_system(struct user_record *user) { input_b = encapsulate_quote(inputbuffer); raw("{ \"bbs\": \"%s\", \"nick\": \"%s\", \"msg\": \"%s\" }", conf.mgchat_bbstag, user->loginname, 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); do_update = 1; } diff --git a/utils/magichat/main.c b/utils/magichat/main.c index a96c596..20b60ae 100644 --- a/utils/magichat/main.c +++ b/utils/magichat/main.c @@ -46,10 +46,13 @@ int main(int argc, char **argv) { int i, j, k; char buffer[1024]; char buf[1024]; + char motd[256]; jsmn_parser parser; jsmntok_t tokens[8]; int r; int nbytes; + FILE *fptr; + if (argc < 2) { printf("Usage: magichat [port]\n"); 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; } }