From 1756d8d1835f04eb23da9ea986d8a9b3069c56c0 Mon Sep 17 00:00:00 2001 From: AlianBlank Date: Mon, 29 Jul 2024 18:17:03 +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 --- .../Common/HotfixBridgeByServer.cs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/GameFrameX.Hotfix/Common/HotfixBridgeByServer.cs b/GameFrameX.Hotfix/Common/HotfixBridgeByServer.cs index 861e363a..2933c7ce 100644 --- a/GameFrameX.Hotfix/Common/HotfixBridgeByServer.cs +++ b/GameFrameX.Hotfix/Common/HotfixBridgeByServer.cs @@ -49,19 +49,19 @@ public async void RunServer(bool reload) 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(); LogHelper.Info("启动 WebSocket 服务器完成..."); 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(); LogHelper.Info("启动 TCP 服务器完成..."); @@ -92,7 +92,8 @@ 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, null, appSession is WebSocketSession); + + var netChannel = new DefaultNetWorkChannel(appSession, Setting, messageEncoderHandler, null, appSession is WebSocketSession); GameClientSessionManager.SetSession(appSession.SessionID, netChannel); //移除 return ValueTask.CompletedTask; @@ -114,8 +115,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); } @@ -129,10 +130,9 @@ private async ValueTask MessagePackageHandler(IAppSession appSession, INetworkMe { if (messageObject is MessageObject message) { - var messageId = message.MessageId; if (Setting.IsDebug && Setting.IsDebugReceive) { - LogHelper.Debug($"---收到消息:[{messageId},{message.GetType().Name}] 消息内容:[{messageObject}]"); + LogHelper.Debug($"---收到{messageObject.ToFormatMessageString()}"); } var handler = HotfixManager.GetTcpHandler(message.MessageId); @@ -142,7 +142,7 @@ private async ValueTask MessagePackageHandler(IAppSession appSession, INetworkMe return; } - handler.Message = message; + handler.Message = message; handler.NetWorkChannel = GameClientSessionManager.GetSession(appSession.SessionID); await handler.Init(); await handler.InnerAction(); @@ -152,7 +152,7 @@ private async ValueTask MessagePackageHandler(IAppSession appSession, INetworkMe private void ConfigureWebServer(HostBuilderContext context, IConfigurationBuilder builder) { builder.AddInMemoryCollection(new Dictionary() - { { "serverOptions:name", "GameServer" }, { "serverOptions:listeners:0:ip", "Any" }, { "serverOptions:listeners:0:port", Setting.WsPort.ToString() } }); + { { "serverOptions:name", "GameServer" }, { "serverOptions:listeners:0:ip", "Any" }, { "serverOptions:listeners:0:port", Setting.WsPort.ToString() } }); } public async Task StopServer()