void InstanceSaveManager::LoadInstanceSaves()
{
    QueryResult result = CharacterDatabase.Query("SELECT id, map, resettime, difficulty, completedEncounters, data FROM instance ORDER BY id ASC");
    if (result)
    {
        do
        {
            Field* fields = result->Fetch();

            uint32 instanceId = fields[0].GetUInt32();
            uint32 mapId = fields[1].GetUInt16();
            time_t resettime = time_t(fields[2].GetUInt32());
            uint8 difficulty = fields[3].GetUInt8();
            uint32 completedEncounters = fields[4].GetUInt32();
            std::string instanceData = fields[5].GetString();

            // Mark instance id as being used
            sMapMgr->RegisterInstanceId(instanceId);

            InstanceSave* save = AddInstanceSave(mapId, instanceId, Difficulty(difficulty), true);
            if (save)
            {
                save->SetCompletedEncounterMask(completedEncounters);
                save->SetInstanceData(instanceData);
                if (resettime > 0)
                    save->SetResetTime(resettime);
            }
        }
        while (result->NextRow());
    }
}
Example #2
0
void InstanceScript::SaveToDB()
{
    std::string data = GetSaveData();
    //if (data.empty()) // pussywizard: encounterMask can be updated and theres no reason to not save
    //    return;

	// pussywizard:
	InstanceSave* save = sInstanceSaveMgr->GetInstanceSave(instance->GetInstanceId());
	if (save)
		save->SetInstanceData(data);

    PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_INSTANCE_SAVE_DATA);
    stmt->setString(0, data);
    stmt->setUInt32(1, instance->GetInstanceId());
    CharacterDatabase.Execute(stmt);
}