chore(m2): 保存功能验收及后续清理前检查点

This commit is contained in:
Liubing\LB
2026-10-10 20:40:27 +08:00
parent d3c5394a55
commit 144e7f739f
110 changed files with 12672 additions and 7514 deletions

View File

@@ -607,7 +607,8 @@ public class EventFishingDuelPanel : BasePanel
}
void CreateMatchmakingTicket()
{
if (GContext.container.Resolve<IUserService>() is not PlayFabUserService)
if (GContext.container.Resolve<IUserService>() is not PlayFabUserService &&
GContext.container.Resolve<IUserService>() is not KVUserService)
{
Debug.LogWarning("KV matchmaking service is not connected.");
FDM.MachingEnd(null);
@@ -631,46 +632,58 @@ public class EventFishingDuelPanel : BasePanel
IUserService userService = GContext.container.Resolve<IUserService>();
List<string> Group = FDM.GetGroups();
string details = GetDetails();
var request = new CreateMatchmakingTicketRequest
var attributes = new
{
Creator = new MatchmakingPlayer
{
Entity = new EntityKey
{
Id = ((PlayFabUserService)userService).entityKey.Id,
Type = ((PlayFabUserService)userService).entityKey.Type
},
Attributes = new MatchmakingPlayerAttributes
{
DataObject = new
{
Tier = matchTierListStr.ToArray(),
Map = mapIDsStr.ToArray(),
Group = Group.ToArray(),
Details = details,
}
}
},
GiveUpAfterSeconds = MaxMatchTime,
QueueName = FishingDuelManager.QueueName // 需要根据实际的匹配队列名称修改
Tier = matchTierListStr.ToArray(),
Map = mapIDsStr.ToArray(),
Group = Group.ToArray(),
Details = details,
};
PlayFabMultiplayerAPI.CreateMatchmakingTicket(request,
(result) =>
Action<CreateMatchmakingTicketResult> success = (result) =>
{
currentTicketId = result.TicketId;
Debug.Log("匹配请求已创建,等待匹配...");
Debug.Log("匹配Ticket ID: " + result.TicketId);
//// 开始轮询匹配状态
StartCoroutine(CheckMatchmakingStatus());
//显示取消按钮
but_stop.gameObject.SetActive(true);
};
Action<string> failure = (error) =>
{
Debug.LogError("创建匹配请求失败: " + error);
FDM.MachingEnd(null);
};
if (userService is KVUserService)
{
RequestKVMatch("CreateMatchmakingTicket", new
{
currentTicketId = result.TicketId;
Debug.Log("匹配请求已创建,等待匹配...");
Debug.Log("匹配Ticket ID: " + result.TicketId);
//// 开始轮询匹配状态
StartCoroutine(CheckMatchmakingStatus());
//显示取消按钮
but_stop.gameObject.SetActive(true);
},
(error) =>
queueName = FishingDuelManager.QueueName,
giveUpAfterSeconds = MaxMatchTime,
attributes
}, response => response.ToObject<CreateMatchmakingTicketResult>(), success, failure);
}
else
{
var request = new CreateMatchmakingTicketRequest
{
Debug.LogError("创建匹配请求失败: " + error.GenerateErrorReport());
FDM.MachingEnd(null);
});
Creator = new MatchmakingPlayer
{
Entity = new EntityKey
{
Id = ((PlayFabUserService)userService).entityKey.Id,
Type = ((PlayFabUserService)userService).entityKey.Type
},
Attributes = new MatchmakingPlayerAttributes
{
DataObject = attributes
}
},
GiveUpAfterSeconds = MaxMatchTime,
QueueName = FishingDuelManager.QueueName
};
PlayFabMultiplayerAPI.CreateMatchmakingTicket(request, success, error => failure(error.GenerateErrorReport()));
}
}
IEnumerator CheckMatchmakingStatus()
@@ -680,7 +693,9 @@ public class EventFishingDuelPanel : BasePanel
yield return new WaitForSeconds(3f);
if (string.IsNullOrEmpty(currentTicketId))
{
yield break;
}
var request = new GetMatchmakingTicketRequest
{
@@ -689,41 +704,53 @@ public class EventFishingDuelPanel : BasePanel
EscapeObject = false
};
PlayFabMultiplayerAPI.GetMatchmakingTicket(request,
(result) =>
Action<GetMatchmakingTicketResult> success = (result) =>
{
string statusInfo = "匹配状态: " + result.Status;
if (result.MatchId != null)
{
string statusInfo = "匹配状态: " + result.Status;
if (result.MatchId != null)
{
statusInfo += ", Match ID: " + result.MatchId;
}
Debug.Log(statusInfo.ToString());
statusInfo += ", Match ID: " + result.MatchId;
}
Debug.Log(statusInfo.ToString());
if (result.Status == "Matched")
{
but_stop.gameObject.SetActive(false);
Debug.Log("匹配成功,获取服务器信息: ");
GetMatchDetails(result.MatchId);
}
else if (result.Status == "Canceled")
{
Debug.Log("匹配已取消: Canceled " + result.CancellationReasonString);
//if (result.CancellationReasonString != "Requested")
//{
MachingEnd();
//}
}
},
(error) =>
if (result.Status == "Matched")
{
Debug.LogError("检查匹配状态失败: " + error.GenerateErrorReport());
but_stop.gameObject.SetActive(false);
Debug.Log("匹配成功,获取服务器信息: ");
GetMatchDetails(result.MatchId);
}
else if (result.Status == "Canceled")
{
Debug.Log("匹配已取消: Canceled " + result.CancellationReasonString);
//if (result.CancellationReasonString != "Requested")
//{
MachingEnd();
});
//}
}
};
Action<string> failure = (error) =>
{
Debug.LogError("检查匹配状态失败: " + error);
MachingEnd();
};
if (GContext.container.Resolve<IUserService>() is KVUserService)
{
RequestKVMatch("GetMatchmakingTicket", new
{
queueName = request.QueueName,
ticketId = request.TicketId
}, response => response.ToObject<GetMatchmakingTicketResult>(), success, failure);
}
else
{
PlayFabMultiplayerAPI.GetMatchmakingTicket(request, success, error => failure(error.GenerateErrorReport()));
}
}
}
void GetMatchDetails(string matchId)
{
if (GContext.container.Resolve<IUserService>() is not PlayFabUserService)
if (GContext.container.Resolve<IUserService>() is not PlayFabUserService &&
GContext.container.Resolve<IUserService>() is not KVUserService)
{
Debug.LogWarning("KV matchmaking service is not connected.");
FDM.MachingEnd(null);
@@ -737,52 +764,63 @@ public class EventFishingDuelPanel : BasePanel
ReturnMemberAttributes = true
};
PlayFabMultiplayerAPI.GetMatch(request,
(result) =>
Action<GetMatchResult> success = (result) =>
{
Debug.Log("匹配成功: " + result.MatchId);
if (string.IsNullOrEmpty(currentTicketId))
{
Debug.Log("匹配成功: " + result.MatchId);
if (string.IsNullOrEmpty(currentTicketId))
return;
}
// 添加玩家信息
if (result.Members != null && result.Members.Count > 0)
{
//AddMatchmakingLog("玩家数量: " + result.Members.Count);
IUserService userService = GContext.container.Resolve<IUserService>();
MatchDetails matchDetails = null;
int[] mapArray = null;
try
{
return;
}
// 添加玩家信息
if (result.Members != null && result.Members.Count > 0)
{
//AddMatchmakingLog("玩家数量: " + result.Members.Count);
IUserService userService = GContext.container.Resolve<IUserService>();
MatchDetails matchDetails = null;
int[] mapArray = null;
try
for (int i = 0; i < result.Members.Count; i++)
{
for (int i = 0; i < result.Members.Count; i++)
MatchmakingPlayerWithTeamAssignment member = result.Members[i];
if (member.Entity.Id != (userService is KVUserService ? userService.UserId : ((PlayFabUserService)userService).entityKey.Id))
{
MatchmakingPlayerWithTeamAssignment member = result.Members[i];
if (member.Entity.Id != ((PlayFabUserService)userService).entityKey.Id)
{
JObject dataObject = JObject.FromObject(result.Members[i].Attributes.DataObject);
string[] tierArray = dataObject["Tier"].ToObject<string[]>();
mapArray = dataObject["Map"].ToObject<int[]>();
string matchDetailsStr = dataObject["Details"].ToString();
matchDetails = Newtonsoft.Json.JsonConvert.DeserializeObject<MatchDetails>(matchDetailsStr);
break;
}
JObject dataObject = JObject.FromObject(result.Members[i].Attributes.DataObject);
string[] tierArray = dataObject["Tier"].ToObject<string[]>();
mapArray = dataObject["Map"].ToObject<int[]>();
string matchDetailsStr = dataObject["Details"].ToString();
matchDetails = Newtonsoft.Json.JsonConvert.DeserializeObject<MatchDetails>(matchDetailsStr);
break;
}
}
catch
{
matchDetails = null;
mapArray = null;
}
currentTicketId = null;
FDM.MachingEnd(result.MatchId, matchDetails, mapArray);
StartCoroutine(CheckReady());
}
},
(error) =>
catch
{
matchDetails = null;
mapArray = null;
}
currentTicketId = null;
FDM.MachingEnd(result.MatchId, matchDetails, mapArray);
StartCoroutine(CheckReady());
}
};
Action<string> failure = (error) =>
{
Debug.LogError("获取匹配详情失败: " + error);
MachingEnd();
};
if (GContext.container.Resolve<IUserService>() is KVUserService)
{
RequestKVMatch("GetMatch", new
{
Debug.LogError("获取匹配详情失败: " + error.GenerateErrorReport());
MachingEnd();
});
queueName = request.QueueName,
matchId = request.MatchId
}, ReadKVMatch, success, failure);
}
else
{
PlayFabMultiplayerAPI.GetMatch(request, success, error => failure(error.GenerateErrorReport()));
}
}
IEnumerator CheckReady()
{
@@ -806,7 +844,9 @@ public class EventFishingDuelPanel : BasePanel
void CancelMatchmaking()
{
if (string.IsNullOrEmpty(currentTicketId))
{
return;
}
but_stop.gameObject.SetActive(false);
var request = new CancelMatchmakingTicketRequest
{
@@ -814,15 +854,98 @@ public class EventFishingDuelPanel : BasePanel
QueueName = FishingDuelManager.QueueName // 需要根据实际的匹配队列名称修改
};
currentTicketId = null;
PlayFabMultiplayerAPI.CancelMatchmakingTicket(request,
(result) =>
Action<CancelMatchmakingTicketResult> success = (result) =>
{
Debug.Log("匹配已取消: ");
};
Action<string> failure = (error) =>
{
Debug.LogError("取消匹配失败: " + error);
};
if (GContext.container.Resolve<IUserService>() is KVUserService)
{
RequestKVMatch("CancelMatchmakingTicket", new
{
Debug.Log("匹配已取消: ");
},
(error) =>
queueName = request.QueueName,
ticketId = request.TicketId
}, response => response.ToObject<CancelMatchmakingTicketResult>(), success, failure);
}
else
{
PlayFabMultiplayerAPI.CancelMatchmakingTicket(request, success, error => failure(error.GenerateErrorReport()));
}
}
private static async void RequestKVMatch<T>(string action, object request, Func<JObject, T> parse,
Action<T> success, Action<string> failure)
{
string body = await GContext.container.Resolve<ICustomServerMgr>().CustomServerPost("matchmaking/" + action,
Newtonsoft.Json.JsonConvert.SerializeObject(request));
T result = default;
string error = "KV matchmaking request failed";
bool accepted = false;
try
{
if (!string.IsNullOrEmpty(body))
{
Debug.LogError("取消匹配失败: " + error.GenerateErrorReport());
var response = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(body);
if (response != null && response["code"]?.ToObject<int>(Newtonsoft.Json.JsonSerializer.CreateDefault()) == 1)
{
result = parse(response);
accepted = true;
}
}
}
catch (Newtonsoft.Json.JsonException ex)
{
error = "KV matchmaking response: " + ex.GetType().Name;
}
if (accepted)
{
success(result);
}
else
{
failure(error);
}
}
private static GetMatchResult ReadKVMatch(JObject response)
{
var result = new GetMatchResult
{
MatchId = response["matchId"]?.ToObject<string>()
};
var members = response["members"];
if (members == null || members.Type == JTokenType.Null)
{
return result;
}
if (members is not JArray array)
{
throw new Newtonsoft.Json.JsonSerializationException("Invalid match members.");
}
result.Members = new List<MatchmakingPlayerWithTeamAssignment>();
foreach (var token in array)
{
if (token is not JObject member || member["playerId"]?.Type != JTokenType.String ||
member["attributes"] is not JObject attributes)
{
throw new Newtonsoft.Json.JsonSerializationException("Invalid match member.");
}
result.Members.Add(new MatchmakingPlayerWithTeamAssignment
{
Entity = new EntityKey
{
Id = member["playerId"].ToObject<string>()
},
Attributes = new MatchmakingPlayerAttributes
{
DataObject = attributes
}
});
}
return result;
}
#endregion Matchmaking