Exemple #1
0
void InstanceMgr::_LoadInstances()
{
	MapInfo* inf;
	Instance* in;
	QueryResult* result;

	// clear any instances that have expired.
	Log.Success("InstanceMgr", "Deleting Expired Instances...");
	CharacterDatabase.WaitExecute("DELETE FROM instances WHERE expiration > 0 AND expiration <= %u", UNIXTIME);
	CharacterDatabase.Execute("DELETE FROM instanceids WHERE instanceid NOT IN ( SELECT id FROM instances )");

	// load saved instances
	result = CharacterDatabase.Query("SELECT id, mapid, creation, expiration, killed_npc_guids, difficulty, creator_group, creator_guid, persistent FROM instances");
	Log.Success("InstanceMgr", "Loading %u saved instances." , result ? result->GetRowCount() : 0);

	if(result)
	{
		do
		{
			inf = WorldMapInfoStorage.LookupEntry(result->Fetch()[1].GetUInt32());
			if(inf == NULL || result->Fetch()[1].GetUInt32() >= NUM_MAPS)
			{
				CharacterDatabase.Execute("DELETE FROM instances WHERE mapid = %u", result->Fetch()[1].GetUInt32());
				continue;
			}

			in = new Instance();
			in->m_mapInfo = inf;
			in->LoadFromDB(result->Fetch());

			// this assumes that groups are already loaded at this point.
			if(!in->m_persistent && in->m_creatorGroup && objmgr.GetGroupById(in->m_creatorGroup) == NULL)
			{
				CharacterDatabase.Execute("DELETE FROM `instances` WHERE `id` = %u", in->m_instanceId);
				delete in;
				continue;
			}

			if(m_instances[in->m_mapId] == NULL)
				m_instances[in->m_mapId] = new InstanceMap;

			m_instances[in->m_mapId]->insert(InstanceMap::value_type(in->m_instanceId, in));

		}
		while(result->NextRow());
		delete result;
	}
}
void InstanceMgr::_LoadInstances()
{
	MapInfo * inf;
	Instance * in;
	QueryResult * result;

	// clear any instances that have expired.
	Log.Notice("InstanceMgr", "Deleting Expired Instances...");
	CharacterDatabase.WaitExecute("DELETE FROM instances WHERE expiration <= %u", UNIXTIME);
	
	// load saved instances
	result = CharacterDatabase.Query("SELECT * FROM instances");
	Log.Notice("InstanceMgr", "Loading %u saved instances." , result ? result->GetRowCount() : 0);

	if(result)
	{
		do 
		{
			inf = WorldMapInfoStorage.LookupEntry(result->Fetch()[1].GetUInt32());
			if(inf == NULL || result->Fetch()[1].GetUInt32() >= NUM_MAPS)
			{
				CharacterDatabase.Execute("DELETE FROM instances WHERE mapid = %u", result->Fetch()[1].GetUInt32());
				continue;
			}

			in = new Instance();
			in->m_mapInfo = inf;
			in->LoadFromDB(result->Fetch());

			if(m_instances[in->m_mapId] == NULL)
				m_instances[in->m_mapId] = new InstanceMap;

			m_instances[in->m_mapId]->insert( InstanceMap::value_type( in->m_instanceId, in ) );

		} while(result->NextRow());
		DEBUG_LOG("InstanceMgr", "Loading %u saved instances." , result->GetRowCount());
		delete result;
	}
	else
		DEBUG_LOG("InstanceMgr", "No saved instances found.");

	//reset the SavedInstanceId on expired instances.
	CharacterDatabase.WaitExecute("UPDATE groups LEFT JOIN instances ON groups.GroupInstanceID = instances.id SET groups.GroupInstanceID = 0 WHERE instances.id IS NULL;"); 
}
void InstanceMgr::_LoadInstances()
{
    MapInfo* inf;
    Instance* in;
    QueryResult* result;

    // clear any instances that have expired.
    sLog.Notice("InstanceMgr", "Deleting Expired Instances...");
    CharacterDatabase.WaitExecute("DELETE FROM instances WHERE expiration <= %u", UNIXTIME);

    // load saved instances
    result = CharacterDatabase.Query("SELECT * FROM instances");
    sLog.Notice("InstanceMgr", "Loading %u saved instance(s)." , result ? result->GetRowCount() : 0);

    if(result)
    {
        do
        {
            inf = WorldMapInfoStorage.LookupEntry(result->Fetch()[1].GetUInt32());
            if(inf == NULL || result->Fetch()[1].GetUInt32() >= NUM_MAPS)
            {
                CharacterDatabase.Execute("DELETE FROM instances WHERE mapid = %u", result->Fetch()[1].GetUInt32());
                continue;
            }

            in = new Instance();
            in->m_mapInfo = inf;
            in->m_dbcMap = dbcMap.LookupEntry(inf->mapid);
            in->LoadFromDB(result->Fetch());

            if(m_instances[in->m_mapId] == NULL)
                m_instances[in->m_mapId] = new InstanceMap;

            m_instances[in->m_mapId]->insert( InstanceMap::value_type( in->m_instanceId, in ) );
        } while(result->NextRow());
        sLog.Success("InstanceMgr", "Loaded %u saved instance(s)." , result->GetRowCount());
        delete result;
    }
    else
        sLog.Debug("InstanceMgr", "No saved instances found.");
}