diff options
author | sfan5 <sfan5@live.de> | 2021-01-30 14:35:34 +0100 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2021-02-01 23:00:13 +0100 |
commit | 40ad9767531beb6cf2e8bd918c9c9ed5f2749320 (patch) | |
tree | 957666f5b93f3e02de412813f0a0a6393b325333 /src/server.cpp | |
parent | a01a02f7a1ec915c207632085cd5f24eab28da17 (diff) | |
download | hax-minetest-server-40ad9767531beb6cf2e8bd918c9c9ed5f2749320.tar.gz hax-minetest-server-40ad9767531beb6cf2e8bd918c9c9ed5f2749320.zip |
Revise dynamic_add_media API to better accomodate future changes
Diffstat (limited to '')
-rw-r--r-- | src/server.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
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; } |