Beispiel #1
0
        public static Difficulty CheckLoadedDungeonDifficultyID(Difficulty difficulty)
        {
            DifficultyRecord difficultyEntry = CliDB.DifficultyStorage.LookupByKey(difficulty);

            if (difficultyEntry == null)
            {
                return(Difficulty.Normal);
            }

            if (difficultyEntry.InstanceType != MapTypes.Instance)
            {
                return(Difficulty.Normal);
            }

            if (!difficultyEntry.Flags.HasAnyFlag(DifficultyFlags.CanSelect))
            {
                return(Difficulty.Normal);
            }

            return(difficulty);
        }
Beispiel #2
0
        public static Difficulty CheckLoadedLegacyRaidDifficultyID(Difficulty difficulty)
        {
            DifficultyRecord difficultyEntry = CliDB.DifficultyStorage.LookupByKey(difficulty);

            if (difficultyEntry == null)
            {
                return(Difficulty.Raid10N);
            }

            if (difficultyEntry.InstanceType != MapTypes.Raid)
            {
                return(Difficulty.Raid10N);
            }

            if (!difficultyEntry.Flags.HasAnyFlag(DifficultyFlags.CanSelect) || !difficultyEntry.Flags.HasAnyFlag(DifficultyFlags.Legacy))
            {
                return(Difficulty.Raid10N);
            }

            return(difficulty);
        }
Beispiel #3
0
        public Difficulty GetDifficultyID(MapRecord mapEntry)
        {
            if (!mapEntry.IsRaid())
            {
                return(m_dungeonDifficulty);
            }

            MapDifficultyRecord defaultDifficulty = Global.DB2Mgr.GetDefaultMapDifficulty(mapEntry.Id);

            if (defaultDifficulty == null)
            {
                return(m_legacyRaidDifficulty);
            }

            DifficultyRecord difficulty = CliDB.DifficultyStorage.LookupByKey(defaultDifficulty.DifficultyID);

            if (difficulty == null || difficulty.Flags.HasAnyFlag(DifficultyFlags.Legacy))
            {
                return(m_legacyRaidDifficulty);
            }

            return(m_raidDifficulty);
        }
