예제 #1
0
        public RegisterStatus Register(string login, string password, string email, int captcha)
        {
            var name = login;

            if (captcha != _random) //«’б«Ќ г‘яб… «б ”ћнб
            {
                return(RegisterStatus.WrongCaptcha);
            }
            var acc = AccountMgr.GetAccount(login);

            if (acc != null || !AccountMgr.NameValidator(ref name) || login == null || login.Length > 16)
            {
                return(RegisterStatus.DuplicateLogin);
            }
            if (string.IsNullOrWhiteSpace(password) || password.Length > 20)
            {
                return(RegisterStatus.BadPassword);
            }
            if (string.IsNullOrWhiteSpace(email))
            {
                return(RegisterStatus.BadPassword);
            }
            acc = AccountMgr.Instance.CreateAccount(name, password, email, RealmServerConfiguration.DefaultRole);
            acc.Save();
            return(RegisterStatus.Ok);
        }
예제 #2
0
        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);
                    }
                }
            }
        }
예제 #3
0
        public RegisterStatus Register(string login, string password, string email, int captcha)
        {
            string name = login;

            if (captcha != this._random)
            {
                return(RegisterStatus.WrongCaptcha);
            }
            if (AccountMgr.GetAccount(login) != null || !AccountMgr.NameValidator(ref name) ||
                (login == null || login.Length > 16))
            {
                return(RegisterStatus.DuplicateLogin);
            }
            if (string.IsNullOrWhiteSpace(password) || password.Length > 20 || string.IsNullOrWhiteSpace(email))
            {
                return(RegisterStatus.BadPassword);
            }
            AccountMgr.Instance.CreateAccount(name, password, email, RealmServerConfiguration.DefaultRole).Save();
            return(RegisterStatus.Ok);
        }
예제 #4
0
            public override void Process(CmdTrigger <AuthServerCmdArgs> trigger)
            {
                var name = trigger.Text.NextWord();

                //Resync accounts first
                AccountMgr.Instance.Resync();

                if (AccountMgr.DoesAccountExist(name))
                {
                    trigger.Reply("The account \"{0}\" already exists!", name);
                }
                else
                {
                    if (!AccountMgr.NameValidator(ref name))
                    {
                        trigger.Reply("Invalid Account-Name: " + name);
                        return;
                    }

                    var pw = trigger.Text.NextWord();

                    if (pw.Length == 0)
                    {
                        trigger.Reply("Password required.");
                    }
                    else
                    {
                        var      role  = trigger.Text.NextWord();
                        var      email = trigger.Text.NextWord();
                        ClientId clientId;
                        if (trigger.Text.HasNext)
                        {
                            clientId = trigger.Text.NextEnum((ClientId)int.MaxValue);
                            if (clientId == (ClientId)int.MaxValue)
                            {
                                trigger.Reply("Invalid ClientId specified - Choose either of: " +
                                              Enum.GetValues(typeof(ClientId)).OfType <object>().ToString(", "));
                            }
                        }
                        else
                        {
                            clientId = ClientId.Wotlk;
                        }

                        role = PrivilegeMgr.Instance.GetRoleOrDefault(role);

                        var acc = AccountMgr.Instance.CreateAccount(name, pw, email, role, clientId);

                        if (acc != null)
                        {
                            trigger.Reply("Account \"{0}\" created (Role: {1}, Email: {2}, ClientId: {3})",
                                          name,
                                          acc.RoleGroupName,
                                          acc.EmailAddress,
                                          clientId);
                        }
                        else
                        {
                            // cannot really happen
                            trigger.Reply("Failed to create Account \"{0}\"!", name);
                        }
                    }
                }
            }
