Exemple #1
0
        /// <summary>
        /// Handles the login attempt of an account.
        /// </summary>
        /// <param name="conn">Connection that the login request was made on.</param>
        /// <param name="name">Name of the account.</param>
        /// <param name="password">Entered password for this account.</param>
        public void LoginAccount(IIPSocket conn, string name, string password)
        {
            if (!RequireServerRunning())
            {
                return;
            }

            ThreadAsserts.IsMainThread();

            if (conn == null)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("conn is null.");
                }
                return;
            }

            // Try to log in the account
            IUserAccount userAccount;
            var          loginResult = UserAccountManager.Login(conn, name, password, out userAccount);

            // Check that the login was successful
            if (loginResult != AccountLoginResult.Successful)
            {
                HandleFailedLogin(conn, loginResult, name);
                return;
            }

            // Check if banned
            int    banMins;
            string banReason;

            if (BanningManager.Instance.IsBanned(userAccount.ID, out banReason, out banMins))
            {
                userAccount.Dispose(GameMessage.AccountBanned, banMins, banReason);
                if (log.IsInfoEnabled)
                {
                    log.InfoFormat("Disconnected account `{0}` after successful login since they have been banned.", name);
                }
                return;
            }

            // Set the connection's tag to the account
            conn.Tag = userAccount;

            // Send the "Login Successful" message
            using (var pw = ServerPacket.LoginSuccessful())
            {
                conn.Send(pw, ServerMessageType.System);
            }

            if (log.IsInfoEnabled)
            {
                log.InfoFormat("Login for account `{0}` successful.", name);
            }

            // Send the account characters
            userAccount.SendAccountCharacterInfos();
        }