From d800531aaca6d65b1a1a59b3fb1d9dcfcf2834e9 Mon Sep 17 00:00:00 2001 From: Ruslan Pyrch Date: Thu, 18 Apr 2024 16:04:31 +0300 Subject: [PATCH] add SendUnconnectedMessage with ReadOnlySpan argument --- LiteNetLib/NetManager.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/LiteNetLib/NetManager.cs b/LiteNetLib/NetManager.cs index 737f616f..64e3a66c 100644 --- a/LiteNetLib/NetManager.cs +++ b/LiteNetLib/NetManager.cs @@ -1268,6 +1268,21 @@ public void SendToAll(ReadOnlySpan data, byte channelNumber, DeliveryMetho _peersLock.ExitReadLock(); } } + + /// + /// Send message without connection + /// + /// Raw data + /// Packet destination + /// Operation result + public bool SendUnconnectedMessage(ReadOnlySpan message, IPEndPoint remoteEndPoint) + { + int headerSize = NetPacket.GetHeaderSize(PacketProperty.UnconnectedMessage); + var packet = PoolGetPacket(message.Length + headerSize); + packet.Property = PacketProperty.UnconnectedMessage; + message.CopyTo(new Span(packet.RawData, headerSize, message.Length)); + return SendRawAndRecycle(packet, remoteEndPoint) > 0; + } #endif ///