public static SummonedPetRecord[] LoadSummonedPetRecords(uint ownerId)
 {
     try
     {
         return(FindAllByProperty("_OwnerLowId", (int)ownerId));
     }
     catch (Exception e)
     {
         RealmDBMgr.OnDBError(e);
         return(FindAllByProperty("_OwnerLowId", (int)ownerId));
     }
 }
Exemple #2
0
 public static SummonedPetRecord[] LoadSummonedPetRecords(uint ownerId)
 {
     try
     {
         return(ActiveRecordBase <SummonedPetRecord> .FindAllByProperty("_OwnerLowId", (object)(int)ownerId));
     }
     catch (Exception ex)
     {
         RealmDBMgr.OnDBError(ex);
         return(ActiveRecordBase <SummonedPetRecord> .FindAllByProperty("_OwnerLowId", (object)(int)ownerId));
     }
 }
Exemple #3
0
 [Initialization(InitializationPass.Sixth)]              // init after NHIdGenerator init'ed (Fifth)
 public static void Initialize()
 {
     try
     {
         CreateIdGenerators();
     }
     catch (Exception e)
     {
         RealmDBMgr.OnDBError(e);
         CreateIdGenerators();
     }
 }
Exemple #4
0
 public static void InitBanMgr()
 {
     try
     {
         BanMgr.m_bans = ((IEnumerable <BanEntry>)ActiveRecordBase <BanEntry> .FindAll()).ToList <BanEntry>();
     }
     catch (Exception ex)
     {
         RealmDBMgr.OnDBError(ex);
         BanMgr.m_bans = ((IEnumerable <BanEntry>)ActiveRecordBase <BanEntry> .FindAll()).ToList <BanEntry>();
     }
 }
Exemple #5
0
        /// <summary>
        /// Creates a game account.
        /// Make sure that the Account-name does not exist before calling this method.
        /// </summary>
        /// <param name="username">the username of the account</param>
        /// <param name="passHash">the hashed password of the account</param>
        public Account CreateAccount(string username,
                                     string password, string email, string privLevel)
        {
            try
            {
                var usr = new Account(
                    username,
                    password,
                    email)
                {
                    RoleGroupName = privLevel,
                    Created       = DateTime.Now,
                    IsActive      = true
                };

                try
                {
                    usr.CreateAndFlush();
                }
                catch (Exception e)
                {
#if DEBUG
                    RealmDBMgr.OnDBError(e);
                    usr.CreateAndFlush();
#else
                    throw e;
#endif
                }

                if (IsCached)
                {
                    using (m_lock.EnterWriteLock())
                    {
                        Update(usr);
                    }
                }
                Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)usr.AccountId)
                .AddAttribute("operation", 1, "registering")
                .AddAttribute("name", 0, username)
                .AddAttribute("role", 0, privLevel)
                .Write();

                log.Info(string.Format("Autocreating acc {0} - {1}", username, usr.RoleGroupName));
                return(usr);
            }
            catch (Exception ex)
            {
                LogUtil.ErrorException(ex, string.Format("Failed autocreate acc {0}.", username));
            }
            return(null);
        }
Exemple #6
0
        public static void Init()
        {
            RealmDBMgr.Initialize();
            var mgr = RealmServer.RealmServer.InitMgr;

            RealmAddonMgr.Initialize(mgr);
            mgr.PerformInitialization();

            ContentMgr.Initialize();

            SpellHandler.LoadSpells();
            FactionMgr.Initialize();
            SpellHandler.Initialize2();
        }
Exemple #7
0
 public static void Initialize()
 {
     InstanceInfos.Sort();
     InstanceConfig.LoadSettings();
     try
     {
         GlobalResetTimers = GlobalInstanceTimer.LoadTimers();
     }
     catch (Exception ex)
     {
         RealmDBMgr.OnDBError(ex);
         GlobalResetTimers = GlobalInstanceTimer.LoadTimers();
     }
 }
Exemple #8
0
        public static void ResetDB()
        {
            RealmDBMgr.Initialize();

            int count = CharacterRecord.GetCount();

            if (count > 500)
            {
                throw new Exception("Cannot run tests on production servers since it requires to drop the complete Database. " +
                                    "Test run aborted because " + count + " Characters were found (must not be more than 500). Drop the Database manually to proceed.");
            }

            DatabaseUtil.DropSchema();
            DatabaseUtil.CreateSchema();
        }
