From 87598a8488ec25f64b9aef260a08d7f872643dc7 Mon Sep 17 00:00:00 2001 From: AlianBlank Date: Mon, 29 Jul 2024 18:16:38 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BF=AE=E6=94=B9]1.=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=8F=82=E6=95=B0=E7=9A=84=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StartUp/Gateway/AppStartUpGateway.cs | 2 +- .../StartUp/Router/AppStartUpRouter.cs | 58 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/GameFrameX.Launcher/StartUp/Gateway/AppStartUpGateway.cs b/GameFrameX.Launcher/StartUp/Gateway/AppStartUpGateway.cs index 824040a8..2b7ee873 100644 --- a/GameFrameX.Launcher/StartUp/Gateway/AppStartUpGateway.cs +++ b/GameFrameX.Launcher/StartUp/Gateway/AppStartUpGateway.cs @@ -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; } diff --git a/GameFrameX.Launcher/StartUp/Router/AppStartUpRouter.cs b/GameFrameX.Launcher/StartUp/Router/AppStartUpRouter.cs index 76ac7fde..6e223dbe 100644 --- a/GameFrameX.Launcher/StartUp/Router/AppStartUpRouter.cs +++ b/GameFrameX.Launcher/StartUp/Router/AppStartUpRouter.cs @@ -68,18 +68,18 @@ protected override void DiscoveryCenterDataReceived(INetworkMessage message) private async Task StartServer() { _webSocketServer = WebSocketHostBuilder.Create() - .UseWebSocketMessageHandler(WebSocketMessageHandler) - .UseSessionHandler(OnConnected, OnDisconnected) - .ConfigureAppConfiguration((Action)(ConfigureWebServer)).Build(); + .UseWebSocketMessageHandler(WebSocketMessageHandler) + .UseSessionHandler(OnConnected, OnDisconnected) + .ConfigureAppConfiguration((Action)(ConfigureWebServer)).Build(); await _webSocketServer.StartAsync(); _tcpService = SuperSocketHostBuilder.Create() - .ConfigureSuperSocket(ConfigureSuperSocket) - .UseClearIdleSession() - .UsePackageDecoder() - .UseSessionHandler(OnConnected, OnDisconnected) - .UsePackageHandler(MessagePackageHandler, ClientErrorHandler) - .UseInProcSessionContainer() - .BuildAsServer(); + .ConfigureSuperSocket(ConfigureSuperSocket) + .UseClearIdleSession() + .UsePackageDecoder() + .UseSessionHandler(OnConnected, OnDisconnected) + .UsePackageHandler(MessagePackageHandler, ClientErrorHandler) + .UseInProcSessionContainer() + .BuildAsServer(); await _tcpService.StartAsync(); } @@ -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; @@ -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); } @@ -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; } @@ -191,7 +191,7 @@ private static async void SendToClient(IAppSession appSession, MessageObject mes private void ConfigureWebServer(HostBuilderContext context, IConfigurationBuilder builder) { builder.AddInMemoryCollection(new Dictionary() - { { "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 = "") @@ -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";