예제 #1
0
        private void LoginPlayer(Player player)
        {
            var message =
                $"Insert your password. Tries left: {player.LoginTries}/{Configuration.Instance.MaximumLogins}";
            var dialog = new InputDialog("Login", message, true, "Login", "Cancel");

            dialog.Show(player);
            dialog.Response += async(sender, ev) =>
            {
                if (ev.DialogButton == DialogButton.Left)
                {
                    if (player.LoginTries >= Configuration.Instance.MaximumLogins)
                    {
                        player.SendClientMessage(Color.OrangeRed,
                                                 "You exceed maximum login tries. You have been kicked!");
                        await Task.Delay(Configuration.Instance.KickDelay);

                        player.Kick();
                    }
                    else if (PasswordHashingService.VerifyPasswordHash(ev.InputText, player.Account.Password))
                    {
                        player.IsLoggedIn = true;

                        PlayerLogin?.Invoke(player, new PlayerLoginEventArgs {
                            Success = true
                        });
                    }
                    else
                    {
                        player.LoginTries++;
                        player.SendClientMessage(Color.Red, "Wrong password");

                        dialog.Message =
                            $"Wrong password! Retype your password! Tries left: {player.LoginTries}/{Configuration.Instance.MaximumLogins}";

                        LoginPlayer(player);
                    }
                }
                else
                {
                    player.Kick();
                }
            };
        }
 public static void OnPlayerLogin(PlayerLoginEventArgs args)
 {
     PlayerLogin?.Invoke(args);
 }