Beispiel #4
0
        void HandleSetRaidDifficulty(SetRaidDifficulty setRaidDifficulty)
        {
            DifficultyRecord difficultyEntry = CliDB.DifficultyStorage.LookupByKey(setRaidDifficulty.DifficultyID);

            if (difficultyEntry == null)
            {
                Log.outDebug(LogFilter.Network, "WorldSession.HandleSetDungeonDifficulty: {0} sent an invalid instance mode {1}!",
                             GetPlayer().GetGUID().ToString(), setRaidDifficulty.DifficultyID);
                return;
            }

            if (difficultyEntry.InstanceType != MapTypes.Raid)
            {
                Log.outDebug(LogFilter.Network, "WorldSession.HandleSetDungeonDifficulty: {0} sent an non-dungeon instance mode {1}!",
                             GetPlayer().GetGUID().ToString(), difficultyEntry.Id);
                return;
            }

            if (!difficultyEntry.Flags.HasAnyFlag(DifficultyFlags.CanSelect))
            {
                Log.outDebug(LogFilter.Network, "WorldSession.HandleSetDungeonDifficulty: {0} sent unselectable instance mode {1}!",
                             GetPlayer().GetGUID().ToString(), difficultyEntry.Id);
                return;
            }

            if (((int)(difficultyEntry.Flags & DifficultyFlags.Legacy) >> 5) != setRaidDifficulty.Legacy)
            {
                Log.outDebug(LogFilter.Network, "WorldSession.HandleSetDungeonDifficulty: {0} sent not matching legacy difficulty {1}!",
                             GetPlayer().GetGUID().ToString(), difficultyEntry.Id);
                return;
            }

            Difficulty difficultyID = (Difficulty)difficultyEntry.Id;

            if (difficultyID == (setRaidDifficulty.Legacy != 0 ? GetPlayer().GetLegacyRaidDifficultyID() : GetPlayer().GetRaidDifficultyID()))
            {
                return;
            }

            // cannot reset while in an instance
            Map map = GetPlayer().GetMap();

            if (map && map.IsDungeon())
            {
                Log.outDebug(LogFilter.Network, "WorldSession:HandleSetRaidDifficulty: player (Name: {0}, {1} tried to reset the instance while inside!",
                             GetPlayer().GetName(), GetPlayer().GetGUID().ToString());
                return;
            }

            Group group = GetPlayer().GetGroup();

            if (group)
            {
                if (group.IsLeader(GetPlayer().GetGUID()))
                {
                    for (GroupReference refe = group.GetFirstMember(); refe != null; refe = refe.Next())
                    {
                        Player groupGuy = refe.GetSource();
                        if (!groupGuy)
                        {
                            continue;
                        }

                        if (!groupGuy.IsInMap(groupGuy))
                        {
                            return;
                        }

                        if (groupGuy.GetMap().IsRaid())
                        {
                            Log.outDebug(LogFilter.Network, "WorldSession:HandleSetRaidDifficulty: player {0} tried to reset the instance while inside!", GetPlayer().GetGUID().ToString());
                            return;
                        }
                    }
                    // the difficulty is set even if the instances can't be reset
                    group.ResetInstances(InstanceResetMethod.ChangeDifficulty, true, setRaidDifficulty.Legacy != 0, GetPlayer());
                    if (setRaidDifficulty.Legacy != 0)
                    {
                        group.SetLegacyRaidDifficultyID(difficultyID);
                    }
                    else
                    {
                        group.SetRaidDifficultyID(difficultyID);
                    }
                }
            }
            else
            {
                GetPlayer().ResetInstances(InstanceResetMethod.ChangeDifficulty, true, setRaidDifficulty.Legacy != 0);
                if (setRaidDifficulty.Legacy != 0)
                {
                    GetPlayer().SetLegacyRaidDifficultyID(difficultyID);
                }
                else
                {
                    GetPlayer().SetRaidDifficultyID(difficultyID);
                }

                GetPlayer().SendRaidDifficulty(setRaidDifficulty.Legacy != 0);
            }
        }
Beispiel #5
0
        void HandleSetDungeonDifficulty(SetDungeonDifficulty setDungeonDifficulty)
        {
            DifficultyRecord difficultyEntry = CliDB.DifficultyStorage.LookupByKey(setDungeonDifficulty.DifficultyID);

            if (difficultyEntry == null)
            {
                Log.outDebug(LogFilter.Network, "WorldSession.HandleSetDungeonDifficulty: {0} sent an invalid instance mode {1}!",
                             GetPlayer().GetGUID().ToString(), setDungeonDifficulty.DifficultyID);
                return;
            }

            if (difficultyEntry.InstanceType != MapTypes.Instance)
            {
                Log.outDebug(LogFilter.Network, "WorldSession.HandleSetDungeonDifficulty: {0} sent an non-dungeon instance mode {1}!",
                             GetPlayer().GetGUID().ToString(), difficultyEntry.Id);
                return;
            }

            if (!difficultyEntry.Flags.HasAnyFlag(DifficultyFlags.CanSelect))
            {
                Log.outDebug(LogFilter.Network, "WorldSession.HandleSetDungeonDifficulty: {0} sent unselectable instance mode {1}!",
                             GetPlayer().GetGUID().ToString(), difficultyEntry.Id);
                return;
            }

            Difficulty difficultyID = (Difficulty)difficultyEntry.Id;

            if (difficultyID == GetPlayer().GetDungeonDifficultyID())
            {
                return;
            }

            // cannot reset while in an instance
            Map map = GetPlayer().GetMap();

            if (map && map.IsDungeon())
            {
                Log.outDebug(LogFilter.Network, "WorldSession:HandleSetDungeonDifficulty: player (Name: {0}, {1}) tried to reset the instance while player is inside!",
                             GetPlayer().GetName(), GetPlayer().GetGUID().ToString());
                return;
            }

            Group group = GetPlayer().GetGroup();

            if (group)
            {
                if (group.IsLeader(GetPlayer().GetGUID()))
                {
                    for (GroupReference refe = group.GetFirstMember(); refe != null; refe = refe.Next())
                    {
                        Player groupGuy = refe.GetSource();
                        if (!groupGuy)
                        {
                            continue;
                        }

                        if (!groupGuy.IsInMap(groupGuy))
                        {
                            return;
                        }

                        if (groupGuy.GetMap().IsNonRaidDungeon())
                        {
                            Log.outDebug(LogFilter.Network, "WorldSession:HandleSetDungeonDifficulty: {0} tried to reset the instance while group member (Name: {1}, {2}) is inside!",
                                         GetPlayer().GetGUID().ToString(), groupGuy.GetName(), groupGuy.GetGUID().ToString());
                            return;
                        }
                    }
                    // the difficulty is set even if the instances can't be reset
                    //_player.SendDungeonDifficulty(true);
                    group.ResetInstances(InstanceResetMethod.ChangeDifficulty, false, false, GetPlayer());
                    group.SetDungeonDifficultyID(difficultyID);
                }
            }
            else
            {
                GetPlayer().ResetInstances(InstanceResetMethod.ChangeDifficulty, false, false);
                GetPlayer().SetDungeonDifficultyID(difficultyID);
                GetPlayer().SendDungeonDifficulty();
            }
        }
