diff --git a/Assets/Scripts/AccountMenu/AccountLoggedIn.cs b/Assets/Scripts/AccountMenu/AccountLoggedIn.cs index 8fc13fb..70f57a7 100644 --- a/Assets/Scripts/AccountMenu/AccountLoggedIn.cs +++ b/Assets/Scripts/AccountMenu/AccountLoggedIn.cs @@ -50,10 +50,9 @@ public class AccountLoggedIn : MonoBehaviour loggedInLogoutButton.interactable = false; loggedInBackButton.interactable = false; 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)))); - 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("ClientVersion", Application.version); request.SetRequestHeader("ClientPlatform", Application.platform.ToString()); @@ -117,10 +116,8 @@ public class AccountLoggedIn : MonoBehaviour loggedInRefreshLoginButton.interactable = false; loggedInLogoutButton.interactable = false; loggedInBackButton.interactable = false; - WWWForm dataForm = new(); - dataForm.AddField("token", BazookaManager.Instance.GetAccountSession()); - dataForm.AddField("username", BazookaManager.Instance.GetAccountName()); - using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "berrydash/loadAccount.php", dataForm); + using UnityWebRequest request = UnityWebRequest.Get(Endpoints.ACCOUNT_SAVE_ENDPOINT); + request.SetRequestHeader("Authorization", BazookaManager.Instance.GetAccountSession()); request.SetRequestHeader("Requester", "BerryDashClient"); request.SetRequestHeader("ClientVersion", Application.version); request.SetRequestHeader("ClientPlatform", Application.platform.ToString()); @@ -137,49 +134,29 @@ public class AccountLoggedIn : MonoBehaviour Tools.UpdateStatusText(loggedInText, "Failed to make HTTP request", Color.red); return; } - string response = request.downloadHandler.text; - if (response == "-999") + var jsonResponse = JObject.Parse(request.downloadHandler.text); + if ((bool)jsonResponse["success"]) { - Tools.UpdateStatusText(loggedInText, "Server error while fetching data", Color.red); - } - 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"]); + if (!Application.isMobilePlatform) { - BazookaManager.Instance.saveFile = JObject.FromObject(jsonResponse["data"]); - if (!Application.isMobilePlatform) - { - var width = Display.main.systemWidth; - 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().volume = BazookaManager.Instance.GetSettingMusicVolume(); - foreach (CustomColorObject customColorObject in FindObjectsByType(FindObjectsSortMode.None)) customColorObject.SetColor(); - Tools.UpdateStatusText(loggedInText, "Loaded account data", Color.green); + var width = Display.main.systemWidth; + var height = Display.main.systemHeight; + Screen.SetResolution(width, height, BazookaManager.Instance.GetSettingFullScreen()); + QualitySettings.vSyncCount = BazookaManager.Instance.GetSettingVsync() ? 1 : -1; } else { - Tools.UpdateStatusText(loggedInText, (string)jsonResponse["message"], Color.red); + Application.targetFrameRate = 360; + QualitySettings.vSyncCount = 0; } + MenuMusic.Instance.GetComponent().volume = BazookaManager.Instance.GetSettingMusicVolume(); + foreach (CustomColorObject customColorObject in FindObjectsByType(FindObjectsSortMode.None)) customColorObject.SetColor(); + Tools.UpdateStatusText(loggedInText, "Loaded account data", Color.green); + } + else + { + Tools.UpdateStatusText(loggedInText, (string)jsonResponse["message"], Color.red); } loggedInChangeUsernameButton.interactable = true; loggedInChangePasswordButton.interactable = true; diff --git a/Assets/Scripts/Other/Endpoints.cs b/Assets/Scripts/Other/Endpoints.cs index 84f99a8..bea809c 100644 --- a/Assets/Scripts/Other/Endpoints.cs +++ b/Assets/Scripts/Other/Endpoints.cs @@ -1,11 +1,14 @@ public class Endpoints { - public static readonly string BASE_URL = "https://games.lncvrt.xyz/api"; - public static readonly string LEADERBOARDS_SCORE_ENDPOINT = BASE_URL + "/berrydash/leaderboards/score"; - public static readonly string LEADERBOARDS_BERRY_ENDPOINT = BASE_URL + "/berrydash/leaderboards/berry"; - public static readonly string LEADERBOARDS_COIN_ENDPOINT = BASE_URL + "/berrydash/leaderboards/coin"; - public static readonly string LEADERBOARDS_LEGACY_ENDPOINT = BASE_URL + "/berrydash/leaderboards/legacy"; - public static readonly string LEADERBOARDS_TOTAL_ENDPOINT = BASE_URL + "/berrydash/leaderboards/total"; + public static readonly string BASE_URL = "http://localhost:3342/api"; + public static readonly string LEADERBOARDS_ENDPOINT = BASE_URL + "/berrydash/leaderboards"; + public static readonly string LEADERBOARDS_SCORE_ENDPOINT = LEADERBOARDS_ENDPOINT + "/score"; + public static readonly string LEADERBOARDS_BERRY_ENDPOINT = LEADERBOARDS_ENDPOINT + "/berry"; + public static readonly string LEADERBOARDS_COIN_ENDPOINT = LEADERBOARDS_ENDPOINT + "/coin"; + 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_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"; } \ No newline at end of file