From 577a2dce4d73eaf8deee232ff36edc6cb7a14cf2 Mon Sep 17 00:00:00 2001 From: DarthArgus Date: Tue, 13 Dec 2016 20:03:32 -0600 Subject: [PATCH] tidy up --- .../src/shared/buffers/ObjvarBuffer.cpp | 541 +++-- .../src/shared/buffers/ObjvarBuffer.h | 131 +- .../src/shared/core/SwgSnapshot.cpp | 2062 ++++++++--------- 3 files changed, 1290 insertions(+), 1444 deletions(-) diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.cpp index e30a8f0a..5e148cb2 100755 --- a/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.cpp +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.cpp @@ -16,327 +16,322 @@ // ====================================================================== -namespace ObjvarBufferNamespace -{ - const int ms_maxItemsPerExec = 10000; +namespace ObjvarBufferNamespace { + const int ms_maxItemsPerExec = 10000; } using namespace ObjvarBufferNamespace; // ====================================================================== -ObjvarBuffer::ObjvarBuffer(DB::ModeQuery::Mode mode, ObjectTableBuffer *objectTableBuffer, bool useGoldNames) : - AbstractTableBuffer(), - m_mode(mode), - m_data(), - m_objectTableBuffer(objectTableBuffer), - m_useGoldNames(useGoldNames) -{ +ObjvarBuffer::ObjvarBuffer(DB::ModeQuery::Mode mode, ObjectTableBuffer *objectTableBuffer, bool useGoldNames) + : AbstractTableBuffer(), m_mode(mode), m_data(), m_objectTableBuffer(objectTableBuffer), + m_useGoldNames(useGoldNames) { } // ---------------------------------------------------------------------- -ObjvarBuffer::~ObjvarBuffer() -{ - m_data.clear(); +ObjvarBuffer::~ObjvarBuffer() { + m_data.clear(); } -bool ObjvarBuffer::load(DB::Session *session,const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase) -{ - int rowsFetched; - UNREF(tags); // all objects have objvars - - DBQuery::GetAllObjectVariables qry(schema); +bool +ObjvarBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase) { + int rowsFetched; + UNREF(tags); // all objects have objvars - if (! (session->exec(&qry))) - return false; + DBQuery::GetAllObjectVariables qry(schema); - while ((rowsFetched = qry.fetch()) > 0) - { - size_t numRows = qry.getNumRowsFetched(); - size_t count = 0; - const std::vector &data = qry.getData(); + if (!(session->exec(&qry))) { + return false; + } - for (std::vector::const_iterator row=data.begin(); row!=data.end(); ++row) - { - if (++count > numRows) - { - break; - } - - IndexKey key(row->object_id.getValue(), row->name_id.getValue()); - ObjvarValue value; - value.m_type=row->type.getValue(); + while ((rowsFetched = qry.fetch()) > 0) { + size_t numRows = qry.getNumRowsFetched(); + size_t count = 0; + const std::vector &data = qry.getData(); - // The string is stored in the database as utf8, so a wide-to-narrow is appropriate - value.m_value=Unicode::wideToNarrow(row->value.getValue()); + for (std::vector::const_iterator row = data.begin(); row != data.end(); ++row) { + if (++count > numRows) { + break; + } - m_data.insert(std::make_pair(key,value)); - } - } - - qry.done(); - if (rowsFetched < 0) - return false; + IndexKey key(row->object_id.getValue(), row->name_id.getValue()); + ObjvarValue value; + value.m_type = row->type.getValue(); - if (usingGoldDatabase) - { - // Check for local overrides to the gold data - DBQuery::GetObjectVariableOverrides qry(DatabaseProcess::getInstance().getSchemaQualifier(), schema); - if (! (session->exec(&qry))) - return false; + // The string is stored in the database as utf8, so a wide-to-narrow is appropriate + value.m_value = Unicode::wideToNarrow(row->value.getValue()); - while ((rowsFetched = qry.fetch()) > 0) - { - size_t numRows = qry.getNumRowsFetched(); - size_t count = 0; - const std::vector &data = qry.getData(); + m_data.insert(std::make_pair(key, value)); + } + } - for (std::vector::const_iterator row=data.begin(); row!=data.end(); ++row) - { - if (++count > numRows) - { - break; - } - - IndexKey key(row->object_id.getValue(), row->name_id.getValue()); - ObjvarValue value; - value.m_type=row->type.getValue(); + qry.done(); + if (rowsFetched < 0) { + return false; + } - // The string is stored in the database as utf8, so a wide-to-narrow is appropriate - value.m_value=Unicode::wideToNarrow(row->value.getValue()); + if (usingGoldDatabase) { + // Check for local overrides to the gold data + DBQuery::GetObjectVariableOverrides qry(DatabaseProcess::getInstance().getSchemaQualifier(), schema); + if (!(session->exec(&qry))) { + return false; + } - value.m_detached=false; - - m_data.insert(std::make_pair(key,value)); - } - } - - qry.done(); - } - return (rowsFetched >= 0); + while ((rowsFetched = qry.fetch()) > 0) { + size_t numRows = qry.getNumRowsFetched(); + size_t count = 0; + const std::vector &data = qry.getData(); + + for (std::vector::const_iterator row = data.begin(); + row != data.end(); ++row) { + if (++count > numRows) { + break; + } + + IndexKey key(row->object_id.getValue(), row->name_id.getValue()); + ObjvarValue value; + value.m_type = row->type.getValue(); + + // The string is stored in the database as utf8, so a wide-to-narrow is appropriate + value.m_value = Unicode::wideToNarrow(row->value.getValue()); + + value.m_detached = false; + + m_data.insert(std::make_pair(key, value)); + } + } + + qry.done(); + } + return (rowsFetched >= 0); } // ---------------------------------------------------------------------- -bool ObjvarBuffer::save(DB::Session *session) -{ - LOG("SaveCounts",("Objvars: %i saved to db",m_data.size())); +bool ObjvarBuffer::save(DB::Session *session) { + LOG("SaveCounts", ("Objvars: %i saved to db", m_data.size())); - { - DBQuery::AddObjectVariableQuery addQuery; - if (!addQuery.setupData(session)) - return false; - for (DataType::iterator i=m_data.begin(); i!=m_data.end(); ++i) - { - if (!i->second.m_detached && !i->second.m_inDatabase) - if (!addQuery.addData(i->first.m_objectId, i->first.m_nameId, i->second.m_type, i->second.m_value)) - return false; - if (addQuery.getNumItems() == ObjvarBufferNamespace::ms_maxItemsPerExec) - { - if (! (session->exec(&addQuery))) - return false; - addQuery.clearData(); - } - } - if (addQuery.getNumItems() != 0) - if (! (session->exec(&addQuery))) - return false; - addQuery.done(); - addQuery.freeData(); - } + { + DBQuery::AddObjectVariableQuery addQuery; + if (!addQuery.setupData(session)) { + return false; + } + for (DataType::iterator i = m_data.begin(); i != m_data.end(); ++i) { + if (!i->second.m_detached && !i->second.m_inDatabase) { + if (!addQuery.addData(i->first.m_objectId, i->first.m_nameId, i->second.m_type, i->second.m_value)) { + return false; + } + } + if (addQuery.getNumItems() == ObjvarBufferNamespace::ms_maxItemsPerExec) { + if (!(session->exec(&addQuery))) { + return false; + } + addQuery.clearData(); + } + } + if (addQuery.getNumItems() != 0) { + if (!(session->exec(&addQuery))) { + return false; + } + } + addQuery.done(); + addQuery.freeData(); + } - { - DBQuery::UpdateObjectVariableQuery updateQuery; - if (!updateQuery.setupData(session)) - return false; - for (DataType::iterator i=m_data.begin(); i!=m_data.end(); ++i) - { - if (!i->second.m_detached && i->second.m_inDatabase) - if (!updateQuery.addData(i->first.m_objectId, i->first.m_nameId, i->second.m_type, i->second.m_value)) - return false; - if (updateQuery.getNumItems() == ObjvarBufferNamespace::ms_maxItemsPerExec) - { - if (! (session->exec(&updateQuery))) - return false; - updateQuery.clearData(); - } - } - if (updateQuery.getNumItems() != 0) - if (! (session->exec(&updateQuery))) - return false; - updateQuery.done(); - updateQuery.freeData(); - } - - { - DBQuery::RemoveObjectVariableQuery removeQuery; - if (!removeQuery.setupData(session)) - return false; - for (DataType::iterator i=m_data.begin(); i!=m_data.end(); ++i) - { - if (i->second.m_detached && i->second.m_inDatabase) - if (!removeQuery.addData(i->first.m_objectId, i->first.m_nameId)) - return false; - if (removeQuery.getNumItems() == ObjvarBufferNamespace::ms_maxItemsPerExec) - { - if (! (session->exec(&removeQuery))) - return false; - removeQuery.clearData(); - } - } - if (removeQuery.getNumItems() != 0) - if (! (session->exec(&removeQuery))) - return false; - removeQuery.done(); - removeQuery.freeData(); - } - return true; + { + DBQuery::UpdateObjectVariableQuery updateQuery; + if (!updateQuery.setupData(session)) { + return false; + } + for (DataType::iterator i = m_data.begin(); i != m_data.end(); ++i) { + if (!i->second.m_detached && i->second.m_inDatabase) { + if (!updateQuery.addData(i->first.m_objectId, i->first.m_nameId, i->second.m_type, i->second.m_value)) { + return false; + } + } + if (updateQuery.getNumItems() == ObjvarBufferNamespace::ms_maxItemsPerExec) { + if (!(session->exec(&updateQuery))) { + return false; + } + updateQuery.clearData(); + } + } + if (updateQuery.getNumItems() != 0) { + if (!(session->exec(&updateQuery))) { + return false; + } + } + updateQuery.done(); + updateQuery.freeData(); + } + + { + DBQuery::RemoveObjectVariableQuery removeQuery; + if (!removeQuery.setupData(session)) { + return false; + } + for (DataType::iterator i = m_data.begin(); i != m_data.end(); ++i) { + if (i->second.m_detached && i->second.m_inDatabase) { + if (!removeQuery.addData(i->first.m_objectId, i->first.m_nameId)) { + return false; + } + } + if (removeQuery.getNumItems() == ObjvarBufferNamespace::ms_maxItemsPerExec) { + if (!(session->exec(&removeQuery))) { + return false; + } + removeQuery.clearData(); + } + } + if (removeQuery.getNumItems() != 0) { + if (!(session->exec(&removeQuery))) { + return false; + } + } + removeQuery.done(); + removeQuery.freeData(); + } + return true; } // ---------------------------------------------------------------------- -void ObjvarBuffer::getObjvarsForObject(const NetworkId &objectId, std::vector &commands) const -{ - DynamicVariableList::MapType::Command c; +void +ObjvarBuffer::getObjvarsForObject(const NetworkId &objectId, std::vector &commands) const { + DynamicVariableList::MapType::Command c; - // unpacked object variables + // unpacked object variables - { - for (DataType::const_iterator i= m_data.lower_bound(IndexKey(objectId,0)); (i!=m_data.end()) && (i->first.m_objectId==objectId); ++i) - { - std::string name; - bool foundName = false; - if (m_useGoldNames) - foundName=ObjvarNameManager::getGoldInstance().getName(i->first.m_nameId, name); - else - foundName=ObjvarNameManager::getInstance().getName(i->first.m_nameId, name); - - if (foundName) - { - c.cmd = DynamicVariableList::MapType::Command::ADD; - c.key = name; - c.value.load(-1, i->second.m_type, Unicode::utf8ToWide(i->second.m_value)); - - commands.push_back(c); - } - else - WARNING_STRICT_FATAL(true,("Object %s has an objvar with name_id %i, which was not in the list of names.",objectId.getValueString().c_str(), i->first.m_nameId)); - } - } - - //packed object variables - - m_objectTableBuffer->getObjvarsForObject(objectId, commands); + { + for (DataType::const_iterator i = m_data.lower_bound(IndexKey(objectId, 0)); + (i != m_data.end()) && (i->first.m_objectId == objectId); ++i) { + std::string name; + bool foundName = false; + if (m_useGoldNames) { + foundName = ObjvarNameManager::getGoldInstance().getName(i->first.m_nameId, name); + } else { + foundName = ObjvarNameManager::getInstance().getName(i->first.m_nameId, name); + } - // Apply overrides, if any. - // The last objvar sent to the game takes precedence, so we want to send the overrides after the values read in through the regular process + if (foundName) { + c.cmd = DynamicVariableList::MapType::Command::ADD; + c.key = name; + c.value.load(-1, i->second.m_type, Unicode::utf8ToWide(i->second.m_value)); - { - for (DataType::const_iterator i= m_data.lower_bound(IndexKey(objectId,0)); (i!=m_data.end()) && (i->first.m_objectId==objectId); ++i) - { - std::string name; - bool foundName = false; - foundName=ObjvarNameManager::getInstance().getName(i->first.m_nameId, name); // overrides always use the live names, not the gold names. - - if (foundName) - { - c.cmd = DynamicVariableList::MapType::Command::ADD; - c.key = name; - c.value.load(-1, i->second.m_type, Unicode::utf8ToWide(i->second.m_value)); - - commands.push_back(c); - } - else - WARNING_STRICT_FATAL(true,("Object %s has an objvar with name_id %i, which was not in the list of names.",objectId.getValueString().c_str(), i->first.m_nameId)); - } - } + commands.push_back(c); + } else { + WARNING_STRICT_FATAL(true, ("Object %s has an objvar with name_id %i, which was not in the list of names.", objectId.getValueString().c_str(), i->first.m_nameId)); + } + } + } + + //packed object variables + + m_objectTableBuffer->getObjvarsForObject(objectId, commands); + + // Apply overrides, if any. + // The last objvar sent to the game takes precedence, so we want to send the overrides after the values read in through the regular process + + { + for (DataType::const_iterator i = m_data.lower_bound(IndexKey(objectId, 0)); + (i != m_data.end()) && (i->first.m_objectId == objectId); ++i) { + std::string name; + bool foundName = false; + foundName = ObjvarNameManager::getInstance().getName(i->first.m_nameId, name); // overrides always use the live names, not the gold names. + + if (foundName) { + c.cmd = DynamicVariableList::MapType::Command::ADD; + c.key = name; + c.value.load(-1, i->second.m_type, Unicode::utf8ToWide(i->second.m_value)); + + commands.push_back(c); + } else { + WARNING_STRICT_FATAL(true, ("Object %s has an objvar with name_id %i, which was not in the list of names.", objectId.getValueString().c_str(), i->first.m_nameId)); + } + } + } } // ---------------------------------------------------------------------- -void ObjvarBuffer::updateObjvars(const NetworkId &objectId, const std::vector &commands) -{ - bool override=false; // flag that we're dealing with the gold data override case (storing an objvar change in the live database, on an object that came from the gold database) - if (ConfigServerDatabase::getEnableGoldDatabase() && objectId < ConfigServerDatabase::getMaxGoldNetworkId()) - override=true; - - for (std::vector::const_iterator i=commands.begin(); i!=commands.end(); ++i) - { - switch(i->cmd) - { - case DynamicVariableList::MapType::Command::ADD : - case DynamicVariableList::MapType::Command::SET : - { - std::string packedValue(Unicode::wideToUTF8(i->value.getPackedValueString())); +void +ObjvarBuffer::updateObjvars(const NetworkId &objectId, const std::vector &commands) { + bool override = false; // flag that we're dealing with the gold data override case (storing an objvar change in the live database, on an object that came from the gold database) + if (ConfigServerDatabase::getEnableGoldDatabase() && objectId < ConfigServerDatabase::getMaxGoldNetworkId()) { + override = true; + } - if (i->value.getPosition() !=-1 && ConfigServerDatabase::getEnableObjvarPacking() && !override) - { - m_objectTableBuffer->handlePackedObjvar(objectId, i->value.getPosition(), i->key, i->value.getType(), packedValue); - } - else - { - int nameId = ObjvarNameManager::getInstance().getOrAddNameId(i->key); - - DataType::iterator row=m_data.find(IndexKey(objectId, nameId)); - if (row==m_data.end()) - { - row=m_data.insert(std::make_pair(IndexKey(objectId, nameId),ObjvarValue())).first; - if (i->cmd==DynamicVariableList::MapType::Command::ADD || override) - row->second.m_inDatabase=false; // new variable - else - row->second.m_inDatabase=true; // update to existing variable - } - row->second.m_type = i->value.getType(); - row->second.m_value = packedValue; - row->second.m_detached = false; - } - break; - } - - case DynamicVariableList::MapType::Command::ERASE : - { - int nameId = ObjvarNameManager::getInstance().getNameId(i->key); - if (nameId != 0) // It's possible to get an ERASE for a packed objvar where the name was never used in the OBJECT_VARIABLES table. We can safely ignore these. - { - DataType::iterator row=m_data.find(IndexKey(objectId, nameId)); - if (row==m_data.end()) - { - if (i->value.getPosition() == -1 || override) - { - row=m_data.insert(std::make_pair(IndexKey(objectId, nameId),ObjvarValue())).first; - row->second.m_inDatabase=true; // deleting existing variable - } - // else it was a packed objvar, and no update is necessary - } + for (std::vector::const_iterator i = commands.begin(); + i != commands.end(); ++i) { + switch (i->cmd) { + case DynamicVariableList::MapType::Command::ADD : + case DynamicVariableList::MapType::Command::SET : { + std::string packedValue(Unicode::wideToUTF8(i->value.getPackedValueString())); - row->second.m_type = i->value.getType(); - row->second.m_detached = true; //why the fuck even store it at this point? - } + if (i->value.getPosition() != -1 && ConfigServerDatabase::getEnableObjvarPacking() && !override) { + m_objectTableBuffer->handlePackedObjvar(objectId, i->value.getPosition(), i->key, i->value.getType(), packedValue); + } else { + int nameId = ObjvarNameManager::getInstance().getOrAddNameId(i->key); - break; - } - - default: - WARNING_STRICT_FATAL(true,("Unknown command %i unpacked in object variables for object %s.",i->cmd,objectId.getValueString().c_str())); - } - } + DataType::iterator row = m_data.find(IndexKey(objectId, nameId)); + if (row == m_data.end()) { + row = m_data.insert(std::make_pair(IndexKey(objectId, nameId), ObjvarValue())).first; + if (i->cmd == DynamicVariableList::MapType::Command::ADD || override) { + row->second.m_inDatabase = false; // new variable + } else { + row->second.m_inDatabase = true; + } // update to existing variable + } + row->second.m_type = i->value.getType(); + row->second.m_value = packedValue; + row->second.m_detached = false; + } + break; + } - DEBUG_WARNING(commands.size() > 100,("Object %s has a suspicious number of objvar updates (%i updates).",objectId.getValueString().c_str(),commands.size())); + case DynamicVariableList::MapType::Command::ERASE : { + int nameId = ObjvarNameManager::getInstance().getNameId(i->key); + if (nameId != + 0) // It's possible to get an ERASE for a packed objvar where the name was never used in the OBJECT_VARIABLES table. We can safely ignore these. + { + DataType::iterator row = m_data.find(IndexKey(objectId, nameId)); + if (row == m_data.end()) { + if (i->value.getPosition() == -1 || override) { + row = m_data.insert(std::make_pair(IndexKey(objectId, nameId), ObjvarValue())).first; + row->second.m_inDatabase = true; // deleting existing variable + } + // else it was a packed objvar, and no update is necessary + } + + row->second.m_type = i->value.getType(); + row->second.m_detached = true; //why the fuck even store it at this point? + } + + break; + } + + default: + WARNING_STRICT_FATAL(true, ("Unknown command %i unpacked in object variables for object %s.", i->cmd, objectId.getValueString().c_str())); + } + } + + DEBUG_WARNING(commands.size() > + 100, ("Object %s has a suspicious number of objvar updates (%i updates).", objectId.getValueString().c_str(), commands.size())); } // ---------------------------------------------------------------------- -void ObjvarBuffer::removeObject(const NetworkId &object) -{ - DataType::iterator i=m_data.lower_bound(IndexKey(object,0)); - while (i!=m_data.end()) - { - if (i->first.m_objectId==object) - i = m_data.erase(i); - else - ++i; - } +void ObjvarBuffer::removeObject(const NetworkId &object) { + DataType::iterator i = m_data.lower_bound(IndexKey(object, 0)); + while (i != m_data.end()) { + if (i->first.m_objectId == object) { + i = m_data.erase(i); + } else { + ++i; + } + } } // ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.h index 7e5ba082..c66afbbb 100755 --- a/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.h +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.h @@ -20,9 +20,8 @@ // ====================================================================== class ObjectTableBuffer; -namespace DBSchema -{ - struct ObjvarRow; +namespace DBSchema { + struct ObjvarRow; } // ====================================================================== @@ -39,92 +38,98 @@ namespace DBSchema * are loaded for that object. */ -class ObjvarBuffer : public AbstractTableBuffer -{ +class ObjvarBuffer : public AbstractTableBuffer { public: - explicit ObjvarBuffer(DB::ModeQuery::Mode mode, ObjectTableBuffer *objectTableBuffer, bool useGoldNames); - virtual ~ObjvarBuffer(void); - - virtual bool load(DB::Session *session,const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); - virtual bool save(DB::Session *session); - virtual void removeObject(const NetworkId &object); - - DBSchema::ObjectVariableRow *findRowByIndex(const NetworkId &objectId, const std::string &name); + explicit ObjvarBuffer(DB::ModeQuery::Mode mode, ObjectTableBuffer *objectTableBuffer, bool useGoldNames); - void updateObjvars(const NetworkId &objectId, const std::vector &commands); - void getObjvarsForObject(const NetworkId &objectId, std::vector &commands) const; - - private: - struct IndexKey - { - const NetworkId m_objectId; - int m_nameId; + virtual ~ObjvarBuffer(void); - IndexKey(const NetworkId &objectId, int nameId); - bool operator==(const IndexKey &rhs) const; - bool operator<(const IndexKey &rhs) const; - bool operator>(const IndexKey &rhs) const; - }; + virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); - struct ObjvarValue - { - int m_type; - std::string m_value; - bool m_detached; - bool m_inDatabase; - }; + virtual bool save(DB::Session *session); - typedef std::map DataType; + virtual void removeObject(const NetworkId &object); - DB::ModeQuery::Mode m_mode; - DataType m_data; - ObjectTableBuffer *m_objectTableBuffer; - bool m_useGoldNames; + DBSchema::ObjectVariableRow *findRowByIndex(const NetworkId &objectId, const std::string &name); + + void updateObjvars(const NetworkId &objectId, const std::vector &commands); + + void + getObjvarsForObject(const NetworkId &objectId, std::vector &commands) const; + +private: + struct IndexKey { + const NetworkId m_objectId; + int m_nameId; + + IndexKey(const NetworkId &objectId, int nameId); + + bool operator==(const IndexKey &rhs) const; + + bool operator<(const IndexKey &rhs) const; + + bool operator>(const IndexKey &rhs) const; + }; + + struct ObjvarValue { + int m_type; + std::string m_value; + bool m_detached; + bool m_inDatabase; + }; + + typedef std::map DataType; + + DB::ModeQuery::Mode m_mode; + DataType m_data; + ObjectTableBuffer *m_objectTableBuffer; + bool m_useGoldNames; // typedef std::map > LoadIndexType; // LoadIndexType m_loadIndex; - private: - ObjvarBuffer(); //disable - ObjvarBuffer(const ObjvarBuffer&); //disable - ObjvarBuffer & operator=(const ObjvarBuffer&); //disable +private: + ObjvarBuffer(); //disable + ObjvarBuffer(const ObjvarBuffer &); //disable + ObjvarBuffer &operator=(const ObjvarBuffer &); //disable }; //lint !e1712 // IndexKey has no default constructor // ====================================================================== -inline ObjvarBuffer::IndexKey::IndexKey(const NetworkId &objectId, int nameId) : m_objectId(objectId), m_nameId(nameId) -{ +inline ObjvarBuffer::IndexKey::IndexKey(const NetworkId &objectId, int nameId) + : m_objectId(objectId), m_nameId(nameId) { } // ---------------------------------------------------------------------- -inline bool ObjvarBuffer::IndexKey::operator==(const IndexKey &rhs) const -{ - return ((m_objectId == rhs.m_objectId) && (m_nameId == rhs.m_nameId)); +inline bool ObjvarBuffer::IndexKey::operator==(const IndexKey &rhs) const { + return ((m_objectId == rhs.m_objectId) && (m_nameId == rhs.m_nameId)); } // ---------------------------------------------------------------------- -inline bool ObjvarBuffer::IndexKey::operator<(const IndexKey &rhs) const -{ - if (m_objectId < rhs.m_objectId) - return true; +inline bool ObjvarBuffer::IndexKey::operator<(const IndexKey &rhs) const { + if (m_objectId < rhs.m_objectId) { + return true; + } - if (m_objectId == rhs.m_objectId) - return (m_nameId < rhs.m_nameId); + if (m_objectId == rhs.m_objectId) { + return (m_nameId < rhs.m_nameId); + } - return false; + return false; } -inline bool ObjvarBuffer::IndexKey::operator>(const IndexKey &rhs) const -{ - if (m_objectId > rhs.m_objectId) - return true; - - if (m_objectId == rhs.m_objectId) - return (m_nameId > rhs.m_nameId); - - return false; +inline bool ObjvarBuffer::IndexKey::operator>(const IndexKey &rhs) const { + if (m_objectId > rhs.m_objectId) { + return true; + } + + if (m_objectId == rhs.m_objectId) { + return (m_nameId > rhs.m_nameId); + } + + return false; } // ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/SwgSnapshot.cpp b/game/server/application/SwgDatabaseServer/src/shared/core/SwgSnapshot.cpp index b02cd32b..99091087 100755 --- a/game/server/application/SwgDatabaseServer/src/shared/core/SwgSnapshot.cpp +++ b/game/server/application/SwgDatabaseServer/src/shared/core/SwgSnapshot.cpp @@ -59,87 +59,62 @@ * (Referring to a _specific_ buffer when you know you need that buffer * is kosher.) */ -SwgSnapshot::SwgSnapshot(DB::ModeQuery::Mode mode, bool useGoldDatabase) : - Snapshot(mode, useGoldDatabase), - m_battlefieldMarkerObjectBuffer(mode), - m_battlefieldParticipantBuffer(mode), - m_bountyHunterTargetBuffer(), - m_buildingObjectBuffer(mode), - m_cellObjectBuffer(mode), - m_cityObjectBuffer(mode), - m_creatureObjectBuffer(mode), - m_experienceBuffer(mode), - m_factoryObjectBuffer(mode), - m_guildObjectBuffer(mode), - m_harvesterInstallationObjectBuffer(mode), - m_installationObjectBuffer(mode), - m_intangibleObjectBuffer(mode), - m_locationBuffer(mode), - m_manufactureInstallationObjectBuffer(mode), - m_manufactureSchematicAttributeBuffer(mode), - m_manufactureSchematicObjectBuffer(mode), - m_messageBuffer(), - m_missionObjectBuffer(mode), - m_objectTableBuffer(mode), - m_objvarBuffer(mode, &m_objectTableBuffer, useGoldDatabase), - m_planetObjectBuffer(mode), - m_playerObjectBuffer(mode), - m_playerQuestObjectBuffer(mode), - m_propertyListBuffer(mode), - m_resourceContainerObjectBuffer(mode), - m_resourceTypeBuffer(), - m_scriptBuffer(), - m_shipObjectBuffer(mode), - m_staticObjectBuffer(mode), - m_tangibleObjectBuffer(mode), - m_universeObjectBuffer(mode), - m_vehicleObjectBuffer(mode), - m_waypointBuffer(mode), - m_weaponObjectBuffer(mode), - m_immediateDeleteStep(nullptr), - m_offlineMoneyCustomPersistStep(nullptr) -{ - m_bufferList.push_back(&m_battlefieldMarkerObjectBuffer); - m_bufferList.push_back(&m_battlefieldParticipantBuffer); - m_bufferList.push_back(&m_buildingObjectBuffer); - m_bufferList.push_back(&m_bountyHunterTargetBuffer); - m_bufferList.push_back(&m_cellObjectBuffer); - m_bufferList.push_back(&m_cityObjectBuffer); - m_bufferList.push_back(&m_creatureObjectBuffer); - m_bufferList.push_back(&m_experienceBuffer); - m_bufferList.push_back(&m_factoryObjectBuffer); - m_bufferList.push_back(&m_guildObjectBuffer); - m_bufferList.push_back(&m_harvesterInstallationObjectBuffer); - m_bufferList.push_back(&m_installationObjectBuffer); - m_bufferList.push_back(&m_intangibleObjectBuffer); - m_bufferList.push_back(&m_locationBuffer); - m_bufferList.push_back(&m_manufactureInstallationObjectBuffer); - m_bufferList.push_back(&m_manufactureSchematicAttributeBuffer); - m_bufferList.push_back(&m_manufactureSchematicObjectBuffer); - m_bufferList.push_back(&m_messageBuffer); - m_bufferList.push_back(&m_missionObjectBuffer); - m_bufferList.push_back(&m_objvarBuffer); - m_bufferList.push_back(&m_planetObjectBuffer); - m_bufferList.push_back(&m_playerObjectBuffer); - m_bufferList.push_back(&m_playerQuestObjectBuffer); - m_bufferList.push_back(&m_propertyListBuffer); - m_bufferList.push_back(&m_resourceContainerObjectBuffer); - m_bufferList.push_back(&m_resourceTypeBuffer); - m_bufferList.push_back(&m_scriptBuffer); - m_bufferList.push_back(&m_shipObjectBuffer); - m_bufferList.push_back(&m_staticObjectBuffer); - m_bufferList.push_back(&m_tangibleObjectBuffer); - m_bufferList.push_back(&m_universeObjectBuffer); - m_bufferList.push_back(&m_vehicleObjectBuffer); - m_bufferList.push_back(&m_waypointBuffer); - m_bufferList.push_back(&m_weaponObjectBuffer); +SwgSnapshot::SwgSnapshot(DB::ModeQuery::Mode mode, bool useGoldDatabase) + : Snapshot(mode, useGoldDatabase), m_battlefieldMarkerObjectBuffer(mode), m_battlefieldParticipantBuffer(mode), + m_bountyHunterTargetBuffer(), m_buildingObjectBuffer(mode), m_cellObjectBuffer(mode), + m_cityObjectBuffer(mode), m_creatureObjectBuffer(mode), m_experienceBuffer(mode), m_factoryObjectBuffer(mode), + m_guildObjectBuffer(mode), m_harvesterInstallationObjectBuffer(mode), m_installationObjectBuffer(mode), + m_intangibleObjectBuffer(mode), m_locationBuffer(mode), m_manufactureInstallationObjectBuffer(mode), + m_manufactureSchematicAttributeBuffer(mode), m_manufactureSchematicObjectBuffer(mode), m_messageBuffer(), + m_missionObjectBuffer(mode), m_objectTableBuffer(mode), + m_objvarBuffer(mode, &m_objectTableBuffer, useGoldDatabase), m_planetObjectBuffer(mode), + m_playerObjectBuffer(mode), m_playerQuestObjectBuffer(mode), m_propertyListBuffer(mode), + m_resourceContainerObjectBuffer(mode), m_resourceTypeBuffer(), m_scriptBuffer(), m_shipObjectBuffer(mode), + m_staticObjectBuffer(mode), m_tangibleObjectBuffer(mode), m_universeObjectBuffer(mode), + m_vehicleObjectBuffer(mode), m_waypointBuffer(mode), m_weaponObjectBuffer(mode), + m_immediateDeleteStep(nullptr), m_offlineMoneyCustomPersistStep(nullptr) { + m_bufferList.push_back(&m_battlefieldMarkerObjectBuffer); + m_bufferList.push_back(&m_battlefieldParticipantBuffer); + m_bufferList.push_back(&m_buildingObjectBuffer); + m_bufferList.push_back(&m_bountyHunterTargetBuffer); + m_bufferList.push_back(&m_cellObjectBuffer); + m_bufferList.push_back(&m_cityObjectBuffer); + m_bufferList.push_back(&m_creatureObjectBuffer); + m_bufferList.push_back(&m_experienceBuffer); + m_bufferList.push_back(&m_factoryObjectBuffer); + m_bufferList.push_back(&m_guildObjectBuffer); + m_bufferList.push_back(&m_harvesterInstallationObjectBuffer); + m_bufferList.push_back(&m_installationObjectBuffer); + m_bufferList.push_back(&m_intangibleObjectBuffer); + m_bufferList.push_back(&m_locationBuffer); + m_bufferList.push_back(&m_manufactureInstallationObjectBuffer); + m_bufferList.push_back(&m_manufactureSchematicAttributeBuffer); + m_bufferList.push_back(&m_manufactureSchematicObjectBuffer); + m_bufferList.push_back(&m_messageBuffer); + m_bufferList.push_back(&m_missionObjectBuffer); + m_bufferList.push_back(&m_objvarBuffer); + m_bufferList.push_back(&m_planetObjectBuffer); + m_bufferList.push_back(&m_playerObjectBuffer); + m_bufferList.push_back(&m_playerQuestObjectBuffer); + m_bufferList.push_back(&m_propertyListBuffer); + m_bufferList.push_back(&m_resourceContainerObjectBuffer); + m_bufferList.push_back(&m_resourceTypeBuffer); + m_bufferList.push_back(&m_scriptBuffer); + m_bufferList.push_back(&m_shipObjectBuffer); + m_bufferList.push_back(&m_staticObjectBuffer); + m_bufferList.push_back(&m_tangibleObjectBuffer); + m_bufferList.push_back(&m_universeObjectBuffer); + m_bufferList.push_back(&m_vehicleObjectBuffer); + m_bufferList.push_back(&m_waypointBuffer); + m_bufferList.push_back(&m_weaponObjectBuffer); - // note: m_objectTableBuffer is left off bufferList intentionally + // note: m_objectTableBuffer is left off bufferList intentionally } // ---------------------------------------------------------------------- -SwgSnapshot::~SwgSnapshot(){ +SwgSnapshot::~SwgSnapshot() { + m_bufferList.clear(); } // ---------------------------------------------------------------------- @@ -150,61 +125,59 @@ SwgSnapshot::~SwgSnapshot(){ * the objectTableBuffer and not override this function? */ -bool SwgSnapshot::saveToDB(DB::Session *session) -{ - // artificial delay can be added here to help debug timing issues - if (ConfigServerDatabase::getWriteDelay() > 0) - { - LOG("SwgSnapshot::saveToDB",("Delaying writing of snapshot for %i seconds",ConfigServerDatabase::getWriteDelay())); - Os::sleep(ConfigServerDatabase::getWriteDelay()*1000); - } +bool SwgSnapshot::saveToDB(DB::Session *session) { + // artificial delay can be added here to help debug timing issues + if (ConfigServerDatabase::getWriteDelay() > 0) { + LOG("SwgSnapshot::saveToDB", ("Delaying writing of snapshot for %i seconds", ConfigServerDatabase::getWriteDelay())); + Os::sleep(ConfigServerDatabase::getWriteDelay() * 1000); + } - session->setAutoCommitMode(false); - - if (! (m_objectTableBuffer.save(session))) - return false; + session->setAutoCommitMode(false); - m_battlefieldMarkerObjectBuffer.save(session); - m_battlefieldParticipantBuffer.save(session); - m_buildingObjectBuffer.save(session); - m_bountyHunterTargetBuffer.save(session); - m_cellObjectBuffer.save(session); - m_cityObjectBuffer.save(session); - m_creatureObjectBuffer.save(session); - m_experienceBuffer.save(session); - m_factoryObjectBuffer.save(session); - m_guildObjectBuffer.save(session); - m_harvesterInstallationObjectBuffer.save(session); - m_installationObjectBuffer.save(session); - m_intangibleObjectBuffer.save(session); - m_locationBuffer.save(session); - m_manufactureInstallationObjectBuffer.save(session); - m_manufactureSchematicAttributeBuffer.save(session); - m_manufactureSchematicObjectBuffer.save(session); - m_messageBuffer.save(session); - m_missionObjectBuffer.save(session); - m_objvarBuffer.save(session); - m_planetObjectBuffer.save(session); - m_playerObjectBuffer.save(session); - m_playerQuestObjectBuffer.save(session); - m_propertyListBuffer.save(session); - m_resourceContainerObjectBuffer.save(session); - m_resourceTypeBuffer.save(session); - m_scriptBuffer.save(session); - m_shipObjectBuffer.save(session); - m_staticObjectBuffer.save(session); - m_tangibleObjectBuffer.save(session); - m_universeObjectBuffer.save(session); - m_vehicleObjectBuffer.save(session); - m_waypointBuffer.save(session); - m_weaponObjectBuffer.save(session); + // save all the buffers + if (!(m_objectTableBuffer.save(session))) { return false; } + if (!(m_battlefieldMarkerObjectBuffer.save(session))) { return false; } + if (!(m_battlefieldParticipantBuffer.save(session))) { return false; } + if (!(m_buildingObjectBuffer.save(session))) { return false; } + if (!(m_bountyHunterTargetBuffer.save(session))) { return false; } + if (!(m_cellObjectBuffer.save(session))) { return false; } + if (!(m_cityObjectBuffer.save(session))) { return false; } + if (!(m_creatureObjectBuffer.save(session))) { return false; } + if (!(m_experienceBuffer.save(session))) { return false; } + if (!(m_factoryObjectBuffer.save(session))) { return false; } + if (!(m_guildObjectBuffer.save(session))) { return false; } + if (!(m_harvesterInstallationObjectBuffer.save(session))) { return false; } + if (!(m_installationObjectBuffer.save(session))) { return false; } + if (!(m_intangibleObjectBuffer.save(session))) { return false; } + if (!(m_locationBuffer.save(session))) { return false; } + if (!(m_manufactureInstallationObjectBuffer.save(session))) { return false; } + if (!(m_manufactureSchematicAttributeBuffer.save(session))) { return false; } + if (!(m_manufactureSchematicObjectBuffer.save(session))) { return false; } + if (!(m_messageBuffer.save(session))) { return false; } + if (!(m_missionObjectBuffer.save(session))) { return false; } + if (!(m_objvarBuffer.save(session))) { return false; } + if (!(m_planetObjectBuffer.save(session))) { return false; } + if (!(m_playerObjectBuffer.save(session))) { return false; } + if (!(m_playerQuestObjectBuffer.save(session))) { return false; } + if (!(m_propertyListBuffer.save(session))) { return false; } + if (!(m_resourceContainerObjectBuffer.save(session))) { return false; } + if (!(m_resourceTypeBuffer.save(session))) { return false; } + if (!(m_scriptBuffer.save(session))) { return false; } + if (!(m_shipObjectBuffer.save(session))) { return false; } + if (!(m_staticObjectBuffer.save(session))) { return false; } + if (!(m_tangibleObjectBuffer.save(session))) { return false; } + if (!(m_universeObjectBuffer.save(session))) { return false; } + if (!(m_vehicleObjectBuffer.save(session))) { return false; } + if (!(m_waypointBuffer.save(session))) { return false; } + if (!(m_weaponObjectBuffer.save(session))) { return false; } - if (! (Snapshot::saveToDB(session))) - return false; + // save the parent class + if (!(Snapshot::saveToDB(session))) { return false; } - session->commitTransaction(); - - return true; + // commit/flush to the db + session->commitTransaction(); + + return true; } // ---------------------------------------------------------------------- @@ -216,16 +189,15 @@ bool SwgSnapshot::saveToDB(DB::Session *session) * table buffer. */ -void SwgSnapshot::handleUpdateObjectPosition(const UpdateObjectPositionMessage &message) -{ - if ( message.isCreatureObject() ) //&& ( message.getPlayerControlled() )) - { - m_creatureObjectBuffer.handleUpdateObjectPosition(message); - } +void SwgSnapshot::handleUpdateObjectPosition(const UpdateObjectPositionMessage &message) { + if (message.isCreatureObject()) //&& ( message.getPlayerControlled() )) + { + m_creatureObjectBuffer.handleUpdateObjectPosition(message); + } - if (m_objectTableBuffer.handleUpdateObjectPosition(message)) return; + if (m_objectTableBuffer.handleUpdateObjectPosition(message)) return; - FATAL(true,("UpdateObjectPosition was not handled by any of the object buffers.")); + FATAL(true, ("UpdateObjectPosition was not handled by any of the object buffers.")); } // ---------------------------------------------------------------------- @@ -236,39 +208,34 @@ void SwgSnapshot::handleUpdateObjectPosition(const UpdateObjectPositionMessage & * Tells the objectTableBuffer to set the deleted column to true. */ -void SwgSnapshot::handleDeleteMessage(const NetworkId &objectId, int reasonCode, bool immediate, bool demandLoadedContainer, bool cascadeReason) -{ - m_objectTableBuffer.handleDeleteMessage(objectId, reasonCode, demandLoadedContainer, cascadeReason); +void +SwgSnapshot::handleDeleteMessage(const NetworkId &objectId, int reasonCode, bool immediate, bool demandLoadedContainer, bool cascadeReason) { + m_objectTableBuffer.handleDeleteMessage(objectId, reasonCode, demandLoadedContainer, cascadeReason); - for (BufferListType::iterator buffer=m_bufferList.begin(); buffer!=m_bufferList.end(); ++buffer) - { - (*buffer)->removeObject(objectId); // if the object is deleted, no reason to save other data for it - } + for (BufferListType::iterator buffer = m_bufferList.begin(); buffer != m_bufferList.end(); ++buffer) { + (*buffer)->removeObject(objectId); // if the object is deleted, no reason to save other data for it + } - if (immediate && (getMode() != DB::ModeQuery::mode_INSERT)) - { - if (!m_immediateDeleteStep) - { - m_immediateDeleteStep = new ImmediateDeleteCustomPersistStep; - addCustomPersistStep(m_immediateDeleteStep); - } + if (immediate && (getMode() != DB::ModeQuery::mode_INSERT)) { + if (!m_immediateDeleteStep) { + m_immediateDeleteStep = new ImmediateDeleteCustomPersistStep; + addCustomPersistStep(m_immediateDeleteStep); + } - m_immediateDeleteStep->addObject(objectId); - } + m_immediateDeleteStep->addObject(objectId); + } } // ---------------------------------------------------------------------- -void SwgSnapshot::handleMessageTo(const MessageToPayload &data) -{ - m_messageBuffer.handleMessageTo(data); +void SwgSnapshot::handleMessageTo(const MessageToPayload &data) { + m_messageBuffer.handleMessageTo(data); } // ---------------------------------------------------------------------- -void SwgSnapshot::handleMessageToAck(const MessageToId &messageId) -{ - m_messageBuffer.handleMessageToAck(messageId); +void SwgSnapshot::handleMessageToAck(const MessageToId &messageId) { + m_messageBuffer.handleMessageToAck(messageId); } // ---------------------------------------------------------------------- @@ -276,211 +243,193 @@ void SwgSnapshot::handleMessageToAck(const MessageToId &messageId) /** * Decodes the Objvars data for an object from the network package. */ -void SwgSnapshot::decodeObjVars(NetworkId const & objectId, Archive::ReadIterator &data, bool isBaseline) -{ - std::vector commands; - if (isBaseline) - DynamicVariableList::MapType::unpack(data, commands); - else - DynamicVariableList::MapType::unpackDelta(data, commands); - m_objvarBuffer.updateObjvars(objectId,commands); +void SwgSnapshot::decodeObjVars(NetworkId const &objectId, Archive::ReadIterator &data, bool isBaseline) { + std::vector commands; + if (isBaseline) { + DynamicVariableList::MapType::unpack(data, commands); + } else { + DynamicVariableList::MapType::unpackDelta(data, commands); + } + m_objvarBuffer.updateObjvars(objectId, commands); } // ---------------------------------------------------------------------- -void SwgSnapshot::encodeObjVars(const NetworkId &objectId, Archive::ByteStream &data) const -{ - PROFILER_AUTO_BLOCK_DEFINE("encodeObjVars"); - static std::vector commands; - commands.clear(); +void SwgSnapshot::encodeObjVars(const NetworkId &objectId, Archive::ByteStream &data) const { + PROFILER_AUTO_BLOCK_DEFINE("encodeObjVars"); + static std::vector commands; + commands.clear(); - m_objvarBuffer.getObjvarsForObject(objectId,commands); - DynamicVariableList::MapType::pack(data, commands); + m_objvarBuffer.getObjvarsForObject(objectId, commands); + DynamicVariableList::MapType::pack(data, commands); } // ---------------------------------------------------------------------- -void SwgSnapshot::decodeObjVarFreeFlags(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline) -{ - UNREF(isBaseline); - int freePositions; - Archive::get(data,freePositions); - m_objectTableBuffer.decodeObjVarFreeFlags(objectId, freePositions); +void SwgSnapshot::decodeObjVarFreeFlags(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline) { + UNREF(isBaseline); + int freePositions; + Archive::get(data, freePositions); + m_objectTableBuffer.decodeObjVarFreeFlags(objectId, freePositions); } // ---------------------------------------------------------------------- -void SwgSnapshot::encodeObjVarFreeFlags(const NetworkId & objectId, Archive::ByteStream &data) const -{ - PROFILER_AUTO_BLOCK_DEFINE("encodeObjVarFreeFlags"); - int freePositions = m_objectTableBuffer.encodeObjVarFreeFlags(objectId); - Archive::put(data, freePositions); +void SwgSnapshot::encodeObjVarFreeFlags(const NetworkId &objectId, Archive::ByteStream &data) const { + PROFILER_AUTO_BLOCK_DEFINE("encodeObjVarFreeFlags"); + int freePositions = m_objectTableBuffer.encodeObjVarFreeFlags(objectId); + Archive::put(data, freePositions); } // ---------------------------------------------------------------------- -void SwgSnapshot::decodeScriptObject(NetworkId const & objectId, Archive::ReadIterator &data, bool /* isBaseline */) -{ - std::string packedScriptList; - Archive::get(data,packedScriptList); +void SwgSnapshot::decodeScriptObject(NetworkId const &objectId, Archive::ReadIterator &data, bool /* isBaseline */) { + std::string packedScriptList; + Archive::get(data, packedScriptList); - if (packedScriptList.length()==0) - packedScriptList=' '; // avoid confusing an empty list with nullptr + if (packedScriptList.length() == 0) { + packedScriptList = ' '; + } // avoid confusing an empty list with nullptr - DBSchema::ObjectBufferRow *row=m_objectTableBuffer.findRowByIndex(objectId); - if (row==nullptr) - row=m_objectTableBuffer.addEmptyRow(objectId); + DBSchema::ObjectBufferRow *row = m_objectTableBuffer.findRowByIndex(objectId); + if (row == nullptr) { + row = m_objectTableBuffer.addEmptyRow(objectId); + } - row->script_list=packedScriptList; - m_scriptBuffer.clearScripts(objectId); + row->script_list = packedScriptList; + m_scriptBuffer.clearScripts(objectId); } // ---------------------------------------------------------------------- -void SwgSnapshot::encodeScriptObject(const NetworkId &objectId, Archive::ByteStream &data) const -{ - PROFILER_AUTO_BLOCK_DEFINE("encodeScriptObject"); - const DBSchema::ObjectBufferRow *row=m_objectTableBuffer.findConstRowByIndex(objectId); - if (row) - { - std::string temp; - row->script_list.getValue(temp); - if (temp.empty()) - { - // Object might have a non-converted script list - std::vector scripts; - m_scriptBuffer.getScriptsForObject(objectId, scripts); - - for (std::vector::const_iterator i=scripts.begin(); i!=scripts.end(); ++i) - { - temp+=(*i)+':'; - } - } - Archive::put(data,temp); - } +void SwgSnapshot::encodeScriptObject(const NetworkId &objectId, Archive::ByteStream &data) const { + PROFILER_AUTO_BLOCK_DEFINE("encodeScriptObject"); + const DBSchema::ObjectBufferRow *row = m_objectTableBuffer.findConstRowByIndex(objectId); + if (row) { + std::string temp; + row->script_list.getValue(temp); + if (temp.empty()) { + // Object might have a non-converted script list + std::vector scripts; + m_scriptBuffer.getScriptsForObject(objectId, scripts); + + for (std::vector::const_iterator i = scripts.begin(); i != scripts.end(); ++i) { + temp += (*i) + ':'; + } + } + Archive::put(data, temp); + } } // ---------------------------------------------------------------------- -void SwgSnapshot::decodeAttributes(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline, int offset) -{ - if (isBaseline) - { - size_t size, baselineCommandCount; - Archive::get(data, size); - Archive::get(data, baselineCommandCount); +void +SwgSnapshot::decodeAttributes(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline, int offset) { + if (isBaseline) { + size_t size, baselineCommandCount; + Archive::get(data, size); + Archive::get(data, baselineCommandCount); - Attributes::Value temp; - for (size_t i=0; i VectorType; - size_t numCommands, baselineCommandCount; - Archive::get(data, numCommands); - Archive::get(data, baselineCommandCount); - for (size_t count=0; count VectorType; + size_t numCommands, baselineCommandCount; + Archive::get(data, numCommands); + Archive::get(data, baselineCommandCount); + for (size_t count = 0; count < numCommands; ++count) { + unsigned char cmd;// datatype? + uint16 index; - switch (cmd) - { - case VectorType::Command::ERASE: - FATAL(true,("AutoDeltaVector::Command::ERASE is not supported for attributes.\n")); + Archive::get(data, cmd); - case VectorType::Command::INSERT: - FATAL(true,("AutoDeltaVector::Command::INSERT is not supported for attributes.\n")); - - case VectorType::Command::SET: - { - Archive::get(data,index); - Attributes::Value value; - Archive::get(data,value); + switch (cmd) { + case VectorType::Command::ERASE: + FATAL(true, ("AutoDeltaVector::Command::ERASE is not supported for attributes.\n")); + + case VectorType::Command::INSERT: + FATAL(true, ("AutoDeltaVector::Command::INSERT is not supported for attributes.\n")); + + case VectorType::Command::SET: { + Archive::get(data, index); + Attributes::Value value; + Archive::get(data, value); // DEBUG_REPORT_LOG(true,("Got Attribute SET with object id %s, index %i, value %i\n",objectId.getValueString().c_str(),index,value)); - m_creatureObjectBuffer.setAttribute(objectId,index+offset,value); - break; - } - - case VectorType::Command::SETALL: - FATAL(true,("AutoDeltaVector::Command::SETALL is not supported for attributes.\n")); + m_creatureObjectBuffer.setAttribute(objectId, index + offset, value); + break; + } - case VectorType::Command::CLEAR: - FATAL(true,("AutoDeltaVector::Command::CLEAR is not supported for attributes.\n")); + case VectorType::Command::SETALL: + FATAL(true, ("AutoDeltaVector::Command::SETALL is not supported for attributes.\n")); - default: - FATAL(true,("Unknown AutoDeltaVector command.\n")); - } - } - } + case VectorType::Command::CLEAR: + FATAL(true, ("AutoDeltaVector::Command::CLEAR is not supported for attributes.\n")); + + default: + FATAL(true, ("Unknown AutoDeltaVector command.\n")); + } + } + } } // ---------------------------------------------------------------------- -void SwgSnapshot::encodeAttributes(const NetworkId &objectId, Archive::ByteStream &data, int offset) const -{ - std::vector values; - m_creatureObjectBuffer.getAttributesForObject(objectId, values, offset, Attributes::NumberOfAttributes); - - Archive::put(data, Attributes::NumberOfAttributes); - Archive::put(data, static_cast(0)); // baselineCommandCount - if (values.size() < static_cast(Attributes::NumberOfAttributes)) - { - DEBUG_REPORT_LOG(true,("Object %s did not have valid attribute data in the database. Missing attributes will be set to 100.\n",objectId.getValueString().c_str())); - values.resize(Attributes::NumberOfAttributes, 100); - } - for (int i=0; i values; + m_creatureObjectBuffer.getAttributesForObject(objectId, values, offset, Attributes::NumberOfAttributes); + + Archive::put(data, Attributes::NumberOfAttributes); + Archive::put(data, static_cast(0)); // baselineCommandCount + if (values.size() < static_cast(Attributes::NumberOfAttributes)) { + DEBUG_REPORT_LOG(true, ("Object %s did not have valid attribute data in the database. Missing attributes will be set to 100.\n", objectId.getValueString().c_str())); + values.resize(Attributes::NumberOfAttributes, 100); + } + for (int i = 0; i < Attributes::NumberOfAttributes; ++i) { + Archive::put(data, values[i]); + } } // ---------------------------------------------------------------------- -void SwgSnapshot::decodePropertyList(const NetworkId &objectId, int listId, Archive::ReadIterator &data, bool isBaseline) -{ - typedef Archive::AutoDeltaSet SetType; - typedef std::vector CommandList; - CommandList commands; - if (isBaseline) - SetType::unpack(data, commands); - else - SetType::unpackDelta(data, commands); - for (CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i) - { - switch (i->cmd) - { - case SetType::Command::ERASE: - m_propertyListBuffer.deleteProperty(objectId, listId, i->value); - break; - case SetType::Command::INSERT: - m_propertyListBuffer.insertProperty(objectId, listId, i->value); - break; - case SetType::Command::CLEAR: - m_propertyListBuffer.clearProperties(objectId, listId); - break; - default: - FATAL(true,("Unknown AutoDeltaSet command.\n")); - } - } +void +SwgSnapshot::decodePropertyList(const NetworkId &objectId, int listId, Archive::ReadIterator &data, bool isBaseline) { + typedef Archive::AutoDeltaSet SetType; + typedef std::vector CommandList; + CommandList commands; + if (isBaseline) { + SetType::unpack(data, commands); + } else { + SetType::unpackDelta(data, commands); + } + for (CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i) { + switch (i->cmd) { + case SetType::Command::ERASE: + m_propertyListBuffer.deleteProperty(objectId, listId, i->value); + break; + case SetType::Command::INSERT: + m_propertyListBuffer.insertProperty(objectId, listId, i->value); + break; + case SetType::Command::CLEAR: + m_propertyListBuffer.clearProperties(objectId, listId); + break; + default: + FATAL(true, ("Unknown AutoDeltaSet command.\n")); + } + } } // ---------------------------------------------------------------------- -void SwgSnapshot::encodePropertyList(const NetworkId &objectId, int listId, Archive::ByteStream &data) const -{ - typedef Archive::AutoDeltaSet SetType; - typedef std::set ValuesType; - ValuesType values; +void SwgSnapshot::encodePropertyList(const NetworkId &objectId, int listId, Archive::ByteStream &data) const { + typedef Archive::AutoDeltaSet SetType; + typedef std::set ValuesType; + ValuesType values; - m_propertyListBuffer.getPropertyListForObject(objectId, listId, values); - SetType::pack(data, values); + m_propertyListBuffer.getPropertyListForObject(objectId, listId, values); + SetType::pack(data, values); } // ====================================================================== @@ -491,55 +440,53 @@ void SwgSnapshot::encodePropertyList(const NetworkId &objectId, int listId, Arch * * This function will load all the objects listed in m_oidList. */ -bool SwgSnapshot::load(DB::Session *session) -{ - DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(),("Load begin.\n")); +bool SwgSnapshot::load(DB::Session *session) { + DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(), ("Load begin.\n")); - std::string schema; - if (getUseGoldDatabase()) - schema=DatabaseProcess::getInstance().getGoldSchemaQualifier(); - else - schema=DatabaseProcess::getInstance().getSchemaQualifier(); - - session->setAutoCommitMode(false); + std::string schema; + if (getUseGoldDatabase()) { + schema = DatabaseProcess::getInstance().getGoldSchemaQualifier(); + } else { + schema = DatabaseProcess::getInstance().getSchemaQualifier(); + } - int objectCount = 0; - int objectsLocated; - - for (LocatorListType::iterator loc=m_locatorList.begin(); loc!=m_locatorList.end(); ++loc) - { - if (! ((*loc)->locateObjects(session, schema, objectsLocated))) - return false; - objectCount += objectsLocated; - } - LOG("LoadTimes",("Snapshot has %i objects",objectCount)); - DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(),("Objects Located.\n")); + session->setAutoCommitMode(false); - if (objectCount > 0) - { - registerTags(); - - DB::TagSet tags; - - if (! (m_objectTableBuffer.load(session, tags, schema, getUseGoldDatabase()))) - return false; - m_objectTableBuffer.getTags(tags); - - for (BufferListType::iterator buffer=m_bufferList.begin(); buffer!=m_bufferList.end(); ++buffer) - { - if (! ((*buffer)->load(session, tags, schema, getUseGoldDatabase()))) - return false; - } + int objectCount = 0; + int objectsLocated; - DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(),("Load end.\n")); - } - else - { - DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(),("Load skipped because there were no objects.\n")); - } - - session->commitTransaction(); // will cause temp tables to be erased - return true; + for (LocatorListType::iterator loc = m_locatorList.begin(); loc != m_locatorList.end(); ++loc) { + if (!((*loc)->locateObjects(session, schema, objectsLocated))) { + return false; + } + objectCount += objectsLocated; + } + LOG("LoadTimes", ("Snapshot has %i objects", objectCount)); + DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(), ("Objects Located.\n")); + + if (objectCount > 0) { + registerTags(); + + DB::TagSet tags; + + if (!(m_objectTableBuffer.load(session, tags, schema, getUseGoldDatabase()))) { + return false; + } + m_objectTableBuffer.getTags(tags); + + for (BufferListType::iterator buffer = m_bufferList.begin(); buffer != m_bufferList.end(); ++buffer) { + if (!((*buffer)->load(session, tags, schema, getUseGoldDatabase()))) { + return false; + } + } + + DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(), ("Load end.\n")); + } else { + DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(), ("Load skipped because there were no objects.\n")); + } + + session->commitTransaction(); // will cause temp tables to be erased + return true; } // ---------------------------------------------------------------------- @@ -553,174 +500,146 @@ bool SwgSnapshot::load(DB::Session *session) * * @return true if the objects were sent, false if they were not. */ -bool SwgSnapshot::send(GameServerConnection *connection) const -{ - PROFILER_AUTO_BLOCK_DEFINE("SwgSnapshot::send"); - - if (connection==0) - return false; +bool SwgSnapshot::send(GameServerConnection *connection) const { + PROFILER_AUTO_BLOCK_DEFINE("SwgSnapshot::send"); - DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(),("Sending Snapshot\n")); + if (connection == 0) { + return false; + } - PROFILER_BLOCK_DEFINE(prebaselinesBlock,"sendPreBaselinesCustomData"); - PROFILER_BLOCK_ENTER(prebaselinesBlock); - for (LocatorListType::const_iterator loc=m_locatorList.begin(); loc!=m_locatorList.end(); ++loc) - { - (*loc)->sendPreBaselinesCustomData(*connection); - } - PROFILER_BLOCK_LEAVE(prebaselinesBlock); + DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(), ("Sending Snapshot\n")); - OIDListType oidList; - m_objectTableBuffer.getObjectList(oidList); + PROFILER_BLOCK_DEFINE(prebaselinesBlock, "sendPreBaselinesCustomData"); + PROFILER_BLOCK_ENTER(prebaselinesBlock); + for (LocatorListType::const_iterator loc = m_locatorList.begin(); loc != m_locatorList.end(); ++loc) { + (*loc)->sendPreBaselinesCustomData(*connection); + } + PROFILER_BLOCK_LEAVE(prebaselinesBlock); - PROFILER_BLOCK_DEFINE(sendObjectData,"send object data"); - PROFILER_BLOCK_ENTER(sendObjectData); + OIDListType oidList; + m_objectTableBuffer.getObjectList(oidList); - static std::vector baselines; - baselines.clear(); + PROFILER_BLOCK_DEFINE(sendObjectData, "send object data"); + PROFILER_BLOCK_ENTER(sendObjectData); - for (OIDListType::iterator i=oidList.begin(); i!=oidList.end(); ++i) - { - PROFILER_BLOCK_DEFINE(createBlock, "object create and position"); - PROFILER_BLOCK_ENTER(createBlock); + static std::vector baselines; + baselines.clear(); - const DBSchema::ObjectBufferRow *baseData=m_objectTableBuffer.findConstRowByIndex((*i)); - NOT_NULL(baseData); - - NetworkId networkId=(*i); - DEBUG_FATAL(networkId != baseData->object_id.getValue(),("Object ID and row value didn't match")); + for (OIDListType::iterator i = oidList.begin(); i != oidList.end(); ++i) { + PROFILER_BLOCK_DEFINE(createBlock, "object create and position"); + PROFILER_BLOCK_ENTER(createBlock); - uint32 crc = baseData->object_template_id.getValue(); - CreateObjectByCrcMessage com(networkId, - crc, - static_cast(baseData->type_id.getValue()), - true, - NetworkId(baseData->contained_by.getValue())); + const DBSchema::ObjectBufferRow *baseData = m_objectTableBuffer.findConstRowByIndex((*i)); + NOT_NULL(baseData); + + NetworkId networkId = (*i); + DEBUG_FATAL(networkId != baseData->object_id.getValue(), ("Object ID and row value didn't match")); + + uint32 crc = baseData->object_template_id.getValue(); + CreateObjectByCrcMessage com(networkId, crc, static_cast(baseData->type_id.getValue()), true, NetworkId(baseData->contained_by.getValue())); // connection->send(com,true); - DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(),("\tSent CreateObjectMessage for object %s\n",networkId.getValueString().c_str())); + DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(), ("\tSent CreateObjectMessage for object %s\n", networkId.getValueString().c_str())); - Transform t; - Quaternion q(static_cast(baseData->quaternion_w.getValue()), - static_cast(baseData->quaternion_x.getValue()), - static_cast(baseData->quaternion_y.getValue()), - static_cast(baseData->quaternion_z.getValue())); - q.getTransform(&t); // reorients the transform according to the quaternion + Transform t; + Quaternion q(static_cast(baseData->quaternion_w.getValue()), static_cast(baseData->quaternion_x.getValue()), static_cast(baseData->quaternion_y.getValue()), static_cast(baseData->quaternion_z.getValue())); + q.getTransform(&t); // reorients the transform according to the quaternion - t.validate(); - - t.setPosition_p(Vector (static_cast(baseData->x.getValue()), - static_cast(baseData->y.getValue()), - static_cast(baseData->z.getValue()))); + t.validate(); - UpdateObjectPositionMessage uopm( - NetworkId(baseData->object_id.getValue()), - t, - t, - NetworkId(baseData->contained_by.getValue()), - baseData->slot_arrangement.getValue(), - NetworkId(baseData->load_with.getValue()), - baseData->player_controlled.getValue(), - false); + t.setPosition_p(Vector(static_cast(baseData->x.getValue()), static_cast(baseData->y.getValue()), static_cast(baseData->z.getValue()))); + + UpdateObjectPositionMessage uopm(NetworkId(baseData->object_id.getValue()), t, t, NetworkId(baseData->contained_by.getValue()), baseData->slot_arrangement.getValue(), NetworkId(baseData->load_with.getValue()), baseData->player_controlled.getValue(), false); // connection->send(uopm,true); - PROFILER_BLOCK_LEAVE(createBlock); + PROFILER_BLOCK_LEAVE(createBlock); - PROFILER_BLOCK_DEFINE(encodeData,"encode data"); - PROFILER_BLOCK_ENTER(encodeData); + PROFILER_BLOCK_DEFINE(encodeData, "encode data"); + PROFILER_BLOCK_ENTER(encodeData); - bool okToSend = encodeParentClientData(networkId,baseData->type_id.getValue(),baselines); - okToSend = okToSend && encodeClientData(networkId,baseData->type_id.getValue(),baselines); - okToSend = okToSend && encodeServerData(networkId,baseData->type_id.getValue(),baselines); - okToSend = okToSend && encodeSharedData(networkId,baseData->type_id.getValue(),baselines); + bool okToSend = encodeParentClientData(networkId, baseData->type_id.getValue(), baselines); + okToSend = okToSend && encodeClientData(networkId, baseData->type_id.getValue(), baselines); + okToSend = okToSend && encodeServerData(networkId, baseData->type_id.getValue(), baselines); + okToSend = okToSend && encodeSharedData(networkId, baseData->type_id.getValue(), baselines); - PROFILER_BLOCK_LEAVE(encodeData); - - if (okToSend) - { - PROFILER_AUTO_BLOCK_DEFINE("connection->send (baselines)"); - - connection->send(com,true); - connection->send(uopm,true); - } - else - { - (*i)=NetworkId::cms_invalid; - } - } + PROFILER_BLOCK_LEAVE(encodeData); - BatchBaselinesMessage bbm(baselines); - connection->send(bbm,true); + if (okToSend) { + PROFILER_AUTO_BLOCK_DEFINE("connection->send (baselines)"); - PROFILER_BLOCK_LEAVE(sendObjectData); + connection->send(com, true); + connection->send(uopm, true); + } else { + (*i) = NetworkId::cms_invalid; + } + } - PROFILER_BLOCK_DEFINE(sendEndBaselines,"send EndBaselines"); - PROFILER_BLOCK_ENTER(sendEndBaselines); - - // Send EndBaselines in reverse order (container & portal system requires this) - for (OIDListType::reverse_iterator r=oidList.rbegin(); r!=oidList.rend(); ++r) - { - if (*r != NetworkId::cms_invalid) - { - EndBaselinesMessage const ebm(*r); - connection->send(ebm,true); - } + BatchBaselinesMessage bbm(baselines); + connection->send(bbm, true); + + PROFILER_BLOCK_LEAVE(sendObjectData); + + PROFILER_BLOCK_DEFINE(sendEndBaselines, "send EndBaselines"); + PROFILER_BLOCK_ENTER(sendEndBaselines); + + // Send EndBaselines in reverse order (container & portal system requires this) + for (OIDListType::reverse_iterator r = oidList.rbegin(); r != oidList.rend(); ++r) { + if (*r != NetworkId::cms_invalid) { + EndBaselinesMessage const ebm(*r); + connection->send(ebm, true); + } // DEBUG_REPORT_LOG(true, ("\tSent EndBaselinesMessage for object %i\n",(*r).getValue())); - } - PROFILER_BLOCK_LEAVE(sendEndBaselines); + } + PROFILER_BLOCK_LEAVE(sendEndBaselines); - // Send resource data (if any) after all objects but before the post-baselines custom data - m_resourceTypeBuffer.sendResourceTypeObjects(*connection); - m_bountyHunterTargetBuffer.sendBountyHunterTargetMessage (*connection); + // Send resource data (if any) after all objects but before the post-baselines custom data + m_resourceTypeBuffer.sendResourceTypeObjects(*connection); + m_bountyHunterTargetBuffer.sendBountyHunterTargetMessage(*connection); - // Send post-baselines custom data, such as "UniverseComplete" messages, etc. - PROFILER_BLOCK_DEFINE(sendPostBaselinesCustomData,"sendPostBaselinesCustomData"); - PROFILER_BLOCK_ENTER(sendPostBaselinesCustomData); - - for (LocatorListType::const_iterator loc2=m_locatorList.begin(); loc2!=m_locatorList.end(); ++loc2) - { - (*loc2)->sendPostBaselinesCustomData(*connection); - } - PROFILER_BLOCK_LEAVE(sendPostBaselinesCustomData); + // Send post-baselines custom data, such as "UniverseComplete" messages, etc. + PROFILER_BLOCK_DEFINE(sendPostBaselinesCustomData, "sendPostBaselinesCustomData"); + PROFILER_BLOCK_ENTER(sendPostBaselinesCustomData); - // Send any MessageTos for these objects - // This must happen after EndBaselinesMessage is sent for all of the objects - { - PROFILER_AUTO_BLOCK_DEFINE("send MessageTos"); + for (LocatorListType::const_iterator loc2 = m_locatorList.begin(); loc2 != m_locatorList.end(); ++loc2) { + (*loc2)->sendPostBaselinesCustomData(*connection); + } + PROFILER_BLOCK_LEAVE(sendPostBaselinesCustomData); - m_messageBuffer.sendMessages(*connection); - for (OIDListType::const_iterator i=oidList.begin(); i!=oidList.end(); ++i) - { - if (*i != NetworkId::cms_invalid) - MessageToManager::getInstance().sendMessagesForObject(*i, *connection); - } - } + // Send any MessageTos for these objects + // This must happen after EndBaselinesMessage is sent for all of the objects + { + PROFILER_AUTO_BLOCK_DEFINE("send MessageTos"); - DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(),("Done sending Snapshot\n")); - return true; + m_messageBuffer.sendMessages(*connection); + for (OIDListType::const_iterator i = oidList.begin(); i != oidList.end(); ++i) { + if (*i != NetworkId::cms_invalid) { + MessageToManager::getInstance().sendMessagesForObject(*i, *connection); + } + } + } + + DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(), ("Done sending Snapshot\n")); + return true; } // ---------------------------------------------------------------------- -void SwgSnapshot::loadAttributes(DB::Session *session, NetworkId const & objectId) -{ - UNREF(session); +void SwgSnapshot::loadAttributes(DB::Session *session, NetworkId const &objectId) { + UNREF(session); } // ---------------------------------------------------------------------- -void SwgSnapshot::loadCommands(DB::Session *session, NetworkId const & objectId) -{ - UNREF(session); - UNREF(objectId); +void SwgSnapshot::loadCommands(DB::Session *session, NetworkId const &objectId) { + UNREF(session); + UNREF(objectId); } // ---------------------------------------------------------------------- -void SwgSnapshot::loadSkills(DB::Session *session, NetworkId const & objectId) -{ - UNREF(session); - UNREF(objectId); +void SwgSnapshot::loadSkills(DB::Session *session, NetworkId const &objectId) { + UNREF(session); + UNREF(objectId); } // ---------------------------------------------------------------------- @@ -728,11 +647,11 @@ void SwgSnapshot::loadSkills(DB::Session *session, NetworkId const & objectId) /** * Helper function to avoid having to put too much logic into generated code. */ -void SwgSnapshot::decodeMissionLocation (Archive::ReadIterator &data, DB::BindableDouble &x,DB::BindableDouble &y, DB::BindableDouble &z, DB::BindableString<500> &planet, DB::BindableString<500> ®ion_name,DB::BindableNetworkId &cell) const -{ - MissionLocation temp; - Archive::get(data,temp); - temp.packToDatabase(x,y,z,planet,region_name, cell); +void +SwgSnapshot::decodeMissionLocation(Archive::ReadIterator &data, DB::BindableDouble &x, DB::BindableDouble &y, DB::BindableDouble &z, DB::BindableString<500> &planet, DB::BindableString<500> ®ion_name, DB::BindableNetworkId &cell) const { + MissionLocation temp; + Archive::get(data, temp); + temp.packToDatabase(x, y, z, planet, region_name, cell); } // ---------------------------------------------------------------------- @@ -740,491 +659,456 @@ void SwgSnapshot::decodeMissionLocation (Archive::ReadIterator &data, DB::Binda /** * Helper function to avoid having to put too much logic into generated code. */ -void SwgSnapshot::encodeMissionLocation (Archive::ByteStream &data, const DB::BindableDouble &x,const DB::BindableDouble &y, const DB::BindableDouble &z, const DB::BindableString<500> &planet, const DB::BindableString<500> ®ion_name, const DB::BindableNetworkId &cell) const -{ - MissionLocation temp; - temp.unpackFromDatabase(x,y,z,planet,region_name, cell); - Archive::put(data,temp); +void +SwgSnapshot::encodeMissionLocation(Archive::ByteStream &data, const DB::BindableDouble &x, const DB::BindableDouble &y, const DB::BindableDouble &z, const DB::BindableString<500> &planet, const DB::BindableString<500> ®ion_name, const DB::BindableNetworkId &cell) const { + MissionLocation temp; + temp.unpackFromDatabase(x, y, z, planet, region_name, cell); + Archive::put(data, temp); } // ---------------------------------------------------------------------- -void SwgSnapshot::decodeVector(Archive::ReadIterator &data, DB::BindableDouble &x,DB::BindableDouble &y, DB::BindableDouble &z) const -{ - Vector temp; - Archive::get(data,temp); - x.setValue(temp.x); - y.setValue(temp.y); - z.setValue(temp.z); +void +SwgSnapshot::decodeVector(Archive::ReadIterator &data, DB::BindableDouble &x, DB::BindableDouble &y, DB::BindableDouble &z) const { + Vector temp; + Archive::get(data, temp); + x.setValue(temp.x); + y.setValue(temp.y); + z.setValue(temp.z); } // ---------------------------------------------------------------------- -void SwgSnapshot::encodeVector(Archive::ByteStream &data, const DB::BindableDouble &x, const DB::BindableDouble &y, const DB::BindableDouble &z) const -{ - Vector temp; - x.getValue(temp.x); - y.getValue(temp.y); - z.getValue(temp.z); - Archive::put(data,temp); +void +SwgSnapshot::encodeVector(Archive::ByteStream &data, const DB::BindableDouble &x, const DB::BindableDouble &y, const DB::BindableDouble &z) const { + Vector temp; + x.getValue(temp.x); + y.getValue(temp.y); + z.getValue(temp.z); + Archive::put(data, temp); } // ---------------------------------------------------------------------- -void SwgSnapshot::decodeStringId(Archive::ReadIterator &data,DB::BufferString &table,DB::BufferString &text) const -{ - StringId temp; - Archive::get(data,temp); - temp.packToDatabase(table,text); +void SwgSnapshot::decodeStringId(Archive::ReadIterator &data, DB::BufferString &table, DB::BufferString &text) const { + StringId temp; + Archive::get(data, temp); + temp.packToDatabase(table, text); } // ---------------------------------------------------------------------- -void SwgSnapshot::encodeStringId(Archive::ByteStream &data, const DB::BufferString &table, const DB::BufferString &text) const -{ - StringId temp; - temp.unpackFromDatabase(table,text); - Archive::put(data,temp); +void +SwgSnapshot::encodeStringId(Archive::ByteStream &data, const DB::BufferString &table, const DB::BufferString &text) const { + StringId temp; + temp.unpackFromDatabase(table, text); + Archive::put(data, temp); } // ---------------------------------------------------------------------- -void SwgSnapshot::ignorePersistedFlag(const NetworkId &objectId, Archive::ReadIterator &data) const -{ - bool persisted; - Archive::get(data,persisted); +void SwgSnapshot::ignorePersistedFlag(const NetworkId &objectId, Archive::ReadIterator &data) const { + bool persisted; + Archive::get(data, persisted); - UNREF(objectId); + UNREF(objectId); } // ---------------------------------------------------------------------- -void SwgSnapshot::decodeLocationDataList(const NetworkId &objectId, size_t listId, Archive::ReadIterator &data, bool isBaseline) -{ - if (isBaseline) - { - size_t size, baselineCommandCount; - Archive::get(data, size); - Archive::get(data, baselineCommandCount); - - LocationData temp; - for (size_t i=0; i VectorType; - size_t numCommands, baselineCommandCount; - Archive::get(data, numCommands); - Archive::get(data, baselineCommandCount); - for (size_t count=0; count VectorType; + size_t numCommands, baselineCommandCount; + Archive::get(data, numCommands); + Archive::get(data, baselineCommandCount); + for (size_t count = 0; count < numCommands; ++count) { + unsigned char cmd; + uint16 index; - case VectorType::Command::INSERT: - { - LocationData value; - Archive::get(data,value); - m_locationBuffer.insert(objectId,listId,index,value); - break; - } - - case VectorType::Command::SET: - { - LocationData value; - Archive::get(data,value); - m_locationBuffer.set(objectId,listId,index,value); - break; - } - - case VectorType::Command::SETALL: - FATAL(true,("AutoDeltaVector::Command::SETALL is not supported for location data lists.\n")); + Archive::get(data, cmd); + Archive::get(data, index); - case VectorType::Command::CLEAR: - FATAL(true,("AutoDeltaVector::Command::CLEAR is not supported for location data lists.\n")); - - default: - FATAL(true,("Unknown AutoDeltaVector command.\n")); - } - } - } + switch (cmd) { + case VectorType::Command::ERASE: + m_locationBuffer.erase(objectId, listId, index); + break; + + case VectorType::Command::INSERT: { + LocationData value; + Archive::get(data, value); + m_locationBuffer.insert(objectId, listId, index, value); + break; + } + + case VectorType::Command::SET: { + LocationData value; + Archive::get(data, value); + m_locationBuffer.set(objectId, listId, index, value); + break; + } + + case VectorType::Command::SETALL: + FATAL(true, ("AutoDeltaVector::Command::SETALL is not supported for location data lists.\n")); + + case VectorType::Command::CLEAR: + FATAL(true, ("AutoDeltaVector::Command::CLEAR is not supported for location data lists.\n")); + + default: + FATAL(true, ("Unknown AutoDeltaVector command.\n")); + } + } + } } // ---------------------------------------------------------------------- -void SwgSnapshot::encodeLocationDataList(const NetworkId &objectId, size_t listId, Archive::ByteStream &data) const -{ - std::vector values; - m_locationBuffer.getLocationList(objectId, listId, values); - - Archive::put(data, values.size()); - Archive::put(data, static_cast(0)); - for (std::vector::iterator i=values.begin(); i!=values.end(); ++i) - { - Archive::put(data,*i); - } +void SwgSnapshot::encodeLocationDataList(const NetworkId &objectId, size_t listId, Archive::ByteStream &data) const { + std::vector values; + m_locationBuffer.getLocationList(objectId, listId, values); + + Archive::put(data, values.size()); + Archive::put(data, static_cast(0)); + for (std::vector::iterator i = values.begin(); i != values.end(); ++i) { + Archive::put(data, *i); + } } // ---------------------------------------------------------------------- -void SwgSnapshot::decodeExperience(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline) -{ - typedef Archive::AutoDeltaMap MapType; - typedef std::vector CommandList; - CommandList commands; - if (isBaseline) - MapType::unpack(data, commands); - else - MapType::unpackDelta(data, commands); - for (CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i) - { - switch ((*i).cmd) - { - case MapType::Command::ERASE: - m_experienceBuffer.removeExperience(objectId, (*i).key); - break; +void SwgSnapshot::decodeExperience(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline) { + typedef Archive::AutoDeltaMap MapType; + typedef std::vector CommandList; + CommandList commands; + if (isBaseline) { + MapType::unpack(data, commands); + } else { + MapType::unpackDelta(data, commands); + } + for (CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i) { + switch ((*i).cmd) { + case MapType::Command::ERASE: + m_experienceBuffer.removeExperience(objectId, (*i).key); + break; - case MapType::Command::ADD: - case MapType::Command::SET: - m_experienceBuffer.setExperience(objectId, (*i).key, (*i).value); - break; + case MapType::Command::ADD: + case MapType::Command::SET: + m_experienceBuffer.setExperience(objectId, (*i).key, (*i).value); + break; - default: - FATAL(true,("Unknown AutoDeltaMap command.\n")); - } - } + default: + FATAL(true, ("Unknown AutoDeltaMap command.\n")); + } + } } // ---------------------------------------------------------------------- -void SwgSnapshot::encodeExperience(const NetworkId &objectId, Archive::ByteStream &data) const -{ - typedef std::vector > ValuesType; - ValuesType values; - m_experienceBuffer.getExperienceForObject(objectId, values); - - Archive::put(data, values.size()); - Archive::put(data, static_cast(0)); // baselineCommandCount - for (ValuesType::const_iterator i=values.begin(); i!=values.end(); ++i) - { - const unsigned char command = 0; //ADD - Archive::put(data, command); - Archive::put(data,(*i).first); - Archive::put(data,(*i).second); - } +void SwgSnapshot::encodeExperience(const NetworkId &objectId, Archive::ByteStream &data) const { + typedef std::vector > ValuesType; + ValuesType values; + m_experienceBuffer.getExperienceForObject(objectId, values); + + Archive::put(data, values.size()); + Archive::put(data, static_cast(0)); // baselineCommandCount + for (ValuesType::const_iterator i = values.begin(); i != values.end(); ++i) { + const unsigned char command = 0; //ADD + Archive::put(data, command); + Archive::put(data, (*i).first); + Archive::put(data, (*i).second); + } } // ---------------------------------------------------------------------- -void SwgSnapshot::decodeBattlefieldParticipants(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline) -{ - typedef Archive::AutoDeltaMap MapType; - typedef std::vector CommandList; - CommandList commands; - if (isBaseline) - MapType::unpack(data, commands); - else - MapType::unpackDelta(data, commands); - for (CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i) - { - switch ((*i).cmd) - { - case MapType::Command::ERASE: - m_battlefieldParticipantBuffer.removeParticipantForRegion(objectId, (*i).key); - break; +void +SwgSnapshot::decodeBattlefieldParticipants(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline) { + typedef Archive::AutoDeltaMap MapType; + typedef std::vector CommandList; + CommandList commands; + if (isBaseline) { + MapType::unpack(data, commands); + } else { + MapType::unpackDelta(data, commands); + } + for (CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i) { + switch ((*i).cmd) { + case MapType::Command::ERASE: + m_battlefieldParticipantBuffer.removeParticipantForRegion(objectId, (*i).key); + break; - case MapType::Command::ADD: - case MapType::Command::SET: - m_battlefieldParticipantBuffer.setParticipantForRegion(objectId, (*i).key, (*i).value); - break; + case MapType::Command::ADD: + case MapType::Command::SET: + m_battlefieldParticipantBuffer.setParticipantForRegion(objectId, (*i).key, (*i).value); + break; - default: - FATAL(true,("Unknown AutoDeltaMap command.\n")); - } - } + default: + FATAL(true, ("Unknown AutoDeltaMap command.\n")); + } + } } // ---------------------------------------------------------------------- -void SwgSnapshot::encodeBattlefieldParticipants(const NetworkId &objectId, Archive::ByteStream &data) const -{ - typedef std::vector > ValuesType; - ValuesType values; - m_battlefieldParticipantBuffer.getParticipantsForRegion(objectId, values); - - Archive::put(data, values.size()); - Archive::put(data, static_cast(0)); // baselineCommandCount - for (ValuesType::const_iterator i=values.begin(); i!=values.end(); ++i) - { - const unsigned char command = 0; //ADD - Archive::put(data, command); - Archive::put(data,(*i).first); - Archive::put(data,(*i).second); - } +void SwgSnapshot::encodeBattlefieldParticipants(const NetworkId &objectId, Archive::ByteStream &data) const { + typedef std::vector > ValuesType; + ValuesType values; + m_battlefieldParticipantBuffer.getParticipantsForRegion(objectId, values); + + Archive::put(data, values.size()); + Archive::put(data, static_cast(0)); // baselineCommandCount + for (ValuesType::const_iterator i = values.begin(); i != values.end(); ++i) { + const unsigned char command = 0; //ADD + Archive::put(data, command); + Archive::put(data, (*i).first); + Archive::put(data, (*i).second); + } } // ---------------------------------------------------------------------- -void SwgSnapshot::decodeManufactureSchematicAttributes(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline) -{ - typedef Archive::AutoDeltaMap MapType; - typedef std::vector CommandList; - CommandList commands; - if (isBaseline) - MapType::unpack(data, commands); - else - MapType::unpackDelta(data, commands); - for (CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i) - { - switch ((*i).cmd) - { - case MapType::Command::ERASE: - m_manufactureSchematicAttributeBuffer.removeManufactureSchematicAttribute(objectId,(*i).key.getCanonicalRepresentation()); - break; +void +SwgSnapshot::decodeManufactureSchematicAttributes(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline) { + typedef Archive::AutoDeltaMap MapType; + typedef std::vector CommandList; + CommandList commands; + if (isBaseline) { + MapType::unpack(data, commands); + } else { + MapType::unpackDelta(data, commands); + } + for (CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i) { + switch ((*i).cmd) { + case MapType::Command::ERASE: + m_manufactureSchematicAttributeBuffer.removeManufactureSchematicAttribute(objectId, (*i).key.getCanonicalRepresentation()); + break; - case MapType::Command::ADD: - case MapType::Command::SET: - m_manufactureSchematicAttributeBuffer.setManufactureSchematicAttribute(objectId,(*i).key.getCanonicalRepresentation(),(*i).value); - break; + case MapType::Command::ADD: + case MapType::Command::SET: + m_manufactureSchematicAttributeBuffer.setManufactureSchematicAttribute(objectId, (*i).key.getCanonicalRepresentation(), (*i).value); + break; - default: - FATAL(true,("Unknown AutoDeltaMap command.\n")); - } - } + default: + FATAL(true, ("Unknown AutoDeltaMap command.\n")); + } + } } -void SwgSnapshot::encodeManufactureSchematicAttributes(const NetworkId & objectId, Archive::ByteStream &data) const -{ - typedef std::vector > ValuesType; - ValuesType values; - m_manufactureSchematicAttributeBuffer.getDataForObject(objectId, values); - - Archive::put(data, values.size()); - Archive::put(data, static_cast(0)); // baselineCommandCount - for (ValuesType::const_iterator i=values.begin(); i!=values.end(); ++i) - { - const unsigned char command = 0; //ADD - Archive::put(data, command); - StringId temp((*i).first); - Archive::put(data,temp); - Archive::put(data,(*i).second); - } +void SwgSnapshot::encodeManufactureSchematicAttributes(const NetworkId &objectId, Archive::ByteStream &data) const { + typedef std::vector > ValuesType; + ValuesType values; + m_manufactureSchematicAttributeBuffer.getDataForObject(objectId, values); + + Archive::put(data, values.size()); + Archive::put(data, static_cast(0)); // baselineCommandCount + for (ValuesType::const_iterator i = values.begin(); i != values.end(); ++i) { + const unsigned char command = 0; //ADD + Archive::put(data, command); + StringId temp((*i).first); + Archive::put(data, temp); + Archive::put(data, (*i).second); + } } // ---------------------------------------------------------------------- -void SwgSnapshot::decodeMatchMakingId(Archive::ReadIterator &data, DB::BufferString &column) const -{ - MatchMakingId mmid; - std::string temp; - Archive::get(data, mmid); - mmid.packBitString(temp); - column.setValue(temp); +void SwgSnapshot::decodeMatchMakingId(Archive::ReadIterator &data, DB::BufferString &column) const { + MatchMakingId mmid; + std::string temp; + Archive::get(data, mmid); + mmid.packBitString(temp); + column.setValue(temp); } // ---------------------------------------------------------------------- -void SwgSnapshot::encodeMatchMakingId(Archive::ByteStream &data, const DB::BufferString &column) const -{ - MatchMakingId mmid; - std::string temp; - column.getValue(temp); - mmid.unPackBitString(temp); - Archive::put(data,mmid); +void SwgSnapshot::encodeMatchMakingId(Archive::ByteStream &data, const DB::BufferString &column) const { + MatchMakingId mmid; + std::string temp; + column.getValue(temp); + mmid.unPackBitString(temp); + Archive::put(data, mmid); } // ---------------------------------------------------------------------- -void SwgSnapshot::decodeComponents(NetworkId const & objectId, Archive::ReadIterator &data, bool isBaseline) -{ - typedef Archive::AutoDeltaSet SetType; - typedef std::vector CommandList; - CommandList commands; - if (isBaseline) - SetType::unpack(data, commands); - else - SetType::unpackDelta(data, commands); - for (CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i) - { - switch (i->cmd) - { - case SetType::Command::ERASE: - { - char buffer[50]; - _itoa(i->value,buffer,10); - m_propertyListBuffer.deleteProperty(objectId, 11, buffer); - break; - } - - case SetType::Command::INSERT: - { - char buffer[50]; - _itoa(i->value,buffer,10); - m_propertyListBuffer.insertProperty(objectId, 11, buffer); - break; - } - - case SetType::Command::CLEAR: - m_propertyListBuffer.clearProperties(objectId, 11); - break; +void SwgSnapshot::decodeComponents(NetworkId const &objectId, Archive::ReadIterator &data, bool isBaseline) { + typedef Archive::AutoDeltaSet SetType; + typedef std::vector CommandList; + CommandList commands; + if (isBaseline) { + SetType::unpack(data, commands); + } else { + SetType::unpackDelta(data, commands); + } + for (CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i) { + switch (i->cmd) { + case SetType::Command::ERASE: { + char buffer[50]; + _itoa(i->value, buffer, 10); + m_propertyListBuffer.deleteProperty(objectId, 11, buffer); + break; + } - default: - FATAL(true,("Unknown AutoDeltaSet command.\n")); - } - } + case SetType::Command::INSERT: { + char buffer[50]; + _itoa(i->value, buffer, 10); + m_propertyListBuffer.insertProperty(objectId, 11, buffer); + break; + } + + case SetType::Command::CLEAR: + m_propertyListBuffer.clearProperties(objectId, 11); + break; + + default: + FATAL(true, ("Unknown AutoDeltaSet command.\n")); + } + } } // ---------------------------------------------------------------------- -void SwgSnapshot::encodeComponents(const NetworkId &objectId, Archive::ByteStream &data) const -{ - typedef Archive::AutoDeltaSet SetType; - typedef std::set PackedValuesType; - typedef std::set ValuesType; +void SwgSnapshot::encodeComponents(const NetworkId &objectId, Archive::ByteStream &data) const { + typedef Archive::AutoDeltaSet SetType; + typedef std::set PackedValuesType; + typedef std::set ValuesType; - PackedValuesType packedValues; - m_propertyListBuffer.getPropertyListForObject(objectId, 11, packedValues); + PackedValuesType packedValues; + m_propertyListBuffer.getPropertyListForObject(objectId, 11, packedValues); - ValuesType values; - for (PackedValuesType::const_iterator i = packedValues.begin(); i != packedValues.end(); ++i) - values.insert(atoi((*i).c_str())); + ValuesType values; + for (PackedValuesType::const_iterator i = packedValues.begin(); i != packedValues.end(); ++i) { + values.insert(atoi((*i).c_str())); + } - SetType::pack(data, values); + SetType::pack(data, values); } // ---------------------------------------------------------------------- -void SwgSnapshot::decodeLocation (Archive::ReadIterator &data, DB::BindableDouble &x,DB::BindableDouble &y, DB::BindableDouble &z, DB::BindableNetworkId &cell, DB::BindableLong &planet) const -{ - Location temp; - Archive::get(data,temp); - Vector vec=temp.getCoordinates(); - x=vec.x; - y=vec.y; - z=vec.z; - cell=temp.getCell(); - planet=temp.getSceneIdCrc(); +void +SwgSnapshot::decodeLocation(Archive::ReadIterator &data, DB::BindableDouble &x, DB::BindableDouble &y, DB::BindableDouble &z, DB::BindableNetworkId &cell, DB::BindableLong &planet) const { + Location temp; + Archive::get(data, temp); + Vector vec = temp.getCoordinates(); + x = vec.x; + y = vec.y; + z = vec.z; + cell = temp.getCell(); + planet = temp.getSceneIdCrc(); } // ---------------------------------------------------------------------- -void SwgSnapshot::encodeLocation (Archive::ByteStream &data, const DB::BindableDouble &x,const DB::BindableDouble &y, const DB::BindableDouble &z, const DB::BindableNetworkId &cell, const DB::BindableLong &planet) const -{ - Location temp(Vector(static_cast(x.getValue()),static_cast(y.getValue()),static_cast(z.getValue())),cell.getValue(),planet.getValue()); - Archive::put(data,temp); +void +SwgSnapshot::encodeLocation(Archive::ByteStream &data, const DB::BindableDouble &x, const DB::BindableDouble &y, const DB::BindableDouble &z, const DB::BindableNetworkId &cell, const DB::BindableLong &planet) const { + Location temp(Vector(static_cast(x.getValue()), static_cast(y.getValue()), static_cast(z.getValue())), cell.getValue(), planet.getValue()); + Archive::put(data, temp); } // ---------------------------------------------------------------------- -void SwgSnapshot::decodeWaypoints(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline) -{ - typedef Archive::AutoDeltaMap MapType; - typedef std::vector CommandList; - CommandList commands; - if (isBaseline) - MapType::unpack(data, commands); - else - MapType::unpackDelta(data, commands); - for (CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i) - { - switch ((*i).cmd) - { - case MapType::Command::ERASE: - m_waypointBuffer.removeWaypoint(objectId, (*i).key); - break; +void SwgSnapshot::decodeWaypoints(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline) { + typedef Archive::AutoDeltaMap MapType; + typedef std::vector CommandList; + CommandList commands; + if (isBaseline) { + MapType::unpack(data, commands); + } else { + MapType::unpackDelta(data, commands); + } + for (CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i) { + switch ((*i).cmd) { + case MapType::Command::ERASE: + m_waypointBuffer.removeWaypoint(objectId, (*i).key); + break; - case MapType::Command::ADD: - case MapType::Command::SET: - m_waypointBuffer.setWaypoint(objectId, (*i).key, (*i).value); - break; + case MapType::Command::ADD: + case MapType::Command::SET: + m_waypointBuffer.setWaypoint(objectId, (*i).key, (*i).value); + break; - default: - FATAL(true,("Unknown AutoDeltaMap command.\n")); - } - } + default: + FATAL(true, ("Unknown AutoDeltaMap command.\n")); + } + } } // ---------------------------------------------------------------------- -void SwgSnapshot::encodeWaypoints(const NetworkId &objectId, Archive::ByteStream &data) const -{ - typedef std::vector ValuesType; - ValuesType values; - m_waypointBuffer.getWaypointsForObject(objectId, values); - - Archive::put(data, values.size()); - Archive::put(data, static_cast(0)); // baselineCommandCount - for (ValuesType::const_iterator i=values.begin(); i!=values.end(); ++i) - { - const unsigned char command = 0; //ADD - Archive::put(data, command); - Archive::put(data,i->m_networkId); - Archive::put(data,*i); - } +void SwgSnapshot::encodeWaypoints(const NetworkId &objectId, Archive::ByteStream &data) const { + typedef std::vector ValuesType; + ValuesType values; + m_waypointBuffer.getWaypointsForObject(objectId, values); + + Archive::put(data, values.size()); + Archive::put(data, static_cast(0)); // baselineCommandCount + for (ValuesType::const_iterator i = values.begin(); i != values.end(); ++i) { + const unsigned char command = 0; //ADD + Archive::put(data, command); + Archive::put(data, i->m_networkId); + Archive::put(data, *i); + } } // ---------------------------------------------------------------------- -void SwgSnapshot::decodeSingleWaypoint(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline) -{ - UNREF(isBaseline); // parameter is there for consistency. - - PersistableWaypoint value; - Archive::get(data, value); - - m_waypointBuffer.setWaypoint(objectId,value.m_networkId,value); +void SwgSnapshot::decodeSingleWaypoint(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline) { + UNREF(isBaseline); // parameter is there for consistency. + + PersistableWaypoint value; + Archive::get(data, value); + + m_waypointBuffer.setWaypoint(objectId, value.m_networkId, value); } // ---------------------------------------------------------------------- -void SwgSnapshot::encodeSingleWaypoint(const NetworkId &objectId, Archive::ByteStream &data) const -{ - typedef std::vector ValuesType; - ValuesType values; - m_waypointBuffer.getWaypointsForObject(objectId, values); +void SwgSnapshot::encodeSingleWaypoint(const NetworkId &objectId, Archive::ByteStream &data) const { + typedef std::vector ValuesType; + ValuesType values; + m_waypointBuffer.getWaypointsForObject(objectId, values); - DEBUG_FATAL(values.size()!=1,("Object %s should have exactly 1 waypoint, but it has %i",objectId.getValueString().c_str(),values.size())); - - ValuesType::const_iterator i=values.begin(); - if (i!=values.end()) - Archive::put(data,*i); - else - Archive::put(data,PersistableWaypoint()); + DEBUG_FATAL(values.size() != + 1, ("Object %s should have exactly 1 waypoint, but it has %i", objectId.getValueString().c_str(), values.size())); + + ValuesType::const_iterator i = values.begin(); + if (i != values.end()) { + Archive::put(data, *i); + } else { + Archive::put(data, PersistableWaypoint()); + } } // ---------------------------------------------------------------------- -void SwgSnapshot::saveCompleted() -{ - m_messageBuffer.removeSavedMessagesFromMemory(); - Snapshot::saveCompleted(); +void SwgSnapshot::saveCompleted() { + m_messageBuffer.removeSavedMessagesFromMemory(); + Snapshot::saveCompleted(); } // ---------------------------------------------------------------------- -void SwgSnapshot::handleCommoditiesDataMessage(const MessageDispatch::MessageBase & message) -{ - UNREF(message); - DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(),("Received Commodities Data in non-commodities snapshot!\n")); +void SwgSnapshot::handleCommoditiesDataMessage(const MessageDispatch::MessageBase &message) { + UNREF(message); + DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(), ("Received Commodities Data in non-commodities snapshot!\n")); } // ---------------------------------------------------------------------- -void SwgSnapshot::startLoadAfterSaveComplete() -{ - DEBUG_WARNING(true,("Called startLoadAfterSaveComplete in non-commodities snapshot!\n")); +void SwgSnapshot::startLoadAfterSaveComplete() { + DEBUG_WARNING(true, ("Called startLoadAfterSaveComplete in non-commodities snapshot!\n")); } // ---------------------------------------------------------------------- @@ -1233,145 +1117,136 @@ void SwgSnapshot::startLoadAfterSaveComplete() * ordinary (non-demand-load) containers. The live database will be checked * for objects inside these objects. */ -void SwgSnapshot::getWorldContainers(std::vector &containers) const -{ - m_objectTableBuffer.getWorldContainers(containers); +void SwgSnapshot::getWorldContainers(std::vector &containers) const { + m_objectTableBuffer.getWorldContainers(containers); } // ---------------------------------------------------------------------- -void SwgSnapshot::handleAddResourceTypeMessage (AddResourceTypeMessage const & message) -{ - m_resourceTypeBuffer.handleAddResourceTypeMessage(message); +void SwgSnapshot::handleAddResourceTypeMessage(AddResourceTypeMessage const &message) { + m_resourceTypeBuffer.handleAddResourceTypeMessage(message); } // ---------------------------------------------------------------------- -void SwgSnapshot::handleBountyHunterTargetMessage (const BountyHunterTargetMessage &message) -{ - m_bountyHunterTargetBuffer.setBountyHunterTarget(message.GetObjectId(), message.GetTargetId()); +void SwgSnapshot::handleBountyHunterTargetMessage(const BountyHunterTargetMessage &message) { + m_bountyHunterTargetBuffer.setBountyHunterTarget(message.GetObjectId(), message.GetTargetId()); } // ---------------------------------------------------------------------- -void SwgSnapshot::getMoneyFromOfflineObject(uint32 replyServer, NetworkId const & sourceObject, int amount, NetworkId const & replyTo, std::string const & successCallback, std::string const & failCallback, std::vector const & packedDictionary) -{ - // Object might be "offline" but still buffered. Try to handle it in memory first: - if (!m_objectTableBuffer.getMoneyFromOfflineObject(replyServer, sourceObject, amount, replyTo, successCallback, failCallback, packedDictionary)) - { - // Object is offline. Handle it in the DB - getOfflineMoneyCustomPersistStep()->getMoneyFromOfflineObject(replyServer, sourceObject, amount, replyTo, successCallback, failCallback, packedDictionary); - } +void +SwgSnapshot::getMoneyFromOfflineObject(uint32 replyServer, NetworkId const &sourceObject, int amount, NetworkId const &replyTo, std::string const &successCallback, std::string const &failCallback, std::vector const &packedDictionary) { + // Object might be "offline" but still buffered. Try to handle it in memory first: + if (!m_objectTableBuffer.getMoneyFromOfflineObject(replyServer, sourceObject, amount, replyTo, successCallback, failCallback, packedDictionary)) { + // Object is offline. Handle it in the DB + getOfflineMoneyCustomPersistStep()->getMoneyFromOfflineObject(replyServer, sourceObject, amount, replyTo, successCallback, failCallback, packedDictionary); + } } // ---------------------------------------------------------------------- -OfflineMoneyCustomPersistStep * SwgSnapshot::getOfflineMoneyCustomPersistStep() -{ - if (!m_offlineMoneyCustomPersistStep) - { - m_offlineMoneyCustomPersistStep = new OfflineMoneyCustomPersistStep; - addCustomPersistStep(m_offlineMoneyCustomPersistStep); - } - return m_offlineMoneyCustomPersistStep; +OfflineMoneyCustomPersistStep *SwgSnapshot::getOfflineMoneyCustomPersistStep() { + if (!m_offlineMoneyCustomPersistStep) { + m_offlineMoneyCustomPersistStep = new OfflineMoneyCustomPersistStep; + addCustomPersistStep(m_offlineMoneyCustomPersistStep); + } + return m_offlineMoneyCustomPersistStep; } // ---------------------------------------------------------------------- -void SwgSnapshot::decodeQuests(NetworkId const & networkId, Archive::ReadIterator &data, - DB::BufferString &part1, DB::BufferString &part2, - DB::BufferString &part3, DB::BufferString &part4) const -{ +void +SwgSnapshot::decodeQuests(NetworkId const &networkId, Archive::ReadIterator &data, DB::BufferString &part1, DB::BufferString &part2, DB::BufferString &part3, DB::BufferString &part4) const { - const int ki_num_parts = 4; - const int ki_chunk_size = DBSchema::PlayerObjectRow::QUEST_DATA_SIZE; - static const std::string space(" "); + const int ki_num_parts = 4; + const int ki_chunk_size = DBSchema::PlayerObjectRow::QUEST_DATA_SIZE; + static const std::string space(" "); - std::string packedValue; - Archive::AutoDeltaPackedMap::unpack(data,packedValue); + std::string packedValue; + Archive::AutoDeltaPackedMap::unpack(data, packedValue); - if (packedValue.length() > ki_chunk_size * ki_num_parts) - { - // Remove completed quests to save space. This is a last-ditch effort to save a crash, not a good way to - // handle it. - - WARNING(true,("QuestData: Object %s had too much quest data to be stored in the database. Truncating.",networkId.getValueString().c_str())); - int charsToRemove = packedValue.length() - ki_chunk_size * ki_num_parts; - char const * sourcePos = packedValue.c_str(); - std::string newPackedValue; - bool activeQuest=false; - char entry[100]; - char * entryPos = entry; - while (charsToRemove > 0 && *sourcePos != '\0') - { - *(entryPos++)=*sourcePos; + if (packedValue.length() > ki_chunk_size * ki_num_parts) { + // Remove completed quests to save space. This is a last-ditch effort to save a crash, not a good way to + // handle it. - if (*sourcePos==' ') - activeQuest=true; - if (*(sourcePos++)==':') - { - if (activeQuest) - { - // copy this active quest - *entryPos='\0'; - newPackedValue+=entry; - entryPos=entry; - activeQuest=false; - } - else - { - // don't copy this completed quest - charsToRemove -= entryPos-entry; - entryPos=entry; - } - } - } - packedValue = newPackedValue + sourcePos; - } + WARNING(true, ("QuestData: Object %s had too much quest data to be stored in the database. Truncating.", networkId.getValueString().c_str())); + int charsToRemove = packedValue.length() - ki_chunk_size * ki_num_parts; + char const *sourcePos = packedValue.c_str(); + std::string newPackedValue; + bool activeQuest = false; + char entry[100]; + char *entryPos = entry; + while (charsToRemove > 0 && *sourcePos != '\0') { + *(entryPos++) = *sourcePos; + + if (*sourcePos == ' ') { + activeQuest = true; + } + if (*(sourcePos++) == ':') { + if (activeQuest) { + // copy this active quest + *entryPos = '\0'; + newPackedValue += entry; + entryPos = entry; + activeQuest = false; + } else { + // don't copy this completed quest + charsToRemove -= entryPos - entry; + entryPos = entry; + } + } + } + packedValue = newPackedValue + sourcePos; + } - part1=std::string(packedValue,0,ki_chunk_size); + part1 = std::string(packedValue, 0, ki_chunk_size); - // part2 - if (packedValue.length() > ki_chunk_size * 1) - part2=std::string(packedValue, ki_chunk_size * 1, ki_chunk_size); - else - part2=space; + // part2 + if (packedValue.length() > ki_chunk_size * 1) { + part2 = std::string(packedValue, ki_chunk_size * 1, ki_chunk_size); + } else { + part2 = space; + } - // part3 - if (packedValue.length() > ki_chunk_size * 2) - part3=std::string(packedValue, ki_chunk_size * 2, ki_chunk_size); - else - part3=space; + // part3 + if (packedValue.length() > ki_chunk_size * 2) { + part3 = std::string(packedValue, ki_chunk_size * 2, ki_chunk_size); + } else { + part3 = space; + } - // part4 - if (packedValue.length() > ki_chunk_size * 3) - part4=std::string(packedValue, ki_chunk_size * 3, ki_chunk_size); - else - part4=space; - } + // part4 + if (packedValue.length() > ki_chunk_size * 3) { + part4 = std::string(packedValue, ki_chunk_size * 3, ki_chunk_size); + } else { + part4 = space; + } +} // ---------------------------------------------------------------------- -void SwgSnapshot::encodeQuests(Archive::ByteStream &data, - DB::BufferString const &part1, DB::BufferString const &part2, - DB::BufferString const &part3, DB::BufferString const &part4) const -{ - std::string packedValue; - std::string packedValue2; - std::string packedValue3; - std::string packedValue4; - part1.getValue(packedValue); - part2.getValue(packedValue2); - part3.getValue(packedValue3); - part4.getValue(packedValue4); - if (packedValue2!=" ") - packedValue+=packedValue2; - if (packedValue3!=" ") - packedValue+=packedValue3; - if (packedValue4!=" ") - packedValue+=packedValue4; - Archive::AutoDeltaPackedMap::pack(data, packedValue); +void +SwgSnapshot::encodeQuests(Archive::ByteStream &data, DB::BufferString const &part1, DB::BufferString const &part2, DB::BufferString const &part3, DB::BufferString const &part4) const { + std::string packedValue; + std::string packedValue2; + std::string packedValue3; + std::string packedValue4; + part1.getValue(packedValue); + part2.getValue(packedValue2); + part3.getValue(packedValue3); + part4.getValue(packedValue4); + if (packedValue2 != " ") { + packedValue += packedValue2; + } + if (packedValue3 != " ") { + packedValue += packedValue3; + } + if (packedValue4 != " ") { + packedValue += packedValue4; + } + Archive::AutoDeltaPackedMap::pack(data, packedValue); } // ---------------------------------------------------------------------- @@ -1380,179 +1255,150 @@ void SwgSnapshot::encodeQuests(Archive::ByteStream &data, static const char* oldschoolBuffFormat = "%lu %I64u"; static const char* versionTwoFormat = "%u %u %f %u %I64i %u:"; #else -static const char* oldschoolBuffFormat = "%lu %llu"; -static const char* versionTwoFormat = "%u %u %f %u %lli %u:"; +static const char *oldschoolBuffFormat = "%lu %llu"; +static const char *versionTwoFormat = "%u %u %f %u %lli %u:"; #endif -static const char* versionOneFormat = "%u %u %f %u:"; -static const char* versionFormat = "%uv"; +static const char *versionOneFormat = "%u %u %f %u:"; +static const char *versionFormat = "%uv"; -void SwgSnapshot::decodePersistedBuffs (Archive::ReadIterator &data, DB::BufferString &dbString) const -{ - const unsigned version = 2; +void SwgSnapshot::decodePersistedBuffs(Archive::ReadIterator &data, DB::BufferString &dbString) const { + const unsigned version = 2; - std::string packedValue; + std::string packedValue; - Archive::AutoDeltaMap temp; - Archive::get(data, temp); - std::map const& rawMap = temp.getMap(); + Archive::AutoDeltaMap temp; + Archive::get(data, temp); + std::map const &rawMap = temp.getMap(); - FormattedString<200> formater; + FormattedString<200> formater; - if(rawMap.empty()) - { - packedValue = " "; - } - else - { - packedValue += formater.sprintf(versionFormat, version); + if (rawMap.empty()) { + packedValue = " "; + } else { + packedValue += formater.sprintf(versionFormat, version); - for(std::map::const_iterator i = rawMap.begin(); i != rawMap.end(); ++i) - { - uint32 tempCrc = (*i).first; - Buff::PackedBuff const & tempPacked = (*i).second; - packedValue += formater.sprintf(versionTwoFormat, tempCrc, tempPacked.endtime, tempPacked.value, tempPacked.duration, tempPacked.caster.getValue(), tempPacked.stackCount); - } - } + for (std::map::const_iterator i = rawMap.begin(); i != rawMap.end(); ++i) { + uint32 tempCrc = (*i).first; + Buff::PackedBuff const &tempPacked = (*i).second; + packedValue += formater.sprintf(versionTwoFormat, tempCrc, tempPacked.endtime, tempPacked.value, tempPacked.duration, tempPacked.caster.getValue(), tempPacked.stackCount); + } + } - dbString.setValue(packedValue); + dbString.setValue(packedValue); } -void SwgSnapshot::encodePersistedBuffs (Archive::ByteStream &data, DB::BufferString const& dbString) const -{ - // some persisted buffs in the database were written as a AutoDeltaPackedMap of Crc's and uint64 - // the new type ones are marked with a version number followed by a 'v' then the data +void SwgSnapshot::encodePersistedBuffs(Archive::ByteStream &data, DB::BufferString const &dbString) const { + // some persisted buffs in the database were written as a AutoDeltaPackedMap of Crc's and uint64 + // the new type ones are marked with a version number followed by a 'v' then the data - std::string stringRepresentation; - dbString.getValue (stringRepresentation); - size_t numchars = stringRepresentation.size(); + std::string stringRepresentation; + dbString.getValue(stringRepresentation); + size_t numchars = stringRepresentation.size(); - int version = -1; + int version = -1; - //format: [v] + //format: [v] - //extract the version - if (numchars > 0) - { - size_t vpos = stringRepresentation.find('v'); - if(vpos == stringRepresentation.npos) - { - version = 0; - } - else - { - std::string versionToken = stringRepresentation.substr(0,vpos); - sscanf(versionToken.c_str(), versionFormat, &version); + //extract the version + if (numchars > 0) { + size_t vpos = stringRepresentation.find('v'); + if (vpos == stringRepresentation.npos) { + version = 0; + } else { + std::string versionToken = stringRepresentation.substr(0, vpos); + sscanf(versionToken.c_str(), versionFormat, &version); - stringRepresentation = stringRepresentation.substr(vpos+1); - } - } - - Archive::AutoDeltaMap::Command tempCommand; - std::vector::Command> commands; - char temp[200]; + stringRepresentation = stringRepresentation.substr(vpos + 1); + } + } - if(version == 0) - { - //string is the old AutoDeltaPackedMap written as [ :]* - uint64 tempPacked64; - uint32 tempCrc; + Archive::AutoDeltaMap::Command tempCommand; + std::vector ::Command> commands; + char temp[200]; - int numbuffs = Archive::countCharacter(stringRepresentation,':'); - commands.reserve(numbuffs); + if (version == 0) { + //string is the old AutoDeltaPackedMap written as [ :]* + uint64 tempPacked64; + uint32 tempCrc; - int tempPos = 0; - for (std::string::const_iterator i=stringRepresentation.begin(); i!=stringRepresentation.end(); ++i) - { - if (*i==':') - { - temp[tempPos]='\0'; - sscanf(temp, oldschoolBuffFormat, &tempCrc, &tempPacked64); + int numbuffs = Archive::countCharacter(stringRepresentation, ':'); + commands.reserve(numbuffs); - tempCommand.cmd = Archive::AutoDeltaMap::Command::ADD; - tempCommand.key = tempCrc; - tempCommand.value = Buff::makePackedBuff(tempPacked64); + int tempPos = 0; + for (std::string::const_iterator i = stringRepresentation.begin(); i != stringRepresentation.end(); ++i) { + if (*i == ':') { + temp[tempPos] = '\0'; + sscanf(temp, oldschoolBuffFormat, &tempCrc, &tempPacked64); - commands.push_back(tempCommand); + tempCommand.cmd = Archive::AutoDeltaMap::Command::ADD; + tempCommand.key = tempCrc; + tempCommand.value = Buff::makePackedBuff(tempPacked64); - tempPos=0; - } - else - { - temp[tempPos++]=*i; - } - } - } - else if (version == 1) - { - //version 1 written as [ :]* - uint32 tempCrc = 0, tempEndtime = 0, tempDuration = 0; - float tempValue = 0.0f; + commands.push_back(tempCommand); - int numbuffs = Archive::countCharacter(stringRepresentation,':'); - commands.reserve(numbuffs); + tempPos = 0; + } else { + temp[tempPos++] = *i; + } + } + } else if (version == 1) { + //version 1 written as [ :]* + uint32 tempCrc = 0, tempEndtime = 0, tempDuration = 0; + float tempValue = 0.0f; - int tempPos = 0; - for (std::string::const_iterator i=stringRepresentation.begin(); i!=stringRepresentation.end(); ++i) - { - if (*i==':') - { - temp[tempPos]='\0'; - sscanf(temp, versionOneFormat, &tempCrc, &tempEndtime, &tempValue, &tempDuration); + int numbuffs = Archive::countCharacter(stringRepresentation, ':'); + commands.reserve(numbuffs); - tempCommand.cmd = Archive::AutoDeltaMap::Command::ADD; - tempCommand.key = tempCrc; - tempCommand.value = Buff(tempCrc, tempEndtime, tempValue, tempDuration).getPackedBuffValue(); + int tempPos = 0; + for (std::string::const_iterator i = stringRepresentation.begin(); i != stringRepresentation.end(); ++i) { + if (*i == ':') { + temp[tempPos] = '\0'; + sscanf(temp, versionOneFormat, &tempCrc, &tempEndtime, &tempValue, &tempDuration); - commands.push_back(tempCommand); + tempCommand.cmd = Archive::AutoDeltaMap::Command::ADD; + tempCommand.key = tempCrc; + tempCommand.value = Buff(tempCrc, tempEndtime, tempValue, tempDuration).getPackedBuffValue(); - tempPos=0; - } - else - { - temp[tempPos++]=*i; - } - } - } - else if (version == 2) - { - //version 2 written as [ :]* - uint32 tempCrc = 0, tempEndtime = 0, tempDuration = 0, tempStackCount = 0; - float tempValue = 0.0f; - int64 tempCaster = 0; + commands.push_back(tempCommand); - int numbuffs = Archive::countCharacter(stringRepresentation,':'); - commands.reserve(numbuffs); + tempPos = 0; + } else { + temp[tempPos++] = *i; + } + } + } else if (version == 2) { + //version 2 written as [ :]* + uint32 tempCrc = 0, tempEndtime = 0, tempDuration = 0, tempStackCount = 0; + float tempValue = 0.0f; + int64 tempCaster = 0; - int tempPos = 0; - for (std::string::const_iterator i=stringRepresentation.begin(); i!=stringRepresentation.end(); ++i) - { - if (*i==':') - { - temp[tempPos]='\0'; - sscanf(temp, versionTwoFormat, &tempCrc, &tempEndtime, &tempValue, &tempDuration, &tempCaster, &tempStackCount); + int numbuffs = Archive::countCharacter(stringRepresentation, ':'); + commands.reserve(numbuffs); - tempCommand.cmd = Archive::AutoDeltaMap::Command::ADD; - tempCommand.key = tempCrc; - tempCommand.value = Buff(tempCrc, tempEndtime, tempValue, tempDuration, NetworkId(tempCaster), tempStackCount).getPackedBuffValue(); + int tempPos = 0; + for (std::string::const_iterator i = stringRepresentation.begin(); i != stringRepresentation.end(); ++i) { + if (*i == ':') { + temp[tempPos] = '\0'; + sscanf(temp, versionTwoFormat, &tempCrc, &tempEndtime, &tempValue, &tempDuration, &tempCaster, &tempStackCount); - commands.push_back(tempCommand); + tempCommand.cmd = Archive::AutoDeltaMap::Command::ADD; + tempCommand.key = tempCrc; + tempCommand.value = Buff(tempCrc, tempEndtime, tempValue, tempDuration, NetworkId(tempCaster), tempStackCount).getPackedBuffValue(); - tempPos=0; - } - else - { - temp[tempPos++]=*i; - } - } - } - else - { - //we don't know how to convert this string to buffs, treat it as though there were no buffs there at all - WARNING(true, ("encodePersistedBuffs: Cannot convert db string with version %d to buffs", version)); - } + commands.push_back(tempCommand); - Archive::AutoDeltaMap::pack(data, commands); + tempPos = 0; + } else { + temp[tempPos++] = *i; + } + } + } else { + //we don't know how to convert this string to buffs, treat it as though there were no buffs there at all + WARNING(true, ("encodePersistedBuffs: Cannot convert db string with version %d to buffs", version)); + } + + Archive::AutoDeltaMap::pack(data, commands); }