Beispiel #6
0
        public InstanceSave AddInstanceSave(uint mapId, uint instanceId, Difficulty difficulty, long resetTime, uint entranceId, bool canReset, bool load = false)
        {
            InstanceSave old_save = GetInstanceSave(instanceId);

            if (old_save != null)
            {
                return(old_save);
            }

            MapRecord entry = CliDB.MapStorage.LookupByKey(mapId);

            if (entry == null)
            {
                Log.outError(LogFilter.Server, "InstanceSaveManager.AddInstanceSave: wrong mapid = {0}, instanceid = {1}!", mapId, instanceId);
                return(null);
            }

            if (instanceId == 0)
            {
                Log.outError(LogFilter.Server, "InstanceSaveManager.AddInstanceSave: mapid = {0}, wrong instanceid = {1}!", mapId, instanceId);
                return(null);
            }

            DifficultyRecord difficultyEntry = CliDB.DifficultyStorage.LookupByKey(difficulty);

            if (difficultyEntry == null || difficultyEntry.InstanceType != entry.InstanceType)
            {
                Log.outError(LogFilter.Server, "InstanceSaveManager.AddInstanceSave: mapid = {0}, instanceid = {1}, wrong dificalty {2}!", mapId, instanceId, difficulty);
                return(null);
            }

            if (entranceId != 0 && !CliDB.WorldSafeLocsStorage.ContainsKey(entranceId))
            {
                Log.outWarn(LogFilter.Misc, "InstanceSaveManager.AddInstanceSave: invalid entranceId = {0} defined for instance save with mapid = {1}, instanceid = {2}!", entranceId, mapId, instanceId);
                entranceId = 0;
            }

            if (resetTime == 0)
            {
                // initialize reset time
                // for normal instances if no creatures are killed the instance will reset in two hours
                if (entry.InstanceType == MapTypes.Raid || difficulty > Difficulty.Normal)
                {
                    resetTime = GetResetTimeFor(mapId, difficulty);
                }
                else
                {
                    resetTime = Time.UnixTime + 2 * Time.Hour;
                    // normally this will be removed soon after in InstanceMap.Add, prevent error
                    ScheduleReset(true, resetTime, new InstResetEvent(0, mapId, difficulty, instanceId));
                }
            }

            Log.outDebug(LogFilter.Maps, "InstanceSaveManager.AddInstanceSave: mapid = {0}, instanceid = {1}", mapId, instanceId);

            InstanceSave save = new InstanceSave(mapId, instanceId, difficulty, entranceId, resetTime, canReset);

            if (!load)
            {
                save.SaveToDB();
            }

            m_instanceSaveById[instanceId] = save;
            return(save);
        }
