From 2c592325465c6a74c070714b6a17b222ff414e15 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Wed, 12 Apr 2017 16:38:33 +1000 Subject: [PATCH 1/7] Start work on New Menu System --- bbs.c | 6 +- bbs.h | 3 + config_default/bbs.ini | 1 + main.c | 2 + main_menu.c | 97 +++++++++-------- menus.c | 229 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 296 insertions(+), 42 deletions(-) create mode 100644 menus.c diff --git a/bbs.c b/bbs.c index a749ee7..68811c1 100644 --- a/bbs.c +++ b/bbs.c @@ -821,8 +821,12 @@ tryagain: } record_last10_callers(user); // main menu - main_menu(user); + if (conf->root_menu != NULL) { + menu_system(conf->root_menu); + } else { + main_menu(user); + } dolog("%s is logging out, on node %d", user->loginname, mynode); broadcast("%s is logging out, on node %d", user->loginname, mynode); diff --git a/bbs.h b/bbs.h index 32281e4..826985d 100644 --- a/bbs.h +++ b/bbs.h @@ -140,6 +140,7 @@ struct bbs_config { int bwave_max_msgs; struct fido_addr *main_aka; + char *root_menu; char *external_editor_cmd; int external_editor_stdio; int fork; @@ -245,6 +246,8 @@ extern struct user_record *new_user(); extern struct user_record *check_user_pass(char *loginname, char *password); extern void list_users(struct user_record *user); +extern void display_bulletins(); +extern void display_textfiles(); extern void main_menu(struct user_record *user); extern s_JamBase *open_jam_base(char *path); diff --git a/config_default/bbs.ini b/config_default/bbs.ini index 41c2819..748b962 100644 --- a/config_default/bbs.ini +++ b/config_default/bbs.ini @@ -27,6 +27,7 @@ Broadcast Address = 192.168.1.255 IP Guard Enable = true IP Guard Timeout = 120 IP Guard Tries = 4 +Root Menu = /home/andrew/MagickaBBS/menus/root.mnu [paths] Config Path = /home/andrew/MagickaBBS/config diff --git a/main.c b/main.c index a1fbb7e..9022411 100644 --- a/main.c +++ b/main.c @@ -481,6 +481,8 @@ static int handler(void* user, const char* section, const char* name, conf->ipguard_timeout = atoi(value); } else if (strcasecmp(name, "ip guard tries") == 0) { conf->ipguard_tries = atoi(value); + } else if (strcasecmp(name, "root menu") == 0) { + conf->root_menu = strdup(value); } } else if (strcasecmp(section, "paths") == 0){ if (strcasecmp(name, "ansi path") == 0) { diff --git a/main_menu.c b/main_menu.c index c474146..ad52af6 100644 --- a/main_menu.c +++ b/main_menu.c @@ -10,6 +10,60 @@ extern struct bbs_config conf; +void display_bulletins() { + int i; + char buffer[PATH_MAX]; + + i = 0; + + sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i); + + while (stat(buffer, &s) == 0) { + sprintf(buffer, "bulletin%d", i); + s_displayansi(buffer); + s_printf(get_string(6)); + s_getc(); + i++; + sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i); + } +} + +void display_textfiles() { + int i; + char buffer[5]; + + if (conf.text_file_count > 0) { + + while(1) { + s_printf(get_string(143)); + s_printf(get_string(144)); + + for (i=0;iname); + } + s_printf(get_string(146)); + s_printf(get_string(147)); + s_readstring(buffer, 4); + if (tolower(buffer[0]) != 'q') { + i = atoi(buffer); + if (i >= 0 && i < conf.text_file_count) { + s_printf("\r\n"); + s_displayansi_p(conf.text_files[i]->path); + s_printf(get_string(6)); + s_getc(); + s_printf("\r\n"); + } + } else { + break; + } + } + } else { + s_printf(get_string(148)); + s_printf(get_string(6)); + s_getc(); + } +} + void main_menu(struct user_record *user) { int doquit = 0; char c; @@ -80,36 +134,7 @@ void main_menu(struct user_record *user) { break; case 'a': { - if (conf.text_file_count > 0) { - - while(1) { - s_printf(get_string(143)); - s_printf(get_string(144)); - - for (i=0;iname); - } - s_printf(get_string(146)); - s_printf(get_string(147)); - s_readstring(buffer, 4); - if (tolower(buffer[0]) != 'q') { - i = atoi(buffer); - if (i >= 0 && i < conf.text_file_count) { - s_printf("\r\n"); - s_displayansi_p(conf.text_files[i]->path); - s_printf(get_string(6)); - s_getc(); - s_printf("\r\n"); - } - } else { - break; - } - } - } else { - s_printf(get_string(148)); - s_printf(get_string(6)); - s_getc(); - } + display_textfiles(); } break; case 'c': @@ -129,17 +154,7 @@ void main_menu(struct user_record *user) { break; case 'b': { - i = 0; - sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i); - - while (stat(buffer, &s) == 0) { - sprintf(buffer, "bulletin%d", i); - s_displayansi(buffer); - s_printf(get_string(6)); - s_getc(); - i++; - sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i); - } + display_bulletins(); } break; case '1': diff --git a/menus.c b/menus.c new file mode 100644 index 0000000..1093068 --- /dev/null +++ b/menus.c @@ -0,0 +1,229 @@ +#define MENU_SUBMENU 1 +#define MENU_LOGOFF 2 +#define MENU_PREVMENU 3 +#define MENU_AUTOMESSAGEWRITE 4 +#define MENU_TEXTFILES 5 +#define MENU_CHATSYSTEM 6 +#define MENU_BBSLIST 7 +#define MENU_LISTUSERS 8 +#define MENU_BULLETINS 9 +#define MENU_LAST10 10 +#define MENU_SETTINGS 11 + +struct menu_item { + char hotkey; + int command; + char *data; +}; + +int menu_system(char *menufile) { + FILE *fptr; + char buffer[256]; + int menu_items = 0; + struct menu_item **menu; + char *lua_script; + int do_lua_menu; + char *ansi_file; + fptr = fopen(menufile, "r"); + int i; + + if (!fptr) { + s_printf("Error opening menu file! %s\r\n", menufile); + return 0; + } + + lua_script = NULL; + ansi_file = NULL; + + while (1) { + + + fgets(buffer, 256, fptr); + chomp(buffer); + + if (strncasecmp(buffer, "HOTKEY", 6) == 0) { + menu_items++; + if (menu_items == 1) { + menu = (struct menu_item **)malloc(sizeof(struct menu_item *)); + } else { + menu = (struct menu_item **)realloc(menu, sizeof(struct menu_item *) * (menu_items)); + } + menu[menu_items-1] = (struct menu_item *)malloc(sizeof(struct menu_item)); + menu[menu_items-1]->hotkey = buffer[7]; + menu[menu_items-1]->data = NULL; + } else if (strncasecmp(buffer, "COMMAND", 7) == 0 && menu_items > 0) { + if (strncasemp(&buffer[8], "SUBMENU", 7) == 0) { + menu[menu_items-1]->command = MENU_SUBMENU; + } else if (strncasecmp(&buffer[8], "LOGOFF", 6) == 0) { + menu[menu_items-1]->command = MENU_LOGOFF; + } else if (strncasecmp(&buffer[8], "AUTOMESSAGE_WRITE", 17) == 0) { + menu[menu_items-1]->command = MENU_AUTOMESSAGEWRITE; + } else if (strncasecmp(&buffer[8], "TEXTFILES", 9) == 0) { + menu[menu_items-1]->command = MENU_TEXTFILES; + } else if (strncasecmp(&buffer[8], "CHATSYSTEM", 10) == 0) { + menu[menu_items-1]->command = MENU_CHATSYSTEM; + } else if (strncasecmp(&buffer[8], "BBSLIST", 7) == 0) { + menu[menu_items-1]->command = MENU_BBSLIST; + } else if (strncasecmp(&buffer[8], "LISTUSERS", 9) == 0) { + menu[menu_items-1]->command = MENU_LISTUSERS; + } else if (strncasecmp(&buffer[8], "BULLETINS", 9) == 0) { + menu[menu_items-1]->command = MENU_BULLETINS; + } else if (strncasecmp(&buffer[8], "LAST10CALLERS", 13) == 0) { + menu[menu_items-1]->command = MENU_LAST10; + } else if (strncasecmp(&buffer[8], "SETTINGS", 8) == 0) { + menu[menu_items-1]->command = MENU_SETTINGS; + } + } else if (strncasecmp(buffer, "DATA", 4) == 0) { + menu[menu_items-1]->data = strdup(&buffer[5]); + } else if (strncasecmp(buffer, "LUASCRIPT", 9) == 0) { + lua_script = strdup(&buffer[10]); + } else if (strncasecmp(buffer, "ANSIFILE", 8) == 0) { + ansi_file = strdup(&buffer[9]); + } + } + fclose(fptr); + + do_lua_menu = 0; + + if (conf.script_path != NULL && lua_script[0] != '/') { + snprintf(buffer, 256 "%s/%s", conf.script_path, lua_script); + do_lua_menu = 1; + } else if (lua_script[0] == '/') { + snprintf(buffer, 256 "%s", lua_script); + do_lua_menu = 1; + } + + if (do_lua_menu) + if (stat(buffer, &s) == 0) { + L = luaL_newstate(); + luaL_openlibs(L); + lua_push_cfunctions(L); + luaL_loadfile(L, buffer); + do_internal_menu = 0; + result = lua_pcall(L, 0, 1, 0); + if (result) { + dolog("Failed to run script: %s", lua_tostring(L, -1)); + do_lua_menu = 0; + } + } else { + do_lua_menu = 0; + } + } + + while (!doquit) { + + if (do_lua_menu == 0) { + if (ansi_file != NULL) { + s_displayansi(ansi_file); + } + s_printf(get_string(142), user->timeleft); + c = s_getc(); + } else { + lua_getglobal(L, "menu"); + result = lua_pcall(L, 0, 1, 0); + if (result) { + dolog("Failed to run script: %s", lua_tostring(L, -1)); + do_lua_menu = 0; + lua_close(L); + continue; + } + lRet = (char *)lua_tostring(L, -1); + lua_pop(L, 1); + c = lRet[0]; + } + + for (i=0;ihotkey == c) { + switch(menu[i]->command) { + case MENU_SUBMENU: + doquit = menu_system(menu[i]->data); + if (doquit == 1) { + // free menus + if (do_lua_menu) { + lua_close(L); + } + if (lua_script != NULL) { + free(lua_script); + } + if (ansi_file != NULL) { + free(ansi_file); + } + for (i=0;idata != NULL) { + free(menu[i]->data) + } + free(menu[i]); + } + free(menu); + return doquit; + } + break; + case MENU_LOGOFF: + if (do_lua_menu) { + lua_close(L); + } + if (lua_script != NULL) { + free(lua_script); + } + if (ansi_file != NULL) { + free(ansi_file); + } + for (i=0;idata != NULL) { + free(menu[i]->data) + } + free(menu[i]); + } + free(menu); + return 1; + case MENU_PREVMENU: + if (do_lua_menu) { + lua_close(L); + } + if (lua_script != NULL) { + free(lua_script); + } + if (ansi_file != NULL) { + free(ansi_file); + } + for (i=0;idata != NULL) { + free(menu[i]->data) + } + free(menu[i]); + } + free(menu); + return 0; + case MENU_AUTOMESSAGEWRITE: + automessage_write(user); + break; + case MENU_TEXTFILES: + display_textfiles(); + break; + case MENU_CHATSYSTEM: + chat_system(user); + break; + case MENU_BBSLIST: + bbs_list(user); + break; + case MENU_LISTUSERS: + list_users(user); + break; + case MENU_BULLETINS: + display_bulletins(); + break; + case MENU_LAST10: + display_last10_callers(user); + break; + case MENU_SETTINGS: + settings_menu(user); + break; + } + break; + } + } + } + + // free menus; + return doquit; +} \ No newline at end of file From a1190bc1d791446bd22a3e4f7567f4bfdea1c049 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Wed, 12 Apr 2017 17:27:59 +1000 Subject: [PATCH 2/7] More Work on Menu System --- bbs.h | 2 +- mail_menu.c | 588 +++++++++++++++++++++++++++------------------------- menus.c | 40 ++++ 3 files changed, 350 insertions(+), 280 deletions(-) diff --git a/bbs.h b/bbs.h index 826985d..709645e 100644 --- a/bbs.h +++ b/bbs.h @@ -260,7 +260,7 @@ extern char *external_editor(struct user_record *user, char *to, char *from, cha extern int msg_is_to(struct user_record *user, char *addressed_to, char *address, int type, int rn, int msgconf); extern int msg_is_from(struct user_record *user, char *addressed_from, char *address, int type, int rn, int msgconf); extern unsigned long generate_msgid(); - +extern void read_mail(struct user_record *user); extern int door_menu(struct user_record *user); extern void rundoor(struct user_record *user, char *cmd, int stdio); diff --git a/mail_menu.c b/mail_menu.c index fe509eb..98ed4c6 100644 --- a/mail_menu.c +++ b/mail_menu.c @@ -1777,6 +1777,313 @@ void read_message(struct user_record *user, struct msg_headers *msghs, int mailn } } +void read_mail(struct user_record *user) { + struct msg_headers *msghs; + s_JamBase *jb; + s_JamLastRead jlr; + int all_unread; + int i; + int k; + char buffer[7]; + + s_printf("\r\n"); + // list mail in message base + msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user); + if (msghs != NULL && msghs->msg_count > 0) { + jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + if (!jb) { + dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + break; + } else { + all_unread = 0; + if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { + jlr.LastReadMsg = 0; + jlr.HighReadMsg = 0; + all_unread = 1; + } + JAM_CloseMB(jb); + s_printf(get_string(120), msghs->msg_count); + + s_readstring(buffer, 6); + + if (tolower(buffer[0]) == 'n') { + if (all_unread == 0) { + k = jlr.HighReadMsg; + for (i=0;imsg_count;i++) { + if (msghs->msgs[i]->msg_h->MsgNum == k) { + break; + } + } + i += 2; + } else { + i = 1; + } + } else { + i = atoi(buffer); + } + + if (i > 0 && i <= msghs->msg_count) { + read_message(user, msghs, i - 1); + } + } + } + if (msghs != NULL) { + free_message_headers(msghs); + } +} + +void post_message(struct user_record *user) { + char *subject; + char *from; + char *to; + char *msg; + int closed; + struct fido_addr *from_addr = NULL; + char buffer[256]; + char buffer2[256]; + + s_JamBase *jb; + s_JamMsgHeader jmh; + s_JamSubPacket* jsp; + s_JamSubfield jsf; + s_JamLastRead jlr; + + if (user->sec_level < conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->write_sec_level) { + s_printf(get_string(113)); + return; + } + if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NEWSGROUP_AREA) { + sprintf(buffer, "ALL"); + } else { + s_printf(get_string(54)); + s_readstring(buffer, 16); + } + if (strlen(buffer) == 0) { + strcpy(buffer, "ALL"); + } + + if (conf.mail_conferences[user->cur_mail_conf]->networked == 0 && strcasecmp(buffer, "ALL") != 0) { + if (check_user(buffer)) { + s_printf(get_string(55)); + return; + } + } + if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) { + s_printf(get_string(121)); + s_readstring(buffer2, 32); + if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { + from_addr = parse_fido_addr(buffer2); + if (!from_addr) { + s_printf(get_string(122)); + return; + } else { + if (from_addr->zone == 0 && from_addr->net == 0 && from_addr->node == 0 && from_addr->point == 0) { + free(from_addr); + s_printf(get_string(122)); + return; + } + s_printf(get_string(123), from_addr->zone, from_addr->net, from_addr->node, from_addr->point); + } + } + } + to = strdup(buffer); + s_printf(get_string(56)); + s_readstring(buffer, 25); + if (strlen(buffer) == 0) { + s_printf(get_string(39)); + free(to); + if (from_addr != NULL) { + free(from_addr); + } + return; + } + subject = strdup(buffer); + + // post a message + if (conf.mail_conferences[user->cur_mail_conf]->realnames == 0) { + from = strdup(user->loginname); + } else { + from = (char *)malloc(strlen(user->firstname) + strlen(user->lastname) + 2); + sprintf(from, "%s %s", user->firstname, user->lastname); + } + msg = external_editor(user, to, from, NULL, 0, NULL, subject, 0); + + free(from); + + if (msg != NULL) { + jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + if (!jb) { + dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + free(msg); + free(to); + free(subject); + return; + } + + JAM_ClearMsgHeader( &jmh ); + jmh.DateWritten = (uint32_t)time(NULL); + jmh.Attribute |= JAM_MSG_LOCAL; + if (conf.mail_conferences[user->cur_mail_conf]->realnames == 0) { + strcpy(buffer, user->loginname); + } else { + sprintf(buffer, "%s %s", user->firstname, user->lastname); + } + + jsp = JAM_NewSubPacket(); + + jsf.LoID = JAMSFLD_SENDERNAME; + jsf.HiID = 0; + jsf.DatLen = strlen(buffer); + jsf.Buffer = (char *)buffer; + JAM_PutSubfield(jsp, &jsf); + + jsf.LoID = JAMSFLD_RECVRNAME; + jsf.HiID = 0; + jsf.DatLen = strlen(to); + jsf.Buffer = (char *)to; + JAM_PutSubfield(jsp, &jsf); + + jsf.LoID = JAMSFLD_SUBJECT; + jsf.HiID = 0; + jsf.DatLen = strlen(subject); + jsf.Buffer = (char *)subject; + JAM_PutSubfield(jsp, &jsf); + + if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_ECHOMAIL_AREA || conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NEWSGROUP_AREA) { + jmh.Attribute |= JAM_MSG_TYPEECHO; + + if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { + if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point) { + sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); + } else { + sprintf(buffer, "%d:%d/%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); + } + jsf.LoID = JAMSFLD_OADDRESS; + jsf.HiID = 0; + jsf.DatLen = strlen(buffer); + jsf.Buffer = (char *)buffer; + JAM_PutSubfield(jsp, &jsf); + + sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, + generate_msgid()); + + jsf.LoID = JAMSFLD_MSGID; + jsf.HiID = 0; + jsf.DatLen = strlen(buffer); + jsf.Buffer = (char *)buffer; + JAM_PutSubfield(jsp, &jsf); + jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); + + } + } else + if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) { + jmh.Attribute |= JAM_MSG_TYPENET; + jmh.Attribute |= JAM_MSG_PRIVATE; + if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { + if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point) { + sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); + } else { + sprintf(buffer, "%d:%d/%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); + } + jsf.LoID = JAMSFLD_OADDRESS; + jsf.HiID = 0; + jsf.DatLen = strlen(buffer); + jsf.Buffer = (char *)buffer; + JAM_PutSubfield(jsp, &jsf); + + if (from_addr != NULL) { + if (from_addr->point) { + sprintf(buffer, "%d:%d/%d.%d", from_addr->zone, + from_addr->net, + from_addr->node, + from_addr->point); + } else { + sprintf(buffer, "%d:%d/%d", from_addr->zone, + from_addr->net, + from_addr->node); + } + jsf.LoID = JAMSFLD_DADDRESS; + jsf.HiID = 0; + jsf.DatLen = strlen(buffer); + jsf.Buffer = (char *)buffer; + JAM_PutSubfield(jsp, &jsf); + free(from_addr); + from_addr = NULL; + } + + sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, + generate_msgid()); + + jsf.LoID = JAMSFLD_MSGID; + jsf.HiID = 0; + jsf.DatLen = strlen(buffer); + jsf.Buffer = (char *)buffer; + JAM_PutSubfield(jsp, &jsf); + jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); + } + } + + while (1) { + z = JAM_LockMB(jb, 100); + if (z == 0) { + break; + } else if (z == JAM_LOCK_FAILED) { + sleep(1); + } else { + free(msg); + free(to); + free(subject); + dolog("Failed to lock msg base!"); + break; + } + } + if (z != 0) { + JAM_CloseMB(jb); + break; + } + + if (JAM_AddMessage(jb, &jmh, jsp, (char *)msg, strlen(msg))) { + dolog("Failed to add message"); + } else { + if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) { + if (conf.netmail_sem != NULL) { + sem_fd = open(conf.netmail_sem, O_RDWR | O_CREAT, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH); + close(sem_fd); + } + } else if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_ECHOMAIL_AREA || conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NEWSGROUP_AREA) { + if (conf.echomail_sem != NULL) { + sem_fd = open(conf.echomail_sem, O_RDWR | O_CREAT, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH); + close(sem_fd); + } + } + } + + JAM_UnlockMB(jb); + + JAM_DelSubPacket(jsp); + free(msg); + JAM_CloseMB(jb); + } + free(to); + free(subject); +} + int mail_menu(struct user_record *user) { int doquit = 0; int domail = 0; @@ -1870,289 +2177,12 @@ int mail_menu(struct user_record *user) { break; case 'd': { - s_printf("\r\n"); - // list mail in message base - msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user); - if (msghs != NULL && msghs->msg_count > 0) { - jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); - if (!jb) { - dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); - break; - } else { - all_unread = 0; - if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { - jlr.LastReadMsg = 0; - jlr.HighReadMsg = 0; - all_unread = 1; - } - JAM_CloseMB(jb); - s_printf(get_string(120), msghs->msg_count); - - s_readstring(buffer, 6); - - if (tolower(buffer[0]) == 'n') { - if (all_unread == 0) { - k = jlr.HighReadMsg; - for (i=0;imsg_count;i++) { - if (msghs->msgs[i]->msg_h->MsgNum == k) { - break; - } - } - i += 2; - } else { - i = 1; - } - } else { - i = atoi(buffer); - } - - if (i > 0 && i <= msghs->msg_count) { - read_message(user, msghs, i - 1); - } - } - } - if (msghs != NULL) { - free_message_headers(msghs); - } + read_mail(user); } break; case 'p': { - if (user->sec_level < conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->write_sec_level) { - s_printf(get_string(113)); - break; - } - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NEWSGROUP_AREA) { - sprintf(buffer, "ALL"); - } else { - s_printf(get_string(54)); - s_readstring(buffer, 16); - } - if (strlen(buffer) == 0) { - strcpy(buffer, "ALL"); - } - - if (conf.mail_conferences[user->cur_mail_conf]->networked == 0 && strcasecmp(buffer, "ALL") != 0) { - if (check_user(buffer)) { - s_printf(get_string(55)); - break; - } - } - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) { - s_printf(get_string(121)); - s_readstring(buffer2, 32); - if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { - from_addr = parse_fido_addr(buffer2); - if (!from_addr) { - s_printf(get_string(122)); - break; - } else { - if (from_addr->zone == 0 && from_addr->net == 0 && from_addr->node == 0 && from_addr->point == 0) { - free(from_addr); - s_printf(get_string(122)); - break; - } - s_printf(get_string(123), from_addr->zone, from_addr->net, from_addr->node, from_addr->point); - } - } - } - to = strdup(buffer); - s_printf(get_string(56)); - s_readstring(buffer, 25); - if (strlen(buffer) == 0) { - s_printf(get_string(39)); - free(to); - if (from_addr != NULL) { - free(from_addr); - } - break; - } - subject = strdup(buffer); - - // post a message - if (conf.mail_conferences[user->cur_mail_conf]->realnames == 0) { - from = strdup(user->loginname); - } else { - from = (char *)malloc(strlen(user->firstname) + strlen(user->lastname) + 2); - sprintf(from, "%s %s", user->firstname, user->lastname); - } - msg = external_editor(user, to, from, NULL, 0, NULL, subject, 0); - - free(from); - - if (msg != NULL) { - jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); - if (!jb) { - dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); - free(msg); - free(to); - free(subject); - break; - } - - JAM_ClearMsgHeader( &jmh ); - jmh.DateWritten = (uint32_t)time(NULL); - jmh.Attribute |= JAM_MSG_LOCAL; - if (conf.mail_conferences[user->cur_mail_conf]->realnames == 0) { - strcpy(buffer, user->loginname); - } else { - sprintf(buffer, "%s %s", user->firstname, user->lastname); - } - - jsp = JAM_NewSubPacket(); - - jsf.LoID = JAMSFLD_SENDERNAME; - jsf.HiID = 0; - jsf.DatLen = strlen(buffer); - jsf.Buffer = (char *)buffer; - JAM_PutSubfield(jsp, &jsf); - - jsf.LoID = JAMSFLD_RECVRNAME; - jsf.HiID = 0; - jsf.DatLen = strlen(to); - jsf.Buffer = (char *)to; - JAM_PutSubfield(jsp, &jsf); - - jsf.LoID = JAMSFLD_SUBJECT; - jsf.HiID = 0; - jsf.DatLen = strlen(subject); - jsf.Buffer = (char *)subject; - JAM_PutSubfield(jsp, &jsf); - - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_ECHOMAIL_AREA || conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NEWSGROUP_AREA) { - jmh.Attribute |= JAM_MSG_TYPEECHO; - - if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { - if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point) { - sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); - } else { - sprintf(buffer, "%d:%d/%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); - } - jsf.LoID = JAMSFLD_OADDRESS; - jsf.HiID = 0; - jsf.DatLen = strlen(buffer); - jsf.Buffer = (char *)buffer; - JAM_PutSubfield(jsp, &jsf); - - sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, - generate_msgid()); - - jsf.LoID = JAMSFLD_MSGID; - jsf.HiID = 0; - jsf.DatLen = strlen(buffer); - jsf.Buffer = (char *)buffer; - JAM_PutSubfield(jsp, &jsf); - jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); - - } - } else - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) { - jmh.Attribute |= JAM_MSG_TYPENET; - jmh.Attribute |= JAM_MSG_PRIVATE; - if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { - if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point) { - sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); - } else { - sprintf(buffer, "%d:%d/%d", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); - - } - jsf.LoID = JAMSFLD_OADDRESS; - jsf.HiID = 0; - jsf.DatLen = strlen(buffer); - jsf.Buffer = (char *)buffer; - JAM_PutSubfield(jsp, &jsf); - - if (from_addr != NULL) { - if (from_addr->point) { - sprintf(buffer, "%d:%d/%d.%d", from_addr->zone, - from_addr->net, - from_addr->node, - from_addr->point); - } else { - sprintf(buffer, "%d:%d/%d", from_addr->zone, - from_addr->net, - from_addr->node); - } - jsf.LoID = JAMSFLD_DADDRESS; - jsf.HiID = 0; - jsf.DatLen = strlen(buffer); - jsf.Buffer = (char *)buffer; - JAM_PutSubfield(jsp, &jsf); - free(from_addr); - from_addr = NULL; - } - - sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, - generate_msgid()); - - jsf.LoID = JAMSFLD_MSGID; - jsf.HiID = 0; - jsf.DatLen = strlen(buffer); - jsf.Buffer = (char *)buffer; - JAM_PutSubfield(jsp, &jsf); - jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer)); - } - } - - while (1) { - z = JAM_LockMB(jb, 100); - if (z == 0) { - break; - } else if (z == JAM_LOCK_FAILED) { - sleep(1); - } else { - free(msg); - free(to); - free(subject); - dolog("Failed to lock msg base!"); - break; - } - } - if (z != 0) { - JAM_CloseMB(jb); - break; - } - - if (JAM_AddMessage(jb, &jmh, jsp, (char *)msg, strlen(msg))) { - dolog("Failed to add message"); - } else { - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) { - if (conf.netmail_sem != NULL) { - sem_fd = open(conf.netmail_sem, O_RDWR | O_CREAT, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH); - close(sem_fd); - } - } else if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_ECHOMAIL_AREA || conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NEWSGROUP_AREA) { - if (conf.echomail_sem != NULL) { - sem_fd = open(conf.echomail_sem, O_RDWR | O_CREAT, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH); - close(sem_fd); - } - } - } - - JAM_UnlockMB(jb); - - JAM_DelSubPacket(jsp); - free(msg); - JAM_CloseMB(jb); - } - free(to); - free(subject); + post_message(user); } break; case 'l': diff --git a/menus.c b/menus.c index 1093068..15193eb 100644 --- a/menus.c +++ b/menus.c @@ -9,6 +9,10 @@ #define MENU_BULLETINS 9 #define MENU_LAST10 10 #define MENU_SETTINGS 11 +#define MENU_DOOR 12 +#define MENU_MAILSCAN 13 +#define MENU_READMAIL 14 +#define MENU_POSTMESSAGE 15 struct menu_item { char hotkey; @@ -26,6 +30,7 @@ int menu_system(char *menufile) { char *ansi_file; fptr = fopen(menufile, "r"); int i; + int j; if (!fptr) { s_printf("Error opening menu file! %s\r\n", menufile); @@ -72,12 +77,26 @@ int menu_system(char *menufile) { menu[menu_items-1]->command = MENU_LAST10; } else if (strncasecmp(&buffer[8], "SETTINGS", 8) == 0) { menu[menu_items-1]->command = MENU_SETTINGS; + } else if (strncasecmp(&buffer[8], "RUNDOOR", 7) == 0) { + menu[menu_items-1]->command = MENU_DOOR; + } else if (strncasecmp(&buffer[8], "MAILSCAN", 8) == 0) { + menu[menu_items-1]->command = MENU_MAILSCAN; + } else if (strncasecmp(&buffer[8], "READMAIL", 8) == 0) { + menu[menu_items-1]->command = MENU_READMAIL; + } else if (strncasecmp(&buffer[8], "POSTMESSAGE", 11) == 0) { + menu[menu_items-1]->command = MENU_POSTMESSAGE; } } else if (strncasecmp(buffer, "DATA", 4) == 0) { menu[menu_items-1]->data = strdup(&buffer[5]); } else if (strncasecmp(buffer, "LUASCRIPT", 9) == 0) { + if (lua_script != NULL) { + free(lua_script); + } lua_script = strdup(&buffer[10]); } else if (strncasecmp(buffer, "ANSIFILE", 8) == 0) { + if (ansi_file != NULL) { + free(ansi_file); + } ansi_file = strdup(&buffer[9]); } } @@ -218,6 +237,27 @@ int menu_system(char *menufile) { case MENU_SETTINGS: settings_menu(user); break; + case MENU_DOOR: + { + for (j=0;jdata, conf.doors[j]->name) == 0) { + dolog("%s launched door %s, on node %d", user->loginname, conf.doors[j]->name, mynode); + rundoor(user, conf.doors[j]->command, conf.doors[j]->stdio); + dolog("%s returned from door %s, on node %d", user->loginname, conf.doors[j]->name, mynode); + break; + } + } + } + break; + case MENU_MAILSCAN: + mail_scan(user); + break; + case MENU_READMAIL: + read_mail(user); + break; + case MENU_POSTMESSAGE: + post_message(user); + break; } break; } From 109f59302a5e4da6db5f052cebcb0fcad63f83be Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Wed, 12 Apr 2017 22:34:08 +1000 Subject: [PATCH 3/7] More work on menusystem --- Makefile.freebsd | 2 +- Makefile.freebsd.WWW | 2 +- Makefile.linux | 2 +- Makefile.linux.WWW | 2 +- Makefile.netbsd | 2 +- Makefile.netbsd.WWW | 2 +- Makefile.osx | 2 +- Makefile.osx.WWW | 2 +- ansis_default/logoff.ans | Bin 0 -> 230 bytes bbs.c | 29 +- bbs.h | 25 +- config_default/bbs.ini | 3 +- doors.c | 84 +--- files.c | 300 +++++-------- mail_menu.c | 663 ++++++++++++----------------- main.c | 7 + main_menu.c | 134 +----- menus.c | 245 +++++++++-- menus_default/doors.mnu | 9 + menus_default/file.mnu | 39 ++ menus_default/logoff.mnu | 7 + menus_default/mail.mnu | 48 +++ menus_default/main.mnu | 42 ++ scripts_examples/logout_stanza.lua | 9 - 24 files changed, 772 insertions(+), 888 deletions(-) create mode 100644 ansis_default/logoff.ans create mode 100644 menus_default/doors.mnu create mode 100644 menus_default/file.mnu create mode 100644 menus_default/logoff.mnu create mode 100644 menus_default/mail.mnu create mode 100644 menus_default/main.mnu diff --git a/Makefile.freebsd b/Makefile.freebsd index 5850a67..8379b14 100644 --- a/Makefile.freebsd +++ b/Makefile.freebsd @@ -29,7 +29,7 @@ $(CDK): cd deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses cd deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o +OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/Makefile.freebsd.WWW b/Makefile.freebsd.WWW index 820dade..3b76f56 100644 --- a/Makefile.freebsd.WWW +++ b/Makefile.freebsd.WWW @@ -34,7 +34,7 @@ $(CDK): cd deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses cd deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = deps/aha/aha.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o hashmap/hashmap.o +OBJ = deps/aha/aha.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o hashmap/hashmap.o menus.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/Makefile.linux b/Makefile.linux index afee5f9..8c4b2ad 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -30,7 +30,7 @@ $(CDK): cd deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o +OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/Makefile.linux.WWW b/Makefile.linux.WWW index 4d29b19..8e53977 100644 --- a/Makefile.linux.WWW +++ b/Makefile.linux.WWW @@ -34,7 +34,7 @@ $(CDK): cd deps/cdk-5.0-20161210/ && ./configure cd deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = deps/aha/aha.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o bluewave.o hashmap/hashmap.o +OBJ = deps/aha/aha.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o bluewave.o hashmap/hashmap.o menus.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/Makefile.netbsd b/Makefile.netbsd index bbc788e..8ebda68 100644 --- a/Makefile.netbsd +++ b/Makefile.netbsd @@ -29,7 +29,7 @@ $(CDK): cd deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/pkg/include && ./configure --with-ncurses cd deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o +OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/Makefile.netbsd.WWW b/Makefile.netbsd.WWW index b847eef..abf326e 100644 --- a/Makefile.netbsd.WWW +++ b/Makefile.netbsd.WWW @@ -34,7 +34,7 @@ $(CDK): cd deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/pkg/include && ./configure --with-ncurses cd deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = deps/aha/aha.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o hashmap/hashmap.o +OBJ = deps/aha/aha.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o hashmap/hashmap.o menus.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/Makefile.osx b/Makefile.osx index 6f9170e..07df784 100644 --- a/Makefile.osx +++ b/Makefile.osx @@ -8,7 +8,7 @@ ODOORS = deps/odoors/libs-`uname -s`/libODoors.a JSMN = deps/jsmn/libjsmn.a CDK = deps/cdk-5-20161210/libcdk.a -OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o +OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd diff --git a/Makefile.osx.WWW b/Makefile.osx.WWW index 09b7cb9..492520e 100644 --- a/Makefile.osx.WWW +++ b/Makefile.osx.WWW @@ -34,7 +34,7 @@ $(CDK): cd deps/cdk-5.0-20161210/ && ./configure cd deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = deps/aha/aha.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o bluewave.o hashmap/hashmap.o +OBJ = deps/aha/aha.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o bluewave.o hashmap/hashmap.o menus.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/ansis_default/logoff.ans b/ansis_default/logoff.ans new file mode 100644 index 0000000000000000000000000000000000000000..e8cf708fb34b25d0c2ca6676e7d90af6e493e078 GIT binary patch literal 230 zcmb1+Hn27^ur@Z&<>gXPkd8LAHa5$3EJ{_V%r8|aE`>766Z1+GO7azQ^3xUa)6(pD zxge^IjdLS`nt-|^U4wbKq@xXTp@tae`avZ8{CT;gf*nJhT@4Hrs0WM;49yKp42@D5 a7#J8C0~lC=G!O`TI{7MuxjRC5a1sC;1Szfn literal 0 HcmV?d00001 diff --git a/bbs.c b/bbs.c index 68811c1..facc804 100644 --- a/bbs.c +++ b/bbs.c @@ -822,18 +822,16 @@ tryagain: record_last10_callers(user); // main menu - if (conf->root_menu != NULL) { - menu_system(conf->root_menu); - } else { - main_menu(user); - } - + menu_system(conf.root_menu); + + do_logout(); + dolog("%s is logging out, on node %d", user->loginname, mynode); broadcast("%s is logging out, on node %d", user->loginname, mynode); disconnect("Log out"); } -int do_logout() { +void do_logout() { char buffer[256]; struct stat s; lua_State *L; @@ -861,28 +859,15 @@ int do_logout() { } if (do_internal_logout == 1) { - s_printf(get_string(53)); - c = s_getc(); - if (tolower(c) == 'y') { - s_displayansi("goodbye"); - ret = 1; - } else { - ret = 0; - } + s_displayansi("goodbye"); } else { lua_getglobal(L, "logout"); - result = lua_pcall(L, 0, 1, 0); + result = lua_pcall(L, 0, 0, 0); if (result) { dolog("Failed to run script: %s", lua_tostring(L, -1)); - lua_close(L); - return 0; } - ret = lua_tointeger(L, -1); - lua_pop(L, 1); lua_close(L); } - - return ret; } void runbbs(int socket, char *ip) { diff --git a/bbs.h b/bbs.h index 709645e..ee22c86 100644 --- a/bbs.h +++ b/bbs.h @@ -141,6 +141,7 @@ struct bbs_config { struct fido_addr *main_aka; char *root_menu; + char *menu_path; char *external_editor_cmd; int external_editor_stdio; int fork; @@ -236,7 +237,7 @@ extern char s_getc(); extern void disconnect(char *calledby); extern void display_info(); extern void display_last10_callers(struct user_record *user); -extern int do_logout(); +extern void do_logout(); extern void gen_salt(char **s); extern char *hash_sha256(char *pass, char *salt); @@ -248,21 +249,26 @@ extern void list_users(struct user_record *user); extern void display_bulletins(); extern void display_textfiles(); -extern void main_menu(struct user_record *user); extern s_JamBase *open_jam_base(char *path); extern void free_message_headers(struct msg_headers *msghs); extern struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_record *user); extern void mail_scan(struct user_record *user); -extern int mail_menu(struct user_record *user); extern char *editor(struct user_record *user, char *quote, int qlen, char *from, int email); extern char *external_editor(struct user_record *user, char *to, char *from, char *quote, int qlen, char *qfrom, char *subject, int email); extern int msg_is_to(struct user_record *user, char *addressed_to, char *address, int type, int rn, int msgconf); extern int msg_is_from(struct user_record *user, char *addressed_from, char *address, int type, int rn, int msgconf); extern unsigned long generate_msgid(); extern void read_mail(struct user_record *user); +extern void list_messages(struct user_record *user); +extern void choose_conference(struct user_record *user); +extern void choose_area(struct user_record *user); +extern void next_mail_conf(struct user_record *user); +extern void prev_mail_conf(struct user_record *user); +extern void next_mail_area(struct user_record *user); +extern void prev_mail_area(struct user_record *user); +extern void post_message(struct user_record *user); -extern int door_menu(struct user_record *user); extern void rundoor(struct user_record *user, char *cmd, int stdio); extern void runexternal(struct user_record *user, char *cmd, int stdio, char **argv, char *cwd, int raw); @@ -274,13 +280,22 @@ extern int mail_getemailcount(struct user_record *user); extern void send_email(struct user_record *user); extern void list_emails(struct user_record *user); -extern int file_menu(struct user_record *user); extern void download_zmodem(struct user_record *user, char *filename); extern void settings_menu(struct user_record *user); extern void upload_zmodem(struct user_record *user, char *upload_p); extern int ttySetRaw(int fd, struct termios *prevTermios); extern int do_upload(struct user_record *user, char *final_path); extern int do_download(struct user_record *user, char *file); +extern void choose_directory(struct user_record *user); +extern void choose_subdir(struct user_record *user); +extern void list_files(struct user_record *user); +extern void upload(struct user_record *user); +extern void download(struct user_record *user); +extern void clear_tagged_files(); +extern void next_file_dir(struct user_record *user); +extern void prev_file_dir(struct user_record *user); +extern void next_file_sub(struct user_record *user); +extern void prev_file_sub(struct user_record *user); extern void lua_push_cfunctions(lua_State *L); diff --git a/config_default/bbs.ini b/config_default/bbs.ini index 748b962..33512cd 100644 --- a/config_default/bbs.ini +++ b/config_default/bbs.ini @@ -27,7 +27,7 @@ Broadcast Address = 192.168.1.255 IP Guard Enable = true IP Guard Timeout = 120 IP Guard Tries = 4 -Root Menu = /home/andrew/MagickaBBS/menus/root.mnu +Root Menu = main.mnu [paths] Config Path = /home/andrew/MagickaBBS/config @@ -40,6 +40,7 @@ Log Path = /home/andrew/MagickaBBS/logs Script Path = /home/andrew/MagickaBBS/scripts Echomail Semaphore = /home/andrew/MagickaBBS/echomail.out Netmail Semaphore = /home/andrew/MagickaBBS/netmail.out +Menu Path = /home/andrew/MagickaBBS/menus [mail conferences] Local Mail = config/localmail.ini diff --git a/doors.c b/doors.c index 6be5bb9..1505d1b 100644 --- a/doors.c +++ b/doors.c @@ -381,86 +381,4 @@ void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], c } } timeoutpaused = 0; -} - -int door_menu(struct user_record *user) { - int doquit = 0; - int dodoors = 0; - char buffer[256]; - int i; - char c; - struct stat s; - int do_internal_menu = 0; - char *lRet; - lua_State *L; - int result; - - if (conf.script_path != NULL) { - sprintf(buffer, "%s/doors.lua", conf.script_path); - if (stat(buffer, &s) == 0) { - L = luaL_newstate(); - luaL_openlibs(L); - lua_push_cfunctions(L); - luaL_loadfile(L, buffer); - do_internal_menu = 0; - result = lua_pcall(L, 0, 1, 0); - if (result) { - dolog("Failed to run script: %s", lua_tostring(L, -1)); - do_internal_menu = 1; - } - } else { - do_internal_menu = 1; - } - } else { - do_internal_menu = 1; - } - - while (!dodoors) { - if (do_internal_menu == 1) { - s_displayansi("doors"); - - s_printf(get_string(52), user->timeleft); - - c = s_getc(); - } else { - lua_getglobal(L, "menu"); - result = lua_pcall(L, 0, 1, 0); - if (result) { - dolog("Failed to run script: %s", lua_tostring(L, -1)); - do_internal_menu = 1; - lua_close(L); - continue; - } - lRet = (char *)lua_tostring(L, -1); - lua_pop(L, 1); - c = lRet[0]; - } - switch(tolower(c)) { - case 'q': - dodoors = 1; - break; - case 'g': - { - doquit = do_logout(); - dodoors = doquit; - } - break; - default: - { - for (i=0;ikey)) { - dolog("%s is launched door %s, on node %d", user->loginname, conf.doors[i]->name, mynode); - rundoor(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; - } - } - } - break; - } - } - if (do_internal_menu == 0) { - lua_close(L); - } - return doquit; -} +} \ No newline at end of file diff --git a/files.c b/files.c index c174c4d..f65aca0 100644 --- a/files.c +++ b/files.c @@ -1072,205 +1072,119 @@ void list_files(struct user_record *user) { } } -int file_menu(struct user_record *user) { - int doquit = 0; - int dofiles = 0; - char c; +void choose_subdir(struct user_record *user) { int i; + char c; int j; - char prompt[256]; - struct stat s; - int do_internal_menu = 0; - char *lRet; - lua_State *L; - int result; + char prompt[6]; - if (conf.script_path != NULL) { - sprintf(prompt, "%s/filemenu.lua", conf.script_path); - if (stat(prompt, &s) == 0) { - L = luaL_newstate(); - luaL_openlibs(L); - lua_push_cfunctions(L); - luaL_loadfile(L, prompt); - do_internal_menu = 0; - result = lua_pcall(L, 0, 1, 0); - if (result) { - dolog("Failed to run script: %s", lua_tostring(L, -1)); - do_internal_menu = 1; - } - } else { - do_internal_menu = 1; - } - } else { - do_internal_menu = 1; - } - - while (!dofiles) { - if (do_internal_menu == 1) { - s_displayansi("filemenu"); - - s_printf(get_string(76), user->cur_file_dir, conf.file_directories[user->cur_file_dir]->name, user->cur_file_sub, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->name, user->timeleft); + s_printf(get_string(81)); + for (i=0;icur_file_dir]->file_sub_count;i++) { + s_printf(" %d. %s\r\n", i, conf.file_directories[user->cur_file_dir]->file_subs[i]->name); + if (i != 0 && i % 20 == 0) { + s_printf(get_string(6)); c = s_getc(); + } + } + s_printf(get_string(82)); + s_readstring(prompt, 5); + if (tolower(prompt[0]) != 'q') { + j = atoi(prompt); + if (j < 0 || j >= conf.file_directories[user->cur_file_dir]->file_sub_count) { + s_printf(get_string(83)); } else { - lua_getglobal(L, "menu"); - result = lua_pcall(L, 0, 1, 0); - if (result) { - dolog("Failed to run script: %s", lua_tostring(L, -1)); - do_internal_menu = 1; - lua_close(L); - continue; - } - lRet = (char *)lua_tostring(L, -1); - lua_pop(L, 1); - c = lRet[0]; - } - switch(tolower(c)) { - case 27: - { - c = s_getc(); - if (c == 91) { - c = s_getc(); - } - } - break; - case 'i': - { - s_printf(get_string(77)); - for (i=0;isec_level <= user->sec_level) { - s_printf(get_string(78), i, conf.file_directories[i]->name); - } - if (i != 0 && i % 20 == 0) { - s_printf(get_string(6)); - c = s_getc(); - } - } - s_printf(get_string(79)); - s_readstring(prompt, 5); - if (tolower(prompt[0]) != 'q') { - j = atoi(prompt); - if (j < 0 || j >= conf.file_directory_count || conf.file_directories[j]->sec_level > user->sec_level) { - s_printf(get_string(80)); - } else { - s_printf("\r\n"); - user->cur_file_dir = j; - user->cur_file_sub = 0; - } - } - } - break; - case 's': - { - s_printf(get_string(81)); - for (i=0;icur_file_dir]->file_sub_count;i++) { - s_printf(" %d. %s\r\n", i, conf.file_directories[user->cur_file_dir]->file_subs[i]->name); - - if (i != 0 && i % 20 == 0) { - s_printf(get_string(6)); - c = s_getc(); - } - } - s_printf(get_string(82)); - s_readstring(prompt, 5); - if (tolower(prompt[0]) != 'q') { - j = atoi(prompt); - if (j < 0 || j >= conf.file_directories[user->cur_file_dir]->file_sub_count) { - s_printf(get_string(83)); - } else { - s_printf("\r\n"); - user->cur_file_sub = j; - } - } - } - break; - case 'l': - list_files(user); - break; - case 'u': - { - if (user->sec_level >= conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->upload_sec_level) { - upload(user); - } else { - s_printf(get_string(84)); - } - } - break; - case 'd': - download(user); - break; - case 'c': - { - // Clear tagged files - if (tagged_count > 0) { - for (i=0;icur_file_dir;isec_level <= user->sec_level) { - user->cur_file_dir = i + 1; - user->cur_file_sub = 0; - break; - } - } - } - break; - case '{': - { - for (i=user->cur_file_dir;i>=0;i--) { - if (i - 1 == -1) { - i = conf.file_directory_count; - } - if (conf.file_directories[i-1]->sec_level <= user->sec_level) { - user->cur_file_dir = i - 1; - user->cur_file_sub = 0; - break; - } - } - } - break; - case ']': - { - i=user->cur_file_sub; - if (i + 1 == conf.file_directories[user->cur_file_dir]->file_sub_count) { - i = -1; - } - user->cur_file_sub = i + 1; - } - break; - case '[': - { - i=user->cur_file_sub; - if (i - 1 == -1) { - i = conf.file_directories[user->cur_file_dir]->file_sub_count; - } - user->cur_file_sub = i - 1; - } - break; - case 'q': - dofiles = 1; - break; - case 'g': - { - doquit = do_logout(); - dofiles = doquit; - } - break; + s_printf("\r\n"); + user->cur_file_sub = j; } } - if (do_internal_menu == 0) { - lua_close(L); - } - return doquit; } + +void choose_directory(struct user_record *user) { + int i; + char c; + int j; + char prompt[6]; + + s_printf(get_string(77)); + for (i=0;isec_level <= user->sec_level) { + s_printf(get_string(78), i, conf.file_directories[i]->name); + } + if (i != 0 && i % 20 == 0) { + s_printf(get_string(6)); + c = s_getc(); + } + } + s_printf(get_string(79)); + s_readstring(prompt, 5); + if (tolower(prompt[0]) != 'q') { + j = atoi(prompt); + if (j < 0 || j >= conf.file_directory_count || conf.file_directories[j]->sec_level > user->sec_level) { + s_printf(get_string(80)); + } else { + s_printf("\r\n"); + user->cur_file_dir = j; + user->cur_file_sub = 0; + } + } +} + +void clear_tagged_files() { + int i; + // Clear tagged files + if (tagged_count > 0) { + for (i=0;icur_file_dir;isec_level <= user->sec_level) { + user->cur_file_dir = i + 1; + user->cur_file_sub = 0; + break; + } + } +} + +void prev_file_dir(struct user_record *user) { + int i; + for (i=user->cur_file_dir;i>=0;i--) { + if (i - 1 == -1) { + i = conf.file_directory_count; + } + if (conf.file_directories[i-1]->sec_level <= user->sec_level) { + user->cur_file_dir = i - 1; + user->cur_file_sub = 0; + break; + } + } +} + +void next_file_sub(struct user_record *user) { + int i; + i=user->cur_file_sub; + if (i + 1 == conf.file_directories[user->cur_file_dir]->file_sub_count) { + i = -1; + } + user->cur_file_sub = i + 1; +} + +void prev_file_sub(struct user_record *user) { + int i; + i=user->cur_file_sub; + if (i - 1 == -1) { + i = conf.file_directories[user->cur_file_dir]->file_sub_count; + } + user->cur_file_sub = i - 1; +} + diff --git a/mail_menu.c b/mail_menu.c index 98ed4c6..7c34fd7 100644 --- a/mail_menu.c +++ b/mail_menu.c @@ -1793,7 +1793,7 @@ void read_mail(struct user_record *user) { jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); if (!jb) { dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); - break; + return; } else { all_unread = 0; if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { @@ -1841,6 +1841,8 @@ void post_message(struct user_record *user) { struct fido_addr *from_addr = NULL; char buffer[256]; char buffer2[256]; + int z; + int sem_fd; s_JamBase *jb; s_JamMsgHeader jmh; @@ -2055,7 +2057,7 @@ void post_message(struct user_record *user) { } if (z != 0) { JAM_CloseMB(jb); - break; + return; } if (JAM_AddMessage(jb, &jmh, jsp, (char *)msg, strlen(msg))) { @@ -2084,409 +2086,290 @@ void post_message(struct user_record *user) { free(subject); } -int mail_menu(struct user_record *user) { - int doquit = 0; - int domail = 0; - char c; - char buffer[256]; - char buffer2[256]; - int i; - int j; - int z; - int k; +void list_messages(struct user_record *user) { struct msg_headers *msghs; - s_JamBase *jb; - s_JamMsgHeader jmh; - s_JamSubPacket* jsp; - s_JamSubfield jsf; + int all_unread; s_JamLastRead jlr; - - struct tm msg_date; - - char *subject; - char *from; - char *to; - char *msg; - int closed; - struct fido_addr *from_addr = NULL; - struct stat s; - int do_internal_menu = 0; - char *lRet; - lua_State *L; - int result; - int sem_fd; - int all_unread = 0; - int redraw; + char buffer[256]; + int i; + int k; + int j; int start; - - if (conf.script_path != NULL) { - sprintf(buffer, "%s/mailmenu.lua", conf.script_path); - if (stat(buffer, &s) == 0) { - L = luaL_newstate(); - luaL_openlibs(L); - lua_push_cfunctions(L); - luaL_loadfile(L, buffer); - do_internal_menu = 0; - result = lua_pcall(L, 0, 1, 0); - if (result) { - dolog("Failed to run script: %s", lua_tostring(L, -1)); - do_internal_menu = 1; - } + int closed; + int redraw; + struct tm msg_date; + char c; + + s_printf("\r\n"); + // list mail in message base + msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user); + if (msghs != NULL && msghs->msg_count > 0) { + jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + if (!jb) { + dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + return; } else { - do_internal_menu = 1; - } - } else { - do_internal_menu = 1; - } - - while (!domail) { - if (do_internal_menu == 1) { - s_displayansi("mailmenu"); - - - s_printf(get_string(119), user->cur_mail_conf, conf.mail_conferences[user->cur_mail_conf]->name, user->cur_mail_area, conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->name, user->timeleft); - - c = s_getc(); - } else { - lua_getglobal(L, "menu"); - result = lua_pcall(L, 0, 1, 0); - if (result) { - dolog("Failed to run script: %s", lua_tostring(L, -1)); - do_internal_menu = 1; - lua_close(L); - continue; + all_unread = 0; + if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { + jlr.LastReadMsg = 0; + jlr.HighReadMsg = 0; + all_unread = 1; } - lRet = (char *)lua_tostring(L, -1); - lua_pop(L, 1); - c = lRet[0]; - } - switch(tolower(c)) { - case 27: - { - c = s_getc(); - if (c == 91) { - c = s_getc(); - } - } - break; - case '!': - { - mail_scan(user); - } - break; - case 'd': - { - read_mail(user); - } - break; - case 'p': - { - post_message(user); - } - break; - case 'l': - { - s_printf("\r\n"); - // list mail in message base - msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user); - if (msghs != NULL && msghs->msg_count > 0) { - jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); - if (!jb) { - dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); + JAM_CloseMB(jb); + s_printf(get_string(125), msghs->msg_count); + + s_readstring(buffer, 6); + if (tolower(buffer[0]) == 'n') { + if (all_unread == 0) { + k = jlr.HighReadMsg; + for (i=0;imsg_count;i++) { + if (msghs->msgs[i]->msg_h->MsgNum == k) { break; - } else { - all_unread = 0; - if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { - jlr.LastReadMsg = 0; - jlr.HighReadMsg = 0; - all_unread = 1; - } - JAM_CloseMB(jb); - s_printf(get_string(125), msghs->msg_count); - - s_readstring(buffer, 6); - if (tolower(buffer[0]) == 'n') { - if (all_unread == 0) { - k = jlr.HighReadMsg; - for (i=0;imsg_count;i++) { - if (msghs->msgs[i]->msg_h->MsgNum == k) { - break; - } - } - if (i == msghs->msg_count - 1) { - i = 1; - } else { - i+=2; - } - - } else { - i = 1; - } - } else { - i = atoi(buffer); - if (i <= 0) { - i = 1; - } - } - closed = 0; + } + } + if (i == msghs->msg_count - 1) { + i = 1; + } else { + i+=2; + } + + } else { + i = 1; + } + } else { + i = atoi(buffer); + if (i <= 0) { + i = 1; + } + } + closed = 0; - redraw = 1; - start = i-1; - while (!closed) { - if (redraw) { - s_printf(get_string(126)); - for (j=start;jmsg_count;j++) { - localtime_r((time_t *)&msghs->msgs[j]->msg_h->DateWritten, &msg_date); - if (j == i -1) { - if (msghs->msgs[j]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { - s_printf(get_string(188), j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } else { - s_printf(get_string(189), j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } - } else { - if (msghs->msgs[j]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { - s_printf(get_string(127), j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } else { - s_printf(get_string(128), j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } - } - } - s_printf(get_string(190)); - s_printf("\e[%d;5H", i - start + 1); - redraw = 0; - } - c = s_getchar(); - if (tolower(c) == 'q') { - closed = 1; - } else if (c == 27) { - c = s_getchar(); - if (c == 91) { - c = s_getchar(); - if (c == 66) { - // down - i++; - if (i > start + 22) { - start += 22; - if (start > msghs->msg_count) { - start = msghs->msg_count - 22; - } - redraw = 1; - } - if (i-1 == msghs->msg_count) { - i--; - s_printf("\e[%d;5H", i - start + 1); - } else if (!redraw) { - s_printf("\e[%d;1H", i - start); - localtime_r((time_t *)&msghs->msgs[i-2]->msg_h->DateWritten, &msg_date); - if (msghs->msgs[i-2]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { - s_printf(get_string(127), i - 1, msghs->msgs[i-2]->subject, msghs->msgs[i-2]->from, msghs->msgs[i-2]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } else { - s_printf(get_string(128), i - 1, msghs->msgs[i-2]->subject, msghs->msgs[i-2]->from, msghs->msgs[i-2]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } - s_printf("\e[%d;1H", i - start + 1); - localtime_r((time_t *)&msghs->msgs[i-1]->msg_h->DateWritten, &msg_date); - if (msghs->msgs[i-1]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { - s_printf(get_string(188), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } else { - s_printf(get_string(189), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } - s_printf("\e[%d;5H", i - start + 1); - } - } else if (c == 65) { - // up - i--; - if (i - 1 < start) { - start -=22; - if (start < 0) { - start = 0; - } - redraw = 1; - } - if (i <= 1) { - start = 0; - i = 1; - redraw = 1; - } else if (!redraw) { - s_printf("\e[%d;1H", i - start + 2); - localtime_r((time_t *)&msghs->msgs[i]->msg_h->DateWritten, &msg_date); - if (msghs->msgs[i]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { - s_printf(get_string(127), i + 1, msghs->msgs[i]->subject, msghs->msgs[i]->from, msghs->msgs[i]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } else { - s_printf(get_string(128), i + 1, msghs->msgs[i]->subject, msghs->msgs[i]->from, msghs->msgs[i]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } - s_printf("\e[%d;1H", i - start + 1); - localtime_r((time_t *)&msghs->msgs[i-1]->msg_h->DateWritten, &msg_date); - if (msghs->msgs[i-1]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { - s_printf(get_string(188), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } else { - s_printf(get_string(189), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } - s_printf("\e[%d;5H", i - start + 1); - - } - } - } - } else if (c == 13) { - closed = 1; - read_message(user, msghs, i - 1); - } + redraw = 1; + start = i-1; + while (!closed) { + if (redraw) { + s_printf(get_string(126)); + for (j=start;jmsg_count;j++) { + localtime_r((time_t *)&msghs->msgs[j]->msg_h->DateWritten, &msg_date); + if (j == i -1) { + if (msghs->msgs[j]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { + s_printf(get_string(188), j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + } else { + s_printf(get_string(189), j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + } + } else { + if (msghs->msgs[j]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { + s_printf(get_string(127), j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + } else { + s_printf(get_string(128), j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } } + } + s_printf(get_string(190)); + s_printf("\e[%d;5H", i - start + 1); + redraw = 0; + } + c = s_getchar(); + if (tolower(c) == 'q') { + closed = 1; + } else if (c == 27) { + c = s_getchar(); + if (c == 91) { + c = s_getchar(); + if (c == 66) { + // down + i++; + if (i > start + 22) { + start += 22; + if (start > msghs->msg_count) { + start = msghs->msg_count - 22; + } + redraw = 1; + } + if (i-1 == msghs->msg_count) { + i--; + s_printf("\e[%d;5H", i - start + 1); + } else if (!redraw) { + s_printf("\e[%d;1H", i - start); + localtime_r((time_t *)&msghs->msgs[i-2]->msg_h->DateWritten, &msg_date); + if (msghs->msgs[i-2]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { + s_printf(get_string(127), i - 1, msghs->msgs[i-2]->subject, msghs->msgs[i-2]->from, msghs->msgs[i-2]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + } else { + s_printf(get_string(128), i - 1, msghs->msgs[i-2]->subject, msghs->msgs[i-2]->from, msghs->msgs[i-2]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + } + s_printf("\e[%d;1H", i - start + 1); + localtime_r((time_t *)&msghs->msgs[i-1]->msg_h->DateWritten, &msg_date); + if (msghs->msgs[i-1]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { + s_printf(get_string(188), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + } else { + s_printf(get_string(189), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + } + s_printf("\e[%d;5H", i - start + 1); + } + } else if (c == 65) { + // up + i--; + if (i - 1 < start) { + start -=22; + if (start < 0) { + start = 0; + } + redraw = 1; + } + if (i <= 1) { + start = 0; + i = 1; + redraw = 1; + } else if (!redraw) { + s_printf("\e[%d;1H", i - start + 2); + localtime_r((time_t *)&msghs->msgs[i]->msg_h->DateWritten, &msg_date); + if (msghs->msgs[i]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { + s_printf(get_string(127), i + 1, msghs->msgs[i]->subject, msghs->msgs[i]->from, msghs->msgs[i]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + } else { + s_printf(get_string(128), i + 1, msghs->msgs[i]->subject, msghs->msgs[i]->from, msghs->msgs[i]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + } + s_printf("\e[%d;1H", i - start + 1); + localtime_r((time_t *)&msghs->msgs[i-1]->msg_h->DateWritten, &msg_date); + if (msghs->msgs[i-1]->msg_h->MsgNum > jlr.HighReadMsg || all_unread) { + s_printf(get_string(188), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + } else { + s_printf(get_string(189), i, msghs->msgs[i-1]->subject, msghs->msgs[i-1]->from, msghs->msgs[i-1]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + } + s_printf("\e[%d;5H", i - start + 1); + + } + } + } + } else if (c == 13) { + closed = 1; + read_message(user, msghs, i - 1); + } + } + } - if (msghs != NULL) { - free_message_headers(msghs); - } - } else { - s_printf(get_string(130)); - } - } - break; - case 'c': - { - s_printf(get_string(131)); - for (i=0;isec_level <= user->sec_level) { - s_printf(get_string(132), i, conf.mail_conferences[i]->name); - } - if (i != 0 && i % 20 == 0) { - s_printf(get_string(6)); - c = s_getc(); - } - } - s_printf(get_string(133)); - s_readstring(buffer, 5); - if (tolower(buffer[0]) != 'q') { - j = atoi(buffer); - if (j < 0 || j >= conf.mail_conference_count || conf.mail_conferences[j]->sec_level > user->sec_level) { - s_printf(get_string(134)); - } else { - s_printf("\r\n"); - user->cur_mail_conf = j; - user->cur_mail_area = 0; - } - } - } - break; - case 'a': - { - s_printf(get_string(135)); - for (i=0;icur_mail_conf]->mail_area_count;i++) { - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[i]->read_sec_level <= user->sec_level) { - s_printf(get_string(136), i, conf.mail_conferences[user->cur_mail_conf]->mail_areas[i]->name); - } - if (i != 0 && i % 20 == 0) { - s_printf(get_string(6)); - c = s_getc(); - } - } - s_printf(get_string(137)); - s_readstring(buffer, 5); - if (tolower(buffer[0]) != 'q') { - j = atoi(buffer); - if (j < 0 || j >= conf.mail_conferences[user->cur_mail_conf]->mail_area_count || conf.mail_conferences[user->cur_mail_conf]->mail_areas[j]->read_sec_level > user->sec_level) { - s_printf(get_string(138)); - } else { - s_printf("\r\n"); - user->cur_mail_area = j; - } - } - } - break; - case 'q': - { - domail = 1; - } - break; - case 'g': - { - doquit = do_logout(); - domail = doquit; - } - break; - case 'e': - { - send_email(user); - } - break; - case 'r': - { - // Read your email... - s_printf("\r\n"); - list_emails(user); - } - break; - case '}': - { - for (i=user->cur_mail_conf;isec_level <= user->sec_level) { - user->cur_mail_conf = i + 1; - user->cur_mail_area = 0; - break; - } - } - } - break; - case '{': - { - for (i=user->cur_mail_conf;i>=0;i--) { - if (i - 1 == -1) { - i = conf.mail_conference_count; - } - if (conf.mail_conferences[i-1]->sec_level <= user->sec_level) { - user->cur_mail_conf = i - 1; - user->cur_mail_area = 0; - break; - } - } - } - break; - case ']': - { - for (i=user->cur_mail_area;icur_mail_conf]->mail_area_count;i++) { - if (i + 1 == conf.mail_conferences[user->cur_mail_conf]->mail_area_count) { - i = -1; - } - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[i+1]->read_sec_level <= user->sec_level) { - user->cur_mail_area = i + 1; - break; - } - } - } - break; - case '[': - { - for (i=user->cur_mail_area;i>=0;i--) { - if (i - 1 == -1) { - i = conf.mail_conferences[user->cur_mail_conf]->mail_area_count; - } - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[i-1]->read_sec_level <= user->sec_level) { - user->cur_mail_area = i - 1; - break; - } - } - } - break; - case 'b': - { - bwave_create_packet(); - } - break; - case 'u': - { - bwave_upload_reply(); - } - break; + if (msghs != NULL) { + free_message_headers(msghs); + } + } else { + s_printf(get_string(130)); + } +} + +void choose_conference(struct user_record *user) { + int i; + int j; + char c; + char buffer[6]; + + + s_printf(get_string(131)); + for (i=0;isec_level <= user->sec_level) { + s_printf(get_string(132), i, conf.mail_conferences[i]->name); + } + if (i != 0 && i % 20 == 0) { + s_printf(get_string(6)); + c = s_getc(); } } - if (do_internal_menu == 0) { - lua_close(L); + s_printf(get_string(133)); + s_readstring(buffer, 5); + if (tolower(buffer[0]) != 'q') { + j = atoi(buffer); + if (j < 0 || j >= conf.mail_conference_count || conf.mail_conferences[j]->sec_level > user->sec_level) { + s_printf(get_string(134)); + } else { + s_printf("\r\n"); + user->cur_mail_conf = j; + user->cur_mail_area = 0; + } + } +} + +void choose_area(struct user_record *user) { + int i; + int j; + char c; + char buffer[6]; + + s_printf(get_string(135)); + for (i=0;icur_mail_conf]->mail_area_count;i++) { + if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[i]->read_sec_level <= user->sec_level) { + s_printf(get_string(136), i, conf.mail_conferences[user->cur_mail_conf]->mail_areas[i]->name); + } + if (i != 0 && i % 20 == 0) { + s_printf(get_string(6)); + c = s_getc(); + } + } + s_printf(get_string(137)); + s_readstring(buffer, 5); + if (tolower(buffer[0]) != 'q') { + j = atoi(buffer); + if (j < 0 || j >= conf.mail_conferences[user->cur_mail_conf]->mail_area_count || conf.mail_conferences[user->cur_mail_conf]->mail_areas[j]->read_sec_level > user->sec_level) { + s_printf(get_string(138)); + } else { + s_printf("\r\n"); + user->cur_mail_area = j; + } + } +} + +void next_mail_conf(struct user_record *user) { + int i; + + for (i=user->cur_mail_conf;isec_level <= user->sec_level) { + user->cur_mail_conf = i + 1; + user->cur_mail_area = 0; + break; + } + } +} + +void prev_mail_conf(struct user_record *user) { + int i; + for (i=user->cur_mail_conf;i>=0;i--) { + if (i - 1 == -1) { + i = conf.mail_conference_count; + } + if (conf.mail_conferences[i-1]->sec_level <= user->sec_level) { + user->cur_mail_conf = i - 1; + user->cur_mail_area = 0; + break; + } + } +} + +void next_mail_area(struct user_record *user) { + int i; + for (i=user->cur_mail_area;icur_mail_conf]->mail_area_count;i++) { + if (i + 1 == conf.mail_conferences[user->cur_mail_conf]->mail_area_count) { + i = -1; + } + if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[i+1]->read_sec_level <= user->sec_level) { + user->cur_mail_area = i + 1; + break; + } + } +} + +void prev_mail_area(struct user_record *user) { + int i; + for (i=user->cur_mail_area;i>=0;i--) { + if (i - 1 == -1) { + i = conf.mail_conferences[user->cur_mail_conf]->mail_area_count; + } + if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[i-1]->read_sec_level <= user->sec_level) { + user->cur_mail_area = i - 1; + break; + } } - return doquit; } void mail_scan(struct user_record *user) { diff --git a/main.c b/main.c index 9022411..1b9dacc 100644 --- a/main.c +++ b/main.c @@ -505,6 +505,8 @@ static int handler(void* user, const char* section, const char* name, conf->www_path = strdup(value); } else if (strcasecmp(name, "config path") == 0) { conf->config_path = strdup(value); + } else if (strcasecmp(name, "menu path") == 0) { + conf->menu_path = strdup(value); } } else if (strcasecmp(section, "mail conferences") == 0) { if (conf->mail_conference_count == 0) { @@ -1168,6 +1170,11 @@ int main(int argc, char **argv) { exit(-1); } + if (conf.root_menu == NULL) { + fprintf(stderr, "Root Menu must be set in your bbs ini!\n"); + exit(-1); + } + // Load mail Areas for (i=0;ipath, mail_area_handler, conf.mail_conferences[i]) <0) { diff --git a/main_menu.c b/main_menu.c index ad52af6..d3343c5 100644 --- a/main_menu.c +++ b/main_menu.c @@ -13,7 +13,7 @@ extern struct bbs_config conf; void display_bulletins() { int i; char buffer[PATH_MAX]; - + struct stat s; i = 0; sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i); @@ -62,134 +62,4 @@ void display_textfiles() { s_printf(get_string(6)); s_getc(); } -} - -void main_menu(struct user_record *user) { - int doquit = 0; - char c; - char buffer[256]; - int i; - struct stat s; - int do_internal_menu = 0; - char *lRet; - lua_State *L; - int result; - - if (conf.script_path != NULL) { - sprintf(buffer, "%s/mainmenu.lua", conf.script_path); - if (stat(buffer, &s) == 0) { - L = luaL_newstate(); - luaL_openlibs(L); - lua_push_cfunctions(L); - luaL_loadfile(L, buffer); - do_internal_menu = 0; - result = lua_pcall(L, 0, 1, 0); - if (result) { - dolog("Failed to run script: %s", lua_tostring(L, -1)); - do_internal_menu = 1; - } - } else { - do_internal_menu = 1; - } - } else { - do_internal_menu = 1; - } - - while (!doquit) { - - if (do_internal_menu == 1) { - s_displayansi("mainmenu"); - - - s_printf(get_string(142), user->timeleft); - - c = s_getc(); - } else { - lua_getglobal(L, "menu"); - result = lua_pcall(L, 0, 1, 0); - if (result) { - dolog("Failed to run script: %s", lua_tostring(L, -1)); - do_internal_menu = 1; - lua_close(L); - continue; - } - lRet = (char *)lua_tostring(L, -1); - lua_pop(L, 1); - c = lRet[0]; - } - - switch(tolower(c)) { - case 27: - { - c = s_getc(); - if (c == 91) { - c = s_getc(); - } - } - break; - case 'o': - { - automessage_write(user); - } - break; - case 'a': - { - display_textfiles(); - } - break; - case 'c': - { - chat_system(user); - } - break; - case 'l': - { - bbs_list(user); - } - break; - case 'u': - { - list_users(user); - } - break; - case 'b': - { - display_bulletins(); - } - break; - case '1': - { - display_last10_callers(user); - } - break; - case 'd': - { - doquit = door_menu(user); - } - break; - case 'm': - { - doquit = mail_menu(user); - } - break; - case 'g': - { - doquit = do_logout(); - } - break; - case 't': - { - doquit = file_menu(user); - } - break; - case 's': - { - settings_menu(user); - } - break; - } - } - if (do_internal_menu == 0) { - lua_close(L); - } -} +} \ No newline at end of file diff --git a/menus.c b/menus.c index 15193eb..b06d002 100644 --- a/menus.c +++ b/menus.c @@ -1,3 +1,11 @@ +#include +#include +#include +#include "bbs.h" +#include "lua/lua.h" +#include "lua/lualib.h" +#include "lua/lauxlib.h" + #define MENU_SUBMENU 1 #define MENU_LOGOFF 2 #define MENU_PREVMENU 3 @@ -13,6 +21,30 @@ #define MENU_MAILSCAN 13 #define MENU_READMAIL 14 #define MENU_POSTMESSAGE 15 +#define MENU_CHOOSEMAILCONF 16 +#define MENU_CHOOSEMAILAREA 17 +#define MENU_SENDEMAIL 18 +#define MENU_LISTEMAIL 19 +#define MENU_NEXTMAILCONF 20 +#define MENU_PREVMAILCONF 21 +#define MENU_NEXTMAILAREA 22 +#define MENU_PREVMAILAREA 23 +#define MENU_BLUEWAVEDOWN 24 +#define MENU_BLUEWAVEUP 25 +#define MENU_CHOOSEFILEDIR 26 +#define MENU_CHOOSEFILESUB 27 +#define MENU_LISTFILES 28 +#define MENU_UPLOAD 29 +#define MENU_DOWNLOAD 30 +#define MENU_CLEARTAGGEDFILES 31 +#define MENU_NEXTFILEDIR 32 +#define MENU_PREVFILEDIR 33 +#define MENU_NEXTFILESUB 34 +#define MENU_PREVFILESUB 35 + +extern struct bbs_config conf; +extern struct user_record *gUser; +extern int mynode; struct menu_item { char hotkey; @@ -22,16 +54,28 @@ struct menu_item { int menu_system(char *menufile) { FILE *fptr; - char buffer[256]; + char buffer[PATH_MAX]; int menu_items = 0; struct menu_item **menu; char *lua_script; int do_lua_menu; char *ansi_file; - fptr = fopen(menufile, "r"); int i; int j; + struct stat s; + char *lRet; + lua_State *L; + int result; + int doquit = 0; + char c; + if (menufile[0] == '/') { + snprintf(buffer, PATH_MAX, "%s.mnu", menufile); + } else { + snprintf(buffer, PATH_MAX, "%s/%s.mnu", conf.menu_path, menufile); + } + fptr = fopen(buffer, "r"); + if (!fptr) { s_printf("Error opening menu file! %s\r\n", menufile); return 0; @@ -40,10 +84,11 @@ int menu_system(char *menufile) { lua_script = NULL; ansi_file = NULL; - while (1) { + + fgets(buffer, 256, fptr); + while (!feof(fptr)) { - fgets(buffer, 256, fptr); chomp(buffer); if (strncasecmp(buffer, "HOTKEY", 6) == 0) { @@ -57,10 +102,12 @@ int menu_system(char *menufile) { menu[menu_items-1]->hotkey = buffer[7]; menu[menu_items-1]->data = NULL; } else if (strncasecmp(buffer, "COMMAND", 7) == 0 && menu_items > 0) { - if (strncasemp(&buffer[8], "SUBMENU", 7) == 0) { + if (strncasecmp(&buffer[8], "SUBMENU", 7) == 0) { menu[menu_items-1]->command = MENU_SUBMENU; } else if (strncasecmp(&buffer[8], "LOGOFF", 6) == 0) { menu[menu_items-1]->command = MENU_LOGOFF; + } else if (strncasecmp(&buffer[8], "PREVMENU", 8) == 0) { + menu[menu_items-1]->command = MENU_PREVMENU; } else if (strncasecmp(&buffer[8], "AUTOMESSAGE_WRITE", 17) == 0) { menu[menu_items-1]->command = MENU_AUTOMESSAGEWRITE; } else if (strncasecmp(&buffer[8], "TEXTFILES", 9) == 0) { @@ -85,6 +132,46 @@ int menu_system(char *menufile) { menu[menu_items-1]->command = MENU_READMAIL; } else if (strncasecmp(&buffer[8], "POSTMESSAGE", 11) == 0) { menu[menu_items-1]->command = MENU_POSTMESSAGE; + } else if (strncasecmp(&buffer[8], "CHOOSEMAILCONF", 14) == 0) { + menu[menu_items-1]->command = MENU_CHOOSEMAILCONF; + } else if (strncasecmp(&buffer[8], "CHOOSEMAILAREA", 14) == 0) { + menu[menu_items-1]->command = MENU_CHOOSEMAILAREA; + } else if (strncasecmp(&buffer[8], "SENDEMAIL", 9) == 0) { + menu[menu_items-1]->command = MENU_SENDEMAIL; + } else if (strncasecmp(&buffer[8], "LISTEMAIL", 9) == 0) { + menu[menu_items-1]->command = MENU_LISTEMAIL; + } else if (strncasecmp(&buffer[8], "NEXTMAILCONF", 12) == 0) { + menu[menu_items-1]->command = MENU_NEXTMAILCONF; + } else if (strncasecmp(&buffer[8], "PREVMAILCONF", 12) == 0) { + menu[menu_items-1]->command = MENU_PREVMAILCONF; + } else if (strncasecmp(&buffer[8], "NEXTMAILAREA", 12) == 0) { + menu[menu_items-1]->command = MENU_NEXTMAILAREA; + } else if (strncasecmp(&buffer[8], "PREVMAILAREA", 12) == 0) { + menu[menu_items-1]->command = MENU_PREVMAILAREA; + } else if (strncasecmp(&buffer[8], "BLUEWAVEDOWNLOAD", 16) == 0) { + menu[menu_items-1]->command = MENU_BLUEWAVEDOWN; + } else if (strncasecmp(&buffer[8], "BLUEWAVEUPLOAD", 14) == 0) { + menu[menu_items-1]->command = MENU_BLUEWAVEUP; + } else if (strncasecmp(&buffer[8], "CHOOSEFILEDIR", 13) == 0) { + menu[menu_items-1]->command = MENU_CHOOSEFILEDIR; + } else if (strncasecmp(&buffer[8], "CHOOSEFILESUB", 13) == 0) { + menu[menu_items-1]->command = MENU_CHOOSEFILESUB; + } else if (strncasecmp(&buffer[8], "LISTFILES", 9) == 0) { + menu[menu_items-1]->command = MENU_LISTFILES; + } else if (strncasecmp(&buffer[8], "UPLOAD", 6) == 0) { + menu[menu_items-1]->command = MENU_UPLOAD; + } else if (strncasecmp(&buffer[8], "DOWNLOAD", 8) == 0) { + menu[menu_items-1]->command = MENU_DOWNLOAD; + } else if (strncasecmp(&buffer[8], "CLEARTAGGED", 11) == 0) { + menu[menu_items-1]->command = MENU_CLEARTAGGEDFILES; + } else if (strncasecmp(&buffer[8], "NEXTFILEDIR", 11) == 0) { + menu[menu_items-1]->command = MENU_NEXTFILEDIR; + } else if (strncasecmp(&buffer[8], "PREVFILEDIR", 11) == 0) { + menu[menu_items-1]->command = MENU_PREVFILEDIR; + } else if (strncasecmp(&buffer[8], "NEXTFILESUB", 11) == 0) { + menu[menu_items-1]->command = MENU_NEXTFILESUB; + } else if (strncasecmp(&buffer[8], "PREVFILESUB", 11) == 0) { + menu[menu_items-1]->command = MENU_PREVFILESUB; } } else if (strncasecmp(buffer, "DATA", 4) == 0) { menu[menu_items-1]->data = strdup(&buffer[5]); @@ -99,35 +186,39 @@ int menu_system(char *menufile) { } ansi_file = strdup(&buffer[9]); } + + fgets(buffer, 256, fptr); } fclose(fptr); do_lua_menu = 0; - if (conf.script_path != NULL && lua_script[0] != '/') { - snprintf(buffer, 256 "%s/%s", conf.script_path, lua_script); - do_lua_menu = 1; - } else if (lua_script[0] == '/') { - snprintf(buffer, 256 "%s", lua_script); - do_lua_menu = 1; - } + if (lua_script != NULL) { + if (conf.script_path != NULL && lua_script[0] != '/') { + snprintf(buffer, PATH_MAX, "%s/%s.lua", conf.script_path, lua_script); + do_lua_menu = 1; + } else if (lua_script[0] == '/') { + snprintf(buffer, PATH_MAX, "%s.lua", lua_script); + do_lua_menu = 1; + } - if (do_lua_menu) - if (stat(buffer, &s) == 0) { - L = luaL_newstate(); - luaL_openlibs(L); - lua_push_cfunctions(L); - luaL_loadfile(L, buffer); - do_internal_menu = 0; - result = lua_pcall(L, 0, 1, 0); - if (result) { - dolog("Failed to run script: %s", lua_tostring(L, -1)); - do_lua_menu = 0; - } - } else { - do_lua_menu = 0; - } - } + if (do_lua_menu) { + if (stat(buffer, &s) == 0) { + L = luaL_newstate(); + luaL_openlibs(L); + lua_push_cfunctions(L); + luaL_loadfile(L, buffer); + do_lua_menu = 1; + result = lua_pcall(L, 0, 1, 0); + if (result) { + dolog("Failed to run script: %s", lua_tostring(L, -1)); + do_lua_menu = 0; + } + } else { + do_lua_menu = 0; + } + } + } while (!doquit) { @@ -135,7 +226,7 @@ int menu_system(char *menufile) { if (ansi_file != NULL) { s_displayansi(ansi_file); } - s_printf(get_string(142), user->timeleft); + s_printf(get_string(142), gUser->timeleft); c = s_getc(); } else { lua_getglobal(L, "menu"); @@ -152,7 +243,7 @@ int menu_system(char *menufile) { } for (i=0;ihotkey == c) { + if (tolower(menu[i]->hotkey) == tolower(c)) { switch(menu[i]->command) { case MENU_SUBMENU: doquit = menu_system(menu[i]->data); @@ -169,7 +260,7 @@ int menu_system(char *menufile) { } for (i=0;idata != NULL) { - free(menu[i]->data) + free(menu[i]->data); } free(menu[i]); } @@ -189,7 +280,7 @@ int menu_system(char *menufile) { } for (i=0;idata != NULL) { - free(menu[i]->data) + free(menu[i]->data); } free(menu[i]); } @@ -207,57 +298,121 @@ int menu_system(char *menufile) { } for (i=0;idata != NULL) { - free(menu[i]->data) + free(menu[i]->data); } free(menu[i]); } free(menu); return 0; case MENU_AUTOMESSAGEWRITE: - automessage_write(user); + automessage_write(gUser); break; case MENU_TEXTFILES: display_textfiles(); break; case MENU_CHATSYSTEM: - chat_system(user); + chat_system(gUser); break; case MENU_BBSLIST: - bbs_list(user); + bbs_list(gUser); break; case MENU_LISTUSERS: - list_users(user); + list_users(gUser); break; case MENU_BULLETINS: display_bulletins(); break; case MENU_LAST10: - display_last10_callers(user); + display_last10_callers(gUser); break; case MENU_SETTINGS: - settings_menu(user); + settings_menu(gUser); break; case MENU_DOOR: { for (j=0;jdata, conf.doors[j]->name) == 0) { - dolog("%s launched door %s, on node %d", user->loginname, conf.doors[j]->name, mynode); - rundoor(user, conf.doors[j]->command, conf.doors[j]->stdio); - dolog("%s returned from door %s, on node %d", user->loginname, conf.doors[j]->name, mynode); + dolog("%s launched door %s, on node %d", gUser->loginname, conf.doors[j]->name, mynode); + rundoor(gUser, conf.doors[j]->command, conf.doors[j]->stdio); + dolog("%s returned from door %s, on node %d", gUser->loginname, conf.doors[j]->name, mynode); break; } } } break; case MENU_MAILSCAN: - mail_scan(user); + mail_scan(gUser); break; case MENU_READMAIL: - read_mail(user); + read_mail(gUser); break; case MENU_POSTMESSAGE: - post_message(user); + post_message(gUser); break; + case MENU_CHOOSEMAILCONF: + choose_conference(gUser); + break; + case MENU_CHOOSEMAILAREA: + choose_area(gUser); + break; + case MENU_SENDEMAIL: + send_email(gUser); + break; + case MENU_LISTEMAIL: + list_emails(gUser); + break; + case MENU_NEXTMAILCONF: + next_mail_conf(gUser); + break; + case MENU_PREVMAILCONF: + prev_mail_conf(gUser); + break; + case MENU_NEXTMAILAREA: + next_mail_area(gUser); + break; + case MENU_PREVMAILAREA: + prev_mail_area(gUser); + break; + case MENU_BLUEWAVEDOWN: + bwave_create_packet(); + break; + case MENU_BLUEWAVEUP: + bwave_upload_reply(); + break; + case MENU_CHOOSEFILEDIR: + choose_directory(gUser); + break; + case MENU_CHOOSEFILESUB: + choose_subdir(gUser); + break; + case MENU_LISTFILES: + list_files(gUser); + break; + case MENU_UPLOAD: + if (gUser->sec_level >= conf.file_directories[gUser->cur_file_dir]->file_subs[gUser->cur_file_sub]->upload_sec_level) { + upload(gUser); + } else { + s_printf(get_string(84)); + } + break; + case MENU_DOWNLOAD: + download(gUser); + break; + case MENU_CLEARTAGGEDFILES: + clear_tagged_files(); + break; + case MENU_NEXTFILEDIR: + next_file_dir(gUser); + break; + case MENU_PREVFILEDIR: + prev_file_dir(gUser); + break; + case MENU_NEXTFILESUB: + next_file_sub(gUser); + break; + case MENU_PREVFILESUB: + prev_file_sub(gUser); + break; } break; } diff --git a/menus_default/doors.mnu b/menus_default/doors.mnu new file mode 100644 index 0000000..e151019 --- /dev/null +++ b/menus_default/doors.mnu @@ -0,0 +1,9 @@ +LUASCRIPT doors +ANSIFILE doors + +HOTKEY Q +COMMAND PREVMENU + +HOTKEY G +COMMAND SUBMENU +DATA logoff \ No newline at end of file diff --git a/menus_default/file.mnu b/menus_default/file.mnu new file mode 100644 index 0000000..f2c212e --- /dev/null +++ b/menus_default/file.mnu @@ -0,0 +1,39 @@ +LUASCRIPT filemenu +ANSIFILE filemenu + +HOTKEY I +COMMAND CHOOSEFILEDIR + +HOTKEY S +COMMAND CHOOSEFILESUB + +HOTKEY L +COMMAND LISTFILES + +HOTKEY U +COMMAND UPLOAD + +HOTKEY D +COMMAND DOWNLOAD + +HOTKEY C +COMMAND CLEARTAGGED + +HOTKEY } +COMMAND NEXTFILEDIR + +HOTKEY { +COMMAND PREVFILEDIR + +HOTKEY ] +COMMAND NEXTFILESUB + +HOTKEY [ +COMMAND PREVFILESUB + +HOTKEY Q +COMMAND PREVMENU + +HOTKEY G +COMMAND SUBMENU +DATA logoff diff --git a/menus_default/logoff.mnu b/menus_default/logoff.mnu new file mode 100644 index 0000000..27eb5c2 --- /dev/null +++ b/menus_default/logoff.mnu @@ -0,0 +1,7 @@ +ANSIFILE logoff + +HOTKEY Y +COMMAND LOGOFF + +HOTKEY N +COMMAND PREVMENU diff --git a/menus_default/mail.mnu b/menus_default/mail.mnu new file mode 100644 index 0000000..bfcc1e0 --- /dev/null +++ b/menus_default/mail.mnu @@ -0,0 +1,48 @@ +LUASCRIPT mailmenu +ANSIFILE mailmenu + +HOTKEY ! +COMMAND MAILSCAN + +HOTKEY D +COMMAND READMAIL + +HOTKEY P +COMMAND POSTMESSAGE + +HOTKEY L +COMMAND LISTMESSAGES + +HOTKEY C +COMMAND CHOOSEMAILCONF + +HOTKEY Q +COMMAND PREVMENU + +HOTKEY G +COMMAND SUBMENU +DATA logoff + +HOTKEY E +COMMAND SENDEMAIL + +HOTKEY R +COMMAND LISTEMAIL + +HOTKEY } +COMMAND NEXTMAILCONF + +HOTKEY { +COMMAND PREVMAILCONF + +HOTKEY ] +COMMAND NEXTMAILAREA + +HOTKEY [ +COMMAND PREVMAILAREA + +HOTKEY B +COMMAND BLUEWAVEDOWNLOAD + +HOTKEY U +COMMAND BLUEWAVEUPLOAD diff --git a/menus_default/main.mnu b/menus_default/main.mnu new file mode 100644 index 0000000..aa93710 --- /dev/null +++ b/menus_default/main.mnu @@ -0,0 +1,42 @@ +LUASCRIPT mainmenu +ANSIFILE mainmenu + +HOTKEY O +COMMAND AUTOMESSAGE_WRITE + +HOTKEY A +COMMAND TEXTFILES + +HOTKEY C +COMMAND CHATSYSTEM + +HOTKEY L +COMMAND BBSLIST + +HOTKEY U +COMMAND LISTUSERS + +HOTKEY B +COMMAND BULLETINS + +HOTKEY 1 +COMMAND LAST10CALLERS + +HOTKEY D +COMMAND SUBMENU +DATA doors + +HOTKEY M +COMMAND SUBMENU +DATA mail + +HOTKEY T +COMMAND SUBMENU +DATA file + +HOTKEY S +COMMAND SETTINGS + +HOTKEY G +COMMAND SUBMENU +DATA logoff diff --git a/scripts_examples/logout_stanza.lua b/scripts_examples/logout_stanza.lua index 2338308..f0cf0f5 100644 --- a/scripts_examples/logout_stanza.lua +++ b/scripts_examples/logout_stanza.lua @@ -1,13 +1,4 @@ function logout() - bbs_write_string("\r\n\r\nAre you sure you want to logoff (Y/N) ? "); - - cmd = bbs_read_char(); - - if (cmd == "n" or cmd == "N") then - return 0; - end - bbs_display_ansi("goodbye"); - return 1; end From 3af9685e52b925cf34413f908e8503a0e2cbabb4 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Wed, 12 Apr 2017 22:37:21 +1000 Subject: [PATCH 4/7] Remove menu key from doors.ini --- bbs.h | 1 - config_default/doors.ini | 2 -- main.c | 8 ++------ 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/bbs.h b/bbs.h index ee22c86..6f76e0f 100644 --- a/bbs.h +++ b/bbs.h @@ -43,7 +43,6 @@ struct text_file { struct door_config { char *name; - char key; char *command; int stdio; }; diff --git a/config_default/doors.ini b/config_default/doors.ini index ad3439b..07de642 100644 --- a/config_default/doors.ini +++ b/config_default/doors.ini @@ -1,6 +1,4 @@ [Test Door] -; the key to press in the door menu must not be Q or G not case sensitive -key = 0 ; the command is passed node number as first argument ; and socket number as second argument. command = /home/andrew/MagickaBBS/doors/rundoor.sh diff --git a/main.c b/main.c index 1b9dacc..a3cfbd2 100644 --- a/main.c +++ b/main.c @@ -202,9 +202,7 @@ static int door_config_handler(void* user, const char* section, const char* name for (i=0;idoor_count;i++) { if (strcasecmp(conf->doors[i]->name, section) == 0) { // found it - if (strcasecmp(name, "key") == 0) { - conf->doors[i]->key = value[0]; - } else if (strcasecmp(name, "command") == 0) { + if (strcasecmp(name, "command") == 0) { conf->doors[i]->command = strdup(value); } else if (strcasecmp(name, "stdio") == 0) { if (strcasecmp(value, "true") == 0) { @@ -227,9 +225,7 @@ static int door_config_handler(void* user, const char* section, const char* name conf->doors[conf->door_count]->name = strdup(section); - if (strcasecmp(name, "key") == 0) { - conf->doors[conf->door_count]->key = value[0]; - } else if (strcasecmp(name, "command") == 0) { + if (strcasecmp(name, "command") == 0) { conf->doors[conf->door_count]->command = strdup(value); } else if (strcasecmp(name, "stdio") == 0) { if (strcasecmp(value, "true") == 0) { From 7379e8e81e12d51885a672298202cc93a86c4498 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Wed, 12 Apr 2017 22:45:15 +1000 Subject: [PATCH 5/7] Fix includes --- menus.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/menus.c b/menus.c index b06d002..8c64b4d 100644 --- a/menus.c +++ b/menus.c @@ -1,5 +1,6 @@ #include -#include +#include +#include #include #include "bbs.h" #include "lua/lua.h" From 0e4dfdc767a9354bb74b4796eb243086f0e09078 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Wed, 12 Apr 2017 23:04:35 +1000 Subject: [PATCH 6/7] Add missing function --- menus.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/menus.c b/menus.c index 8c64b4d..70e6853 100644 --- a/menus.c +++ b/menus.c @@ -42,6 +42,7 @@ #define MENU_PREVFILEDIR 33 #define MENU_NEXTFILESUB 34 #define MENU_PREVFILESUB 35 +#define MENU_LISTMESSAGES 36 extern struct bbs_config conf; extern struct user_record *gUser; @@ -173,6 +174,8 @@ int menu_system(char *menufile) { menu[menu_items-1]->command = MENU_NEXTFILESUB; } else if (strncasecmp(&buffer[8], "PREVFILESUB", 11) == 0) { menu[menu_items-1]->command = MENU_PREVFILESUB; + } else if (strncasecmp(&buffer[8], "LISTMESSAGES", 12) == 0) { + menu[menu_items-1]->command = MENU_LISTMESSAGES; } } else if (strncasecmp(buffer, "DATA", 4) == 0) { menu[menu_items-1]->data = strdup(&buffer[5]); @@ -413,7 +416,10 @@ int menu_system(char *menufile) { break; case MENU_PREVFILESUB: prev_file_sub(gUser); - break; + break; + case MENU_LISTMESSAGES: + list_messages(gUser); + break; } break; } From 9240d0b42548f7446f0863f25d0e79267cf938fa Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Wed, 12 Apr 2017 23:07:16 +1000 Subject: [PATCH 7/7] Add missing menu entry --- menus_default/mail.mnu | 3 +++ 1 file changed, 3 insertions(+) diff --git a/menus_default/mail.mnu b/menus_default/mail.mnu index bfcc1e0..49a83e1 100644 --- a/menus_default/mail.mnu +++ b/menus_default/mail.mnu @@ -16,6 +16,9 @@ COMMAND LISTMESSAGES HOTKEY C COMMAND CHOOSEMAILCONF +HOTKEY A +COMMAND CHOOSEMAILAREA + HOTKEY Q COMMAND PREVMENU