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;
|
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-14 09:56:15 +00:00
|
|
|
s_printf(get_string(142), 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-12-02 05:31:29 +00:00
|
|
|
case 27:
|
|
|
|
{
|
|
|
|
c = s_getc();
|
|
|
|
if (c == 91) {
|
|
|
|
c = s_getc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
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-14 09:56:15 +00:00
|
|
|
s_printf(get_string(143));
|
|
|
|
s_printf(get_string(144));
|
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-14 09:56:15 +00:00
|
|
|
s_printf(get_string(145), i, conf.text_files[i]->name);
|
2016-03-27 00:33:43 +00:00
|
|
|
}
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(146));
|
|
|
|
s_printf(get_string(147));
|
2016-08-06 04:36:36 +00:00
|
|
|
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);
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(6));
|
2016-08-06 04:36:36 +00:00
|
|
|
s_getc();
|
|
|
|
s_printf("\r\n");
|
2016-03-27 00:33:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(148));
|
|
|
|
s_printf(get_string(6));
|
2016-08-06 04:36:36 +00:00
|
|
|
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);
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(6));
|
2016-08-06 04:36:36 +00:00
|
|
|
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-09-05 04:05:17 +00:00
|
|
|
doquit = do_logout();
|
2016-03-22 01:48:59 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|