Esempio n. 1
0
 /// <summary>
 /// Called when the user try to login with wrong credentials (user name or password)
 /// </summary>
 private void OnWrongCredentials(CustomAuthCredentials credentials)
 {
     remaingAttempts--;
     if (remaingAttempts > 0)
     {
         if (remaingAttempts > 3)
         {
             SetLogText("The username or password you've entered are incorrect!");
         }
         else
         {
             SetLogText($"The username or password you've entered are incorrect!, attempts left: {remaingAttempts}");
         }
     }
     else
     {
         var currentTime = DateTime.Now.ToUniversalTime();
         currentTime = currentTime.AddSeconds(ULoginSettings.waitTimeAfterFailAttempts);
         var    gt      = new CultureInfo("en-US");
         string dateStr = currentTime.ToString(gt);
         string key     = bl_DataBaseUtils.Encrypt(bl_DataBaseUtils.LOCK_TIME_KEY);
         PlayerPrefs.SetString(key, bl_DataBaseUtils.Encrypt(dateStr));
         SetPlayAsGuestButtonActive(false);
         ChangePanel(9);
         remaingAttempts = ULoginSettings.maxLoginAttempts;
     }
 }
Esempio n. 2
0
    /// <summary>
    ///
    /// </summary>
    void CreateAccountWithCredentials(CustomAuthCredentials credentials)
    {
        if (string.IsNullOrEmpty(credentials.UniqueID) || string.IsNullOrEmpty(credentials.UserName))
        {
            return;
        }

        bl_ULoginLoadingWindow.Instance?.SetText($"Creating account with {credentials.authenticationType.ToString()}...", true);

        string loginName = string.IsNullOrEmpty(credentials.UserName) ? credentials.NickName : credentials.UserName;
        string password  = credentials.GetUniquePassword();
        //Used for security check for authorization to modify database
        string  hash = bl_DataBaseUtils.Md5Sum(loginName + password + bl_LoginProDataBase.Instance.SecretKey).ToLower();
        WWWForm wf   = CreateForm(false, true);

        wf.AddSecureField("name", loginName);            // adds the login name to the form
        wf.AddSecureField("nick", credentials.NickName); // adds the nick name to the form
        wf.AddSecureField("password", password);         // adds the player password to the form
        wf.AddSecureField("coins", bl_GameData.Instance.VirtualCoins.InitialCoins);
        wf.AddSecureField("multiemail", 0);
        wf.AddSecureField("emailVerification", 1);
        wf.AddSecureField("uIP", currentIP);
        wf.AddSecureField("hash", hash); // adds the security hash for Authorization

        LoadingUI.SetActive(true);
        WebRequest.POST(GetURL(bl_LoginProDataBase.URLType.Register), wf, (result) =>
        {
            if (!result.isError)
            {
                string text = result.Text;
                if (bl_LoginProDataBase.Instance.FullLogs)
                {
                    Debug.Log("Register Result: " + result.RawText);
                }
                if (result.resultState == ULoginResult.Status.Success)
                {
                    //show success
                    SetLogText("Register success!");
                    Authenticate(credentials);
                }
                else if (text == "008")
                {
                    SetLogText("This Nickname is already taken.");
                }
                else
                {
                    ErrorType(text);
                    result.Print();
                }
            }
            else
            {
                result.PrintError();
            }
            bl_ULoginLoadingWindow.Instance.SetActive(false);
            LoadingUI.SetActive(false);
        });
    }
Esempio n. 3
0
 /// <summary>
 ///
 /// </summary>
 private void OnAuthenticated(CustomAuthCredentials credentials, LoginUserInfo info)
 {
     SetPlayAsGuestButtonActive(false);
     SetLogText("Sign In success!");
     //detect if this account is banned before load next level
     if (bl_LoginProDataBase.Instance.DetectBan && Ban.CheckBanAccount(info.LoginName))
     {
         return;
     }
     //if it's OK, load next level of show continue menu
     isLogin = true;
     OnLogin?.Invoke();
     //check if session has to be remember
     if (bl_LoginProDataBase.Instance.rememberMeBehave == RememberMeBehave.RememberSession)
     {
         if (SignIn != null && SignIn.RememberMe())
         {
             string p = credentials.authenticationType == AuthenticationType.ULogin ? credentials.UniqueID : credentials.GetUniquePassword();
             //if it's so, encrypt and save the authentication credentials that the user used.
             bl_LoginProDataBase.Instance.RememberCredentials = $"{(int)credentials.authenticationType}:{credentials.UserName}:{p}";
         }
     }
     if (bl_LoginProDataBase.Instance.AutomaticallyLoadScene)//load the scene after login success (without continue menu)
     {
         Continue();
     }
     else
     {
         LoginSuccessText.text = string.Format("Welcome <b>{0}</b>", info.NickName);
         if (info.UserStatus == LoginUserInfo.Status.Admin || info.UserStatus == LoginUserInfo.Status.Moderator)
         {
             AdminPanelButon.SetActive(true);
         }
         ChangePanel(3);
     }
 }
