summaryrefslogtreecommitdiff
path: root/src/network/clientpackethandler.cpp
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2018-12-04 20:37:48 +0100
committerGitHub <noreply@github.com>2018-12-04 20:37:48 +0100
commit3d66622772e66154b7624957a27f9be54c4c7c28 (patch)
tree7ff32e791a39d302f6d1306089b95cb23ebba838 /src/network/clientpackethandler.cpp
parentae8d14b009650f0fe019301123793312406556e4 (diff)
downloadminetest-3d66622772e66154b7624957a27f9be54c4c7c28.tar.gz
minetest-3d66622772e66154b7624957a27f9be54c4c7c28.tar.bz2
minetest-3d66622772e66154b7624957a27f9be54c4c7c28.zip
Send only changed node metadata to clients instead of whole mapblock (#5268)
Includes newer style changes and fixes by est31 Improve the block position de-serialization Add type NodeMetadataMap
Diffstat (limited to 'src/network/clientpackethandler.cpp')
-rw-r--r--src/network/clientpackethandler.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp
index 1be7d4eeb..0dca4aff4 100644
--- a/src/network/clientpackethandler.cpp
+++ b/src/network/clientpackethandler.cpp
@@ -243,6 +243,33 @@ void Client::handleCommand_AddNode(NetworkPacket* pkt)
addNode(p, n, remove_metadata);
}
+
+void Client::handleCommand_NodemetaChanged(NetworkPacket *pkt)
+{
+ if (pkt->getSize() < 1)
+ return;
+
+ std::istringstream is(pkt->readLongString(), std::ios::binary);
+ std::stringstream sstr;
+ decompressZlib(is, sstr);
+
+ NodeMetadataList meta_updates_list(false);
+ meta_updates_list.deSerialize(sstr, m_itemdef, true);
+
+ Map &map = m_env.getMap();
+ for (NodeMetadataMap::const_iterator i = meta_updates_list.begin();
+ i != meta_updates_list.end(); ++i) {
+ v3s16 pos = i->first;
+
+ if (map.isValidPosition(pos) &&
+ map.setNodeMetadata(pos, i->second))
+ continue; // Prevent from deleting metadata
+
+ // Meta couldn't be set, unused metadata
+ delete i->second;
+ }
+}
+
void Client::handleCommand_BlockData(NetworkPacket* pkt)
{
// Ignore too small packet