| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086 |
- /*
- * Managed C# wrapper for an extended version of ENet
- * Copyright (c) 2013 James Bellinger
- * Copyright (c) 2016 Nate Shoffner
- * Copyright (c) 2018 Stanislav Denisov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
- using System;
- using System.Runtime.InteropServices;
- using System.Security;
- using System.Text;
- namespace ENet {
- [Flags]
- public enum PacketFlags {
- None = 0,
- Reliable = 1 << 0,
- Unsequenced = 1 << 1,
- NoAllocate = 1 << 2,
- UnreliableFragmented = 1 << 3,
- Instant = 1 << 4
- }
- public enum EventType {
- None = 0,
- Connect = 1,
- Disconnect = 2,
- Receive = 3,
- Timeout = 4
- }
- public enum PeerState {
- Uninitialized = -1,
- Disconnected = 0,
- Connecting = 1,
- AcknowledgingConnect = 2,
- ConnectionPending = 3,
- ConnectionSucceeded = 4,
- Connected = 5,
- DisconnectLater = 6,
- Disconnecting = 7,
- AcknowledgingDisconnect = 8,
- Zombie = 9
- }
- [StructLayout(LayoutKind.Sequential)]
- internal struct ENetAddress {
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
- public byte[] ip;
- public ushort port;
- }
- [StructLayout(LayoutKind.Sequential)]
- internal struct ENetEvent {
- public EventType type;
- public IntPtr peer;
- public byte channelID;
- public uint data;
- public IntPtr packet;
- }
- [StructLayout(LayoutKind.Sequential)]
- internal struct ENetCallbacks {
- public AllocCallback malloc;
- public FreeCallback free;
- public NoMemoryCallback noMemory;
- }
- public delegate IntPtr AllocCallback(IntPtr size);
- public delegate void FreeCallback(IntPtr memory);
- public delegate void NoMemoryCallback();
- public delegate void PacketFreeCallback(Packet packet);
- internal static class ArrayPool {
- [ThreadStatic]
- private static byte[] byteBuffer;
- [ThreadStatic]
- private static IntPtr[] pointerBuffer;
- public static byte[] GetByteBuffer() {
- if (byteBuffer == null)
- byteBuffer = new byte[64];
- return byteBuffer;
- }
- public static IntPtr[] GetPointerBuffer() {
- if (pointerBuffer == null)
- pointerBuffer = new IntPtr[Library.maxPeers];
- return pointerBuffer;
- }
- }
- public struct Address {
- private ENetAddress nativeAddress;
- internal ENetAddress NativeData {
- get {
- return nativeAddress;
- }
- set {
- nativeAddress = value;
- }
- }
- internal Address(ENetAddress address) {
- nativeAddress = address;
- }
- public ushort Port {
- get {
- return nativeAddress.port;
- }
- set {
- nativeAddress.port = value;
- }
- }
- public string GetIP() {
- StringBuilder ip = new StringBuilder(1025);
- if (Native.enet_address_get_ip(nativeAddress, ip, (IntPtr)ip.Capacity) != 0)
- return String.Empty;
- return ip.ToString();
- }
- public bool SetIP(string ip) {
- if (ip == null)
- throw new ArgumentNullException("ip");
- return Native.enet_address_set_ip(ref nativeAddress, ip) == 0;
- }
- public string GetHost() {
- StringBuilder hostName = new StringBuilder(1025);
- if (Native.enet_address_get_hostname(nativeAddress, hostName, (IntPtr)hostName.Capacity) != 0)
- return String.Empty;
- return hostName.ToString();
- }
- public bool SetHost(string hostName) {
- if (hostName == null)
- throw new ArgumentNullException("hostName");
- return Native.enet_address_set_hostname(ref nativeAddress, hostName) == 0;
- }
- }
- public struct Event {
- private ENetEvent nativeEvent;
- internal ENetEvent NativeData {
- get {
- return nativeEvent;
- }
- set {
- nativeEvent = value;
- }
- }
- internal Event(ENetEvent @event) {
- nativeEvent = @event;
- }
- public EventType Type {
- get {
- return nativeEvent.type;
- }
- }
- public Peer Peer {
- get {
- return new Peer(nativeEvent.peer);
- }
- }
- public byte ChannelID {
- get {
- return nativeEvent.channelID;
- }
- }
- public uint Data {
- get {
- return nativeEvent.data;
- }
- }
- public Packet Packet {
- get {
- return new Packet(nativeEvent.packet);
- }
- }
- }
- public class Callbacks {
- private ENetCallbacks nativeCallbacks;
- internal ENetCallbacks NativeData {
- get {
- return nativeCallbacks;
- }
- set {
- nativeCallbacks = value;
- }
- }
- public Callbacks(AllocCallback allocCallback, FreeCallback freeCallback, NoMemoryCallback noMemoryCallback) {
- nativeCallbacks.malloc = allocCallback;
- nativeCallbacks.free = freeCallback;
- nativeCallbacks.noMemory = noMemoryCallback;
- }
- }
- public struct Packet : IDisposable {
- private IntPtr nativePacket;
- internal IntPtr NativeData {
- get {
- return nativePacket;
- }
- set {
- nativePacket = value;
- }
- }
- internal Packet(IntPtr packet) {
- nativePacket = packet;
- }
- public void Dispose() {
- if (nativePacket != IntPtr.Zero) {
- Native.enet_packet_dispose(nativePacket);
- nativePacket = IntPtr.Zero;
- }
- }
- public bool IsSet {
- get {
- return nativePacket != IntPtr.Zero;
- }
- }
- public IntPtr Data {
- get {
- CheckCreated();
- return Native.enet_packet_get_data(nativePacket);
- }
- }
- public int Length {
- get {
- CheckCreated();
- return Native.enet_packet_get_length(nativePacket);
- }
- }
- public bool HasReferences {
- get {
- CheckCreated();
- return Native.enet_packet_check_references(nativePacket) != 0;
- }
- }
- internal void CheckCreated() {
- if (nativePacket == IntPtr.Zero)
- throw new InvalidOperationException("Packet not created");
- }
- public void SetFreeCallback(IntPtr callback) {
- CheckCreated();
- Native.enet_packet_set_free_callback(nativePacket, callback);
- }
- public void SetFreeCallback(PacketFreeCallback callback) {
- CheckCreated();
- Native.enet_packet_set_free_callback(nativePacket, Marshal.GetFunctionPointerForDelegate(callback));
- }
- public void Create(byte[] data) {
- if (data == null)
- throw new ArgumentNullException("data");
- Create(data, data.Length);
- }
- public void Create(byte[] data, int length) {
- Create(data, length, PacketFlags.None);
- }
- public void Create(byte[] data, PacketFlags flags) {
- Create(data, data.Length, flags);
- }
- public void Create(byte[] data, int length, PacketFlags flags) {
- if (data == null)
- throw new ArgumentNullException("data");
- if (length < 0 || length > data.Length)
- throw new ArgumentOutOfRangeException();
- nativePacket = Native.enet_packet_create(data, (IntPtr)length, flags);
- }
- public void Create(IntPtr data, int length, PacketFlags flags) {
- if (data == IntPtr.Zero)
- throw new ArgumentNullException("data");
- if (length < 0)
- throw new ArgumentOutOfRangeException();
- nativePacket = Native.enet_packet_create(data, (IntPtr)length, flags);
- }
- public void Create(byte[] data, int offset, int length, PacketFlags flags) {
- if (data == null)
- throw new ArgumentNullException("data");
- if (offset < 0 || length < 0 || length > data.Length)
- throw new ArgumentOutOfRangeException();
- nativePacket = Native.enet_packet_create_offset(data, (IntPtr)length, (IntPtr)offset, flags);
- }
- public void Create(IntPtr data, int offset, int length, PacketFlags flags) {
- if (data == IntPtr.Zero)
- throw new ArgumentNullException("data");
- if (offset < 0 || length < 0)
- throw new ArgumentOutOfRangeException();
- nativePacket = Native.enet_packet_create_offset(data, (IntPtr)length, (IntPtr)offset, flags);
- }
- public void CopyTo(byte[] destination) {
- if (destination == null)
- throw new ArgumentNullException("destination");
- Marshal.Copy(Data, destination, 0, Length);
- }
- }
- public class Host : IDisposable {
- private IntPtr nativeHost;
- internal IntPtr NativeData {
- get {
- return nativeHost;
- }
- set {
- nativeHost = value;
- }
- }
- public void Dispose() {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- protected virtual void Dispose(bool disposing) {
- if (nativeHost != IntPtr.Zero) {
- Native.enet_host_destroy(nativeHost);
- nativeHost = IntPtr.Zero;
- }
- }
- ~Host() {
- Dispose(false);
- }
- public bool IsSet {
- get {
- return nativeHost != IntPtr.Zero;
- }
- }
- public uint PeersCount {
- get {
- CheckCreated();
- return Native.enet_host_get_peers_count(nativeHost);
- }
- }
- public uint PacketsSent {
- get {
- CheckCreated();
- return Native.enet_host_get_packets_sent(nativeHost);
- }
- }
- public uint PacketsReceived {
- get {
- CheckCreated();
- return Native.enet_host_get_packets_received(nativeHost);
- }
- }
- public uint BytesSent {
- get {
- CheckCreated();
- return Native.enet_host_get_bytes_sent(nativeHost);
- }
- }
- public uint BytesReceived {
- get {
- CheckCreated();
- return Native.enet_host_get_bytes_received(nativeHost);
- }
- }
- internal void CheckCreated() {
- if (nativeHost == IntPtr.Zero)
- throw new InvalidOperationException("Host not created");
- }
- private void CheckChannelLimit(int channelLimit) {
- if (channelLimit < 0 || channelLimit > Library.maxChannelCount)
- throw new ArgumentOutOfRangeException("channelLimit");
- }
- public void Create() {
- Create(null, 1, 0);
- }
- public void Create(int bufferSize) {
- Create(null, 1, 0, 0, 0, bufferSize);
- }
- public void Create(Address? address, int peerLimit) {
- Create(address, peerLimit, 0);
- }
- public void Create(Address? address, int peerLimit, int channelLimit) {
- Create(address, peerLimit, channelLimit, 0, 0, 0);
- }
- public void Create(int peerLimit, int channelLimit) {
- Create(null, peerLimit, channelLimit, 0, 0, 0);
- }
- public void Create(int peerLimit, int channelLimit, uint incomingBandwidth, uint outgoingBandwidth) {
- Create(null, peerLimit, channelLimit, incomingBandwidth, outgoingBandwidth, 0);
- }
- public void Create(Address? address, int peerLimit, int channelLimit, uint incomingBandwidth, uint outgoingBandwidth) {
- Create(address, peerLimit, channelLimit, incomingBandwidth, outgoingBandwidth, 0);
- }
- public void Create(Address? address, int peerLimit, int channelLimit, uint incomingBandwidth, uint outgoingBandwidth, int bufferSize) {
- if (nativeHost != IntPtr.Zero)
- throw new InvalidOperationException("Host already created");
- if (peerLimit < 0 || peerLimit > Library.maxPeers)
- throw new ArgumentOutOfRangeException("peerLimit");
- CheckChannelLimit(channelLimit);
- if (address != null) {
- var nativeAddress = address.Value.NativeData;
- nativeHost = Native.enet_host_create(ref nativeAddress, (IntPtr)peerLimit, (IntPtr)channelLimit, incomingBandwidth, outgoingBandwidth, bufferSize);
- } else {
- nativeHost = Native.enet_host_create(IntPtr.Zero, (IntPtr)peerLimit, (IntPtr)channelLimit, incomingBandwidth, outgoingBandwidth, bufferSize);
- }
- if (nativeHost == IntPtr.Zero)
- throw new InvalidOperationException("Host creation call failed");
- }
- public void EnableCompression() {
- CheckCreated();
- Native.enet_host_enable_compression(nativeHost);
- }
- public void PreventConnections(bool state) {
- CheckCreated();
- Native.enet_host_prevent_connections(nativeHost, (byte)(state ? 1 : 0));
- }
- public void Broadcast(byte channelID, ref Packet packet) {
- CheckCreated();
- packet.CheckCreated();
- Native.enet_host_broadcast(nativeHost, channelID, packet.NativeData);
- packet.NativeData = IntPtr.Zero;
- }
- public void Broadcast(byte channelID, ref Packet packet, Peer excludedPeer) {
- CheckCreated();
- packet.CheckCreated();
- Native.enet_host_broadcast_exclude(nativeHost, channelID, packet.NativeData, excludedPeer.NativeData);
- packet.NativeData = IntPtr.Zero;
- }
- public void Broadcast(byte channelID, ref Packet packet, Peer[] peers) {
- CheckCreated();
- packet.CheckCreated();
- if (peers.Length > 0) {
- IntPtr[] nativePeers = ArrayPool.GetPointerBuffer();
- int nativeCount = 0;
- for (int i = 0; i < peers.Length; i++) {
- if (peers[i].NativeData != IntPtr.Zero) {
- nativePeers[nativeCount] = peers[i].NativeData;
- nativeCount++;
- }
- }
- Native.enet_host_broadcast_selective(nativeHost, channelID, packet.NativeData, nativePeers, (IntPtr)nativeCount);
- }
- packet.NativeData = IntPtr.Zero;
- }
- public int CheckEvents(out Event @event) {
- CheckCreated();
- ENetEvent nativeEvent;
- var result = Native.enet_host_check_events(nativeHost, out nativeEvent);
- if (result <= 0) {
- @event = default(Event);
- return result;
- }
- @event = new Event(nativeEvent);
- return result;
- }
- public Peer Connect(Address address) {
- return Connect(address, 0, 0);
- }
- public Peer Connect(Address address, int channelLimit) {
- return Connect(address, channelLimit, 0);
- }
- public Peer Connect(Address address, int channelLimit, uint data) {
- CheckCreated();
- CheckChannelLimit(channelLimit);
- var nativeAddress = address.NativeData;
- var peer = new Peer(Native.enet_host_connect(nativeHost, ref nativeAddress, (IntPtr)channelLimit, data));
- if (peer.NativeData == IntPtr.Zero)
- throw new InvalidOperationException("Host connect call failed");
- return peer;
- }
- public int Service(int timeout, out Event @event) {
- if (timeout < 0)
- throw new ArgumentOutOfRangeException("timeout");
- CheckCreated();
- ENetEvent nativeEvent;
- var result = Native.enet_host_service(nativeHost, out nativeEvent, (uint)timeout);
- if (result <= 0) {
- @event = default(Event);
- return result;
- }
- @event = new Event(nativeEvent);
- return result;
- }
- public void SetBandwidthLimit(uint incomingBandwidth, uint outgoingBandwidth) {
- CheckCreated();
- Native.enet_host_bandwidth_limit(nativeHost, incomingBandwidth, outgoingBandwidth);
- }
- public void SetChannelLimit(int channelLimit) {
- CheckCreated();
- CheckChannelLimit(channelLimit);
- Native.enet_host_channel_limit(nativeHost, (IntPtr)channelLimit);
- }
- public void Flush() {
- CheckCreated();
- Native.enet_host_flush(nativeHost);
- }
- }
- public struct Peer {
- private IntPtr nativePeer;
- private uint nativeID;
- internal IntPtr NativeData {
- get {
- return nativePeer;
- }
- set {
- nativePeer = value;
- }
- }
- internal Peer(IntPtr peer) {
- nativePeer = peer;
- nativeID = nativePeer != IntPtr.Zero ? Native.enet_peer_get_id(nativePeer) : 0;
- }
- public bool IsSet {
- get {
- return nativePeer != IntPtr.Zero;
- }
- }
- public uint ID {
- get {
- return nativeID;
- }
- }
- public string IP {
- get {
- CheckCreated();
- byte[] ip = ArrayPool.GetByteBuffer();
- if (Native.enet_peer_get_ip(nativePeer, ip, (IntPtr)ip.Length) == 0)
- return Encoding.ASCII.GetString(ip, 0, ip.StringLength());
- else
- return String.Empty;
- }
- }
- public ushort Port {
- get {
- CheckCreated();
- return Native.enet_peer_get_port(nativePeer);
- }
- }
- public uint MTU {
- get {
- CheckCreated();
- return Native.enet_peer_get_mtu(nativePeer);
- }
- }
- public PeerState State {
- get {
- return nativePeer == IntPtr.Zero ? PeerState.Uninitialized : Native.enet_peer_get_state(nativePeer);
- }
- }
- public uint RoundTripTime {
- get {
- CheckCreated();
- return Native.enet_peer_get_rtt(nativePeer);
- }
- }
- public uint LastSendTime {
- get {
- CheckCreated();
- return Native.enet_peer_get_lastsendtime(nativePeer);
- }
- }
- public uint LastReceiveTime {
- get {
- CheckCreated();
- return Native.enet_peer_get_lastreceivetime(nativePeer);
- }
- }
- public ulong PacketsSent {
- get {
- CheckCreated();
- return Native.enet_peer_get_packets_sent(nativePeer);
- }
- }
- public ulong PacketsLost {
- get {
- CheckCreated();
- return Native.enet_peer_get_packets_lost(nativePeer);
- }
- }
- public ulong BytesSent {
- get {
- CheckCreated();
- return Native.enet_peer_get_bytes_sent(nativePeer);
- }
- }
- public ulong BytesReceived {
- get {
- CheckCreated();
- return Native.enet_peer_get_bytes_received(nativePeer);
- }
- }
- public IntPtr Data {
- get {
- CheckCreated();
- return Native.enet_peer_get_data(nativePeer);
- }
- set {
- CheckCreated();
- Native.enet_peer_set_data(nativePeer, value);
- }
- }
- internal void CheckCreated() {
- if (nativePeer == IntPtr.Zero)
- throw new InvalidOperationException("Peer not created");
- }
- public void ConfigureThrottle(uint interval, uint acceleration, uint deceleration, uint threshold) {
- CheckCreated();
- Native.enet_peer_throttle_configure(nativePeer, interval, acceleration, deceleration, threshold);
- }
- public bool Send(byte channelID, ref Packet packet) {
- CheckCreated();
- packet.CheckCreated();
- return Native.enet_peer_send(nativePeer, channelID, packet.NativeData) == 0;
- }
- public bool Receive(out byte channelID, out Packet packet) {
- CheckCreated();
- IntPtr nativePacket = Native.enet_peer_receive(nativePeer, out channelID);
- if (nativePacket != IntPtr.Zero) {
- packet = new Packet(nativePacket);
- return true;
- }
- packet = default(Packet);
- return false;
- }
- public void Ping() {
- CheckCreated();
- Native.enet_peer_ping(nativePeer);
- }
- public void PingInterval(uint interval) {
- CheckCreated();
- Native.enet_peer_ping_interval(nativePeer, interval);
- }
- public void Timeout(uint timeoutLimit, uint timeoutMinimum, uint timeoutMaximum) {
- CheckCreated();
- Native.enet_peer_timeout(nativePeer, timeoutLimit, timeoutMinimum, timeoutMaximum);
- }
- public void Disconnect(uint data) {
- CheckCreated();
- Native.enet_peer_disconnect(nativePeer, data);
- }
- public void DisconnectNow(uint data) {
- CheckCreated();
- Native.enet_peer_disconnect_now(nativePeer, data);
- }
- public void DisconnectLater(uint data) {
- CheckCreated();
- Native.enet_peer_disconnect_later(nativePeer, data);
- }
- public void Reset() {
- CheckCreated();
- Native.enet_peer_reset(nativePeer);
- }
- }
- public static class Extensions {
- public static int StringLength(this byte[] data) {
- if (data == null)
- throw new ArgumentNullException("data");
- int i;
- for (i = 0; i < data.Length && data[i] != 0; i++);
- return i;
- }
- }
- public static class Library {
- public const uint maxChannelCount = 0xFF;
- public const uint maxPeers = 0xFFF;
- public const uint maxPacketSize = 32 * 1024 * 1024;
- public const uint throttleScale = 32;
- public const uint throttleAcceleration = 2;
- public const uint throttleDeceleration = 2;
- public const uint throttleInterval = 5000;
- public const uint timeoutLimit = 32;
- public const uint timeoutMinimum = 5000;
- public const uint timeoutMaximum = 30000;
- public const uint version = (2 << 16) | (3 << 8) | (1);
- public static bool Initialize() {
- return Native.enet_initialize() == 0;
- }
- public static bool Initialize(Callbacks inits) {
- return Native.enet_initialize_with_callbacks(version, inits.NativeData) == 0;
- }
- public static void Deinitialize() {
- Native.enet_deinitialize();
- }
- public static uint Time {
- get {
- return Native.enet_time_get();
- }
- }
- }
- [SuppressUnmanagedCodeSecurity]
- internal static class Native {
- #if __IOS__ || UNITY_IOS && !UNITY_EDITOR
- private const string nativeLibrary = "__Internal";
- #else
- private const string nativeLibrary = "enet";
- #endif
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int enet_initialize();
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int enet_initialize_with_callbacks(uint version, ENetCallbacks inits);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_deinitialize();
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern uint enet_time_get();
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int enet_address_set_ip(ref ENetAddress address, string ip);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int enet_address_set_hostname(ref ENetAddress address, string hostName);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int enet_address_get_ip(ENetAddress address, StringBuilder ip, IntPtr ipLength);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int enet_address_get_hostname(ENetAddress address, StringBuilder hostName, IntPtr nameLength);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr enet_packet_create(byte[] data, IntPtr dataLength, PacketFlags flags);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr enet_packet_create(IntPtr data, IntPtr dataLength, PacketFlags flags);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr enet_packet_create_offset(byte[] data, IntPtr dataLength, IntPtr dataOffset, PacketFlags flags);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr enet_packet_create_offset(IntPtr data, IntPtr dataLength, IntPtr dataOffset, PacketFlags flags);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int enet_packet_check_references(IntPtr packet);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr enet_packet_get_data(IntPtr packet);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int enet_packet_get_length(IntPtr packet);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_packet_set_free_callback(IntPtr packet, IntPtr callback);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_packet_dispose(IntPtr packet);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr enet_host_create(ref ENetAddress address, IntPtr peerLimit, IntPtr channelLimit, uint incomingBandwidth, uint outgoingBandwidth, int bufferSize);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr enet_host_create(IntPtr address, IntPtr peerLimit, IntPtr channelLimit, uint incomingBandwidth, uint outgoingBandwidth, int bufferSize);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr enet_host_connect(IntPtr host, ref ENetAddress address, IntPtr channelCount, uint data);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_host_broadcast(IntPtr host, byte channelID, IntPtr packet);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_host_broadcast_exclude(IntPtr host, byte channelID, IntPtr packet, IntPtr excludedPeer);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_host_broadcast_selective(IntPtr host, byte channelID, IntPtr packet, IntPtr[] peers, IntPtr peersLength);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int enet_host_service(IntPtr host, out ENetEvent @event, uint timeout);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int enet_host_check_events(IntPtr host, out ENetEvent @event);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_host_channel_limit(IntPtr host, IntPtr channelLimit);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_host_bandwidth_limit(IntPtr host, uint incomingBandwidth, uint outgoingBandwidth);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern uint enet_host_get_peers_count(IntPtr host);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern uint enet_host_get_packets_sent(IntPtr host);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern uint enet_host_get_packets_received(IntPtr host);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern uint enet_host_get_bytes_sent(IntPtr host);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern uint enet_host_get_bytes_received(IntPtr host);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_host_flush(IntPtr host);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_host_destroy(IntPtr host);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_host_enable_compression(IntPtr host);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_host_prevent_connections(IntPtr host, byte state);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_peer_throttle_configure(IntPtr peer, uint interval, uint acceleration, uint deceleration, uint threshold);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern uint enet_peer_get_id(IntPtr peer);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int enet_peer_get_ip(IntPtr peer, byte[] ip, IntPtr ipLength);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern ushort enet_peer_get_port(IntPtr peer);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern uint enet_peer_get_mtu(IntPtr peer);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern PeerState enet_peer_get_state(IntPtr peer);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern uint enet_peer_get_rtt(IntPtr peer);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern uint enet_peer_get_lastsendtime(IntPtr peer);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern uint enet_peer_get_lastreceivetime(IntPtr peer);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern ulong enet_peer_get_packets_sent(IntPtr peer);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern ulong enet_peer_get_packets_lost(IntPtr peer);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern ulong enet_peer_get_bytes_sent(IntPtr peer);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern ulong enet_peer_get_bytes_received(IntPtr peer);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr enet_peer_get_data(IntPtr peer);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_peer_set_data(IntPtr peer, IntPtr data);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int enet_peer_send(IntPtr peer, byte channelID, IntPtr packet);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr enet_peer_receive(IntPtr peer, out byte channelID);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_peer_ping(IntPtr peer);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_peer_ping_interval(IntPtr peer, uint pingInterval);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_peer_timeout(IntPtr peer, uint timeoutLimit, uint timeoutMinimum, uint timeoutMaximum);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_peer_disconnect(IntPtr peer, uint data);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_peer_disconnect_now(IntPtr peer, uint data);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_peer_disconnect_later(IntPtr peer, uint data);
- [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void enet_peer_reset(IntPtr peer);
- }
- }
|