Instructions Jenkins Doxygen

[changed] StructurePermissionList::ownerName is now serialized 12/712/2
authorIvojedi <ivojedi@swgemu.com>
Fri, 30 Aug 2013 13:49:53 +0000 (06:49 -0700)
committerIvojedi <ivojedi@swgemu.com>
Fri, 30 Aug 2013 20:43:40 +0000 (13:43 -0700)
Change-Id: I452452042ec1317cf055ec553498492ac300dced

MMOCoreORB/src/server/zone/managers/object/ObjectVersionUpdateManager.cpp
MMOCoreORB/src/server/zone/managers/object/ObjectVersionUpdateManager.h
MMOCoreORB/src/server/zone/objects/structure/StructurePermissionList.cpp

index dd5eb9d..fb0a36c 100644 (file)
@@ -10,6 +10,7 @@
 #include "server/zone/objects/player/Races.h"
 #include "server/db/ServerDatabase.h"
 #include "system/util/SortedVector.h"
+#include "server/zone/objects/structure/StructurePermissionList.h"
 
 #define INITIAL_DATABASE_VERSION 0
 
@@ -34,7 +35,11 @@ int ObjectVersionUpdateManager::run() {
                updateWeaponsDots();
                ObjectDatabaseManager::instance()->updateCurrentVersion(INITIAL_DATABASE_VERSION + 3);
                return 0;
-       } else {
+       } else if (version == INITIAL_DATABASE_VERSION + 3) {
+               updateStructurePermissionLists();
+               ObjectDatabaseManager::instance()->updateCurrentVersion(INITIAL_DATABASE_VERSION + 4);
+               return 0;
+       }  else {
 
                info("database on latest version : " + String::valueOf(version), true);
                //verifyResidenceVariables();
@@ -256,6 +261,100 @@ void ObjectVersionUpdateManager::updateWeaponsDots() {
 }
 
 
+void ObjectVersionUpdateManager::updateStructurePermissionLists() {
+       ObjectDatabase* database = ObjectDatabaseManager::instance()->loadObjectDatabase("playerstructures", true);
+
+       ObjectDatabaseIterator iterator(database);
+
+       ObjectInputStream objectData(2000);
+       uint64 objectID = 0;
+       int count = 0;
+
+       info("Setting owner on structure permission lists",true);
+
+       try {
+
+               while (iterator.getNextKeyAndValue(objectID, &objectData)) {
+
+                       String className;
+
+                       try {
+                               if (!Serializable::getVariable<String>(String("_className").hashCode(), &className, &objectData)) {
+                                       objectData.clear();
+                                       continue;
+                               }
+                       } catch (...) {
+                               objectData.clear();
+                               continue;
+                       }
+
+                       if (className == "BuildingObject" || className == "InstallationObject" || className == "GarageInstallation" || className == "ShuttleInstallation") {
+                               uint64 ownerID = 0;
+                               String ownerName;
+                               count ++;
+                               printf("\r\tUpdating structure owners [%d] / [?]\t", count);
+
+                               if( Serializable::getVariable<uint64>(String("StructureObject.ownerObjectID").hashCode(), &ownerID, &objectData)) {
+                                       String owner = getOwnerName(ownerID);
+                                       StructurePermissionList permissionList;
+
+                                       if ( Serializable::getVariable<StructurePermissionList>(String("StructureObject.structurePermissionList").hashCode(), &permissionList, &objectData)){
+                                               ObjectOutputStream newOutputStream;
+                                               permissionList.setOwnerName(owner);
+                                               permissionList.toBinaryStream(&newOutputStream);
+
+                                               ObjectOutputStream* test = changeVariableData(String("StructureObject.structurePermissionList").hashCode(), &objectData, &newOutputStream);
+                                               test->reset();
+                                               database->putData(objectID, test, NULL);
+                                       } else {
+                                               info("ERROR unable to get structurePermissionList for structure " + String::valueOf(objectID),true);
+                                       }
+
+                               } else {
+                                       info("ERROR unable to get ownerObjectID for structure " + String::valueOf(objectID),true);
+                               }
+                       }
+                       objectData.clear();
+               }
+       } catch (Exception& e) {
+               error(e.getMessage());
+               e.printStackTrace();
+       }
+       info("Done updating owner on structure permission lists\n",true);
+
+}
+
+String ObjectVersionUpdateManager::getOwnerName(uint64 ownerID) {
+       ObjectDatabase* database = ObjectDatabaseManager::instance()->loadObjectDatabase("sceneobjects", true);
+       ObjectInputStream objectData(2000);
+
+       String className;
+       UnicodeString fullName;
+
+       if(!database->getData(ownerID,&objectData)){
+               if ( Serializable::getVariable<String>(String("_className").hashCode(), &className, &objectData)){
+
+                       if(className == "CreatureObject"){
+                               if ( Serializable::getVariable<UnicodeString>(String("SceneObject.customName").hashCode(), &fullName, &objectData)){
+                                       int idx = fullName.indexOf(' ');
+
+                                       if (idx != -1) {
+                                               return fullName.subString(0, idx).toString();
+                                       } else {
+                                               return fullName.toString();
+                                       }
+                               }
+                       }
+               } else {
+
+                       info("ERROR couldn't get object " + String::valueOf(ownerID),true);
+
+               }
+       }
+
+       return "";
+}
+
 void ObjectVersionUpdateManager::updateResidences(){
        ObjectDatabase* database = ObjectDatabaseManager::instance()->loadObjectDatabase("sceneobjects", true);
 
index 3be37ca..4c4c129 100644 (file)
@@ -32,6 +32,8 @@ public:
        void setResidence(uint64 buildingID, bool isResidence);
        void verifyResidenceVariables();
        void updateWeaponsDots();
+       void updateStructurePermissionLists();
+       String getOwnerName(uint64 ownerID);
 
        void updateCityTreasury();
        int run();
index c5008a9..e74582e 100644 (file)
@@ -47,6 +47,14 @@ int StructurePermissionList::writeObjectMembers(ObjectOutputStream* stream) {
        _totalSize = (uint32) (stream->getOffset() - (_offset + 4));
        stream->writeInt(_offset, _totalSize);
 
+       _name = "ownerName";
+       _name.toBinaryStream(stream);
+       _offset = stream->getOffset();
+       stream->writeInt(0);
+       TypeInfo<String>::toBinaryStream(&ownerName, stream);
+       _totalSize = (uint32) (stream->getOffset() - (_offset + 4));
+       stream->writeInt(_offset, _totalSize);
+
        String emptyName; // making it serialize the same way as Serializable so bas doesnt have to update all the objects
 
        _name = "_className";
@@ -57,7 +65,7 @@ int StructurePermissionList::writeObjectMembers(ObjectOutputStream* stream) {
        _totalSize = (uint32) (stream->getOffset() - (_offset + 4));
        stream->writeInt(_offset, _totalSize);
 
-       return 2;
+       return 3;
 }
 
 bool StructurePermissionList::readObjectMember(ObjectInputStream* stream, const String& name) {
@@ -65,6 +73,10 @@ bool StructurePermissionList::readObjectMember(ObjectInputStream* stream, const
                TypeInfo<VectorMap<String, SortedVector<String> > >::parseFromBinaryStream(&permissionLists, stream);
 
                return true;
+       } else if (name == "ownerName") {
+               TypeInfo<String>::parseFromBinaryStream(&ownerName, stream);
+
+               return true;
        }
 
        return false;