0
0
Fork 0
mirror of https://github.com/Sanae6/SmoOnlineServer.git synced 2024-11-22 03:05:16 +00:00

I'm going to commit war crimes

This commit is contained in:
Sanae 2022-04-27 14:17:02 -06:00
parent df2e976782
commit 605be3947f
3 changed files with 6 additions and 7 deletions

View file

@ -41,15 +41,14 @@ public class Client : IDisposable {
if (packetAttribute.Type is not PacketType.Cap and not PacketType.Player) if (packetAttribute.Type is not PacketType.Cap and not PacketType.Player)
Logger.Info($"Pre-header {packetAttribute.Type} ({(short)packetAttribute.Type}) - {typeof(T)}"); Logger.Info($"Pre-header {packetAttribute.Type} ({(short)packetAttribute.Type}) - {typeof(T)}");
try { try {
PacketHeader header = new PacketHeader { Server.FillPacket(new PacketHeader {
Id = sender?.Id ?? Id, Id = sender?.Id ?? Id,
Type = packetAttribute.Type, Type = packetAttribute.Type,
PacketSize = packet.Size PacketSize = packet.Size
}; }, packet, memory.Memory);
Server.FillPacket(header, packet, memory.Memory);
} }
catch (Exception e) { catch (Exception e) {
Logger.Error($"I will lose my shit {e}"); Logger.Error($"I will lose my shit {e} {memory.Memory.Span[..Constants.HeaderSize].Length} {memory.Memory.Span[Constants.HeaderSize..].Length} {packet.Size}");
} }
if (packetAttribute.Type is not PacketType.Cap and not PacketType.Player) if (packetAttribute.Type is not PacketType.Cap and not PacketType.Player)

View file

@ -59,7 +59,7 @@ public class Server {
public static void FillPacket<T>(PacketHeader header, T packet, Memory<byte> memory) where T : struct, IPacket { public static void FillPacket<T>(PacketHeader header, T packet, Memory<byte> memory) where T : struct, IPacket {
Span<byte> data = memory.Span; Span<byte> data = memory.Span;
header.Serialize(data[..Constants.HeaderSize]); header.Serialize(data[..Constants.HeaderSize]);
packet.Serialize(data[Constants.HeaderSize..]); packet.Serialize(data[Constants.HeaderSize..]);
} }

View file

@ -12,9 +12,9 @@ public struct GamePacket : IPacket {
public GamePacket() { } public GamePacket() { }
public short Size => 0x3A; public short Size => 0x3C;
public void Serialize(Span<byte> data) { public void Serialize(Span<byte> data) {
MemoryMarshal.Write(data[..0], ref Is2d); MemoryMarshal.Write(data, ref Is2d);
MemoryMarshal.Write(data[1..], ref ScenarioNum); MemoryMarshal.Write(data[1..], ref ScenarioNum);
Encoding.UTF8.GetBytes(Stage).CopyTo(data[2..(2 + StageSize)]); Encoding.UTF8.GetBytes(Stage).CopyTo(data[2..(2 + StageSize)]);
} }