public override void Send(ulong clientId, ArraySegment <byte> data, NetworkChannel networkChannel) { if (ProfilerEnabled) { s_TransportProfilerData.Increment(ProfilerConstants.NumberOfTransportSends); } GetUNetConnectionDetails(clientId, out byte hostId, out ushort connectionId); int channelId = 0; if (m_ChannelNameToId.TryGetValue(networkChannel, out int value)) { channelId = value; } else { channelId = m_ChannelNameToId[NetworkChannel.Internal]; } byte[] buffer; if (data.Offset > 0) { // UNET cant handle this, do a copy if (m_MessageBuffer.Length >= data.Count) { buffer = m_MessageBuffer; } else { object bufferRef = null; if (m_TemporaryBufferReference != null && ((bufferRef = m_TemporaryBufferReference.Target) != null) && ((byte[])bufferRef).Length >= data.Count) { buffer = (byte[])bufferRef; } else { buffer = new byte[data.Count]; m_TemporaryBufferReference = new WeakReference(buffer); } } Buffer.BlockCopy(data.Array, data.Offset, buffer, 0, data.Count); } else { buffer = data.Array; } if (MessageSendMode == SendMode.Queued) { RelayTransport.QueueMessageForSending(hostId, connectionId, channelId, buffer, data.Count, out byte error); } else { RelayTransport.Send(hostId, connectionId, channelId, buffer, data.Count, out byte error); } }
public override void Send(ulong clientId, ArraySegment <byte> data, string channelName, bool skipQueue) { UpdateRelay(); GetUnetConnectionDetails(clientId, out byte hostId, out ushort connectionId); int channelId = channelNameToId[channelName]; byte[] buffer; if (data.Offset > 0) { // UNET cant handle this, do a copy if (messageBuffer.Length >= data.Count) { buffer = messageBuffer; } else { if (temporaryBufferReference != null && temporaryBufferReference.IsAlive && ((byte[])temporaryBufferReference.Target).Length >= data.Count) { buffer = (byte[])temporaryBufferReference.Target; } else { buffer = new byte[data.Count]; temporaryBufferReference = new WeakReference(buffer); } } Buffer.BlockCopy(data.Array, data.Offset, buffer, 0, data.Count); } else { buffer = data.Array; } if (skipQueue) { RelayTransport.Send(hostId, connectionId, channelId, buffer, data.Count, out byte error); } else { RelayTransport.QueueMessageForSending(hostId, connectionId, channelId, buffer, data.Count, out byte error); } }
public void QueueMessageForSending(uint clientId, byte[] dataBuffer, int dataSize, int channelId, bool skipqueue, out byte error) { NetId netId = new NetId(clientId); if (netId.IsServer()) { netId.ConnectionId = (ushort)serverConnectionId; netId.HostId = (byte)serverHostId; } if (skipqueue) { RelayTransport.Send(netId.HostId, netId.ConnectionId, channelId, dataBuffer, dataSize, out error); } else { RelayTransport.QueueMessageForSending(netId.HostId, netId.ConnectionId, channelId, dataBuffer, dataSize, out error); } }