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
2024-01-27 21:08:24 +08:00

47 lines
1.1 KiB
C#

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);
}
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);
}
}
}