2016-03-22 01:48:59 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2016-03-27 00:33:43 +00:00
|
|
|
#include <stdlib.h>
|
2016-03-22 01:48:59 +00:00
|
|
|
#include <ctype.h>
|
2016-03-23 06:31:00 +00:00
|
|
|
#include <sys/stat.h>
|
2016-03-22 01:48:59 +00:00
|
|
|
#include "bbs.h"
|
2016-04-12 05:19:56 +00:00
|
|
|
#include "lua/lua.h"
|
|
|
|
#include "lua/lualib.h"
|
|
|
|
#include "lua/lauxlib.h"
|
2016-03-22 01:48:59 +00:00
|
|
|
|
2016-08-04 09:25:49 +00:00
|
|
|
extern struct bbs_config conf;
|
2016-03-22 01:48:59 +00:00
|
|
|
|
2016-08-06 04:36:36 +00:00
|
|
|
void main_menu(struct user_record *user) {
|
2016-03-22 01:48:59 +00:00
|
|
|
int doquit = 0;
|
|
|
|
char c;
|
|
|
|
char prompt[128];
|
2016-03-23 06:31:00 +00:00
|
|
|
char buffer[256];
|
|
|
|
int i;
|
|
|
|
struct stat s;
|
2016-04-12 05:19:56 +00:00
|
|
|
int do_internal_menu = 0;
|
|
|
|
char *lRet;
|
|
|
|
lua_State *L;
|
|
|
|
int result;
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2016-04-12 05:19:56 +00:00
|
|
|
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) {
|
2016-08-04 09:25:49 +00:00
|
|
|
dolog("Failed to run script: %s", lua_tostring(L, -1));
|
2016-04-12 05:19:56 +00:00
|
|
|
do_internal_menu = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
do_internal_menu = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
do_internal_menu = 1;
|
|
|
|
}
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2016-03-22 01:48:59 +00:00
|
|
|
while (!doquit) {
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2016-04-12 05:19:56 +00:00
|
|
|
if (do_internal_menu == 1) {
|
2016-08-06 04:36:36 +00:00
|
|
|
s_displayansi("mainmenu");
|
2016-08-04 09:25:49 +00:00
|
|
|
|
|
|
|
|
2016-08-06 04:36:36 +00:00
|
|
|
s_printf("\r\n\e[0mTL: %dm :> ", user->timeleft);
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2016-08-06 04:36:36 +00:00
|
|
|
c = s_getc();
|
2016-04-12 05:19:56 +00:00
|
|
|
} else {
|
|
|
|
lua_getglobal(L, "menu");
|
|
|
|
result = lua_pcall(L, 0, 1, 0);
|
|
|
|
if (result) {
|
2016-08-04 09:25:49 +00:00
|
|
|
dolog("Failed to run script: %s", lua_tostring(L, -1));
|
2016-04-12 05:19:56 +00:00
|
|
|
do_internal_menu = 1;
|
|
|
|
lua_close(L);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lRet = (char *)lua_tostring(L, -1);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
c = lRet[0];
|
|
|
|
}
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2016-03-22 01:48:59 +00:00
|
|
|
switch(tolower(c)) {
|
2016-04-18 10:34:07 +00:00
|
|
|
case 'o':
|
|
|
|
{
|
2016-08-06 04:38:08 +00:00
|
|
|
automessage_write(user);
|
2016-04-18 10:34:07 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-03-27 00:33:43 +00:00
|
|
|
case 'a':
|
|
|
|
{
|
|
|
|
if (conf.text_file_count > 0) {
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2016-03-27 00:33:43 +00:00
|
|
|
while(1) {
|
2016-08-06 04:36:36 +00:00
|
|
|
s_printf("\r\n\e[1;32mText Files Collection\r\n");
|
|
|
|
s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2016-03-27 00:33:43 +00:00
|
|
|
for (i=0;i<conf.text_file_count;i++) {
|
2016-08-06 04:36:36 +00:00
|
|
|
s_printf("\e[1;30m[\e[1;34m%3d\e[1;30m] \e[1;37m%s\r\n", i, conf.text_files[i]->name);
|
2016-03-27 00:33:43 +00:00
|
|
|
}
|
2016-08-06 04:36:36 +00:00
|
|
|
s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
|
|
|
|
s_printf("Enter the number of a text file to display or Q to quit: ");
|
|
|
|
s_readstring(buffer, 4);
|
2016-03-27 00:33:43 +00:00
|
|
|
if (tolower(buffer[0]) != 'q') {
|
|
|
|
i = atoi(buffer);
|
|
|
|
if (i >= 0 && i < conf.text_file_count) {
|
2016-08-06 04:36:36 +00:00
|
|
|
s_printf("\r\n");
|
|
|
|
s_displayansi_p(conf.text_files[i]->path);
|
|
|
|
s_printf("Press any key to continue...");
|
|
|
|
s_getc();
|
|
|
|
s_printf("\r\n");
|
2016-03-27 00:33:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2016-08-06 04:36:36 +00:00
|
|
|
s_printf("\r\nSorry, there are no text files to display\r\n");
|
|
|
|
s_printf("Press any key to continue...\r\n");
|
|
|
|
s_getc();
|
2016-03-27 00:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2016-03-26 12:41:14 +00:00
|
|
|
case 'c':
|
|
|
|
{
|
2016-08-06 04:36:36 +00:00
|
|
|
chat_system(user);
|
2016-03-26 12:41:14 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-03-25 10:21:28 +00:00
|
|
|
case 'l':
|
|
|
|
{
|
2016-08-06 04:36:36 +00:00
|
|
|
bbs_list(user);
|
2016-03-25 10:21:28 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-03-23 06:31:00 +00:00
|
|
|
case 'u':
|
|
|
|
{
|
2016-08-06 04:36:36 +00:00
|
|
|
list_users(user);
|
2016-03-23 06:31:00 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
{
|
|
|
|
i = 0;
|
|
|
|
sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i);
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2016-03-23 06:31:00 +00:00
|
|
|
while (stat(buffer, &s) == 0) {
|
|
|
|
sprintf(buffer, "bulletin%d", i);
|
2016-08-06 04:36:36 +00:00
|
|
|
s_displayansi(buffer);
|
|
|
|
s_printf("\e[0mPress any key to continue...\r\n");
|
|
|
|
s_getc();
|
2016-03-23 06:31:00 +00:00
|
|
|
i++;
|
|
|
|
sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i);
|
2016-08-04 09:25:49 +00:00
|
|
|
}
|
2016-03-23 06:31:00 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-03-23 05:21:53 +00:00
|
|
|
case '1':
|
|
|
|
{
|
2016-08-06 04:36:36 +00:00
|
|
|
display_last10_callers(user);
|
2016-03-23 05:21:53 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-03-23 03:26:12 +00:00
|
|
|
case 'd':
|
|
|
|
{
|
2016-08-06 04:36:36 +00:00
|
|
|
doquit = door_menu(user);
|
2016-03-23 03:26:12 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-03-22 03:07:42 +00:00
|
|
|
case 'm':
|
|
|
|
{
|
2016-08-06 04:36:36 +00:00
|
|
|
doquit = mail_menu(user);
|
2016-03-22 03:07:42 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-03-22 01:48:59 +00:00
|
|
|
case 'g':
|
|
|
|
{
|
2016-08-06 04:36:36 +00:00
|
|
|
s_printf("\r\nAre you sure you want to log off? (Y/N)");
|
|
|
|
c = s_getc();
|
2016-03-22 01:48:59 +00:00
|
|
|
if (tolower(c) == 'y') {
|
|
|
|
doquit = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2016-04-02 23:26:17 +00:00
|
|
|
case 't':
|
|
|
|
{
|
2016-08-06 04:36:36 +00:00
|
|
|
doquit = file_menu(user);
|
2016-04-02 23:26:17 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-04-10 08:45:02 +00:00
|
|
|
case 's':
|
|
|
|
{
|
2016-08-06 04:36:36 +00:00
|
|
|
settings_menu(user);
|
2016-04-10 08:45:02 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-03-22 01:48:59 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-12 05:19:56 +00:00
|
|
|
if (do_internal_menu == 0) {
|
|
|
|
lua_close(L);
|
|
|
|
}
|
2016-03-22 01:48:59 +00:00
|
|
|
}
|