示例#1
0
    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    IEnumerator SetChangeName(string nick)
    {
        WWWForm wf = CreateForm(false, true);

        wf.AddSecureField("id", bl_DataBase.Instance.LocalUser.LoginName);
        wf.AddSecureField("data", nick);
        wf.AddSecureField("type", 4);
        wf.AddSecureField("hash", bl_DataBaseUtils.CreateSecretHash(bl_DataBase.Instance.LocalUser.LoginName));

        using (UnityWebRequest www = UnityWebRequest.Post(bl_LoginProDataBase.Instance.GetUrl(bl_LoginProDataBase.URLType.Account), wf))
        {
            yield return(www.SendWebRequest());

            if (www.error == null && !www.isNetworkError)
            {
                if (www.downloadHandler.text.Contains("success"))
                {
                    bl_DataBase.Instance.LocalUser.NickName = nick;
                    ProfileNameText.text = bl_DataBase.Instance.LocalUser.NickName;
                    NameText.text        = bl_DataBase.Instance.LocalUser.NickName;
                    Debug.Log("Changed nick name!");
                    SuccessWindow.SetActive(true);
                }
                else
                {
                    Debug.Log(www.downloadHandler.text);
                }
            }
            else
            {
                Debug.LogError(www.error);
            }
        }
    }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="wf"></param>
        public WWWForm AddToWebForm(WWWForm wf)
        {
            if (datas == null || datas.Count <= 0)
            {
                return(wf);
            }

            wf.AddSecureField("key", GetKeysAsString());
            wf.AddSecureField("values", GetValuesAsString());
            return(wf);
        }
示例#3
0
    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    IEnumerator ProcessBuy()
    {
#if ULSP && SHOP
        bussy = true;
        LoadingUI.SetActive(true);
        WWWForm wf = bl_DataBaseUtils.CreateWWWForm(MFPS.ULogin.FormHashParm.Name, true);
        wf.AddSecureField("id", bl_DataBase.Instance.LocalUser.ID);
        wf.AddSecureField("name", bl_DataBase.Instance.LocalUser.LoginName);
        wf.AddSecureField("coins", CurrentPrice);
        //temp add the purchase
        List <bl_ShopPurchase> plist = bl_DataBase.Instance.LocalUser.ShopData.ShopPurchases;
        bl_ShopPurchase        sp    = new bl_ShopPurchase();
        sp.ID     = previewData.ID;
        sp.TypeID = (int)previewData.Type;
        plist.Add(sp);
        wf.AddSecureField("line", bl_ShopData.CompilePurchases(plist));

        using (UnityWebRequest w = UnityWebRequest.Post(bl_LoginProDataBase.Instance.GetUrl(bl_LoginProDataBase.URLType.Shop), wf))
        {
            yield return(w.SendWebRequest());

            if (!w.isHttpError && !w.isNetworkError)
            {
                string result = w.downloadHandler.text;
                if (result.Contains("done"))
                {
                    bl_DataBase.Instance.LocalUser.ShopData.ShopPurchases = plist;
                    bl_DataBase.Instance.LocalUser.Coins -= CurrentPrice;
                    bl_LobbyUI.Instance.UpdateCoinsText();
                    //update all UI and Inventory
                    InstanceItems();
                    ConfirmationIcon.sprite = BuyIconImage.sprite;
                    PurchaseAnimationUI.SetActive(true);
                    Debug.Log("Purchase successfully");
                }
                else
                {
                    Debug.LogWarning(result);
                }
            }
            else
            {
                Debug.LogError(w.error);
            }
        }
        LoadingUI.SetActive(false);
        bussy = false;
#else
        yield break;
#endif
    }
示例#4
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);
        });
    }
