75 lines
2.3 KiB
C#
75 lines
2.3 KiB
C#
using System;
|
||
using System.Threading;
|
||
using game.Account;
|
||
using UnityEditor;
|
||
using UnityEngine;
|
||
|
||
public sealed class S101LoginWindow : EditorWindow
|
||
{
|
||
string playerId = "101";
|
||
string status = "输入涂游测试 ID,验证 s101 认证及 Cookie。";
|
||
bool busy;
|
||
S101AccountSession session;
|
||
CancellationTokenSource cancellation;
|
||
|
||
[MenuItem("Tools/Debug/S101 Minimal Login")]
|
||
static void Open() => GetWindow<S101LoginWindow>("S101 最小登录");
|
||
|
||
void OnGUI()
|
||
{
|
||
EditorGUILayout.LabelField("API", S101AccountSession.DefaultApiUrl);
|
||
using (new EditorGUI.DisabledScope(busy))
|
||
{
|
||
playerId = EditorGUILayout.TextField("涂游测试 ID", playerId);
|
||
if (GUILayout.Button("登录并验证 Cookie")) Login();
|
||
}
|
||
EditorGUILayout.HelpBox(status, MessageType.Info);
|
||
EditorGUILayout.LabelField("此入口只验证认证,不初始化玩法或写入存档。");
|
||
}
|
||
|
||
async void Login()
|
||
{
|
||
busy = true;
|
||
session?.Dispose();
|
||
cancellation?.Dispose();
|
||
cancellation = new CancellationTokenSource();
|
||
var attempt = new S101AccountSession();
|
||
session = attempt;
|
||
var token = cancellation.Token;
|
||
status = "正在登录…";
|
||
try
|
||
{
|
||
var login = await attempt.LoginAsync(playerId, token);
|
||
if (token.IsCancellationRequested) return;
|
||
if (!login.Success)
|
||
{
|
||
status = $"登录失败:{login.Error},HTTP {login.StatusCode}";
|
||
return;
|
||
}
|
||
var probe = await attempt.CheckAuthorizationAsync(token);
|
||
if (token.IsCancellationRequested) return;
|
||
status = probe.Success
|
||
? $"认证通过:涂游 ID {attempt.PlayerId},内部 ID {attempt.InternalId};Cookie 授权读取通过。"
|
||
: $"登录成功,但授权读取未通过:{probe.Error},HTTP {probe.StatusCode}";
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
status = "验证异常:" + ex.GetType().Name;
|
||
}
|
||
finally
|
||
{
|
||
busy = false;
|
||
if (this != null) Repaint();
|
||
}
|
||
}
|
||
|
||
void OnDisable()
|
||
{
|
||
cancellation?.Cancel();
|
||
session?.Dispose();
|
||
cancellation?.Dispose();
|
||
cancellation = null;
|
||
session = null;
|
||
}
|
||
}
|