Files
SVSimServer/SVSim.BattleEngine/Engine/Wizard/WebViewHelper.cs
gamer147 2d9a6eea4b engine cleanup passes 4-7 + multi-instancing ambient rip
Squashes 146 commits from battle-engine-extraction. Net: 2,045 files changed,
+11,896 / -158,687 lines. Ships engine passes 4-7 (dead-code cull, view-layer
stub, receive-path shrink) plus the Phase-5 AsyncLocal ambient deletion that
turns concurrent battles into a type-system property rather than a scope
contract.

## What landed

**Passes 4-7 (chunks 1-34):** Extended the Phase-4 const-false collapse into a
cascading cull across the skill graph, view layer, and receive-path periphery.
Six mode flags (IsWatchBattle/IsReplayBattle/IsAdmin/IsAdminWatch/IsPuzzleQuest/
IsAINetwork) became `const false`, every guarded block deleted. Field*.cs
subclass ctors + BackGroundBase + ObjectChecker culled to no-ops. Mulligan
family reworked to take a mgr param through IMulliganMgr.InitMulligan.
Emotion/Recovery/Resource clusters null-stubbed. Prediction/OperationSimulator/
skill filters converted from static ambient reads to per-mgr reads via
SkillPrm.ownerCard.SelfBattlePlayer.BattleMgr / ins.BattleMgr / this.BattleMgr.

**Phase-5 ambient rip (chunks 35-47):** Deleted BattleAmbient / BattleAmbient-
Context / TestBattleScope in full. Every per-battle mutable slot now lives on
the mgr instance itself:
  mgr.InstanceIsForecast / InstanceIsRandomDraw / InstanceRecoveryInfo /
  InstanceViewerId / InstanceNetworkAgent / GameMgr
BattleManagerBase.GetIns() returns null unconditionally; the residual static
flags + 3 façades (Certification.ViewerId, Data.BattleRecoveryInfo,
ToolboxGame.RealTimeNetworkAgent) are null-tolerant defaults kept for the
handful of engine-internal readers that still reference their types. Zero
BattleAmbient references anywhere in engine + node + tests.

Added pre-seeded GameMgr ctor overload threaded through the mgr chain
(BattleManagerBase → SingleBattleMgr / NetworkBattleManagerBase → NetworkStandard-
BattleMgr → HeadlessBattleMgr / HeadlessNetworkBattleMgr). Fixtures build a
GameMgr, seed it via HeadlessEngineEnv.SeedCharaIds/SeedNetUser, and pass it
to the mgr's ctor — no ambient reach.

Node side (SVSim.BattleNode/SessionBattleEngine): _ctx replaced with a plain
GameMgr field; 34 `using var _ambient = BattleAmbient.Enter(_ctx)` scope wraps
ripped from every accessor and mutator; EngineGlobalInit.WirePerSessionGameMgr
takes GameMgr as a param and runs from SessionBattleEngine.SetupInternal
BEFORE mgr construction.

Test side: TestBattleScope deleted; 18 fixture [SetUp]s migrated to
`HeadlessEngineEnv.EnsureProcessGlobals()`; MultiInstanceEngineTests rewritten
around per-mgr construction (GetIns() → null is the pinned invariant).

## Regression fixes

- **chunk-48** (MulliganCtrl): chunk-35's `= null` stubs on card lookups broke
  the live receive-driven Deal path (BattlePlayerBase.DrawCard NRE'd downstream
  of NetworkPlayerMulliganCtrl.StartMulliganVfx). Restored the three lookups
  via `_battlePlayer.BattleMgr.GetBattleCardIdx`. Engine tests were satisfied
  by the WireMulliganPhase seam; unit tests exposed the live-path gap.

## Ship state

- SVSim.BattleEngine.Tests: 56/56 pass, 2 skip
- SVSim.UnitTests: 1554/1554 pass (was 1523/31-fail before chunk 48)
- Solution build: 0 source warnings (40 pre-existing NU1902 MessagePack CVEs
  in SVSim.EmulatedEntrypoint, unrelated)
- Sequential PVP smoke: verified live (two back-to-back battles, no regression
  on cleanup/spinup)
- Concurrent PVP smoke: verified live

Adds tools/engine-port/ClosureAnalyzer/ — the Roslyn transitive-type-closure
analyzer needed to make future cascade cleanup safe (per feedback memory
"Engine cleanup needs closure tool" from the 2026-06-28 pass-3 failure).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-07-03 19:18:54 -04:00

316 lines
8.6 KiB
C#