示例#5
0
    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    IEnumerator PasswordRequest(string user, string email)
    {
        isRequesting = true;
        LoadingUI.SetActive(true);
        SetLogText("");
        //Used for security check for authorization to modify database
        lastKey = string.Format("LS-{0}", bl_DataBaseUtils.GenerateKey(8));
        // Create instance of WWWForm
        WWWForm wf = CreateForm(false, true);

        //sets the mySQL query to the amount of rows to load
        wf.AddSecureField("id", user);
        wf.AddSecureField("email", email);
        wf.AddSecureField("data", lastKey);
        wf.AddSecureField("type", 2);
        wf.AddSecureField("hash", bl_DataBaseUtils.CreateSecretHash(user));

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

            string result = www.downloadHandler.text;

            //check if we have some error
            if (www.error == null && !www.isNetworkError)
            {
                if (result.Contains("success"))
                {
                    SetLogText("An email with your reset key has been sent to your email-address");
                    ChangePanel(7);
                }
                else//Wait, have a error?, please contact me for help with the result of next debug logwarning.
                {
                    ErrorType(result);
                }
            }
            else
            {
                Debug.LogError("Error: " + www.error);
            }
            LoadingUI.SetActive(false);
        }
        isRequesting = false;
    }
示例#6
0
    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    IEnumerator ChangePasswordRequest(string pass, string newpass)
    {
        isRequesting = true;
        LoadingUI.SetActive(true);
        SetLogText("");
        //Used for security check for authorization to modify database
        // Create instance of WWWForm
        WWWForm wf = CreateForm(FormHashParm.ID, true);

        //sets the mySQL query to the amount of rows to load
        wf.AddSecureField("id", LocalUserInfo.ID);
        wf.AddSecureField("type", 1);
        wf.AddSecureField("password", pass);
        wf.AddSecureField("data", newpass);
        wf.AddSecureField("hash", bl_DataBaseUtils.CreateSecretHash(bl_DataBase.Instance.LocalUser.ID.ToString()));

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

            string result = www.downloadHandler.text;

            //check if we have some error
            if (www.error == null && !www.isNetworkError)
            {
                if (result.Contains("success"))
                {
                    SetLogText("your password has been changed successfully.");
                    ChangePanel(3);
                }
                else//Wait, have a error?, please contact me for help with the result of next debug log.
                {
                    ErrorType(result);
                }
            }
            else
            {
                Debug.LogError("Error: " + www.error);
            }
            LoadingUI.SetActive(false);
        }
        isRequesting = false;
    }
示例#7
0
        /// <summary>
        ///
        /// </summary>
        public void ResetStatsOfCurrentUser()
        {
            if (CurrentUser == null || string.IsNullOrEmpty(CurrentUser.NickName))
            {
                Debug.LogWarning("There's not user selected.");
                return;
            }

            confirmationWindow.AskConfirmation("Reset user statistics?", () =>
            {
                SetBusy(true);
                string data = "kills='0',deaths='0',score='0',playtime='0'";
                WWWForm wf  = CreateForm(false, false);
                wf.AddSecureField("name", CurrentUser.ID);
                wf.AddSecureField("type", 5);
                wf.AddSecureField("unsafe", data);
                wf.AddSecureField("hash", bl_DataBaseUtils.CreateSecretHash(CurrentUser.ID.ToString()));

                var url = GetURL(bl_LoginProDataBase.URLType.Admin);
                WebRequest.POST(url, wf, (result) =>
                {
                    if (result.isError)
                    {
                        result.PrintError();
                        return;
                    }

                    if (result.Text.Contains("done"))
                    {
                        CurrentUser.Kills    = 0;
                        CurrentUser.Deaths   = 0;
                        CurrentUser.Score    = 0;
                        CurrentUser.PlayTime = 0;
                        ShowUserInfo(CurrentUser);
                        LogText.text = "Player stats updated.";
                    }
                    else
                    {
                        result.Print(true);
                    }
                    SetBusy(false);
                });
            });
        }
