diff --git a/.gitignore b/.gitignore index 66e4386..e238d4c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ last10.dat ansis/* config/* illusion/* +logs/* *.a diff --git a/bbs.c b/bbs.c index be554df..79203bb 100644 --- a/bbs.c +++ b/bbs.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "inih/ini.h" #include "bbs.h" @@ -21,6 +22,34 @@ int gSocket; int usertimeout; int timeoutpaused; +void dolog(char *fmt, ...) { + char buffer[512]; + struct tm time_now; + time_t timen; + FILE *logfptr; + + if (conf.log_path == NULL) return; + + timen = time(NULL); + + localtime_r(&timen, &time_now); + + snprintf(buffer, 512, "%s/%04d%02d%02d.log", conf.log_path, time_now.tm_year + 1900, time_now.tm_mon + 1, time_now.tm_mday); + logfptr = fopen(buffer, "a"); + if (!logfptr) { + printf("Error opening log file!\n"); + return; + } + va_list ap; + va_start(ap, fmt); + vsnprintf(buffer, 512, fmt, ap); + va_end(ap); + + fprintf(logfptr, "%02d:%02d:%02d %s\n", time_now.tm_hour, time_now.tm_min, time_now.tm_sec, buffer); + + fclose(logfptr); +} + struct fido_addr *parse_fido_addr(const char *str) { struct fido_addr *ret = (struct fido_addr *)malloc(sizeof(struct fido_addr)); int c; @@ -322,6 +351,8 @@ static int handler(void* user, const char* section, const char* name, conf->ansi_path = strdup(value); } else if (strcasecmp(name, "bbs path") == 0) { conf->bbs_path = strdup(value); + } else if (strcasecmp(name, "log path") == 0) { + conf->log_path = strdup(value); } } else if (strcasecmp(section, "mail conferences") == 0) { if (conf->mail_conference_count == 0) { @@ -512,6 +543,7 @@ void disconnect(int socket) { if (gUser != NULL) { save_user(gUser); } + dolog("Node %d disconnected", mynode); sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, mynode); remove(buffer); close(socket); @@ -631,6 +663,7 @@ void runbbs(int socket, char *config_path) { conf.irc_port = 6667; conf.text_file_count = 0; conf.external_editor_cmd = NULL; + conf.log_path = NULL; // Load BBS data if (ini_parse(config_path, handler, &conf) <0) { @@ -751,6 +784,7 @@ void runbbs(int socket, char *config_path) { fclose(nodefile); // do post-login + dolog("%s logged in, on node %d", user->loginname, mynode); // check time left now = time(NULL); localtime_r(&now, &thetime); @@ -770,7 +804,7 @@ void runbbs(int socket, char *config_path) { while (stat(buffer, &s) == 0) { sprintf(buffer, "bulletin%d", i); s_displayansi(socket, buffer); - sprintf(buffer, "Press any key to continue...\r\n"); + sprintf(buffer, "\e[0mPress any key to continue...\r\n"); s_putstring(socket, buffer); s_getc(socket); i++; @@ -799,6 +833,6 @@ void runbbs(int socket, char *config_path) { main_menu(socket, user); s_displayansi(socket, "goodbye"); - + dolog("%s is logging out, on node %d", user->loginname, mynode); disconnect(socket); } diff --git a/bbs.h b/bbs.h index 14f6550..a6419f9 100644 --- a/bbs.h +++ b/bbs.h @@ -83,6 +83,7 @@ struct bbs_config { char *ansi_path; char *bbs_path; + char *log_path; char *default_tagline; @@ -128,7 +129,7 @@ struct user_record { int timeson; }; - +extern void dolog(char *fmt, ...); extern void runbbs(int sock, char *config); extern struct fido_addr *parse_fido_addr(const char *str); extern void s_putchar(int socket, char c); diff --git a/config_default/bbs.ini b/config_default/bbs.ini index 7fb4e9f..fbabe5d 100644 --- a/config_default/bbs.ini +++ b/config_default/bbs.ini @@ -13,6 +13,7 @@ External Editor stdio = false [paths] ANSI Path = /home/andrew/MagickaBBS/ansis BBS Path = /home/andrew/MagickaBBS +Log Path = /home/andrew/MagickaBBS/logs [mail conferences] Local Mail = config/localmail.ini diff --git a/doors.c b/doors.c index 6c5caaa..83169a8 100644 --- a/doors.c +++ b/doors.c @@ -262,7 +262,9 @@ int door_menu(int socket, struct user_record *user) { { for (i=0;ikey)) { + dolog("%s is launched door %s, on node %d", user->loginname, conf.doors[i]->name, mynode); rundoor(socket, user, conf.doors[i]->command, conf.doors[i]->stdio); + dolog("%s is returned from door %s, on node %d", user->loginname, conf.doors[i]->name, mynode); break; } } diff --git a/main.c b/main.c index 32218ca..bad9433 100644 --- a/main.c +++ b/main.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "bbs.h" void sigchld_handler(int s) @@ -71,7 +72,6 @@ int main(int argc, char **argv) { if (pid == 0) { close(socket_desc); - runbbs(client_sock, argv[1]); exit(0); diff --git a/main_menu.c b/main_menu.c index d1e9506..e612900 100644 --- a/main_menu.c +++ b/main_menu.c @@ -82,7 +82,7 @@ void main_menu(int socket, struct user_record *user) { while (stat(buffer, &s) == 0) { sprintf(buffer, "bulletin%d", i); s_displayansi(socket, buffer); - sprintf(buffer, "Press any key to continue...\r\n"); + sprintf(buffer, "\e[0mPress any key to continue...\r\n"); s_putstring(socket, buffer); s_getc(socket); i++;