Exemplo n.º 1
0
        public void OnLoginAttempt(MyPlayer player, string username, string password)
        {
            if (player.IsLoggedIn || username.Length < 4 || password.Length < 4)
            {
                return;
            }

            //Vorname_Nachname
            Regex regex = new Regex(@"([a-zA-Z]+)_([a-zA-Z]+)");

            if (!regex.IsMatch(username))
            {
                player.Emit("alttutorial:loginError", 1, "Der Name muss dem Format: Vorname_Nachname entsprechen.");
                return;
            }

            if (!PlayerDatabase.DoesPlayerNameExists(username))
            {
                player.Emit("alttutorial:loginError", 1, "Der Name ist nicht vergeben!");
                return;
            }

            if (PlayerDatabase.CheckLoginDetails(username, password))
            {
                //Passwort ist korrekt
                player.LoadPlayer(username);
                player.Spawn(new Position(0, 0, 72), 0);
                player.Emit("alttutorial:loginSuccess");
                player.SendNotification("Erfolgreich eingeloggt!");
                if (player.HasData("alttutorial:loginattempts"))
                {
                    player.DeleteData("alttutorial:loginattempts");
                }
            }
            else
            {
                //Passwort ist nicht korrekt
                player.Emit("alttutorial:loginError", 1, "Login Daten stimmen nicht überein!");

                int attempts = 1;
                if (player.HasData("alttutorial:loginattempts"))
                {
                    player.GetData("alttutorial:loginattempts", out attempts);

                    if (attempts == 2)
                    {
                        player.Kick("Zu viele Loginversuche.");
                    }
                    else
                    {
                        attempts++;
                    }
                }
                player.SetData("alttutorial:loginattempts", attempts);
            }
        }