Add Lua scripting to log out stanza

This commit is contained in:
Andrew Pamment 2016-09-05 14:05:17 +10:00
parent 146924694c
commit 0088ce8a71
7 changed files with 74 additions and 24 deletions

54
bbs.c
View File

@ -717,11 +717,63 @@ void runbbs_real(int socket, char *ip, int ssh) {
// main menu // main menu
main_menu(user); main_menu(user);
s_displayansi("goodbye");
dolog("%s is logging out, on node %d", user->loginname, mynode); dolog("%s is logging out, on node %d", user->loginname, mynode);
disconnect("Log out"); disconnect("Log out");
} }
int do_logout() {
char buffer[256];
struct stat s;
lua_State *L;
int ret = 0;
char c;
int result;
int do_internal_logout = 1;
if (conf.script_path != NULL) {
sprintf(buffer, "%s/logout_stanza.lua", conf.script_path);
if (stat(buffer, &s) == 0) {
L = luaL_newstate();
luaL_openlibs(L);
lua_push_cfunctions(L);
luaL_loadfile(L, buffer);
result = lua_pcall(L, 0, 1, 0);
if (result) {
dolog("Failed to run script: %s", lua_tostring(L, -1));
do_internal_logout = 1;
lua_close(L);
} else {
do_internal_logout = 0;
}
}
}
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);
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) { void runbbs(int socket, char *ip) {
runbbs_real(socket, ip, 0); runbbs_real(socket, ip, 0);
} }

1
bbs.h
View File

@ -183,6 +183,7 @@ extern char s_getc();
extern void disconnect(char *calledby); extern void disconnect(char *calledby);
extern void display_info(); extern void display_info();
extern void display_last10_callers(struct user_record *user); extern void display_last10_callers(struct user_record *user);
extern int do_logout();
extern void gen_salt(char **s); extern void gen_salt(char **s);
extern char *hash_sha256(char *pass, char *salt); extern char *hash_sha256(char *pass, char *salt);

View File

@ -305,12 +305,8 @@ int door_menu(struct user_record *user) {
break; break;
case 'g': case 'g':
{ {
s_printf(get_string(53)); doquit = do_logout();
c = s_getc(); dodoors = doquit;
if (tolower(c) == 'y') {
doquit = 1;
dodoors = 1;
}
} }
break; break;
default: default:

View File

@ -843,12 +843,8 @@ int file_menu(struct user_record *user) {
break; break;
case 'g': case 'g':
{ {
s_printf(get_string(53)); doquit = do_logout();
c = s_getc(); dofiles = doquit;
if (tolower(c) == 'y') {
dofiles = 1;
doquit = 1;
}
} }
break; break;
} }

View File

@ -1774,12 +1774,8 @@ int mail_menu(struct user_record *user) {
break; break;
case 'g': case 'g':
{ {
s_printf(get_string(53)); doquit = do_logout();
c = s_getc(); domail = doquit;
if (tolower(c) == 'y') {
domail = 1;
doquit = 1;
}
} }
break; break;
case 'e': case 'e':

View File

@ -151,11 +151,7 @@ void main_menu(struct user_record *user) {
break; break;
case 'g': case 'g':
{ {
s_printf(get_string(53)); doquit = do_logout();
c = s_getc();
if (tolower(c) == 'y') {
doquit = 1;
}
} }
break; break;
case 't': case 't':

View File

@ -0,0 +1,13 @@
function logout()
bbs_write_string("\r\n\r\nAre you sure you want to logoff (Y/N) ? ");
cmd = bbs_read_char();
if (cmd == 10) then
return 0;
end
bbs_display_ansi("goodbye");
return 1;
end