OneShotOneKill/Assets/Script/Server/ServerInfo.cs

141 lines
3.9 KiB
C#
Raw Permalink Normal View History

2026-01-07 21:27:42 +00:00
using CodeStage.AntiCheat.Storage;
//using Firebase.Analytics;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using Random = UnityEngine.Random;
public class ServerInfo : MyCoroutine
{
private static ServerInfo _ins;
public static ServerInfo Ins { get { if (_ins == null) { _ins = new GameObject("ServerInfo").AddComponent<ServerInfo>(); DontDestroyOnLoad(_ins.gameObject); } return _ins; } }
public static DateTime ServerTime;
public ServerData m_ServerData;
public string UserName, UserID;
public int VersionCode;
bool ServerTimeUpdate = false;
public float m_relogintime = 0f, m_serverTimeRefresh = 0f;
DateTime AppPauseTime;
public SC_ServerStatus m_SC_ServerStatus;
//public bool IsLiveServer() { return PlayFabSettings.TitleId.Equals(Server_Live_ID); }
List<string> list_log = new List<string>();
private void Awake()
{
//PlayFabSettings.TitleId = Server_Live_ID;
}
void Update()
{
ServerTime = ServerTime.AddSeconds(Time.unscaledDeltaTime);
m_relogintime += Time.unscaledDeltaTime;
if (m_relogintime > 43200f) // 12시간
{
m_relogintime = 0f;
Login(null, () =>
{
m_relogintime = 43000f; // 실패 시, 200초 뒤에 다시 시도
});
}
// 인터넷 연결 체크
if (Application.internetReachability == NetworkReachability.NotReachable)
return;
if (ServerTimeUpdate)
{
m_serverTimeRefresh += Time.unscaledDeltaTime;
if (m_serverTimeRefresh > 300f) // 5분
{
m_serverTimeRefresh = 0f;
//Get_ServerTime(null); // 고민 중...
}
}
}
private void OnApplicationPause(bool pause)
{
if (pause)
{
AppPauseTime = ServerTime;
}
else
{
//if (InGameInfo.Ins != null)
//{
// //OffLineReward.m_Sec = (int)(ServerTime - AppPauseTime).TotalSeconds;
// // TODO 정인호 : 오프라인 보상 서버 통신 필요?
//}
2026-01-07 21:27:42 +00:00
}
}
public void Save()
{
if (m_ServerData == null) return;
CryptoUtil.Save(m_ServerData, MyValue.SaveDataFileName);
}
public void Load(Action<bool> _servercomplete = null)
{
m_ServerData = CryptoUtil.Load<ServerData>(MyValue.SaveDataFileName);
if (m_ServerData == null)
{ // 최초 생성
m_ServerData = new ServerData();
_servercomplete?.Invoke(true);
}
else
_servercomplete?.Invoke(false);
}
public void Show_UpdateAppPopup()
{
#if UNITY_ANDROID
Popup.Ins.Set(ePopupType.One, 138,
() =>
{
#if FGB_OneStore
Application.OpenURL(MyValue.OnestoreURL);
#else
Application.OpenURL("market://details?id=" + Application.identifier);
#endif
DSUtil.Quit();
}, DSUtil.Quit);
#else
Popup.Ins.Set(ePopupType.One, 138,
() =>
{
Application.OpenURL("itms-apps://itunes.apple.com/app/id6444575874");
DSUtil.Quit();
}, DSUtil.Quit);
#endif
}
void Show_QuitPopup(ePopupType _type, int _msgkey, Action _ok = null)
{
Time.timeScale = 0f;
ServerTimeUpdate = false;
Popup.Ins.Set(_type, _msgkey, _ok == null ? DSUtil.Quit : _ok, DSUtil.Quit);
}
public void Login(Action<bool> _servercomplete, Action _fail = null)
{
Load(_servercomplete);
}
public void FirebaseAnalyticsEvent(string _event)
{
//FirebaseAnalytics.LogEvent(_event);
}
void FirebaseAnalyticsEvent_Inapp(string _productid)
{
//var split = _productid.Split('.');
//Add_Log(1, split[split.Length - 1]);
}
}