mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-25 12:45:18 +00:00
Read header normally
This commit is contained in:
parent
1f57a9fb65
commit
1bcb15eb54
1 changed files with 7 additions and 8 deletions
|
@ -47,22 +47,21 @@ public class Client : IDisposable {
|
||||||
PacketSize = packet.Size
|
PacketSize = packet.Size
|
||||||
};
|
};
|
||||||
Server.FillPacket(header, packet, memory.Memory);
|
Server.FillPacket(header, packet, memory.Memory);
|
||||||
await Send(memory.Memory[..], sender);
|
await Send(memory.Memory, sender);
|
||||||
memory.Dispose();
|
memory.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Send(Memory<byte> data, Client? sender) {
|
public async Task Send(Memory<byte> data, Client? sender) {
|
||||||
PacketType packetType = MemoryMarshal.Read<PacketType>(data.Span[16..]);
|
PacketHeader header = MemoryMarshal.Read<PacketHeader>(data.Span);
|
||||||
if (!Connected && packetType is not PacketType.Connect) {
|
if (!Connected && header.Type is not PacketType.Connect) {
|
||||||
Server.Logger.Error($"Didn't send {packetType} to {Id} because they weren't connected yet");
|
Server.Logger.Error($"Didn't send {header.Type} to {Id} because they weren't connected yet");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packetType is not PacketType.Cap and not PacketType.Player)
|
if (header.Type is not PacketType.Cap and not PacketType.Player)
|
||||||
Logger.Info($"About to receive {packetType} +");
|
Logger.Info($"About to receive {header.Type} +");
|
||||||
|
|
||||||
int packetSize = MemoryMarshal.Read<short>(data.Span[18..]);
|
await Socket!.SendAsync(data[..(Constants.HeaderSize + header.PacketSize)], SocketFlags.None);
|
||||||
await Socket!.SendAsync(data[..(Constants.HeaderSize + packetSize)], SocketFlags.None);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator ==(Client? left, Client? right) {
|
public static bool operator ==(Client? left, Client? right) {
|
||||||
|
|
Loading…
Reference in a new issue