Skip to content

Commit 53a42a5

Browse files
committed
refactor(DiscoverCenter): 重构游戏应用客户端配置使用方式
将 GameAppClientOption 类删除,改为直接使用 AppSetting 中的配置项 更新 GameAppClient 构造函数以接收 AppSetting 参数 在 AppSetting 和 LauncherOptions 中添加对应的客户端配置属性
1 parent f0d8387 commit 53a42a5

File tree

4 files changed

+57
-65
lines changed

4 files changed

+57
-65
lines changed

GameFrameX.StartUp/DiscoverCenter/GameAppClient.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
using GameFrameX.NetWork.Messages;
3838
using GameFrameX.SuperSocket.ClientEngine;
3939
using GameFrameX.Utility;
40+
using GameFrameX.Utility.Setting;
4041

4142
namespace GameFrameX.StartUp.DiscoverCenter;
4243

@@ -95,16 +96,16 @@ internal sealed class GameAppClient
9596
/// </summary>
9697
/// <param name="clientEvent">客户端事件回调结构体,包含连接、断开、消息等事件的处理委托</param>
9798
/// <param name="endPoint">服务器端点信息(IP和端口)</param>
98-
/// <param name="option">配置信息</param>
99-
public GameAppClient(GameAppClientEvent clientEvent, EndPoint endPoint, GameAppClientOption option)
99+
/// <param name="appSetting">配置信息</param>
100+
public GameAppClient(GameAppClientEvent clientEvent, EndPoint endPoint, AppSetting appSetting)
100101
{
101-
ArgumentNullException.ThrowIfNull(option, nameof(option));
102-
ConnectDelay = option.ConnectDelay;
102+
ArgumentNullException.ThrowIfNull(appSetting, nameof(appSetting));
103+
ConnectDelay = appSetting.GameAppClientConnectDelay;
103104
_mGameAppClientEvent = clientEvent;
104105
_serverHost = endPoint;
105-
_heartBeatInterval = option.HeartBeatInterval;
106-
_retryDelay = option.RetryDelay;
107-
MaxRetryCount = option.MaxRetryCount;
106+
_heartBeatInterval = appSetting.GameAppClientHeartBeatInterval;
107+
_retryDelay = appSetting.GameAppClientRetryDelay;
108+
MaxRetryCount = appSetting.GameAppClientMaxRetryCount;
108109
_mTcpClient = new AsyncTcpSession();
109110
_mTcpClient.Connected += OnClientOnConnected;
110111
_mTcpClient.Closed += OnClientOnClosed;

GameFrameX.StartUp/DiscoverCenter/GameAppClientOption.cs

Lines changed: 0 additions & 58 deletions
This file was deleted.

GameFrameX.StartUp/Options/LauncherOptions.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,4 +430,33 @@ public sealed class LauncherOptions
430430
[Option(nameof(HubApiUrl), Description = "HubAPI地址")]
431431
[DefaultValue("")]
432432
public string HubApiUrl { get; set; }
433+
434+
435+
/// <summary>
436+
/// 心跳间隔(毫秒),默认 5000 毫秒
437+
/// </summary>
438+
[Option(nameof(GameAppClientHeartBeatInterval), Description = "心跳间隔(毫秒),默认 5000 毫秒")]
439+
[DefaultValue(5000)]
440+
public int GameAppClientHeartBeatInterval { get; set; } = 5000;
441+
442+
/// <summary>
443+
/// 连接延迟(毫秒),默认 5000 毫秒
444+
/// </summary>
445+
[Option(nameof(GameAppClientConnectDelay), Description = "连接延迟(毫秒),默认 5000 毫秒")]
446+
[DefaultValue(5000)]
447+
public int GameAppClientConnectDelay { get; set; } = 5000;
448+
449+
/// <summary>
450+
/// 重试延迟(毫秒),默认 5000 毫秒
451+
/// </summary>
452+
[Option(nameof(GameAppClientRetryDelay), Description = "重试延迟(毫秒),默认 5000 毫秒")]
453+
[DefaultValue(5000)]
454+
public int GameAppClientRetryDelay { get; set; } = 5000;
455+
456+
/// <summary>
457+
/// 最大重试次数,默认 -1 表示无限重试
458+
/// </summary>
459+
[Option(nameof(GameAppClientMaxRetryCount), Description = "最大重试次数,默认 -1 表示无限重试")]
460+
[DefaultValue(-1)]
461+
public int GameAppClientMaxRetryCount { get; set; } = -1;
433462
}

GameFrameX.Utility/Setting/AppSetting.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,5 +389,25 @@ public string ToFormatString()
389389
/// </summary>
390390
public string Label { get; set; }
391391

392+
/// <summary>
393+
/// 心跳间隔(毫秒),默认 5000 毫秒
394+
/// </summary>
395+
public int GameAppClientHeartBeatInterval { get; set; }
396+
397+
/// <summary>
398+
/// 连接延迟(毫秒),默认 5000 毫秒
399+
/// </summary>
400+
public int GameAppClientConnectDelay { get; set; }
401+
402+
/// <summary>
403+
/// 重试延迟(毫秒),默认 5000 毫秒
404+
/// </summary>
405+
public int GameAppClientRetryDelay { get; set; }
406+
407+
/// <summary>
408+
/// 最大重试次数,默认 -1 表示无限重试
409+
/// </summary>
410+
public int GameAppClientMaxRetryCount { get; set; }
411+
392412
#endregion
393413
}

0 commit comments

Comments
 (0)