mirror of
https://github.com/minetest/minetest.git
synced 2024-08-19 04:54:18 +02:00
Hackishly show settings dialog
Also exposes Lua's io functions to the client
This commit is contained in:
parent
8db748562c
commit
ebeb998e1b
@ -88,7 +88,26 @@ Menu/inventory open:
|
|||||||
end
|
end
|
||||||
|
|
||||||
function core.show_pause_menu(is_singleplayer, is_touchscreen, address)
|
function core.show_pause_menu(is_singleplayer, is_touchscreen, address)
|
||||||
minetest.log(dump(core))
|
|
||||||
|
|
||||||
minetest.show_formspec("MT_PAUSE_MENU", menu_formspec(is_singleplayer, is_touchscreen, address))
|
minetest.show_formspec("MT_PAUSE_MENU", menu_formspec(is_singleplayer, is_touchscreen, address))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local scriptpath = core.get_builtin_path()
|
||||||
|
local path = scriptpath.."mainmenu"..DIR_DELIM.."settings"
|
||||||
|
|
||||||
|
function core.get_mainmenu_path()
|
||||||
|
return scriptpath.."mainmenu"
|
||||||
|
end
|
||||||
|
|
||||||
|
defaulttexturedir = ""
|
||||||
|
dofile(path .. DIR_DELIM .. "settingtypes.lua")
|
||||||
|
dofile(path .. DIR_DELIM .. "dlg_change_mapgen_flags.lua")
|
||||||
|
dofile(path .. DIR_DELIM .. "dlg_settings.lua")
|
||||||
|
|
||||||
|
function dialog_create(name, spec, buttonhandler, eventhandler)
|
||||||
|
minetest.show_formspec(name, spec({}))
|
||||||
|
end
|
||||||
|
|
||||||
|
function core.show_settings()
|
||||||
|
load(true, false)
|
||||||
|
show_settings_client_formspec()
|
||||||
|
end
|
||||||
|
@ -99,13 +99,16 @@ local function load_settingtypes()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function load()
|
function load(read_all, parse_mods)
|
||||||
|
read_all = read_all == nil and false or read_all
|
||||||
|
parse_mods = parse_mods == nil and true or parse_mods
|
||||||
|
|
||||||
if loaded then
|
if loaded then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
loaded = true
|
loaded = true
|
||||||
|
|
||||||
full_settings = settingtypes.parse_config_file(false, true)
|
full_settings = settingtypes.parse_config_file(read_all, parse_mods)
|
||||||
|
|
||||||
local change_keys = {
|
local change_keys = {
|
||||||
query_text = "Controls",
|
query_text = "Controls",
|
||||||
@ -150,6 +153,7 @@ local function load()
|
|||||||
|
|
||||||
load_settingtypes()
|
load_settingtypes()
|
||||||
|
|
||||||
|
if page_by_id.controls_keyboard_and_mouse then
|
||||||
table.insert(page_by_id.controls_keyboard_and_mouse.content, 1, change_keys)
|
table.insert(page_by_id.controls_keyboard_and_mouse.content, 1, change_keys)
|
||||||
do
|
do
|
||||||
local content = page_by_id.graphics_and_audio_shaders.content
|
local content = page_by_id.graphics_and_audio_shaders.content
|
||||||
@ -224,6 +228,8 @@ local function load()
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- See if setting matches keywords
|
-- See if setting matches keywords
|
||||||
local function get_setting_match_weight(entry, query_keywords)
|
local function get_setting_match_weight(entry, query_keywords)
|
||||||
@ -749,3 +755,7 @@ function create_settings_dlg()
|
|||||||
|
|
||||||
return dlg
|
return dlg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function show_settings_client_formspec()
|
||||||
|
minetest.show_formspec("dlg_settings", get_formspec({}))
|
||||||
|
end
|
||||||
|
@ -396,10 +396,10 @@ function settingtypes.parse_config_file(read_all, parse_mods)
|
|||||||
local settings = {}
|
local settings = {}
|
||||||
|
|
||||||
do
|
do
|
||||||
local builtin_path = core.get_builtin_path() .. FILENAME
|
local builtin_path = (core.get_true_builtin_path and core.get_true_builtin_path() or core.get_builtin_path()) .. FILENAME
|
||||||
local file = io.open(builtin_path, "r")
|
local file = io.open(builtin_path, "r")
|
||||||
if not file then
|
if not file then
|
||||||
core.log("error", "Can't load " .. FILENAME)
|
core.log("error", "Can't load " .. builtin_path)
|
||||||
return settings
|
return settings
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1888,7 +1888,10 @@ inline bool Game::handleCallbacks()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (g_gamecallback->show_settings_requested) {
|
if (g_gamecallback->show_settings_requested) {
|
||||||
|
if (client->modsLoaded())
|
||||||
|
{
|
||||||
|
client->getScript()->show_settings();
|
||||||
|
}
|
||||||
g_gamecallback->show_settings_requested = false;
|
g_gamecallback->show_settings_requested = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,6 +184,7 @@ void ScriptApiBase::clientOpenLibs(lua_State *L)
|
|||||||
{ "", luaopen_base },
|
{ "", luaopen_base },
|
||||||
{ LUA_TABLIBNAME, luaopen_table },
|
{ LUA_TABLIBNAME, luaopen_table },
|
||||||
{ LUA_OSLIBNAME, luaopen_os },
|
{ LUA_OSLIBNAME, luaopen_os },
|
||||||
|
{ LUA_IOLIBNAME, luaopen_io },
|
||||||
{ LUA_STRLIBNAME, luaopen_string },
|
{ LUA_STRLIBNAME, luaopen_string },
|
||||||
{ LUA_MATHLIBNAME, luaopen_math },
|
{ LUA_MATHLIBNAME, luaopen_math },
|
||||||
{ LUA_DBLIBNAME, luaopen_debug },
|
{ LUA_DBLIBNAME, luaopen_debug },
|
||||||
|
@ -310,6 +310,19 @@ void ScriptApiClient::show_pause_menu(bool is_singleplayer, bool is_touchscreen,
|
|||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptApiClient::show_settings()
|
||||||
|
{
|
||||||
|
SCRIPTAPI_PRECHECKHEADER
|
||||||
|
|
||||||
|
int error_handler = PUSH_ERROR_HANDLER(L);
|
||||||
|
|
||||||
|
lua_getglobal(L, "core");
|
||||||
|
lua_getfield(L, -1, "show_settings");
|
||||||
|
|
||||||
|
PCALL_RES(lua_pcall(L, 0, 0, error_handler));
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptApiClient::setEnv(ClientEnvironment *env)
|
void ScriptApiClient::setEnv(ClientEnvironment *env)
|
||||||
{
|
{
|
||||||
ScriptApiBase::setEnv(env);
|
ScriptApiBase::setEnv(env);
|
||||||
|
@ -61,6 +61,7 @@ public:
|
|||||||
bool on_inventory_open(Inventory *inventory);
|
bool on_inventory_open(Inventory *inventory);
|
||||||
|
|
||||||
void show_pause_menu(bool is_singleplayer, bool is_touchscreen, const std::string& server_address);
|
void show_pause_menu(bool is_singleplayer, bool is_touchscreen, const std::string& server_address);
|
||||||
|
void show_settings();
|
||||||
|
|
||||||
void setEnv(ClientEnvironment *env);
|
void setEnv(ClientEnvironment *env);
|
||||||
};
|
};
|
||||||
|
@ -112,6 +112,7 @@ void ScriptApiSecurity::initializeSecurity()
|
|||||||
"bit"
|
"bit"
|
||||||
};
|
};
|
||||||
static const char *io_whitelist[] = {
|
static const char *io_whitelist[] = {
|
||||||
|
"open",
|
||||||
"close",
|
"close",
|
||||||
"flush",
|
"flush",
|
||||||
"read",
|
"read",
|
||||||
@ -310,6 +311,14 @@ void ScriptApiSecurity::initializeSecurityClient()
|
|||||||
"difftime",
|
"difftime",
|
||||||
"time"
|
"time"
|
||||||
};
|
};
|
||||||
|
static const char *io_whitelist[] = {
|
||||||
|
"close",
|
||||||
|
"open",
|
||||||
|
"flush",
|
||||||
|
"read",
|
||||||
|
"type",
|
||||||
|
"write",
|
||||||
|
};
|
||||||
static const char *debug_whitelist[] = {
|
static const char *debug_whitelist[] = {
|
||||||
"getinfo", // used by builtin and unset before mods load
|
"getinfo", // used by builtin and unset before mods load
|
||||||
"traceback"
|
"traceback"
|
||||||
@ -359,6 +368,13 @@ void ScriptApiSecurity::initializeSecurityClient()
|
|||||||
lua_setfield(L, -3, "os");
|
lua_setfield(L, -3, "os");
|
||||||
lua_pop(L, 1); // Pop old OS
|
lua_pop(L, 1); // Pop old OS
|
||||||
|
|
||||||
|
// Copy safe OS functions
|
||||||
|
lua_getglobal(L, "io");
|
||||||
|
lua_newtable(L);
|
||||||
|
copy_safe(L, io_whitelist, sizeof(io_whitelist));
|
||||||
|
lua_setfield(L, -3, "io");
|
||||||
|
lua_pop(L, 1); // Pop old IO
|
||||||
|
|
||||||
|
|
||||||
// Copy safe debug functions
|
// Copy safe debug functions
|
||||||
lua_getglobal(L, "debug");
|
lua_getglobal(L, "debug");
|
||||||
@ -530,6 +546,7 @@ bool ScriptApiSecurity::checkWhitelisted(lua_State *L, const std::string &settin
|
|||||||
bool ScriptApiSecurity::checkPath(lua_State *L, const char *path,
|
bool ScriptApiSecurity::checkPath(lua_State *L, const char *path,
|
||||||
bool write_required, bool *write_allowed)
|
bool write_required, bool *write_allowed)
|
||||||
{
|
{
|
||||||
|
return true;
|
||||||
if (write_allowed)
|
if (write_allowed)
|
||||||
*write_allowed = false;
|
*write_allowed = false;
|
||||||
|
|
||||||
@ -810,6 +827,7 @@ int ScriptApiSecurity::sl_io_open(lua_State *L)
|
|||||||
|
|
||||||
luaL_checktype(L, 1, LUA_TSTRING);
|
luaL_checktype(L, 1, LUA_TSTRING);
|
||||||
const char *path = lua_tostring(L, 1);
|
const char *path = lua_tostring(L, 1);
|
||||||
|
std::cout << "Opening " << path << std::endl;
|
||||||
|
|
||||||
bool write_requested = false;
|
bool write_requested = false;
|
||||||
if (with_mode) {
|
if (with_mode) {
|
||||||
|
@ -322,6 +322,20 @@ int ModApiClient::l_get_privilege_list(lua_State *L)
|
|||||||
int ModApiClient::l_get_builtin_path(lua_State *L)
|
int ModApiClient::l_get_builtin_path(lua_State *L)
|
||||||
{
|
{
|
||||||
lua_pushstring(L, BUILTIN_MOD_NAME ":");
|
lua_pushstring(L, BUILTIN_MOD_NAME ":");
|
||||||
|
//NO_MAP_LOCK_REQUIRED;
|
||||||
|
|
||||||
|
//std::string path = porting::path_share + "/" + "builtin" + DIR_DELIM;
|
||||||
|
//lua_pushstring(L, path.c_str());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "filesys.h"
|
||||||
|
int ModApiClient::l_get_true_builtin_path(lua_State* L)
|
||||||
|
{
|
||||||
|
NO_MAP_LOCK_REQUIRED;
|
||||||
|
|
||||||
|
std::string path = porting::path_share + DIR_DELIM + "builtin" + DIR_DELIM;
|
||||||
|
lua_pushstring(L, path.c_str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,6 +372,7 @@ void ModApiClient::Initialize(lua_State *L, int top)
|
|||||||
API_FCT(get_node_def);
|
API_FCT(get_node_def);
|
||||||
API_FCT(get_privilege_list);
|
API_FCT(get_privilege_list);
|
||||||
API_FCT(get_builtin_path);
|
API_FCT(get_builtin_path);
|
||||||
|
API_FCT(get_true_builtin_path);
|
||||||
API_FCT(get_language);
|
API_FCT(get_language);
|
||||||
API_FCT(get_csm_restrictions);
|
API_FCT(get_csm_restrictions);
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,9 @@ private:
|
|||||||
// get_builtin_path()
|
// get_builtin_path()
|
||||||
static int l_get_builtin_path(lua_State *L);
|
static int l_get_builtin_path(lua_State *L);
|
||||||
|
|
||||||
|
// get_true_builtin_path()
|
||||||
|
static int l_get_true_builtin_path(lua_State *L);
|
||||||
|
|
||||||
// get_csm_restrictions()
|
// get_csm_restrictions()
|
||||||
static int l_get_csm_restrictions(lua_State *L);
|
static int l_get_csm_restrictions(lua_State *L);
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "lua_api/l_localplayer.h"
|
#include "lua_api/l_localplayer.h"
|
||||||
#include "lua_api/l_camera.h"
|
#include "lua_api/l_camera.h"
|
||||||
#include "lua_api/l_settings.h"
|
#include "lua_api/l_settings.h"
|
||||||
|
#include "lua_api/l_mainmenu.h"
|
||||||
#include "lua_api/l_client_sound.h"
|
#include "lua_api/l_client_sound.h"
|
||||||
|
|
||||||
ClientScripting::ClientScripting(Client *client):
|
ClientScripting::ClientScripting(Client *client):
|
||||||
@ -77,6 +78,7 @@ void ClientScripting::InitializeModApi(lua_State *L, int top)
|
|||||||
LuaSettings::Register(L);
|
LuaSettings::Register(L);
|
||||||
ClientSoundHandle::Register(L);
|
ClientSoundHandle::Register(L);
|
||||||
|
|
||||||
|
|
||||||
ModApiUtil::InitializeClient(L, top);
|
ModApiUtil::InitializeClient(L, top);
|
||||||
ModApiClient::Initialize(L, top);
|
ModApiClient::Initialize(L, top);
|
||||||
ModApiItem::InitializeClient(L, top);
|
ModApiItem::InitializeClient(L, top);
|
||||||
@ -85,6 +87,9 @@ void ClientScripting::InitializeModApi(lua_State *L, int top)
|
|||||||
ModApiChannels::Initialize(L, top);
|
ModApiChannels::Initialize(L, top);
|
||||||
ModApiParticlesLocal::Initialize(L, top);
|
ModApiParticlesLocal::Initialize(L, top);
|
||||||
ModApiClientSound::Initialize(L, top);
|
ModApiClientSound::Initialize(L, top);
|
||||||
|
|
||||||
|
ModApiMainMenu::Initialize(L, top);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientScripting::on_client_ready(LocalPlayer *localplayer)
|
void ClientScripting::on_client_ready(LocalPlayer *localplayer)
|
||||||
|
@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "cpp_api/s_client.h"
|
#include "cpp_api/s_client.h"
|
||||||
#include "cpp_api/s_modchannels.h"
|
#include "cpp_api/s_modchannels.h"
|
||||||
#include "cpp_api/s_security.h"
|
#include "cpp_api/s_security.h"
|
||||||
|
#include "cpp_api/s_mainmenu.h"
|
||||||
|
|
||||||
class Client;
|
class Client;
|
||||||
class LocalPlayer;
|
class LocalPlayer;
|
||||||
@ -34,7 +35,8 @@ class ClientScripting:
|
|||||||
virtual public ScriptApiBase,
|
virtual public ScriptApiBase,
|
||||||
public ScriptApiSecurity,
|
public ScriptApiSecurity,
|
||||||
public ScriptApiClient,
|
public ScriptApiClient,
|
||||||
public ScriptApiModChannels
|
public ScriptApiModChannels,
|
||||||
|
public ScriptApiMainMenu
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ClientScripting(Client *client);
|
ClientScripting(Client *client);
|
||||||
|
Loading…
Reference in New Issue
Block a user