/// <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 { AuthDBMgr.DatabaseProvider.Save(usr); } catch (Exception e) { #if DEBUG AuthDBMgr.OnDBError(e); AuthDBMgr.DatabaseProvider.Save(usr); #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; }
private static void QueryAccountCallback(IAuthClient client, Account acct) { if (!client.IsConnected) { return; } var accName = client.AccountName; if (acct == null) { // Account doesn't exist yet -> Check for auto creation if (AuthServerConfiguration.AutocreateAccounts) { if (!AccountMgr.NameValidator(ref accName)) { OnLoginError(client, AccountStatus.InvalidInformation); return; } // Fill in this client's info with the username they gave. // We have to go through the authentication phase, and if // the password ends up matching the username, we know it's // an autocreation attempt. var passHash = SecureRemotePassword.GenerateCredentialsHash(accName, accName); client.Authenticator = new Authenticator(new SecureRemotePassword(accName, passHash, true)); SendAuthChallengeSuccessReply(client); } else { OnLoginError(client, AccountStatus.InvalidInformation); } } else { // check if Account may be used if (acct.CheckActive()) { client.Account = acct; client.Authenticator = new Authenticator(new SecureRemotePassword(accName, acct.Password, true)); SendAuthChallengeSuccessReply(client); } else { // Account has been deactivated if (client.Account.StatusUntil == null) { // temporarily suspended OnLoginError(client, AccountStatus.AccountBanned); } else { // deactivated OnLoginError(client, AccountStatus.AccountFrozen); } } } }
private void Update(Account acc) { Account oldAcc; if (!m_cachedAccsById.TryGetValue(acc.AccountId, out oldAcc)) { m_cachedAccsById[acc.AccountId] = acc; m_cachedAccsByName[acc.Name] = acc; } else { oldAcc.Update(acc); } }
private void RemoveUnlocked(Account acc) { m_cachedAccsById.Remove(acc.AccountId); m_cachedAccsByName.Remove(acc.Name); }
internal void Remove(Account acc) { using (m_lock.EnterWriteLock()) { RemoveUnlocked(acc); } }
public FullAccountInfo GetFullAccountInfo(Account acc) { var info = new FullAccountInfo { Name = acc.Name, IsActive = acc.IsActive, StatusUntil = acc.StatusUntil, AccountId = acc.AccountId, EmailAddress = acc.EmailAddress, ClientId = acc.ClientId, RoleGroupName = acc.RoleGroupName, LastIP = acc.LastIP, LastLogin = acc.LastLogin, Locale = acc.Locale }; return info; }
public AuthServerCmdArgs(Account acc) { Account = acc; }