From d4bf5769fd9fb42c5ce84aedba0b4f60143211b0 Mon Sep 17 00:00:00 2001 From: Blank Date: Tue, 3 Nov 2026 17:18:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(server-lifecycle):=20=E9=99=8D=E4=BD=8E?= =?UTF-8?q?=E5=90=88=E6=9C=8D=E5=8F=82=E6=95=B0=E8=A7=A3=E6=9E=90=E5=A4=8D?= =?UTF-8?q?=E6=9D=82=E5=BA=A6=EF=BC=88GFX-1226=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 提取单参数与源服列表解析私有方法,保持公共接口和解析行为不变。 通过解决方案构建、34 项定向测试及 705 组参数差分验证。 本地 Sonar 分析器复现原始复杂度 23,重构后不再触发 S3776。 Linear: GFX-1226 --- .../ServerMerge/OnlineServerMergeCli.cs | 101 +++++++++++------- 1 file changed, 62 insertions(+), 39 deletions(-) diff --git a/Capability/GameFrameX.Capability.Online.ServerLifecycle/ServerMerge/OnlineServerMergeCli.cs b/Capability/GameFrameX.Capability.Online.ServerLifecycle/ServerMerge/OnlineServerMergeCli.cs index 82630b40..fbca9798 100644 --- a/Capability/GameFrameX.Capability.Online.ServerLifecycle/ServerMerge/OnlineServerMergeCli.cs +++ b/Capability/GameFrameX.Capability.Online.ServerLifecycle/ServerMerge/OnlineServerMergeCli.cs @@ -125,58 +125,81 @@ private static async Task ParseArgumentsAsync(strin var options = new OnlineServerMergeCliOptions(); foreach (var arg in args ?? Array.Empty()) { - if (arg == "--execute") + if (!await ParseArgumentAsync(arg, options, output).ConfigureAwait(false)) { - options.Execute = true; - continue; + return null; } + } + + return options; + } - var separatorIndex = arg.IndexOf('='); - if (separatorIndex <= 0) + /// + /// 解析单个 CLI 参数;非法参数输出错误并返回 false。 + /// + private static async Task ParseArgumentAsync(string arg, OnlineServerMergeCliOptions options, TextWriter output) + { + if (arg == "--execute") + { + options.Execute = true; + return true; + } + + var separatorIndex = arg.IndexOf('='); + if (separatorIndex <= 0) + { + await output.WriteLineAsync("ERROR: unknown argument '" + arg + "'. Usage: --target= --sources= [--execute]").ConfigureAwait(false); + return false; + } + + var name = arg.Substring(0, separatorIndex); + var value = arg.Substring(separatorIndex + 1); + if (name == "--target") + { + if (!long.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var targetServerId)) { - await output.WriteLineAsync("ERROR: unknown argument '" + arg + "'. Usage: --target= --sources= [--execute]").ConfigureAwait(false); - return null; + await output.WriteLineAsync("ERROR: invalid --target value '" + value + "'.").ConfigureAwait(false); + return false; } - var name = arg.Substring(0, separatorIndex); - var value = arg.Substring(separatorIndex + 1); - if (name == "--target") - { - if (!long.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var targetServerId)) - { - await output.WriteLineAsync("ERROR: invalid --target value '" + value + "'.").ConfigureAwait(false); - return null; - } + options.TargetServerId = targetServerId; + } + else if (name == "--sources") + { + return await ParseSourceServerIdsAsync(value, options, output).ConfigureAwait(false); + } + else + { + await output.WriteLineAsync("ERROR: unknown argument '" + arg + "'. Usage: --target= --sources= [--execute]").ConfigureAwait(false); + return false; + } - options.TargetServerId = targetServerId; - } - else if (name == "--sources") + return true; + } + + /// + /// 依次解析并追加源服标识;非法分段输出错误并返回 false。 + /// + private static async Task ParseSourceServerIdsAsync(string value, OnlineServerMergeCliOptions options, TextWriter output) + { + foreach (var segment in value.Split(',')) + { + if (!long.TryParse(segment.Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out var sourceServerId)) { - foreach (var segment in value.Split(',')) - { - if (!long.TryParse(segment.Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out var sourceServerId)) - { - await output.WriteLineAsync("ERROR: invalid --sources segment '" + segment + "'.").ConfigureAwait(false); - return null; - } - - if (sourceServerId <= 0) - { - await output.WriteLineAsync("ERROR: invalid --sources segment '" + segment + "' (server ids must be positive).").ConfigureAwait(false); - return null; - } - - options.SourceServerIds.Add(sourceServerId); - } + await output.WriteLineAsync("ERROR: invalid --sources segment '" + segment + "'.").ConfigureAwait(false); + return false; } - else + + if (sourceServerId <= 0) { - await output.WriteLineAsync("ERROR: unknown argument '" + arg + "'. Usage: --target= --sources= [--execute]").ConfigureAwait(false); - return null; + await output.WriteLineAsync("ERROR: invalid --sources segment '" + segment + "' (server ids must be positive).").ConfigureAwait(false); + return false; } + + options.SourceServerIds.Add(sourceServerId); } - return options; + return true; } /// From c2a8f3b5f7108e88d37a7a569b21c6ff7c3fe074 Mon Sep 17 00:00:00 2001 From: Blank Date: Tue, 3 Nov 2026 20:04:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(client):=20=E7=A7=BB=E9=99=A4=E5=9B=9B?= =?UTF-8?q?=E5=AD=90=E6=A3=8B=20Bot=20=E5=8F=AA=E5=86=99=E4=B8=8D=E8=AF=BB?= =?UTF-8?q?=E7=9A=84=E6=88=BF=E9=97=B4=E4=B8=8E=E5=AF=B9=E5=B1=80=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=EF=BC=88GFX-1220=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 删除 _connectFourRoomInfo / _connectFourGameInfo 及其赋值,消除 Sonar S4487;连带移除仅剩该赋值的 lock 块与随之冗余的 return,流程行为不变。 Linear: GFX-1220 --- GameFrameX.Client/Bot/BotClient.ConnectFour.cs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/GameFrameX.Client/Bot/BotClient.ConnectFour.cs b/GameFrameX.Client/Bot/BotClient.ConnectFour.cs index f7f5ec20..9183ac5d 100644 --- a/GameFrameX.Client/Bot/BotClient.ConnectFour.cs +++ b/GameFrameX.Client/Bot/BotClient.ConnectFour.cs @@ -87,8 +87,6 @@ private enum ConnectFourStage private ConnectFourStage _connectFourStage; private long _connectFourRoomId; - private RoomInfo _connectFourRoomInfo; - private ConnectFourGameInfo _connectFourGameInfo; private int _connectFourSubmittedRound = -1; private int _connectFourSubmittedMoveCount = -1; private int _connectFourLoggedFinishedRound; @@ -144,7 +142,6 @@ private void OnConnectFourRoomListResponse(RespRoomList msg) lock (_connectFourGate) { _connectFourRoomId = room.RoomId; - _connectFourRoomInfo = room; _connectFourStage = ConnectFourStage.WaitJoin; _connectFourNoProgressCount = 0; } @@ -175,7 +172,6 @@ private void OnConnectFourJoinRoomResponse(RespJoinRoom msg) lock (_connectFourGate) { - _connectFourRoomInfo = msg.Room; _connectFourStage = msg.Room.Status == RoomStatus.Playing ? ConnectFourStage.Playing : ConnectFourStage.WaitStart; _connectFourNoProgressCount = 0; } @@ -197,7 +193,6 @@ private void OnConnectFourRoomChangedNotify(NotifyRoomChanged msg) { lock (_connectFourGate) { - _connectFourRoomInfo = msg.Room; _connectFourStage = ConnectFourStage.Playing; _connectFourNoProgressCount = 0; } @@ -205,12 +200,6 @@ private void OnConnectFourRoomChangedNotify(NotifyRoomChanged msg) // Localization: Client.Bot.ConnectFourGameStarted - 机器人-{0}四子棋场景-对局开始,房间ID:{1}。 LogHelper.Info(LocalizationService.GetString(Localization.Keys.Client.Bot.ConnectFourGameStarted, m_BotName, _connectFourRoomId)); SendToTransport(new ReqConnectFourGameInfo { RoomId = _connectFourRoomId }); - return; - } - - lock (_connectFourGate) - { - _connectFourRoomInfo = msg.Room; } } @@ -252,7 +241,6 @@ private void ApplyConnectFourGameInfo(ConnectFourGameInfo gameInfo) lock (_connectFourGate) { - _connectFourGameInfo = gameInfo; _connectFourNoProgressCount = 0; }