Ejemplo n.º 1
0
    /// <summary>
    /// Update the given fields of the logged user in the external database
    /// </summary>
    public void UpdateUserData(ULoginUpdateFields fieldsToUpdate, Action <bool> callback = null)
    {
        if (LocalUser == null || !isLogged || isGuest)
        {
            Debug.LogWarning("To save data user have to be log-in.");
            return;
        }
        if (fieldsToUpdate == null)
        {
            return;
        }

        var wf = CreateForm(false, true);

        wf.AddSecureField("hash", bl_DataBaseUtils.CreateSecretHash(LocalUser.LoginName));
        wf.AddSecureField("name", LocalUser.LoginName);
        wf.AddSecureField("id", LocalUser.ID);
        wf.AddSecureField("typ", 0);
        wf = fieldsToUpdate.AddToWebForm(wf);

        WebRequest.POST(GetURL(bl_LoginProDataBase.URLType.DataBase), wf, (result) =>
        {
            if (result.isError)
            {
                result.PrintError();
                callback?.Invoke(false);
                return;
            }
            if (ULoginSettings.FullLogs)
            {
                result.Print();
            }

            if (result.resultState == ULoginResult.Status.Success)
            {
                Debug.LogFormat("Data update successfully for user: {0}", LocalUser.NickName);
                FireUpdateData();
            }
            else if (result.resultState == ULoginResult.Status.Fail)
            {
                Debug.Log("Update user data fail, that could be caused to the data sent were the same that the one already saved.");
            }
            callback?.Invoke(true);
        });
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Save the Kills, Deaths and Score of the local player
    /// </summary>
    public static void SaveLocalPlayerKDS(Action <bool> callback = null)
    {
        if (!bl_DataBase.IsUserLogged)
        {
            Debug.Log("Player has to be logged in order to save data");
            return;
        }

        var lp = bl_PhotonNetwork.LocalPlayer;
        var lu = bl_DataBase.Instance.LocalUser;

        lu.SendNewData(lp.GetKills(), lp.GetDeaths(), lp.GetPlayerScore());
        var fields = new ULoginUpdateFields();

        fields.AddField("kills", lu.Kills);
        fields.AddField("deaths", lu.Deaths);
        fields.AddField("score", lu.Score);

        bl_DataBase.Instance.UpdateUserData(fields, callback);
    }