using System;
using Cute;
using UnityEngine;
namespace Wizard;
public class WebViewHelper
{
public enum WebViewType
{
NONE,
INFO,
HELP,
COPYRIGHT,
TOS,
PRIVACY_POLICY,
KOR_AUTHORITY,
GACHARATE,
LEGALTEXT,
FUND_SETTLEMENT,
TELECOMMUNICATION_POLICY,
KOREA_CRYSTAL_PAGE,
ANNOUNCE,
SEALED_GACHARATE,
LIMITED_INFO
}
public delegate void ActionWebviewOpen(DialogBase webviewDialog);
public enum UrlType
{
POLICY,
FACEBOOK,
RECOMMENDED_DEVICE,
GAME_GUIDE,
NICONICO,
NICONICO_PUBLISH
}
private bool _isDestroyedWebView;
private DialogBase _webViewDialog;
public DialogBase WebViewDialog => _webViewDialog;
public void OpenWebView(WebViewType webviewtype, ActionWebviewOpen cbWebviewOpen = null, Action cbWebviewClose = null, Action onButton1 = null, Action onCancel = null)
{
_OpenWebView(webviewtype, cbWebviewOpen, cbWebviewClose, 0, 0, null, "", onButton1, onCancel);
}
public void OpenGachaRateWebView(int ratePackId, int packCategory = 0)
{
_OpenWebView(WebViewType.GACHARATE, null, null, ratePackId, packCategory);
}
public void OpenAnnounceWebView(string announceId, Action<DialogBase> onDialogOpening = null)
{
_OpenWebView(WebViewType.ANNOUNCE, null, null, 0, 0, announceId, "", null, null, onDialogOpening);
}
public void OpenWebViewDirectly(string openUrl, bool isLimited = false)
{
string directOpenUrl = CustomPreference.GetApplicationServerURL() + openUrl + GetWebviewBaseQueryParameters();
if (isLimited)
{
_OpenWebView(WebViewType.LIMITED_INFO, null, null, 0, 0, null, directOpenUrl);
}
else
{
_OpenWebView(WebViewType.INFO, null, null, 0, 0, null, directOpenUrl);
}
}
public void OpenWebviewWithPageId(string pageId, bool isLimited = false)
{
string text = CustomPreference.GetApplicationServerURL() + "webview2/index#/info_detail" + GetWebviewBaseQueryParameters();
if (!string.IsNullOrEmpty(pageId))
{
text = text + "&id=" + pageId;
}
if (isLimited)
{
_OpenWebView(WebViewType.LIMITED_INFO, null, null, 0, 0, null, text);
}
else
{
_OpenWebView(WebViewType.INFO, null, null, 0, 0, null, text);
}
}
private void _OpenWebView(WebViewType webviewtype, ActionWebviewOpen cbWebviewOpen = null, Action cbWebviewClose = null, int ratePackId = 0, int packCategory = 0, string announceId = null, string directOpenUrl = "", Action onButton1 = null, Action onCancel = null, Action<DialogBase> onDialogOpening = null)
{
VideoHostingUtil.CheckVideoHostingAndExecAction(delegate
{
if (webviewtype == WebViewType.ANNOUNCE)
{
OpenBrowserInsteadOfWebView(webviewtype, onDialogOpening, announceId);
}
else if (webviewtype == WebViewType.SEALED_GACHARATE)
{
OpenBrowserInsteadOfWebView(webviewtype, onDialogOpening, Data.ArenaData.SealedMyPageResponseData.ScheduleId.ToString());
}
else
{
string text = ratePackId.ToString();
string text2 = packCategory.ToString();
OpenBrowserInsteadOfWebView(webviewtype, onDialogOpening, text, text2);
}
});
}
private string GetWebviewBaseQueryParameters()
{
string encodedViewerId = Certification.GetEncodedViewerId();
string encodedSessionId = Certification.GetEncodedSessionId();
string encodedShortUdid = Certification.GetEncodedShortUdid();
return "?lang=" + CustomPreference.GetTextLanguage() + "&HASH_ID=" + encodedViewerId + "&SID=" + encodedSessionId + "&SUDID=" + encodedShortUdid;
}
private string GetWebViewDialogTitleId(WebViewType webviewtype)
{
string result = null;
switch (webviewtype)
{
case WebViewType.INFO:
case WebViewType.ANNOUNCE:
result = "Common_0036";
break;
case WebViewType.LIMITED_INFO:
result = "Mission_0048";
break;
case WebViewType.HELP:
result = "OtherTop_0006";
break;
case WebViewType.TOS:
result = ((PlayerStaticData._tosAgreementState == PlayerStaticData.AgreementState.Reset) ? "OtherTop_0010_Update" : "OtherTop_0010");
break;
case WebViewType.PRIVACY_POLICY:
result = ((PlayerStaticData._privacyPolicyAgreementState == PlayerStaticData.AgreementState.Reset) ? "OtherTop_0009_Update" : "OtherTop_0009");
break;
case WebViewType.TELECOMMUNICATION_POLICY:
result = "OtherTop_0069";
break;
case WebViewType.KOR_AUTHORITY:
result = ((PlayerStaticData.KorAuthorityAgreementState == PlayerStaticData.AgreementState.Reset) ? "OtherTop_0067_Update" : "OtherTop_0067");
break;
case WebViewType.COPYRIGHT:
result = "OtherTop_0022";
break;
case WebViewType.GACHARATE:
result = "Shop_0004";
break;
case WebViewType.LEGALTEXT:
result = "Shop_0005";
break;
case WebViewType.FUND_SETTLEMENT:
result = "Shop_0077";
break;
case WebViewType.KOREA_CRYSTAL_PAGE:
result = "Shop_0126";
break;
case WebViewType.SEALED_GACHARATE:
result = "Sealed_GachaRateWebViewTitle";
break;
}
return result;
}
private string GetBrowserUrl(WebViewType webviewtype)
{
string text = null;
switch (webviewtype)
{
case WebViewType.INFO:
case WebViewType.LIMITED_INFO:
text = "URL_0004";
break;
case WebViewType.HELP:
text = "URL_0011";
break;
case WebViewType.TOS:
text = "URL_0005";
break;
case WebViewType.PRIVACY_POLICY:
text = "URL_0007";
break;
case WebViewType.TELECOMMUNICATION_POLICY:
text = "URL_0018";
break;
case WebViewType.COPYRIGHT:
text = "URL_0006";
break;
case WebViewType.GACHARATE:
text = "URL_0010";
break;
case WebViewType.LEGALTEXT:
text = "URL_0009";
break;
case WebViewType.FUND_SETTLEMENT:
text = "URL_0008";
break;
case WebViewType.KOREA_CRYSTAL_PAGE:
text = "URL_0015";
break;
case WebViewType.ANNOUNCE:
text = "URL_0016";
break;
case WebViewType.SEALED_GACHARATE:
text = "URL_0017";
break;
}
return text + "_steam";
}
private void OpenBrowserInsteadOfWebView(WebViewType webviewtype, Action<DialogBase> onDialogOpening, params string[] param)
{
string webViewDialogTitleId = GetWebViewDialogTitleId(webviewtype);
string browserUrl = GetBrowserUrl(webviewtype);
SystemText systemText = Data.SystemText;
UIManager.ShowDialogUrl(systemText.Get(webViewDialogTitleId), systemText.Get(browserUrl, param), onDialogOpening);
}
public void DestroyWebView()
{
if (!_isDestroyedWebView && WebViewManager.HasInstance)
{
_isDestroyedWebView = true;
WebViewManager instance = WebViewManager.getInstance();
instance.UnloadWebView();
instance.SetCallback(null);
}
}
public void CloseWebViewDialog()
{
if (IsOpenWebViewDialog())
{
_webViewDialog.Close();
_webViewDialog = null;
DestroyWebView();
}
}
public bool IsOpenWebViewDialog()
{
if (_webViewDialog != null)
{
return _webViewDialog.IsOpen();
}
return false;
}
public DialogBase CreateOpenURLWindow(UrlType type)
{
string applicationServerURL = CustomPreference.GetApplicationServerURL();
string text = "?lang=" + CustomPreference.GetTextLanguage();
string openUrl = null;
string key = null;
DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
SystemText systemText = Data.SystemText;
switch (type)
{
case UrlType.POLICY:
dialogBase.SetPanelDepth(3000);
openUrl = applicationServerURL + "information/policy" + text;
key = "OtherTop_0009";
break;
case UrlType.FACEBOOK:
key = "Account_0038";
break;
case UrlType.RECOMMENDED_DEVICE:
key = "Common_0134";
openUrl = "https://shadowverse.jp/device.php";
break;
case UrlType.GAME_GUIDE:
openUrl = systemText.Get("URL_0012_steam");
key = "OtherTop_0021";
break;
case UrlType.NICONICO:
dialogBase.SetPanelDepth(3000);
key = "VideoHosting_0034";
openUrl = "https://account.nicovideo.jp/rules/account";
break;
case UrlType.NICONICO_PUBLISH:
dialogBase.SetPanelDepth(3000);
key = "VideoHosting_0035";
openUrl = "http://live.nicovideo.jp/static/rule.html";
break;
}
dialogBase.SetTitleLabel(systemText.Get(key));
dialogBase.SetText(systemText.Get("Common_0208"));
dialogBase.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_CancelBtn);
dialogBase.SetButtonText(systemText.Get("Dia_Web_001_Button"));
dialogBase.onPushButton1 = delegate
{
PrepareOpenUrl(delegate
{
if (type == UrlType.FACEBOOK)
{
UIManager.GetInstance().AccountTransferHelper.DataTransferByFaceBook();
}
else
{
BrowserURL.Open(openUrl);
}
});
};
return dialogBase;
}
public void PrepareOpenUrl(Action onFinish)
{
onFinish();
}
}