Beispiel #7
0
        public void LoadGroups()
        {
            {
                uint oldMSTime = Time.GetMSTime();

                // Delete all groups whose leader does not exist
                DB.Characters.DirectExecute("DELETE FROM groups WHERE leaderGuid NOT IN (SELECT guid FROM characters)");
                // Delete all groups with less than 2 members
                DB.Characters.DirectExecute("DELETE FROM groups WHERE guid NOT IN (SELECT guid FROM group_member GROUP BY guid HAVING COUNT(guid) > 1)");

                //                                                    0              1           2             3                 4      5          6      7         8       9
                SQLResult result = DB.Characters.Query("SELECT g.leaderGuid, g.lootMethod, g.looterGuid, g.lootThreshold, g.icon1, g.icon2, g.icon3, g.icon4, g.icon5, g.icon6" +
                                                       //  10         11          12         13              14                  15                     16             17          18         19
                                                       ", g.icon7, g.icon8, g.groupType, g.difficulty, g.raiddifficulty, g.legacyRaidDifficulty, g.masterLooterGuid, g.guid, lfg.dungeon, lfg.state FROM groups g LEFT JOIN lfg_data lfg ON lfg.guid = g.guid ORDER BY g.guid ASC");
                if (result.IsEmpty())
                {
                    Log.outInfo(LogFilter.ServerLoading, "Loaded 0 group definitions. DB table `groups` is empty!");
                    return;
                }

                uint count = 0;
                do
                {
                    Group group = new Group();
                    group.LoadGroupFromDB(result.GetFields());
                    AddGroup(group);

                    // Get the ID used for storing the group in the database and register it in the pool.
                    uint storageId = group.GetDbStoreId();

                    RegisterGroupDbStoreId(storageId, group);

                    // Increase the next available storage ID
                    if (storageId == NextGroupDbStoreId)
                    {
                        NextGroupDbStoreId++;
                    }

                    ++count;
                }while (result.NextRow());

                Log.outInfo(LogFilter.ServerLoading, "Loaded {0} group definitions in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime));
            }

            Log.outInfo(LogFilter.ServerLoading, "Loading Group members...");
            {
                uint oldMSTime = Time.GetMSTime();

                // Delete all rows from group_member or group_instance with no group
                DB.Characters.DirectExecute("DELETE FROM group_member WHERE guid NOT IN (SELECT guid FROM groups)");
                DB.Characters.DirectExecute("DELETE FROM group_instance WHERE guid NOT IN (SELECT guid FROM groups)");
                // Delete all members that does not exist
                DB.Characters.DirectExecute("DELETE FROM group_member WHERE memberGuid NOT IN (SELECT guid FROM characters)");

                //                                                0        1           2            3       4
                SQLResult result = DB.Characters.Query("SELECT guid, memberGuid, memberFlags, subgroup, roles FROM group_member ORDER BY guid");
                if (result.IsEmpty())
                {
                    Log.outInfo(LogFilter.ServerLoading, "Loaded 0 group members. DB table `group_member` is empty!");
                    return;
                }

                uint count = 0;

                do
                {
                    Group group = GetGroupByDbStoreId(result.Read <uint>(0));

                    if (group)
                    {
                        group.LoadMemberFromDB(result.Read <uint>(1), result.Read <byte>(2), result.Read <byte>(3), (LfgRoles)result.Read <byte>(4));
                    }
                    else
                    {
                        Log.outError(LogFilter.Server, "GroupMgr:LoadGroups: Consistency failed, can't find group (storage id: {0})", result.Read <uint>(0));
                    }

                    ++count;
                }while (result.NextRow());

                Log.outInfo(LogFilter.ServerLoading, "Loaded {0} group members in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime));
            }

            Log.outInfo(LogFilter.ServerLoading, "Loading Group instance saves...");
            {
                uint oldMSTime = Time.GetMSTime();

                //                                                0           1        2              3             4             5            6           7
                SQLResult result = DB.Characters.Query("SELECT gi.guid, i.map, gi.instance, gi.permanent, i.difficulty, i.resettime, i.entranceId, COUNT(g.guid) " +
                                                       "FROM group_instance gi INNER JOIN instance i ON gi.instance = i.id " +
                                                       "LEFT JOIN character_instance ci LEFT JOIN groups g ON g.leaderGuid = ci.guid ON ci.instance = gi.instance AND ci.permanent = 1 GROUP BY gi.instance ORDER BY gi.guid");
                if (result.IsEmpty())
                {
                    Log.outInfo(LogFilter.ServerLoading, "Loaded 0 group-instance saves. DB table `group_instance` is empty!");
                    return;
                }

                uint count = 0;
                do
                {
                    Group group = GetGroupByDbStoreId(result.Read <uint>(0));
                    // group will never be NULL (we have run consistency sql's before loading)

                    MapRecord mapEntry = CliDB.MapStorage.LookupByKey(result.Read <ushort>(1));
                    if (mapEntry == null || !mapEntry.IsDungeon())
                    {
                        Log.outError(LogFilter.Sql, "Incorrect entry in group_instance table : no dungeon map {0}", result.Read <ushort>(1));
                        continue;
                    }

                    uint             diff            = result.Read <byte>(4);
                    DifficultyRecord difficultyEntry = CliDB.DifficultyStorage.LookupByKey(diff);
                    if (difficultyEntry == null || difficultyEntry.InstanceType != mapEntry.InstanceType)
                    {
                        continue;
                    }

                    InstanceSave save = Global.InstanceSaveMgr.AddInstanceSave(mapEntry.Id, result.Read <uint>(2), (Difficulty)diff, result.Read <uint>(5), result.Read <uint>(6), result.Read <ulong>(7) != 0, true);
                    group.BindToInstance(save, result.Read <bool>(3), true);
                    ++count;
                }while (result.NextRow());

                Log.outInfo(LogFilter.ServerLoading, "Loaded {0} group-instance saves in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime));
            }
        }
Beispiel #8
0
        public void SaveToDB()
        {
            if (_criteriaProgress.Empty())
            {
                return;
            }

            DifficultyRecord difficultyEntry = CliDB.DifficultyStorage.LookupByKey(_map.GetDifficultyID());

            if (difficultyEntry == null || difficultyEntry.Flags.HasAnyFlag(DifficultyFlags.ChallengeMode)) // Map should have some sort of "CanSave" boolean that returns whether or not the map is savable. (Challenge modes cannot be saved for example)
            {
                return;
            }

            uint id = _map.GetInstanceId();

            if (id == 0)
            {
                Log.outDebug(LogFilter.Scenario, "Scenario.SaveToDB: Can not save scenario progress without an instance save. Map.GetInstanceId() did not return an instance save.");
                return;
            }

            SQLTransaction trans = new SQLTransaction();

            foreach (var iter in _criteriaProgress)
            {
                if (!iter.Value.Changed)
                {
                    continue;
                }

                Criteria criteria = Global.CriteriaMgr.GetCriteria(iter.Key);
                switch (criteria.Entry.Type)
                {
                // Blizzard only appears to store creature kills
                case CriteriaTypes.KillCreature:
                    break;

                default:
                    continue;
                }

                if (iter.Value.Counter != 0)
                {
                    PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_SCENARIO_INSTANCE_CRITERIA);
                    stmt.AddValue(0, id);
                    stmt.AddValue(1, iter.Key);
                    trans.Append(stmt);

                    stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_SCENARIO_INSTANCE_CRITERIA);
                    stmt.AddValue(0, id);
                    stmt.AddValue(1, iter.Key);
                    stmt.AddValue(2, iter.Value.Counter);
                    stmt.AddValue(3, (uint)iter.Value.Date);
                    trans.Append(stmt);
                }

                iter.Value.Changed = false;
            }

            DB.Characters.CommitTransaction(trans);
        }