From 351304f99f90d39fc2560875c001c0ce8ef5a260 Mon Sep 17 00:00:00 2001 From: Sanae Date: Wed, 9 Feb 2022 19:42:46 -0600 Subject: [PATCH] Send connect packets to new connection for other players --- Server/Server.cs | 15 +++++++++++++++ TestClient/Program.cs | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Server/Server.cs b/Server/Server.cs index b5f61fe..db0ba3c 100644 --- a/Server/Server.cs +++ b/Server/Server.cs @@ -138,6 +138,21 @@ public class Server { // done disconnecting and removing stale clients with the same id } } + List otherConnectedPlayers = Clients.FindAll(c => c.Id != header.Id && c.Connected && c.Socket != null); + await Parallel.ForEachAsync(otherConnectedPlayers, async (other, _) => { + IMemoryOwner connectBuffer = MemoryPool.Shared.Rent(256); + PacketHeader connectHeader = new PacketHeader() { + Id = other.Id, + Type = PacketType.Connect + }; + MemoryMarshal.Write(connectBuffer.Memory.Span, ref connectHeader); + ConnectPacket connectPacket = new ConnectPacket() { + ConnectionType = ConnectionTypes.FirstConnection // doesn't matter what it is :) + }; + MemoryMarshal.Write(connectBuffer.Memory.Span, ref connectPacket); + await client.Send(connectBuffer.Memory); + connectBuffer.Dispose(); + }); Logger.Info($"Client {socket.RemoteEndPoint} ({client.Id}) connected."); } diff --git a/TestClient/Program.cs b/TestClient/Program.cs index 5a14bdb..9c9e981 100644 --- a/TestClient/Program.cs +++ b/TestClient/Program.cs @@ -7,7 +7,7 @@ using Shared; using Shared.Packet; using Shared.Packet.Packets; -TcpClient client = new TcpClient("127.0.0.1", 1027); +TcpClient client = new TcpClient(args[0], 1027); Guid ownId = new Guid(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); Guid otherId = Guid.Empty; Logger logger = new Logger("Client");