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

Fixed suspicious non-maxsizes

This commit is contained in:
Sanae 2022-02-09 19:52:33 -06:00
parent 7dbe2ecd55
commit 691086fdb9
2 changed files with 5 additions and 5 deletions

View file

@ -44,7 +44,7 @@ public class Server {
// broadcast packets to all clients
public async Task Broadcast<T>(T packet, Client? sender = null) where T : unmanaged, IPacket {
IMemoryOwner<byte> memory = memoryPool.Rent(Marshal.SizeOf<T>() + Constants.HeaderSize);
IMemoryOwner<byte> memory = memoryPool.Rent(Constants.MaxPacketSize);
PacketHeader header = new PacketHeader {
Id = sender?.Id ?? Guid.Empty,
@ -142,7 +142,7 @@ public class Server {
List<Client> otherConnectedPlayers = Clients.FindAll(c => c.Id != header.Id && c.Connected && c.Socket != null);
await Parallel.ForEachAsync(otherConnectedPlayers, async (other, _) => {
IMemoryOwner<byte> connectBuffer = MemoryPool<byte>.Shared.Rent(256);
IMemoryOwner<byte> connectBuffer = MemoryPool<byte>.Shared.Rent(Constants.MaxPacketSize);
PacketHeader connectHeader = new PacketHeader {
Id = other.Id,
Type = PacketType.Connect

View file

@ -27,7 +27,7 @@ PacketType[] reboundPackets = {
};
async Task S() {
IMemoryOwner<byte> owner = MemoryPool<byte>.Shared.Rent(256);
IMemoryOwner<byte> owner = MemoryPool<byte>.Shared.Rent(Constants.MaxPacketSize);
while (true) {
await stream.ReadAsync(owner.Memory);
PacketHeader header = MemoryMarshal.Read<PacketHeader>(owner.Memory.Span);
@ -43,12 +43,12 @@ PacketHeader coolHeader = new PacketHeader {
Type = PacketType.Connect,
Id = ownId
};
IMemoryOwner<byte> owner = MemoryPool<byte>.Shared.Rent(256);
IMemoryOwner<byte> owner = MemoryPool<byte>.Shared.Rent(Constants.MaxPacketSize);
MemoryMarshal.Write(owner.Memory.Span[..], ref coolHeader);
ConnectPacket connect = new ConnectPacket {
ConnectionType = ConnectionTypes.FirstConnection
};
MemoryMarshal.Write(owner.Memory.Span[Constants.HeaderSize..256], ref connect);
MemoryMarshal.Write(owner.Memory.Span[Constants.HeaderSize..Constants.MaxPacketSize], ref connect);
await stream.WriteAsync(owner.Memory);
coolHeader.Type = PacketType.Player;
MemoryMarshal.Write(owner.Memory.Span[..], ref coolHeader);