Exemple #9
0
        protected bool Start()
        {
            try
            {
                this.IsCached = RealmServerConfiguration.CacheAccounts;
                if (this.Count == 0)
                {
                    AccountMgr.log.Info("Detected empty Account-database.");
                }
            }
            catch (Exception ex)
            {
                RealmDBMgr.OnDBError(ex);
            }

            return(true);
        }
Exemple #10
0
        public static void CreateMaps()
        {
            if (Maps != null)
            {
                return;
            }

            RealmDBMgr.Initialize();
            ContentMgr.Initialize();
            SpellHandler.LoadSpells();
            SpellHandler.Initialize2();

            World.InitializeWorld();
            World.LoadDefaultMaps();
            ArchetypeMgr.EnsureInitialize();                            // for default spells

            NPCMgr.LoadNPCDefs();                                       // for trainers

            Maps = new Dictionary <string, HashSet <Spell> > [(int)ClassId.End];

            FindTalents();
            FindAbilities();

            foreach (var spell in SpellHandler.ById)
            {
                if (spell != null && spell.Ability != null && LineSkills.Contains(spell.Ability.Skill.Id))
                {
                    AddSpell(spell, true);
                }
            }

            // remove empty lines
            foreach (var dict in Maps)
            {
                if (dict != null)
                {
                    foreach (var pair in dict.ToArray())
                    {
                        if (pair.Value.Count == 0)
                        {
                            dict.Remove(pair.Key);
                        }
                    }
                }
            }
        }
Exemple #11
0
        /// <summary>
        /// If we want this method to be public,
        /// it should update all Quests correctly (remove non-existant ones etc)
        /// </summary>
        internal void Load()
        {
            QuestRecord[] records;
            try
            {
                records = QuestRecord.GetQuestRecordForCharacter(Owner.EntityId.Low);
            }
            catch (Exception e)
            {
                RealmDBMgr.OnDBError(e);
                records = QuestRecord.GetQuestRecordForCharacter(Owner.EntityId.Low);
            }

            if (records != null)
            {
                foreach (var record in records)
                {
                    var templ = QuestMgr.GetTemplate(record.QuestTemplateId);
                    if (templ != null)
                    {
                        var quest = new Quest(this, record, templ);
                        AddQuest(quest);

                        //Cancel any quests relating to inactive events
                        if (templ.EventIds.Count > 0)
                        {
                            if (!templ.EventIds.Where(WorldEventMgr.IsEventActive).Any())
                            {
                                quest.Cancel(false);
                            }
                        }
                    }
                    else
                    {
                        log.Error("Character {0} had Invalid Quest: {1} (Record: {2})", Owner,
                                  record.QuestTemplateId, record.QuestRecordId);
                    }
                }
            }
        }
Exemple #12
0
        private void Initialize()
        {
            BaseRelation[] all;
            try
            {
                all = PersistedRelation.GetAll();
            }
            catch (Exception ex)
            {
                RealmDBMgr.OnDBError(ex);
                all = PersistedRelation.GetAll();
            }

            m_lock.EnterWriteLock();
            try
            {
                foreach (PersistedRelation persistedRelation in all)
                {
                    HashSet <IBaseRelation> baseRelationSet;
                    if (!m_activeRelations[(int)persistedRelation.Type]
                        .TryGetValue(persistedRelation.CharacterId, out baseRelationSet))
                    {
                        m_activeRelations[(int)persistedRelation.Type].Add(persistedRelation.CharacterId,
                                                                           baseRelationSet = new HashSet <IBaseRelation>());
                    }
                    baseRelationSet.Add(persistedRelation);
                    if (!m_passiveRelations[(int)persistedRelation.Type]
                        .TryGetValue(persistedRelation.RelatedCharacterId, out baseRelationSet))
                    {
                        m_passiveRelations[(int)persistedRelation.Type].Add(persistedRelation.RelatedCharacterId,
                                                                            baseRelationSet = new HashSet <IBaseRelation>());
                    }
                    baseRelationSet.Add(persistedRelation);
                }
            }
            finally
            {
                m_lock.ExitWriteLock();
            }
        }