예제 #5
0
        private static void QueryAccountCallback(IRealmClient client, Account acct)
        {
            if (client == null || !client.IsConnected)
            {
                return;
            }
            if (acct != null)
            {
                Character characterByAccId = World.GetCharacterByAccId((uint)acct.AccountId);
                if (characterByAccId != null)
                {
                    characterByAccId.Logout(true, 0);
                    AuthenticationHandler.OnLoginError(client,
                                                       AccountStatus.WrongLoginOrPass | AccountStatus.AccountInUse);
                    return;
                }
            }

            string       accountName     = client.AccountName;
            RealmAccount loggedInAccount =
                ServerApp <WCell.RealmServer.RealmServer> .Instance.GetLoggedInAccount(accountName);

            if (acct != null && acct.IsLogedOn)
            {
                Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)acct.AccountId)
                .AddAttribute("operation", 1.0, "account_in_use").AddAttribute("name", 0.0, acct.Name)
                .AddAttribute("ip", 0.0, client.ClientAddress.ToString()).Write();
                AuthenticationHandler.OnLoginError(client, AccountStatus.AccountInUse);
            }
            else if (loggedInAccount != null && loggedInAccount.ActiveCharacter != null &&
                     (loggedInAccount.Client != null && loggedInAccount.Client.IsConnected))
            {
                Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)acct.AccountId)
                .AddAttribute("operation", 1.0, "account_in_use").AddAttribute("name", 0.0, acct.Name)
                .AddAttribute("ip", 0.0, client.ClientAddress.ToString()).Write();
                AuthenticationHandler.OnLoginError(client, AccountStatus.AccountInUse);
            }
            else
            {
                if (acct == null)
                {
                    if (RealmServerConfiguration.AutocreateAccounts)
                    {
                        if (!AccountMgr.NameValidator(ref accountName) || client.Password == null ||
                            client.Password.Length > 20)
                        {
                            AuthenticationHandler.OnLoginError(client, AccountStatus.WrongLoginOrPass);
                            return;
                        }

                        client.AuthAccount = AccountMgr.Instance.CreateAccount(accountName, client.Password, "",
                                                                               RealmServerConfiguration.DefaultRole);
                        client.AuthAccount.Save();
                        AuthenticationHandler.SendAuthChallengeSuccessReply(client);
                        client.AuthAccount.IsLogedOn = true;
                    }
                    else
                    {
                        AuthenticationHandler.OnLoginError(client, AccountStatus.WrongLoginOrPass);
                        return;
                    }
                }
                else if (acct.CheckActive())
                {
                    client.AuthAccount = acct;
                    if (loggedInAccount == null)
                    {
                        AuthenticationHandler.SendAuthChallengeSuccessReply(client);
                    }
                }
                else
                {
                    Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)acct.AccountId)
                    .AddAttribute("operation", 1.0, "login_banned").AddAttribute("name", 0.0, acct.Name)
                    .AddAttribute("ip", 0.0, client.ClientAddress.ToString()).Write();
                    if (client.AuthAccount == null || !client.AuthAccount.StatusUntil.HasValue)
                    {
                        AuthenticationHandler.OnLoginError(client, AccountStatus.WrongLoginOrPass);
                        return;
                    }

                    AuthenticationHandler.OnLoginError(client, AccountStatus.WrongLoginOrPass);
                    return;
                }

                if (loggedInAccount == null)
                {
                    if (acct != null)
                    {
                        Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)acct.AccountId)
                        .AddAttribute("operation", 1.0, "login_ok").AddAttribute("name", 0.0, acct.Name)
                        .AddAttribute("ip", 0.0, client.ClientAddress.ToString()).Write();
                    }
                    RealmAccount.InitializeAccount(client, client.AuthAccount.Name);
                }
                else
                {
                    if (acct == null)
                    {
                        return;
                    }
                    if (loggedInAccount.Client != null)
                    {
                        if (loggedInAccount.Client.ActiveCharacter != null)
                        {
                            loggedInAccount.Client.ActiveCharacter.SendInfoMsg(
                                "Some one loggin in to your account. Disconnecting.");
                        }
                        loggedInAccount.Client.Disconnect(false);
                    }

                    if (client.ClientAddress == null)
                    {
                        return;
                    }
                    loggedInAccount.LastIP = client.ClientAddress.GetAddressBytes();
                    acct.LastIP            = client.ClientAddress.GetAddressBytes();
                    acct.Save();
                    client.Account = loggedInAccount;
                    if (loggedInAccount.ActiveCharacter != null)
                    {
                        AuthenticationHandler.ConnectClientToIngameCharacter(client, acct, loggedInAccount);
                    }
                    else
                    {
                        Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)acct.AccountId)
                        .AddAttribute("operation", 1.0, "character_select_menu")
                        .AddAttribute("name", 0.0, acct.Name)
                        .AddAttribute("ip", 0.0, client.ClientAddress.ToString()).Write();
                        AuthenticationHandler.SendAuthChallengeSuccessReply(client);
                    }
                }
            }
        }