diff --git a/ansis_default/mainmenu.ans b/ansis_default/mainmenu.ans index 9f4284f..fa00634 100644 Binary files a/ansis_default/mainmenu.ans and b/ansis_default/mainmenu.ans differ diff --git a/bbs.c b/bbs.c index d27669b..5dc5f65 100644 --- a/bbs.c +++ b/bbs.c @@ -350,6 +350,8 @@ static int handler(void* user, const char* section, const char* name, } else { conf->external_editor_stdio = 0; } + } else if (strcasecmp(name, "automessage write level") == 0) { + conf->automsgwritelvl = atoi(value); } } else if (strcasecmp(section, "paths") == 0){ if (strcasecmp(name, "ansi path") == 0) { @@ -660,6 +662,72 @@ void display_info(int socket) { s_getc(socket); } +void automessage_write(int socket, struct user_record *user) { + FILE *fptr; + char automsg[450]; + char buffer[90]; + int i; + struct tm timenow; + time_t timen; + + memset(automsg, 0, 450); + memset(buffer, 0, 90); + + if (user->sec_level >= conf.automsgwritelvl) { + timen = time(NULL); + localtime_r(&timen, &timenow); + + sprintf(automsg, "Posted by %s @ %s", user->loginname, asctime(&timenow)); + + automsg[strlen(automsg) - 1] = '\r'; + automsg[strlen(automsg)] = '\n'; + + for (i=0;i<4;i++) { + sprintf(buffer, "\r\n%d: ", i); + s_putstring(socket, buffer); + s_readstring(socket, buffer, 75); + strcat(automsg, buffer); + strcat(automsg, "\r\n"); + } + + fptr = fopen("automessage.txt", "w"); + if (fptr) { + fwrite(automsg, strlen(automsg), 1, fptr); + fclose(fptr); + } else { + printf("Unable to open automessage.txt for writing\n"); + } + } +} + +void automessage_display(int socket) { + struct stat s; + FILE *fptr; + char buffer[90]; + int i; + s_putstring(socket, "\r\n\r\n"); + if (stat("automessage.txt", &s) == 0) { + fptr = fopen("automessage.txt", "r"); + if (fptr) { + for (i=0;i<5;i++) { + memset(buffer, 0, 90); + fgets(buffer, 88, fptr); + buffer[strlen(buffer) - 1] = '\r'; + buffer[strlen(buffer)] = '\n'; + + s_putstring(socket, buffer); + } + fclose(fptr); + } else { + printf("Error opening automessage.txt\n"); + } + } else { + s_putstring(socket, "No automessage!\r\n"); + } + s_putstring(socket, "\e[0mPress any key to continue...\r\n"); + s_getc(socket); +} + void runbbs(int socket, char *config_path, char *ip) { char buffer[256]; char password[17]; @@ -697,6 +765,7 @@ void runbbs(int socket, char *config_path, char *ip) { conf.external_editor_cmd = NULL; conf.log_path = NULL; conf.script_path = NULL; + conf.automsgwritelvl = 10; // Load BBS data if (ini_parse(config_path, handler, &conf) <0) { @@ -882,6 +951,8 @@ void runbbs(int socket, char *config_path, char *ip) { } mail_scan(socket, user); + + automessage_display(socket); } record_last10_callers(user); // main menu diff --git a/bbs.h b/bbs.h index 4381615..072d3e2 100644 --- a/bbs.h +++ b/bbs.h @@ -99,6 +99,7 @@ struct bbs_config { int nodes; int newuserlvl; + int automsgwritelvl; int mail_conference_count; struct mail_conference **mail_conferences; int door_count; @@ -132,6 +133,8 @@ struct user_record { int timeson; }; +extern void automessage_write(int socket, struct user_record *user); +extern void automessage_display(int socket); extern void dolog(char *fmt, ...); extern void runbbs(int sock, char *config, char *ipaddress); extern struct fido_addr *parse_fido_addr(const char *str); diff --git a/config_default/bbs.ini b/config_default/bbs.ini index 2ca2aec..5a3feb9 100644 --- a/config_default/bbs.ini +++ b/config_default/bbs.ini @@ -9,6 +9,7 @@ IRC Channel = #bbs Default Tagline = Brought to you by Another Magicka BBS! External Editor cmd = /home/andrew/MagickaBBS/doors/oedit.sh External Editor stdio = false +Automessage Write Level = 10 [paths] ANSI Path = /home/andrew/MagickaBBS/ansis diff --git a/lua_glue.c b/lua_glue.c index a8823f4..c9ce526 100644 --- a/lua_glue.c +++ b/lua_glue.c @@ -112,6 +112,11 @@ int l_bbsTimeLeft(lua_State *L) { return 1; } +int l_bbsDisplayAutoMsg(lua_State *L) { + automessage_display(gSocket); + return 0; +} + int l_getMailAreaInfo(lua_State *L) { lua_pushnumber(L, gUser->cur_mail_conf); lua_pushstring(L, conf.mail_conferences[gUser->cur_mail_conf]->name); @@ -157,4 +162,6 @@ void lua_push_cfunctions(lua_State *L) { lua_setglobal(L, "bbs_cur_mailarea_info"); lua_pushcfunction(L, l_getFileAreaInfo); lua_setglobal(L, "bbs_cur_filearea_info"); + lua_pushcfunction(L, l_bbsDisplayAutoMsg); + lua_setglobal(L, "bbs_display_automsg"); } diff --git a/main_menu.c b/main_menu.c index 65579a6..852cc3f 100644 --- a/main_menu.c +++ b/main_menu.c @@ -67,6 +67,11 @@ void main_menu(int socket, struct user_record *user) { } switch(tolower(c)) { + case 'o': + { + automessage_write(socket, user); + } + break; case 'a': { if (conf.text_file_count > 0) {