示例#8
0
    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    IEnumerator ResetPasswordCall(string user, string pass)
    {
        isRequesting = true;
        LoadingUI.SetActive(true);
        SetLogText("");
        // Create instance of WWWForm
        WWWForm wf = CreateForm(false, true);

        //sets the mySQL query to the amount of rows to load
        wf.AddSecureField("id", user);
        wf.AddSecureField("password", pass);
        wf.AddSecureField("type", 3);
        wf.AddSecureField("hash", bl_DataBaseUtils.CreateSecretHash(user));

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

            string result = www.downloadHandler.text;

            //check if we have some error
            if (www.error == null)
            {
                if (result.Contains("success"))
                {
                    SetLogText("your password has been reset successfully, you can sign in now.");
                    ChangePanel(0);
                }
                else//Wait, have a error?, please contact me for help with the result of next debug logwarning.
                {
                    ErrorType(result);
                }
            }
            else
            {
                Debug.LogError("Error: " + www.error);
            }
            LoadingUI.SetActive(false);
        }
        isRequesting = false;
    }
示例#9
0
    IEnumerator SetChangePass(string pass, string newpass)
    {
        // Create instance of WWWForm
        WWWForm wf = CreateForm(FormHashParm.ID, true);

        //sets the mySQL query to the amount of rows to load
        wf.AddSecureField("id", bl_DataBase.Instance.LocalUser.ID);
        wf.AddSecureField("type", 1);
        wf.AddSecureField("password", pass);
        wf.AddSecureField("data", newpass);

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

            string result = www.downloadHandler.text;

            //check if we have some error
            if (www.error == null && !www.isNetworkError)
            {
                if (result.Contains("success"))
                {
                    Debug.Log("Change password!");
                    bl_DataBase.Instance.CacheAccessToken = newpass;
                    SuccessWindow.SetActive(true);
                }
                else//Wait, have a error?, please contact me for help with the result of next debug log.
                {
                    // ErrorType(result);
                }
            }
            else
            {
                Debug.LogError("Error: " + www.error);
                SetLog(www.error);
            }
        }
    }
示例#10
0
    public static WWWForm CreateWWWForm(FormHashParm hashParamenter = FormHashParm.ID, bool addSID = false)
    {
        WWWForm wf = new WWWForm();

        if (hashParamenter != FormHashParm.None)
        {
            string parm = "0";
            if (bl_DataBase.Instance != null && bl_DataBase.Instance.LocalUser != null)
            {
                parm = hashParamenter == FormHashParm.ID ? bl_DataBase.Instance.LocalUser.ID.ToString() : bl_DataBase.Instance.LocalUser.LoginName;
            }
            if (hashParamenter == FormHashParm.Name)
            {
                wf.AddSecureField("name", parm);
            }
            string hash = Md5Sum(parm + bl_LoginProDataBase.Instance.SecretKey).ToLower();
            wf.AddSecureField("hash", hash);
        }
        if (addSID && bl_DataBase.Instance != null)
        {
            wf.AddField("sid", AnalyticsSessionInfo.sessionId.ToString());
        }
        return(wf);
    }
