|
|
@@ -327,7 +327,7 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_packet_get_data(nativePacket);
|
|
|
}
|
|
|
@@ -337,14 +337,14 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_packet_get_user_data(nativePacket);
|
|
|
}
|
|
|
|
|
|
set
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_packet_set_user_data(nativePacket, value);
|
|
|
}
|
|
|
@@ -354,7 +354,7 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_packet_get_length(nativePacket);
|
|
|
}
|
|
|
@@ -364,13 +364,13 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_packet_check_references(nativePacket) != 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- internal void IsCreated()
|
|
|
+ internal void ThrowIfNotCreated()
|
|
|
{
|
|
|
if (nativePacket == IntPtr.Zero)
|
|
|
throw new InvalidOperationException("Packet not created");
|
|
|
@@ -378,14 +378,14 @@ namespace ENet
|
|
|
|
|
|
public void SetFreeCallback(IntPtr callback)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_packet_set_free_callback(nativePacket, callback);
|
|
|
}
|
|
|
|
|
|
public void SetFreeCallback(PacketFreeCallback callback)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_packet_set_free_callback(nativePacket, Marshal.GetFunctionPointerForDelegate(callback));
|
|
|
}
|
|
|
@@ -523,7 +523,7 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_host_get_peers_count(nativeHost);
|
|
|
}
|
|
|
@@ -533,7 +533,7 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_host_get_packets_sent(nativeHost);
|
|
|
}
|
|
|
@@ -543,7 +543,7 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_host_get_packets_received(nativeHost);
|
|
|
}
|
|
|
@@ -553,7 +553,7 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_host_get_bytes_sent(nativeHost);
|
|
|
}
|
|
|
@@ -563,19 +563,19 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_host_get_bytes_received(nativeHost);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- internal void IsCreated()
|
|
|
+ internal void ThrowIfNotCreated()
|
|
|
{
|
|
|
if (nativeHost == IntPtr.Zero)
|
|
|
throw new InvalidOperationException("Host not created");
|
|
|
}
|
|
|
|
|
|
- private static void IsChannelsLimited(int channelLimit)
|
|
|
+ private static void ThrowIfChannelsExceeded(int channelLimit)
|
|
|
{
|
|
|
if (channelLimit < 0 || channelLimit > Library.maxChannelCount)
|
|
|
throw new ArgumentOutOfRangeException("channelLimit");
|
|
|
@@ -624,7 +624,7 @@ namespace ENet
|
|
|
if (peerLimit < 0 || peerLimit > Library.maxPeers)
|
|
|
throw new ArgumentOutOfRangeException("peerLimit");
|
|
|
|
|
|
- IsChannelsLimited(channelLimit);
|
|
|
+ ThrowIfChannelsExceeded(channelLimit);
|
|
|
|
|
|
if (address != null)
|
|
|
{
|
|
|
@@ -643,25 +643,25 @@ namespace ENet
|
|
|
|
|
|
public void PreventConnections(bool state)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_host_prevent_connections(nativeHost, (byte)(state ? 1 : 0));
|
|
|
}
|
|
|
|
|
|
public void Broadcast(byte channelID, ref Packet packet)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
- packet.IsCreated();
|
|
|
+ packet.ThrowIfNotCreated();
|
|
|
Native.enet_host_broadcast(nativeHost, channelID, packet.NativeData);
|
|
|
packet.NativeData = IntPtr.Zero;
|
|
|
}
|
|
|
|
|
|
public void Broadcast(byte channelID, ref Packet packet, Peer excludedPeer)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
- packet.IsCreated();
|
|
|
+ packet.ThrowIfNotCreated();
|
|
|
Native.enet_host_broadcast_exclude(nativeHost, channelID, packet.NativeData, excludedPeer.NativeData);
|
|
|
packet.NativeData = IntPtr.Zero;
|
|
|
}
|
|
|
@@ -671,9 +671,9 @@ namespace ENet
|
|
|
if (peers == null)
|
|
|
throw new ArgumentNullException("peers");
|
|
|
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
- packet.IsCreated();
|
|
|
+ packet.ThrowIfNotCreated();
|
|
|
|
|
|
if (peers.Length > 0)
|
|
|
{
|
|
|
@@ -697,7 +697,7 @@ namespace ENet
|
|
|
|
|
|
public int CheckEvents(out Event @event)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
ENetEvent nativeEvent;
|
|
|
|
|
|
@@ -727,8 +727,8 @@ namespace ENet
|
|
|
|
|
|
public Peer Connect(Address address, int channelLimit, uint data)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
- IsChannelsLimited(channelLimit);
|
|
|
+ ThrowIfNotCreated();
|
|
|
+ ThrowIfChannelsExceeded(channelLimit);
|
|
|
|
|
|
var nativeAddress = address.NativeData;
|
|
|
var peer = new Peer(Native.enet_host_connect(nativeHost, ref nativeAddress, (IntPtr)channelLimit, data));
|
|
|
@@ -744,7 +744,7 @@ namespace ENet
|
|
|
if (timeout < 0)
|
|
|
throw new ArgumentOutOfRangeException("timeout");
|
|
|
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
ENetEvent nativeEvent;
|
|
|
|
|
|
@@ -764,57 +764,57 @@ namespace ENet
|
|
|
|
|
|
public void SetBandwidthLimit(uint incomingBandwidth, uint outgoingBandwidth)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_host_bandwidth_limit(nativeHost, incomingBandwidth, outgoingBandwidth);
|
|
|
}
|
|
|
|
|
|
public void SetChannelLimit(int channelLimit)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
- IsChannelsLimited(channelLimit);
|
|
|
+ ThrowIfNotCreated();
|
|
|
+ ThrowIfChannelsExceeded(channelLimit);
|
|
|
|
|
|
Native.enet_host_channel_limit(nativeHost, (IntPtr)channelLimit);
|
|
|
}
|
|
|
|
|
|
public void SetMaxDuplicatePeers(ushort number)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_host_set_max_duplicate_peers(nativeHost, number);
|
|
|
}
|
|
|
|
|
|
public void SetInterceptCallback(IntPtr callback)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_host_set_intercept_callback(nativeHost, callback);
|
|
|
}
|
|
|
|
|
|
public void SetInterceptCallback(InterceptCallback callback)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_host_set_intercept_callback(nativeHost, Marshal.GetFunctionPointerForDelegate(callback));
|
|
|
}
|
|
|
|
|
|
public void SetChecksumCallback(IntPtr callback)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_host_set_checksum_callback(nativeHost, callback);
|
|
|
}
|
|
|
|
|
|
public void SetChecksumCallback(ChecksumCallback callback)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_host_set_checksum_callback(nativeHost, Marshal.GetFunctionPointerForDelegate(callback));
|
|
|
}
|
|
|
|
|
|
public void Flush()
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_host_flush(nativeHost);
|
|
|
}
|
|
|
@@ -864,7 +864,7 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
byte[] ip = ArrayPool.GetByteBuffer();
|
|
|
|
|
|
@@ -879,7 +879,7 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_peer_get_port(nativePeer);
|
|
|
}
|
|
|
@@ -889,7 +889,7 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_peer_get_mtu(nativePeer);
|
|
|
}
|
|
|
@@ -907,7 +907,7 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_peer_get_rtt(nativePeer);
|
|
|
}
|
|
|
@@ -917,7 +917,7 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_peer_get_last_rtt(nativePeer);
|
|
|
}
|
|
|
@@ -927,7 +927,7 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_peer_get_lastsendtime(nativePeer);
|
|
|
}
|
|
|
@@ -937,7 +937,7 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_peer_get_lastreceivetime(nativePeer);
|
|
|
}
|
|
|
@@ -947,7 +947,7 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_peer_get_packets_sent(nativePeer);
|
|
|
}
|
|
|
@@ -957,7 +957,7 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_peer_get_packets_lost(nativePeer);
|
|
|
}
|
|
|
@@ -967,7 +967,7 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_peer_get_packets_throttle(nativePeer);
|
|
|
}
|
|
|
@@ -977,7 +977,7 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_peer_get_bytes_sent(nativePeer);
|
|
|
}
|
|
|
@@ -987,7 +987,7 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_peer_get_bytes_received(nativePeer);
|
|
|
}
|
|
|
@@ -997,20 +997,20 @@ namespace ENet
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_peer_get_data(nativePeer);
|
|
|
}
|
|
|
|
|
|
set
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_peer_set_data(nativePeer, value);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- internal void IsCreated()
|
|
|
+ internal void ThrowIfNotCreated()
|
|
|
{
|
|
|
if (nativePeer == IntPtr.Zero)
|
|
|
throw new InvalidOperationException("Peer not created");
|
|
|
@@ -1018,23 +1018,23 @@ namespace ENet
|
|
|
|
|
|
public void ConfigureThrottle(uint interval, uint acceleration, uint deceleration, uint threshold)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_peer_throttle_configure(nativePeer, interval, acceleration, deceleration, threshold);
|
|
|
}
|
|
|
|
|
|
public int Send(byte channelID, ref Packet packet)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
- packet.IsCreated();
|
|
|
+ packet.ThrowIfNotCreated();
|
|
|
|
|
|
return Native.enet_peer_send(nativePeer, channelID, packet.NativeData);
|
|
|
}
|
|
|
|
|
|
public bool Receive(out byte channelID, out Packet packet)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
IntPtr nativePacket = Native.enet_peer_receive(nativePeer, out channelID);
|
|
|
|
|
|
@@ -1052,49 +1052,49 @@ namespace ENet
|
|
|
|
|
|
public void Ping()
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_peer_ping(nativePeer);
|
|
|
}
|
|
|
|
|
|
public void PingInterval(uint interval)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_peer_ping_interval(nativePeer, interval);
|
|
|
}
|
|
|
|
|
|
public void Timeout(uint timeoutLimit, uint timeoutMinimum, uint timeoutMaximum)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_peer_timeout(nativePeer, timeoutLimit, timeoutMinimum, timeoutMaximum);
|
|
|
}
|
|
|
|
|
|
public void Disconnect(uint data)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_peer_disconnect(nativePeer, data);
|
|
|
}
|
|
|
|
|
|
public void DisconnectNow(uint data)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_peer_disconnect_now(nativePeer, data);
|
|
|
}
|
|
|
|
|
|
public void DisconnectLater(uint data)
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_peer_disconnect_later(nativePeer, data);
|
|
|
}
|
|
|
|
|
|
public void Reset()
|
|
|
{
|
|
|
- IsCreated();
|
|
|
+ ThrowIfNotCreated();
|
|
|
|
|
|
Native.enet_peer_reset(nativePeer);
|
|
|
}
|