feat: isolate lobby during minigames
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
31afce6882
commit
6a5e534d00
@@ -69,12 +69,19 @@ namespace XGame.MiniGame
|
||||
var dl = new MiniGameDownloader(cdnBase, gameId, version);
|
||||
bool ok = false;
|
||||
yield return dl.Run(r => ok = r);
|
||||
if (!ok) { Debug.LogError("[MiniGameHost] 下载失败: " + dl.Error); yield break; }
|
||||
if (!ok)
|
||||
{
|
||||
FailEnterAndExit("下载失败: " + dl.Error);
|
||||
yield break;
|
||||
}
|
||||
|
||||
// 2) 加载 Core/Client DLL,反射入口
|
||||
var asmLoader = new MiniGameAssemblyLoader();
|
||||
if (!asmLoader.Load(dl.LocalDir, dl.Manifest))
|
||||
{ Debug.LogError("[MiniGameHost] 加载程序集失败: " + asmLoader.Error); yield break; }
|
||||
{
|
||||
FailEnterAndExit("加载程序集失败: " + asmLoader.Error);
|
||||
yield break;
|
||||
}
|
||||
|
||||
// 3) 网络通道
|
||||
_net = new MiniGameNetChannel(sock);
|
||||
@@ -82,7 +89,16 @@ namespace XGame.MiniGame
|
||||
_net.OnFrameworkFrame = OnFrameworkFrame;
|
||||
|
||||
// 4) 反射实例化 IGameClient + 注入 ctx
|
||||
_client = asmLoader.CreateClient();
|
||||
try
|
||||
{
|
||||
_client = asmLoader.CreateClient();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FailEnterAndExit("创建客户端失败: " + e.Message);
|
||||
yield break;
|
||||
}
|
||||
|
||||
_assets = new MiniGameAssetLoader(dl.LocalDir, dl.Manifest);
|
||||
if (_players == null)
|
||||
{
|
||||
@@ -103,7 +119,15 @@ namespace XGame.MiniGame
|
||||
|
||||
// 6) OnEnter 接管
|
||||
// 注意:OnEnter 在 MatchFound 到达之前调用,房间可能尚未就绪;小游戏应等待后续网络消息再依赖房间状态
|
||||
SafeCall(() => _client.OnEnter(_ctx), "OnEnter");
|
||||
try
|
||||
{
|
||||
_client.OnEnter(_ctx);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FailEnterAndExit("OnEnter 抛异常: " + e.Message);
|
||||
yield break;
|
||||
}
|
||||
_running = true;
|
||||
Debug.Log("[MiniGameHost] 小游戏已进入: " + gameId);
|
||||
}
|
||||
@@ -157,6 +181,27 @@ namespace XGame.MiniGame
|
||||
// 返回大厅:交回 Lua game_module_runner 或大厅 UI(按现有大厅返回流程)
|
||||
}
|
||||
|
||||
private void FailEnterAndExit(string reason)
|
||||
{
|
||||
DestroyResultDialog();
|
||||
_waitingForResultConfirm = false;
|
||||
_running = false;
|
||||
_client = null;
|
||||
_net = null;
|
||||
_ctx = null;
|
||||
if (_players != null)
|
||||
{
|
||||
_players.SetRoomPlayers(null);
|
||||
}
|
||||
if (_assets != null)
|
||||
{
|
||||
_assets.UnloadAll();
|
||||
_assets = null;
|
||||
}
|
||||
Debug.LogError("[MiniGameHost] 进入小游戏失败: " + reason);
|
||||
OnGameExited?.Invoke();
|
||||
}
|
||||
|
||||
private void ShowResultDialog(RoomEndMsg roomEnd)
|
||||
{
|
||||
if (_waitingForResultConfirm)
|
||||
|
||||
Reference in New Issue
Block a user