using UnityEngine;
using System.Threading.Tasks;
using BackEnd;
using TMPro;
using System;
using System.Collections;
#if UNITY_ANDROID
using GooglePlayGames;
using GooglePlayGames.BasicApi;
#endif
public class BackendManager : MonoBehaviour
{
public GameObject serverCheckPanelObj;
private bool isServerUnderMaintenance = false;
public TextMeshProUGUI text;
private static BackendManager instance;
public string serverCheck;
public PrivacyURL privacyURL;
public CountdownTimer countdownTimer;
public GameObject hackBanPanel;
public static BackendManager Instance
{
get
{
if (instance == null)
{
instance = FindObjectOfType<BackendManager>();
if (instance == null)
{
GameObject obj = new GameObject("BackendManager");
instance = obj.AddComponent<BackendManager>();
}
}
return instance;
}
}
void Awake()
{
privacyURL.gameObject.SetActive(true);
if (instance == null)
{
instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
if (this != instance)
{
Destroy(gameObject);
}
}
}
void Start()
{
var bro = Backend.Initialize(true);
if (bro.IsSuccess())
{
Debug.Log("초기화 성공 : " + bro);
RegisterErrorHandlers();
}
else
{
Debug.LogError("초기화 실패 : " + bro);
}
privacyURL.StartGame();
}
void RegisterErrorHandlers()
{
if (Backend.IsInitialized)
{
Backend.ErrorHandler.OnMaintenanceError = () => { isServerUnderMaintenance = true; };
if (Backend.IsInitialized)
{
StartCoroutine(CheckServerStatusRoutine());
}
Backend.ErrorHandler.OnOtherDeviceLoginDetectedError = () =>
{
Debug.LogWarning("다른 기기에서 로그인하여 자동 로그아웃됨!");
NotificationPanel.Instance.Notify("다른기기에서 로그인해서 자동 로그아웃됐어요");
if (serverCheckPanelObj == null)
{
Debug.LogError("serverCheckPanelObj가 null입니다. Inspector에서 할당되었는지 확인하세요.");
return;
}
if (text == null)
{
Debug.LogError("text(TextMeshProUGUI)가 null입니다. Inspector에서 할당되었는지 확인하세요.");
return;
}
serverCheckPanelObj.SetActive(true);
text.text = "다른기기에서 로그인해서 자동 로그아웃됐어요";
BackendGameData.Instance.GameDataUpdate();
Invoke("Quit", 3);
};
}
else
{
Debug.LogError("Backend 초기화가 완료되지 않았습니다. 핸들러가 정상적으로 등록되지 않을 가능성이 있음.");
}
}
public async void Test()
{
#if UNITY_EDITOR || UNITY_ANDROID
if (DataManager.Instance.data.privacyOk)
{
Loading(true);
}
#endif
serverCheck = Backend.Utils.GetServerStatus().GetReturnValuetoJSON()["serverStatus"].ToString();
if (serverCheck == "2")
{
serverCheckPanelObj.SetActive(true);
Debug.Log("서버 점검 중입니다.");
}
await Task.Run(() => {});
Login();
}
void Loading(bool b)
{
privacyURL.loadingPanelObj.SetActive(b);
}
private void Update()
{
if (isServerUnderMaintenance)
{
serverCheckPanelObj.SetActive(true);
Debug.Log("서버 점검 중입니다.");
isServerUnderMaintenance = false;
}
}
IEnumerator CheckServerStatusRoutine()
{
while (true)
{
var serverStatus = Backend.Utils.GetServerStatus().GetReturnValuetoJSON()["serverStatus"].ToString();
if (serverStatus == "2")
{
Debug.Log("점검 에러 발생!!!");
serverCheckPanelObj.SetActive(true);
yield break;
}
yield return new WaitForSeconds(60);
}
}
}
autorefreshtoken은 체크해놨어요.
근데 다른기기 로그인 할떄 Backend.ErrorHandler.OnOtherDeviceLoginDetectedError이게 안돼요.
어떻게 하면 되는지 궁금합니다.