diff options
author | SmallJoker <SmallJoker@users.noreply.github.com> | 2018-12-04 20:37:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-04 20:37:48 +0100 |
commit | 3d66622772e66154b7624957a27f9be54c4c7c28 (patch) | |
tree | 7ff32e791a39d302f6d1306089b95cb23ebba838 /src/network | |
parent | ae8d14b009650f0fe019301123793312406556e4 (diff) | |
download | minetest-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')
-rw-r--r-- | src/network/clientopcodes.cpp | 2 | ||||
-rw-r--r-- | src/network/clientpackethandler.cpp | 27 | ||||
-rw-r--r-- | src/network/networkprotocol.h | 11 | ||||
-rw-r--r-- | src/network/serveropcodes.cpp | 6 | ||||
-rw-r--r-- | src/network/serverpackethandler.cpp | 4 |
5 files changed, 43 insertions, 7 deletions
diff --git a/src/network/clientopcodes.cpp b/src/network/clientopcodes.cpp index 923a92d32..7f3ab50ed 100644 --- a/src/network/clientopcodes.cpp +++ b/src/network/clientopcodes.cpp @@ -113,7 +113,7 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] = { "TOCLIENT_UPDATE_PLAYER_LIST", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_UpdatePlayerList }, // 0x56 { "TOCLIENT_MODCHANNEL_MSG", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ModChannelMsg }, // 0x57 { "TOCLIENT_MODCHANNEL_SIGNAL", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ModChannelSignal }, // 0x58 - null_command_handler, + { "TOCLIENT_NODEMETA_CHANGED", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_NodemetaChanged }, // 0x59 null_command_handler, null_command_handler, null_command_handler, 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 diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index 855afc638..12a91e647 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -190,6 +190,7 @@ with this program; if not, write to the Free Software Foundation, Inc., Add TOCLIENT_FORMSPEC_PREPEND PROTOCOL VERSION 37: Redo detached inventory sending + Add TOCLIENT_NODEMETA_CHANGED */ #define LATEST_PROTOCOL_VERSION 37 @@ -638,13 +639,19 @@ enum ToClientCommand std::string channel name u16 message length std::string message - */ + */ + TOCLIENT_MODCHANNEL_SIGNAL = 0x58, /* u8 signal id u16 channel name length std::string channel name - */ + */ + + TOCLIENT_NODEMETA_CHANGED = 0x59, + /* + serialized and compressed node metadata + */ TOCLIENT_SRP_BYTES_S_B = 0x60, /* diff --git a/src/network/serveropcodes.cpp b/src/network/serveropcodes.cpp index e4e313611..013b549c6 100644 --- a/src/network/serveropcodes.cpp +++ b/src/network/serveropcodes.cpp @@ -200,9 +200,9 @@ const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] = { "TOCLIENT_CLOUD_PARAMS", 0, true }, // 0x54 { "TOCLIENT_FADE_SOUND", 0, true }, // 0x55 { "TOCLIENT_UPDATE_PLAYER_LIST", 0, true }, // 0x56 - { "TOCLIENT_MODCHANNEL_MSG", 0, true}, // 0x57 - { "TOCLIENT_MODCHANNEL_SIGNAL", 0, true}, // 0x58 - null_command_factory, + { "TOCLIENT_MODCHANNEL_MSG", 0, true }, // 0x57 + { "TOCLIENT_MODCHANNEL_SIGNAL", 0, true }, // 0x58 + { "TOCLIENT_NODEMETA_CHANGED", 0, true }, // 0x59 null_command_factory, null_command_factory, null_command_factory, diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index 8299ad002..329b38765 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -609,7 +609,9 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt) ma->to_inv.applyCurrentPlayer(player->getName()); setInventoryModified(ma->from_inv, false); - setInventoryModified(ma->to_inv, false); + if (ma->from_inv != ma->to_inv) { + setInventoryModified(ma->to_inv, false); + } bool from_inv_is_current_player = (ma->from_inv.type == InventoryLocation::PLAYER) && |