summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2020-06-13 19:03:26 +0200
committerGitHub <noreply@github.com>2020-06-13 19:03:26 +0200
commit2424dfe007e451bb02f87884c2b272cf307d6e7c (patch)
treede43d4ab42126b0533bf5955de3ce68f97f53420 /src/script
parent982a030f330bd4f4953ed7d4a7f88286f6fd645d (diff)
downloadminetest-2424dfe007e451bb02f87884c2b272cf307d6e7c.tar.gz
minetest-2424dfe007e451bb02f87884c2b272cf307d6e7c.tar.bz2
minetest-2424dfe007e451bb02f87884c2b272cf307d6e7c.zip
Server pushing media at runtime (#9961)
Diffstat (limited to 'src/script')
-rw-r--r--src/script/lua_api/l_server.cpp22
-rw-r--r--src/script/lua_api/l_server.h3
2 files changed, 22 insertions, 3 deletions
diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp
index b6754938e..6f934bb9d 100644
--- a/src/script/lua_api/l_server.cpp
+++ b/src/script/lua_api/l_server.cpp
@@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "common/c_converter.h"
#include "common/c_content.h"
#include "cpp_api/s_base.h"
+#include "cpp_api/s_security.h"
#include "server.h"
#include "environment.h"
#include "remoteplayer.h"
@@ -412,9 +413,6 @@ int ModApiServer::l_get_modnames(lua_State *L)
std::vector<std::string> modlist;
getServer(L)->getModNames(modlist);
- // Take unsorted items from mods_unsorted and sort them into
- // mods_sorted; not great performance but the number of mods on a
- // server will likely be small.
std::sort(modlist.begin(), modlist.end());
// Package them up for Lua
@@ -474,6 +472,23 @@ int ModApiServer::l_sound_fade(lua_State *L)
return 0;
}
+// dynamic_add_media(filepath)
+int ModApiServer::l_dynamic_add_media(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+
+ // Reject adding media before the server has started up
+ if (!getEnv(L))
+ throw LuaError("Dynamic media cannot be added before server has started up");
+
+ std::string filepath = readParam<std::string>(L, 1);
+ CHECK_SECURE_PATH(L, filepath.c_str(), false);
+
+ bool ok = getServer(L)->dynamicAddMedia(filepath);
+ lua_pushboolean(L, ok);
+ return 1;
+}
+
// is_singleplayer()
int ModApiServer::l_is_singleplayer(lua_State *L)
{
@@ -538,6 +553,7 @@ void ModApiServer::Initialize(lua_State *L, int top)
API_FCT(sound_play);
API_FCT(sound_stop);
API_FCT(sound_fade);
+ API_FCT(dynamic_add_media);
API_FCT(get_player_information);
API_FCT(get_player_privs);
diff --git a/src/script/lua_api/l_server.h b/src/script/lua_api/l_server.h
index 3aa1785a2..938bfa8ef 100644
--- a/src/script/lua_api/l_server.h
+++ b/src/script/lua_api/l_server.h
@@ -70,6 +70,9 @@ private:
// sound_fade(handle, step, gain)
static int l_sound_fade(lua_State *L);
+ // dynamic_add_media(filepath)
+ static int l_dynamic_add_media(lua_State *L);
+
// get_player_privs(name, text)
static int l_get_player_privs(lua_State *L);