1
This commit is contained in:
@@ -450,7 +450,7 @@ namespace Assets.MyGame.Scripts.Net
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LoginHub LevelChangedNEW — 后台修改玩家等级
|
||||
/// LoginHub LevelChanged — 后台修改玩家等级
|
||||
/// 直接调用 GetUser 刷新用户数据,触发 OnUserDataChanged 同步 UI
|
||||
/// </summary>
|
||||
public static void LevelChanged(string msg)
|
||||
@@ -461,10 +461,136 @@ namespace Assets.MyGame.Scripts.Net
|
||||
APIRequestList.GetUser(userId, a => GameManager.Instance.UpdataUserData(a));
|
||||
}
|
||||
|
||||
// ---------------- LoginHub 断线房间 ----------------
|
||||
|
||||
/// <summary>当前是否有待处理的断线房间弹窗(防止重复弹)</summary>
|
||||
private static bool _pendingRoomActive;
|
||||
|
||||
/// <summary>
|
||||
/// LoginHub PendingRoomNotice — 登录后检测到有未完成的断线游戏
|
||||
/// 弹窗提示用户选择"返回房间"(调 Reconnect)或"离开"(调 DismissPendingRoom)
|
||||
/// 60 秒无操作自动离开
|
||||
/// </summary>
|
||||
public static void PendingRoomNotice(string msg)
|
||||
{
|
||||
if (_pendingRoomActive) return; // 防重复
|
||||
var data = JsonConvert.DeserializeObject<WebSocketResponseBase<PendingRoomData>>(msg).arguments[0];
|
||||
if (data == null) return;
|
||||
|
||||
_pendingRoomActive = true;
|
||||
var userId = GameManager.Instance?.user?.id;
|
||||
if (string.IsNullOrEmpty(userId)) return;
|
||||
|
||||
// 创建 TiShi 弹窗(直接 Instantiate 拿引用,方便 60 秒后销毁)
|
||||
var prefab = UIManager.Instance.TiShiParefab;
|
||||
if (prefab == null)
|
||||
{
|
||||
Debug.LogWarning("[PendingRoomNotice] TiShiParefab 未赋值,自动离开");
|
||||
WebSocketSendList.DismissPendingRoom(userId);
|
||||
_pendingRoomActive = false;
|
||||
return;
|
||||
}
|
||||
var obj = UnityEngine.Object.Instantiate(prefab, UIManager.Instance.uiRoot);
|
||||
obj.transform.SetAsLastSibling();
|
||||
var tishi = obj.GetComponent<TiShi>();
|
||||
if (tishi == null)
|
||||
{
|
||||
UnityEngine.Object.Destroy(obj);
|
||||
_pendingRoomActive = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// 标记用户是否已操作
|
||||
bool acted = false;
|
||||
|
||||
// 确认 = 返回房间
|
||||
tishi.Init($"检测到您在 {data.gameType} {data.roomName} 有未完成的游戏,是否返回房间?", () =>
|
||||
{
|
||||
acted = true;
|
||||
WebSocketSendList.Reconnect(userId);
|
||||
});
|
||||
|
||||
// 关闭 = 离开(额外给 btn_Close 加监听;TiShi.Close 本身只销毁不触发 action)
|
||||
if (tishi.btn_Close != null)
|
||||
{
|
||||
tishi.btn_Close.onClick.AddListener(() =>
|
||||
{
|
||||
if (acted) return;
|
||||
acted = true;
|
||||
WebSocketSendList.DismissPendingRoom(userId);
|
||||
});
|
||||
}
|
||||
|
||||
// 60 秒无操作自动离开
|
||||
WebSocketManager.Instance.StartCoroutine(PendingRoomCountdown(
|
||||
60f, () => acted, () =>
|
||||
{
|
||||
acted = true;
|
||||
WebSocketSendList.DismissPendingRoom(userId);
|
||||
if (obj != null) UnityEngine.Object.Destroy(obj);
|
||||
_pendingRoomActive = false;
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>断线房间弹窗倒计时协程(到时检查是否已操作,未操作则触发回调)</summary>
|
||||
private static System.Collections.IEnumerator PendingRoomCountdown(
|
||||
float seconds, System.Func<bool> hasActed, System.Action onTimeout)
|
||||
{
|
||||
yield return new UnityEngine.WaitForSeconds(seconds);
|
||||
if (!hasActed())
|
||||
onTimeout?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LoginHub PendingRoomNotice 数据
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class PendingRoomData
|
||||
{
|
||||
public string roomId;
|
||||
public string gameType;
|
||||
public string roomName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LoginHub AccountKicked — 账号被顶通知
|
||||
/// 该账号在其他设备登录时,旧连接收到此事件。
|
||||
/// 前端应提示"账号已在其他地方登录"并清空房间 UI、断开游戏连接。
|
||||
/// </summary>
|
||||
public static void AccountKicked(string msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = JsonConvert.DeserializeObject<WebSocketResponseBase<AccountKickedData>>(msg).arguments[0];
|
||||
var userId = GameManager.Instance?.user?.id;
|
||||
// 只处理当前登录用户被顶的情况
|
||||
if (data != null && !string.IsNullOrEmpty(data.userId)
|
||||
&& !string.IsNullOrEmpty(userId) && data.userId != userId)
|
||||
return;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogWarning("[AccountKicked] 解析失败: " + e.Message);
|
||||
}
|
||||
|
||||
// 提示并登出(Logout 已封装:CloseAll WebSocket + 清空用户 + 关闭所有 UI + 回登录界面)
|
||||
UIManager.Instance.ShowBoardError("账号已在其他地方登录");
|
||||
GameManager.Instance.Logout();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LoginHub AccountKicked 数据
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class AccountKickedData
|
||||
{
|
||||
public string userId;
|
||||
}
|
||||
|
||||
// ---------------- FishGameHub 补充 ----------------
|
||||
|
||||
/// <summary>
|
||||
/// FishGameHub BotLeaveRoomNoticeNEW — 机器人退出房间
|
||||
/// FishGameHub BotLeaveRoomNotice — 机器人退出房间
|
||||
/// 仅触发对应座位显示等待,不影响本地玩家(自己退出走 LeaveRoomResult)
|
||||
/// </summary>
|
||||
public static void BotLeaveRoom(string botUserId)
|
||||
@@ -506,7 +632,7 @@ namespace Assets.MyGame.Scripts.Net
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// FishGameHub HostDisconnectNEW — 房主断线
|
||||
/// FishGameHub HostDisconnect — 房主断线
|
||||
/// 其他玩家可接受机器人控制权。本地房主引用若已断线则转移给本地首个非人机玩家。
|
||||
/// </summary>
|
||||
public static void HostDisconnect()
|
||||
@@ -586,17 +712,17 @@ namespace Assets.MyGame.Scripts.Net
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LoginHub LevelChangedNEW 数据
|
||||
/// LoginHub LevelChanged 数据(字段名对齐后端大写首字母)
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class LevelChangedData
|
||||
{
|
||||
public int newLevel;
|
||||
public long newExp;
|
||||
public long newGold;
|
||||
public int newDiamond;
|
||||
public string source;
|
||||
public string remark;
|
||||
public int NewLevel;
|
||||
public long NewExp;
|
||||
public long NewGold;
|
||||
public int NewDiamond;
|
||||
public string Source;
|
||||
public string Remark;
|
||||
}
|
||||
|
||||
// ---------------- Customer ----------------
|
||||
|
||||
Reference in New Issue
Block a user