X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fstaticobject.cpp;h=86e455b9f65093247d5aaf09609733657e6d1db0;hb=2f6393f49d5ebf21abfaa7bff876b8c0cf4ca191;hp=973257fcfa1482853ebec4051224780a37da38e1;hpb=a0566270d9fa075afa36a7e3e68c690b1b23ba90;p=dragonfireclient.git diff --git a/src/staticobject.cpp b/src/staticobject.cpp index 973257fcf..86e455b9f 100644 --- a/src/staticobject.cpp +++ b/src/staticobject.cpp @@ -19,71 +19,78 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "staticobject.h" #include "util/serialize.h" +#include "server/serveractiveobject.h" + +StaticObject::StaticObject(const ServerActiveObject *s_obj, const v3f &pos_): + type(s_obj->getType()), + pos(pos_) +{ + s_obj->getStaticData(&data); +} void StaticObject::serialize(std::ostream &os) { - char buf[12]; // type - buf[0] = type; - os.write(buf, 1); + writeU8(os, type); // pos - writeV3S32((u8*)buf, v3s32(pos.X*1000,pos.Y*1000,pos.Z*1000)); - os.write(buf, 12); + writeV3F1000(os, pos); // data - os<::iterator - i = m_stored.begin(); - i != m_stored.end(); ++i) - { - StaticObject &s_obj = *i; + size_t count = m_stored.size() + m_active.size(); + // Make sure it fits into u16, else it would get truncated and cause e.g. + // issue #2610 (Invalid block data in database: unsupported NameIdMapping version). + if (count > U16_MAX) { + errorstream << "StaticObjectList::serialize(): " + << "too many objects (" << count << ") in list, " + << "not writing them to disk." << std::endl; + writeU16(os, 0); // count = 0 + return; + } + writeU16(os, count); + + for (StaticObject &s_obj : m_stored) { s_obj.serialize(os); } - for(std::map::iterator - i = m_active.begin(); - i != m_active.end(); ++i) - { - StaticObject s_obj = i->second; + + for (auto &i : m_active) { + StaticObject s_obj = i.second; s_obj.serialize(os); } } void StaticObjectList::deSerialize(std::istream &is) { - char buf[12]; + if (m_active.size()) { + errorstream << "StaticObjectList::deSerialize(): " + << "deserializing objects while " << m_active.size() + << " active objects already exist (not cleared). " + << m_stored.size() << " stored objects _were_ cleared" + << std::endl; + } + m_stored.clear(); + // version - is.read(buf, 1); - u8 version = buf[0]; + u8 version = readU8(is); // count - is.read(buf, 2); - u16 count = readU16((u8*)buf); - for(u16 i=0; i