summaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_security.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2019-11-08 20:01:47 +0100
committersfan5 <sfan5@live.de>2019-11-09 16:08:38 +0100
commit82a2e02323615473fc3039508b4c4529591e27d9 (patch)
tree3d66f3bf530df8403cdf77199d15a1a9a3fea384 /src/script/cpp_api/s_security.cpp
parent5ab546f99bf3f438a8d19a3582798b5ab98476d6 (diff)
downloadminetest-82a2e02323615473fc3039508b4c4529591e27d9.tar.gz
minetest-82a2e02323615473fc3039508b4c4529591e27d9.tar.bz2
minetest-82a2e02323615473fc3039508b4c4529591e27d9.zip
Load client mods into memory before execution.
Preperation for server-sent CSM which will eventually need this.
Diffstat (limited to 'src/script/cpp_api/s_security.cpp')
-rw-r--r--src/script/cpp_api/s_security.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/script/cpp_api/s_security.cpp b/src/script/cpp_api/s_security.cpp
index fd68a2cb0..b5abcfb5d 100644
--- a/src/script/cpp_api/s_security.cpp
+++ b/src/script/cpp_api/s_security.cpp
@@ -627,16 +627,19 @@ int ScriptApiSecurity::sl_g_loadfile(lua_State *L)
ScriptApiBase *script = (ScriptApiBase *) lua_touserdata(L, -1);
lua_pop(L, 1);
+ // Client implementation
if (script->getType() == ScriptingType::Client) {
- std::string display_path = readParam<std::string>(L, 1);
- const std::string *path = script->getClient()->getModFile(display_path);
- if (!path) {
- std::string error_msg = "Coudln't find script called:" + display_path;
+ std::string path = readParam<std::string>(L, 1);
+ const std::string *contents = script->getClient()->getModFile(path);
+ if (!contents) {
+ std::string error_msg = "Coudln't find script called: " + path;
lua_pushnil(L);
lua_pushstring(L, error_msg.c_str());
return 2;
}
- if (!safeLoadFile(L, path->c_str(), display_path.c_str())) {
+
+ std::string chunk_name = "@" + path;
+ if (!safeLoadString(L, *contents, chunk_name.c_str())) {
lua_pushnil(L);
lua_insert(L, -2);
return 2;
@@ -644,6 +647,8 @@ int ScriptApiSecurity::sl_g_loadfile(lua_State *L)
return 1;
}
#endif
+
+ // Server implementation
const char *path = NULL;
if (lua_isstring(L, 1)) {
path = lua_tostring(L, 1);