Skip to content

Commit d5ee369

Browse files
committed
Replaced shorthand NetworkingManager Singleton resolutions
1 parent 6d55a03 commit d5ee369

File tree

4 files changed

+79
-80
lines changed

4 files changed

+79
-80
lines changed

MLAPI/NetworkingManagerComponents/Core/InternalMessageHandler.Receive.cs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,24 @@ internal static void HandleHailRequest(uint clientId, Stream stream, int channel
2323
byte[] serverDiffieHellmanPublicPart = null;
2424
using (PooledBitReader reader = PooledBitReader.Get(stream))
2525
{
26-
if (netManager.NetworkConfig.EnableEncryption)
26+
if (NetworkingManager.Singleton.NetworkConfig.EnableEncryption)
2727
{
2828
// Read the certificate
29-
if (netManager.NetworkConfig.SignKeyExchange)
29+
if (NetworkingManager.Singleton.NetworkConfig.SignKeyExchange)
3030
{
3131
// Allocation justification: This runs on client and only once, at initial connection
3232
certificate = new X509Certificate2(reader.ReadByteArray());
33-
if (CryptographyHelper.VerifyCertificate(certificate, netManager.ConnectedHostname))
33+
if (CryptographyHelper.VerifyCertificate(certificate, NetworkingManager.Singleton.ConnectedHostname))
3434
{
3535
// The certificate is not valid :(
3636
// Man in the middle.
3737
if (LogHelper.CurrentLogLevel <= LogLevel.Normal) if (LogHelper.CurrentLogLevel <= LogLevel.Normal) LogHelper.LogWarning("Invalid certificate. Disconnecting");
38-
netManager.StopClient();
38+
NetworkingManager.Singleton.StopClient();
3939
return;
4040
}
4141
else
4242
{
43-
netManager.NetworkConfig.ServerX509Certificate = certificate;
43+
NetworkingManager.Singleton.NetworkConfig.ServerX509Certificate = certificate;
4444
}
4545
}
4646

@@ -49,7 +49,7 @@ internal static void HandleHailRequest(uint clientId, Stream stream, int channel
4949
serverDiffieHellmanPublicPart = reader.ReadByteArray();
5050

5151
// Verify the key exchange
52-
if (netManager.NetworkConfig.SignKeyExchange)
52+
if (NetworkingManager.Singleton.NetworkConfig.SignKeyExchange)
5353
{
5454
byte[] serverDiffieHellmanPublicPartSignature = reader.ReadByteArray();
5555

@@ -62,7 +62,7 @@ internal static void HandleHailRequest(uint clientId, Stream stream, int channel
6262
if (!rsa.VerifyData(serverDiffieHellmanPublicPart, sha, serverDiffieHellmanPublicPartSignature))
6363
{
6464
if (LogHelper.CurrentLogLevel <= LogLevel.Normal) if (LogHelper.CurrentLogLevel <= LogLevel.Normal) LogHelper.LogWarning("Invalid signature. Disconnecting");
65-
netManager.StopClient();
65+
NetworkingManager.Singleton.StopClient();
6666
return;
6767
}
6868
}
@@ -75,14 +75,14 @@ internal static void HandleHailRequest(uint clientId, Stream stream, int channel
7575
{
7676
using (PooledBitWriter writer = PooledBitWriter.Get(outStream))
7777
{
78-
if (netManager.NetworkConfig.EnableEncryption)
78+
if (NetworkingManager.Singleton.NetworkConfig.EnableEncryption)
7979
{
8080
// Create a ECDH key
8181
EllipticDiffieHellman diffieHellman = new EllipticDiffieHellman(EllipticDiffieHellman.DEFAULT_CURVE, EllipticDiffieHellman.DEFAULT_GENERATOR, EllipticDiffieHellman.DEFAULT_ORDER);
82-
netManager.clientAesKey = diffieHellman.GetSharedSecret(serverDiffieHellmanPublicPart);
82+
NetworkingManager.Singleton.clientAesKey = diffieHellman.GetSharedSecret(serverDiffieHellmanPublicPart);
8383
byte[] diffieHellmanPublicKey = diffieHellman.GetPublicKey();
8484
writer.WriteByteArray(diffieHellmanPublicKey);
85-
if (netManager.NetworkConfig.SignKeyExchange)
85+
if (NetworkingManager.Singleton.NetworkConfig.SignKeyExchange)
8686
{
8787
RSACryptoServiceProvider rsa = certificate.PublicKey.Key as RSACryptoServiceProvider;
8888

@@ -108,19 +108,19 @@ internal static void HandleHailRequest(uint clientId, Stream stream, int channel
108108
// Ran on server
109109
internal static void HandleHailResponse(uint clientId, Stream stream, int channelId)
110110
{
111-
if (!netManager.PendingClients.ContainsKey(clientId) || netManager.PendingClients[clientId].ConnectionState != PendingClient.State.PendingHail) return;
112-
if (!netManager.NetworkConfig.EnableEncryption) return;
111+
if (!NetworkingManager.Singleton.PendingClients.ContainsKey(clientId) || NetworkingManager.Singleton.PendingClients[clientId].ConnectionState != PendingClient.State.PendingHail) return;
112+
if (!NetworkingManager.Singleton.NetworkConfig.EnableEncryption) return;
113113

114114
using (PooledBitReader reader = PooledBitReader.Get(stream))
115115
{
116116
if (NetworkingManager.Singleton.PendingClients[clientId].KeyExchange != null)
117117
{
118118
byte[] diffieHellmanPublic = reader.ReadByteArray();
119-
netManager.PendingClients[clientId].AesKey = netManager.PendingClients[clientId].KeyExchange.GetSharedSecret(diffieHellmanPublic);
120-
if (netManager.NetworkConfig.SignKeyExchange)
119+
NetworkingManager.Singleton.PendingClients[clientId].AesKey = NetworkingManager.Singleton.PendingClients[clientId].KeyExchange.GetSharedSecret(diffieHellmanPublic);
120+
if (NetworkingManager.Singleton.NetworkConfig.SignKeyExchange)
121121
{
122122
byte[] diffieHellmanPublicSignature = reader.ReadByteArray();
123-
X509Certificate2 certificate = netManager.NetworkConfig.ServerX509Certificate;
123+
X509Certificate2 certificate = NetworkingManager.Singleton.NetworkConfig.ServerX509Certificate;
124124
RSACryptoServiceProvider rsa = certificate.PrivateKey as RSACryptoServiceProvider;
125125

126126
if (rsa != null)
@@ -134,7 +134,7 @@ internal static void HandleHailResponse(uint clientId, Stream stream, int channe
134134
{
135135
//Man in the middle.
136136
if (LogHelper.CurrentLogLevel <= LogLevel.Normal) if (LogHelper.CurrentLogLevel <= LogLevel.Normal) LogHelper.LogWarning("Signature doesnt match for the key exchange public part. Disconnecting");
137-
netManager.DisconnectClient(clientId);
137+
NetworkingManager.Singleton.DisconnectClient(clientId);
138138
return;
139139
}
140140
}
@@ -147,8 +147,8 @@ internal static void HandleHailResponse(uint clientId, Stream stream, int channe
147147
}
148148
}
149149

150-
netManager.PendingClients[clientId].ConnectionState = PendingClient.State.PendingConnection;
151-
netManager.PendingClients[clientId].KeyExchange = null; // Give to GC
150+
NetworkingManager.Singleton.PendingClients[clientId].ConnectionState = PendingClient.State.PendingConnection;
151+
NetworkingManager.Singleton.PendingClients[clientId].KeyExchange = null; // Give to GC
152152

153153
// Send greetings, they have passed all the handshakes
154154
using (PooledBitStream outStream = PooledBitStream.Get())
@@ -173,21 +173,21 @@ internal static void HandleConnectionRequest(uint clientId, Stream stream, int c
173173
using (PooledBitReader reader = PooledBitReader.Get(stream))
174174
{
175175
ulong configHash = reader.ReadUInt64Packed();
176-
if (!netManager.NetworkConfig.CompareConfig(configHash))
176+
if (!NetworkingManager.Singleton.NetworkConfig.CompareConfig(configHash))
177177
{
178178
if (LogHelper.CurrentLogLevel <= LogLevel.Normal) LogHelper.LogWarning("NetworkConfiguration mismatch. The configuration between the server and client does not match");
179-
netManager.DisconnectClient(clientId);
179+
NetworkingManager.Singleton.DisconnectClient(clientId);
180180
return;
181181
}
182182

183-
if (netManager.NetworkConfig.ConnectionApproval)
183+
if (NetworkingManager.Singleton.NetworkConfig.ConnectionApproval)
184184
{
185185
byte[] connectionBuffer = reader.ReadByteArray();
186-
netManager.ConnectionApprovalCallback(connectionBuffer, clientId, netManager.HandleApproval);
186+
NetworkingManager.Singleton.ConnectionApprovalCallback(connectionBuffer, clientId, NetworkingManager.Singleton.HandleApproval);
187187
}
188188
else
189189
{
190-
netManager.HandleApproval(clientId, -1, true, null, null);
190+
NetworkingManager.Singleton.HandleApproval(clientId, -1, true, null, null);
191191
}
192192
}
193193
}
@@ -196,10 +196,10 @@ internal static void HandleConnectionApproved(uint clientId, Stream stream, int
196196
{
197197
using (PooledBitReader reader = PooledBitReader.Get(stream))
198198
{
199-
netManager.LocalClientId = reader.ReadUInt32Packed();
199+
NetworkingManager.Singleton.LocalClientId = reader.ReadUInt32Packed();
200200
uint sceneIndex = 0;
201201
Guid sceneSwitchProgressGuid = new Guid();
202-
if (netManager.NetworkConfig.EnableSceneSwitching)
202+
if (NetworkingManager.Singleton.NetworkConfig.EnableSceneSwitching)
203203
{
204204
sceneIndex = reader.ReadUInt32Packed();
205205
sceneSwitchProgressGuid = new Guid(reader.ReadByteArray());
@@ -208,9 +208,9 @@ internal static void HandleConnectionApproved(uint clientId, Stream stream, int
208208
float netTime = reader.ReadSinglePacked();
209209
int remoteStamp = reader.ReadInt32Packed();
210210
int msDelay = NetworkingManager.Singleton.NetworkConfig.NetworkTransport.GetRemoteDelayTimeMS(clientId, remoteStamp, out byte error);
211-
netManager.NetworkTime = netTime + (msDelay / 1000f);
211+
NetworkingManager.Singleton.NetworkTime = netTime + (msDelay / 1000f);
212212

213-
netManager.ConnectedClients.Add(netManager.LocalClientId, new NetworkedClient() { ClientId = netManager.LocalClientId });
213+
NetworkingManager.Singleton.ConnectedClients.Add(NetworkingManager.Singleton.LocalClientId, new NetworkedClient() { ClientId = NetworkingManager.Singleton.LocalClientId });
214214

215215
SpawnManager.DestroySceneObjects();
216216
int objectCount = reader.ReadInt32Packed();
@@ -238,14 +238,14 @@ internal static void HandleConnectionApproved(uint clientId, Stream stream, int
238238
sceneSpawnedInIndex, sceneDelayedSpawn, destroyWithScene, new Vector3(xPos, yPos, zPos), Quaternion.Euler(xRot, yRot, zRot), isActive, stream, false, 0, true);
239239
}
240240

241-
if (netManager.NetworkConfig.EnableSceneSwitching)
241+
if (NetworkingManager.Singleton.NetworkConfig.EnableSceneSwitching)
242242
{
243243
NetworkSceneManager.OnSceneSwitch(sceneIndex, sceneSwitchProgressGuid);
244244
}
245245

246-
netManager.IsConnectedClient = true;
247-
if (netManager.OnClientConnectedCallback != null)
248-
netManager.OnClientConnectedCallback.Invoke(netManager.LocalClientId);
246+
NetworkingManager.Singleton.IsConnectedClient = true;
247+
if (NetworkingManager.Singleton.OnClientConnectedCallback != null)
248+
NetworkingManager.Singleton.OnClientConnectedCallback.Invoke(NetworkingManager.Singleton.LocalClientId);
249249
}
250250
}
251251

@@ -311,12 +311,12 @@ internal static void HandleChangeOwner(uint clientId, Stream stream, int channel
311311
{
312312
uint netId = reader.ReadUInt32Packed();
313313
uint ownerClientId = reader.ReadUInt32Packed();
314-
if (SpawnManager.SpawnedObjects[netId].OwnerClientId == netManager.LocalClientId)
314+
if (SpawnManager.SpawnedObjects[netId].OwnerClientId == NetworkingManager.Singleton.LocalClientId)
315315
{
316316
//We are current owner.
317317
SpawnManager.SpawnedObjects[netId].InvokeBehaviourOnLostOwnership();
318318
}
319-
if (ownerClientId == netManager.LocalClientId)
319+
if (ownerClientId == NetworkingManager.Singleton.LocalClientId)
320320
{
321321
//We are new owner.
322322
SpawnManager.SpawnedObjects[netId].InvokeBehaviourOnGainedOwnership();
@@ -363,7 +363,7 @@ internal static void HandleTimeSync(uint clientId, Stream stream, int channelId)
363363
int timestamp = reader.ReadInt32Packed();
364364

365365
int msDelay = NetworkingManager.Singleton.NetworkConfig.NetworkTransport.GetRemoteDelayTimeMS(clientId, timestamp, out byte error);
366-
netManager.NetworkTime = netTime + (msDelay / 1000f);
366+
NetworkingManager.Singleton.NetworkTime = netTime + (msDelay / 1000f);
367367
}
368368
}
369369

0 commit comments

Comments
 (0)