From 109f59302a5e4da6db5f052cebcb0fcad63f83be Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Wed, 12 Apr 2017 22:34:08 +1000 Subject: [PATCH] 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