Exemple #13
0
 /// <summary>
 ///
 /// </summary>
 public void LoadItems()
 {
     if (!_hasItemLoaded)
     {
         try
         {
             foreach (var itemRecord in ItemRecord.LoadAuctionedItems())
             {
                 _auctionedItems.Add(itemRecord.EntityLowId, itemRecord);
             }
             _hasItemLoaded = true;
         }
         catch (Exception e)
         {
             RealmDBMgr.OnDBError(e);
             foreach (var itemRecord in ItemRecord.LoadAuctionedItems())
             {
                 _auctionedItems.Add(itemRecord.EntityLowId, itemRecord);
             }
             _hasItemLoaded = true;
         }
     }
 }
Exemple #14
0
        private void Initialize()
        {
            BaseRelation[] found;
            try
            {
                found = PersistedRelation.GetAll();
            }
            catch (Exception e)
            {
                RealmDBMgr.OnDBError(e);
                found = PersistedRelation.GetAll();
            }

            m_lock.EnterWriteLock();
            try
            {
                foreach (PersistedRelation relation in found)
                {
                    HashSet <IBaseRelation> relations;
                    if (!m_activeRelations[(int)relation.Type].TryGetValue(relation.CharacterId, out relations))
                    {
                        m_activeRelations[(int)relation.Type].Add(relation.CharacterId, relations = new HashSet <IBaseRelation>());
                    }
                    relations.Add(relation);

                    if (!m_passiveRelations[(int)relation.Type].TryGetValue(relation.RelatedCharacterId, out relations))
                    {
                        m_passiveRelations[(int)relation.Type].Add(relation.RelatedCharacterId, relations = new HashSet <IBaseRelation>());
                    }
                    relations.Add(relation);
                }
            }
            finally
            {
                m_lock.ExitWriteLock();
            }
        }
Exemple #15
0
        /// <summary>
        /// If we want this method to be public,
        /// it should update all Quests correctly (remove non-existant ones etc)
        /// </summary>
        internal void Load()
        {
            QuestRecord[] recordForCharacter;
            try
            {
                recordForCharacter = QuestRecord.GetQuestRecordForCharacter(Owner.EntityId.Low);
            }
            catch (Exception ex)
            {
                RealmDBMgr.OnDBError(ex);
                recordForCharacter = QuestRecord.GetQuestRecordForCharacter(Owner.EntityId.Low);
            }

            if (recordForCharacter == null)
            {
                return;
            }
            foreach (QuestRecord record in recordForCharacter)
            {
                QuestTemplate template = QuestMgr.GetTemplate(record.QuestTemplateId);
                if (template != null)
                {
                    Quest quest = new Quest(this, record, template);
                    AddQuest(quest);
                    if (template.EventIds.Count > 0 && !template.EventIds
                        .Where(WorldEventMgr.IsEventActive).Any())
                    {
                        quest.Cancel(false);
                    }
                }
                else
                {
                    log.Error("Character {0} had Invalid Quest: {1} (Record: {2})", Owner,
                              record.QuestTemplateId, record.QuestRecordId);
                }
            }
        }
Exemple #16
0
 /// <summary>
 ///
 /// </summary>
 public void LoadItems()
 {
     if (_hasItemLoaded)
     {
         return;
     }
     try
     {
         foreach (ItemRecord loadAuctionedItem in ItemRecord.LoadAuctionedItems())
         {
             _auctionedItems.Add(loadAuctionedItem.EntityLowId, loadAuctionedItem);
         }
         _hasItemLoaded = true;
     }
     catch (Exception ex)
     {
         RealmDBMgr.OnDBError(ex);
         foreach (ItemRecord loadAuctionedItem in ItemRecord.LoadAuctionedItems())
         {
             _auctionedItems.Add(loadAuctionedItem.EntityLowId, loadAuctionedItem);
         }
         _hasItemLoaded = true;
     }
 }
Exemple #17
0
 public Account this[long id]
 {
     get
     {
         if (IsCached)
         {
             using (m_lock.EnterReadLock())
             {
                 Account acc;
                 m_cachedAccsById.TryGetValue(id, out acc);
                 return(acc);
             }
         }
         try
         {
             return(Account.FindOne(Restrictions.Eq("AccountId", (int)id)));
         }
         catch (Exception e)
         {
             RealmDBMgr.OnDBError(e);
             return(Account.FindOne(Restrictions.Eq("AccountId", (int)id)));
         }
     }
 }
