예제 #1
0
        protected bool Start()
        {
            try
            {
                IsCached = RealmServerConfiguration.CacheAccounts;
                //I would have liked this to be a readonly field but it must be
                //initialised here otherwise in the ctor AccountReloadIntervalMs
                //wont have been init'd which would mean we cant customise the timer easily

                /*_accountsReloadTimer = new TimerEntry(0, AccountReloadIntervalMs, delay =>
                 * {
                 *      if (Instance.IsCached)
                 *              Instance.Resync();
                 * });*/
                //_accountsReloadTimer.Start();
                //RealmServer.IOQueue.RegisterUpdatable(_accountsReloadTimer);

                if (Count == 0)
                {
                    log.Info("Detected empty Account-database.");
                    //if (!DoesAccountExist("Administrator"))
                    //{
                    //    CreateAccount("Administrator", DefaultAdminPW, null, RoleGroupInfo.HighestRole.Name, ClientId.Wotlk);
                    //    log.Warn("Created new Account \"Administrator\" with same password.");
                    //}
                }
            }
            catch (Exception e)
            {
                RealmDBMgr.OnDBError(e);
            }
            return(true);
        }
예제 #2
0
        public static void LoadFromDB()
        {
            ArenaTeam[] teams;
#if DEBUG
            try
            {
#endif
            teams = WCellRecord <ArenaTeam> .FindAll();

#if DEBUG
        }
        catch (Exception e)
        {
            RealmDBMgr.OnDBError(e);
            teams = WCellRecord <ArenaTeam> .FindAll();
        }
#endif
            if (teams != null)
            {
                foreach (var team in teams)
                {
                    team.InitAfterLoad();
                }
            }
        }
예제 #3
0
        protected bool Start()
        {
            _auctionedItems = new SynchronizedDictionary <uint, ItemRecord>(10000);

            if (AllowInterFactionAuctions)
            {
                NeutralAuctions  = new AuctionHouse();
                AllianceAuctions = NeutralAuctions;
                HordeAuctions    = NeutralAuctions;
            }
            else
            {
                AllianceAuctions = new AuctionHouse();
                HordeAuctions    = new AuctionHouse();
                NeutralAuctions  = new AuctionHouse();
            }

#if DEBUG
            try
            {
#endif
            FetchAuctions();
#if DEBUG
        }
        catch (Exception e)
        {
            RealmDBMgr.OnDBError(e);
            FetchAuctions();
        }
#endif
            return(true);
        }
예제 #4
0
        private bool Start()
        {
            Guild[] guilds = null;

#if DEBUG
            try
            {
#endif
            guilds = ActiveRecordBase <Guild> .FindAll();

#if DEBUG
        }
        catch (Exception e)
        {
            RealmDBMgr.OnDBError(e);
            guilds = ActiveRecordBase <Guild> .FindAll();
        }
#endif

            if (guilds != null)
            {
                foreach (var guild in guilds)
                {
                    guild.InitAfterLoad();
                }
            }

            return(true);
        }
예제 #5
0
 public Account this[long id]
 {
     get
     {
         if (this.IsCached)
         {
             using (this.m_lock.EnterReadLock())
             {
                 Account account;
                 this.m_cachedAccsById.TryGetValue(id, out account);
                 return(account);
             }
         }
         else
         {
             try
             {
                 return(ActiveRecordBase <Account> .FindOne(new ICriterion[1]
                 {
                     (ICriterion)Restrictions.Eq("AccountId", (object)(int)id)
                 }));
             }
             catch (Exception ex)
             {
                 RealmDBMgr.OnDBError(ex);
                 return(ActiveRecordBase <Account> .FindOne(new ICriterion[1]
                 {
                     (ICriterion)Restrictions.Eq("AccountId", (object)(int)id)
                 }));
             }
         }
     }
 }
예제 #6
0
 public static void InitBanMgr()
 {
     try
     {
         m_bans = BanEntry.FindAll().ToList();
     }
     catch (Exception e)
     {
         RealmDBMgr.OnDBError(e);
         m_bans = BanEntry.FindAll().ToList();
     }
 }
예제 #7
0
 public static PermanentPetRecord[] LoadPermanentPetRecords(uint ownerId)
 {
     try
     {
         return(FindAllByProperty("_OwnerLowId", (int)ownerId));
     }
     catch (Exception e)
     {
         RealmDBMgr.OnDBError(e);
         return(FindAllByProperty("_OwnerLowId", (int)ownerId));
     }
 }
예제 #8
0
 [Initialization(InitializationPass.Sixth)]              // init after NHIdGenerator init'ed (Fifth)
 public static void Initialize()
 {
     try
     {
         CreateIdGenerators();
     }
     catch (Exception e)
     {
         RealmDBMgr.OnDBError(e);
         CreateIdGenerators();
     }
 }
예제 #9
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>();
     }
 }
예제 #10
0
 public static void Initialize()
 {
     try
     {
         MailMgr.CreateIdGenerators();
     }
     catch (Exception ex)
     {
         RealmDBMgr.OnDBError(ex);
         MailMgr.CreateIdGenerators();
     }
 }
예제 #11
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));
     }
 }
예제 #12
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);
        }
예제 #13
0
 public static void Initialize()
 {
     InstanceInfos.Sort();
     InstanceConfig.LoadSettings();
     try
     {
         GlobalResetTimers = GlobalInstanceTimer.LoadTimers();
     }
     catch (Exception ex)
     {
         RealmDBMgr.OnDBError(ex);
         GlobalResetTimers = GlobalInstanceTimer.LoadTimers();
     }
 }
예제 #14
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);
        }
예제 #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[] 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);
                    }
                }
            }
        }
예제 #16
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();
            }
        }
예제 #17
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;
         }
     }
 }
예제 #18
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();
            }
        }
예제 #19
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);
                }
            }
        }
예제 #20
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)));
         }
     }
 }
예제 #21
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;
     }
 }
예제 #22
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();
            }
        }
예제 #23
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();
        }