diff --git a/Server/AuthSession.cs b/Server/AuthSession.cs index b466dfa..b85a459 100644 --- a/Server/AuthSession.cs +++ b/Server/AuthSession.cs @@ -71,11 +71,10 @@ public class AuthSession : TcpSession protected override void OnReceived(byte[] buffer, long offset, long size) { _logger.LogDebug("Length: {Size} & offset: {Offset}", size, offset); - Span decryptedBuffer = new byte[size]; + Span decryptedBuffer = stackalloc byte[(int)size]; // xor every value after the first 8 bytes - var dataBuffer = Decrypt(new ArraySegment(buffer, 8, (int)size - 8).ToArray()); - + var dataBuffer = Decrypt(buffer.AsSpan(8, (int)size - 8)); _logger.LogDebug("Length {Length}", BitConverter.ToUInt16(buffer, 0)); var opCode = BitConverter.ToUInt16(buffer.ToArray(), 2); @@ -99,7 +98,7 @@ public class AuthSession : TcpSession base.OnReceived(decryptedBuffer.ToArray(), offset, decryptedBuffer.Length); } - private static byte[] Decrypt(byte[] buffer) + private static Span Decrypt(Span buffer) { for (var i = 0; i < buffer.Length; ++i) { diff --git a/Server/Packets/RawPacket.cs b/Server/Packets/RawPacket.cs index 9080036..cb04ac6 100644 --- a/Server/Packets/RawPacket.cs +++ b/Server/Packets/RawPacket.cs @@ -8,10 +8,10 @@ namespace Server.Packets; [MessageUrn("packets")] public class RawPacket { - public RawPacket(OperationCode operationCode, byte[] messageBody, uint aliveTime, byte unknownValue2, + public RawPacket(OperationCode operationCode, Span messageBody, uint aliveTime, byte unknownValue2, byte unknownValue, Guid sessionId, AuthSession session) { - MessageBody = messageBody; + MessageBody = messageBody.ToArray(); UnknownValue2 = unknownValue2; UnknownValue = unknownValue; SessionId = sessionId;