Skip to content

Commit

Permalink
[增加]1. 增加消息压缩器和解压缩器的设置
Browse files Browse the repository at this point in the history
  • Loading branch information
AlianBlank committed Aug 13, 2024
1 parent 426b06e commit 568e876
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions GameFrameX.Hotfix/Common/HotfixBridgeByServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using GameFrameX.NetWork.Messages;
using GameFrameX.SuperSocket.Connection;
using GameFrameX.SuperSocket.Primitives;
using GameFrameX.SuperSocket.ProtoBase;
using GameFrameX.SuperSocket.Server;
using GameFrameX.SuperSocket.Server.Abstractions;
using GameFrameX.SuperSocket.Server.Abstractions.Session;
Expand Down Expand Up @@ -52,6 +53,8 @@ public async void RunServer(bool reload)

private async Task StartServer()
{
messageEncoderHandler.SetCompressionHandler(new BaseMessageCompressHandler());
messageDecoderHandler.SetDecompressionHandler(new BaseMessageDecompressHandler());
if (Setting.WsPort > 0)
{
LogHelper.Info("启动 WebSocket 服务器开始...");
Expand All @@ -75,6 +78,9 @@ private async Task StartServer()
.UseInProcSessionContainer()
.BuildAsServer();

// 设置消息解压缩的处理器
var baseMessageDecoderHandler = (BaseMessageDecoderHandler)tcpService.ServiceProvider.GetService(typeof(IPackageDecoder<INetworkMessage>));
baseMessageDecoderHandler?.SetDecompressionHandler(new BaseMessageDecompressHandler());
await tcpService.StartAsync();
LogHelper.Info("启动 TCP 服务器完成...");
}
Expand Down Expand Up @@ -127,8 +133,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 @@ -154,7 +160,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();
Expand All @@ -164,7 +170,7 @@ private async ValueTask MessagePackageHandler(IAppSession appSession, INetworkMe
private void ConfigureWebServer(HostBuilderContext context, IConfigurationBuilder builder)
{
builder.AddInMemoryCollection(new Dictionary<string, string>()
{ { "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()
Expand Down

0 comments on commit 568e876

Please sign in to comment.