UI联机bug
This commit is contained in:
parent
464fbde2e8
commit
af960ba10d
@ -35,7 +35,8 @@ public enum NetworkPlayerTipType
|
||||
MapSyncMismatch,
|
||||
ActionSendFailed,
|
||||
LobbyDataRequestFailed,
|
||||
InviteVersionMismatch
|
||||
InviteVersionMismatch,
|
||||
P2PModuleInitFailed
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
@ -42,7 +42,7 @@ namespace TH1_Logic.Net
|
||||
if (!ignoreCooldown && _nextTipTimes.TryGetValue(tipType, out var nextTipTime) && now < nextTipTime) return false;
|
||||
|
||||
_nextTipTimes[tipType] = now + cooldownSeconds;
|
||||
var message = ResolveText(info?.Message, tipType.ToString());
|
||||
var message = ResolveText(info?.Message, ResolveDefaultMessage(tipType));
|
||||
if (!string.IsNullOrWhiteSpace(detailMessage)
|
||||
&& !string.Equals(message, detailMessage, StringComparison.Ordinal))
|
||||
{
|
||||
@ -55,7 +55,7 @@ namespace TH1_Logic.Net
|
||||
{
|
||||
TipType = tipType,
|
||||
TipInfo = info,
|
||||
Title = ResolveText(info?.Title, tipType.ToString()),
|
||||
Title = ResolveText(info?.Title, ResolveDefaultTitle(tipType)),
|
||||
Message = message
|
||||
};
|
||||
AddRecentPayload(payload);
|
||||
@ -136,5 +136,19 @@ namespace TH1_Logic.Net
|
||||
if (uint.TryParse(text, out var id)) return MultilingualManager.Instance.GetMultilingualText(id);
|
||||
return text;
|
||||
}
|
||||
|
||||
private static string ResolveDefaultTitle(NetworkPlayerTipType tipType)
|
||||
{
|
||||
return tipType == NetworkPlayerTipType.P2PModuleInitFailed
|
||||
? "P2P module init failed"
|
||||
: tipType.ToString();
|
||||
}
|
||||
|
||||
private static string ResolveDefaultMessage(NetworkPlayerTipType tipType)
|
||||
{
|
||||
return tipType == NetworkPlayerTipType.P2PModuleInitFailed
|
||||
? "Steam P2P relay or listen socket is not ready. Multiplayer lobby actions are unavailable."
|
||||
: tipType.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using Logic.CrashSight;
|
||||
@ -117,7 +117,13 @@ namespace TH1_Logic.Steam
|
||||
_lastConnectionFailureTime = -999f;
|
||||
_lastConnectionFailureReason = string.Empty;
|
||||
LogSystem.LogInfo($"成功在虚拟端口 {TargetPort} 创建监听套接字: {_listenSocket}");
|
||||
return;
|
||||
}
|
||||
|
||||
var reason = $"P2P listen socket init failed: port={TargetPort}";
|
||||
MarkConnectionFailure(reason);
|
||||
LogSystem.LogWarning(reason);
|
||||
NetworkPlayerTipManager.Instance.Request(NetworkPlayerTipType.P2PModuleInitFailed, reason);
|
||||
}
|
||||
|
||||
// 定时刷新套接字创建
|
||||
@ -132,6 +138,13 @@ namespace TH1_Logic.Steam
|
||||
{
|
||||
CreateListenSocket();
|
||||
}
|
||||
else
|
||||
{
|
||||
var reason = $"P2P relay network is not ready: {relayStatus.m_eAvail}, {relayStatus.m_debugMsg}";
|
||||
MarkConnectionFailure(reason);
|
||||
LogSystem.LogWarning(reason);
|
||||
NetworkPlayerTipManager.Instance.Request(NetworkPlayerTipType.P2PModuleInitFailed, reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -438,7 +451,7 @@ namespace TH1_Logic.Steam
|
||||
LogSystem.LogWarning($"Problem details: {info.m_info.m_szEndDebug}");
|
||||
var problemReason = $"Connection problem detected locally: {remote}, {info.m_info.m_szEndDebug}";
|
||||
MarkConnectionFailure(problemReason);
|
||||
NetworkPlayerTipManager.Instance.Request(NetworkPlayerTipType.P2PConnectionFailed, problemReason, true);
|
||||
NetworkPlayerTipManager.Instance.Request(IsValidRemotePeer(remote) ? NetworkPlayerTipType.P2PConnectionFailed : NetworkPlayerTipType.P2PModuleInitFailed, problemReason, true);
|
||||
HandleDisconnection(remote, info.m_hConn);
|
||||
break;
|
||||
|
||||
@ -450,9 +463,7 @@ namespace TH1_Logic.Steam
|
||||
MarkConnectionFailure(failureReason);
|
||||
var isTimeout = endReason == (int)ESteamNetConnectionEnd.k_ESteamNetConnectionEnd_Misc_Timeout
|
||||
|| endReason == (int)ESteamNetConnectionEnd.k_ESteamNetConnectionEnd_Remote_Timeout;
|
||||
NetworkPlayerTipManager.Instance.Request(isTimeout
|
||||
? NetworkPlayerTipType.P2PConnectionTimeout
|
||||
: NetworkPlayerTipType.P2PConnectionFailed, failureReason, true);
|
||||
NetworkPlayerTipManager.Instance.Request(GetConnectionFailureTipType(remote, isTimeout), failureReason, true);
|
||||
|
||||
// 提供更详细的错误信息
|
||||
switch (endReason)
|
||||
@ -487,6 +498,17 @@ namespace TH1_Logic.Steam
|
||||
}
|
||||
|
||||
// 检查是否应该接受这个连接
|
||||
private static bool IsValidRemotePeer(CSteamID remote)
|
||||
{
|
||||
return remote.IsValid() && remote.m_SteamID != 0;
|
||||
}
|
||||
|
||||
private static NetworkPlayerTipType GetConnectionFailureTipType(CSteamID remote, bool isTimeout)
|
||||
{
|
||||
if (!IsValidRemotePeer(remote)) return NetworkPlayerTipType.P2PModuleInitFailed;
|
||||
return isTimeout ? NetworkPlayerTipType.P2PConnectionTimeout : NetworkPlayerTipType.P2PConnectionFailed;
|
||||
}
|
||||
|
||||
private void MarkConnectionFailure(string reason)
|
||||
{
|
||||
_lastConnectionFailureTime = Time.time;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user