Skip to content

Commit

Permalink
[修改]1. 修改设置参数的适配
Browse files Browse the repository at this point in the history
  • Loading branch information
AlianBlank committed Jul 29, 2024
1 parent c7b17fd commit 87598a8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion GameFrameX.Launcher/StartUp/Gateway/AppStartUpGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private ValueTask OnDisconnected(IAppSession appSession, CloseEventArgs disconne
private ValueTask OnConnected(IAppSession appSession)
{
LogHelper.Info("有客户端网络连接成功!。链接信息:SessionID:" + appSession.SessionID + " RemoteEndPoint:" + appSession.RemoteEndPoint);
var netChannel = new DefaultNetWorkChannel(appSession, messageEncoderHandler, RpcSession);
var netChannel = new DefaultNetWorkChannel(appSession, Setting, messageEncoderHandler, RpcSession);
GameClientSessionManager.SetSession(appSession.SessionID, netChannel); //移除
return ValueTask.CompletedTask;
}
Expand Down
58 changes: 29 additions & 29 deletions GameFrameX.Launcher/StartUp/Router/AppStartUpRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ protected override void DiscoveryCenterDataReceived(INetworkMessage message)
private async Task StartServer()
{
_webSocketServer = WebSocketHostBuilder.Create()
.UseWebSocketMessageHandler(WebSocketMessageHandler)
.UseSessionHandler(OnConnected, OnDisconnected)
.ConfigureAppConfiguration((Action<HostBuilderContext, IConfigurationBuilder>)(ConfigureWebServer)).Build();
.UseWebSocketMessageHandler(WebSocketMessageHandler)
.UseSessionHandler(OnConnected, OnDisconnected)
.ConfigureAppConfiguration((Action<HostBuilderContext, IConfigurationBuilder>)(ConfigureWebServer)).Build();
await _webSocketServer.StartAsync();
_tcpService = SuperSocketHostBuilder.Create<INetworkMessage, MessageObjectPipelineFilter>()
.ConfigureSuperSocket(ConfigureSuperSocket)
.UseClearIdleSession()
.UsePackageDecoder<MessageRouterDecoderHandler>()
.UseSessionHandler(OnConnected, OnDisconnected)
.UsePackageHandler(MessagePackageHandler, ClientErrorHandler)
.UseInProcSessionContainer()
.BuildAsServer();
.ConfigureSuperSocket(ConfigureSuperSocket)
.UseClearIdleSession()
.UsePackageDecoder<MessageRouterDecoderHandler>()
.UseSessionHandler(OnConnected, OnDisconnected)
.UsePackageHandler(MessagePackageHandler, ClientErrorHandler)
.UseInProcSessionContainer()
.BuildAsServer();

await _tcpService.StartAsync();
}
Expand All @@ -100,7 +100,7 @@ private ValueTask OnDisconnected(IAppSession appSession, CloseEventArgs disconne
private ValueTask OnConnected(IAppSession appSession)
{
LogHelper.Info("有外部客户端网络连接成功!。链接信息:SessionID:" + appSession.SessionID + " RemoteEndPoint:" + appSession.RemoteEndPoint);
var netChannel = new DefaultNetWorkChannel(appSession, messageEncoderHandler, RpcSession, appSession is WebSocketSession);
var netChannel = new DefaultNetWorkChannel(appSession, Setting, messageEncoderHandler, RpcSession, appSession is WebSocketSession);
GameClientSessionManager.SetSession(appSession.SessionID, netChannel); //移除

return ValueTask.CompletedTask;
Expand All @@ -120,8 +120,8 @@ private async ValueTask WebSocketMessageHandler(WebSocketSession session, WebSoc
return;
}

var bytes = message.Data;
var buffer = bytes.ToArray();
var bytes = message.Data;
var buffer = bytes.ToArray();
var messageObject = messageDecoderHandler.Handler(buffer);
await MessagePackageHandler(session, messageObject);
}
Expand All @@ -144,10 +144,10 @@ private ValueTask MessagePackageHandler(IAppSession appSession, INetworkMessage
{
var reqHeartBeat = (ReqHeartBeat)outerMessage.DeserializeMessageObject();
var response = new NotifyHeartBeat()
{
UniqueId = reqHeartBeat.UniqueId,
Timestamp = TimeHelper.UnixTimeSeconds()
};
{
UniqueId = reqHeartBeat.UniqueId,
Timestamp = TimeHelper.UnixTimeSeconds()
};
SendToClient(appSession, response);
return ValueTask.CompletedTask;
}
Expand Down Expand Up @@ -191,7 +191,7 @@ private static async void SendToClient(IAppSession appSession, MessageObject mes
private void ConfigureWebServer(HostBuilderContext context, IConfigurationBuilder builder)
{
builder.AddInMemoryCollection(new Dictionary<string, string>()
{ { "serverOptions:name", "TestServer" }, { "serverOptions:listeners:0:ip", "Any" }, { "serverOptions:listeners:0:port", Setting.WsPort.ToString() } });
{ { "serverOptions:name", "TestServer" }, { "serverOptions:listeners:0:ip", "Any" }, { "serverOptions:listeners:0:port", Setting.WsPort.ToString() } });
}

public override async Task StopAsync(string message = "")
Expand All @@ -207,17 +207,17 @@ protected override void Init()
if (Setting == null)
{
Setting = new AppSetting
{
ServerId = 3000,
ServerType = ServerType.Router,
InnerPort = 23001,
WsPort = 23110,
// 网关配置
DiscoveryCenterIp = "127.0.0.1",
DiscoveryCenterPort = 21001,
// 最大连接数
MaxClientCount = 3000,
};
{
ServerId = 3000,
ServerType = ServerType.Router,
InnerPort = 23001,
WsPort = 23110,
// 网关配置
DiscoveryCenterIp = "127.0.0.1",
DiscoveryCenterPort = 21001,
// 最大连接数
MaxClientCount = 3000,
};
if (PlatformRuntimeHelper.IsLinux)
{
Setting.DiscoveryCenterIp = "gateway";
Expand Down

0 comments on commit 87598a8

Please sign in to comment.