1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Add minetest.get_game_info and allow reading game.conf (#12989)

Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
Jude Melton-Houghton 2022-11-28 07:21:43 -05:00 committed by GitHub
parent 3fd5bff128
commit d0a118f5b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 0 deletions

View file

@ -579,6 +579,17 @@ bool ScriptApiSecurity::checkPath(lua_State *L, const char *path,
}
lua_pop(L, 1); // Pop mod name
// Allow read-only access to game directory
if (!write_required) {
const SubgameSpec *game_spec = gamedef->getGameSpec();
if (game_spec && !game_spec->path.empty()) {
str = fs::AbsolutePath(game_spec->path);
if (!str.empty() && fs::PathStartsWith(abs_path, str)) {
return true;
}
}
}
// Allow read-only access to all mod directories
if (!write_required) {
const std::vector<ModSpec> &mods = gamedef->getMods();

View file

@ -424,6 +424,20 @@ int ModApiServer::l_get_modnames(lua_State *L)
return 1;
}
// get_game_info()
int ModApiServer::l_get_game_info(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
const SubgameSpec *game_spec = getGameDef(L)->getGameSpec();
assert(game_spec);
lua_newtable(L);
setstringfield(L, -1, "id", game_spec->id);
setstringfield(L, -1, "title", game_spec->title);
setstringfield(L, -1, "author", game_spec->author);
setstringfield(L, -1, "path", game_spec->path);
return 1;
}
// get_worldpath()
int ModApiServer::l_get_worldpath(lua_State *L)
{
@ -608,6 +622,7 @@ void ModApiServer::Initialize(lua_State *L, int top)
API_FCT(get_current_modname);
API_FCT(get_modpath);
API_FCT(get_modnames);
API_FCT(get_game_info);
API_FCT(print);
@ -643,4 +658,5 @@ void ModApiServer::InitializeAsync(lua_State *L, int top)
API_FCT(get_current_modname);
API_FCT(get_modpath);
API_FCT(get_modnames);
API_FCT(get_game_info);
}

View file

@ -52,6 +52,9 @@ private:
// the returned list is sorted alphabetically for you
static int l_get_modnames(lua_State *L);
// get_game_info()
static int l_get_game_info(lua_State *L);
// print(text)
static int l_print(lua_State *L);