Esempio n. 4
0
    /// <summary>
    /// Login with custom credentials
    /// You can use this to login/register a player with they ID from authenticator like Facebook, Steam, GooglePlay, etc...
    /// </summary>
    /// <param name="credentials"></param>
    public void Authenticate(CustomAuthCredentials credentials)
    {
        if (string.IsNullOrEmpty(credentials.UniqueID) || string.IsNullOrEmpty(credentials.UserName))
        {
            return;
        }

        bl_ULoginLoadingWindow.Instance?.SetText($"Authenticating with {credentials.authenticationType.ToString()}...", true);
        customAuthCredentials = credentials;
        WWWForm wf = CreateForm(false, true);

        wf.AddSecureField("name", credentials.UserName);
        wf.AddSecureField("password", credentials.GetUniquePassword());
        wf.AddSecureField("appAuth", credentials.authenticationType.ToString().ToLower());
        LoadingUI.SetActive(true);

        WebRequest.POST(GetURL(bl_LoginProDataBase.URLType.Login), wf, (result) =>
        {
            if (!result.isError)
            {
                //if the login is successful
                if (ParseLoginData(result.RawTextReadable))
                {
                    //parse the player data retrieved by the server
                    var info = BuildUserData();

#if CLANS
                    info.Clan = new bl_ClanInfo();
                    info.Clan.GetSplitInfo(loginUserData);
                    StartCoroutine(info.Clan.GetClanBasicInfo(() =>
                    {
                        OnAuthenticated(credentials, info);
                    }));
                    ClanButton.SetActive(true);
#else
                    OnAuthenticated(credentials, info);
#endif
                }
                else  //if we can't login
                {
                    result.Print(true);
                }
            }
            else
            {
                if (result.HTTPCode == 401)  //because the account is not registered yet
                {
                    if (string.IsNullOrEmpty(credentials.NickName))
                    {
                        ChangePanel(8);
                        Panels[8].GetComponent <bl_NickNamePanel>().SetCallback((nickName) =>
                        {
                            customAuthCredentials.NickName = nickName;
                            CreateAccountWithCredentials(customAuthCredentials);
                        });
                    }
                    else
                    {
                        CreateAccountWithCredentials(customAuthCredentials);
                        return;
                    }
                }
                else
                {
                    result.PrintError();
                }
            }
            bl_ULoginLoadingWindow.Instance.SetActive(false);
            LoadingUI.SetActive(false);
        });
    }
Esempio n. 5
0
    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    IEnumerator LoginProcess(string user, string pass)
    {
        isRequesting = true;
        LoadingUI.SetActive(true);
        SetLogText("");

        var formData = CreateForm(false, true);

        formData.AddSecureField("name", user);
        formData.AddSecureField("password", pass);
        formData.AddSecureField("authApp", "ulogin");

        var credential = new CustomAuthCredentials()
        {
            UserName           = user,
            UniqueID           = pass,
            authenticationType = AuthenticationType.ULogin,
        };

        using (UnityWebRequest www = UnityWebRequest.Post(bl_LoginProDataBase.Instance.GetUrl(bl_LoginProDataBase.URLType.Login), formData))
        {
            //Wait for server response...
            yield return(www.SendWebRequest());

            var response = new ULoginResult(www);
            if (bl_LoginProDataBase.Instance.FullLogs)
            {
                Debug.Log("Login Result: " + response.RawTextReadable);
            }
            //check if we have some error
            if (!response.isError)
            {
                if (ParseLoginData(response.RawTextReadable))
                {
                    //'Decompile' information from response
                    LoginUserInfo info = new LoginUserInfo();
                    info.ParseFullData(loginUserData);
                    info.IP = currentIP;
#if CLANS
                    info.Clan = new bl_ClanInfo();
                    info.Clan.GetSplitInfo(loginUserData);
                    yield return(StartCoroutine(info.Clan.GetClanBasicInfo()));

                    ClanButton.SetActive(true);
#endif
                    //send information to local database
                    DataBase.OnLogin(info);
                    LocalUserInfo = info;
                    SignIn.OnLogin(info);
                    DataBase.CacheAccessToken = pass;

                    OnAuthenticated(credential, info);
                }
                else
                {
                    //Some error with the server setup.
                    if (bl_LoginProDataBase.Instance.FullLogs)
                    {
                        Debug.Log(response.RawTextReadable);
                    }

                    if (www.responseCode == 401)//wrong credentials
                    {
                        OnWrongCredentials(credential);
                    }
                    else
                    {
                        ErrorType(response.RawTextReadable);
                    }
                }
            }
            else
            {
                if (www.responseCode == 401)//wrong credentials
                {
                    OnWrongCredentials(credential);
                }
                else
                {
                    response.PrintError();
                }
            }
        }
        bl_ULoginLoadingWindow.Instance?.SetActive(false);
        LoadingUI.SetActive(false);
        isRequesting = false;
    }