1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

Add core.remove_detached_inventory (#7684)

Breaks backwards compatibility for good
Bump protocol version
This commit is contained in:
SmallJoker 2018-10-10 20:48:58 +02:00 committed by GitHub
parent d6f2a1c4b8
commit 0a5e77132a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 101 additions and 35 deletions

View file

@ -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);
}