summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/clientpackethandler.cpp29
-rw-r--r--src/network/networkprotocol.h8
2 files changed, 25 insertions, 12 deletions
diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp
index cbd0d6a57..5a62fec3d 100644
--- a/src/network/clientpackethandler.cpp
+++ b/src/network/clientpackethandler.cpp
@@ -843,21 +843,32 @@ void Client::handleCommand_InventoryFormSpec(NetworkPacket* pkt)
void Client::handleCommand_DetachedInventory(NetworkPacket* pkt)
{
- std::string datastring(pkt->getString(0), pkt->getSize());
- std::istringstream is(datastring, std::ios_base::binary);
-
- std::string name = deSerializeString(is);
+ std::string name;
+ bool keep_inv = true;
+ *pkt >> name >> keep_inv;
infostream << "Client: Detached inventory update: \"" << name
- << "\"" << std::endl;
+ << "\", mode=" << (keep_inv ? "update" : "remove") << std::endl;
- Inventory *inv = NULL;
- if (m_detached_inventories.count(name) > 0)
- inv = m_detached_inventories[name];
- else {
+ const auto &inv_it = m_detached_inventories.find(name);
+ if (!keep_inv) {
+ if (inv_it != m_detached_inventories.end()) {
+ delete inv_it->second;
+ m_detached_inventories.erase(inv_it);
+ }
+ return;
+ }
+ Inventory *inv = nullptr;
+ if (inv_it == m_detached_inventories.end()) {
inv = new Inventory(m_itemdef);
m_detached_inventories[name] = inv;
+ } else {
+ inv = inv_it->second;
}
+
+ std::string contents;
+ *pkt >> contents;
+ std::istringstream is(contents, std::ios::binary);
inv->deSerialize(is);
}
diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h
index 4e896602b..855afc638 100644
--- a/src/network/networkprotocol.h
+++ b/src/network/networkprotocol.h
@@ -188,19 +188,21 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Nodebox version 5
Add disconnected nodeboxes
Add TOCLIENT_FORMSPEC_PREPEND
+ PROTOCOL VERSION 37:
+ Redo detached inventory sending
*/
-#define LATEST_PROTOCOL_VERSION 36
+#define LATEST_PROTOCOL_VERSION 37
#define LATEST_PROTOCOL_VERSION_STRING TOSTRING(LATEST_PROTOCOL_VERSION)
// Server's supported network protocol range
-#define SERVER_PROTOCOL_VERSION_MIN 36
+#define SERVER_PROTOCOL_VERSION_MIN 37
#define SERVER_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION
// Client's supported network protocol range
// The minimal version depends on whether
// send_pre_v25_init is enabled or not
-#define CLIENT_PROTOCOL_VERSION_MIN 36
+#define CLIENT_PROTOCOL_VERSION_MIN 37
#define CLIENT_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION
// Constant that differentiates the protocol from random data and other protocols