-
Notifications
You must be signed in to change notification settings - Fork 5
/
main_menu.c
180 lines (168 loc) · 4.03 KB
/
main_menu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/stat.h>
#include "bbs.h"
#include "lua/lua.h"
#include "lua/lualib.h"
#include "lua/lauxlib.h"
extern struct bbs_config conf;
void main_menu(int socket, struct user_record *user) {
int doquit = 0;
char c;
char prompt[128];
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) {
fprintf(stderr, "Failed to run script: %s\n", 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(socket, "mainmenu");
sprintf(prompt, "\r\n\e[0mTL: %dm :> ", user->timeleft);
s_putstring(socket, prompt);
c = s_getc(socket);
} else {
lua_getglobal(L, "menu");
result = lua_pcall(L, 0, 1, 0);
if (result) {
fprintf(stderr, "Failed to run script: %s\n", 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 'o':
{
automessage_write(socket, user);
}
break;
case 'a':
{
if (conf.text_file_count > 0) {
while(1) {
s_putstring(socket, "\r\n\e[1;32mText Files Collection\r\n");
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
for (i=0;i<conf.text_file_count;i++) {
sprintf(buffer, "\e[1;30m[\e[1;34m%3d\e[1;30m] \e[1;37m%s\r\n", i, conf.text_files[i]->name);
s_putstring(socket, buffer);
}
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
s_putstring(socket, "Enter the number of a text file to display or Q to quit: ");
s_readstring(socket, buffer, 4);
if (tolower(buffer[0]) != 'q') {
i = atoi(buffer);
if (i >= 0 && i < conf.text_file_count) {
s_putstring(socket, "\r\n");
s_displayansi_p(socket, conf.text_files[i]->path);
s_putstring(socket, "Press any key to continue...");
s_getc(socket);
s_putstring(socket, "\r\n");
}
} else {
break;
}
}
} else {
s_putstring(socket, "\r\nSorry, there are no text files to display\r\n");
s_putstring(socket, "Press any key to continue...\r\n");
s_getc(socket);
}
}
break;
case 'c':
{
chat_system(socket, user);
}
break;
case 'l':
{
bbs_list(socket, user);
}
break;
case 'u':
{
list_users(socket, user);
}
break;
case 'b':
{
i = 0;
sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i);
while (stat(buffer, &s) == 0) {
sprintf(buffer, "bulletin%d", i);
s_displayansi(socket, buffer);
sprintf(buffer, "\e[0mPress any key to continue...\r\n");
s_putstring(socket, buffer);
s_getc(socket);
i++;
sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i);
}
}
break;
case '1':
{
display_last10_callers(socket, user);
}
break;
case 'd':
{
doquit = door_menu(socket, user);
}
break;
case 'm':
{
doquit = mail_menu(socket, user);
}
break;
case 'g':
{
s_putstring(socket, "\r\nAre you sure you want to log off? (Y/N)");
c = s_getc(socket);
if (tolower(c) == 'y') {
doquit = 1;
}
}
break;
case 't':
{
doquit = file_menu(socket, user);
}
break;
case 's':
{
settings_menu(socket, user);
}
break;
}
}
if (do_internal_menu == 0) {
lua_close(L);
}
}