示例#11
0
    /// <summary>
    /// Connect with database
    /// </summary>
    /// <returns></returns>
    IEnumerator RegisterProcess(string user, string nick, string pass, string email)
    {
        isRequesting = true;
        SetLogText("");
        //Used for security check for authorization to modify database
        string hash = bl_DataBaseUtils.Md5Sum(user + pass + bl_LoginProDataBase.Instance.SecretKey).ToLower();

        LoadingUI.SetActive(true);
        //Assigns the data we want to save
        //Where -> Form.AddField("name" = matching name of value in SQL database
        WWWForm mForm = CreateForm(false, true);

        mForm.AddSecureField("name", user);     // adds the login name to the form
        mForm.AddSecureField("nick", nick);     // adds the nick name to the form
        mForm.AddSecureField("password", pass); // adds the player password to the form
        mForm.AddSecureField("coins", bl_GameData.Instance.VirtualCoins.InitialCoins);
        if (bl_LoginProDataBase.Instance.RequiredEmailVerification && !string.IsNullOrEmpty(email))
        {
            mForm.AddSecureField("email", email);
        }
        else
        {
            mForm.AddSecureField("email", "none");
        }
        mForm.AddSecureField("multiemail", bl_LoginProDataBase.Instance.CanRegisterSameEmailInt());
        mForm.AddSecureField("emailVerification", bl_LoginProDataBase.Instance.RequiereVerification());
        mForm.AddSecureField("uIP", currentIP);
        mForm.AddSecureField("hash", hash); // adds the security hash for Authorization

        //Creates instance of WWW to runs the PHP script to save data to mySQL database
        using (UnityWebRequest www = UnityWebRequest.Post(GetURL(bl_LoginProDataBase.URLType.Register), mForm))
        {
            yield return(www.SendWebRequest());

            if (www.error == null)
            {
                string result = www.downloadHandler.text;
                if (bl_LoginProDataBase.Instance.FullLogs)
                {
                    Debug.Log("Register Result: " + result);
                }
                if (result.Contains("success") == true)
                {
                    //show success
                    ChangePanel(4);
                    SetLogText("Register success!");
                }
                else
                {
                    //Debug.Log(www.downloadHandler.text);
                    ErrorType(www.downloadHandler.text);
                }
            }
            else
            {
                Debug.Log("Error:" + www.error);
            }
            LoadingUI.SetActive(false);
        }
        isRequesting = false;
    }
示例#12
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);
        });
    }
示例#13
0
        /// <summary>
        ///
        /// </summary>
        public void Search()
        {
            string user = SearchInput.text;

            if (string.IsNullOrEmpty(user))
            {
                return;
            }
            if (isRequesting)
            {
                return;
            }

            SetBusy(true);
            WWWForm wf = CreateForm(false, true);

            wf.AddSecureField("name", user);
            wf.AddSecureField("type", 4);
            wf.AddSecureField("hash", bl_DataBaseUtils.CreateSecretHash(user));

            var url = GetURL(bl_LoginProDataBase.URLType.Admin);

            WebRequest.POST(url, wf, (result) =>
            {
                if (result.isError)
                {
                    result.PrintError();
                    return;
                }

                string raw     = result.RawText;
                string[] split = raw.Split("|"[0]);
                if (split[0].Contains("success"))
                {
                    LoginUserInfo info = new LoginUserInfo();
                    info.LoginName     = split[1];
                    info.Kills         = split[2].ToInt();
                    info.Deaths        = split[3].ToInt();
                    info.Score         = split[4].ToInt();
                    info.IP            = split[5];
                    info.UserStatus    = (LoginUserInfo.Status)split[6].ToInt();
                    info.PlayTime      = split[7].ToInt();
                    info.NickName      = split[8];
                    info.ID            = split[9].ToInt();
                    ShowUserInfo(info);
                    CurrentUser  = info;
                    LogText.text = "information obtained.";
                    foreach (GameObject g in BanUI)
                    {
                        g.SetActive(true);
                    }
                    if (info.UserStatus == LoginUserInfo.Status.Banned)
                    {
                        BanUI[0].SetActive(false);
                        BanUI[1].SetActive(false);
                    }
                    else
                    {
                        BanUI[2].SetActive(false);
                    }
                    if (info.UserStatus != LoginUserInfo.Status.Banned)
                    {
                        foreach (Button g in StatusButtons)
                        {
                            g.gameObject.SetActive(true); g.interactable = true;
                        }
                        StatusButtons[(int)info.UserStatus].interactable = false;
                    }
                    else
                    {
                        foreach (Button g in StatusButtons)
                        {
                            g.gameObject.SetActive(false);
                        }
                    }
                }
                else
                {
                    Debug.Log(raw);
                    LogText.text = raw;
                }
                SetBusy(false);
            });
        }