Exemple #18
0
        /// <summary>
        /// Reloads all account-data
        /// </summary>
        public void Resync()
        {
            var lastTime = m_lastResyncTime;

            m_lastResyncTime = DateTime.Now;

            Account[] accounts = null;
            try
            {
                using (m_lock.EnterWriteLock())
                {
                    //if (lastTime == default(DateTime))
                    //{
                    //    m_cachedAccsById.Clear();
                    //    m_cachedAccsByName.Clear();
                    //    accounts = Account.FindAll();
                    //}
                    //else
                    //{
                    //    accounts = Account.FindAll(Expression.Ge("LastChanged", lastTime));
                    //}
                    m_cachedAccsById.Clear();
                    m_cachedAccsByName.Clear();
                    accounts = Account.FindAll();
                }
            }
            catch (Exception e)
            {
#if DEBUG
                RealmDBMgr.OnDBError(e);
                accounts = Account.FindAll();
#else
                throw e;
#endif
            }
            finally
            {
                if (accounts != null)
                {
                    // remove accounts
                    var toRemove = new List <Account>(5);
                    foreach (var acc in m_cachedAccsById.Values)
                    {
                        if (!accounts.Contains(acc))
                        {
                            toRemove.Add(acc);
                        }
                    }
                    foreach (var acc in toRemove)
                    {
                        RemoveUnlocked(acc);
                    }

                    // update existing accounts
                    foreach (var acc in accounts)
                    {
                        Update(acc);
                    }
                }
            }

            log.Info(string.Format("{0} accaunts chached."), accounts != null ? accounts.Count() : 0);

            var evt = AccountsResync;
            if (evt != null)
            {
                evt();
            }
        }
Exemple #19
0
 private static void Init()
 {
     RealmDBMgr.Initialize();
     SpellHandler.LoadSpells();
     GOMgr.LoadAll();
 }
Exemple #20
0
 public static void InitializeDefault()
 {
     RealmDBMgr.Initialize();
     ContentMgr.InitializeAndLoad(typeof(ContentMgr).Assembly);
 }
