@@ -121,8 +121,16 @@ public struct ConnectionAddressData
121121 [ SerializeField ] public string Address ;
122122 [ SerializeField ] public int Port ;
123123
124- public static implicit operator NetworkEndPoint ( ConnectionAddressData d ) =>
125- NetworkEndPoint . Parse ( d . Address , ( ushort ) d . Port ) ;
124+ public static implicit operator NetworkEndPoint ( ConnectionAddressData d )
125+ {
126+ if ( ! NetworkEndPoint . TryParse ( d . Address , ( ushort ) d . Port , out var networkEndPoint ) )
127+ {
128+ Debug . LogError ( $ "Invalid address { d . Address } :{ d . Port } ") ;
129+ return default ;
130+ }
131+
132+ return networkEndPoint ;
133+ }
126134
127135 public static implicit operator ConnectionAddressData ( NetworkEndPoint d ) =>
128136 new ConnectionAddressData ( ) { Address = d . Address . Split ( ':' ) [ 0 ] , Port = d . Port } ;
@@ -322,12 +330,26 @@ private static RelayConnectionData ConvertConnectionData(byte[] connectionData)
322330 }
323331 }
324332
333+ private void SetProtocol ( ProtocolType inProtocol )
334+ {
335+ m_ProtocolType = inProtocol ;
336+ }
337+
325338 public void SetRelayServerData ( string ipv4Address , ushort port , byte [ ] allocationIdBytes , byte [ ] keyBytes ,
326339 byte [ ] connectionDataBytes , byte [ ] hostConnectionDataBytes = null , bool isSecure = false )
327340 {
328341 RelayConnectionData hostConnectionData ;
329342
330- var serverEndpoint = NetworkEndPoint . Parse ( ipv4Address , port ) ;
343+ if ( ! NetworkEndPoint . TryParse ( ipv4Address , port , out var serverEndpoint ) )
344+ {
345+ Debug . LogError ( $ "Invalid address { ipv4Address } :{ port } ") ;
346+
347+ // We set this to default to cause other checks to fail to state you need to call this
348+ // function again.
349+ m_RelayServerData = default ;
350+ return ;
351+ }
352+
331353 var allocationId = ConvertFromAllocationIdBytes ( allocationIdBytes ) ;
332354 var key = ConvertFromHMAC ( keyBytes ) ;
333355 var connectionData = ConvertConnectionData ( connectionDataBytes ) ;
@@ -344,15 +366,25 @@ public void SetRelayServerData(string ipv4Address, ushort port, byte[] allocatio
344366 m_RelayServerData = new RelayServerData ( ref serverEndpoint , 0 , ref allocationId , ref connectionData ,
345367 ref hostConnectionData , ref key , isSecure ) ;
346368 m_RelayServerData . ComputeNewNonce ( ) ;
369+
370+
371+ SetProtocol ( ProtocolType . RelayUnityTransport ) ;
347372 }
348373
349374 /// <summary>
350375 /// Sets IP and Port information. This will be ignored if using the Unity Relay and you should call <see cref="SetRelayServerData"/>
351376 /// </summary>
352377 public void SetConnectionData ( string ipv4Address , ushort port )
353378 {
354- ConnectionData . Address = ipv4Address ;
355- ConnectionData . Port = port ;
379+ if ( ! NetworkEndPoint . TryParse ( ipv4Address , port , out var endPoint ) )
380+ {
381+ Debug . LogError ( $ "Invalid address { ipv4Address } :{ port } ") ;
382+ ConnectionData = default ;
383+
384+ return ;
385+ }
386+
387+ SetConnectionData ( endPoint ) ;
356388 }
357389
358390 /// <summary>
@@ -361,6 +393,7 @@ public void SetConnectionData(string ipv4Address, ushort port)
361393 public void SetConnectionData ( NetworkEndPoint endPoint )
362394 {
363395 ConnectionData = endPoint ;
396+ SetProtocol ( ProtocolType . UnityTransport ) ;
364397 }
365398
366399 private bool StartRelayServer ( )
0 commit comments