Fix save/load
This commit is contained in:
@@ -50,10 +50,9 @@ public class AccountLoggedIn : MonoBehaviour
|
|||||||
loggedInLogoutButton.interactable = false;
|
loggedInLogoutButton.interactable = false;
|
||||||
loggedInBackButton.interactable = false;
|
loggedInBackButton.interactable = false;
|
||||||
WWWForm dataForm = new();
|
WWWForm dataForm = new();
|
||||||
dataForm.AddField("username", BazookaManager.Instance.GetAccountName());
|
|
||||||
dataForm.AddField("token", BazookaManager.Instance.GetAccountSession());
|
|
||||||
dataForm.AddField("saveData", Convert.ToBase64String(Encoding.UTF8.GetBytes(BazookaManager.Instance.saveFile.ToString(Formatting.None))));
|
dataForm.AddField("saveData", Convert.ToBase64String(Encoding.UTF8.GetBytes(BazookaManager.Instance.saveFile.ToString(Formatting.None))));
|
||||||
using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "berrydash/saveAccount.php", dataForm);
|
using UnityWebRequest request = UnityWebRequest.Post(Endpoints.ACCOUNT_SAVE_ENDPOINT, dataForm);
|
||||||
|
request.SetRequestHeader("Authorization", BazookaManager.Instance.GetAccountSession());
|
||||||
request.SetRequestHeader("Requester", "BerryDashClient");
|
request.SetRequestHeader("Requester", "BerryDashClient");
|
||||||
request.SetRequestHeader("ClientVersion", Application.version);
|
request.SetRequestHeader("ClientVersion", Application.version);
|
||||||
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
||||||
@@ -117,10 +116,8 @@ public class AccountLoggedIn : MonoBehaviour
|
|||||||
loggedInRefreshLoginButton.interactable = false;
|
loggedInRefreshLoginButton.interactable = false;
|
||||||
loggedInLogoutButton.interactable = false;
|
loggedInLogoutButton.interactable = false;
|
||||||
loggedInBackButton.interactable = false;
|
loggedInBackButton.interactable = false;
|
||||||
WWWForm dataForm = new();
|
using UnityWebRequest request = UnityWebRequest.Get(Endpoints.ACCOUNT_SAVE_ENDPOINT);
|
||||||
dataForm.AddField("token", BazookaManager.Instance.GetAccountSession());
|
request.SetRequestHeader("Authorization", BazookaManager.Instance.GetAccountSession());
|
||||||
dataForm.AddField("username", BazookaManager.Instance.GetAccountName());
|
|
||||||
using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "berrydash/loadAccount.php", dataForm);
|
|
||||||
request.SetRequestHeader("Requester", "BerryDashClient");
|
request.SetRequestHeader("Requester", "BerryDashClient");
|
||||||
request.SetRequestHeader("ClientVersion", Application.version);
|
request.SetRequestHeader("ClientVersion", Application.version);
|
||||||
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
||||||
@@ -137,49 +134,29 @@ public class AccountLoggedIn : MonoBehaviour
|
|||||||
Tools.UpdateStatusText(loggedInText, "Failed to make HTTP request", Color.red);
|
Tools.UpdateStatusText(loggedInText, "Failed to make HTTP request", Color.red);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
string response = request.downloadHandler.text;
|
var jsonResponse = JObject.Parse(request.downloadHandler.text);
|
||||||
if (response == "-999")
|
if ((bool)jsonResponse["success"])
|
||||||
{
|
{
|
||||||
Tools.UpdateStatusText(loggedInText, "Server error while fetching data", Color.red);
|
BazookaManager.Instance.saveFile = JObject.FromObject(jsonResponse["data"]);
|
||||||
}
|
if (!Application.isMobilePlatform)
|
||||||
else if (response == "-998")
|
|
||||||
{
|
|
||||||
Tools.UpdateStatusText(loggedInText, "Client version too outdated to access servers", Color.red);
|
|
||||||
}
|
|
||||||
else if (response == "-997")
|
|
||||||
{
|
|
||||||
Tools.UpdateStatusText(loggedInText, "Encryption/decryption issues", Color.red);
|
|
||||||
}
|
|
||||||
else if (response == "-996")
|
|
||||||
{
|
|
||||||
Tools.UpdateStatusText(loggedInText, "Can't send requests on self-built instance", Color.red);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var jsonResponse = JObject.Parse(response);
|
|
||||||
if ((bool)jsonResponse["success"])
|
|
||||||
{
|
{
|
||||||
BazookaManager.Instance.saveFile = JObject.FromObject(jsonResponse["data"]);
|
var width = Display.main.systemWidth;
|
||||||
if (!Application.isMobilePlatform)
|
var height = Display.main.systemHeight;
|
||||||
{
|
Screen.SetResolution(width, height, BazookaManager.Instance.GetSettingFullScreen());
|
||||||
var width = Display.main.systemWidth;
|
QualitySettings.vSyncCount = BazookaManager.Instance.GetSettingVsync() ? 1 : -1;
|
||||||
var height = Display.main.systemHeight;
|
|
||||||
Screen.SetResolution(width, height, BazookaManager.Instance.GetSettingFullScreen());
|
|
||||||
QualitySettings.vSyncCount = BazookaManager.Instance.GetSettingVsync() ? 1 : -1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Application.targetFrameRate = 360;
|
|
||||||
QualitySettings.vSyncCount = 0;
|
|
||||||
}
|
|
||||||
MenuMusic.Instance.GetComponent<AudioSource>().volume = BazookaManager.Instance.GetSettingMusicVolume();
|
|
||||||
foreach (CustomColorObject customColorObject in FindObjectsByType<CustomColorObject>(FindObjectsSortMode.None)) customColorObject.SetColor();
|
|
||||||
Tools.UpdateStatusText(loggedInText, "Loaded account data", Color.green);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Tools.UpdateStatusText(loggedInText, (string)jsonResponse["message"], Color.red);
|
Application.targetFrameRate = 360;
|
||||||
|
QualitySettings.vSyncCount = 0;
|
||||||
}
|
}
|
||||||
|
MenuMusic.Instance.GetComponent<AudioSource>().volume = BazookaManager.Instance.GetSettingMusicVolume();
|
||||||
|
foreach (CustomColorObject customColorObject in FindObjectsByType<CustomColorObject>(FindObjectsSortMode.None)) customColorObject.SetColor();
|
||||||
|
Tools.UpdateStatusText(loggedInText, "Loaded account data", Color.green);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Tools.UpdateStatusText(loggedInText, (string)jsonResponse["message"], Color.red);
|
||||||
}
|
}
|
||||||
loggedInChangeUsernameButton.interactable = true;
|
loggedInChangeUsernameButton.interactable = true;
|
||||||
loggedInChangePasswordButton.interactable = true;
|
loggedInChangePasswordButton.interactable = true;
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
public class Endpoints
|
public class Endpoints
|
||||||
{
|
{
|
||||||
public static readonly string BASE_URL = "https://games.lncvrt.xyz/api";
|
public static readonly string BASE_URL = "http://localhost:3342/api";
|
||||||
public static readonly string LEADERBOARDS_SCORE_ENDPOINT = BASE_URL + "/berrydash/leaderboards/score";
|
public static readonly string LEADERBOARDS_ENDPOINT = BASE_URL + "/berrydash/leaderboards";
|
||||||
public static readonly string LEADERBOARDS_BERRY_ENDPOINT = BASE_URL + "/berrydash/leaderboards/berry";
|
public static readonly string LEADERBOARDS_SCORE_ENDPOINT = LEADERBOARDS_ENDPOINT + "/score";
|
||||||
public static readonly string LEADERBOARDS_COIN_ENDPOINT = BASE_URL + "/berrydash/leaderboards/coin";
|
public static readonly string LEADERBOARDS_BERRY_ENDPOINT = LEADERBOARDS_ENDPOINT + "/berry";
|
||||||
public static readonly string LEADERBOARDS_LEGACY_ENDPOINT = BASE_URL + "/berrydash/leaderboards/legacy";
|
public static readonly string LEADERBOARDS_COIN_ENDPOINT = LEADERBOARDS_ENDPOINT + "/coin";
|
||||||
public static readonly string LEADERBOARDS_TOTAL_ENDPOINT = BASE_URL + "/berrydash/leaderboards/total";
|
public static readonly string LEADERBOARDS_LEGACY_ENDPOINT = LEADERBOARDS_ENDPOINT + "/legacy";
|
||||||
|
public static readonly string LEADERBOARDS_TOTAL_ENDPOINT = LEADERBOARDS_ENDPOINT + "/total";
|
||||||
public static readonly string PROFILE_ENDPOINT = BASE_URL + "/berrydash/profile";
|
public static readonly string PROFILE_ENDPOINT = BASE_URL + "/berrydash/profile";
|
||||||
public static readonly string PROFILE_POSTS_ENDPOINT = BASE_URL + "/berrydash/profile/posts";
|
public static readonly string PROFILE_POSTS_ENDPOINT = PROFILE_ENDPOINT + "/posts";
|
||||||
|
public static readonly string ACCOUNT_ENDPOINT = BASE_URL + "/berrydash/account";
|
||||||
|
public static readonly string ACCOUNT_SAVE_ENDPOINT = ACCOUNT_ENDPOINT + "/save";
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user