Browse Source

Add function for receiving packets selectively per peer

NX 6 years ago
parent
commit
0eaf6c5c50
2 changed files with 25 additions and 6 deletions
  1. 20 1
      Source/Managed/ENet.cs
  2. 5 5
      Source/Native/enet.h

+ 20 - 1
Source/Managed/ENet.cs

@@ -787,6 +787,22 @@ namespace ENet {
 			return Native.enet_peer_send(nativePeer, channelID, packet.NativeData) == 0;
 			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() {
 		public void Ping() {
 			CheckCreated();
 			CheckCreated();
 
 
@@ -854,7 +870,7 @@ namespace ENet {
 		public const uint timeoutLimit = 32;
 		public const uint timeoutLimit = 32;
 		public const uint timeoutMinimum = 5000;
 		public const uint timeoutMinimum = 5000;
 		public const uint timeoutMaximum = 30000;
 		public const uint timeoutMaximum = 30000;
-		public const uint version = (2 << 16) | (2 << 8) | (5);
+		public const uint version = (2 << 16) | (2 << 8) | (6);
 
 
 		public static bool Initialize() {
 		public static bool Initialize() {
 			return Native.enet_initialize() == 0;
 			return Native.enet_initialize() == 0;
@@ -1039,6 +1055,9 @@ namespace ENet {
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern int enet_peer_send(IntPtr peer, byte channelID, IntPtr packet);
 		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)]
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_peer_ping(IntPtr peer);
 		internal static extern void enet_peer_ping(IntPtr peer);
 
 

+ 5 - 5
Source/Native/enet.h

@@ -31,7 +31,7 @@
 
 
 #define ENET_VERSION_MAJOR 2
 #define ENET_VERSION_MAJOR 2
 #define ENET_VERSION_MINOR 2
 #define ENET_VERSION_MINOR 2
-#define ENET_VERSION_PATCH 5
+#define ENET_VERSION_PATCH 6
 #define ENET_VERSION_CREATE(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch))
 #define ENET_VERSION_CREATE(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch))
 #define ENET_VERSION_GET_MAJOR(version) (((version) >> 16) & 0xFF)
 #define ENET_VERSION_GET_MAJOR(version) (((version) >> 16) & 0xFF)
 #define ENET_VERSION_GET_MINOR(version) (((version) >> 8) & 0xFF)
 #define ENET_VERSION_GET_MINOR(version) (((version) >> 8) & 0xFF)
@@ -752,7 +752,7 @@ extern "C" {
 	ENET_API void enet_host_bandwidth_limit(ENetHost*, enet_uint32, enet_uint32);
 	ENET_API void enet_host_bandwidth_limit(ENetHost*, enet_uint32, enet_uint32);
 
 
 	ENET_API int enet_peer_send(ENetPeer*, enet_uint8, ENetPacket*);
 	ENET_API int enet_peer_send(ENetPeer*, enet_uint8, ENetPacket*);
-	ENET_API ENetPacket* enet_peer_receive(ENetPeer*, enet_uint8* channelID);
+	ENET_API ENetPacket* enet_peer_receive(ENetPeer*, enet_uint8*);
 	ENET_API void enet_peer_ping(ENetPeer*);
 	ENET_API void enet_peer_ping(ENetPeer*);
 	ENET_API void enet_peer_ping_interval(ENetPeer*, enet_uint32);
 	ENET_API void enet_peer_ping_interval(ENetPeer*, enet_uint32);
 	ENET_API void enet_peer_timeout(ENetPeer*, enet_uint32, enet_uint32, enet_uint32);
 	ENET_API void enet_peer_timeout(ENetPeer*, enet_uint32, enet_uint32, enet_uint32);
@@ -776,7 +776,7 @@ extern "C" {
 	ENET_API enet_uint32 enet_host_get_bytes_received(const ENetHost*);
 	ENET_API enet_uint32 enet_host_get_bytes_received(const ENetHost*);
 
 
 	ENET_API enet_uint32 enet_peer_get_id(const ENetPeer*);
 	ENET_API enet_uint32 enet_peer_get_id(const ENetPeer*);
-	ENET_API int enet_peer_get_ip(const ENetPeer*, char* ip, size_t ipLength);
+	ENET_API int enet_peer_get_ip(const ENetPeer*, char*, size_t);
 	ENET_API enet_uint16 enet_peer_get_port(const ENetPeer*);
 	ENET_API enet_uint16 enet_peer_get_port(const ENetPeer*);
 	ENET_API enet_uint32 enet_peer_get_mtu(const ENetPeer*);
 	ENET_API enet_uint32 enet_peer_get_mtu(const ENetPeer*);
 	ENET_API ENetPeerState enet_peer_get_state(const ENetPeer*);
 	ENET_API ENetPeerState enet_peer_get_state(const ENetPeer*);
@@ -4353,7 +4353,7 @@ extern "C" {
 		}
 		}
 
 
 		int enet_address_set_host(ENetAddress* address, const char* name) {
 		int enet_address_set_host(ENetAddress* address, const char* name) {
-			struct addrinfo hints, * resultList = NULL, * result = NULL;
+			struct addrinfo hints, *resultList = NULL, *result = NULL;
 
 
 			memset(&hints, 0, sizeof(hints));
 			memset(&hints, 0, sizeof(hints));
 
 
@@ -5084,4 +5084,4 @@ extern "C" {
 }
 }
 #endif
 #endif
 #endif
 #endif
-#endif
+#endif