aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/script/lua_api/l_server.cpp21
-rw-r--r--src/script/lua_api/l_server.h2
-rw-r--r--src/server.cpp20
-rw-r--r--src/server.h2
4 files changed, 33 insertions, 12 deletions
diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp
index 0ae699c9f..78cf4b403 100644
--- a/src/script/lua_api/l_server.cpp
+++ b/src/script/lua_api/l_server.cpp
@@ -452,19 +452,30 @@ int ModApiServer::l_sound_fade(lua_State *L)
}
// dynamic_add_media(filepath)
-int ModApiServer::l_dynamic_add_media(lua_State *L)
+int ModApiServer::l_dynamic_add_media_raw(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);
+ 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);
+ }
+
return 1;
}
@@ -532,7 +543,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(dynamic_add_media_raw);
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 938bfa8ef..2df180b17 100644
--- a/src/script/lua_api/l_server.h
+++ b/src/script/lua_api/l_server.h
@@ -71,7 +71,7 @@ private:
static int l_sound_fade(lua_State *L);
// dynamic_add_media(filepath)
- static int l_dynamic_add_media(lua_State *L);
+ static int l_dynamic_add_media_raw(lua_State *L);
// get_player_privs(name, text)
static int l_get_player_privs(lua_State *L);
diff --git a/src/server.cpp b/src/server.cpp
index 8a86dbd82..90496129e 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -3465,7 +3465,8 @@ void Server::deleteParticleSpawner(const std::string &playername, u32 id)
SendDeleteParticleSpawner(peer_id, id);
}
-bool Server::dynamicAddMedia(const std::string &filepath)
+bool Server::dynamicAddMedia(const std::string &filepath,
+ std::vector<RemotePlayer*> &sent_to)
{
std::string filename = fs::GetFilenameFromPath(filepath.c_str());
if (m_media.find(filename) != m_media.end()) {
@@ -3485,9 +3486,17 @@ bool Server::dynamicAddMedia(const std::string &filepath)
pkt << raw_hash << filename << (bool) true;
pkt.putLongString(filedata);
- auto client_ids = m_clients.getClientIDs(CS_DefinitionsSent);
- for (session_t client_id : client_ids) {
+ m_clients.lock();
+ for (auto &pair : m_clients.getClientList()) {
+ if (pair.second->getState() < CS_DefinitionsSent)
+ continue;
+ if (pair.second->net_proto_version < 39)
+ continue;
+
+ if (auto player = m_env->getPlayer(pair.second->peer_id))
+ sent_to.emplace_back(player);
/*
+ FIXME: this is a very awful hack
The network layer only guarantees ordered delivery inside a channel.
Since the very next packet could be one that uses the media, we have
to push the media over ALL channels to ensure it is processed before
@@ -3496,9 +3505,10 @@ bool Server::dynamicAddMedia(const std::string &filepath)
- channel 1 (HUD)
- channel 0 (everything else: e.g. play_sound, object messages)
*/
- m_clients.send(client_id, 1, &pkt, true);
- m_clients.send(client_id, 0, &pkt, true);
+ m_clients.send(pair.second->peer_id, 1, &pkt, true);
+ m_clients.send(pair.second->peer_id, 0, &pkt, true);
}
+ m_clients.unlock();
return true;
}
diff --git a/src/server.h b/src/server.h
index 7071d2d07..5c143a657 100644
--- a/src/server.h
+++ b/src/server.h
@@ -257,7 +257,7 @@ public:
void deleteParticleSpawner(const std::string &playername, u32 id);
- bool dynamicAddMedia(const std::string &filepath);
+ bool dynamicAddMedia(const std::string &filepath, std::vector<RemotePlayer*> &sent_to);
ServerInventoryManager *getInventoryMgr() const { return m_inventory_mgr.get(); }
void sendDetachedInventory(Inventory *inventory, const std::string &name, session_t peer_id);