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

Updated test client to send varsize packets, 8p test

This commit is contained in:
Sanae 2022-03-14 17:48:30 -06:00
parent 15960a8d5a
commit 3974b7022e
2 changed files with 84 additions and 72 deletions

View file

@ -13,14 +13,14 @@ public struct PacketHeader : IPacket {
public short Size => 20; public short Size => 20;
public void Serialize(Span<byte> data) { public void Serialize(Span<byte> data) {
// MemoryMarshal.Write(data, ref Length);
MemoryMarshal.Write(data, ref Id); MemoryMarshal.Write(data, ref Id);
MemoryMarshal.Write(data[16..], ref Type); MemoryMarshal.Write(data[16..], ref Type);
MemoryMarshal.Write(data[18..], ref PacketSize);
} }
public void Deserialize(Span<byte> data) { public void Deserialize(Span<byte> data) {
Id = MemoryMarshal.Read<Guid>(data); Id = MemoryMarshal.Read<Guid>(data);
Type = MemoryMarshal.Read<PacketType>(data[16..]); Type = MemoryMarshal.Read<PacketType>(data[16..]);
Type = MemoryMarshal.Read<PacketType>(data[16..]); PacketSize = MemoryMarshal.Read<short>(data[16..]);
} }
} }

View file

@ -6,73 +6,85 @@ using Shared;
using Shared.Packet; using Shared.Packet;
using Shared.Packet.Packets; using Shared.Packet.Packets;
// TcpClient client = new TcpClient(args[0], 1027); // Guid ownId = new Guid(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
Guid ownId = new Guid(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); Guid baseOtherId = Guid.Parse("8ca3fcdd-2940-1000-b5f8-579301fcbfbb");
// Guid ownId = Guid.NewGuid();
// Guid otherId = Guid.Parse("d5feae62-2e71-1000-88fd-597ea147ae88"); PacketType[] reboundPackets = {
// Logger logger = new Logger("Client"); PacketType.Player,
// NetworkStream stream = client.GetStream(); PacketType.Cap,
// PacketType.Capture,
// Vector3 basePoint = Vector3.Zero; PacketType.Costume,
// PacketType.Tag,
// PacketType[] reboundPackets = { PacketType.Game,
// PacketType.Player,
// PacketType.Cap,
// PacketType.Capture,
// PacketType.Costume,
// PacketType.Tag,
// PacketType.Shine // PacketType.Shine
// }; };
//
// string lastCapture = ""; string lastCapture = "";
//
// async Task S() { async Task S(string n, Guid otherId, Guid ownId) {
// IMemoryOwner<byte> owner = MemoryPool<byte>.Shared.Rent(Constants.MaxPacketSize); Logger logger = new Logger($"Client ({n})");
// while (true) { TcpClient client = new TcpClient(args[0], 1027);
// await stream.ReadAsync(owner.Memory); NetworkStream stream = client.GetStream();
// PacketHeader header = MemoryMarshal.Read<PacketHeader>(owner.Memory.Span); logger.Info("Connected!");
// PacketType type = header.Type; async Task<bool> Read(Memory<byte> readMem, int readSize, int readOffset) {
// if (header.Id != otherId) continue; readSize += readOffset;
// if (type is PacketType.Player) { while (readOffset < readSize) {
// // CapPacket cap = new CapPacket(); int size = await stream.ReadAsync(readMem[readOffset..readSize]);
// PlayerPacket playerPacket = new PlayerPacket(); if (size == 0) {
// playerPacket.Deserialize(owner.Memory.Span[Constants.HeaderSize..]); // treat it as a disconnect and exit
// logger.Info(playerPacket.Hack); logger.Info($"Socket {client.Client.RemoteEndPoint} disconnected.");
// if (playerPacket.Hack != lastCapture) logger.Info($"Changed to hack: {lastCapture = playerPacket.Hack}"); return false;
// // cap.Position = playerPacket.Position + Vector3.UnitY * 500f; }
// // cap.Rotation = Quaternion.CreateFromYawPitchRoll(0,0,0);
// // cap.CapAnim = "StayR"; readOffset += size;
// // playerPacket.Position = new Vector3(1000000f); }
// // playerPacket.ThrowingCap = true;
// // header.Id = ownId; return true;
// // MemoryMarshal.Write(owner.Memory.Span, ref header); }
// // playerPacket.Serialize(owner.Memory.Span[Constants.HeaderSize..]);
// // await stream.WriteAsync(owner.Memory[..Constants.MaxPacketSize]); {
// // header.Type = PacketType.Cap; ConnectPacket connect = new ConnectPacket {
// // MemoryMarshal.Write(owner.Memory.Span, ref header); ConnectionType = ConnectPacket.ConnectionTypes.FirstConnection,
// // cap.Serialize(owner.Memory.Span[Constants.HeaderSize..]); ClientName = n
// // await stream.WriteAsync(owner.Memory[..Constants.MaxPacketSize]); };
// // continue; PacketHeader coolHeader = new PacketHeader {
// } Type = PacketType.Connect,
// Id = ownId,
// if (reboundPackets.All(x => x != type)) continue; PacketSize = connect.Size,
// header.Id = ownId; };
// MemoryMarshal.Write(owner.Memory.Span, ref header); IMemoryOwner<byte> connectOwner = MemoryPool<byte>.Shared.RentZero(Constants.HeaderSize + connect.Size);
// await stream.WriteAsync(owner.Memory[..Constants.MaxPacketSize]); // coolHeader.Serialize(connectOwner.Memory.Span[..Constants.HeaderSize]);
// } MemoryMarshal.Write(connectOwner.Memory.Span[..Constants.HeaderSize], ref coolHeader);
// } connect.Serialize(connectOwner.Memory.Span[Constants.HeaderSize..(Constants.HeaderSize + connect.Size)]);
// await stream.WriteAsync(connectOwner.Memory[..(Constants.HeaderSize + connect.Size)]);
// PacketHeader coolHeader = new PacketHeader { connectOwner.Dispose();
// Type = PacketType.Connect, }
// Id = ownId
// }; while (true) {
// IMemoryOwner<byte> owner = MemoryPool<byte>.Shared.RentZero(Constants.MaxPacketSize); IMemoryOwner<byte> owner = MemoryPool<byte>.Shared.RentZero(0xFF);
// MemoryMarshal.Write(owner.Memory.Span[..], ref coolHeader); if (!await Read(owner.Memory, Constants.HeaderSize, 0)) return;
// ConnectPacket connect = new ConnectPacket { PacketHeader header = MemoryMarshal.Read<PacketHeader>(owner.Memory.Span);
// ConnectionType = ConnectionTypes.Reconnecting, if (header.Size > 0) {
// ClientName = "Test Sanae" if (!await Read(owner.Memory, header.PacketSize, Constants.HeaderSize)) return;
// }; }
// connect.Serialize(owner.Memory.Span[Constants.HeaderSize..Constants.MaxPacketSize]); PacketType type = header.Type;
// await stream.WriteAsync(owner.Memory); if (header.Id != otherId) continue;
// logger.Info("Connected"); if (reboundPackets.All(x => x != type)) continue;
// await S(); if (type == PacketType.Player) {
}
header.Id = ownId;
MemoryMarshal.Write(owner.Memory.Span[..Constants.HeaderSize], ref header);
await stream.WriteAsync(owner.Memory[..(Constants.HeaderSize + header.PacketSize)]);
owner.Dispose();
}
}
Guid temp = baseOtherId;
IEnumerable<Task> stuff = Enumerable.Range(0, 7).Select(i => {
Guid newOwnId = Guid.NewGuid();
Task task = S($"Sussy {i}", temp, newOwnId);
temp = newOwnId;
return task;
});
await Task.WhenAll(stuff.ToArray());