void HarvesterFactory::handleDatabaseJobComplete(void* ref,swganh::database::DatabaseResult* result) { QueryContainerBase* asyncContainer = reinterpret_cast<QueryContainerBase*>(ref); switch(asyncContainer->mQueryType) { case HFQuery_ResourceData: { uint32 count = (uint32)result->getRowCount(); HarvesterObject* harvester = dynamic_cast<HarvesterObject*>(asyncContainer->mObject); if(count) { swganh::database::DataBinding* binding = mDatabase->createDataBinding(2); binding->addField(swganh::database::DFT_uint64,offsetof(HarvesterHopperItem,ResourceID),8,0); binding->addField(swganh::database::DFT_float,offsetof(HarvesterHopperItem,Quantity),4,1); HResourceList* hRList = harvester->getResourceList(); hRList->resize(hRList->size()+count); HarvesterHopperItem hopperTemp; for(uint64 i=0; i <count; i++) { result->getNextRow(binding,&hopperTemp); hRList->push_back(std::make_pair(hopperTemp.ResourceID,hopperTemp.Quantity)); } } QueryContainerBase* asynContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,HFQuery_AttributeData,asyncContainer->mClient,asyncContainer->mId); asynContainer->mId = harvester->getId(); asynContainer->mObject = harvester; mDatabase->executeSqlAsync(this,asynContainer,"SELECT attributes.name,sa.value,attributes.internal" " FROM %s.structure_attributes sa" " INNER JOIN %s.attributes ON (sa.attribute_id = attributes.id)" " WHERE sa.structure_id = %"PRIu64" ORDER BY sa.order", mDatabase->galaxy(),mDatabase->galaxy(),harvester->getId()); } break; case HFQuery_AttributeData: { HarvesterObject* harvester = dynamic_cast<HarvesterObject*>(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); harvester->addInternalAttribute(BString(attribute.mKey.c_str()),attribute.mValue); } QueryContainerBase* asynContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,HFQuery_AdminData,asyncContainer->mClient,asyncContainer->mId); asynContainer->mId = harvester->getId(); asynContainer->mObject = harvester; std::stringstream sql; sql << "SELECT sad.PlayerID, sad.AdminType, c.firstname FROM " << mDatabase->galaxy() << ".structure_admin_data sad INNER JOIN " << mDatabase->galaxy() << ".characters c ON (c.id = sad.PlayerID) WHERE StructureID = " << harvester->getId() << ";"; mDatabase->executeSqlAsync(this, asynContainer, sql.str()); } break; case HFQuery_AdminData: { HarvesterObject* harvester = dynamic_cast<HarvesterObject*>(asyncContainer->mObject); std::unique_ptr<sql::ResultSet>& result_set = result->getResultSet(); while (result_set->next()) { std::string type = result_set->getString(2); if(type == "ADMIN") { harvester->admin_data_.admin_add_(result_set->getInt64(1), result_set->getString(3)); LOG(info) << " added Admin to harvester : " << harvester->getId(); } else if(type == "BAN") { harvester->admin_data_.ban_add_(result_set->getInt64(1), result_set->getString(3)); LOG(info) << " added ban to harvester : " << harvester->getId(); } else if(type == "ENTRY") { harvester->admin_data_.entry_add_(result_set->getInt64(1), result_set->getString(3)); LOG(info) << " added entry to harvester : " << harvester->getId(); } else if(type == "HOPPER") { harvester->admin_data_.entry_add_(result_set->getInt64(1), result_set->getString(3)); LOG(info) << " added entry to harvester : " << harvester->getId(); } } harvester->admin_data_.structure_id_ = harvester->getId(); harvester->admin_data_.owner_id_ = harvester->getOwner(); harvester->setLoadState(LoadState_Loaded); LOG(info) << "Loaded harvester with id [" << harvester->getId() << "]"; asyncContainer->mOfCallback->handleObjectReady(harvester,asyncContainer->mClient); } break; case HFQuery_MainData: { QueryContainerBase* asynContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,HFQuery_ResourceData,asyncContainer->mClient,asyncContainer->mId); HarvesterObject* harvester = new(HarvesterObject); _createHarvester(result,harvester); asynContainer->mObject = harvester; asynContainer->mClient = asyncContainer->mClient; //asyncContainer->mOfCallback->handleObjectReady(harvester,asyncContainer->mClient); //now request the associated resource container count int8 sql[250]; sprintf(sql,"SELECT hr.resourceID, hr.quantity FROM %s.harvester_resources hr WHERE hr.ID = '%"PRIu64"' ",mDatabase->galaxy(),harvester->getId()); mDatabase->executeSqlAsync(this,asynContainer,sql); } break; default: break; } mQueryContainerPool.free(asyncContainer); }
void HarvesterFactory::handleDatabaseJobComplete(void* ref,DatabaseResult* result) { QueryContainerBase* asyncContainer = reinterpret_cast<QueryContainerBase*>(ref); switch(asyncContainer->mQueryType) { case HFQuery_ResourceData: { uint32 count = (uint32)result->getRowCount(); HarvesterObject* harvester = dynamic_cast<HarvesterObject*>(asyncContainer->mObject); if(count) { DataBinding* binding = mDatabase->createDataBinding(2); binding->addField(DFT_uint64,offsetof(HarvesterHopperItem,ResourceID),8,0); binding->addField(DFT_float,offsetof(HarvesterHopperItem,Quantity),4,1); HResourceList* hRList = harvester->getResourceList(); hRList->resize(hRList->size()+count); HarvesterHopperItem hopperTemp; for(uint64 i=0; i <count; i++) { result->getNextRow(binding,&hopperTemp); hRList->push_back(std::make_pair(hopperTemp.ResourceID,hopperTemp.Quantity)); } } QueryContainerBase* asynContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,HFQuery_AttributeData,asyncContainer->mClient,asyncContainer->mId); asynContainer->mId = harvester->getId(); asynContainer->mObject = harvester; mDatabase->executeSqlAsync(this,asynContainer,"SELECT attributes.name,sa.value,attributes.internal" " FROM %s.structure_attributes sa" " INNER JOIN %s.attributes ON (sa.attribute_id = attributes.id)" " WHERE sa.structure_id = %" PRIu64 " ORDER BY sa.order", mDatabase->galaxy(),mDatabase->galaxy(),harvester->getId()); } break; case HFQuery_AttributeData: { HarvesterObject* harvester = dynamic_cast<HarvesterObject*>(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); harvester->addInternalAttribute(attribute.mKey,std::string(attribute.mValue.getAnsi())); } harvester->setLoadState(LoadState_Loaded); LOG(info) << "Loaded harvester with id [" << harvester->getId() << "]"; asyncContainer->mOfCallback->handleObjectReady(harvester,asyncContainer->mClient); } break; case HFQuery_MainData: { QueryContainerBase* asynContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,HFQuery_ResourceData,asyncContainer->mClient,asyncContainer->mId); HarvesterObject* harvester = new(HarvesterObject); _createHarvester(result,harvester); asynContainer->mObject = harvester; asynContainer->mClient = asyncContainer->mClient; //asyncContainer->mOfCallback->handleObjectReady(harvester,asyncContainer->mClient); //now request the associated resource container count int8 sql[250]; sprintf(sql,"SELECT hr.resourceID, hr.quantity FROM %s.harvester_resources hr WHERE hr.ID = '%" PRIu64 "' ",mDatabase->galaxy(),harvester->getId()); mDatabase->executeSqlAsync(this,asynContainer,sql); } break; default: break; } mQueryContainerPool.free(asyncContainer); }
void HarvesterObject::handleDatabaseJobComplete(void* ref,swganh::database::DatabaseResult* result) { StructureManagerAsyncContainer* asynContainer = (StructureManagerAsyncContainer*)ref; switch(asynContainer->mQueryType) { case Structure_ResourceRetrieve: { PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asynContainer->mPlayerId)); HarvesterObject* harvester = dynamic_cast<HarvesterObject*>(gWorldManager->getObjectById(asynContainer->mStructureId)); swganh::database::DataBinding* binding = gWorldManager->getKernel()->GetDatabase()->createDataBinding(1); binding->addField(swganh::database::DFT_uint32,0,4); uint64 count; uint32 error; count = result->getRowCount(); if(!count) { assert(false && "HarvesterObject::handleDatabaseJobComplete Structure_ResourceRetrieve did not find any resources"); return; } result->getNextRow(binding,&error); if(error > 0) { //mmh there was something fishy ... no changes db side gMessageLib->sendResourceEmptyHopperResponse(harvester,player,error, asynContainer->command.b1, asynContainer->command.b2); return; } createResourceContainer(asynContainer->command.ResourceId, player, asynContainer->command.Amount); StructureManagerAsyncContainer* asyncContainer = new StructureManagerAsyncContainer(Structure_ResourceDiscardUpdateHopper,player->getClient()); asyncContainer->mStructureId = asynContainer->mStructureId; asyncContainer->mPlayerId = asynContainer->mPlayerId; asyncContainer->command = asynContainer->command; gWorldManager->getKernel()->GetDatabase()->executeSqlAsync(harvester,asyncContainer,"SELECT hr.resourceID, hr.quantity FROM %s.harvester_resources hr WHERE hr.ID = '%"PRIu64"' ",gWorldManager->getKernel()->GetDatabase()->galaxy(), harvester->getId()); } break; case Structure_ResourceDiscard: { PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asynContainer->mPlayerId)); HarvesterObject* harvester = dynamic_cast<HarvesterObject*>(gWorldManager->getObjectById(asynContainer->mStructureId)); swganh::database::DataBinding* binding = gWorldManager->getKernel()->GetDatabase()->createDataBinding(1); binding->addField(swganh::database::DFT_uint32,0,4); uint64 count; uint32 error; count = result->getRowCount(); if(!count) { assert(false && "HarvesterObject::handleDatabaseJobComplete Structure_ResourceDiscard did not find resource"); return; } result->getNextRow(binding,&error); if(result > 0) { //mmh there was something fishy ... no changes db side gMessageLib->sendResourceEmptyHopperResponse(harvester,player,error, asynContainer->command.b1, asynContainer->command.b2); return; } StructureManagerAsyncContainer* asyncContainer = new StructureManagerAsyncContainer(Structure_ResourceDiscardUpdateHopper,player->getClient()); asyncContainer->mStructureId = asynContainer->mStructureId; asyncContainer->mPlayerId = asynContainer->mPlayerId; asyncContainer->command = asyncContainer->command; gWorldManager->getKernel()->GetDatabase()->executeSqlAsync(harvester,asyncContainer,"SELECT hr.resourceID, hr.quantity FROM %s.harvester_resources hr WHERE hr.ID = '%"PRIu64"' ",gWorldManager->getKernel()->GetDatabase()->galaxy(),harvester->getId()); } break; case Structure_ResourceDiscardUpdateHopper: { uint64 count = result->getRowCount(); HarvesterObject* harvester = dynamic_cast<HarvesterObject*>(gWorldManager->getObjectById(asynContainer->mStructureId)); PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asynContainer->mPlayerId)); swganh::database::DataBinding* binding = gWorldManager->getKernel()->GetDatabase()->createDataBinding(2); binding->addField(swganh::database::DFT_uint64,offsetof(HarvesterHopperItem,ResourceID),8,0); binding->addField(swganh::database::DFT_float,offsetof(HarvesterHopperItem,Quantity),4,1); HResourceList* hRList = harvester->getResourceList(); hRList->clear(); HarvesterHopperItem hopperTemp; for(uint64 i=0; i <count; i++) { result->getNextRow(binding,&hopperTemp); hRList->push_back(std::make_pair(hopperTemp.ResourceID,hopperTemp.Quantity)); } //now send the update to the client gMessageLib->SendHarvesterHopperUpdate(harvester,player); gMessageLib->sendResourceEmptyHopperResponse(harvester,player,0, asynContainer->command.b2, asynContainer->command.b2); gWorldManager->getKernel()->GetDatabase()->destroyDataBinding(binding); } break; case Structure_GetResourceData: { uint64 count = result->getRowCount(); HarvesterObject* harvester = dynamic_cast<HarvesterObject*>(gWorldManager->getObjectById(asynContainer->mStructureId)); PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asynContainer->mPlayerId)); swganh::database::DataBinding* binding = gWorldManager->getKernel()->GetDatabase()->createDataBinding(2); binding->addField(swganh::database::DFT_uint64,offsetof(HarvesterHopperItem,ResourceID),8,0); binding->addField(swganh::database::DFT_float,offsetof(HarvesterHopperItem,Quantity),4,1); HResourceList* hRList = harvester->getResourceList(); hRList->clear(); HarvesterHopperItem hopperTemp; for(uint64 i=0; i <count; i++) { result->getNextRow(binding,&hopperTemp); hRList->push_back(std::make_pair(hopperTemp.ResourceID,hopperTemp.Quantity)); } //now send the update to the client gMessageLib->sendHarvesterResourceData(harvester,player); gMessageLib->sendBaselinesHINO_7(harvester,player); gWorldManager->getKernel()->GetDatabase()->destroyDataBinding(binding); } break; //read in the current resource hoppers contents case Structure_HopperUpdate: { uint64 count = result->getRowCount(); HarvesterObject* harvester = dynamic_cast<HarvesterObject*>(gWorldManager->getObjectById(asynContainer->mStructureId)); PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asynContainer->mPlayerId)); swganh::database::DataBinding* binding = gWorldManager->getKernel()->GetDatabase()->createDataBinding(2); binding->addField(swganh::database::DFT_uint64,offsetof(HarvesterHopperItem,ResourceID),8,0); binding->addField(swganh::database::DFT_float,offsetof(HarvesterHopperItem,Quantity),4,1); HResourceList* hRList = harvester->getResourceList(); hRList->clear(); HarvesterHopperItem hopperTemp; for(uint64 i=0; i <count; i++) { result->getNextRow(binding,&hopperTemp); hRList->push_back(std::make_pair(hopperTemp.ResourceID,hopperTemp.Quantity)); } //now send the update to the client gMessageLib->SendHarvesterHopperUpdate(harvester,player); gWorldManager->getKernel()->GetDatabase()->destroyDataBinding(binding); } break; case Structure_HopperDiscard: { //PlayerStructure* structure = dynamic_cast<PlayerStructure*>(gWorldManager->getObjectById(asynContainer->mStructureId)); PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asynContainer->mPlayerId)); if(!player) { return; } StructureManagerAsyncContainer* asyncContainer = new StructureManagerAsyncContainer(Structure_HopperUpdate,player->getClient()); asyncContainer->mStructureId = this->getId(); asyncContainer->mPlayerId = player->getId(); int8 sql[250]; sprintf(sql,"SELECT hr.resourceID, hr.quantity FROM %s.harvester_resources hr WHERE hr.ID = '%"PRIu64"' ",gWorldManager->getKernel()->GetDatabase()->galaxy(),this->getId()); gWorldManager->getKernel()->GetDatabase()->executeSqlAsync(this,asyncContainer,sql); } break; default: break; } SAFE_DELETE(asynContainer); }