This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
magicka/src/menus.c

680 lines
35 KiB
C
Raw Normal View History

2017-04-12 12:34:08 +00:00
#include <stdio.h>
2017-04-12 12:45:15 +00:00
#include <string.h>
#include <stdlib.h>
2017-04-12 12:34:08 +00:00
#include <sys/stat.h>
2017-04-23 02:14:14 +00:00
#include <unistd.h>
2017-04-12 12:34:08 +00:00
#include "bbs.h"
#include "lua/lua.h"
#include "lua/lualib.h"
#include "lua/lauxlib.h"
2017-04-12 06:38:33 +00:00
#define MENU_SUBMENU 1
#define MENU_LOGOFF 2
#define MENU_PREVMENU 3
#define MENU_AUTOMESSAGE 4
2017-04-12 06:38:33 +00:00
#define MENU_TEXTFILES 5
#define MENU_CHATSYSTEM 6
#define MENU_BBSLIST 7
#define MENU_LISTUSERS 8
#define MENU_BULLETINS 9
#define MENU_LAST10 10
#define MENU_SETTINGS 11
2017-04-12 07:27:59 +00:00
#define MENU_DOOR 12
#define MENU_MAILSCAN 13
#define MENU_READMAIL 14
#define MENU_POSTMESSAGE 15
2017-04-12 12:34:08 +00:00
#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
2017-04-12 13:04:35 +00:00
#define MENU_LISTMESSAGES 36
2017-04-16 05:53:33 +00:00
#define MENU_DOSCRIPT 37
2017-04-22 01:53:44 +00:00
#define MENU_SENDNODEMSG 38
2017-09-21 00:21:51 +00:00
#define MENU_SUBUNSUBCONF 39
2017-09-21 06:07:31 +00:00
#define MENU_RESETPOINTERS 40
#define MENU_RESETALLPOINTERS 41
2017-09-28 09:11:00 +00:00
#define MENU_FILESCAN 42
2017-10-12 10:24:55 +00:00
#define MENU_FULLMAILSCAN 43
2017-10-19 02:54:20 +00:00
#define MENU_FILESEARCH 44
#define MENU_DISPTXTFILE 45
#define MENU_DISPTXTFILEPAUSE 46
2018-01-23 10:57:58 +00:00
#define MENU_GENWWWURLS 47
2018-02-06 01:41:55 +00:00
#define MENU_NLBROWSER 48
2018-02-07 10:38:25 +00:00
#define MENU_SENDFEEDBACK 49
2018-02-27 08:26:32 +00:00
#define MENU_BLOGDISPLAY 50
#define MENU_BLOGWRITE 51
2017-04-12 12:34:08 +00:00
extern struct bbs_config conf;
extern struct user_record *gUser;
extern int mynode;
2017-04-12 06:38:33 +00:00
struct menu_item {
char hotkey;
2018-05-01 06:05:01 +00:00
int *command;
char **data;
int command_count;
2017-04-16 09:04:29 +00:00
int seclevel;
2017-04-12 06:38:33 +00:00
};
int menu_system(char *menufile) {
FILE *fptr;
2017-04-12 12:34:08 +00:00
char buffer[PATH_MAX];
2017-04-12 06:38:33 +00:00
int menu_items = 0;
struct menu_item **menu;
char *lua_script;
int do_lua_menu;
char *ansi_file;
int i;
2017-04-12 07:27:59 +00:00
int j;
int k;
2018-05-01 06:05:01 +00:00
int m;
2017-04-12 12:34:08 +00:00
struct stat s;
char *lRet;
lua_State *L;
int result;
int doquit = 0;
char c;
2017-09-14 09:37:48 +00:00
int clearscreen = 0;
2017-09-21 06:24:05 +00:00
char confirm;
2018-02-07 10:38:25 +00:00
char *msg;
2018-02-07 07:27:50 +00:00
dolog("%s is loading menu: %s", gUser->loginname, menufile);
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Browsing menu %s.", gUser->loginname, mynode, menufile);
2018-02-07 07:27:50 +00:00
2017-04-12 12:34:08 +00:00
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");
2017-04-12 06:38:33 +00:00
if (!fptr) {
s_printf("Error opening menu file! %s\r\n", menufile);
return 0;
}
lua_script = NULL;
ansi_file = NULL;
2017-04-12 12:34:08 +00:00
fgets(buffer, 256, fptr);
while (!feof(fptr)) {
2017-04-12 06:38:33 +00:00
chomp(buffer);
if (strncasecmp(buffer, "HOTKEY", 6) == 0) {
menu_items++;
if (menu_items == 1) {
menu = (struct menu_item **)malloc(sizeof(struct menu_item *));
} else {
menu = (struct menu_item **)realloc(menu, sizeof(struct menu_item *) * (menu_items));
}
menu[menu_items-1] = (struct menu_item *)malloc(sizeof(struct menu_item));
menu[menu_items-1]->hotkey = buffer[7];
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command = NULL;
2017-04-12 06:38:33 +00:00
menu[menu_items-1]->data = NULL;
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command_count = 0;
2017-04-16 09:04:29 +00:00
menu[menu_items-1]->seclevel = 0;
2017-04-12 06:38:33 +00:00
} else if (strncasecmp(buffer, "COMMAND", 7) == 0 && menu_items > 0) {
2018-05-01 06:05:01 +00:00
if (menu[menu_items-1]->command_count == 0) {
menu[menu_items-1]->command = (int *)malloc(sizeof(int));
menu[menu_items-1]->data = (char **)malloc(sizeof(char *));
} else {
menu[menu_items-1]->command = (int *)realloc(menu[menu_items-1]->command, sizeof(int) * (menu[menu_items-1]->command_count + 1));
menu[menu_items-1]->data = (char **)realloc(menu[menu_items-1]->data, sizeof(char *) * (menu[menu_items-1]->command_count + 1));
}
menu[menu_items-1]->command_count++;
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = 0;
menu[menu_items-1]->data[menu[menu_items -1]->command_count - 1] = NULL;
2017-04-12 12:34:08 +00:00
if (strncasecmp(&buffer[8], "SUBMENU", 7) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SUBMENU;
2017-04-12 06:38:33 +00:00
} else if (strncasecmp(&buffer[8], "LOGOFF", 6) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LOGOFF;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "PREVMENU", 8) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVMENU;
} else if (strncasecmp(&buffer[8], "AUTOMESSAGE", 11) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_AUTOMESSAGE;
2017-04-12 06:38:33 +00:00
} else if (strncasecmp(&buffer[8], "TEXTFILES", 9) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_TEXTFILES;
2017-04-12 06:38:33 +00:00
} else if (strncasecmp(&buffer[8], "CHATSYSTEM", 10) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHATSYSTEM;
2017-04-12 06:38:33 +00:00
} else if (strncasecmp(&buffer[8], "BBSLIST", 7) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BBSLIST;
2017-04-12 06:38:33 +00:00
} else if (strncasecmp(&buffer[8], "LISTUSERS", 9) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LISTUSERS;
2017-04-12 06:38:33 +00:00
} else if (strncasecmp(&buffer[8], "BULLETINS", 9) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BULLETINS;
2017-04-12 06:38:33 +00:00
} else if (strncasecmp(&buffer[8], "LAST10CALLERS", 13) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LAST10;
2017-04-12 06:38:33 +00:00
} else if (strncasecmp(&buffer[8], "SETTINGS", 8) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SETTINGS;
2017-04-12 07:27:59 +00:00
} else if (strncasecmp(&buffer[8], "RUNDOOR", 7) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_DOOR;
2017-04-12 07:27:59 +00:00
} else if (strncasecmp(&buffer[8], "MAILSCAN", 8) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_MAILSCAN;
2017-04-12 07:27:59 +00:00
} else if (strncasecmp(&buffer[8], "READMAIL", 8) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_READMAIL;
2017-04-12 07:27:59 +00:00
} else if (strncasecmp(&buffer[8], "POSTMESSAGE", 11) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_POSTMESSAGE;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "CHOOSEMAILCONF", 14) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHOOSEMAILCONF;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "CHOOSEMAILAREA", 14) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHOOSEMAILAREA;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "SENDEMAIL", 9) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SENDEMAIL;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "LISTEMAIL", 9) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LISTEMAIL;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "NEXTMAILCONF", 12) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NEXTMAILCONF;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "PREVMAILCONF", 12) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVMAILCONF;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "NEXTMAILAREA", 12) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NEXTMAILAREA;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "PREVMAILAREA", 12) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVMAILAREA;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "BLUEWAVEDOWNLOAD", 16) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BLUEWAVEDOWN;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "BLUEWAVEUPLOAD", 14) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BLUEWAVEUP;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "CHOOSEFILEDIR", 13) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHOOSEFILEDIR;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "CHOOSEFILESUB", 13) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHOOSEFILESUB;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "LISTFILES", 9) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LISTFILES;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "UPLOAD", 6) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_UPLOAD;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "DOWNLOAD", 8) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_DOWNLOAD;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "CLEARTAGGED", 11) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CLEARTAGGEDFILES;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "NEXTFILEDIR", 11) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NEXTFILEDIR;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "PREVFILEDIR", 11) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVFILEDIR;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "NEXTFILESUB", 11) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NEXTFILESUB;
2017-04-12 12:34:08 +00:00
} else if (strncasecmp(&buffer[8], "PREVFILESUB", 11) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVFILESUB;
2017-04-12 13:04:35 +00:00
} else if (strncasecmp(&buffer[8], "LISTMESSAGES", 12) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LISTMESSAGES;
2017-04-16 05:53:33 +00:00
} else if (strncasecmp(&buffer[8], "DOSCRIPT", 8) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_DOSCRIPT;
2017-04-22 01:53:44 +00:00
} else if (strncasecmp(&buffer[8], "SENDNODEMSG", 11) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SENDNODEMSG;
2017-09-21 00:21:51 +00:00
} else if (strncasecmp(&buffer[8], "SUBUNSUBCONF", 12) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SUBUNSUBCONF;
2017-09-21 06:07:31 +00:00
} else if (strncasecmp(&buffer[8], "RESETMSGPTRS", 12) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_RESETPOINTERS;
2017-09-21 06:07:31 +00:00
} else if (strncasecmp(&buffer[8], "RESETALLMSGPTRS", 15) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_RESETALLPOINTERS;
2017-09-28 09:11:00 +00:00
} else if (strncasecmp(&buffer[8], "FILESCAN", 8) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_FILESCAN;
2017-10-12 10:24:55 +00:00
} else if (strncasecmp(&buffer[8], "FULLMAILSCAN", 12) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_FULLMAILSCAN;
2017-10-19 02:54:20 +00:00
} else if (strncasecmp(&buffer[8], "FILESEARCH", 10) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_FILESEARCH;
} else if (strncasecmp(&buffer[8], "DISPLAYTXTFILE", 14) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_DISPTXTFILE;
2017-10-25 22:41:05 +00:00
} else if (strncasecmp(&buffer[8], "DISPLAYTXTPAUSE", 15) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_DISPTXTFILEPAUSE;
2018-01-23 10:57:58 +00:00
} else if (strncasecmp(&buffer[8], "GENWWWURLS", 10) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_GENWWWURLS;
2018-02-06 01:41:55 +00:00
} else if (strncasecmp(&buffer[8], "NLBROWSER", 9) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NLBROWSER;
2018-02-07 10:38:25 +00:00
} else if (strncasecmp(&buffer[8], "SENDFEEDBACK", 12) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SENDFEEDBACK;
2018-02-27 08:26:32 +00:00
} else if (strncasecmp(&buffer[8], "BLOGDISPLAY", 11) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BLOGDISPLAY;
2018-02-27 08:26:32 +00:00
} else if (strncasecmp(&buffer[8], "BLOGWRITE", 9) == 0) {
2018-05-01 06:05:01 +00:00
menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BLOGWRITE;
2018-01-23 10:57:58 +00:00
}
2017-04-16 09:04:29 +00:00
} else if (strncasecmp(buffer, "SECLEVEL", 8) == 0) {
menu[menu_items-1]->seclevel = atoi(&buffer[9]);
2017-04-12 06:38:33 +00:00
} else if (strncasecmp(buffer, "DATA", 4) == 0) {
2018-05-01 06:05:01 +00:00
if (menu[menu_items-1]->data[menu[menu_items -1]->command_count - 1] != NULL) {
free(menu[menu_items-1]->data[menu[menu_items -1]->command_count - 1]);
}
menu[menu_items-1]->data[menu[menu_items -1]->command_count - 1] = strdup(&buffer[5]);
2017-04-12 06:38:33 +00:00
} else if (strncasecmp(buffer, "LUASCRIPT", 9) == 0) {
2017-04-12 07:27:59 +00:00
if (lua_script != NULL) {
free(lua_script);
}
2017-04-12 06:38:33 +00:00
lua_script = strdup(&buffer[10]);
} else if (strncasecmp(buffer, "ANSIFILE", 8) == 0) {
2017-04-12 07:27:59 +00:00
if (ansi_file != NULL) {
free(ansi_file);
}
2017-04-12 06:38:33 +00:00
ansi_file = strdup(&buffer[9]);
2017-09-14 09:37:48 +00:00
} else if (strncasecmp(buffer, "CLEARSCREEN", 11) == 0) {
clearscreen = 1;
}
2017-04-12 12:34:08 +00:00
fgets(buffer, 256, fptr);
2017-04-12 06:38:33 +00:00
}
fclose(fptr);
do_lua_menu = 0;
2017-04-12 12:34:08 +00:00
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;
}
2017-04-12 06:38:33 +00:00
2017-04-12 12:34:08 +00:00
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;
}
}
}
2017-04-12 06:38:33 +00:00
2017-04-19 05:35:46 +00:00
2017-04-12 06:38:33 +00:00
while (!doquit) {
2017-04-19 05:57:29 +00:00
if (gUser->nodemsgs) {
snprintf(buffer, PATH_MAX, "%s/node%d/nodemsg.txt", conf.bbs_path, mynode);
2017-04-19 05:35:46 +00:00
2017-04-19 05:57:29 +00:00
if (stat(buffer, &s) == 0) {
fptr = fopen(buffer, "r");
if (fptr) {
2017-04-19 05:41:41 +00:00
fgets(buffer, PATH_MAX, fptr);
2017-04-19 05:57:29 +00:00
while (!feof(fptr)) {
chomp(buffer);
s_printf("\r\n%s\r\n", buffer);
fgets(buffer, PATH_MAX, fptr);
}
fclose(fptr);
snprintf(buffer, PATH_MAX, "%s/node%d/nodemsg.txt", conf.bbs_path, mynode);
unlink(buffer);
2017-04-12 06:38:33 +00:00
2017-04-19 05:57:29 +00:00
s_printf(get_string(6));
c = s_getc();
}
2017-04-19 05:35:46 +00:00
}
}
2017-09-14 09:37:48 +00:00
if (clearscreen) {
s_printf("\e[2J\e[1;1H");
}
2017-04-12 06:38:33 +00:00
if (do_lua_menu == 0) {
if (ansi_file != NULL) {
s_displayansi(ansi_file);
}
2017-04-12 12:34:08 +00:00
s_printf(get_string(142), gUser->timeleft);
2017-04-12 06:38:33 +00:00
c = s_getc();
} else {
lua_getglobal(L, "menu");
result = lua_pcall(L, 0, 1, 0);
if (result) {
dolog("Failed to run script: %s", lua_tostring(L, -1));
do_lua_menu = 0;
lua_close(L);
continue;
}
lRet = (char *)lua_tostring(L, -1);
2018-06-12 07:06:49 +00:00
c = lRet[0];
2017-04-12 06:38:33 +00:00
lua_pop(L, 1);
}
for (i=0;i<menu_items;i++) {
2017-04-12 12:34:08 +00:00
if (tolower(menu[i]->hotkey) == tolower(c)) {
2017-04-16 09:04:29 +00:00
if (menu[i]->seclevel <= gUser->sec_level) {
2018-05-01 06:05:01 +00:00
for (j=0; j<menu[i]->command_count;j++) {
switch(menu[i]->command[j]) {
case MENU_SUBMENU:
doquit = menu_system(menu[i]->data[j]);
if (doquit == 1) {
// free menus
if (do_lua_menu) {
lua_close(L);
}
if (lua_script != NULL) {
free(lua_script);
}
if (ansi_file != NULL) {
free(ansi_file);
}
for (i=0;i<menu_items;i++) {
for (j=0;j<menu[i]->command_count;j++) {
if (menu[i]->data[j] != NULL) {
free(menu[i]->data[j]);
}
}
free(menu[i]->data);
free(menu[i]->command);
free(menu[i]);
}
free(menu);
return doquit;
}
break;
case MENU_LOGOFF:
2017-04-16 09:04:29 +00:00
if (do_lua_menu) {
lua_close(L);
2018-05-01 06:05:01 +00:00
}
2017-04-16 09:04:29 +00:00
if (lua_script != NULL) {
free(lua_script);
}
if (ansi_file != NULL) {
free(ansi_file);
}
for (i=0;i<menu_items;i++) {
2018-05-01 06:05:01 +00:00
for (j=0;j<menu[i]->command_count;j++) {
if (menu[i]->data[j] != NULL) {
free(menu[i]->data[j]);
}
2017-04-16 09:04:29 +00:00
}
2018-05-01 06:05:01 +00:00
free(menu[i]->data);
free(menu[i]->command);
2017-04-16 09:04:29 +00:00
free(menu[i]);
}
2018-05-01 06:05:01 +00:00
free(menu);
return 1;
case MENU_PREVMENU:
if (do_lua_menu) {
lua_close(L);
}
if (lua_script != NULL) {
free(lua_script);
}
if (ansi_file != NULL) {
free(ansi_file);
2017-04-16 09:04:29 +00:00
}
2018-05-01 06:05:01 +00:00
for (i=0;i<menu_items;i++) {
for (j=0;j<menu[i]->command_count;j++) {
if (menu[i]->data[j] != NULL) {
free(menu[i]->data[j]);
}
}
2017-04-12 12:34:08 +00:00
free(menu[i]->data);
2018-05-01 06:05:01 +00:00
free(menu[i]->command);
free(menu[i]);
2017-04-12 06:38:33 +00:00
}
2018-05-01 06:05:01 +00:00
free(menu);
return 0;
case MENU_AUTOMESSAGE:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Viewing/Changing Automessage.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
automessage();
break;
case MENU_TEXTFILES:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Browsing Textfiles.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
display_textfiles();
break;
case MENU_CHATSYSTEM:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: In Chat System.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
chat_system(gUser);
break;
case MENU_BBSLIST:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Browsing BBS List.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
bbs_list(gUser);
break;
case MENU_LISTUSERS:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Browsing User List.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
list_users(gUser);
break;
case MENU_BULLETINS:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Reading Bulletins.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
display_bulletins();
break;
case MENU_LAST10:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Viewing Last 10 Callers.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
display_last10_callers(gUser);
break;
case MENU_SETTINGS:
settings_menu(gUser);
break;
case MENU_DOOR:
{
for (m=0;m<conf.door_count;m++) {
if (strcasecmp(menu[i]->data[j], conf.doors[m]->name) == 0) {
dolog("%s launched door %s, on node %d", gUser->loginname, conf.doors[m]->name, mynode);
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Executing Door %s.", gUser->loginname, mynode, conf.doors[m]->name);
2018-05-01 06:05:01 +00:00
rundoor(gUser, conf.doors[m]->command, conf.doors[m]->stdio, conf.doors[m]->codepage);
dolog("%s returned from door %s, on node %d", gUser->loginname, conf.doors[m]->name, mynode);
break;
}
2017-04-16 09:04:29 +00:00
}
}
2018-05-01 06:05:01 +00:00
break;
case MENU_MAILSCAN:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Performing Mail Scan.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
mail_scan(gUser);
break;
case MENU_READMAIL:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Reading Mail.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
read_mail(gUser);
break;
case MENU_POSTMESSAGE:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Posting a Message.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
post_message(gUser);
break;
case MENU_CHOOSEMAILCONF:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Choosing Mail Conference.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
choose_conference();
break;
case MENU_CHOOSEMAILAREA:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Choosing Mail Area.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
choose_area();
break;
case MENU_SENDEMAIL:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Sending an Email.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
send_email(gUser);
break;
case MENU_LISTEMAIL:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Browsing their Emails.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
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:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Downloading Bluewave Packet.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
bwave_create_packet();
break;
case MENU_BLUEWAVEUP:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Uploading Bluewave Packet.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
bwave_upload_reply();
break;
case MENU_CHOOSEFILEDIR:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Choosing a file directory.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
choose_directory();
break;
case MENU_CHOOSEFILESUB:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Choosing a file sub-directory.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
choose_subdir();
break;
case MENU_LISTFILES:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Browsing Files.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
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) {
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Uploading a File.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
upload(gUser);
} else {
s_printf(get_string(84));
}
break;
case MENU_DOWNLOAD:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Downloading Files.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
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;
case MENU_LISTMESSAGES:
list_messages(gUser);
break;
case MENU_DOSCRIPT:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Executing a script %s.", gUser->loginname, mynode, menu[i]->data[j]);
2018-05-02 22:23:26 +00:00
do_lua_script(menu[i]->data[j]);
2018-05-01 06:05:01 +00:00
break;
case MENU_SENDNODEMSG:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Sending a node Message.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
send_node_msg();
break;
case MENU_SUBUNSUBCONF:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Subscribing to conferences.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
msg_conf_sub_bases();
break;
case MENU_RESETPOINTERS:
s_printf(get_string(229));
s_readstring(buffer, 10);
if (tolower(buffer[0]) == 'r') {
k = -1;
m = 1;
} else if (tolower(buffer[0]) == 'u') {
k = -1;
m = 0;
} else if (buffer[0] < '0' || buffer[0] > '9') {
s_printf(get_string(39));
break;
} else {
k = atoi(buffer) - 1;
}
2018-05-01 06:05:01 +00:00
msgbase_reset_pointers(gUser->cur_mail_conf, gUser->cur_mail_area, m, k);
2018-05-01 06:05:01 +00:00
break;
case MENU_RESETALLPOINTERS:
s_printf(get_string(230));
confirm = s_getc();
if (confirm == 'r' || confirm == 'R') {
m = 1;
} else if (confirm == 'u' || confirm == 'U') {
m = 0;
} else {
s_printf(get_string(39));
break;
}
msgbase_reset_all_pointers(m);
break;
case MENU_FILESCAN:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Doing a filescan.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
file_scan();
break;
case MENU_FULLMAILSCAN:
if (menu[i]->data[j] != NULL) {
if (strcasecmp(menu[i]->data[j], "PERSONAL") == 0) {
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Scanning for personal mail.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
full_mail_scan_personal(gUser);
} else {
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Scanning all mail.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
full_mail_scan(gUser);
}
2018-02-18 03:51:39 +00:00
} else {
full_mail_scan(gUser);
}
2018-05-01 06:05:01 +00:00
break;
case MENU_FILESEARCH:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Executing a filesearch.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
file_search();
break;
case MENU_DISPTXTFILE:
if (menu[i]->data[j] != NULL) {
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Displaying Text File: %s.", gUser->loginname, mynode, menu[i]->data[j]);
2018-05-01 06:05:01 +00:00
s_displayansi_pause(menu[i]->data[j], 0);
}
break;
case MENU_DISPTXTFILEPAUSE:
if (menu[i]->data[j] != NULL) {
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Displaying Text File: %s.", gUser->loginname, mynode, menu[i]->data[j]);
2018-05-01 06:05:01 +00:00
s_displayansi_pause(menu[i]->data[j], 1);
}
s_printf(get_string(6));
s_getc();
break;
case MENU_GENWWWURLS:
genurls();
break;
case MENU_NLBROWSER:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Executing a filesearch.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
nl_browser();
break;
case MENU_SENDFEEDBACK:
if (check_user(conf.sysop_name)) {
break;
}
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Sending feedback to Sysop.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
msg = external_editor(gUser, conf.sysop_name, gUser->loginname, NULL, 0, NULL, "Feedback", 1, 0);
if (msg != NULL) {
commit_email(conf.sysop_name, "Feedback", msg);
free(msg);
}
break;
case MENU_BLOGDISPLAY:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Displaying Blog.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
blog_display();
break;
case MENU_BLOGWRITE:
2018-06-18 06:52:27 +00:00
broadcast("USER: %s; NODE:%d; STATUS: Writing a Blog Entry.", gUser->loginname, mynode);
2018-05-01 06:05:01 +00:00
blog_write();
break;
default:
break;
}
2017-04-16 09:04:29 +00:00
}
2018-05-01 06:13:55 +00:00
break;
2017-04-12 06:38:33 +00:00
}
}
}
}
// free menus;
return doquit;
2017-09-14 09:37:48 +00:00
}