Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,58 +125,81 @@ private static async Task<OnlineServerMergeCliOptions> ParseArgumentsAsync(strin
var options = new OnlineServerMergeCliOptions();
foreach (var arg in args ?? Array.Empty<string>())
{
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)
/// <summary>
/// 解析单个 CLI 参数;非法参数输出错误并返回 false。
/// </summary>
private static async Task<bool> 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=<serverId> --sources=<id1,id2,...> [--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=<serverId> --sources=<id1,id2,...> [--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=<serverId> --sources=<id1,id2,...> [--execute]").ConfigureAwait(false);
return false;
}

options.TargetServerId = targetServerId;
}
else if (name == "--sources")
return true;
}

/// <summary>
/// 依次解析并追加源服标识;非法分段输出错误并返回 false。
/// </summary>
private static async Task<bool> 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=<serverId> --sources=<id1,id2,...> [--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;
}

/// <summary>
Expand Down
12 changes: 0 additions & 12 deletions GameFrameX.Client/Bot/BotClient.ConnectFour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -144,7 +142,6 @@ private void OnConnectFourRoomListResponse(RespRoomList msg)
lock (_connectFourGate)
{
_connectFourRoomId = room.RoomId;
_connectFourRoomInfo = room;
_connectFourStage = ConnectFourStage.WaitJoin;
_connectFourNoProgressCount = 0;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -197,20 +193,13 @@ private void OnConnectFourRoomChangedNotify(NotifyRoomChanged msg)
{
lock (_connectFourGate)
{
_connectFourRoomInfo = msg.Room;
_connectFourStage = ConnectFourStage.Playing;
_connectFourNoProgressCount = 0;
}

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

Expand Down Expand Up @@ -252,7 +241,6 @@ private void ApplyConnectFourGameInfo(ConnectFourGameInfo gameInfo)

lock (_connectFourGate)
{
_connectFourGameInfo = gameInfo;
_connectFourNoProgressCount = 0;
}

Expand Down
Loading