Browse Source

Expose duplicate peers setter

nxrighthere 5 years ago
parent
commit
3f53937d7d
2 changed files with 21 additions and 1 deletions
  1. 10 1
      Source/Managed/ENet.cs
  2. 11 0
      Source/Native/enet.h

+ 10 - 1
Source/Managed/ENet.cs

@@ -647,6 +647,12 @@ namespace ENet {
 			Native.enet_host_channel_limit(nativeHost, (IntPtr)channelLimit);
 		}
 
+		public void SetMaxDuplicatePeers(ushort number) {
+			IsCreated();
+
+			Native.enet_host_set_max_duplicate_peers(nativeHost, number);
+		}
+
 		public void Flush() {
 			IsCreated();
 
@@ -1037,6 +1043,9 @@ namespace ENet {
 		[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_set_max_duplicate_peers(IntPtr host, ushort number);
+
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_host_flush(IntPtr host);
 
@@ -1121,4 +1130,4 @@ namespace ENet {
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_peer_reset(IntPtr peer);
 	}
-}
+}

+ 11 - 0
Source/Native/enet.h

@@ -747,6 +747,7 @@ extern "C" {
 	ENET_API uint32_t enet_host_get_packets_received(const ENetHost*);
 	ENET_API uint32_t enet_host_get_bytes_sent(const ENetHost*);
 	ENET_API uint32_t enet_host_get_bytes_received(const ENetHost*);
+	ENET_API void enet_host_set_max_duplicate_peers(ENetHost*, uint16_t);
 
 	ENET_API uint32_t enet_peer_get_id(const ENetPeer*);
 	ENET_API int enet_peer_get_ip(const ENetPeer*, char*, size_t);
@@ -4941,6 +4942,16 @@ extern "C" {
 		return host->totalReceivedData;
 	}
 
+	void enet_host_set_max_duplicate_peers(ENetHost* host, uint16_t number) {
+		if (number < 1)
+			number = 1;
+
+		if (number > ENET_PROTOCOL_MAXIMUM_PEER_ID)
+			number = ENET_PROTOCOL_MAXIMUM_PEER_ID;
+
+		host->duplicatePeers = number;
+	}
+
 	uint32_t enet_peer_get_id(const ENetPeer* peer) {
 		return peer->incomingPeerID;
 	}