mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
Dynamic_Add_Media v2 (#11550)
This commit is contained in:
parent
bcb6565483
commit
bbfae0cc67
19 changed files with 796 additions and 246 deletions
|
@ -453,29 +453,37 @@ int ModApiServer::l_sound_fade(lua_State *L)
|
|||
}
|
||||
|
||||
// dynamic_add_media(filepath)
|
||||
int ModApiServer::l_dynamic_add_media_raw(lua_State *L)
|
||||
int ModApiServer::l_dynamic_add_media(lua_State *L)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
|
||||
if (!getEnv(L))
|
||||
throw LuaError("Dynamic media cannot be added before server has started up");
|
||||
Server *server = getServer(L);
|
||||
|
||||
std::string filepath;
|
||||
std::string to_player;
|
||||
bool ephemeral = false;
|
||||
|
||||
if (lua_istable(L, 1)) {
|
||||
getstringfield(L, 1, "filepath", filepath);
|
||||
getstringfield(L, 1, "to_player", to_player);
|
||||
getboolfield(L, 1, "ephemeral", ephemeral);
|
||||
} else {
|
||||
filepath = readParam<std::string>(L, 1);
|
||||
}
|
||||
if (filepath.empty())
|
||||
luaL_typerror(L, 1, "non-empty string");
|
||||
luaL_checktype(L, 2, LUA_TFUNCTION);
|
||||
|
||||
std::string filepath = readParam<std::string>(L, 1);
|
||||
CHECK_SECURE_PATH(L, filepath.c_str(), false);
|
||||
|
||||
std::vector<RemotePlayer*> sent_to;
|
||||
bool ok = getServer(L)->dynamicAddMedia(filepath, sent_to);
|
||||
if (ok) {
|
||||
// (see wrapper code in builtin)
|
||||
lua_createtable(L, sent_to.size(), 0);
|
||||
int i = 0;
|
||||
for (RemotePlayer *player : sent_to) {
|
||||
lua_pushstring(L, player->getName());
|
||||
lua_rawseti(L, -2, ++i);
|
||||
}
|
||||
} else {
|
||||
lua_pushboolean(L, false);
|
||||
}
|
||||
u32 token = server->getScriptIface()->allocateDynamicMediaCallback(2);
|
||||
|
||||
bool ok = server->dynamicAddMedia(filepath, token, to_player, ephemeral);
|
||||
if (!ok)
|
||||
server->getScriptIface()->freeDynamicMediaCallback(token);
|
||||
lua_pushboolean(L, ok);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -519,7 +527,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_raw);
|
||||
API_FCT(dynamic_add_media);
|
||||
|
||||
API_FCT(get_player_information);
|
||||
API_FCT(get_player_privs);
|
||||
|
|
|
@ -71,7 +71,7 @@ private:
|
|||
static int l_sound_fade(lua_State *L);
|
||||
|
||||
// dynamic_add_media(filepath)
|
||||
static int l_dynamic_add_media_raw(lua_State *L);
|
||||
static int l_dynamic_add_media(lua_State *L);
|
||||
|
||||
// get_player_privs(name, text)
|
||||
static int l_get_player_privs(lua_State *L);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue