Rework the way account menu works
This commit is contained in:
80
Assets/Scripts/AccountMenu/AccountLogin.cs
Normal file
80
Assets/Scripts/AccountMenu/AccountLogin.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System.Numerics;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class AccountLogin : MonoBehaviour
|
||||
{
|
||||
public TMP_Text loginPanelStatusText;
|
||||
public TMP_InputField loginUsernameInput;
|
||||
public TMP_InputField loginPasswordInput;
|
||||
public Button loginBackButton;
|
||||
public Button loginSubmitButton;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
loginBackButton.onClick.AddListener(() => AccountHandler.instance.SwitchPanel(1));
|
||||
loginSubmitButton.onClick.AddListener(() => SubmitLogin());
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
loginUsernameInput.text = "";
|
||||
loginPasswordInput.text = "";
|
||||
loginPanelStatusText.text = "";
|
||||
}
|
||||
|
||||
async void SubmitLogin()
|
||||
{
|
||||
WWWForm dataForm = new();
|
||||
dataForm.AddField("username", loginUsernameInput.text);
|
||||
dataForm.AddField("password", loginPasswordInput.text);
|
||||
dataForm.AddField("currentHighScore", PlayerPrefs.GetString("HighScoreV2", "0"));
|
||||
dataForm.AddField("loginType", "0");
|
||||
using UnityWebRequest request = UnityWebRequest.Post("https://berrydash.lncvrt.xyz/database/loginAccount.php", dataForm);
|
||||
request.SetRequestHeader("User-Agent", "BerryDashClient");
|
||||
request.SetRequestHeader("ClientVersion", Application.version);
|
||||
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
||||
await request.SendWebRequest();
|
||||
if (request.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
AccountHandler.UpdateStatusText(loginPanelStatusText, "Failed to make HTTP request", Color.red);
|
||||
return;
|
||||
}
|
||||
string response = request.downloadHandler.text;
|
||||
if (response != "-1")
|
||||
{
|
||||
if (response == "-2")
|
||||
{
|
||||
AccountHandler.UpdateStatusText(loginPanelStatusText, "Incorrect username or password", Color.red);
|
||||
}
|
||||
else if (response.Split(":")[0] == "1")
|
||||
{
|
||||
string[] array = response.Split(':');
|
||||
string session = array[1];
|
||||
string userName = array[2];
|
||||
int userId = int.Parse(array[3]);
|
||||
BigInteger highScore = BigInteger.Parse(array[4]);
|
||||
int iconId = int.Parse(array[5]);
|
||||
int overlayId = int.Parse(array[6]);
|
||||
PlayerPrefs.SetString("gameSession", session);
|
||||
PlayerPrefs.SetString("userName", userName);
|
||||
PlayerPrefs.SetInt("userId", userId);
|
||||
PlayerPrefs.SetString("HighScoreV2", highScore.ToString());
|
||||
PlayerPrefs.SetInt("icon", iconId);
|
||||
PlayerPrefs.SetInt("overlay", overlayId);
|
||||
AccountHandler.instance.SwitchPanel(0);
|
||||
AccountHandler.UpdateStatusText(loginPanelStatusText, "", Color.red);
|
||||
}
|
||||
else
|
||||
{
|
||||
AccountHandler.UpdateStatusText(loginPanelStatusText, "Unknown server response", Color.red);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AccountHandler.UpdateStatusText(loginPanelStatusText, "Internal login server error", Color.red);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user