Archived
1
0
Fork 0
forked from Moux23333/FreeSR
This repository has been archived on 2024-03-30. You can view files and clone it, but cannot push or open issues or pull requests.
FreeSR/FreeSR.Gateserver/Network/NetSession.cs

48 lines
1.1 KiB
C#
Raw Normal View History

2024-01-27 13:06:07 +00:00
namespace FreeSR.Gateserver.Network
{
using DotNetty.Buffers;
using DotNetty.Transport.Channels;
using FreeSR.Gateserver.Network.Packet;
using FreeSR.Proto;
internal class NetSession
{
private IChannel _channel;
public NetSession(IChannel channel)
{
_channel = channel;
}
public async void Send<T>(CmdType cmdId, T data) where T : class
{
var packet = new NetPacket()
{
CmdId = (int)cmdId,
Data = data
};
var buffer = Unpooled.Buffer();
packet.Serialize<T>(buffer);
packet.Buf = buffer;
await _channel.WriteAndFlushAsync(packet);
}
2024-01-27 13:08:24 +00:00
public async void Send<T>(int cmdId, T data) where T : class
{
var packet = new NetPacket()
{
CmdId = cmdId,
Data = data
};
var buffer = Unpooled.Buffer();
packet.Serialize<T>(buffer);
packet.Buf = buffer;
await _channel.WriteAndFlushAsync(packet);
}
2024-01-27 13:06:07 +00:00
}
}