mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-21 18:55:17 +00:00
Revert potential scenario merging fix
This commit is contained in:
parent
e75df1bbb4
commit
aea7d4414f
2 changed files with 9 additions and 8 deletions
|
@ -38,6 +38,7 @@ public class Client : IDisposable {
|
||||||
|
|
||||||
public async Task Send<T>(T packet, Client? sender = null) where T : struct, IPacket {
|
public async Task Send<T>(T packet, Client? sender = null) where T : struct, IPacket {
|
||||||
IMemoryOwner<byte> memory = MemoryPool<byte>.Shared.RentZero(Constants.HeaderSize + packet.Size);
|
IMemoryOwner<byte> memory = MemoryPool<byte>.Shared.RentZero(Constants.HeaderSize + packet.Size);
|
||||||
|
packet = (T) (PacketTransformer?.Invoke(sender, packet) ?? packet);
|
||||||
PacketHeader header = new PacketHeader {
|
PacketHeader header = new PacketHeader {
|
||||||
Id = sender?.Id ?? Id,
|
Id = sender?.Id ?? Id,
|
||||||
Type = Constants.PacketMap[typeof(T)].Type,
|
Type = Constants.PacketMap[typeof(T)].Type,
|
||||||
|
@ -55,13 +56,13 @@ public class Client : IDisposable {
|
||||||
}
|
}
|
||||||
|
|
||||||
int packetSize = MemoryMarshal.Read<short>(data.Span[18..]);
|
int packetSize = MemoryMarshal.Read<short>(data.Span[18..]);
|
||||||
if (PacketTransformer != null) {
|
// if (PacketTransformer != null) {
|
||||||
PacketType type = MemoryMarshal.Read<PacketType>(data.Span[16..]);
|
// PacketType type = MemoryMarshal.Read<PacketType>(data.Span[16..]);
|
||||||
IPacket packet = (IPacket) Activator.CreateInstance(Constants.PacketIdMap[type])!;
|
// IPacket packet = (IPacket) Activator.CreateInstance(Constants.PacketIdMap[type])!;
|
||||||
packet.Deserialize(data.Span);
|
// packet.Deserialize(data.Span);
|
||||||
packet = PacketTransformer?.Invoke(sender, packet) ?? packet;
|
// packet = PacketTransformer?.Invoke(sender, packet) ?? packet;
|
||||||
packet.Serialize(data.Span);
|
// packet.Serialize(data.Span);
|
||||||
}
|
// }
|
||||||
await Socket!.SendAsync(data[..(Constants.HeaderSize + packetSize)], SocketFlags.None);
|
await Socket!.SendAsync(data[..(Constants.HeaderSize + packetSize)], SocketFlags.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ public struct GamePacket : IPacket {
|
||||||
public short Size => 0x32;
|
public short Size => 0x32;
|
||||||
public void Serialize(Span<byte> data) {
|
public void Serialize(Span<byte> data) {
|
||||||
MemoryMarshal.Write(data[..0], ref Is2d);
|
MemoryMarshal.Write(data[..0], ref Is2d);
|
||||||
MemoryMarshal.Write(data[1..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)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue