aboutsummaryrefslogtreecommitdiff
path: root/src/network/clientpackethandler.cpp
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2018-10-10 20:48:58 +0200
committerGitHub <noreply@github.com>2018-10-10 20:48:58 +0200
commit0a5e77132ae8c495c50cfc58bbe4ce1bfcd377e3 (patch)
treed60c7186893663e2556d6d9efc46c14fd4520b0f /src/network/clientpackethandler.cpp
parentd6f2a1c4b8ab13cee92e2041b3410fe3548e88e6 (diff)
downloaddragonfireclient-0a5e77132ae8c495c50cfc58bbe4ce1bfcd377e3.tar.xz
Add core.remove_detached_inventory (#7684)
Breaks backwards compatibility for good Bump protocol version
Diffstat (limited to 'src/network/clientpackethandler.cpp')
-rw-r--r--src/network/clientpackethandler.cpp29
1 files changed, 20 insertions, 9 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);
}