fork from 1.3

This commit is contained in:
moux23333
2024-01-27 21:06:07 +08:00
commit 22fc0b0848
1507 changed files with 24139 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
namespace FreeSR.Gateserver.Network.Handlers.Decoder
{
using DotNetty.Buffers;
using DotNetty.Codecs;
using DotNetty.Transport.Channels;
using FreeSR.Gateserver.Network.Packet;
using NLog;
internal class PacketDecoder : MessageToMessageDecoder<IByteBuffer>
{
private static readonly Logger s_log = LogManager.GetCurrentClassLogger();
protected override void Decode(IChannelHandlerContext context, IByteBuffer message, List<object> output)
{
var netPacket = new NetPacket();
DeserializationResult result;
if ((result = netPacket.Deserialize(message)) != DeserializationResult.SUCC)
{
context.CloseAsync();
s_log.Info("Closing connection, reason: " + result);
return;
}
output.Add(netPacket);
}
}
}

View File

@@ -0,0 +1,53 @@
namespace FreeSR.Gateserver.Network.Handlers.Decoder
{
using DotNetty.Buffers;
using DotNetty.Codecs;
using DotNetty.Transport.Channels;
internal class StarRailHeaderDecoder : ByteToMessageDecoder
{
private IByteBuffer _current;
public StarRailHeaderDecoder()
{
_current = Unpooled.Buffer();
}
protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List<object> output)
{
var allocated = Unpooled.Buffer();
allocated.WriteBytes(_current);
allocated.WriteBytes(input);
_current = allocated;
byte[] lands = new byte[_current.ReadableBytes];
_current.ReadBytes(lands);
_current.ResetReaderIndex();
IByteBuffer packet;
while ((packet = Process()) != null)
output.Add(packet);
}
private IByteBuffer Process()
{
if (_current.ReadableBytes < 12)
return null;
_current.ReadInt(); // headMagic
_current.ReadShort(); // CmdID
int headerLength = _current.ReadShort();
int payloadLength = _current.ReadInt();
int totalLength = 12 + headerLength + payloadLength + 4;
_current.ResetReaderIndex();
if (_current.ReadableBytes < totalLength)
return null;
IByteBuffer result = _current.ReadBytes(totalLength);
_current = _current.ReadBytes(_current.ReadableBytes);
return result;
}
}
}