void HouseFactory::handleObjectReady(Object* object,DispatchClient* client) { //Perform checking on startup there is no client! // client will in all cases be NULL in this factory //if(!client) // return; //add our cells InLoadingContainer* ilc = _getObject(object->getParentId()); //Perform checking. if(!ilc) { gLogger->log(LogManager::NOTICE,"House creation failed (HouseFactory.cpp line 289)"); return; } HouseObject* house = dynamic_cast<HouseObject*>(ilc->mObject); //add hopper / new item to worldObjectlist, but NOT to the SI gWorldManager->addObject(object,true); //pondering whether to use the objectcontainer instead house->addCell(dynamic_cast<CellObject*>(object)); if(house->getLoadCount() == (house->getCellList())->size()) { if(!(_removeFromObjectLoadMap(house->getId()))) gLogger->log(LogManager::NOTICE,"BuildingFactory: Failed removing object from loadmap"); ilc->mOfCallback->handleObjectReady(house,ilc->mClient); mILCPool.free(ilc); } }
void HouseFactory::handleDatabaseJobComplete(void* ref,DatabaseResult* result) { QueryContainerBase* asyncContainer = reinterpret_cast<QueryContainerBase*>(ref); switch(asyncContainer->mQueryType) { case HOFQuery_CellData: { HouseObject* house = dynamic_cast<HouseObject*>(asyncContainer->mObject); uint32 cellCount; uint64 cellId; DataBinding* cellBinding = mDatabase->CreateDataBinding(1); cellBinding->addField(DFT_int64,0,8); // store us for later lookup mObjectLoadMap.insert(std::make_pair(house->getId(),new(mILCPool.ordered_malloc()) InLoadingContainer(house,asyncContainer->mOfCallback,asyncContainer->mClient))); cellCount = static_cast<uint32>(result->getRowCount()); house->setLoadCount(cellCount); uint64 maxid = 0xffffffffffffffff; for(uint32 j = 0; j < cellCount; j++) { result->GetNextRow(cellBinding,&cellId); mCellFactory->requestStructureCell(this,cellId,0,0,asyncContainer->mClient); if(cellId < maxid) maxid = cellId; } house->setMinCellId(maxid); mDatabase->DestroyDataBinding(cellBinding); //read in admin list - do houses only have an admin list ??? QueryContainerBase* asContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,HOFQuery_AdminData,asyncContainer->mClient); asContainer->mObject = house; int8 sql[1024]; sprintf(sql,"SELECT PlayerID FROM structure_admin_data WHERE StructureID = %"PRIu64" AND AdminType like 'ADMIN';",house->getId()); mDatabase->ExecuteSqlAsync(this,asContainer,sql); } break; case HOFQuery_AdminData: { HouseObject* house = dynamic_cast<HouseObject*>(asyncContainer->mObject); struct adminStruct { uint64 playerID; BString adminList; }; adminStruct adminData; DataBinding* adminBinding = mDatabase->CreateDataBinding(1); adminBinding->addField(DFT_uint64,offsetof(adminStruct,playerID),8,0); uint64 count = result->getRowCount(); for(uint32 j = 0; j < count; j++) { result->GetNextRow(adminBinding,&adminData); house->addHousingAdminEntry(adminData.playerID); } mDatabase->DestroyDataBinding(adminBinding); } break; case HOFQuery_AttributeData: { HouseObject* house = dynamic_cast<HouseObject*>(asyncContainer->mObject); //_buildAttributeMap(harvester,result); Attribute_QueryContainer attribute; uint64 count = result->getRowCount(); //int8 str[256]; //BStringVector dataElements; for(uint64 i = 0; i < count; i++) { result->GetNextRow(mAttributeBinding,(void*)&attribute); house->addInternalAttribute(attribute.mKey,std::string(attribute.mValue.getAnsi())); } QueryContainerBase* asContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,HOFQuery_CellData,asyncContainer->mClient); asContainer->mObject = house; mDatabase->ExecuteSqlAsync(this,asContainer,"SELECT id FROM structure_cells WHERE parent_id = %"PRIu64" ORDER BY structure_cells.id;",house->getId()); } break; case HOFQuery_MainData: { QueryContainerBase* asynContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,HOFQuery_AttributeData,asyncContainer->mClient,asyncContainer->mId); HouseObject* house = new(HouseObject); _createHouse(result,house); asynContainer->mObject = house; asynContainer->mClient = asyncContainer->mClient; asynContainer->mId = house->getId(); mDatabase->ExecuteSqlAsync(this,asynContainer,"SELECT attributes.name,sa.value,attributes.internal" " FROM structure_attributes sa" " INNER JOIN attributes ON (sa.attribute_id = attributes.id)" " WHERE sa.structure_id = %"PRIu64" ORDER BY sa.order",house->getId()); } break; default: break; } mQueryContainerPool.free(asyncContainer); }