aboutsummaryrefslogtreecommitdiff
path: root/src/client/client.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2021-09-09 16:51:35 +0200
committerGitHub <noreply@github.com>2021-09-09 16:51:35 +0200
commitbbfae0cc673d3abdc21224c53e09b209ee4688a2 (patch)
treee1afb8f64570b212d3db53a975b59fff5af67ad8 /src/client/client.cpp
parentbcb65654836caffa670a611ff7c79b0705a40c3c (diff)
downloadhax-minetest-server-bbfae0cc673d3abdc21224c53e09b209ee4688a2.tar.gz
hax-minetest-server-bbfae0cc673d3abdc21224c53e09b209ee4688a2.zip
Dynamic_Add_Media v2 (#11550)
Diffstat (limited to 'src/client/client.cpp')
-rw-r--r--src/client/client.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp
index 3c5559fca..13ff22e8e 100644
--- a/src/client/client.cpp
+++ b/src/client/client.cpp
@@ -555,6 +555,29 @@ void Client::step(float dtime)
m_media_downloader = NULL;
}
}
+ {
+ // Acknowledge dynamic media downloads to server
+ std::vector<u32> done;
+ for (auto it = m_pending_media_downloads.begin();
+ it != m_pending_media_downloads.end();) {
+ assert(it->second->isStarted());
+ it->second->step(this);
+ if (it->second->isDone()) {
+ done.emplace_back(it->first);
+
+ it = m_pending_media_downloads.erase(it);
+ } else {
+ it++;
+ }
+
+ if (done.size() == 255) { // maximum in one packet
+ sendHaveMedia(done);
+ done.clear();
+ }
+ }
+ if (!done.empty())
+ sendHaveMedia(done);
+ }
/*
If the server didn't update the inventory in a while, revert
@@ -770,7 +793,8 @@ void Client::request_media(const std::vector<std::string> &file_requests)
Send(&pkt);
infostream << "Client: Sending media request list to server ("
- << file_requests.size() << " files. packet size)" << std::endl;
+ << file_requests.size() << " files, packet size "
+ << pkt.getSize() << ")" << std::endl;
}
void Client::initLocalMapSaving(const Address &address,
@@ -1295,6 +1319,19 @@ void Client::sendPlayerPos()
Send(&pkt);
}
+void Client::sendHaveMedia(const std::vector<u32> &tokens)
+{
+ NetworkPacket pkt(TOSERVER_HAVE_MEDIA, 1 + tokens.size() * 4);
+
+ sanity_check(tokens.size() < 256);
+
+ pkt << static_cast<u8>(tokens.size());
+ for (u32 token : tokens)
+ pkt << token;
+
+ Send(&pkt);
+}
+
void Client::removeNode(v3s16 p)
{
std::map<v3s16, MapBlock*> modified_blocks;