Fix sqlite3 map shutdown fails due to missing to finalize list statement
[oweals/minetest.git] / src / inventory.cpp
index 7051b611fe014f4c28996a35a7645b7b133b322d..4b1beb230c6a90fbe9dd71b463a433fb6d5638be 100644 (file)
@@ -175,7 +175,7 @@ void ItemStack::deSerialize(std::istream &is, IItemDefManager *itemdef)
                // Convert old materials
                if(material <= 0xff)
                        material = content_translate_from_19_to_internal(material);
-               if(material > MAX_CONTENT)
+               if(material > 0xfff)
                        throw SerializationError("Too large material number");
                // Convert old id to name
                NameIdMapping legacy_nimap;
@@ -194,7 +194,7 @@ void ItemStack::deSerialize(std::istream &is, IItemDefManager *itemdef)
                is>>material;
                u16 materialcount;
                is>>materialcount;
-               if(material > MAX_CONTENT)
+               if(material > 0xfff)
                        throw SerializationError("Too large material number");
                // Convert old id to name
                NameIdMapping legacy_nimap;
@@ -562,6 +562,26 @@ InventoryList & InventoryList::operator = (const InventoryList &other)
        return *this;
 }
 
+bool InventoryList::operator == (const InventoryList &other) const
+{
+       if(m_size != other.m_size)
+               return false;
+       if(m_width != other.m_width)
+               return false;
+       if(m_name != other.m_name)
+               return false;
+       for(u32 i=0; i<m_items.size(); i++)
+       {
+               ItemStack s1 = m_items[i];
+               ItemStack s2 = other.m_items[i];
+               if(s1.name != s2.name || s1.wear!= s2.wear || s1.count != s2.count ||
+                               s1.metadata != s2.metadata)
+                       return false;
+       }
+
+       return true;
+}
+
 const std::string &InventoryList::getName() const
 {
        return m_name;
@@ -855,6 +875,19 @@ Inventory & Inventory::operator = (const Inventory &other)
        return *this;
 }
 
+bool Inventory::operator == (const Inventory &other) const
+{
+       if(m_lists.size() != other.m_lists.size())
+               return false;
+
+       for(u32 i=0; i<m_lists.size(); i++)
+       {
+               if(*m_lists[i] != *other.m_lists[i])
+                       return false;
+       }
+       return true;
+}
+
 void Inventory::serialize(std::ostream &os) const
 {
        for(u32 i=0; i<m_lists.size(); i++)
@@ -903,6 +936,10 @@ void Inventory::deSerialize(std::istream &is)
 
                        m_lists.push_back(list);
                }
+               else
+               {
+                       throw SerializationError("invalid inventory specifier");
+               }
        }
 }
 
@@ -920,6 +957,9 @@ InventoryList * Inventory::addList(const std::string &name, u32 size)
        }
        else
        {
+               //don't create list with invalid name
+               if (name.find(" ") != std::string::npos) return NULL;
+
                InventoryList *list = new InventoryList(name, size, m_itemdef);
                m_lists.push_back(list);
                return list;