Exemple #1
0
        public static void EventSink_AccountLogin(AccountLoginEventArgs e)
        {
            e.Accepted = false;

            if (e.Username == "" || e.Password == "")
            {
                e.RejectReason = ALRReason.BadPass;
                return;
            }

            SunAccount account;

            try {
                account = accountDB.GetAccount(e.Username);
            } catch (Exception ex) {
                log.Error("AccountDB.GetAccount failed", ex);
                e.RejectReason = ALRReason.Blocked;
                return;
            }

            if (account == null)
            {
                if (Core.Config.Login.AutoCreateAccounts)
                {
                    try {
                        log.Info(String.Format("Login: {0}: Creating account '{1}'", e.State, e.Username));
                        e.State.Account = accountDB.CreateAccount(e.State, e.Username, e.Password);
                        e.Accepted      = true;
                    } catch (Exception ex) {
                        log.Error("AccountDB.CreateAccount failed", ex);
                        e.RejectReason = ALRReason.Blocked;
                        return;
                    }
                }
                else
                {
                    log.Warn(String.Format("Login: {0}: Invalid username '{1}'", e.State, e.Username));
                    e.RejectReason = ALRReason.Invalid;
                }
            }
            else if (!account.CheckPassword(e.Password))
            {
                log.Warn(String.Format("Login: {0}: Invalid password for '{1}'", e.State, e.Username));
                e.RejectReason = ALRReason.BadPass;
            }
            else if (account.Banned)
            {
                log.Warn(String.Format("Login: {0}: Banned account '{1}'", e.State, e.Username));
                e.RejectReason = ALRReason.Blocked;
            }
            else
            {
                log.Info(String.Format("Login: {0}: Valid credentials for '{1}'", e.State, e.Username));
                e.State.Account = account;
                e.Accepted      = true;
            }
        }
        public static void EventSink_AccountLogin(AccountLoginEventArgs e)
        {
            e.Accepted = false;
            SunAccount account;

            try {
                account = accountDB.GetAccount(e.Username);
            } catch (Exception ex) {
                Console.WriteLine("AccountDB.GetAccount failed: {0}", ex);
                e.RejectReason = ALRReason.Blocked;
                return;
            }

            if (account == null)
            {
                if (Core.Config.LoginConfig.AutoCreateAccounts)
                {
                    try {
                        e.State.Account = accountDB.CreateAccount(e.State, e.Username, e.Password);
                        e.Accepted      = true;
                    } catch (Exception ex) {
                        Console.WriteLine("AccountDB.CreateAccount failed: {0}", ex);
                        e.RejectReason = ALRReason.Blocked;
                        return;
                    }
                }
                else
                {
                    Console.WriteLine("Login: {0}: Invalid username '{1}'", e.State, e.Username);
                    e.RejectReason = ALRReason.Invalid;
                }
            }
            else if (!account.CheckPassword(e.Password))
            {
                Console.WriteLine("Login: {0}: Invalid password for '{1}'", e.State, e.Username);
                e.RejectReason = ALRReason.BadPass;
            }
            else if (account.Banned)
            {
                Console.WriteLine("Login: {0}: Banned account '{1}'", e.State, e.Username);
                e.RejectReason = ALRReason.Blocked;
            }
            else
            {
                Console.WriteLine("Login: {0}: Valid credentials for '{1}'", e.State, e.Username);
                e.State.Account = account;
                e.Accepted      = true;
            }
        }