99using Unity . Networking . Transport . Relay ;
1010using Unity . Networking . Transport . Utilities ;
1111
12+ #if ! UTP_TRANSPORT_2_0_ABOVE
13+ using NetworkEndpoint = Unity . Networking . Transport . NetworkEndPoint ;
14+ #endif
15+
1216namespace Unity . Netcode . Transports . UTP
1317{
1418 /// <summary>
@@ -263,9 +267,9 @@ public struct ConnectionAddressData
263267 [ SerializeField ]
264268 public string ServerListenAddress ;
265269
266- private static NetworkEndPoint ParseNetworkEndpoint ( string ip , ushort port )
270+ private static NetworkEndpoint ParseNetworkEndpoint ( string ip , ushort port )
267271 {
268- if ( ! NetworkEndPoint . TryParse ( ip , port , out var endpoint ) )
272+ if ( ! NetworkEndpoint . TryParse ( ip , port , out var endpoint ) )
269273 {
270274 Debug . LogError ( $ "Invalid network endpoint: { ip } :{ port } .") ;
271275 return default ;
@@ -277,12 +281,12 @@ private static NetworkEndPoint ParseNetworkEndpoint(string ip, ushort port)
277281 /// <summary>
278282 /// Endpoint (IP address and port) clients will connect to.
279283 /// </summary>
280- public NetworkEndPoint ServerEndPoint => ParseNetworkEndpoint ( Address , Port ) ;
284+ public NetworkEndpoint ServerEndPoint => ParseNetworkEndpoint ( Address , Port ) ;
281285
282286 /// <summary>
283287 /// Endpoint (IP address and port) server will listen/bind on.
284288 /// </summary>
285- public NetworkEndPoint ListenEndPoint => ParseNetworkEndpoint ( ( ServerListenAddress == string . Empty ) ? Address : ServerListenAddress , Port ) ;
289+ public NetworkEndpoint ListenEndPoint => ParseNetworkEndpoint ( ( ServerListenAddress == string . Empty ) ? Address : ServerListenAddress , Port ) ;
286290 }
287291
288292 /// <summary>
@@ -425,7 +429,7 @@ private NetworkPipeline SelectSendPipeline(NetworkDelivery delivery)
425429
426430 private bool ClientBindAndConnect ( )
427431 {
428- var serverEndpoint = default ( NetworkEndPoint ) ;
432+ var serverEndpoint = default ( NetworkEndpoint ) ;
429433
430434 if ( m_ProtocolType == ProtocolType . RelayUnityTransport )
431435 {
@@ -446,7 +450,7 @@ private bool ClientBindAndConnect()
446450
447451 InitDriver ( ) ;
448452
449- int result = m_Driver . Bind ( NetworkEndPoint . AnyIpv4 ) ;
453+ int result = m_Driver . Bind ( NetworkEndpoint . AnyIpv4 ) ;
450454 if ( result != 0 )
451455 {
452456 Debug . LogError ( "Client failed to bind" ) ;
@@ -459,7 +463,7 @@ private bool ClientBindAndConnect()
459463 return true ;
460464 }
461465
462- private bool ServerBindAndListen ( NetworkEndPoint endPoint )
466+ private bool ServerBindAndListen ( NetworkEndpoint endPoint )
463467 {
464468 InitDriver ( ) ;
465469
@@ -536,7 +540,7 @@ public void SetRelayServerData(string ipv4Address, ushort port, byte[] allocatio
536540 {
537541 RelayConnectionData hostConnectionData ;
538542
539- if ( ! NetworkEndPoint . TryParse ( ipv4Address , port , out var serverEndpoint ) )
543+ if ( ! NetworkEndpoint . TryParse ( ipv4Address , port , out var serverEndpoint ) )
540544 {
541545 Debug . LogError ( $ "Invalid address { ipv4Address } :{ port } ") ;
542546
@@ -613,7 +617,7 @@ public void SetConnectionData(string ipv4Address, ushort port, string listenAddr
613617 /// </summary>
614618 /// <param name="endPoint">The remote end point</param>
615619 /// <param name="listenEndPoint">The local listen endpoint</param>
616- public void SetConnectionData ( NetworkEndPoint endPoint , NetworkEndPoint listenEndPoint = default )
620+ public void SetConnectionData ( NetworkEndpoint endPoint , NetworkEndpoint listenEndPoint = default )
617621 {
618622 string serverAddress = endPoint . Address . Split ( ':' ) [ 0 ] ;
619623
@@ -662,7 +666,7 @@ private bool StartRelayServer()
662666 else
663667 {
664668 m_NetworkSettings . WithRelayParameters ( ref m_RelayServerData , m_HeartbeatTimeoutMS ) ;
665- return ServerBindAndListen ( NetworkEndPoint . AnyIpv4 ) ;
669+ return ServerBindAndListen ( NetworkEndpoint . AnyIpv4 ) ;
666670 }
667671 }
668672
@@ -907,7 +911,11 @@ private void ExtractNetworkMetricsFromPipeline(NetworkPipeline pipeline, Network
907911 {
908912 //Don't need to dispose of the buffers, they are filled with data pointers.
909913 m_Driver . GetPipelineBuffers ( pipeline ,
914+ #if UTP_TRANSPORT_2_0_ABOVE
915+ NetworkPipelineStageId . Get < NetworkMetricsPipelineStage > ( ) ,
916+ #else
910917 NetworkPipelineStageCollection . GetStageId ( typeof ( NetworkMetricsPipelineStage ) ) ,
918+ #endif
911919 networkConnection,
912920 out _ ,
913921 out _ ,
@@ -934,7 +942,11 @@ private int ExtractRtt(NetworkConnection networkConnection)
934942 }
935943
936944 m_Driver . GetPipelineBuffers ( m_ReliableSequencedPipeline ,
945+ #if UTP_TRANSPORT_2_0_ABOVE
946+ NetworkPipelineStageId . Get < ReliableSequencedPipelineStage > ( ) ,
947+ #else
937948 NetworkPipelineStageCollection . GetStageId ( typeof ( ReliableSequencedPipelineStage ) ) ,
949+ #endif
938950 networkConnection,
939951 out _ ,
940952 out _ ,
@@ -956,7 +968,11 @@ private float ExtractPacketLoss(NetworkConnection networkConnection)
956968 }
957969
958970 m_Driver . GetPipelineBuffers ( m_ReliableSequencedPipeline ,
971+ #if UTP_TRANSPORT_2_0_ABOVE
972+ NetworkPipelineStageId . Get < ReliableSequencedPipelineStage > ( ) ,
973+ #else
959974 NetworkPipelineStageCollection . GetStageId ( typeof ( ReliableSequencedPipelineStage ) ) ,
975+ #endif
960976 networkConnection,
961977 out _ ,
962978 out _ ,
@@ -1117,11 +1133,12 @@ public override void Initialize(NetworkManager networkManager = null)
11171133 // account for the overhead of its length when we store it in the send queue.
11181134 var fragmentationCapacity = m_MaxPayloadSize + BatchedSendQueue . PerMessageOverhead ;
11191135
1120- m_NetworkSettings
1121- . WithFragmentationStageParameters ( payloadCapacity : fragmentationCapacity )
1122- . WithBaselibNetworkInterfaceParameters (
1123- receiveQueueCapacity : m_MaxPacketQueueSize ,
1124- sendQueueCapacity : m_MaxPacketQueueSize ) ;
1136+ m_NetworkSettings . WithFragmentationStageParameters ( payloadCapacity : fragmentationCapacity ) ;
1137+ #if ! UTP_TRANSPORT_2_0_ABOVE
1138+ m_NetworkSettings . WithBaselibNetworkInterfaceParameters (
1139+ receiveQueueCapacity : m_MaxPacketQueueSize ,
1140+ sendQueueCapacity : m_MaxPacketQueueSize ) ;
1141+ #endif
11251142#endif
11261143 }
11271144
@@ -1306,6 +1323,9 @@ private void ConfigureSimulator()
13061323 packetDelayMs : DebugSimulator . PacketDelayMS ,
13071324 packetJitterMs : DebugSimulator . PacketJitterMS ,
13081325 packetDropPercentage : DebugSimulator . PacketDropRate
1326+ #if UTP_TRANSPORT_2_0_ABOVE
1327+ , mode : ApplyMode . AllPackets
1328+ #endif
13091329 ) ;
13101330 }
13111331
@@ -1323,8 +1343,10 @@ public void CreateDriver(UnityTransport transport, out NetworkDriver driver,
13231343 out NetworkPipeline reliableSequencedPipeline )
13241344 {
13251345#if MULTIPLAYER_TOOLS_1_0_0_PRE_7
1346+ #if ! UTP_TRANSPORT_2_0_ABOVE
13261347 NetworkPipelineStageCollection . RegisterPipelineStage ( new NetworkMetricsPipelineStage ( ) ) ;
13271348#endif
1349+ #endif
13281350
13291351#if UNITY_EDITOR || DEVELOPMENT_BUILD
13301352 ConfigureSimulator ( ) ;
@@ -1334,34 +1356,50 @@ public void CreateDriver(UnityTransport transport, out NetworkDriver driver,
13341356 maxConnectAttempts : transport . m_MaxConnectAttempts ,
13351357 connectTimeoutMS : transport . m_ConnectTimeoutMS ,
13361358 disconnectTimeoutMS : transport . m_DisconnectTimeoutMS ,
1359+ #if UTP_TRANSPORT_2_0_ABOVE
1360+ sendQueueCapacity : m_MaxPacketQueueSize,
1361+ receiveQueueCapacity: m_MaxPacketQueueSize,
1362+ #endif
13371363 heartbeatTimeoutMS: transport. m_HeartbeatTimeoutMS ) ;
13381364
13391365 driver = NetworkDriver . Create ( m_NetworkSettings ) ;
13401366
1367+ #if MULTIPLAYER_TOOLS_1_0_0_PRE_7
1368+ #if UTP_TRANSPORT_2_0_ABOVE
1369+ driver . RegisterPipelineStage < NetworkMetricsPipelineStage > ( new NetworkMetricsPipelineStage ( ) ) ;
1370+ #endif
1371+ #endif
1372+
13411373#if UNITY_EDITOR || DEVELOPMENT_BUILD
13421374 if ( DebugSimulator . PacketDelayMS > 0 || DebugSimulator . PacketDropRate > 0 )
13431375 {
13441376 unreliableFragmentedPipeline = driver . CreatePipeline (
13451377 typeof ( FragmentationPipelineStage ) ,
1346- typeof ( SimulatorPipelineStage ) ,
1347- typeof ( SimulatorPipelineStageInSend )
1378+ typeof ( SimulatorPipelineStage )
1379+ #if ! UTP_TRANSPORT_2_0_ABOVE
1380+ , typeof ( SimulatorPipelineStageInSend )
1381+ #endif
13481382#if MULTIPLAYER_TOOLS_1_0_0_PRE_7
13491383 , typeof ( NetworkMetricsPipelineStage )
13501384#endif
13511385 ) ;
13521386 unreliableSequencedFragmentedPipeline = driver . CreatePipeline (
13531387 typeof ( FragmentationPipelineStage ) ,
13541388 typeof ( UnreliableSequencedPipelineStage ) ,
1355- typeof ( SimulatorPipelineStage ) ,
1356- typeof ( SimulatorPipelineStageInSend )
1389+ typeof ( SimulatorPipelineStage )
1390+ #if ! UTP_TRANSPORT_2_0_ABOVE
1391+ , typeof ( SimulatorPipelineStageInSend )
1392+ #endif
13571393#if MULTIPLAYER_TOOLS_1_0_0_PRE_7
13581394 , typeof ( NetworkMetricsPipelineStage )
13591395#endif
13601396 ) ;
13611397 reliableSequencedPipeline = driver . CreatePipeline (
13621398 typeof ( ReliableSequencedPipelineStage ) ,
1363- typeof ( SimulatorPipelineStage ) ,
1364- typeof ( SimulatorPipelineStageInSend )
1399+ typeof ( SimulatorPipelineStage )
1400+ #if ! UTP_TRANSPORT_2_0_ABOVE
1401+ , typeof ( SimulatorPipelineStageInSend )
1402+ #endif
13651403#if MULTIPLAYER_TOOLS_1_0_0_PRE_7
13661404 , typeof ( NetworkMetricsPipelineStage )
13671405#endif
0 commit comments