void StructureManager::_HandleUpdateAdminPermission(StructureManagerAsyncContainer* asynContainer,DatabaseResult* result)
{
	HouseObject*	house = dynamic_cast<HouseObject*>(gWorldManager->getObjectById(asynContainer->mStructureId));

	struct adminStruct
	{
		uint64 playerID;
	};

	adminStruct adminData;

	DataBinding*	adminBinding = mDatabase->CreateDataBinding(1);
	adminBinding->addField(DFT_uint64,offsetof(adminStruct,playerID),8,0);

	uint64 count = result->getRowCount();
	house->resetHousingAdminList();

	for(uint32 j = 0;j < count;j++)
	{
		result->GetNextRow(adminBinding,&adminData);
		house->addHousingAdminEntry(adminData.playerID);

		//now that we added it to the list we need to update the players delta
	}

	mDatabase->DestroyDataBinding(adminBinding);

}
Beispiel #2
0
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 StructureManager::_HandleStructureRedeedCallBack(StructureManagerAsyncContainer* asynContainer,DatabaseResult* result)
{
	PlayerStructure* structure = dynamic_cast<PlayerStructure*>(gWorldManager->getObjectById(asynContainer->mStructureId));

	//if its a playerstructure boot all players and pets inside
	HouseObject* house = dynamic_cast<HouseObject*>(structure);
	if(house)
	{
		house->prepareDestruction();
	}
	

	//destroy the structure here so the sf can still access the relevant data
	gObjectFactory->deleteObjectFromDB(structure);
	gMessageLib->sendDestroyObject_InRangeofObject(structure);

	gWorldManager->destroyObject(structure);
	

	PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asynContainer->mPlayerId));

	uint64 deedId;
	DataBinding* binding = mDatabase->CreateDataBinding(1);
	binding->addField(DFT_uint64,0,8);

	uint64 count;
	count = result->getRowCount();

	if (!count)
	{
		gLogger->logMsgLoadFailure("StructureManager::create deed no result...",MSG_NORMAL);
		mDatabase->DestroyDataBinding(binding);
		return;
	}
	result->GetNextRow(binding,&deedId);

	//return value of 0 means something wasnt found
	if(!deedId)
	{
		gLogger->logMsgF("StructureManager::create deed no valid return value...",MSG_NORMAL);
		mDatabase->DestroyDataBinding(binding);
		return;
	}
	//returnvalue of 1 means that there wasnt enough money on the deed
	if(deedId == 1)
	{
		gLogger->logMsgF("StructureManager::create deed with not enough maintenance...",MSG_NORMAL);
		gMessageLib->sendSysMsg(player, "player_structure","structure_destroyed ");	
		mDatabase->DestroyDataBinding(binding);
		return;
	}

	if(player)
	{
		//load the deed into the inventory
		Inventory* inventory = dynamic_cast<Inventory*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory));
		if(inventory)
		{
			//15 is itemfamily for deeds
			gObjectFactory->createIteminInventory(inventory,deedId,TanGroup_Item);
		}
	}

	UpdateCharacterLots(asynContainer->mPlayerId);

	mDatabase->DestroyDataBinding(binding);
}
void ObjectFactory::deleteObjectFromDB(Object* object)
{
	int8 sql[256];

	switch(object->getType())
	{
		case ObjType_Tangible:
		{
			TangibleObject* tangibleObject = dynamic_cast<TangibleObject*>(object);

			switch(tangibleObject->getTangibleGroup())
			{
				case TanGroup_Item:
				{
					Item* item = dynamic_cast<Item*>(object);
					if(item->getItemType() == ItemFamily_ManufacturingSchematic)
					{
						ManufacturingSchematic* schem = dynamic_cast<ManufacturingSchematic*> (object);
						//first associated item
						sprintf(sql,"DELETE FROM items WHERE id = %"PRIu64"",schem->getItem()->getId());
						mDatabase->ExecuteSqlAsync(NULL,NULL,sql);
						sprintf(sql,"DELETE FROM item_attributes WHERE item_id = %"PRIu64"",schem->getItem()->getId());
						mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

					}

					ObjectIDList* objectList		= item->getObjects();
					ObjectIDList::iterator objIt	= objectList->begin();

					while(objIt != objectList->end())
					{			
						Object* object = gWorldManager->getObjectById((*objIt));
						deleteObjectFromDB(object);
						
						++objIt;
					}

					sprintf(sql,"DELETE FROM items WHERE id = %"PRIu64"",object->getId());
					mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

					sprintf(sql,"DELETE FROM item_attributes WHERE item_id = %"PRIu64"",object->getId());
					mDatabase->ExecuteSqlAsync(NULL,NULL,sql);
				}
				break;

				case TanGroup_ResourceContainer:
				{
					sprintf(sql,"DELETE FROM resource_containers WHERE id = %"PRIu64"",object->getId());
					mDatabase->ExecuteSqlAsync(NULL,NULL,sql);
				}
				break;

				case TanGroup_Terminal:
				{
					sprintf(sql,"DELETE FROM terminals WHERE id = %"PRIu64"",object->getId());
					mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

				}
				break;

				default:break;
			}
		}
		break;

		case ObjType_Intangible:
		{
			IntangibleObject* itno = dynamic_cast<IntangibleObject*>(object);

			switch(itno->getItnoGroup())
			{
				case ItnoGroup_Vehicle:
				{
					sprintf(sql,"DELETE FROM vehicle_cutomization WHERE vehicles_id = %"PRIu64"",object->getId());
					mDatabase->ExecuteSqlAsync(NULL,NULL,sql);
					sprintf(sql,"DELETE FROM vehicle_attributes WHERE vehicles_id = %"PRIu64"",object->getId());
					mDatabase->ExecuteSqlAsync(NULL,NULL,sql);
					sprintf(sql,"DELETE FROM vehicles WHERE id = %"PRIu64"",object->getId());
					mDatabase->ExecuteSqlAsync(NULL,NULL,sql);
				}
				break;

				default: break;
			}
		}
		break;

		case ObjType_Cell:
		{
			CellObject* cell = dynamic_cast<CellObject*>(object);
			ObjectIDList* cellObjects		= cell->getObjects();
			ObjectIDList::iterator objIt	= cellObjects->begin();

			while(objIt != cellObjects->end())
			{
				Object* childObject = gWorldManager->getObjectById((*objIt));

				if(PlayerObject* player = dynamic_cast<PlayerObject*>(childObject))
				{
					//place the player in the world	and db	- do *NOT* delete him :P
					//player->setParentId(0,0xffffffff,player->getKnownPlayers(),true);
				}
				else
				if(CreatureObject* pet = dynamic_cast<CreatureObject*>(childObject))
				{
					//place the player in the world	and db	- do *NOT* delete him :P
					//pet->setParentId(0,0xffffffff,pet->getKnownPlayers(),true);
				}
				else
				{
					deleteObjectFromDB(childObject);
				}
				
				++objIt;

				sprintf(sql,"UPDATE characters SET parent_id = 0 WHERE parent_id = %"PRIu64"",object->getId());
				mDatabase->ExecuteSqlAsync(NULL,NULL,sql);
			}

			sprintf(sql,"DELETE FROM cells WHERE id = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);
		}
		break;

		case ObjType_Building:
		{
			//only delete when a playerbuilding
			HouseObject* house = dynamic_cast<HouseObject*>(object);
			if(!house)
			{
				//no player building
				return;
			}

			CellObjectList*				cellList	= house->getCellList();
			CellObjectList::iterator	cellIt		= cellList->begin();

			while(cellIt != cellList->end())
			{
				CellObject* cell = (*cellIt);
				deleteObjectFromDB(cell);
				//remove items in the building from world and db

				++cellIt;
			}

			sprintf(sql,"DELETE FROM houses WHERE ID = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			//sprintf(sql,"DELETE FROM terminals WHERE ID = %"PRIu64"",object->getId());
			//mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			sprintf(sql,"DELETE FROM structures WHERE ID = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			//Admin / Hopper Lists
			sprintf(sql,"DELETE FROM structure_admin_data WHERE StructureID = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			//update attributes cave redeed vs destroy
			sprintf(sql,"DELETE FROM structure_attributes WHERE Structure_id = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

		}
		break;
		case ObjType_Structure:
		{			

			//Harvester
			sprintf(sql,"DELETE FROM structures WHERE ID = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			sprintf(sql,"DELETE FROM harvesters WHERE ID = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			sprintf(sql,"DELETE FROM factories WHERE ID = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			//Admin / Hopper Lists
			sprintf(sql,"DELETE FROM structure_admin_data WHERE StructureID = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			//update attributes cave redeed vs destroy
			sprintf(sql,"DELETE FROM structure_attributes WHERE Structure_id = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			//update hopper contents
			sprintf(sql,"DELETE FROM harvester_resources WHERE ID = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

		}
		break;

		case ObjType_Waypoint:
		{
			sprintf(sql,"DELETE FROM waypoints WHERE waypoint_id = %"PRIu64"",object->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);
		}
		break;


		default:break;
	}
}
Beispiel #5
0
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);
}