Exemple #21
0
        /// <summary>
        /// Loads this Character from DB when logging in.
        /// </summary>
        /// <remarks>Requires IO-Context.</remarks>
        internal protected void Load()
        {
            var nativeModel = m_archetype.Race.GetModel(m_record.Gender);

            NativeDisplayId = nativeModel.DisplayId;
            var model = nativeModel;

            if (m_record.DisplayId != model.DisplayId)
            {
                model = UnitMgr.GetModelInfo(m_record.DisplayId) ?? nativeModel;
            }
            Model = model;

            // set FreeTalentPoints silently
            UpdateFreeTalentPointsSilently(0);
            if (m_record.JustCreated)
            {
                // newly created Character
                SpecProfiles = new[] { SpecProfile.NewSpecProfile(this, 0) };

                if (m_zone != null)
                {
                    SetZoneExplored(m_zone.Template, true);
                }

                //m_record.FreeTalentPoints = 0;

                // Honor and Arena
                m_record.KillsTotal             = 0u;
                m_record.HonorToday             = 0u;
                m_record.HonorYesterday         = 0u;
                m_record.LifetimeHonorableKills = 0u;
                m_record.HonorPoints            = 0u;
                m_record.ArenaPoints            = 0u;
            }
            else
            {
                // existing Character
                try
                {
                    //Set Playerfields for glyphs on load
                    InitGlyphsForLevel();
                    // load & validate SpecProfiles
                    SpecProfiles = SpecProfile.LoadAllOfCharacter(this);
                    if (SpecProfiles.Length == 0)
                    {
                        log.Warn("Character had no SpecProfiles: {0}", this);
                        SpecProfiles = new[] { SpecProfile.NewSpecProfile(this, 0) };
                    }
                    if (m_record.CurrentSpecIndex >= SpecProfiles.Length)
                    {
                        log.Warn("Character had invalid CurrentSpecIndex: {0} ({1})", this, m_record.CurrentSpecIndex);
                        m_record.CurrentSpecIndex = 0;
                    }

                    // load all the rest
                    m_achievements.Load();
                    ((PlayerSpellCollection)m_spells).LoadSpellsAndTalents();
                    ((PlayerSpellCollection)m_spells).LoadCooldowns();
                    m_skills.Load();
                    m_mailAccount.Load();
                    m_reputations.Load();
                    var auras = AuraRecord.LoadAuraRecords(EntityId.Low);
                    AddPostUpdateMessage(() => m_auras.InitializeAuras(auras));

                    if (QuestMgr.Loaded)
                    {
                        LoadQuests();
                    }

                    if (m_record.FinishedQuests != null)
                    {
                        m_questLog.FinishedQuests.AddRange(m_record.FinishedQuests);
                    }
                }
                catch (Exception e)
                {
                    RealmDBMgr.OnDBError(e);
                    throw new Exception(string.Format("Failed to load Character \"{0}\" for Client: {1}", this, Client), e);
                }

                SetExploredZones();

                //Add existing talents to the character
                ((PlayerSpellCollection)m_spells).PlayerInitialize();

                // calculate amount of spent talent points per tree
                m_talents.CalcSpentTalentPoints();

                // update RestState
                if (m_record.RestTriggerId != 0 &&
                    (m_restTrigger = AreaTriggerMgr.GetTrigger((uint)m_record.RestTriggerId)) != null)
                {
                    RestState = RestState.Resting;
                }

                if (m_record.LastLogout != null)
                {
                    var now = DateTime.Now;
                    RestXp += RestGenerator.GetRestXp(now - m_record.LastLogout.Value, this);

                    m_lastRestUpdate = now;
                }
                else
                {
                    m_lastRestUpdate = DateTime.Now;
                }

                m_taxiNodeMask.Mask = m_record.TaxiMask;

                // Honor and Arena
                KillsTotal             = m_record.KillsTotal;
                HonorToday             = m_record.HonorToday;
                HonorYesterday         = m_record.HonorYesterday;
                LifetimeHonorableKills = m_record.LifetimeHonorableKills;
                HonorPoints            = m_record.HonorPoints;
                ArenaPoints            = m_record.ArenaPoints;
            }

            // Set FreeTalentPoints, after SpecProfile was loaded
            var freePointsForLevel = m_talents.GetFreeTalentPointsForLevel(m_record.Level);

            m_talents.UpdateFreeTalentPointsSilently(freePointsForLevel);

            // Load pets (if any)
            LoadPets();

            //foreach (var skill in m_skills)
            //{
            //    if (skill.SkillLine.Category == SkillCategory.ArmorProficiency) {
            //        CharacterHandler.SendProfiency(m_client, ItemClass.Armor, (uint)skill.SkillLine.Id);
            //    }
            //}

            // this prevents a the Char from re-sending a value update when being pushed to world AFTER creation
            ResetUpdateInfo();
        }
Exemple #22
0
 private static void Init()
 {
     RealmDBMgr.Initialize();
     SpellHandler.LoadSpells();
     AreaTriggerMgr.Initialize();
 }
Exemple #23
0
        public static void WriteSpellId()
        {
            RealmDBMgr.Initialize();
            ContentMgr.Initialize();
            World.InitializeWorld();
            SpellHandler.LoadSpells();
            FactionMgr.Initialize();
            SpellHandler.Initialize2();

            var noSpell = new Spell {
                Name = "None", Effects = new SpellEffect[0]
            };

            SpellHandler.ById[0] = noSpell;
            WriteEnum("SpellId", " : uint", "Spells", SpellHandler.ById, false,
                      (spell) => { return(true); },
                      (spell) => { return(spell.FullName + spell.RankDesc); },
                      (spell) =>
            {
                TalentEntry talent = spell.Talent;

                var descs = new List <string>();

                if (spell.IsPassive)
                {
                    descs.Add("Passive");
                }

                if (talent != null)
                {
                    descs.Add("Talent");
                }
                else if (spell.Ability != null &&
                         spell.Ability.Skill != null && spell.Ability.Skill.Category != SkillCategory.Invalid)
                {
                    descs.Add(spell.Ability.Skill.Category.ToString());
                }

                if (spell.IsTeachSpell)
                {
                    descs.Add("Teachspell");
                }
                if (spell.Level > 0)
                {
                    descs.Add("Level: " + spell.Level);
                }

                string desc = string.Join(", ", descs.ToArray());

                if (!string.IsNullOrEmpty(spell.Description))
                {
                    if (desc.Length > 0)
                    {
                        desc += "\n";
                    }
                    desc += spell.Description;
                }

                return(desc);
            },
                      (spell, name) => { return(null); },
                      (spell) => { return(spell.Id.ToString()); });
        }