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; } /// 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; }