More work on menusystem

This commit is contained in:
Andrew Pamment 2017-04-12 22:34:08 +10:00
parent a1190bc1d7
commit 109f59302a
24 changed files with 772 additions and 888 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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)

BIN
ansis_default/logoff.ans Normal file

Binary file not shown.

25
bbs.c
View File

@ -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;
}
} 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) {

25
bbs.h
View File

@ -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);

View File

@ -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

82
doors.c
View File

@ -382,85 +382,3 @@ 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;i<conf.door_count;i++) {
if (tolower(c) == tolower(conf.doors[i]->key)) {
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;
}

168
files.c
View File

@ -1072,70 +1072,40 @@ 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;
}
s_printf(get_string(81));
for (i=0;i<conf.file_directories[user->cur_file_dir]->file_sub_count;i++) {
s_printf(" %d. %s\r\n", i, conf.file_directories[user->cur_file_dir]->file_subs[i]->name);
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);
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) {
if (i != 0 && i % 20 == 0) {
s_printf(get_string(6));
c = s_getc();
}
}
break;
case 'i':
{
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;
}
}
}
void choose_directory(struct user_record *user) {
int i;
char c;
int j;
char prompt[6];
s_printf(get_string(77));
for (i=0;i<conf.file_directory_count;i++) {
if (conf.file_directories[i]->sec_level <= user->sec_level) {
@ -1159,48 +1129,9 @@ int file_menu(struct user_record *user) {
}
}
}
break;
case 's':
{
s_printf(get_string(81));
for (i=0;i<conf.file_directories[user->cur_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':
{
void clear_tagged_files() {
int i;
// Clear tagged files
if (tagged_count > 0) {
for (i=0;i<tagged_count;i++) {
@ -1210,10 +1141,9 @@ int file_menu(struct user_record *user) {
tagged_count = 0;
}
}
break;
case '}':
{
void next_file_dir(struct user_record *user) {
int i;
for (i=user->cur_file_dir;i<conf.file_directory_count;i++) {
if (i + 1 == conf.file_directory_count) {
i = -1;
@ -1225,9 +1155,9 @@ int file_menu(struct user_record *user) {
}
}
}
break;
case '{':
{
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;
@ -1239,38 +1169,22 @@ int file_menu(struct user_record *user) {
}
}
}
break;
case ']':
{
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;
}
break;
case '[':
{
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;
}
break;
case 'q':
dofiles = 1;
break;
case 'g':
{
doquit = do_logout();
dofiles = doquit;
}
break;
}
}
if (do_internal_menu == 0) {
lua_close(L);
}
return doquit;
}

View File

@ -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,109 +2086,21 @@ 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;
int closed;
int redraw;
struct tm msg_date;
char c;
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;
}
} 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;
}
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);
@ -2194,7 +2108,7 @@ int mail_menu(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) {
@ -2342,9 +2256,14 @@ int mail_menu(struct user_record *user) {
s_printf(get_string(130));
}
}
break;
case 'c':
{
void choose_conference(struct user_record *user) {
int i;
int j;
char c;
char buffer[6];
s_printf(get_string(131));
for (i=0;i<conf.mail_conference_count;i++) {
if (conf.mail_conferences[i]->sec_level <= user->sec_level) {
@ -2368,9 +2287,13 @@ int mail_menu(struct user_record *user) {
}
}
}
break;
case 'a':
{
void choose_area(struct user_record *user) {
int i;
int j;
char c;
char buffer[6];
s_printf(get_string(135));
for (i=0;i<conf.mail_conferences[user->cur_mail_conf]->mail_area_count;i++) {
if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[i]->read_sec_level <= user->sec_level) {
@ -2393,32 +2316,10 @@ int mail_menu(struct user_record *user) {
}
}
}
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 '}':
{
void next_mail_conf(struct user_record *user) {
int i;
for (i=user->cur_mail_conf;i<conf.mail_conference_count;i++) {
if (i + 1 == conf.mail_conference_count) {
i = -1;
@ -2430,9 +2331,9 @@ int mail_menu(struct user_record *user) {
}
}
}
break;
case '{':
{
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;
@ -2444,9 +2345,9 @@ int mail_menu(struct user_record *user) {
}
}
}
break;
case ']':
{
void next_mail_area(struct user_record *user) {
int i;
for (i=user->cur_mail_area;i<conf.mail_conferences[user->cur_mail_conf]->mail_area_count;i++) {
if (i + 1 == conf.mail_conferences[user->cur_mail_conf]->mail_area_count) {
i = -1;
@ -2457,9 +2358,9 @@ int mail_menu(struct user_record *user) {
}
}
}
break;
case '[':
{
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;
@ -2470,24 +2371,6 @@ int mail_menu(struct user_record *user) {
}
}
}
break;
case 'b':
{
bwave_create_packet();
}
break;
case 'u':
{
bwave_upload_reply();
}
break;
}
}
if (do_internal_menu == 0) {
lua_close(L);
}
return doquit;
}
void mail_scan(struct user_record *user) {
s_JamBase *jb;

7
main.c
View File

@ -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;i<conf.mail_conference_count;i++) {
if (ini_parse(conf.mail_conferences[i]->path, mail_area_handler, conf.mail_conferences[i]) <0) {

View File

@ -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);
@ -63,133 +63,3 @@ void display_textfiles() {
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);
}
}

207
menus.c
View File

@ -1,3 +1,11 @@
#include <stdio.h>
#include <strings.h>
#include <sys/stat.h>
#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,15 +54,27 @@ 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);
@ -40,10 +84,11 @@ int menu_system(char *menufile) {
lua_script = NULL;
ansi_file = NULL;
while (1) {
fgets(buffer, 256, fptr);
while (!feof(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,26 +186,29 @@ int menu_system(char *menufile) {
}
ansi_file = strdup(&buffer[9]);
}
fgets(buffer, 256, fptr);
}
fclose(fptr);
do_lua_menu = 0;
if (lua_script != NULL) {
if (conf.script_path != NULL && lua_script[0] != '/') {
snprintf(buffer, 256 "%s/%s", conf.script_path, lua_script);
snprintf(buffer, PATH_MAX, "%s/%s.lua", conf.script_path, lua_script);
do_lua_menu = 1;
} else if (lua_script[0] == '/') {
snprintf(buffer, 256 "%s", lua_script);
snprintf(buffer, PATH_MAX, "%s.lua", lua_script);
do_lua_menu = 1;
}
if (do_lua_menu)
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;
do_lua_menu = 1;
result = lua_pcall(L, 0, 1, 0);
if (result) {
dolog("Failed to run script: %s", lua_tostring(L, -1));
@ -128,6 +218,7 @@ int menu_system(char *menufile) {
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;i<menu_items;i++) {
if (menu[i]->hotkey == 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;i<menu_items;i++) {
if (menu[i]->data != NULL) {
free(menu[i]->data)
free(menu[i]->data);
}
free(menu[i]);
}
@ -189,7 +280,7 @@ int menu_system(char *menufile) {
}
for (i=0;i<menu_items;i++) {
if (menu[i]->data != NULL) {
free(menu[i]->data)
free(menu[i]->data);
}
free(menu[i]);
}
@ -207,56 +298,120 @@ int menu_system(char *menufile) {
}
for (i=0;i<menu_items;i++) {
if (menu[i]->data != 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;j<conf.door_count;j++) {
if (strcasecmp(menu[i]->data, 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;

9
menus_default/doors.mnu Normal file
View File

@ -0,0 +1,9 @@
LUASCRIPT doors
ANSIFILE doors
HOTKEY Q
COMMAND PREVMENU
HOTKEY G
COMMAND SUBMENU
DATA logoff

39
menus_default/file.mnu Normal file
View File

@ -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

7
menus_default/logoff.mnu Normal file
View File

@ -0,0 +1,7 @@
ANSIFILE logoff
HOTKEY Y
COMMAND LOGOFF
HOTKEY N
COMMAND PREVMENU

48
menus_default/mail.mnu Normal file
View File

@ -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

42
menus_default/main.mnu Normal file
View File

@ -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

View File

@ -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