some more lua functionality

This commit is contained in:
Andrew Pamment 2018-01-30 17:33:57 +10:00
parent 23f73405ae
commit 8935b660ec
4 changed files with 39 additions and 6 deletions

View File

@ -20,7 +20,7 @@ function menu()
-- display tagline
local tLines = readLines("scripts/taglines.txt");
local tLines = readLines(bbs_data_path() .. "taglines.txt");
local rand = math.random(#tLines);

View File

@ -689,7 +689,7 @@ void automessage_display() {
}
void runbbs_real(int socket, char *ip, int ssh) {
char buffer[1024];
char buffer[PATH_MAX];
char password[17];
struct stat s;
@ -878,7 +878,7 @@ tryagain:
user = gUser;
}
}
sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, mynode);
snprintf(buffer, PATH_MAX, "%s/nodeinuse.%d", conf.bbs_path, mynode);
nodefile = fopen(buffer, "w");
if (!nodefile) {
dolog("Error opening nodefile!");
@ -889,15 +889,25 @@ tryagain:
fputs(user->loginname, nodefile);
fclose(nodefile);
sprintf(buffer, "%s/node%d/nodemsg.txt", conf.bbs_path, mynode);
snprintf(buffer, PATH_MAX, "%s/node%d/nodemsg.txt", conf.bbs_path, mynode);
if (stat(buffer, &s) == 0) {
unlink(buffer);
}
snprintf(buffer, PATH_MAX, "%s/node%d/lua/", conf.bbs_path, mynode);
if (stat(buffer, &s) == 0) {
recursive_delete(buffer);
}
#if defined(ENABLE_WWW)
www_expire_old_links();
#endif
// do post-login
dolog("%s logged in, on node %d", user->loginname, mynode);
broadcast("%s logged in, on node %d", user->loginname, mynode);
@ -918,7 +928,7 @@ tryagain:
if (conf.script_path != NULL) {
sprintf(buffer, "%s/login_stanza.lua", conf.script_path);
snprintf(buffer, PATH_MAX, "%s/login_stanza.lua", conf.script_path);
if (stat(buffer, &s) == 0) {
L = luaL_newstate();
luaL_openlibs(L);
@ -980,7 +990,7 @@ void do_logout() {
int do_internal_logout = 1;
if (conf.script_path != NULL) {
sprintf(buffer, "%s/logout_stanza.lua", conf.script_path);
snprintf(buffer, PATH_MAX, "%s/logout_stanza.lua", conf.script_path);
if (stat(buffer, &s) == 0) {
L = luaL_newstate();
luaL_openlibs(L);

View File

@ -336,6 +336,20 @@ int l_readMessage(lua_State *L) {
return 1;
}
int l_dataPath(lua_State *L) {
char buffer[PATH_MAX];
struct stat s;
snprintf(buffer, PATH_MAX, "%s/data/", conf.script_path);
if (stat(buffer, &s) != 0) {
mkdir(buffer, 0755);
}
lua_pushstring(L, buffer);
return 1;
}
int l_tempPath(lua_State *L) {
char buffer[PATH_MAX];
struct stat s;
@ -350,6 +364,11 @@ int l_tempPath(lua_State *L) {
return 1;
}
int l_userSecurity(lua_State *L) {
lua_pushnumber(L, gUser->sec_level);
return 1;
}
int l_postMessage(lua_State *L) {
int confr = lua_tointeger(L, 1);
int area = lua_tointeger(L, 2);
@ -576,6 +595,10 @@ void lua_push_cfunctions(lua_State *L) {
lua_setglobal(L, "bbs_temp_path");
lua_pushcfunction(L, l_postMessage);
lua_setglobal(L, "bbs_post_message");
lua_pushcfunction(L, l_dataPath);
lua_setglobal(L, "bbs_data_path");
lua_pushcfunction(L, l_userSecurity);
lua_setglobal(L, "bbs_user_security");
}
void do_lua_script(char *script) {