서버 연결 — 접속 판정 안내(업데이트 · 서버 점검 · 이용 제한) · 소셜 계정 탈퇴 (PD 2026-11-17)
- PD 「버전이 맞지 않을 경우 "새로운 업데이트를 진행하세요" + 스토어 바로가기 · 서버 점검 중에는 "서버 점검 중입니다." + 점검 시간 · 확인 = 게임 즉시 종료 · 블랙리스트 = "이용이 제한 된 계정입니다." + 제한 시간 · 종료 버튼만(게임 중에도) · 소셜 계정은 계정 삭제가 아닌 계정 탈퇴(복구 불가 · 7일 후 완전 삭제 안내 · 7일 이내 취소)」 - 접속할 때 앱 버전을 실어 서버 상태를 묻고(?ver=) updateRequired 면 업데이트 안내 + 스토어 버튼(안드로이드 = 구글 플레이 스토어 · iOS = 애플 앱스토어 · 에디터는 둘 다)을 띄우고 멈춘다 - 서버가 503 SERVER_MAINTENANCE · 401 ACCOUNT_SUSPENDED 로 답하면(ServerClient.Stop) 접속할 때든 게임 중이든 점검 안내(점검 시간 · 확인 = 종료) · 이용 제한 안내(제한 해제 시각 · 종료 버튼뿐)를 띄운다 — 503 을 연결 문제(다시 시도)에서 뺐다 - 점검 중이어도 상태 조회에서 막지 않고 로그인까지 간다(점검 중 접속을 허용받은 계정인지는 로그인해야 알 수 있다) · 점검 「예정」 상태에서 게임이 막히던 것 고침 - 옵션(소셜 계정)에 「계정 탈퇴」 — 유예 일수(서버 값) 안내 → 신청하면 로그아웃 · 탈퇴를 신청한 계정으로 로그인하면 「탈퇴 취소 / 다른 계정으로 로그인」 - 안내 버튼 2개까지(ShowChoice) · 게임 종료/스토어 열기 = ServerLink.Quit · OpenStore · 테스트는 응답만 끼워 넣어 본다(ServerClient.Intercept) - 확인: 재컴파일 오류 0 · ServerLinkTests 22 통과 + 1 건너뜀(새 7건) · BootFlowTests 8 · TitleScreenTests 8 · 캡처 6장 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
2e363fda9c
commit
9892d05bd7
|
|
@ -7,7 +7,8 @@ namespace TKS.OutGame.Net
|
|||
{
|
||||
/// <summary>
|
||||
/// 옵션 팝업의 계정 칸 — 서버 모드에서만 열린다(로비 「옵션」 버튼).
|
||||
/// · 소셜 계정으로 로그인한 유저 = 「로그아웃」 → 타이틀의 로그인 화면으로.
|
||||
/// · 소셜 계정으로 로그인한 유저 = 「로그아웃」 → 타이틀의 로그인 화면으로 · 「계정 탈퇴」 → 복구할 수 없고 유예 일수(서버 값) 뒤 완전 삭제된다는 안내를 보고
|
||||
/// 신청한다(로그아웃됨 · 유예 안에 다시 로그인하면 취소할 수 있다).
|
||||
/// · 게스트 = 로그아웃 대신 「계정 삭제」(확인 문구 「계정 삭제」를 입력해야 한다 → 데이터 삭제 · 로그인 상태 초기화) + 「소셜 계정 연동」.
|
||||
/// · 연동하려는 소셜 계정이 이미 다른 게임 계정에 연동돼 있으면 「어느 계정으로 할지」 고르는 팝업(계정 요약 · 데이터가 사라질 수 있다는 안내).
|
||||
/// (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));
|
||||
}
|
||||
|
||||
/// <summary>계정 탈퇴 안내 글 — 복구할 수 없다 · 유예 일수 뒤 완전 삭제 · 그 안에 취소할 수 있다.</summary>
|
||||
public static string WithdrawNotice(int days)
|
||||
{
|
||||
return "계정을 탈퇴하면 복구할 수 없으며, " + days + "일 뒤 계정과 모든 데이터가 완전히 삭제됩니다. " + days + "일 안에 같은 소셜 계정으로 다시 로그인하면 언제든 탈퇴를 취소할 수 있습니다.";
|
||||
}
|
||||
|
||||
/// <summary>계정 탈퇴 확인(소셜 계정) — 안내를 보고 「탈퇴」를 눌러야 신청한다.</summary>
|
||||
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));
|
||||
}
|
||||
|
||||
/// <summary>계정 삭제 확인 — 유저가 「계정 삭제」를 입력해야 삭제 버튼이 통한다.</summary>
|
||||
public static void ConfirmDelete(OutGameRoot root, ServerSync sync)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -80,6 +80,19 @@ namespace TKS.OutGame.Net
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>서버가 게임을 막은 이유 — 서버 점검(시간 · 안내 글) 또는 이용 제한(끝나는 시각). 안내한 뒤 게임을 끝낸다.</summary>
|
||||
public class ServerStop
|
||||
{
|
||||
/// <summary>SERVER_MAINTENANCE · ACCOUNT_SUSPENDED</summary>
|
||||
public string code;
|
||||
/// <summary>점검 시작 시각(ISO · 없으면 "").</summary>
|
||||
public string startAt;
|
||||
/// <summary>점검이 끝나는 시각 · 이용 제한이 끝나는 시각(ISO · 없으면 "" = 이용 제한은 무기한).</summary>
|
||||
public string endAt;
|
||||
/// <summary>운영자가 적은 점검 안내 글(없으면 "").</summary>
|
||||
public string message;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 서버와 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";
|
||||
|
||||
/// <summary>세션을 잃은 이유(null = 정상) — 값이 있으면 다시 로그인해야 한다.</summary>
|
||||
public string LostReason { get; private set; }
|
||||
/// <summary>서버가 게임을 막았다(null = 정상) — 서버 점검 · 이용 제한. 값이 있으면 안내한 뒤 게임을 끝낸다.</summary>
|
||||
public ServerStop Stop { get; private set; }
|
||||
/// <summary>지금 세션의 로그인 방식(guest · google · apple).</summary>
|
||||
public string Method { get; private set; }
|
||||
|
||||
/// <summary>테스트 전용 — 정해 둔 응답.</summary>
|
||||
public class FakeResponse
|
||||
{
|
||||
public long status;
|
||||
public string json;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 테스트 전용 — (방식, 주소)를 받아 정해 둔 응답을 돌려주면 서버에 보내지 않고 그 응답을 쓴다(null = 실제로 보낸다).
|
||||
/// 서버 점검 · 업데이트 필요 · 이용 제한 화면을 서버 전체 설정을 건드리지 않고 확인하려는 것(ServerLink.ClearForce 가 비운다).
|
||||
/// </summary>
|
||||
public static Func<string, string, FakeResponse> Intercept;
|
||||
|
||||
// 기기에 저장하지 않는 모드(테스트)의 임시 보관 — 씬을 다시 열어도 남는다(ClearMemory 로 비운다)
|
||||
static readonly Dictionary<string, string> memory = new Dictionary<string, string>();
|
||||
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>응답을 결과로 정리한다 — 본문 해석 · 성공/연결 문제 구분 · 서버가 게임을 막았는지(점검 · 이용 제한).</summary>
|
||||
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 = "" };
|
||||
}
|
||||
|
||||
/// <summary>테스트용 자동 로그인 — 저장한 증표가 있으면 이어 하기 → 없거나 서버가 받지 않으면 새 게스트 계정(로그인 화면 없음).</summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 계정 탈퇴 신청(소셜 계정) — 서버가 유예 일수 뒤 완전 삭제를 예약하고 로그아웃시킨다. 기기의 증표를 지운다
|
||||
/// (마지막 로그인 방식은 남는다 — 유예 안에 그 계정으로 다시 로그인하면 탈퇴를 취소할 수 있다).
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>계정 탈퇴 취소 — 유예 기간 안에 다시 로그인한 유저가 고른다.</summary>
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -1302,12 +1302,39 @@ namespace TKS.OutGame.Net
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>게임 종료를 요청한 횟수(서버 점검 · 이용 제한 안내의 버튼) — 테스트가 본다.</summary>
|
||||
public static int Quits { get; private set; }
|
||||
/// <summary>마지막으로 연 스토어 주소(업데이트 안내의 버튼) — 테스트가 본다.</summary>
|
||||
public static string LastStoreUrl { get; private set; }
|
||||
|
||||
/// <summary>게임을 끝낸다(서버 점검 안내의 「확인」 · 이용 제한 안내의 「종료」). 테스트 모드에서는 세기만 한다.</summary>
|
||||
public static void Quit()
|
||||
{
|
||||
Quits++;
|
||||
if (ServerConfig.Forced) return;
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.isPlaying = false;
|
||||
#else
|
||||
Application.Quit();
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>스토어를 연다(업데이트 안내의 버튼). 테스트 모드에서는 주소만 적어 둔다.</summary>
|
||||
public static void OpenStore(string url)
|
||||
{
|
||||
LastStoreUrl = url;
|
||||
if (ServerConfig.Forced || string.IsNullOrEmpty(url)) return;
|
||||
Application.OpenURL(url);
|
||||
}
|
||||
|
||||
/// <summary>서버 연결 테스트 전용 — 씬을 열기 전에 부른다. 끝나면 ClearForce.</summary>
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -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) —
|
||||
/// 로그인 화면은 타이틀 위에 뜨고, 계정 상태는 게임 씬에서 받는다. 게임 씬을 바로 열면(개발 · 테스트) 전 과정을 그 씬에서 한다.
|
||||
/// </summary>
|
||||
|
|
@ -52,6 +56,21 @@ namespace TKS.OutGame.Net
|
|||
{
|
||||
get { return overlayText != null && Blocking ? overlayText.text : ""; }
|
||||
}
|
||||
/// <summary>안내의 첫 버튼 글(테스트 · 확인용 · 버튼이 없으면 "").</summary>
|
||||
public string OverlayButtonLabel
|
||||
{
|
||||
get { return Blocking && overlayButton != null && overlayButton.activeSelf && overlayButtonLabel != null ? overlayButtonLabel.text : ""; }
|
||||
}
|
||||
/// <summary>게임을 계속할 수 없다는 안내(업데이트 필요 · 서버 점검 · 이용 제한)가 떴는가 — 버튼은 스토어 이동 또는 종료뿐이다.</summary>
|
||||
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).
|
||||
/// </summary>
|
||||
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<size=26>확인을 누르면 타이틀 화면으로 돌아갑니다</size>", true, "확인");
|
||||
|
|
@ -349,22 +385,31 @@ namespace TKS.OutGame.Net
|
|||
/// <summary>로그아웃(소셜 계정) → 타이틀의 로그인 화면으로. 실패하면 fail(이유).</summary>
|
||||
public void Logout(Action<string> fail)
|
||||
{
|
||||
StartCoroutine(Leave(false, fail));
|
||||
StartCoroutine(Leave(Client.Logout, "로그아웃하는 중…", fail));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 계정 탈퇴 신청(소셜 계정) → 서버가 유예 일수 뒤 완전 삭제를 예약하고 로그아웃시킨다 → 타이틀의 로그인 화면으로.
|
||||
/// 유예 안에 같은 소셜 계정으로 다시 로그인하면 탈퇴를 취소할 수 있다.
|
||||
/// </summary>
|
||||
public void Withdraw(Action<string> fail)
|
||||
{
|
||||
StartCoroutine(Leave(Client.Withdraw, "계정 탈퇴를 신청하는 중…", fail));
|
||||
}
|
||||
|
||||
/// <summary>계정 삭제(게스트) → 서버가 데이터를 지우고, 기기의 로그인 상태를 초기화한 뒤 타이틀의 로그인 화면으로.</summary>
|
||||
public void DeleteAccount(Action<string> fail)
|
||||
{
|
||||
StartCoroutine(Leave(true, fail));
|
||||
StartCoroutine(Leave(Client.DeleteAccount, "계정을 삭제하는 중…", fail));
|
||||
}
|
||||
|
||||
IEnumerator Leave(bool delete, Action<string> fail)
|
||||
IEnumerator Leave(Func<ServerResult, IEnumerator> request, string busy, Action<string> 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;
|
||||
}
|
||||
|
||||
/// <summary>「다시 시도」 누름(화면 버튼 · 테스트).</summary>
|
||||
/// <summary>안내의 첫 버튼 누름(화면 버튼 · 테스트) — 「다시 시도」 · 「확인」 · 「종료」 · 스토어 이동 · 「탈퇴 취소」.</summary>
|
||||
public void PressRetry()
|
||||
{
|
||||
retryPressed = true;
|
||||
if (overlayAction != null) overlayAction();
|
||||
else retryPressed = true;
|
||||
}
|
||||
|
||||
/// <summary>안내의 둘째 버튼 누름(화면 버튼 · 테스트) — 고르는 안내에서만 있다.</summary>
|
||||
public void PressSecond()
|
||||
{
|
||||
if (overlayAction2 != null) overlayAction2();
|
||||
}
|
||||
|
||||
// ---------- 접속 판정 안내 (업데이트 필요 · 서버 점검 · 이용 제한 · 탈퇴 신청 계정) ----------
|
||||
|
||||
/// <summary>서버 시각 글자(ISO · UTC) → 이 기기의 시각 「yyyy-MM-dd HH:mm」. 비었거나 읽지 못하면 "".</summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>줄 선 요청을 버리고(알림) 더 진행하지 않는 상태로 둔다 — 게임을 계속할 수 없는 안내를 띄우기 전에.</summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 업데이트 필요 — 앱 버전이 서버의 타겟 버전보다 낮다. 「새로운 업데이트를 진행하세요」 + 스토어 바로가기(안드로이드 = 구글 플레이 스토어 · iOS = 애플 앱스토어).
|
||||
/// 에디터 등 그 밖의 플랫폼에서는 두 스토어 버튼을 모두 보여 준다(확인용). 더 진행하지 않는다.
|
||||
/// </summary>
|
||||
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<size=26>스토어에서 최신 버전으로 업데이트한 뒤 다시 실행해 주세요</size>";
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 서버가 게임을 막았다 — 서버 점검(「서버 점검 중입니다.」 + 점검 시간 → 확인 = 게임 종료) 또는
|
||||
/// 이용 제한(「이용이 제한 된 계정입니다.」 + 제한이 끝나는 시각(정해졌을 때만) → 종료 버튼만). 접속할 때도, 게임 중에도 뜬다. 돌아오지 않는다.
|
||||
/// </summary>
|
||||
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<size=28>점검 시간 " + from + " ~ " + to + "</size>" : "")
|
||||
+ (string.IsNullOrEmpty(stop.message) ? "" : "\n<size=26>" + stop.message + "</size>")
|
||||
+ "\n<size=24>확인을 누르면 게임이 종료됩니다</size>";
|
||||
}
|
||||
else
|
||||
{
|
||||
string until = LocalTime(stop.endAt);
|
||||
msg = TextSuspended + (until.Length > 0 ? "\n<size=28>제한 해제 " + until + "</size>" : "");
|
||||
}
|
||||
ShowChoice(msg, maintenance ? "확인" : "종료", ServerLink.Quit, null, null);
|
||||
while (true) yield return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 탈퇴를 신청한 계정으로 로그인했다 — 삭제 예정 시각을 알리고 고르게 한다: 「탈퇴 취소」(계속 플레이) · 「다른 계정으로 로그인」(로그아웃).
|
||||
/// done(true) = 취소하고 계속 · done(false) = 로그아웃했다(로그인 화면으로).
|
||||
/// </summary>
|
||||
IEnumerator AskWithdrawal(string deleteAt, Action<bool> done)
|
||||
{
|
||||
var res = new ServerResult();
|
||||
string note = "";
|
||||
while (true)
|
||||
{
|
||||
int pick = 0;
|
||||
ShowChoice(TextWithdrawing + "\n<size=28>" + LocalTime(deleteAt) + " 에 계정과 모든 데이터가 완전히 삭제됩니다.\n탈퇴를 취소하고 계속 플레이하시겠습니까?</size>" + 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<size=24><color=#ff9090>탈퇴를 취소하지 못했습니다 (" + (res.network ? "서버와 연결되지 않았습니다" : res.Message) + ")</color></size>";
|
||||
continue;
|
||||
}
|
||||
ShowOverlay("로그아웃하는 중…", false);
|
||||
yield return Client.Logout(res);
|
||||
Client.Forget(); // 서버에 닿지 않았어도 기기의 증표는 지운다 — 로그인 화면으로 돌아간다
|
||||
done(false);
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 안내를 띄운다 — 버튼 0~2개. label1 = null 이면 버튼 없음 · action1 = null 이면 첫 버튼이 기다리는 쪽을 깨운다(「다시 시도」 · 「확인」).
|
||||
/// 버튼이 하나면 가운데, 둘이면 나란히 놓는다.
|
||||
/// </summary>
|
||||
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<Image>().color = UiKit.Red;
|
||||
btn.GetComponent<Button>().onClick.AddListener(PressRetry);
|
||||
var label = UiKit.Label(rt, "다시 시도", 36, Color.white, TextAnchor.MiddleCenter, center, center, Vector2.zero, rt.sizeDelta);
|
||||
rt.anchoredPosition = new Vector2(0f, ButtonY);
|
||||
rt.sizeDelta = ButtonSize;
|
||||
btn.GetComponent<Image>().color = color;
|
||||
btn.GetComponent<Button>().onClick.AddListener(onClick);
|
||||
label = UiKit.Label(rt, "", 34, Color.white, TextAnchor.MiddleCenter, center, center, Vector2.zero, rt.sizeDelta);
|
||||
label.raycastTarget = false;
|
||||
overlayButtonLabel = label;
|
||||
overlayButton = btn;
|
||||
return btn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -970,6 +970,235 @@ namespace TKS.Tests
|
|||
Assert.AreEqual(a.Str("userId"), b.Str("userId"), "다시 로그인하면 그 계정 그대로");
|
||||
}
|
||||
|
||||
// ---------- 접속 판정 화면 (업데이트 필요 · 서버 점검 · 이용 제한 · 계정 탈퇴) ----------
|
||||
// 서버 전체 설정(점검 시간 · 타겟 버전 · 계정 정지)을 실제로 바꾸면 같은 서버를 쓰는 다른 실행이 막힌다 →
|
||||
// 그 응답만 끼워 넣어(ServerClient.Intercept) 게임의 안내와 흐름을 본다. 서버가 실제로 그렇게 답하는지는 서버 저장소의 smoke:gate 가 본다.
|
||||
|
||||
static ServerClient.FakeResponse Fake(long status, string json)
|
||||
{
|
||||
return new ServerClient.FakeResponse { status = status, json = json };
|
||||
}
|
||||
|
||||
/// <summary>게임 씬을 연다(접속이 끝나기를 기다리지 않는다 — 접속 중에 뜨는 안내를 보려고).</summary>
|
||||
IEnumerator Open()
|
||||
{
|
||||
WorldProgress.Reset();
|
||||
SaveStore.UseMemory(true);
|
||||
ServerLink.ForceForTest(TestUrl(), ServerConfig.GameId);
|
||||
SceneManager.LoadScene("Battle");
|
||||
yield return null;
|
||||
yield return null;
|
||||
og = OutGameRoot.Instance;
|
||||
sync = ServerSync.Instance;
|
||||
Assert.IsNotNull(sync, "서버 모드 세션");
|
||||
}
|
||||
|
||||
// 끼워 넣는 응답의 점검 시간(서버가 주는 형식 = ISO · UTC)
|
||||
const string MaintStart = "2026-11-17T09:00:00.000Z";
|
||||
const string MaintEnd = "2026-11-17T11:00:00.000Z";
|
||||
|
||||
static string StatusBody(string status)
|
||||
{
|
||||
return "{\"status\":\"" + status + "\",\"maintenanceStartAt\":\"" + MaintStart + "\",\"maintenanceEndAt\":\"" + MaintEnd + "\",\"version\":\"0.1.0\",\"updateRequired\":false}";
|
||||
}
|
||||
|
||||
static string MaintenanceBody()
|
||||
{
|
||||
return "{\"statusCode\":503,\"message\":\"SERVER_MAINTENANCE\",\"maintenanceStartAt\":\"" + MaintStart + "\",\"maintenanceEndAt\":\"" + MaintEnd + "\",\"maintenanceMessage\":\"정기 점검\"}";
|
||||
}
|
||||
|
||||
static string SuspendedBody(string endAt)
|
||||
{
|
||||
return "{\"statusCode\":401,\"message\":\"ACCOUNT_SUSPENDED\",\"accountStatus\":\"suspended\",\"suspensionReason\":\"점검용\",\"suspendedAt\":\"2026-11-17T03:00:00.000Z\",\"suspensionEndAt\":\"" + endAt + "\"}";
|
||||
}
|
||||
|
||||
/// <summary>버전 체크 — 앱 버전이 서버의 타겟 버전보다 낮으면 「새로운 업데이트를 진행하세요」 안내와 스토어 바로가기(구글 플레이 스토어 · 애플 앱스토어)가 뜨고 더 진행하지 않는다.</summary>
|
||||
[UnityTest]
|
||||
public IEnumerator Update_VersionTooLow_ShowsNoticeAndStoreButtons()
|
||||
{
|
||||
string asked = null;
|
||||
ServerClient.Intercept = (m, p) =>
|
||||
{
|
||||
if (!p.Contains("/status")) return null;
|
||||
asked = p;
|
||||
return Fake(200, "{\"status\":\"NORMAL\",\"version\":\"99.0.0\",\"updateRequired\":true,\"storeUrls\":{\"android\":\"https://play.example/tks\",\"ios\":\"https://apps.example/tks\"}}");
|
||||
};
|
||||
yield return Open();
|
||||
yield return Until(() => sync.Halted || sync.Ready, 20f, "업데이트 안내");
|
||||
Assert.IsTrue(sync.Halted, "업데이트가 필요하면 더 진행하지 않는다");
|
||||
Assert.IsFalse(sync.Ready);
|
||||
StringAssert.Contains("ver=" + Uri.EscapeDataString(Application.version), asked, "접속할 때 앱 버전을 실어 보낸다");
|
||||
StringAssert.Contains(ServerSync.TextUpdate, sync.OverlayMessage);
|
||||
Assert.IsNull(LoginPanel.Current, "로그인 화면으로 가지 않는다");
|
||||
yield return CaptureUtil.Capture(Camera.main, 720, 1280, System.IO.Path.Combine("Temp", "tks_update_required.png"));
|
||||
sync.PressRetry();
|
||||
Assert.AreEqual("https://play.example/tks", ServerLink.LastStoreUrl, "첫 버튼 = 구글 플레이 스토어 바로가기");
|
||||
sync.PressSecond();
|
||||
Assert.AreEqual("https://apps.example/tks", ServerLink.LastStoreUrl, "둘째 버튼 = 애플 앱스토어 바로가기(에디터는 두 스토어를 모두 보여 준다)");
|
||||
Assert.IsTrue(sync.Halted && sync.Blocking, "스토어에 다녀와도 안내는 그대로");
|
||||
Assert.AreEqual(0, ServerLink.Quits);
|
||||
}
|
||||
|
||||
/// <summary>서버 점검 — 점검 중 접속을 허용받지 않은 계정은 「서버 점검 중입니다.」 안내와 점검 시간을 보고, 확인을 누르면 게임이 끝난다.</summary>
|
||||
[UnityTest]
|
||||
public IEnumerator Maintenance_NotAllowed_ShowsTimeAndOkQuits()
|
||||
{
|
||||
ServerClient.Intercept = (m, p) => p.Contains("/status") ? Fake(200, StatusBody("MAINTENANCE")) : p.StartsWith("/auth/") ? Fake(503, MaintenanceBody()) : null;
|
||||
yield return Open();
|
||||
yield return Until(() => sync.Halted || sync.Ready, 20f, "점검 안내");
|
||||
Assert.IsTrue(sync.Halted, "점검 중에는 들어가지 못한다");
|
||||
Assert.IsFalse(sync.Ready);
|
||||
StringAssert.Contains(ServerSync.TextMaintenance, sync.OverlayMessage);
|
||||
StringAssert.Contains(ServerSync.LocalTime(MaintStart) + " ~ " + ServerSync.LocalTime(MaintEnd), sync.OverlayMessage, "점검 시간(이 기기의 시각으로)");
|
||||
StringAssert.Contains("정기 점검", sync.OverlayMessage, "운영자가 적은 점검 안내 글");
|
||||
Assert.AreEqual("확인", sync.OverlayButtonLabel);
|
||||
yield return CaptureUtil.Capture(Camera.main, 720, 1280, System.IO.Path.Combine("Temp", "tks_maintenance.png"));
|
||||
Assert.AreEqual(0, ServerLink.Quits);
|
||||
sync.PressRetry();
|
||||
Assert.AreEqual(1, ServerLink.Quits, "확인 = 게임 종료");
|
||||
}
|
||||
|
||||
/// <summary>서버 점검 중이어도 서버가 로그인을 받아 주는 계정(화이트리스트)은 그대로 게임에 들어간다.</summary>
|
||||
[UnityTest]
|
||||
public IEnumerator Maintenance_AllowedAccount_EntersGame()
|
||||
{
|
||||
ServerClient.Intercept = (m, p) => p.Contains("/status") ? Fake(200, StatusBody("MAINTENANCE")) : null;
|
||||
yield return Open();
|
||||
yield return Until(() => sync.Ready || sync.Halted || sync.LastError != null, 30f, "접속");
|
||||
Assert.IsTrue(sync.Ready, "점검 중 접속을 허용받은 계정은 들어간다: " + sync.LastError);
|
||||
Assert.IsFalse(sync.Halted);
|
||||
Assert.AreEqual(0, ServerLink.Quits);
|
||||
}
|
||||
|
||||
/// <summary>게임 중에 서버 점검이 시작되면 다음 요청에서 바로 점검 안내가 뜨고, 확인을 누르면 게임이 끝난다.</summary>
|
||||
[UnityTest]
|
||||
public IEnumerator Maintenance_StartsWhilePlaying_NoticeThenQuit()
|
||||
{
|
||||
yield return Boot();
|
||||
ServerClient.Intercept = (m, p) => p.StartsWith("/tks/") ? Fake(503, MaintenanceBody()) : null;
|
||||
og.Session.ReportStep("tutorial_end"); // 이 기기가 아무 요청이나 보내는 순간
|
||||
yield return Until(() => sync.Halted, 15f, "게임 중 점검 안내");
|
||||
StringAssert.Contains(ServerSync.TextMaintenance, sync.OverlayMessage);
|
||||
StringAssert.Contains(ServerSync.LocalTime(MaintEnd), sync.OverlayMessage);
|
||||
Assert.IsFalse(sync.Ready);
|
||||
Assert.IsFalse(sync.Kicked, "타이틀로 돌려보내는 안내가 아니다");
|
||||
sync.PressRetry();
|
||||
Assert.AreEqual(1, ServerLink.Quits, "확인 = 게임 종료");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 블랙리스트 — 게임 중이라도 서버에서 이용이 제한되면 다음 요청에서 바로 「이용이 제한 된 계정입니다.」 안내(제한이 끝나는 시각 포함)가 뜨고, 종료 버튼만 누를 수 있다.
|
||||
/// </summary>
|
||||
[UnityTest]
|
||||
public IEnumerator Blacklist_WhilePlaying_ShowsLimitTimeAndQuitOnly()
|
||||
{
|
||||
yield return Boot();
|
||||
const string until = "2026-11-19T03:00:00.000Z";
|
||||
ServerClient.Intercept = (m, p) => p.StartsWith("/tks/") ? Fake(401, SuspendedBody(until)) : null;
|
||||
og.Session.ReportStep("tutorial_end");
|
||||
yield return Until(() => sync.Halted, 15f, "이용 제한 안내");
|
||||
StringAssert.Contains(ServerSync.TextSuspended, sync.OverlayMessage);
|
||||
StringAssert.Contains(ServerSync.LocalTime(until), sync.OverlayMessage, "제한이 끝나는 시각");
|
||||
Assert.AreEqual("종료", sync.OverlayButtonLabel);
|
||||
Assert.IsFalse(sync.Kicked, "「다른 기기에서 접속」 안내가 아니다");
|
||||
Assert.IsNull(LoginPanel.Current, "로그인 화면으로 보내지 않는다");
|
||||
yield return CaptureUtil.Capture(Camera.main, 720, 1280, System.IO.Path.Combine("Temp", "tks_account_limited.png"));
|
||||
sync.PressSecond();
|
||||
Assert.AreEqual(0, ServerLink.Quits, "둘째 버튼은 없다(종료 버튼만)");
|
||||
sync.PressRetry();
|
||||
Assert.AreEqual(1, ServerLink.Quits, "종료 = 게임 종료");
|
||||
}
|
||||
|
||||
/// <summary>블랙리스트 — 접속할 때 이용이 제한된 계정이면 로그인 화면이 아니라 제한 안내가 뜬다. 끝나는 시각이 없으면(무기한) 시각을 적지 않는다.</summary>
|
||||
[UnityTest]
|
||||
public IEnumerator Blacklist_AtLogin_NoEndTime_ShowsLimitOnly()
|
||||
{
|
||||
ServerClient.Intercept = (m, p) => p.StartsWith("/auth/") ? Fake(401, SuspendedBody("")) : null;
|
||||
yield return Open();
|
||||
yield return Until(() => sync.Halted || sync.Ready, 20f, "이용 제한 안내");
|
||||
Assert.IsTrue(sync.Halted);
|
||||
StringAssert.Contains(ServerSync.TextSuspended, sync.OverlayMessage);
|
||||
StringAssert.DoesNotContain("제한 해제", sync.OverlayMessage, "제한 시간이 없으면 시각을 적지 않는다");
|
||||
Assert.AreEqual("종료", sync.OverlayButtonLabel);
|
||||
sync.PressRetry();
|
||||
Assert.AreEqual(1, ServerLink.Quits);
|
||||
}
|
||||
|
||||
/// <summary>(탈퇴를 신청해 다시 열린 씬에서) 로그인 화면에서 그 소셜 계정으로 로그인 → 「탈퇴 취소」를 묻는 안내가 뜨기를 기다린다.</summary>
|
||||
IEnumerator WithdrawPrompt(string devId)
|
||||
{
|
||||
yield return Until(() => ServerSync.Instance != null && OutGameRoot.Instance != null, 10f, "씬 열림");
|
||||
og = OutGameRoot.Instance;
|
||||
sync = ServerSync.Instance;
|
||||
yield return Until(() => LoginPanel.Current != null || sync.Ready || sync.LastError != null, 20f, "로그인 화면");
|
||||
Assert.IsNotNull(LoginPanel.Current, "탈퇴를 신청하면 로그아웃된다(로그인 화면): " + sync.LastError);
|
||||
LoginPanel.Current.Choose(SocialSignIn.Google, devId);
|
||||
yield return Until(() => sync.OverlayMessage.Contains(ServerSync.TextWithdrawing) || sync.Ready || sync.LastError != null, 30f, "탈퇴 취소 안내");
|
||||
StringAssert.Contains(ServerSync.TextWithdrawing, sync.OverlayMessage, "탈퇴를 신청한 계정으로 로그인하면 취소할지 묻는다: " + sync.LastError);
|
||||
Assert.IsFalse(sync.Ready, "취소 전에는 게임에 들어가지 않는다");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 소셜 계정 = 계정 삭제 대신 「계정 탈퇴」 — 복구할 수 없고 유예 일수(서버 값) 뒤 완전 삭제된다는 안내를 보고 신청하면 로그아웃된다.
|
||||
/// 유예 안에 같은 소셜 계정으로 로그인하면 「탈퇴 취소」로 그 계정 그대로 계속하거나, 「다른 계정으로 로그인」으로 로그인 화면에 돌아간다.
|
||||
/// </summary>
|
||||
[UnityTest]
|
||||
public IEnumerator Social_Withdraw_NoticeThenCancelWithinGrace()
|
||||
{
|
||||
string id = NewSocialId("uw");
|
||||
yield return BootWithLogin(SocialSignIn.Google, id);
|
||||
var a = new ServerResult();
|
||||
yield return Who(a);
|
||||
int days = (int)a.Num("withdrawGraceDays");
|
||||
if (days <= 0) Assert.Ignore("서버가 계정 탈퇴를 받지 않는다 — 새 서버 빌드가 아니거나 data/server/service_config.csv 에 withdraw_grace_days 가 없다");
|
||||
|
||||
// 옵션 팝업 = 소셜 계정은 「로그아웃」 + 「계정 탈퇴」(계정 삭제는 없다)
|
||||
AccountPanel.Open(og);
|
||||
yield return Until(() => GameObject.Find("Withdraw") != null, 10f, "옵션 팝업의 계정 탈퇴 버튼");
|
||||
Assert.IsNotNull(GameObject.Find("Logout"));
|
||||
Assert.IsNull(GameObject.Find("Delete"), "소셜 계정에는 계정 삭제를 주지 않는다");
|
||||
string notice = AccountPanel.WithdrawNotice(days);
|
||||
StringAssert.Contains("복구할 수 없", notice);
|
||||
StringAssert.Contains(days + "일 뒤", notice, "유예 일수 = 서버 값");
|
||||
StringAssert.Contains("취소", notice);
|
||||
yield return CaptureUtil.Capture(Camera.main, 720, 1280, System.IO.Path.Combine("Temp", "tks_option_social_withdraw.png"));
|
||||
AccountPanel.ConfirmWithdraw(og, sync, days);
|
||||
yield return null;
|
||||
yield return CaptureUtil.Capture(Camera.main, 720, 1280, System.IO.Path.Combine("Temp", "tks_withdraw_confirm.png"));
|
||||
og.CloseModal();
|
||||
|
||||
// 탈퇴 신청 → 로그아웃 → 같은 계정으로 로그인하면 취소할지 묻는다 → 「탈퇴 취소」
|
||||
var old = sync;
|
||||
string fail = null;
|
||||
sync.Withdraw(why => fail = why);
|
||||
yield return Reopened(old);
|
||||
Assert.IsNull(fail, "계정 탈퇴: " + fail);
|
||||
yield return WithdrawPrompt(id);
|
||||
Assert.AreEqual("탈퇴 취소", sync.OverlayButtonLabel);
|
||||
yield return CaptureUtil.Capture(Camera.main, 720, 1280, System.IO.Path.Combine("Temp", "tks_withdraw_cancel_prompt.png"));
|
||||
sync.PressRetry();
|
||||
yield return Until(() => sync.Ready || sync.LastError != null, 30f, "탈퇴 취소 뒤 접속");
|
||||
Assert.IsTrue(sync.Ready, "탈퇴를 취소하면 그대로 들어간다: " + sync.LastError);
|
||||
var b = new ServerResult();
|
||||
yield return Who(b);
|
||||
Assert.AreEqual(a.Str("userId"), b.Str("userId"), "취소하면 그 계정 그대로");
|
||||
var acc = new ServerResult();
|
||||
yield return Account(acc);
|
||||
|
||||
// 다시 신청 → 로그인 → 「다른 계정으로 로그인」 = 로그인 화면으로
|
||||
old = sync;
|
||||
sync.Withdraw(why => fail = why);
|
||||
yield return Reopened(old);
|
||||
yield return WithdrawPrompt(id);
|
||||
sync.PressSecond();
|
||||
yield return Until(() => LoginPanel.Current != null, 20f, "다른 계정으로 로그인 = 로그인 화면");
|
||||
Assert.IsFalse(sync.Client.HasSaved, "탈퇴 중인 계정의 증표는 기기에 남지 않는다");
|
||||
yield return Login(ServerClient.MethodGuest, null);
|
||||
var c = new ServerResult();
|
||||
yield return Who(c);
|
||||
Assert.AreNotEqual(a.Str("userId"), c.Str("userId"), "다른 계정으로 플레이한다");
|
||||
}
|
||||
|
||||
static long DeviceOffsetMin()
|
||||
{
|
||||
return (long)Math.Round(TimeZoneInfo.Local.GetUtcOffset(DateTime.Now).TotalMinutes);
|
||||
|
|
|
|||
Loading…
Reference in New Issue