diff --git a/Assets/Scripts/OutGame/Net/AccountPanel.cs b/Assets/Scripts/OutGame/Net/AccountPanel.cs index 6e049cd4..9b95f765 100644 --- a/Assets/Scripts/OutGame/Net/AccountPanel.cs +++ b/Assets/Scripts/OutGame/Net/AccountPanel.cs @@ -7,7 +7,8 @@ namespace TKS.OutGame.Net { /// /// 옵션 팝업의 계정 칸 — 서버 모드에서만 열린다(로비 「옵션」 버튼). - /// · 소셜 계정으로 로그인한 유저 = 「로그아웃」 → 타이틀의 로그인 화면으로. + /// · 소셜 계정으로 로그인한 유저 = 「로그아웃」 → 타이틀의 로그인 화면으로 · 「계정 탈퇴」 → 복구할 수 없고 유예 일수(서버 값) 뒤 완전 삭제된다는 안내를 보고 + /// 신청한다(로그아웃됨 · 유예 안에 다시 로그인하면 취소할 수 있다). /// · 게스트 = 로그아웃 대신 「계정 삭제」(확인 문구 「계정 삭제」를 입력해야 한다 → 데이터 삭제 · 로그인 상태 초기화) + 「소셜 계정 연동」. /// · 연동하려는 소셜 계정이 이미 다른 게임 계정에 연동돼 있으면 「어느 계정으로 할지」 고르는 팝업(계정 요약 · 데이터가 사라질 수 있다는 안내). /// (PD 2026-11-17) @@ -65,6 +66,14 @@ namespace TKS.OutGame.Net root.Modal("로그아웃", "로그아웃할까요?\n타이틀의 로그인 화면으로 돌아갑니다.", new OutGameRoot.ModalButton("로그아웃", UiKit.Red, () => sync.Logout(why => root.Toast("로그아웃하지 못했습니다 (" + why + ")"))), new OutGameRoot.ModalButton("취소", UiKit.Dark, null))); + // 소셜 계정 — 계정 삭제 대신 계정 탈퇴(유예 일수 = 서버 값 · 값이 없으면 서버가 탈퇴를 받지 않는다) + int days = (int)info.Num("withdrawGraceDays"); + if (days > 0) + { + UiKit.Label(content, WithdrawNotice(days), 26, UiKit.InkSoft, TextAnchor.UpperLeft, top, top, new Vector2(0f, y - 250f), new Vector2(Width - 16f, 120f), false) + .horizontalOverflow = HorizontalWrapMode.Wrap; + UiKit.Btn("Withdraw", content, "계정 탈퇴", 34, UiKit.Red, UiKit.White, top, top, new Vector2(0f, y - 390f), new Vector2(560f, 100f), () => ConfirmWithdraw(root, sync, days)); + } return; } @@ -102,6 +111,20 @@ namespace TKS.OutGame.Net UiKit.Btn("Delete", content, "계정 삭제", 34, UiKit.Red, UiKit.White, top, top, new Vector2(0f, y - 120f), new Vector2(560f, 100f), () => ConfirmDelete(root, sync)); } + /// 계정 탈퇴 안내 글 — 복구할 수 없다 · 유예 일수 뒤 완전 삭제 · 그 안에 취소할 수 있다. + public static string WithdrawNotice(int days) + { + return "계정을 탈퇴하면 복구할 수 없으며, " + days + "일 뒤 계정과 모든 데이터가 완전히 삭제됩니다. " + days + "일 안에 같은 소셜 계정으로 다시 로그인하면 언제든 탈퇴를 취소할 수 있습니다."; + } + + /// 계정 탈퇴 확인(소셜 계정) — 안내를 보고 「탈퇴」를 눌러야 신청한다. + public static void ConfirmWithdraw(OutGameRoot root, ServerSync sync, int days) + { + root.Modal("계정 탈퇴", WithdrawNotice(days) + "\n\n탈퇴를 신청할까요?", + new OutGameRoot.ModalButton("탈퇴", UiKit.Red, () => sync.Withdraw(why => root.Toast("계정 탈퇴를 신청하지 못했습니다 (" + why + ")"))), + new OutGameRoot.ModalButton("취소", UiKit.Dark, null)); + } + /// 계정 삭제 확인 — 유저가 「계정 삭제」를 입력해야 삭제 버튼이 통한다. public static void ConfirmDelete(OutGameRoot root, ServerSync sync) { diff --git a/Assets/Scripts/OutGame/Net/ServerClient.cs b/Assets/Scripts/OutGame/Net/ServerClient.cs index 99efc194..11b99f5a 100644 --- a/Assets/Scripts/OutGame/Net/ServerClient.cs +++ b/Assets/Scripts/OutGame/Net/ServerClient.cs @@ -80,6 +80,19 @@ namespace TKS.OutGame.Net } } + /// 서버가 게임을 막은 이유 — 서버 점검(시간 · 안내 글) 또는 이용 제한(끝나는 시각). 안내한 뒤 게임을 끝낸다. + public class ServerStop + { + /// SERVER_MAINTENANCE · ACCOUNT_SUSPENDED + public string code; + /// 점검 시작 시각(ISO · 없으면 ""). + public string startAt; + /// 점검이 끝나는 시각 · 이용 제한이 끝나는 시각(ISO · 없으면 "" = 이용 제한은 무기한). + public string endAt; + /// 운영자가 적은 점검 안내 글(없으면 ""). + public string message; + } + /// /// 서버와 HTTP 로 말하는 가장 아래 층 — 주소 붙이기 · 로그인 증표 · 응답 해석만 한다(게임 규칙은 모른다). /// 로그인 = 게스트(새 계정) 또는 소셜 계정(구글 플레이 · 게임센터) · 다음부터는 기기에 저장한 재발급 증표로 이어 한다(앱을 켤 때 = 새 세션). @@ -98,15 +111,36 @@ namespace TKS.OutGame.Net public const string LostReplaced = "SESSION_REPLACED"; // 다른 기기에서 접속(또는 로그아웃 · 연동 변경) public const string LostDeleted = "ACCOUNT_DELETED"; public const string LostExpired = "SESSION_EXPIRED"; // 증표를 다시 받지 못함 + public const string LostWithdrawing = "ACCOUNT_WITHDRAWING"; // 탈퇴를 신청한 계정 — 다시 로그인해 탈퇴를 취소해야 한다 + // 서버가 「지금은 게임을 할 수 없다」고 알리는 이유 코드 — 다시 보내도 소용없다(안내 뒤 게임 종료) + public const string StopMaintenance = "SERVER_MAINTENANCE"; // 서버 점검 중(점검 중 접속을 허용받은 계정이 아님) + public const string StopSuspended = "ACCOUNT_SUSPENDED"; // 이용이 제한된 계정(블랙리스트) public const string MethodGuest = "guest"; + // 계정 탈퇴 요청의 확인 값 — 유저가 화면에서 안내를 보고 누른 뒤에만 보낸다(서버 규칙과 같은 값) + const string WithdrawConfirm = "WITHDRAW"; // 계정 삭제 요청의 확인 값 — 유저가 화면에서 확인 문구를 입력한 뒤에만 보낸다(서버 규칙과 같은 값) const string DeleteConfirm = "DELETE"; /// 세션을 잃은 이유(null = 정상) — 값이 있으면 다시 로그인해야 한다. public string LostReason { get; private set; } + /// 서버가 게임을 막았다(null = 정상) — 서버 점검 · 이용 제한. 값이 있으면 안내한 뒤 게임을 끝낸다. + public ServerStop Stop { get; private set; } /// 지금 세션의 로그인 방식(guest · google · apple). public string Method { get; private set; } + /// 테스트 전용 — 정해 둔 응답. + public class FakeResponse + { + public long status; + public string json; + } + + /// + /// 테스트 전용 — (방식, 주소)를 받아 정해 둔 응답을 돌려주면 서버에 보내지 않고 그 응답을 쓴다(null = 실제로 보낸다). + /// 서버 점검 · 업데이트 필요 · 이용 제한 화면을 서버 전체 설정을 건드리지 않고 확인하려는 것(ServerLink.ClearForce 가 비운다). + /// + public static Func Intercept; + // 기기에 저장하지 않는 모드(테스트)의 임시 보관 — 씬을 다시 열어도 남는다(ClearMemory 로 비운다) static readonly Dictionary memory = new Dictionary(); @@ -208,6 +242,12 @@ namespace TKS.OutGame.Net for (int attempt = 0; attempt < 2; attempt++) { yield return SendOnce(method, path, body, auth, res); + if (Stop != null) yield break; // 서버 점검 · 이용 제한 — 증표를 다시 받아도 소용없다 + if (auth && res.status == 403 && res.Message == LostWithdrawing) + { + LostReason = LostWithdrawing; + yield break; + } if (res.status != 401 || !auth) yield break; // 서버가 세션이 끝났다고 알렸다(다른 기기에서 접속 · 삭제된 계정) — 증표를 다시 받으려 하지 않는다 if (res.Message == LostReplaced || res.Message == LostDeleted) @@ -237,6 +277,14 @@ namespace TKS.OutGame.Net res.status = 0; res.error = null; res.json = null; + var fake = Intercept != null ? Intercept(method, path) : null; + if (fake != null) + { + yield return null; // 실제 요청처럼 한 프레임 뒤에 답한다 + res.status = fake.status; + Finish(res, false, fake.json, null); + yield break; + } using (var req = new UnityWebRequest(baseUrl + path, method)) { req.downloadHandler = new DownloadHandlerBuffer(); @@ -264,31 +312,44 @@ namespace TKS.OutGame.Net res.status = req.responseCode; bool transport = req.result == UnityWebRequest.Result.ConnectionError || req.result == UnityWebRequest.Result.DataProcessingError; - var text = req.downloadHandler != null ? req.downloadHandler.text : null; - if (!string.IsNullOrEmpty(text)) - { - try - { - res.json = Parse(text); - } - catch (Exception) - { - res.json = null; // JSON 이 아닌 응답(프록시 오류 화면 등) - } - } - res.ok = !transport && res.status >= 200 && res.status < 300; - res.network = transport || res.status == 0 || res.status >= 500; - if (!res.ok) res.error = transport || res.status == 0 ? req.error : "HTTP " + res.status + " " + res.Message; + Finish(res, transport, req.downloadHandler != null ? req.downloadHandler.text : null, req.error); } } + /// 응답을 결과로 정리한다 — 본문 해석 · 성공/연결 문제 구분 · 서버가 게임을 막았는지(점검 · 이용 제한). + void Finish(ServerResult res, bool transport, string text, string transportError) + { + if (!string.IsNullOrEmpty(text)) + { + try + { + res.json = Parse(text); + } + catch (Exception) + { + res.json = null; // JSON 이 아닌 응답(프록시 오류 화면 등) + } + } + res.ok = !transport && res.status >= 200 && res.status < 300; + res.network = transport || res.status == 0 || res.status >= 500; + if (!res.ok) res.error = transport || res.status == 0 ? transportError : "HTTP " + res.status + " " + res.Message; + // 서버 점검 · 이용 제한 = 연결 문제가 아니라 서버가 막은 것 — 다시 보내지 않는다 + if (res.status == 503 && res.Message == StopMaintenance) + { + res.network = false; + Stop = new ServerStop { code = StopMaintenance, startAt = res.Str("maintenanceStartAt"), endAt = res.Str("maintenanceEndAt"), message = res.Str("maintenanceMessage") }; + } + else if (res.status == 401 && res.Message == StopSuspended) + Stop = new ServerStop { code = StopSuspended, startAt = res.Str("suspendedAt"), endAt = res.Str("suspensionEndAt"), message = "" }; + } + /// 테스트용 자동 로그인 — 저장한 증표가 있으면 이어 하기 → 없거나 서버가 받지 않으면 새 게스트 계정(로그인 화면 없음). public IEnumerator Login(int gameId, ServerResult res) { if (HasSaved) { yield return Resume(res); - if (res.ok || res.network) yield break; // 연결 문제면 새 계정을 만들지 않는다(계정을 잃지 않게) + if (res.ok || res.network || Stop != null) yield break; // 연결 문제 · 서버 점검 · 이용 제한이면 새 계정을 만들지 않는다(계정을 잃지 않게) Debug.LogWarning("[TKS] 저장한 로그인 증표를 서버가 받지 않아 새 게스트 계정으로 시작합니다: " + res.error); } yield return GuestLogin(gameId, res); @@ -346,6 +407,23 @@ namespace TKS.OutGame.Net if (res.ok) Forget(true); } + /// + /// 계정 탈퇴 신청(소셜 계정) — 서버가 유예 일수 뒤 완전 삭제를 예약하고 로그아웃시킨다. 기기의 증표를 지운다 + /// (마지막 로그인 방식은 남는다 — 유예 안에 그 계정으로 다시 로그인하면 탈퇴를 취소할 수 있다). + /// + public IEnumerator Withdraw(ServerResult res) + { + var body = new JObject { ["confirm"] = WithdrawConfirm }; + yield return Send("POST", "/auth/withdraw", body.ToString(Formatting.None), true, res); + if (res.ok) Forget(); + } + + /// 계정 탈퇴 취소 — 유예 기간 안에 다시 로그인한 유저가 고른다. + public IEnumerator CancelWithdraw(ServerResult res) + { + yield return Send("POST", "/auth/withdraw/cancel", null, true, res); + } + IEnumerator Refresh(ServerResult res) { var body = new JObject { ["refreshToken"] = refreshToken }; @@ -359,6 +437,7 @@ namespace TKS.OutGame.Net accessToken = res.Str("accessToken"); refreshToken = res.Str("refreshToken"); LostReason = null; + Stop = null; if (method == null && res.Has("accountType")) method = res.Has("provider") ? res.Str("provider") : MethodGuest; if (method != null) Method = method; Keep("refresh", refreshToken); diff --git a/Assets/Scripts/OutGame/Net/ServerSession.cs b/Assets/Scripts/OutGame/Net/ServerSession.cs index 356b4fac..fd8c7363 100644 --- a/Assets/Scripts/OutGame/Net/ServerSession.cs +++ b/Assets/Scripts/OutGame/Net/ServerSession.cs @@ -1302,12 +1302,39 @@ namespace TKS.OutGame.Net } } + /// 게임 종료를 요청한 횟수(서버 점검 · 이용 제한 안내의 버튼) — 테스트가 본다. + public static int Quits { get; private set; } + /// 마지막으로 연 스토어 주소(업데이트 안내의 버튼) — 테스트가 본다. + public static string LastStoreUrl { get; private set; } + + /// 게임을 끝낸다(서버 점검 안내의 「확인」 · 이용 제한 안내의 「종료」). 테스트 모드에서는 세기만 한다. + public static void Quit() + { + Quits++; + if (ServerConfig.Forced) return; +#if UNITY_EDITOR + UnityEditor.EditorApplication.isPlaying = false; +#else + Application.Quit(); +#endif + } + + /// 스토어를 연다(업데이트 안내의 버튼). 테스트 모드에서는 주소만 적어 둔다. + public static void OpenStore(string url) + { + LastStoreUrl = url; + if (ServerConfig.Forced || string.IsNullOrEmpty(url)) return; + Application.OpenURL(url); + } + /// 서버 연결 테스트 전용 — 씬을 열기 전에 부른다. 끝나면 ClearForce. public static void ForceForTest(string url, int gameId) { ServerClient.ClearMemory(); // 테스트마다 새 계정으로 시작한다 ServerSync.Drop(); // 앞 테스트가 타이틀 씬에서 만든 일꾼(씬이 바뀌어도 남는다)을 치운다 FromTitle = false; + Quits = 0; + LastStoreUrl = null; ServerConfig.ForceForTest(url, gameId); Apply(); } @@ -1342,6 +1369,9 @@ namespace TKS.OutGame.Net SkipSignupTimezone = false; LoginUi = false; FromTitle = false; + Quits = 0; + LastStoreUrl = null; + ServerClient.Intercept = null; ServerSync.Drop(); ServerClient.ClearMemory(); ServerConfig.ClearForce(); diff --git a/Assets/Scripts/OutGame/Net/ServerSync.cs b/Assets/Scripts/OutGame/Net/ServerSync.cs index 565b4179..ce635be3 100644 --- a/Assets/Scripts/OutGame/Net/ServerSync.cs +++ b/Assets/Scripts/OutGame/Net/ServerSync.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Globalization; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; @@ -15,6 +16,9 @@ namespace TKS.OutGame.Net /// 4. 거절: 서버가 요청을 받아 주지 않으면(기기와 서버가 어긋남) 남은 요청을 버리고 서버 상태로 되돌린다. /// 5. 끊김: 연결 문제는 몇 번 조용히 다시 보내고, 그래도 안 되면 화면을 막고 「다시 시도」를 받는다. /// 6. 로그인: 저장한 증표로 이어 하기 → 없으면 로그인 화면(게스트 · 소셜). 다른 기기에서 같은 계정으로 접속하면 이쪽은 안내 뒤 타이틀로 돌아간다. + /// 8. 접속 판정: 앱 버전이 낮으면 「업데이트」 안내와 스토어 바로가기 · 서버 점검 중이면(점검 중 접속을 허용받은 계정이 아닐 때) 점검 시간 안내 → + /// 확인 = 게임 종료 · 이용이 제한된 계정이면 제한 안내(끝나는 시각) → 종료 — 점검 · 이용 제한은 게임 중이어도 다음 요청에서 바로 뜬다. + /// 탈퇴를 신청한 소셜 계정으로 로그인하면 「탈퇴 취소」를 물어본다(PD 2026-11-17). /// 7. 타이틀 씬: 타이틀 씬이 열리면 세션 없이 먼저 만들어져(ServerLink) 로그인까지 하고, 씬이 바뀌어도 남아 게임 씬의 세션이 이어받는다(Attach) — /// 로그인 화면은 타이틀 위에 뜨고, 계정 상태는 게임 씬에서 받는다. 게임 씬을 바로 열면(개발 · 테스트) 전 과정을 그 씬에서 한다. /// @@ -52,6 +56,21 @@ namespace TKS.OutGame.Net { get { return overlayText != null && Blocking ? overlayText.text : ""; } } + /// 안내의 첫 버튼 글(테스트 · 확인용 · 버튼이 없으면 ""). + public string OverlayButtonLabel + { + get { return Blocking && overlayButton != null && overlayButton.activeSelf && overlayButtonLabel != null ? overlayButtonLabel.text : ""; } + } + /// 게임을 계속할 수 없다는 안내(업데이트 필요 · 서버 점검 · 이용 제한)가 떴는가 — 버튼은 스토어 이동 또는 종료뿐이다. + public bool Halted { get; private set; } + + // 접속 판정 안내 글(PD 2026-11-17 지정 문구) + public const string TextUpdate = "새로운 업데이트를 진행하세요"; + public const string TextMaintenance = "서버 점검 중입니다."; + public const string TextSuspended = "이용이 제한 된 계정입니다."; + public const string TextWithdrawing = "탈퇴를 신청한 계정입니다."; + // 서버 상태 값 — 점검 중 + const string StatusMaintenance = "MAINTENANCE"; class Item { @@ -92,6 +111,12 @@ namespace TKS.OutGame.Net Text overlayText; GameObject overlayButton; Text overlayButtonLabel; + // 둘째 버튼(고르는 안내에서만 — 스토어 두 곳 · 탈퇴 취소/다른 계정) + GameObject overlayButton2; + Text overlayButtonLabel2; + // 버튼이 하는 일(null = 「다시 시도」 · 「확인」 = 기다리는 쪽을 깨운다) + Action overlayAction; + Action overlayAction2; internal static ServerSync Create(ServerSession session) { @@ -194,17 +219,17 @@ namespace TKS.OutGame.Net if (!loggedIn) { - yield return Client.Send("GET", "/games/" + ServerConfig.GameId + "/status", null, false, r); + // 앱 버전을 실어 보낸다 — 서버가 타겟 버전과 견줘 업데이트가 필요한지 알려 준다 + yield return Client.Send("GET", "/games/" + ServerConfig.GameId + "/status?ver=" + Uri.EscapeDataString(Application.version ?? ""), null, false, r); if (!r.ok) { yield return AskRetry("서버에 접속할 수 없습니다", r); continue; } - if (r.Str("status") != "NORMAL") - { - yield return AskRetry("서버 점검 중입니다 (" + r.Str("status") + ")", null); - continue; - } + if (r.Bool("updateRequired")) yield return UpdateRequired(r); // 돌아오지 않는다 — 스토어에서 업데이트해야 한다 + // 서버 점검 중이어도 여기서 막지 않는다 — 점검 중 접속을 허용받은 계정(화이트리스트)인지는 로그인해야 알 수 있다. + // 허용받지 않은 계정은 로그인 · 요청을 서버가 거절하고(Client.Stop), 그때 점검 안내를 띄운다 + bool maintenance = r.Str("status") == StatusMaintenance; yield return Client.Send("GET", "/tks/config", null, false, goods); if (!goods.ok) @@ -213,12 +238,21 @@ namespace TKS.OutGame.Net continue; } - yield return Authenticate(r); + yield return Authenticate(r, maintenance ? TextMaintenance + "\n점검 중 접속이 허용된 계정만 로그인할 수 있습니다." : null); + if (Client.Stop != null) yield return Stopped(); // 서버 점검 · 이용 제한 — 돌아오지 않는다 if (!r.ok) { yield return AskRetry("로그인하지 못했습니다", r); continue; } + if (r.Has("withdrawal")) + { + // 탈퇴를 신청한 계정 — 취소하고 계속할지 물어본다(다른 계정으로 로그인 = 로그아웃 뒤 처음부터) + bool keep = false; + yield return AskWithdrawal(r.Str("withdrawal.deleteAt"), v => keep = v); + if (!keep) continue; + ShowOverlay("서버에 접속하는 중…", false); + } } loggedIn = false; // 아래에서 막혀 다시 시도할 때는 처음부터 한다 @@ -238,6 +272,7 @@ namespace TKS.OutGame.Net // 기기 시간대를 실어 보낸다 — 새 계정이면 서버가 이때 계정에 고정한다(일일 초기화 = 그 나라 0시) yield return Client.Send("GET", ServerSession.AccountPath(), null, true, r); + if (Client.Stop != null) yield return Stopped(); if (!r.ok) { yield return AskRetry("계정 정보를 받지 못했습니다", r); @@ -256,18 +291,18 @@ namespace TKS.OutGame.Net /// 로그인 — 기기에 저장한 증표가 있으면 그 계정으로 이어 하고(마지막에 로그인한 계정), 없거나 서버가 받지 않으면 로그인 화면을 띄운다. /// 로그인 화면 = 게스트로 시작 · 소셜 계정(구글 플레이 · 게임센터)으로 로그인. 끝나면 r.ok (연결 문제면 r.network). /// - IEnumerator Authenticate(ServerResult r) + IEnumerator Authenticate(ServerResult r, string firstNotice = null) { if (ServerLink.AutoLogin) { yield return Client.Login(ServerConfig.GameId, r); // 테스트: 화면 없이 이어 하기 → 없으면 새 게스트 yield break; } - string notice = null; + string notice = firstNotice; if (Client.HasSaved) { yield return Client.Resume(r); - if (r.ok || r.network) yield break; + if (r.ok || r.network || Client.Stop != null) yield break; // 서버 점검 · 이용 제한이면 저장한 로그인을 지우지 않는다 notice = "로그인 정보가 만료되었거나 다른 기기에서 접속했습니다.\n다시 로그인해 주세요."; Client.Forget(); } @@ -304,7 +339,7 @@ namespace TKS.OutGame.Net } yield return Client.SocialLogin(ServerConfig.GameId, method, credential, socialId, r); } - if (r.ok || r.network) yield break; + if (r.ok || r.network || Client.Stop != null) yield break; notice = "로그인하지 못했습니다 (" + (string.IsNullOrEmpty(r.Message) ? r.error : r.Message) + ")"; } } @@ -330,6 +365,7 @@ namespace TKS.OutGame.Net Client.Forget(); string msg = reason == ServerClient.LostReplaced ? "다른 기기에서 이 계정으로 접속하여\n연결이 종료되었습니다." : reason == ServerClient.LostDeleted ? "삭제된 계정입니다." + : reason == ServerClient.LostWithdrawing ? TextWithdrawing + "\n다시 로그인하면 탈퇴를 취소할 수 있습니다." : "로그인 정보가 만료되었습니다."; retryPressed = false; ShowOverlay(msg + "\n확인을 누르면 타이틀 화면으로 돌아갑니다", true, "확인"); @@ -349,22 +385,31 @@ namespace TKS.OutGame.Net /// 로그아웃(소셜 계정) → 타이틀의 로그인 화면으로. 실패하면 fail(이유). public void Logout(Action fail) { - StartCoroutine(Leave(false, fail)); + StartCoroutine(Leave(Client.Logout, "로그아웃하는 중…", fail)); + } + + /// + /// 계정 탈퇴 신청(소셜 계정) → 서버가 유예 일수 뒤 완전 삭제를 예약하고 로그아웃시킨다 → 타이틀의 로그인 화면으로. + /// 유예 안에 같은 소셜 계정으로 다시 로그인하면 탈퇴를 취소할 수 있다. + /// + public void Withdraw(Action fail) + { + StartCoroutine(Leave(Client.Withdraw, "계정 탈퇴를 신청하는 중…", fail)); } /// 계정 삭제(게스트) → 서버가 데이터를 지우고, 기기의 로그인 상태를 초기화한 뒤 타이틀의 로그인 화면으로. public void DeleteAccount(Action fail) { - StartCoroutine(Leave(true, fail)); + StartCoroutine(Leave(Client.DeleteAccount, "계정을 삭제하는 중…", fail)); } - IEnumerator Leave(bool delete, Action fail) + IEnumerator Leave(Func request, string busy, Action fail) { while (Busy) yield return null; // 줄 선 요청을 먼저 다 보낸다 - ShowOverlay(delete ? "계정을 삭제하는 중…" : "로그아웃하는 중…", false); + ShowOverlay(busy, false); var r = new ServerResult(); - if (delete) yield return Client.DeleteAccount(r); - else yield return Client.Logout(r); + yield return request(r); + if (Client.Stop != null) yield return Stopped(); HideOverlay(); if (!r.ok) { @@ -445,6 +490,7 @@ namespace TKS.OutGame.Net } waitSince = -1f; HideOverlay(); + if (Client.Stop != null) yield return Stopped(); // 게임 중에 서버 점검이 시작됐다 · 이용이 제한됐다 — 안내 뒤 게임 종료(돌아오지 않는다) if (Client.LostReason != null) { yield return Kick(); // 다른 기기에서 접속했다 등 — 타이틀로 돌아간다 @@ -497,6 +543,7 @@ namespace TKS.OutGame.Net { var r = new ServerResult(); yield return Client.Send("GET", "/tks/account", null, true, r); + if (Client.Stop != null) yield return Stopped(); if (Client.LostReason != null) { yield return Kick(); @@ -535,10 +582,121 @@ namespace TKS.OutGame.Net while (!retryPressed) yield return null; } - /// 「다시 시도」 누름(화면 버튼 · 테스트). + /// 안내의 첫 버튼 누름(화면 버튼 · 테스트) — 「다시 시도」 · 「확인」 · 「종료」 · 스토어 이동 · 「탈퇴 취소」. public void PressRetry() { - retryPressed = true; + if (overlayAction != null) overlayAction(); + else retryPressed = true; + } + + /// 안내의 둘째 버튼 누름(화면 버튼 · 테스트) — 고르는 안내에서만 있다. + public void PressSecond() + { + if (overlayAction2 != null) overlayAction2(); + } + + // ---------- 접속 판정 안내 (업데이트 필요 · 서버 점검 · 이용 제한 · 탈퇴 신청 계정) ---------- + + /// 서버 시각 글자(ISO · UTC) → 이 기기의 시각 「yyyy-MM-dd HH:mm」. 비었거나 읽지 못하면 "". + public static string LocalTime(string iso) + { + DateTime t; + if (string.IsNullOrEmpty(iso) || !DateTime.TryParse(iso, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out t)) return ""; + return t.ToLocalTime().ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture); + } + + /// 줄 선 요청을 버리고(알림) 더 진행하지 않는 상태로 둔다 — 게임을 계속할 수 없는 안내를 띄우기 전에. + void Halt(string why) + { + var dropped = queue.ToArray(); + queue.Clear(); + sending = false; + waitSince = -1f; + Ready = false; + Halted = true; + LastError = why; + Debug.LogWarning("[TKS] " + why); + LoginPanel.Close(); + var lost = new ServerResult { ok = false, status = 0, error = why }; + foreach (var d in dropped) + if (d.onReject != null) d.onReject(lost); + } + + /// + /// 업데이트 필요 — 앱 버전이 서버의 타겟 버전보다 낮다. 「새로운 업데이트를 진행하세요」 + 스토어 바로가기(안드로이드 = 구글 플레이 스토어 · iOS = 애플 앱스토어). + /// 에디터 등 그 밖의 플랫폼에서는 두 스토어 버튼을 모두 보여 준다(확인용). 더 진행하지 않는다. + /// + IEnumerator UpdateRequired(ServerResult r) + { + Halt("업데이트 필요: 앱 버전 " + Application.version + " < 타겟 버전 " + r.Str("version")); + string android = r.Str("storeUrls.android"), ios = r.Str("storeUrls.ios"); + string msg = TextUpdate + "\n스토어에서 최신 버전으로 업데이트한 뒤 다시 실행해 주세요"; + if (Application.platform == RuntimePlatform.Android) ShowChoice(msg, "Play 스토어로 이동", () => ServerLink.OpenStore(android), null, null); + else if (Application.platform == RuntimePlatform.IPhonePlayer) ShowChoice(msg, "App Store로 이동", () => ServerLink.OpenStore(ios), null, null); + else ShowChoice(msg, "Play 스토어", () => ServerLink.OpenStore(android), "App Store", () => ServerLink.OpenStore(ios)); + while (true) yield return null; + } + + /// + /// 서버가 게임을 막았다 — 서버 점검(「서버 점검 중입니다.」 + 점검 시간 → 확인 = 게임 종료) 또는 + /// 이용 제한(「이용이 제한 된 계정입니다.」 + 제한이 끝나는 시각(정해졌을 때만) → 종료 버튼만). 접속할 때도, 게임 중에도 뜬다. 돌아오지 않는다. + /// + IEnumerator Stopped() + { + var stop = Client.Stop; + bool maintenance = stop.code == ServerClient.StopMaintenance; + Halt((maintenance ? "서버 점검" : "이용 제한") + ": " + stop.code); + string msg; + if (maintenance) + { + string from = LocalTime(stop.startAt), to = LocalTime(stop.endAt); + msg = TextMaintenance + + (from.Length > 0 || to.Length > 0 ? "\n점검 시간 " + from + " ~ " + to + "" : "") + + (string.IsNullOrEmpty(stop.message) ? "" : "\n" + stop.message + "") + + "\n확인을 누르면 게임이 종료됩니다"; + } + else + { + string until = LocalTime(stop.endAt); + msg = TextSuspended + (until.Length > 0 ? "\n제한 해제 " + until + "" : ""); + } + ShowChoice(msg, maintenance ? "확인" : "종료", ServerLink.Quit, null, null); + while (true) yield return null; + } + + /// + /// 탈퇴를 신청한 계정으로 로그인했다 — 삭제 예정 시각을 알리고 고르게 한다: 「탈퇴 취소」(계속 플레이) · 「다른 계정으로 로그인」(로그아웃). + /// done(true) = 취소하고 계속 · done(false) = 로그아웃했다(로그인 화면으로). + /// + IEnumerator AskWithdrawal(string deleteAt, Action done) + { + var res = new ServerResult(); + string note = ""; + while (true) + { + int pick = 0; + ShowChoice(TextWithdrawing + "\n" + LocalTime(deleteAt) + " 에 계정과 모든 데이터가 완전히 삭제됩니다.\n탈퇴를 취소하고 계속 플레이하시겠습니까?" + note, + "탈퇴 취소", () => pick = 1, "다른 계정으로 로그인", () => pick = 2); + while (pick == 0) yield return null; + if (pick == 1) + { + ShowOverlay("탈퇴를 취소하는 중…", false); + yield return Client.CancelWithdraw(res); + if (Client.Stop != null) yield return Stopped(); + if (res.ok) + { + done(true); + yield break; + } + note = "\n탈퇴를 취소하지 못했습니다 (" + (res.network ? "서버와 연결되지 않았습니다" : res.Message) + ")"; + continue; + } + ShowOverlay("로그아웃하는 중…", false); + yield return Client.Logout(res); + Client.Forget(); // 서버에 닿지 않았어도 기기의 증표는 지운다 — 로그인 화면으로 돌아간다 + done(false); + yield break; + } } /// @@ -555,14 +713,35 @@ namespace TKS.OutGame.Net void ShowOverlay(string msg, bool button, string buttonLabel = "다시 시도") { - if (button) EnsureInput(); + ShowChoice(msg, button ? buttonLabel : null, null, null, null); + } + + /// + /// 안내를 띄운다 — 버튼 0~2개. label1 = null 이면 버튼 없음 · action1 = null 이면 첫 버튼이 기다리는 쪽을 깨운다(「다시 시도」 · 「확인」). + /// 버튼이 하나면 가운데, 둘이면 나란히 놓는다. + /// + void ShowChoice(string msg, string label1, Action action1, string label2, Action action2) + { + if (label1 != null) EnsureInput(); if (overlay == null) BuildOverlay(); overlayText.text = msg; - overlayButton.SetActive(button); - if (overlayButtonLabel != null) overlayButtonLabel.text = buttonLabel; + overlayAction = action1; + overlayAction2 = action2; + bool two = label1 != null && label2 != null; + overlayButton.SetActive(label1 != null); + overlayButton2.SetActive(two); + if (label1 != null) overlayButtonLabel.text = label1; + if (two) overlayButtonLabel2.text = label2; + ((RectTransform)overlayButton.transform).anchoredPosition = new Vector2(two ? -ButtonGapX : 0f, ButtonY); + ((RectTransform)overlayButton2.transform).anchoredPosition = new Vector2(ButtonGapX, ButtonY); overlay.SetActive(true); } + // 안내 버튼 자리 · 크기 + const float ButtonY = -190f; + const float ButtonGapX = 215f; + static readonly Vector2 ButtonSize = new Vector2(400f, 110f); + void HideOverlay() { if (overlay != null) overlay.SetActive(false); @@ -582,21 +761,29 @@ namespace TKS.OutGame.Net img.raycastTarget = true; // 아래 화면 누름 막기 var center = new Vector2(0.5f, 0.5f); - overlayText = UiKit.Label(dim, "", 36, Color.white, TextAnchor.MiddleCenter, center, center, new Vector2(0f, 60f), new Vector2(900f, 260f)); + overlayText = UiKit.Label(dim, "", 36, Color.white, TextAnchor.MiddleCenter, center, center, new Vector2(0f, 60f), new Vector2(960f, 340f)); overlayText.supportRichText = true; + overlayText.horizontalOverflow = HorizontalWrapMode.Wrap; - var btn = new GameObject("Retry", typeof(RectTransform), typeof(Image), typeof(Button)); - btn.transform.SetParent(dim, false); + overlayButton = OverlayButton(dim, "Retry", UiKit.Red, PressRetry, out overlayButtonLabel); + overlayButton2 = OverlayButton(dim, "Second", UiKit.Dark, PressSecond, out overlayButtonLabel2); + overlayButton2.SetActive(false); + } + + static GameObject OverlayButton(Transform parent, string name, Color color, UnityEngine.Events.UnityAction onClick, out Text label) + { + var center = new Vector2(0.5f, 0.5f); + var btn = new GameObject(name, typeof(RectTransform), typeof(Image), typeof(Button)); + btn.transform.SetParent(parent, false); var rt = (RectTransform)btn.transform; rt.anchorMin = rt.anchorMax = rt.pivot = center; - rt.anchoredPosition = new Vector2(0f, -150f); - rt.sizeDelta = new Vector2(360f, 110f); - btn.GetComponent().color = UiKit.Red; - btn.GetComponent