forked from hunterzonewu/unity-decompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkManager.cs
More file actions
1636 lines (1532 loc) · 55.1 KB
/
NetworkManager.cs
File metadata and controls
1636 lines (1532 loc) · 55.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Decompiled with JetBrains decompiler
// Type: UnityEngine.Networking.NetworkManager
// Assembly: UnityEngine.Networking, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 8B34E19C-EF53-416E-AE36-35C45BAFD2DE
// Assembly location: C:\Users\Blake\sandbox\unity\test-project\Library\UnityAssemblies\UnityEngine.Networking.dll
using System;
using System.Collections.Generic;
using System.Net;
using UnityEngine.Networking.Match;
using UnityEngine.Networking.NetworkSystem;
using UnityEngine.Networking.Types;
using UnityEngine.SceneManagement;
namespace UnityEngine.Networking
{
/// <summary>
/// <para>The NetworkManager is a convenience class for the HLAPI for managing networking systems.</para>
/// </summary>
[AddComponentMenu("Network/NetworkManager")]
public class NetworkManager : MonoBehaviour
{
/// <summary>
/// <para>The name of the current network scene.</para>
/// </summary>
public static string networkSceneName = string.Empty;
private static List<Transform> s_StartPositions = new List<Transform>();
private static AddPlayerMessage s_AddPlayerMessage = new AddPlayerMessage();
private static RemovePlayerMessage s_RemovePlayerMessage = new RemovePlayerMessage();
private static ErrorMessage s_ErrorMessage = new ErrorMessage();
[SerializeField]
private int m_NetworkPort = 7777;
[SerializeField]
private string m_ServerBindAddress = string.Empty;
[SerializeField]
private string m_NetworkAddress = "localhost";
[SerializeField]
private bool m_DontDestroyOnLoad = true;
[SerializeField]
private bool m_RunInBackground = true;
[SerializeField]
private bool m_ScriptCRCCheck = true;
[SerializeField]
private float m_MaxDelay = 0.01f;
[SerializeField]
private LogFilter.FilterLevel m_LogLevel = LogFilter.FilterLevel.Info;
[SerializeField]
private bool m_AutoCreatePlayer = true;
[SerializeField]
private string m_OfflineScene = string.Empty;
[SerializeField]
private string m_OnlineScene = string.Empty;
[SerializeField]
private List<GameObject> m_SpawnPrefabs = new List<GameObject>();
[SerializeField]
private int m_MaxConnections = 4;
[SerializeField]
private List<QosType> m_Channels = new List<QosType>();
[SerializeField]
private int m_SimulatedLatency = 1;
[SerializeField]
private string m_MatchHost = "mm.unet.unity3d.com";
[SerializeField]
private int m_MatchPort = 443;
/// <summary>
/// <para>The name of the current match.</para>
/// </summary>
public string matchName = "default";
/// <summary>
/// <para>The maximum number of players in the current match.</para>
/// </summary>
public uint matchSize = 4;
[SerializeField]
private bool m_ServerBindToIP;
[SerializeField]
private GameObject m_PlayerPrefab;
[SerializeField]
private PlayerSpawnMethod m_PlayerSpawnMethod;
[SerializeField]
private bool m_CustomConfig;
[SerializeField]
private ConnectionConfig m_ConnectionConfig;
[SerializeField]
private GlobalConfig m_GlobalConfig;
[SerializeField]
private bool m_UseWebSockets;
[SerializeField]
private bool m_UseSimulator;
[SerializeField]
private float m_PacketLossPercentage;
private NetworkMigrationManager m_MigrationManager;
private EndPoint m_EndPoint;
private bool m_ClientLoadedScene;
/// <summary>
/// <para>True if the NetworkServer or NetworkClient isactive.</para>
/// </summary>
public bool isNetworkActive;
/// <summary>
/// <para>The current NetworkClient being used by the manager.</para>
/// </summary>
public NetworkClient client;
private static int s_StartPositionIndex;
/// <summary>
/// <para>A MatchInfo instance that will be used when StartServer() or StartClient() are called.</para>
/// </summary>
public MatchInfo matchInfo;
/// <summary>
/// <para>The UMatch matchmaker object.</para>
/// </summary>
public NetworkMatch matchMaker;
/// <summary>
/// <para>The list of matches that are available to join.</para>
/// </summary>
public List<MatchDesc> matches;
/// <summary>
/// <para>The NetworkManager singleton object.</para>
/// </summary>
public static NetworkManager singleton;
private static AsyncOperation s_LoadingSceneAsync;
private static NetworkConnection s_ClientReadyConnection;
private static string s_Address;
private static bool s_DomainReload;
private static NetworkManager s_PendingSingleton;
/// <summary>
/// <para>The network port currently in use.</para>
/// </summary>
public int networkPort
{
get
{
return this.m_NetworkPort;
}
set
{
this.m_NetworkPort = value;
}
}
/// <summary>
/// <para>Flag to tell the server whether to bind to a specific IP address.</para>
/// </summary>
public bool serverBindToIP
{
get
{
return this.m_ServerBindToIP;
}
set
{
this.m_ServerBindToIP = value;
}
}
/// <summary>
/// <para>The IP address to bind the server to.</para>
/// </summary>
public string serverBindAddress
{
get
{
return this.m_ServerBindAddress;
}
set
{
this.m_ServerBindAddress = value;
}
}
/// <summary>
/// <para>The network address currently in use.</para>
/// </summary>
public string networkAddress
{
get
{
return this.m_NetworkAddress;
}
set
{
this.m_NetworkAddress = value;
}
}
/// <summary>
/// <para>A flag to control whether the NetworkManager object is destroyed when the scene changes.</para>
/// </summary>
public bool dontDestroyOnLoad
{
get
{
return this.m_DontDestroyOnLoad;
}
set
{
this.m_DontDestroyOnLoad = value;
}
}
/// <summary>
/// <para>Controls whether the program runs when it is in the background.</para>
/// </summary>
public bool runInBackground
{
get
{
return this.m_RunInBackground;
}
set
{
this.m_RunInBackground = value;
}
}
/// <summary>
/// <para>Flag for using the script CRC check between server and clients.</para>
/// </summary>
public bool scriptCRCCheck
{
get
{
return this.m_ScriptCRCCheck;
}
set
{
this.m_ScriptCRCCheck = value;
}
}
/// <summary>
/// <para>A flag to control sending the network information about every peer to all members of a match.</para>
/// </summary>
[Obsolete("moved to NetworkMigrationManager")]
public bool sendPeerInfo
{
get
{
return false;
}
set
{
}
}
/// <summary>
/// <para>The maximum delay before sending packets on connections.</para>
/// </summary>
public float maxDelay
{
get
{
return this.m_MaxDelay;
}
set
{
this.m_MaxDelay = value;
}
}
/// <summary>
/// <para>The log level specifically to user for network log messages.</para>
/// </summary>
public LogFilter.FilterLevel logLevel
{
get
{
return this.m_LogLevel;
}
set
{
this.m_LogLevel = value;
LogFilter.currentLogLevel = (int) value;
}
}
/// <summary>
/// <para>The default prefab to be used to create player objects on the server.</para>
/// </summary>
public GameObject playerPrefab
{
get
{
return this.m_PlayerPrefab;
}
set
{
this.m_PlayerPrefab = value;
}
}
/// <summary>
/// <para>A flag to control whether or not player objects are automatically created on connect, and on scene change.</para>
/// </summary>
public bool autoCreatePlayer
{
get
{
return this.m_AutoCreatePlayer;
}
set
{
this.m_AutoCreatePlayer = value;
}
}
/// <summary>
/// <para>The current method of spawning players used by the NetworkManager.</para>
/// </summary>
public PlayerSpawnMethod playerSpawnMethod
{
get
{
return this.m_PlayerSpawnMethod;
}
set
{
this.m_PlayerSpawnMethod = value;
}
}
/// <summary>
/// <para>The scene to switch to when offline.</para>
/// </summary>
public string offlineScene
{
get
{
return this.m_OfflineScene;
}
set
{
this.m_OfflineScene = value;
}
}
/// <summary>
/// <para>The scene to switch to when online.</para>
/// </summary>
public string onlineScene
{
get
{
return this.m_OnlineScene;
}
set
{
this.m_OnlineScene = value;
}
}
/// <summary>
/// <para>List of prefabs that will be registered with the spawning system.</para>
/// </summary>
public List<GameObject> spawnPrefabs
{
get
{
return this.m_SpawnPrefabs;
}
}
/// <summary>
/// <para>The list of currently registered player start positions for the current scene.</para>
/// </summary>
public List<Transform> startPositions
{
get
{
return NetworkManager.s_StartPositions;
}
}
/// <summary>
/// <para>Flag to enable custom network configuration.</para>
/// </summary>
public bool customConfig
{
get
{
return this.m_CustomConfig;
}
set
{
this.m_CustomConfig = value;
}
}
/// <summary>
/// <para>The custom network configuration to use.</para>
/// </summary>
public ConnectionConfig connectionConfig
{
get
{
if (this.m_ConnectionConfig == null)
this.m_ConnectionConfig = new ConnectionConfig();
return this.m_ConnectionConfig;
}
}
/// <summary>
/// <para>The transport layer global configuration to be used.</para>
/// </summary>
public GlobalConfig globalConfig
{
get
{
if (this.m_GlobalConfig == null)
this.m_GlobalConfig = new GlobalConfig();
return this.m_GlobalConfig;
}
}
/// <summary>
/// <para>The maximum number of concurrent network connections to support.</para>
/// </summary>
public int maxConnections
{
get
{
return this.m_MaxConnections;
}
set
{
this.m_MaxConnections = value;
}
}
/// <summary>
/// <para>The Quality-of-Service channels to use for the network transport layer.</para>
/// </summary>
public List<QosType> channels
{
get
{
return this.m_Channels;
}
}
/// <summary>
/// <para>Allows you to specify an EndPoint object instead of setting networkAddress and networkPort (required for some platforms such as Xbox One).</para>
/// </summary>
public EndPoint secureTunnelEndpoint
{
get
{
return this.m_EndPoint;
}
set
{
this.m_EndPoint = value;
}
}
/// <summary>
/// <para>This makes the NetworkServer listen for WebSockets connections instead of normal transport layer connections.</para>
/// </summary>
public bool useWebSockets
{
get
{
return this.m_UseWebSockets;
}
set
{
this.m_UseWebSockets = value;
}
}
/// <summary>
/// <para>Flag that control whether clients started by this NetworkManager will use simulated latency and packet loss.</para>
/// </summary>
public bool useSimulator
{
get
{
return this.m_UseSimulator;
}
set
{
this.m_UseSimulator = value;
}
}
/// <summary>
/// <para>The delay in milliseconds to be added to incoming and outgoing packets for clients.</para>
/// </summary>
public int simulatedLatency
{
get
{
return this.m_SimulatedLatency;
}
set
{
this.m_SimulatedLatency = value;
}
}
/// <summary>
/// <para>The percentage of incoming and outgoing packets to be dropped for clients.</para>
/// </summary>
public float packetLossPercentage
{
get
{
return this.m_PacketLossPercentage;
}
set
{
this.m_PacketLossPercentage = value;
}
}
/// <summary>
/// <para>The hostname of the matchmaking server.</para>
/// </summary>
public string matchHost
{
get
{
return this.m_MatchHost;
}
set
{
this.m_MatchHost = value;
}
}
/// <summary>
/// <para>The port of the matchmaking service.</para>
/// </summary>
public int matchPort
{
get
{
return this.m_MatchPort;
}
set
{
this.m_MatchPort = value;
}
}
/// <summary>
/// <para>This is true if the client loaded a new scene when connecting to the server.</para>
/// </summary>
public bool clientLoadedScene
{
get
{
return this.m_ClientLoadedScene;
}
set
{
this.m_ClientLoadedScene = value;
}
}
/// <summary>
/// <para>The migration manager being used with the NetworkManager.</para>
/// </summary>
public NetworkMigrationManager migrationManager
{
get
{
return this.m_MigrationManager;
}
}
/// <summary>
/// <para>NumPlayers is the number of active player objects across all connections on the server.</para>
/// </summary>
public int numPlayers
{
get
{
int num = 0;
foreach (NetworkConnection connection in NetworkServer.connections)
{
if (connection != null)
{
using (List<PlayerController>.Enumerator enumerator = connection.playerControllers.GetEnumerator())
{
while (enumerator.MoveNext())
{
if (enumerator.Current.IsValid)
++num;
}
}
}
}
return num;
}
}
public NetworkManager()
{
NetworkManager.s_PendingSingleton = this;
}
internal static void OnDomainReload()
{
NetworkManager.s_DomainReload = true;
}
private void Awake()
{
this.InitializeSingleton();
}
private void InitializeSingleton()
{
if ((UnityEngine.Object) NetworkManager.singleton != (UnityEngine.Object) null && (UnityEngine.Object) NetworkManager.singleton == (UnityEngine.Object) this)
return;
LogFilter.currentLogLevel = (int) this.m_LogLevel;
if (this.m_DontDestroyOnLoad)
{
if ((UnityEngine.Object) NetworkManager.singleton != (UnityEngine.Object) null)
{
if (LogFilter.logDev)
Debug.Log((object) "Multiple NetworkManagers detected in the scene. Only one NetworkManager can exist at a time. The duplicate NetworkManager will not be used.");
UnityEngine.Object.Destroy((UnityEngine.Object) this.gameObject);
return;
}
if (LogFilter.logDev)
Debug.Log((object) "NetworkManager created singleton (DontDestroyOnLoad)");
NetworkManager.singleton = this;
UnityEngine.Object.DontDestroyOnLoad((UnityEngine.Object) this.gameObject);
}
else
{
if (LogFilter.logDev)
Debug.Log((object) "NetworkManager created singleton (ForScene)");
NetworkManager.singleton = this;
}
if (this.m_NetworkAddress != string.Empty)
{
NetworkManager.s_Address = this.m_NetworkAddress;
}
else
{
if (!(NetworkManager.s_Address != string.Empty))
return;
this.m_NetworkAddress = NetworkManager.s_Address;
}
}
private void OnValidate()
{
if (this.m_SimulatedLatency < 1)
this.m_SimulatedLatency = 1;
if (this.m_SimulatedLatency > 500)
this.m_SimulatedLatency = 500;
if ((double) this.m_PacketLossPercentage < 0.0)
this.m_PacketLossPercentage = 0.0f;
if ((double) this.m_PacketLossPercentage > 99.0)
this.m_PacketLossPercentage = 99f;
if (this.m_MaxConnections <= 0)
this.m_MaxConnections = 1;
if (this.m_MaxConnections > 32000)
this.m_MaxConnections = 32000;
if ((UnityEngine.Object) this.m_PlayerPrefab != (UnityEngine.Object) null && (UnityEngine.Object) this.m_PlayerPrefab.GetComponent<NetworkIdentity>() == (UnityEngine.Object) null)
{
if (LogFilter.logError)
Debug.LogError((object) "NetworkManager - playerPrefab must have a NetworkIdentity.");
this.m_PlayerPrefab = (GameObject) null;
}
if (this.m_ConnectionConfig.MinUpdateTimeout <= 0U)
{
if (LogFilter.logError)
Debug.LogError((object) "NetworkManager MinUpdateTimeout cannot be zero or less. The value will be reset to 1 millisecond");
this.m_ConnectionConfig.MinUpdateTimeout = 1U;
}
if (this.m_GlobalConfig == null || this.m_GlobalConfig.ThreadAwakeTimeout > 0U)
return;
if (LogFilter.logError)
Debug.LogError((object) "NetworkManager ThreadAwakeTimeout cannot be zero or less. The value will be reset to 1 millisecond");
this.m_GlobalConfig.ThreadAwakeTimeout = 1U;
}
internal void RegisterServerMessages()
{
NetworkServer.RegisterHandler((short) 32, new NetworkMessageDelegate(this.OnServerConnectInternal));
NetworkServer.RegisterHandler((short) 33, new NetworkMessageDelegate(this.OnServerDisconnectInternal));
NetworkServer.RegisterHandler((short) 35, new NetworkMessageDelegate(this.OnServerReadyMessageInternal));
NetworkServer.RegisterHandler((short) 37, new NetworkMessageDelegate(this.OnServerAddPlayerMessageInternal));
NetworkServer.RegisterHandler((short) 38, new NetworkMessageDelegate(this.OnServerRemovePlayerMessageInternal));
NetworkServer.RegisterHandler((short) 34, new NetworkMessageDelegate(this.OnServerErrorInternal));
}
/// <summary>
/// <para>This sets up a NetworkMigrationManager object to work with this NetworkManager.</para>
/// </summary>
/// <param name="man">The migration manager object to use with the NetworkManager.</param>
public void SetupMigrationManager(NetworkMigrationManager man)
{
this.m_MigrationManager = man;
}
public bool StartServer(ConnectionConfig config, int maxConnections)
{
return this.StartServer((MatchInfo) null, config, maxConnections);
}
/// <summary>
/// <para>This starts a new server.</para>
/// </summary>
/// <returns>
/// <para>True is the server was started.</para>
/// </returns>
public bool StartServer()
{
return this.StartServer((MatchInfo) null);
}
public bool StartServer(MatchInfo info)
{
return this.StartServer(info, (ConnectionConfig) null, -1);
}
private bool StartServer(MatchInfo info, ConnectionConfig config, int maxConnections)
{
this.InitializeSingleton();
this.OnStartServer();
if (this.m_RunInBackground)
Application.runInBackground = true;
NetworkCRC.scriptCRCCheck = this.scriptCRCCheck;
NetworkServer.useWebSockets = this.m_UseWebSockets;
if (this.m_GlobalConfig != null)
NetworkTransport.Init(this.m_GlobalConfig);
if (this.m_CustomConfig && this.m_ConnectionConfig != null && config == null)
{
this.m_ConnectionConfig.Channels.Clear();
using (List<QosType>.Enumerator enumerator = this.m_Channels.GetEnumerator())
{
while (enumerator.MoveNext())
{
int num = (int) this.m_ConnectionConfig.AddChannel(enumerator.Current);
}
}
NetworkServer.Configure(this.m_ConnectionConfig, this.m_MaxConnections);
}
if (config != null)
NetworkServer.Configure(config, maxConnections);
if (info != null)
{
if (!NetworkServer.Listen(info, this.m_NetworkPort))
{
if (LogFilter.logError)
Debug.LogError((object) "StartServer listen failed.");
return false;
}
}
else if (this.m_ServerBindToIP && !string.IsNullOrEmpty(this.m_ServerBindAddress))
{
if (!NetworkServer.Listen(this.m_ServerBindAddress, this.m_NetworkPort))
{
if (LogFilter.logError)
Debug.LogError((object) ("StartServer listen on " + this.m_ServerBindAddress + " failed."));
return false;
}
}
else if (!NetworkServer.Listen(this.m_NetworkPort))
{
if (LogFilter.logError)
Debug.LogError((object) "StartServer listen failed.");
return false;
}
this.RegisterServerMessages();
if (LogFilter.logDebug)
Debug.Log((object) ("NetworkManager StartServer port:" + (object) this.m_NetworkPort));
this.isNetworkActive = true;
string name = SceneManager.GetSceneAt(0).name;
if (this.m_OnlineScene != string.Empty && this.m_OnlineScene != name && this.m_OnlineScene != this.m_OfflineScene)
this.ServerChangeScene(this.m_OnlineScene);
else
NetworkServer.SpawnObjects();
return true;
}
internal void RegisterClientMessages(NetworkClient client)
{
client.RegisterHandler((short) 32, new NetworkMessageDelegate(this.OnClientConnectInternal));
client.RegisterHandler((short) 33, new NetworkMessageDelegate(this.OnClientDisconnectInternal));
client.RegisterHandler((short) 36, new NetworkMessageDelegate(this.OnClientNotReadyMessageInternal));
client.RegisterHandler((short) 34, new NetworkMessageDelegate(this.OnClientErrorInternal));
client.RegisterHandler((short) 39, new NetworkMessageDelegate(this.OnClientSceneInternal));
if ((UnityEngine.Object) this.m_PlayerPrefab != (UnityEngine.Object) null)
ClientScene.RegisterPrefab(this.m_PlayerPrefab);
using (List<GameObject>.Enumerator enumerator = this.m_SpawnPrefabs.GetEnumerator())
{
while (enumerator.MoveNext())
{
GameObject current = enumerator.Current;
if ((UnityEngine.Object) current != (UnityEngine.Object) null)
ClientScene.RegisterPrefab(current);
}
}
}
/// <summary>
/// <para>This allows the NetworkManager to use a client object created externally to the NetworkManager instead of using StartClient().</para>
/// </summary>
/// <param name="externalClient">The NetworkClient object to use.</param>
public void UseExternalClient(NetworkClient externalClient)
{
if (this.m_RunInBackground)
Application.runInBackground = true;
if (externalClient != null)
{
this.client = externalClient;
this.isNetworkActive = true;
this.RegisterClientMessages(this.client);
this.OnStartClient(this.client);
}
else
{
this.OnStopClient();
ClientScene.DestroyAllClientObjects();
ClientScene.HandleClientDisconnect(this.client.connection);
this.client = (NetworkClient) null;
if (this.m_OfflineScene != string.Empty)
this.ClientChangeScene(this.m_OfflineScene, false);
}
NetworkManager.s_Address = this.m_NetworkAddress;
}
public NetworkClient StartClient(MatchInfo info, ConnectionConfig config)
{
this.InitializeSingleton();
this.matchInfo = info;
if (this.m_RunInBackground)
Application.runInBackground = true;
this.isNetworkActive = true;
if (this.m_GlobalConfig != null)
NetworkTransport.Init(this.m_GlobalConfig);
this.client = new NetworkClient();
if (config != null)
{
if (config.UsePlatformSpecificProtocols && Application.platform != RuntimePlatform.PS4)
throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
this.client.Configure(config, 1);
}
else if (this.m_CustomConfig && this.m_ConnectionConfig != null)
{
this.m_ConnectionConfig.Channels.Clear();
using (List<QosType>.Enumerator enumerator = this.m_Channels.GetEnumerator())
{
while (enumerator.MoveNext())
{
int num = (int) this.m_ConnectionConfig.AddChannel(enumerator.Current);
}
}
if (this.m_ConnectionConfig.UsePlatformSpecificProtocols && Application.platform != RuntimePlatform.PS4)
throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
this.client.Configure(this.m_ConnectionConfig, this.m_MaxConnections);
}
this.RegisterClientMessages(this.client);
if (this.matchInfo != null)
{
if (LogFilter.logDebug)
Debug.Log((object) ("NetworkManager StartClient match: " + (object) this.matchInfo));
this.client.Connect(this.matchInfo);
}
else if (this.m_EndPoint != null)
{
if (LogFilter.logDebug)
Debug.Log((object) "NetworkManager StartClient using provided SecureTunnel");
this.client.Connect(this.m_EndPoint);
}
else
{
if (string.IsNullOrEmpty(this.m_NetworkAddress))
{
if (LogFilter.logError)
Debug.LogError((object) "Must set the Network Address field in the manager");
return (NetworkClient) null;
}
if (LogFilter.logDebug)
Debug.Log((object) ("NetworkManager StartClient address:" + this.m_NetworkAddress + " port:" + (object) this.m_NetworkPort));
if (this.m_UseSimulator)
this.client.ConnectWithSimulator(this.m_NetworkAddress, this.m_NetworkPort, this.m_SimulatedLatency, this.m_PacketLossPercentage);
else
this.client.Connect(this.m_NetworkAddress, this.m_NetworkPort);
}
if ((UnityEngine.Object) this.m_MigrationManager != (UnityEngine.Object) null)
this.m_MigrationManager.Initialize(this.client, this.matchInfo);
this.OnStartClient(this.client);
NetworkManager.s_Address = this.m_NetworkAddress;
return this.client;
}
public NetworkClient StartClient(MatchInfo matchInfo)
{
return this.StartClient(matchInfo, (ConnectionConfig) null);
}
/// <summary>
/// <para>This starts a network client. It uses the networkAddress and networkPort properties as the address to connect to.</para>
/// </summary>
/// <returns>
/// <para>The client object created.</para>
/// </returns>
public NetworkClient StartClient()
{
return this.StartClient((MatchInfo) null, (ConnectionConfig) null);
}
public virtual NetworkClient StartHost(ConnectionConfig config, int maxConnections)
{
this.OnStartHost();
if (!this.StartServer(config, maxConnections))
return (NetworkClient) null;
NetworkClient client = this.ConnectLocalClient();
this.OnServerConnect(client.connection);
this.OnStartClient(client);
return client;
}
public virtual NetworkClient StartHost(MatchInfo info)
{
this.OnStartHost();
this.matchInfo = info;
if (!this.StartServer(info))
return (NetworkClient) null;
NetworkClient client = this.ConnectLocalClient();
this.OnServerConnect(client.connection);
this.OnStartClient(client);
return client;
}
/// <summary>
/// <para>This starts a network "host" - a server and client in the same application.</para>
/// </summary>
/// <returns>
/// <para>The client object created - this is a "local client".</para>
/// </returns>
public virtual NetworkClient StartHost()
{
this.OnStartHost();
if (!this.StartServer())
return (NetworkClient) null;
NetworkClient client = this.ConnectLocalClient();
this.OnServerConnect(client.connection);
this.OnStartClient(client);
return client;
}
private NetworkClient ConnectLocalClient()
{
if (LogFilter.logDebug)
Debug.Log((object) ("NetworkManager StartHost port:" + (object) this.m_NetworkPort));
this.m_NetworkAddress = "localhost";
this.client = ClientScene.ConnectLocalServer();
this.RegisterClientMessages(this.client);
if ((UnityEngine.Object) this.m_MigrationManager != (UnityEngine.Object) null)
this.m_MigrationManager.Initialize(this.client, this.matchInfo);
return this.client;
}
/// <summary>
/// <para>This stops both the client and the server that the manager is using.</para>
/// </summary>
public void StopHost()
{
bool active = NetworkServer.active;
this.OnStopHost();
this.StopServer();
this.StopClient();
if (!((UnityEngine.Object) this.m_MigrationManager != (UnityEngine.Object) null) || !active)
return;
this.m_MigrationManager.LostHostOnHost();
}
/// <summary>
/// <para>Stops the server that the manager is using.</para>
/// </summary>
public void StopServer()
{
if (!NetworkServer.active)
return;
this.OnStopServer();
if (LogFilter.logDebug)
Debug.Log((object) "NetworkManager StopServer");
this.isNetworkActive = false;
NetworkServer.Shutdown();
this.StopMatchMaker();
if (!(this.m_OfflineScene != string.Empty))
return;
this.ServerChangeScene(this.m_OfflineScene);
}
/// <summary>
/// <para>Stops the client that the manager is using.</para>
/// </summary>
public void StopClient()
{
this.OnStopClient();
if (LogFilter.logDebug)