コード例 #1
0
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;
	}
}
コード例 #2
0
ファイル: CellFactory.cpp プロジェクト: jason83/mmoserver
void CellFactory::handleObjectReady(Object* object,DispatchClient* client)
{
    InLoadingContainer* ilc = _getObject(object->getParentId());

    if (! ilc) {//Crashbug fix: http://paste.swganh.org/viewp.php?id=20100627114151-8f7df7f74013af71c0d0b00bc240770d
        gLogger->log(LogManager::WARNING,"CellFactory::handleObjectReady could not locate ILC for objectParentId:%I64u",object->getParentId());
        return;
    }

    CellObject*			cell = dynamic_cast<CellObject*>(ilc->mObject);

    gWorldManager->addObject(object,true);

    switch(object->getType())
    {
    case ObjType_NPC:
    case ObjType_Creature:
    {
        CreatureObject* creature = dynamic_cast<CreatureObject*>(object);

        if(creature->getCreoGroup() == CreoGroup_Shuttle)
            gWorldManager->addShuttle(dynamic_cast<Shuttle*>(creature));
    }
    break;

    case ObjType_Tangible:
    {
        PlayerStructureTerminal* terminal = dynamic_cast<PlayerStructureTerminal*>(object);
        if(terminal)
        {
            terminal->setStructure(cell->getParentId());
        }
    }
    break;

    case ObjType_Building:
    case ObjType_Cell:
    case ObjType_DraftSchematic:
    case ObjType_Structure:
    case ObjType_Intangible:
    case ObjType_Lair:
    case ObjType_Mission:
    case ObjType_None:
    case ObjType_NonPersistant:
    case ObjType_Player:
    case ObjType_Region:

    case ObjType_Waypoint:
    default:
        break;
    }

    cell->addObjectSecure(object);

    if(cell->getLoadCount() == cell->getObjects()->size())
    {
        if(!(_removeFromObjectLoadMap(cell->getId())))
            gLogger->log(LogManager::DEBUG,"CellFactory: Failed removing object from loadmap");

        ilc->mOfCallback->handleObjectReady(cell,ilc->mClient);

        mILCPool.free(ilc);
    }
}