Skip to content

Commit 2b14f67

Browse files
committed
Fixed DISABLE_CRYPTOGRAPHY conditional
1 parent af024bc commit 2b14f67

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

MLAPI/Data/PendingClient.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
using MLAPI.Cryptography;
1+
#if !DISABLE_CRYPTOGRAPHY
2+
using MLAPI.Cryptography;
3+
#endif
24

35
namespace MLAPI.Data
46
{
57
public class PendingClient
68
{
79
public uint ClientId;
8-
10+
11+
#if !DISABLE_CRYPTOGRAPHY
912
internal EllipticDiffieHellman KeyExchange;
10-
13+
#endif
14+
1115
public byte[] AesKey;
1216

1317
public State ConnectionState;

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
using System.IO;
1111
using MLAPI.Components;
1212
using MLAPI.Configuration;
13+
#if !DISABLE_CRYPTOGRAPHY
1314
using MLAPI.Cryptography;
15+
#endif
1416
using MLAPI.Internal;
1517
using MLAPI.Profiling;
1618
using MLAPI.Serialization;
@@ -637,6 +639,7 @@ private void Update()
637639
if (isServer)
638640
{
639641
if (LogHelper.CurrentLogLevel <= LogLevel.Developer) LogHelper.LogInfo("Client Connected");
642+
#if !DISABLE_CRYPTOGRAPHY
640643
if (NetworkConfig.EnableEncryption)
641644
{
642645
// This client is required to complete the crypto-hail exchange.
@@ -687,12 +690,15 @@ private void Update()
687690
}
688691
else
689692
{
693+
#endif
690694
PendingClients.Add(clientId, new PendingClient()
691695
{
692696
ClientId = clientId,
693697
ConnectionState = PendingClient.State.PendingConnection
694698
});
699+
#if !DISABLE_CRYPTOGRAPHY
695700
}
701+
#endif
696702
StartCoroutine(ApprovalTimeout(clientId));
697703
}
698704
else
@@ -889,6 +895,7 @@ private void HandleIncomingData(uint clientId, byte[] data, int channelId, int t
889895
case MLAPIConstants.MLAPI_CUSTOM_MESSAGE:
890896
InternalMessageHandler.HandleCustomMessage(clientId, messageStream, channelId);
891897
break;
898+
#if !DISABLE_CRYPTOGRAPHY
892899
case MLAPIConstants.MLAPI_CERTIFICATE_HAIL:
893900
if (isClient) InternalMessageHandler.HandleHailRequest(clientId, messageStream, channelId);
894901
break;
@@ -898,12 +905,13 @@ private void HandleIncomingData(uint clientId, byte[] data, int channelId, int t
898905
case MLAPIConstants.MLAPI_GREETINGS:
899906
if (isClient) InternalMessageHandler.HandleGreetings(clientId, messageStream, channelId);
900907
break;
901-
default:
902-
if (LogHelper.CurrentLogLevel <= LogLevel.Error) LogHelper.LogError("Read unrecognized messageType " + messageType);
903-
break;
908+
#endif
904909
case MLAPIConstants.MLAPI_CLIENT_SWITCH_SCENE_COMPLETED:
905910
if (isServer) InternalMessageHandler.HandleClientSwitchSceneCompleted(clientId, messageStream, channelId);
906911
break;
912+
default:
913+
if (LogHelper.CurrentLogLevel <= LogLevel.Error) LogHelper.LogError("Read unrecognized messageType " + messageType);
914+
break;
907915
}
908916

909917
#endregion

MLAPI/NetworkingManagerComponents/Core/InternalMessageHandler.Receive.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
using System.Security.Cryptography;
44
using System.Security.Cryptography.X509Certificates;
55
using MLAPI.Components;
6+
#if !DISABLE_CRYPTOGRAPHY
67
using MLAPI.Cryptography;
8+
#endif
79
using MLAPI.Data;
810
using MLAPI.Logging;
911
using MLAPI.Serialization;
@@ -13,6 +15,7 @@ namespace MLAPI.Internal
1315
{
1416
internal static partial class InternalMessageHandler
1517
{
18+
#if !DISABLE_CRYPTOGRAPHY
1619
// Runs on client
1720
internal static void HandleHailRequest(uint clientId, Stream stream, int channelId)
1821
{
@@ -172,6 +175,7 @@ internal static void HandleGreetings(uint clientId, Stream stream, int channelId
172175
// Server greeted us, we can now initiate our request to connect.
173176
NetworkingManager.singleton.SendConnectionRequest();
174177
}
178+
#endif
175179

176180
internal static void HandleConnectionRequest(uint clientId, Stream stream, int channelId)
177181
{

MLAPI/NetworkingManagerComponents/Core/MessageManager.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
using MLAPI.Cryptography;
1+
#if !DISABLE_CRYPTOGRAPHY
2+
using MLAPI.Cryptography;
3+
#endif
24
using MLAPI.Data;
35
using MLAPI.Logging;
46
using MLAPI.Serialization;
57
using System;
68
using System.Collections.Generic;
9+
#if !DISABLE_CRYPTOGRAPHY
710
using System.Security.Cryptography;
11+
#endif
812

913
namespace MLAPI.Internal
1014
{
@@ -28,6 +32,7 @@ internal static BitStream UnwrapMessage(BitStream inputStream, uint clientId, ou
2832
bool isEncrypted = inputHeaderReader.ReadBit();
2933
bool isAuthenticated = inputHeaderReader.ReadBit();
3034

35+
#if !DISABLE_CRYPTOGRAPHY
3136
if (isEncrypted || isAuthenticated)
3237
{
3338
if (!NetworkingManager.singleton.NetworkConfig.EnableEncryption)
@@ -124,10 +129,13 @@ internal static BitStream UnwrapMessage(BitStream inputStream, uint clientId, ou
124129
}
125130
else
126131
{
132+
#endif
127133
messageType = inputHeaderReader.ReadByteBits(6);
128134
// The input stream is now ready to be read from. It's "safe" and has the correct position
129135
return inputStream;
136+
#if !DISABLE_CRYPTOGRAPHY
130137
}
138+
#endif
131139
}
132140
catch (Exception e)
133141
{
@@ -153,7 +161,8 @@ internal static BitStream WrapMessage(byte messageType, uint clientId, BitStream
153161
{
154162
outWriter.WriteBit(encrypted);
155163
outWriter.WriteBit(authenticated);
156-
164+
165+
#if !DISABLE_CRYPTOGRAPHY
157166
if (authenticated || encrypted)
158167
{
159168
outWriter.WritePadBits();
@@ -214,9 +223,12 @@ internal static BitStream WrapMessage(byte messageType, uint clientId, BitStream
214223
}
215224
else
216225
{
226+
#endif
217227
outWriter.WriteBits(messageType, 6);
218228
outStream.Write(messageBody.GetBuffer(), 0, (int)messageBody.Length);
229+
#if !DISABLE_CRYPTOGRAPHY
219230
}
231+
#endif
220232
}
221233

222234
return outStream;

0 commit comments

Comments
 (0)