From a64b5f295984987118a83f3d57613171db1e948f Mon Sep 17 00:00:00 2001 From: lidgren Date: Wed, 2 Nov 2011 09:47:22 +0000 Subject: [PATCH] Added SendUnconnectedToSelf() --- Lidgren.Network/NetPeer.Send.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Lidgren.Network/NetPeer.Send.cs b/Lidgren.Network/NetPeer.Send.cs index 7599373..95c7696 100644 --- a/Lidgren.Network/NetPeer.Send.cs +++ b/Lidgren.Network/NetPeer.Send.cs @@ -145,6 +145,7 @@ namespace Lidgren.Network throw new NetException("Failed to resolve " + host); msg.m_messageType = NetMessageType.Unconnected; + msg.m_isSent = true; Interlocked.Increment(ref msg.m_recyclingCount); m_unsentUnconnectedMessages.Enqueue(new NetTuple(new IPEndPoint(adr, port), msg)); @@ -194,5 +195,31 @@ namespace Lidgren.Network foreach(IPEndPoint ep in recipients) m_unsentUnconnectedMessages.Enqueue(new NetTuple(ep, msg)); } + + /// + /// Send a message to this exact same netpeer (loopback) + /// + public void SendUnconnectedToSelf(NetOutgoingMessage msg) + { + if (msg == null) + throw new ArgumentNullException("msg"); + if (msg.m_isSent) + throw new NetException("This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently"); + + msg.m_messageType = NetMessageType.Unconnected; + msg.m_isSent = true; + + if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.UnconnectedData) == false) + return; // dropping unconnected message since it's not enabled for receiving + + NetIncomingMessage om = CreateIncomingMessage(NetIncomingMessageType.UnconnectedData, msg.LengthBytes); + om.m_isFragment = false; + om.m_receiveTime = NetTime.Now; + om.m_senderConnection = null; + om.m_senderEndpoint = m_socket.LocalEndPoint as IPEndPoint; + om.m_bitLength = msg.LengthBits; + + ReleaseMessage(om); + } } }