public void SendPacketRaw(int type, byte[] data, ENetPeer peer, ENetPacketFlags flag = ENetPacketFlags.Reliable) { byte[] packetData = new byte[data.Length + 5]; Array.Copy(BitConverter.GetBytes(type), packetData, 4); Array.Copy(data, 0, packetData, 4, data.Length); SendData(packetData, peer); }
public ENetPacket(Span <byte> data, ENetPacketFlags flags) { fixed(byte *p = data) { m_Native = LibENet.PacketCreate(new IntPtr(p), unchecked ((UIntPtr)data.Length), flags); } }
public ENetPacket(int dataLength, ENetPacketFlags flags) { if (dataLength < 0) { throw new ArgumentOutOfRangeException(nameof(dataLength)); } m_Native = LibENet.PacketCreate(IntPtr.Zero, unchecked ((UIntPtr)dataLength), flags); }
internal ENetPacket(Native.ENetPacket *packet, byte channel) { Channel = channel; Flags = packet->Flags; m_Payload = new byte[packet->DataLength.ToUInt32()]; fixed(byte *dest = m_Payload) { Platform.Current.MemoryCopy((IntPtr)dest, (IntPtr)packet->Data, packet->DataLength); } }
public void SendData(byte[] data, ENetPeer peer, ENetPacketFlags flag = ENetPacketFlags.Reliable) { if (peer == null) { return; } if (peer.State != ENetPeerState.Connected) { return; } peer.Send((byte)rand.Next(0, 1), data, flag); }
public void Broadcast(byte[] buffer, byte channel, ENetPacketFlags flags) { CheckDispose(); Native.ENetPacket *packet; fixed(byte *p = buffer) { packet = LibENet.PacketCreate((IntPtr)p, (UIntPtr)buffer.Length, flags & ~ENetPacketFlags.NoAllocate); } LibENet.HostBroadcast(Pointer, channel, packet); }
public void Send(byte[] buffer, byte channel, ENetPacketFlags flags) { Native.ENetPacket *packet; fixed(byte *p = buffer) { packet = LibENet.PacketCreate((IntPtr)p, (UIntPtr)buffer.Length, flags & ~ENetPacketFlags.NoAllocate); } if (LibENet.PeerSend(Unsafe, channel, packet) < 0) { throw new Exception("Failed to send packet to peer."); } }
/// <summary> /// Queues a packet to be sent. /// </summary> /// <param name="channelId">Destination channel Id</param> /// <param name="buffer">Buffer containing packet data</param> /// <param name="flags">Packet flags</param> /// <remarks> /// <see cref="ENetPacketFlags.NoAllocate"/> will be ignored. /// </remarks> public void Send(byte channelId, ReadOnlySpan <byte> buffer, ENetPacketFlags flags) { ThrowIfNull(); NativeENetPacket *packet; fixed(byte *p = buffer) { packet = LibENet.PacketCreate((IntPtr)p, unchecked ((UIntPtr)buffer.Length), flags & ~ENetPacketFlags.NoAllocate); } if (LibENet.PeerSend(m_Native, channelId, packet) < 0) { ThrowHelper.ThrowENetPeerSendFailed(); } }
public void Multicast(byte[] buffer, byte channel, ENetPacketFlags flags, IEnumerable <ENetPeer> peers, ENetPeer except) { CheckDispose(); Native.ENetPacket *packet; fixed(byte *p = buffer) { packet = LibENet.PacketCreate((IntPtr)p, (UIntPtr)buffer.Length, flags & ~ENetPacketFlags.NoAllocate); } foreach (var peer in peers) { if (peer == null) { throw new NullReferenceException(); } if (peer.Host != this) { throw new ENetMulticastException("Speicfied peer is not of this host.", peer); } if (peer == except) { continue; } if (peer.Unsafe->State != ENetPeerState.Connected) { continue; } if (LibENet.PeerSend(peer.Unsafe, channel, packet) != 0) { throw new ENetMulticastException("Failed to send packet to speicfied peer.", peer); } } if (packet->ReferenceCount.ToUInt32() == 0) { LibENet.PacketDestroy(packet); } }
public void SendPacketRaw(int type, byte[] data, ENetPeer peer, ENetPacketFlags flag = ENetPacketFlags.Reliable) { if (peer == null) { return; } if (peer.IsNull) { return; } if (peer.State != ENetPeerState.Connected) { return; } byte[] packetData = new byte[data.Length + 5]; Array.Copy(BitConverter.GetBytes(type), packetData, 4); Array.Copy(data, 0, packetData, 4, data.Length); SendData(packetData, peer); }
public void SendData(byte[] data, ENetPeer peer, ENetPacketFlags flag = ENetPacketFlags.Reliable) { if (peer == null) { return; } if (peer.State != ENetPeerState.Connected) { return; } if (rand.Next(0, 1) == 0) { peer.Send(data, 0, flag); } else { peer.Send(data, 1, flag); } }
public static extern NativeENetPacket *PacketCreate(IntPtr data, UIntPtr dataLength, ENetPacketFlags flags);
public void SendPacket(int type, string str, ENetPeer peer, ENetPacketFlags flag = ENetPacketFlags.Reliable) { SendPacketRaw(type, Encoding.ASCII.GetBytes(str.ToCharArray()), peer); }
public void Send(byte[] buffer, Enum channel, ENetPacketFlags flags) { Send(buffer, Convert.ToByte(channel), flags); }
public ENetPacket(byte[] data, uint dataLength, ENetPacketFlags flags) { Data = data; DataLength = dataLength; Flags = flags; }
public void Multicast(byte[] buffer, byte channel, ENetPacketFlags flags, IEnumerable <ENetPeer> peers) => Multicast(buffer, channel, flags, peers, null);
public void Multicast(byte[] buffer, Enum channel, ENetPacketFlags flags, IEnumerable <ENetPeer> peers, ENetPeer except) => Multicast(buffer, Convert.ToByte(channel), flags, peers, except);
public void Broadcast(byte[] buffer, Enum channel, ENetPacketFlags flags) => Broadcast(buffer, Convert.ToByte(channel), flags);