Beispiel #1
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;
    }
    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    IEnumerator LoginProcess(string user, string pass)
    {
        isRequesting = true;
        LoadingUI.SetActive(true);
        SetLogText("");

        //sets the mySQL query to the amount of rows to load
        Dictionary <string, string> formData = new Dictionary <string, string>();

        formData.Add("name", user);
        formData.Add("password", pass);

        //Creates instance to run the php script to access the mySQL database
        using (UnityWebRequest www = UnityWebRequest.Post(bl_LoginProDataBase.Instance.GetUrl(bl_LoginProDataBase.URLType.Login), formData))
        {
            //Wait for server response...
            yield return(www.SendWebRequest());

            string result = www.downloadHandler.text;

            //check if we have some error
            if (www.isNetworkError == false && !www.isHttpError)
            {
                //decompile information
                string[] data = result.Split("|"[0]);

                if (data[0].Contains("success"))
                {
                    //'Decompile' information from response
                    LoginUserInfo info = new LoginUserInfo();
                    info.LoginName = data[1];
                    info.NickName  = data[2];
                    info.Kills     = int.Parse(data[3]);
                    info.Deaths    = int.Parse(data[4]);
                    info.Score     = int.Parse(data[5]);
                    info.PlayTime  = int.Parse(data[6]);
                    int st = int.Parse(data[7]);
                    info.UserStatus = (LoginUserInfo.Status)st;
                    info.ID         = int.Parse(data[8]);//unique identifier of the player in database
                    info.SetFriends(data[9]);
                    info.Coins   = int.Parse(data[10]);
                    info.SavedIP = data[11];
#if CLANS
                    info.Clan = new bl_ClanInfo();
                    info.Clan.GetSplitInfo(data);
                    yield return(StartCoroutine(info.Clan.GetClanBasicInfo()));

                    ClanButton.SetActive(true);
#endif
#if SHOP
                    info.ShopData = new bl_ShopUserData();
                    info.ShopData.GetInfo(data);
#endif
                    info.IP = currentIP;
                    //send information to local database
                    DataBase.OnLogin(info);
                    DataBase.CacheAccessToken = pass;
                    LocalUserInfo             = info;
                    SignIn.OnLogin(info);
                    SetLogText("Sign In success!");
                    //detect if this account is banned before load next level
                    if (bl_LoginProDataBase.Instance.DetectBan && Ban.CheckBanAccount(info.LoginName))
                    {
                        yield break;//just stop here due this account is banned
                    }
                    //if it's OK, load next level of show continue menu
                    isLogin = true;
                    if (OnLogin != null)
                    {
                        OnLogin.Invoke();
                    }
                    yield return(new WaitForSeconds(1f));

                    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);
                    }
                }
                else//Wait, have a error?, please contact me for help with the result of next debug log.
                {
                    //Some error with the server setup.
                    Debug.Log(result);
                    ErrorType(result);
                }
            }
            else
            {
                Debug.LogError("Error: " + www.error);
            }
        }
        LoadingUI.SetActive(false);
        isRequesting = false;
    }