@@ -156,9 +156,11 @@ public bool IsClientConnected
156156 /// </summary>
157157 public NetworkConfig NetworkConfig ;
158158
159+ #if ! DISABLE_CRYPTOGRAPHY
159160 internal EllipticDiffieHellman clientDiffieHellman ;
160161 internal readonly Dictionary < uint , byte [ ] > diffieHellmanPublicKeys = new Dictionary < uint , byte [ ] > ( ) ;
161162 internal byte [ ] clientAesKey ;
163+ #endif
162164
163165 /// <summary>
164166 /// An inspector bool that acts as a Trigger for regenerating RSA keys. Should not be used outside Unity editor.
@@ -235,7 +237,9 @@ private object Init(bool server)
235237 connectedClients . Clear ( ) ;
236238 connectedClientsList . Clear ( ) ;
237239 messageBuffer = new byte [ NetworkConfig . MessageBufferSize ] ;
240+ #if ! DISABLE_CRYPTOGRAPHY
238241 diffieHellmanPublicKeys . Clear ( ) ;
242+ #endif
239243 Data . Cache . messageAttributeHashes . Clear ( ) ;
240244 Data . Cache . messageAttributeNames . Clear ( ) ;
241245 MessageManager . channels . Clear ( ) ;
@@ -707,19 +711,22 @@ private void Update()
707711 else
708712 {
709713 if ( LogHelper . CurrentLogLevel <= LogLevel . Developer ) LogHelper . LogInfo ( "Connected" ) ;
714+ #if ! DISABLE_CRYPTOGRAPHY
710715 byte [ ] diffiePublic = new byte [ 0 ] ;
711716 if ( NetworkConfig . EnableEncryption )
712717 {
713718 clientDiffieHellman = new EllipticDiffieHellman ( EllipticDiffieHellman . DEFAULT_CURVE , EllipticDiffieHellman . DEFAULT_GENERATOR , EllipticDiffieHellman . DEFAULT_ORDER ) ;
714719 diffiePublic = clientDiffieHellman . GetPublicKey ( ) ;
715720 }
721+ #endif
716722
717723 using ( BitWriter writer = BitWriter . Get ( ) )
718724 {
719725 writer . WriteByteArray ( NetworkConfig . GetConfig ( ) , true ) ;
720-
726+ #if ! DISABLE_CRYPTOGRAPHY
721727 if ( NetworkConfig . EnableEncryption )
722728 writer . WriteByteArray ( diffiePublic ) ;
729+ #endif
723730
724731 if ( NetworkConfig . ConnectionApproval )
725732 writer . WriteByteArray ( NetworkConfig . ConnectionData ) ;
@@ -831,6 +838,7 @@ private void HandleIncomingData(uint clientId, byte[] data, int channelId)
831838 }
832839
833840 reader . SkipPadded ( ) ;
841+ #if ! DISABLE_CRYPTOGRAPHY
834842 byte [ ] readBuffer = null ;
835843 if ( NetworkConfig . EncryptedChannelsHashSet . Contains ( MessageManager . reverseChannels [ channelId ] ) )
836844 {
@@ -843,6 +851,9 @@ private void HandleIncomingData(uint clientId, byte[] data, int channelId)
843851 }
844852
845853 using ( BitReader messageReader = readBuffer == null ? reader : BitReader . Get ( readBuffer ) )
854+ #else
855+ using ( BitReader messageReader = reader )
856+ #endif
846857 {
847858 if ( isServer && isPassthrough && ! NetworkConfig . PassthroughMessageHashSet . Contains ( messageType ) )
848859 {
@@ -1012,8 +1023,10 @@ internal void DisconnectClient(uint clientId)
10121023
10131024 connectedClientsList . RemoveAll ( x => x . ClientId == clientId ) ; // :(
10141025
1026+ #if ! DISABLE_CRYPTOGRAPHY
10151027 if ( diffieHellmanPublicKeys . ContainsKey ( clientId ) )
10161028 diffieHellmanPublicKeys . Remove ( clientId ) ;
1029+ #endif
10171030
10181031 foreach ( KeyValuePair < uint , NetworkedObject > pair in SpawnManager . spawnedObjects )
10191032 pair . Value . observers . Remove ( clientId ) ;
@@ -1074,6 +1087,7 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
10741087 if ( pendingClients . Contains ( clientId ) )
10751088 pendingClients . Remove ( clientId ) ;
10761089
1090+ #if ! DISABLE_CRYPTOGRAPHY
10771091 byte [ ] aesKey = new byte [ 0 ] ;
10781092 byte [ ] publicKey = new byte [ 0 ] ;
10791093 byte [ ] publicKeySignature = new byte [ 0 ] ;
@@ -1096,11 +1110,14 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
10961110 }
10971111 }
10981112 }
1113+ #endif
10991114
11001115 NetworkedClient client = new NetworkedClient ( )
11011116 {
11021117 ClientId = clientId ,
1118+ #if ! DISABLE_CRYPTOGRAPHY
11031119 AesKey = aesKey
1120+ #endif
11041121 } ;
11051122 connectedClients . Add ( clientId , client ) ;
11061123 connectedClientsList . Add ( client ) ;
@@ -1120,12 +1137,14 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
11201137 if ( NetworkConfig . EnableSceneSwitching )
11211138 writer . WriteUInt ( NetworkSceneManager . CurrentSceneIndex ) ;
11221139
1140+ #if ! DISABLE_CRYPTOGRAPHY
11231141 if ( NetworkConfig . EnableEncryption )
11241142 {
11251143 writer . WriteByteArray ( publicKey ) ;
11261144 if ( NetworkConfig . SignKeyExchange )
11271145 writer . WriteByteArray ( publicKeySignature ) ;
11281146 }
1147+ #endif
11291148
11301149 writer . WriteFloat ( NetworkTime ) ;
11311150 writer . WriteInt ( NetworkConfig . NetworkTransport . GetNetworkTimestamp ( ) ) ;
@@ -1216,13 +1235,15 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
12161235 if ( pendingClients . Contains ( clientId ) )
12171236 pendingClients . Remove ( clientId ) ;
12181237
1238+ #if ! DISABLE_CRYPTOGRAPHY
12191239 if ( diffieHellmanPublicKeys . ContainsKey ( clientId ) )
12201240 diffieHellmanPublicKeys . Remove ( clientId ) ;
1241+ #endif
12211242
12221243 NetworkConfig . NetworkTransport . DisconnectClient ( clientId ) ;
12231244 }
12241245 }
1225- #region SEND METHODS
1246+ #region SEND METHODS
12261247 /// <summary>
12271248 /// Registers a message handler
12281249 /// </summary>
@@ -1608,6 +1629,6 @@ public NetworkedObject GetNetworkedObject(uint networkId)
16081629 {
16091630 return SpawnManager . spawnedObjects [ networkId ] ;
16101631 }
1611- #endregion
1632+ #endregion
16121633 }
16131634}
0 commit comments