Browse Source

Add packet broadcast with excluded peer

NX 6 years ago
parent
commit
535c9f6d32
2 changed files with 28 additions and 2 deletions
  1. 12 1
      Source/Managed/ENet.cs
  2. 16 1
      Source/Native/enet.h

+ 12 - 1
Source/Managed/ENet.cs

@@ -502,6 +502,14 @@ namespace ENet {
 			packet.NativeData = IntPtr.Zero;
 			packet.NativeData = IntPtr.Zero;
 		}
 		}
 
 
+		public void Broadcast(byte channelID, ref Packet packet, Peer peer) {
+			CheckCreated();
+
+			packet.CheckCreated();
+			Native.enet_host_broadcast_excluding(nativeHost, channelID, packet.NativeData, peer.NativeData);
+			packet.NativeData = IntPtr.Zero;
+		}
+
 		public void Broadcast(byte channelID, ref Packet packet, Peer[] peers) {
 		public void Broadcast(byte channelID, ref Packet packet, Peer[] peers) {
 			CheckCreated();
 			CheckCreated();
 
 
@@ -830,7 +838,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) | (2);
+		public const uint version = (2 << 16) | (2 << 8) | (3);
 
 
 		public static bool Initialize() {
 		public static bool Initialize() {
 			return Native.enet_initialize() == 0;
 			return Native.enet_initialize() == 0;
@@ -916,6 +924,9 @@ namespace ENet {
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_host_broadcast(IntPtr host, byte channelID, IntPtr packet);
 		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_excluding(IntPtr host, byte channelID, IntPtr packet, IntPtr peer);
+
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_host_broadcast_selective(IntPtr host, byte channelID, IntPtr packet, IntPtr[] peers, IntPtr peersLength);
 		internal static extern void enet_host_broadcast_selective(IntPtr host, byte channelID, IntPtr packet, IntPtr[] peers, IntPtr peersLength);
 
 

+ 16 - 1
Source/Native/enet.h

@@ -35,7 +35,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 2
+#define ENET_VERSION_PATCH 3
 #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)
@@ -746,6 +746,7 @@ extern "C" {
 	ENET_API int enet_host_service(ENetHost*, ENetEvent*, enet_uint32);
 	ENET_API int enet_host_service(ENetHost*, ENetEvent*, enet_uint32);
 	ENET_API void enet_host_flush(ENetHost*);
 	ENET_API void enet_host_flush(ENetHost*);
 	ENET_API void enet_host_broadcast(ENetHost*, enet_uint8, ENetPacket*);
 	ENET_API void enet_host_broadcast(ENetHost*, enet_uint8, ENetPacket*);
+	ENET_API void enet_host_broadcast_excluding(ENetHost*, enet_uint8, ENetPacket*, ENetPeer*);
 	ENET_API void enet_host_broadcast_selective(ENetHost*, enet_uint8, ENetPacket*, ENetPeer**, size_t);
 	ENET_API void enet_host_broadcast_selective(ENetHost*, enet_uint8, ENetPacket*, ENetPeer**, size_t);
 	ENET_API void enet_host_channel_limit(ENetHost*, size_t);
 	ENET_API void enet_host_channel_limit(ENetHost*, size_t);
 	ENET_API void enet_host_bandwidth_limit(ENetHost*, enet_uint32, enet_uint32);
 	ENET_API void enet_host_bandwidth_limit(ENetHost*, enet_uint32, enet_uint32);
@@ -3917,6 +3918,20 @@ extern "C" {
 			enet_packet_destroy(packet);
 			enet_packet_destroy(packet);
 	}
 	}
 
 
+	void enet_host_broadcast_excluding(ENetHost* host, enet_uint8 channelID, ENetPacket* packet, ENetPeer* peer) {
+		ENetPeer* currentPeer;
+
+		for (currentPeer = host->peers; currentPeer < &host->peers[host->peerCount]; ++currentPeer) {
+			if (currentPeer->state != ENET_PEER_STATE_CONNECTED || currentPeer == peer)
+				continue;
+
+			enet_peer_send(currentPeer, channelID, packet);
+		}
+
+		if (packet->referenceCount == 0)
+			enet_packet_destroy(packet);		
+	}
+
 	void enet_host_broadcast_selective(ENetHost* host, enet_uint8 channelID, ENetPacket* packet, ENetPeer** peers, size_t length) {
 	void enet_host_broadcast_selective(ENetHost* host, enet_uint8 channelID, ENetPacket* packet, ENetPeer** peers, size_t length) {
 		ENetPeer* currentPeer;
 		ENetPeer* currentPeer;
 		size_t i;
 		size_t i;