Add refresh login
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -15,6 +15,7 @@ public class AccountMenu : MonoBehaviour
|
|||||||
public Button loggedInChangePasswordButton;
|
public Button loggedInChangePasswordButton;
|
||||||
public Button loggedInSaveButton;
|
public Button loggedInSaveButton;
|
||||||
public Button loggedInLoadButton;
|
public Button loggedInLoadButton;
|
||||||
|
public Button loggedInRefreshLoginButton;
|
||||||
public Button loggedInLogoutButton;
|
public Button loggedInLogoutButton;
|
||||||
public Button loggedInBackButton;
|
public Button loggedInBackButton;
|
||||||
|
|
||||||
@@ -57,6 +58,13 @@ public class AccountMenu : MonoBehaviour
|
|||||||
public Button changePasswordBackButton;
|
public Button changePasswordBackButton;
|
||||||
public Button changePasswordSubmitButton;
|
public Button changePasswordSubmitButton;
|
||||||
|
|
||||||
|
public GameObject refreshLoginPanel;
|
||||||
|
public TMP_Text refreshLoginStatusText;
|
||||||
|
public TMP_InputField refreshLoginUsernameInput;
|
||||||
|
public TMP_InputField refreshLoginPasswordInput;
|
||||||
|
public Button refreshLoginBackButton;
|
||||||
|
public Button refreshLoginSubmitButton;
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
if (PlayerPrefs.HasKey("gameSession") && PlayerPrefs.HasKey("userName") && PlayerPrefs.HasKey("userId"))
|
if (PlayerPrefs.HasKey("gameSession") && PlayerPrefs.HasKey("userName") && PlayerPrefs.HasKey("userId"))
|
||||||
@@ -72,6 +80,7 @@ public class AccountMenu : MonoBehaviour
|
|||||||
loggedInChangePasswordButton.onClick.AddListener(() => SwitchPanel(5));
|
loggedInChangePasswordButton.onClick.AddListener(() => SwitchPanel(5));
|
||||||
loggedInSaveButton.onClick.AddListener(() => SaveAccount());
|
loggedInSaveButton.onClick.AddListener(() => SaveAccount());
|
||||||
loggedInLoadButton.onClick.AddListener(() => LoadAccount());
|
loggedInLoadButton.onClick.AddListener(() => LoadAccount());
|
||||||
|
loggedInRefreshLoginButton.onClick.AddListener(() => SwitchPanel(6));
|
||||||
loggedInLogoutButton.onClick.AddListener(() => SwitchPanel(1));
|
loggedInLogoutButton.onClick.AddListener(() => SwitchPanel(1));
|
||||||
loggedInBackButton.onClick.AddListener(async () => await SceneManager.LoadSceneAsync("MainMenu"));
|
loggedInBackButton.onClick.AddListener(async () => await SceneManager.LoadSceneAsync("MainMenu"));
|
||||||
loggedOutLoginButton.onClick.AddListener(() => SwitchPanel(2));
|
loggedOutLoginButton.onClick.AddListener(() => SwitchPanel(2));
|
||||||
@@ -87,6 +96,8 @@ public class AccountMenu : MonoBehaviour
|
|||||||
changeUsernameSubmitButton.onClick.AddListener(() => ChangeUsername());
|
changeUsernameSubmitButton.onClick.AddListener(() => ChangeUsername());
|
||||||
changePasswordBackButton.onClick.AddListener(() => SwitchPanel(0));
|
changePasswordBackButton.onClick.AddListener(() => SwitchPanel(0));
|
||||||
changePasswordSubmitButton.onClick.AddListener(() => ChangePassword());
|
changePasswordSubmitButton.onClick.AddListener(() => ChangePassword());
|
||||||
|
refreshLoginBackButton.onClick.AddListener(() => SwitchPanel(0));
|
||||||
|
refreshLoginSubmitButton.onClick.AddListener(() => RefreshLogin());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitchPanel(int panel)
|
void SwitchPanel(int panel)
|
||||||
@@ -103,6 +114,7 @@ public class AccountMenu : MonoBehaviour
|
|||||||
registerPanel.SetActive(false);
|
registerPanel.SetActive(false);
|
||||||
changeUsernamePanel.SetActive(false);
|
changeUsernamePanel.SetActive(false);
|
||||||
changePasswordPanel.SetActive(false);
|
changePasswordPanel.SetActive(false);
|
||||||
|
refreshLoginPanel.SetActive(false);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
PlayerPrefs.DeleteKey("gameSession");
|
PlayerPrefs.DeleteKey("gameSession");
|
||||||
@@ -117,6 +129,7 @@ public class AccountMenu : MonoBehaviour
|
|||||||
registerPanel.SetActive(false);
|
registerPanel.SetActive(false);
|
||||||
changeUsernamePanel.SetActive(false);
|
changeUsernamePanel.SetActive(false);
|
||||||
changePasswordPanel.SetActive(false);
|
changePasswordPanel.SetActive(false);
|
||||||
|
refreshLoginPanel.SetActive(false);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
loginUsernameInput.text = "";
|
loginUsernameInput.text = "";
|
||||||
@@ -128,6 +141,7 @@ public class AccountMenu : MonoBehaviour
|
|||||||
registerPanel.SetActive(false);
|
registerPanel.SetActive(false);
|
||||||
changeUsernamePanel.SetActive(false);
|
changeUsernamePanel.SetActive(false);
|
||||||
changePasswordPanel.SetActive(false);
|
changePasswordPanel.SetActive(false);
|
||||||
|
refreshLoginPanel.SetActive(false);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
registerUsernameInput.text = "";
|
registerUsernameInput.text = "";
|
||||||
@@ -142,6 +156,7 @@ public class AccountMenu : MonoBehaviour
|
|||||||
registerPanel.SetActive(true);
|
registerPanel.SetActive(true);
|
||||||
changeUsernamePanel.SetActive(false);
|
changeUsernamePanel.SetActive(false);
|
||||||
changePasswordPanel.SetActive(false);
|
changePasswordPanel.SetActive(false);
|
||||||
|
refreshLoginPanel.SetActive(false);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
changeUsernameCurrentUsernameInput.text = "";
|
changeUsernameCurrentUsernameInput.text = "";
|
||||||
@@ -153,6 +168,7 @@ public class AccountMenu : MonoBehaviour
|
|||||||
registerPanel.SetActive(false);
|
registerPanel.SetActive(false);
|
||||||
changeUsernamePanel.SetActive(true);
|
changeUsernamePanel.SetActive(true);
|
||||||
changePasswordPanel.SetActive(false);
|
changePasswordPanel.SetActive(false);
|
||||||
|
refreshLoginPanel.SetActive(false);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
changePasswordCurrentPasswordInput.text = "";
|
changePasswordCurrentPasswordInput.text = "";
|
||||||
@@ -165,6 +181,18 @@ public class AccountMenu : MonoBehaviour
|
|||||||
registerPanel.SetActive(false);
|
registerPanel.SetActive(false);
|
||||||
changeUsernamePanel.SetActive(false);
|
changeUsernamePanel.SetActive(false);
|
||||||
changePasswordPanel.SetActive(true);
|
changePasswordPanel.SetActive(true);
|
||||||
|
refreshLoginPanel.SetActive(false);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
refreshLoginUsernameInput.text = "";
|
||||||
|
refreshLoginPasswordInput.text = "";
|
||||||
|
loggedInPanel.SetActive(false);
|
||||||
|
loggedOutPanel.SetActive(false);
|
||||||
|
loginPanel.SetActive(false);
|
||||||
|
registerPanel.SetActive(false);
|
||||||
|
changeUsernamePanel.SetActive(false);
|
||||||
|
changePasswordPanel.SetActive(false);
|
||||||
|
refreshLoginPanel.SetActive(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,6 +270,7 @@ public class AccountMenu : MonoBehaviour
|
|||||||
dataForm.AddField("username", loginUsernameInput.text);
|
dataForm.AddField("username", loginUsernameInput.text);
|
||||||
dataForm.AddField("password", loginPasswordInput.text);
|
dataForm.AddField("password", loginPasswordInput.text);
|
||||||
dataForm.AddField("currentHighScore", PlayerPrefs.GetString("HighScoreV2", "0"));
|
dataForm.AddField("currentHighScore", PlayerPrefs.GetString("HighScoreV2", "0"));
|
||||||
|
dataForm.AddField("loginType", "0");
|
||||||
using UnityWebRequest request = UnityWebRequest.Post("https://berrydash.lncvrt.xyz/database/loginAccount.php", dataForm);
|
using UnityWebRequest request = UnityWebRequest.Post("https://berrydash.lncvrt.xyz/database/loginAccount.php", dataForm);
|
||||||
request.SetRequestHeader("User-Agent", "BerryDashClient");
|
request.SetRequestHeader("User-Agent", "BerryDashClient");
|
||||||
request.SetRequestHeader("ClientVersion", Application.version);
|
request.SetRequestHeader("ClientVersion", Application.version);
|
||||||
@@ -475,6 +504,52 @@ public class AccountMenu : MonoBehaviour
|
|||||||
loggedInSaveButton.interactable = true;
|
loggedInSaveButton.interactable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async void RefreshLogin()
|
||||||
|
{
|
||||||
|
WWWForm dataForm = new();
|
||||||
|
dataForm.AddField("username", refreshLoginUsernameInput.text);
|
||||||
|
dataForm.AddField("password", refreshLoginPasswordInput.text);
|
||||||
|
dataForm.AddField("loginType", "1");
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
UpdateStatusText(refreshLoginStatusText, "Failed to make HTTP request", Color.red);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string response = request.downloadHandler.text;
|
||||||
|
if (response != "-1")
|
||||||
|
{
|
||||||
|
if (response == "-2")
|
||||||
|
{
|
||||||
|
UpdateStatusText(refreshLoginStatusText, "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]);
|
||||||
|
PlayerPrefs.SetString("gameSession", session);
|
||||||
|
PlayerPrefs.SetString("userName", userName);
|
||||||
|
PlayerPrefs.SetInt("userId", userId);
|
||||||
|
SwitchPanel(0);
|
||||||
|
UpdateStatusText(refreshLoginStatusText, "", Color.red);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UpdateStatusText(refreshLoginStatusText, "Unknown server response", Color.red);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UpdateStatusText(refreshLoginStatusText, "Internal login server error", Color.red);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void UpdateStatusText(TMP_Text statusText, string message, Color color)
|
void UpdateStatusText(TMP_Text statusText, string message, Color color)
|
||||||
{
|
{
|
||||||
statusText.text = message;
|
statusText.text = message;
|
||||||
|
|||||||
Reference in New Issue
Block a user