protected bool Start() { try { IsCached = AuthServerConfiguration.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(); AuthenticationServer.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) { AuthDBMgr.OnDBError(e); } return(true); }
public static void InitBanMgr() { try { m_bans = BanEntry.FindAll().ToList(); } catch (Exception e) { AuthDBMgr.OnDBError(e); m_bans = BanEntry.FindAll().ToList(); } }
/// <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, byte[] passHash, string email, string privLevel, ClientId clientId) { try { var usr = new Account( username, passHash, email) { ClientId = clientId, RoleGroupName = privLevel, Created = DateTime.Now, IsActive = true }; try { usr.CreateAndFlush(); } catch (Exception e) { #if DEBUG AuthDBMgr.OnDBError(e); usr.CreateAndFlush(); #else throw e; #endif } if (IsCached) { using (m_lock.EnterWriteLock()) { Update(usr); } } log.Info(resources.AccountCreated, username, usr.RoleGroupName); return(usr); } catch (Exception ex) { LogUtil.ErrorException(ex, resources.AccountCreationFailed, username); } return(null); }
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", id))); } catch (Exception e) { AuthDBMgr.OnDBError(e); return(Account.FindOne(Restrictions.Eq("AccountId", id))); } } }
/// <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 AuthDBMgr.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(resources.AccountsCached, accounts != null ? accounts.Count() : 0); var evt = AccountsResync; if (evt != null) { evt(); } }