Send connect packets to new connection for other players

This commit is contained in:
Sanae 2022-02-09 19:42:46 -06:00
parent 6771707dae
commit 351304f99f
2 changed files with 16 additions and 1 deletions

View File

@ -138,6 +138,21 @@ public class Server {
// done disconnecting and removing stale clients with the same id
}
}
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);
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.");
}

View File

@ -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");