/
NetworkManager.cs
1809 lines (1635 loc) · 51.5 KB
/
NetworkManager.cs
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: CAEE5E9F-B085-483B-8DC7-7FEB12D926E7
// Assembly location: C:\Program Files\Unity 5.1.0b6\Editor\Data\UnityExtensions\Unity\Networking\UnityEngine.Networking.dll
using System;
using System.Collections.Generic;
using System.Net;
using UnityEngine;
using UnityEngine.Networking.Match;
using UnityEngine.Networking.NetworkSystem;
using UnityEngine.Networking.Types;
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 int s_StartPositionIndex = 0;
private static AddPlayerMessage s_AddPlayerMessage = new AddPlayerMessage();
private static RemovePlayerMessage s_RemovePlayerMessage = new RemovePlayerMessage();
private static ErrorMessage s_ErrorMessage = new ErrorMessage();
private static AsyncOperation s_LoadingSceneAsync = (AsyncOperation) null;
[SerializeField]
private int m_NetworkPort = 7777;
[SerializeField]
private string m_NetworkAddress = "localhost";
[SerializeField]
private bool m_DontDestroyOnLoad = true;
[SerializeField]
private bool m_RunInBackground = 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 = 4U;
[SerializeField]
private bool m_SendPeerInfo;
[SerializeField]
private GameObject m_PlayerPrefab;
[SerializeField]
private PlayerSpawnMethod m_PlayerSpawnMethod;
[SerializeField]
private bool m_CustomConfig;
[SerializeField]
private ConnectionConfig m_ConnectionConfig;
[SerializeField]
private bool m_UseSimulator;
[SerializeField]
private float m_PacketLossPercentage;
private EndPoint m_EndPoint;
/// <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;
/// <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 NetworkConnection s_ClientReadyConnection;
private static string s_address;
/// <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>
/// 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>
/// Control 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>
/// A flag to control sending the network information about every peer to all members of a match.
/// </para>
///
/// </summary>
public bool sendPeerInfo
{
get
{
return this.m_SendPeerInfo;
}
set
{
this.m_SendPeerInfo = value;
}
}
/// <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 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>
/// 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>
/// NumPlayers is the number of active player objects across all connections on the server.
/// </para>
///
/// </summary>
public int numPlayers
{
get
{
int num = 0;
using (List<NetworkConnection>.Enumerator enumerator1 = NetworkServer.connections.GetEnumerator())
{
while (enumerator1.MoveNext())
{
NetworkConnection current = enumerator1.Current;
if (current != null)
{
using (List<PlayerController>.Enumerator enumerator2 = current.playerControllers.GetEnumerator())
{
while (enumerator2.MoveNext())
{
if (enumerator2.Current.IsValid)
++num;
}
}
}
}
}
// Checking here if there is more than one player connected from this client to make total player number correct
using (List<NetworkConnection>.Enumerator enumerator1 = NetworkServer.localConnections.GetEnumerator())
{
while (enumerator1.MoveNext())
{
NetworkConnection current = enumerator1.Current;
if (current != null)
{
using (List<PlayerController>.Enumerator enumerator2 = current.playerControllers.GetEnumerator())
{
while (enumerator2.MoveNext())
{
if (enumerator2.Current.IsValid)
++num;
}
}
}
}
}
return num;
}
}
private void Awake()
{
LogFilter.currentLogLevel = (int) this.m_LogLevel;
if (this.m_DontDestroyOnLoad)
{
// Reinforce the singleton idea in awake by deleting a copy if made
if ((UnityEngine.Object) NetworkManager.singleton != (UnityEngine.Object) null)
{
if (LogFilter.logDebug)
Debug.Log((object) "NetworkManager created but singleton already exists");
UnityEngine.Object.Destroy((UnityEngine.Object) this.gameObject);
return;
}
if (LogFilter.logDev)
Debug.Log((object) "NetworkManager created singleton (DontDestroyOnLoad)");
NetworkManager.singleton = this; // set the singleton field for the network game
UnityEngine.Object.DontDestroyOnLoad((UnityEngine.Object) this.gameObject); // persist the same NetManager/singleton object between scenes
}
else // NetManager will not persist between scenes
{
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 (!((UnityEngine.Object) this.m_PlayerPrefab != (UnityEngine.Object) null) || !((UnityEngine.Object) this.m_PlayerPrefab.GetComponent<NetworkIdentity>() == (UnityEngine.Object) null))
return;
if (LogFilter.logError)
Debug.LogError((object) "NetworkManager - playerPrefab must have a NetworkIdentity.");
this.m_PlayerPrefab = (GameObject) null;
}
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));
}
// overloads to handle different config param cases for starting a stand alone server
#region StartServer() overloads
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.OnStartServer();
if (this.m_RunInBackground)
Application.runInBackground = true;
// Check if we have been given custom config info and configure server accordingly if so
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);
}
// register server handlers
this.RegisterServerMessages();
NetworkServer.sendPeerInfo = this.m_SendPeerInfo; // check if we are to send peer info also
// if no custom config has been set and a config param was sent in then use that config
if (config != null)
NetworkServer.Configure(config, maxConnections);
// check the MatchInfo param
if (info != null)
{
if (!NetworkServer.Listen(info, this.m_NetworkPort))
{
if (LogFilter.logError)
Debug.LogError((object) "StartServer listen failed.");
return false;
}
}
else if (!NetworkServer.Listen(this.m_NetworkPort))
{
if (LogFilter.logError)
Debug.LogError((object) "StartServer listen failed.");
return false;
}
if (LogFilter.logDebug)
Debug.Log((object) ("NetworkManager StartServer port:" + (object) this.m_NetworkPort));
this.isNetworkActive = true; // set the flag indicating this object is network active
// transition to the online scene if its name has been set(must be included in build settings before being allowed to be set)
if (this.m_OnlineScene != string.Empty && this.m_OnlineScene != Application.loadedLevelName && this.m_OnlineScene != this.m_OfflineScene)
this.ServerChangeScene(this.m_OnlineScene);
else
NetworkServer.SpawnObjects();
return true;
}
#endregion
// This provided NetManager accounts for a client, server, or host. Register handlers for a client here using the NetworkClient field
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));
// handle the registering of the clients prefab also so it doesnt need to be done manually from separate client code
if ((UnityEngine.Object) this.m_PlayerPrefab != (UnityEngine.Object) null)
ClientScene.RegisterPrefab(this.m_PlayerPrefab);
// Also register any prefabs added in the inspector so they are included in the game for the client, no manual client code also needed
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);
}
}
}
// overloads to handle different config param cases for connecting as a Client
#region StartClient() overloads
// Connections methods return a NetworkClient object, this method connects according to the endpoint being used
public NetworkClient StartClient(MatchInfo info, ConnectionConfig config)
{
this.matchInfo = info;
if (this.m_RunInBackground)
Application.runInBackground = true;
this.isNetworkActive = true;
this.client = new NetworkClient();
this.OnStartClient(this.client);
// if not using a custom config
if (config != null)
this.client.Configure(config, 1);
else if (this.m_CustomConfig && this.m_ConnectionConfig != null) // else using a custom config setup for our clients
{
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);
}
}
this.client.Configure(this.m_ConnectionConfig, this.m_MaxConnections);
}
this.RegisterClientMessages(this.client); // register client handlers
// if a match was sent in then connect to that game
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 we are connecting to an endpoint used by something like XboxOne, then connect there
{
if (LogFilter.logDebug)
Debug.Log((object) "NetworkManager StartClient using provided SecureTunnel");
this.client.Connect(this.m_EndPoint);
}
else // we are going to local connect otherwise if address has been set
{
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)
{
object[] objArray = new object[4];
int index1 = 0;
string str1 = "NetworkManager StartClient address:";
objArray[index1] = (object) str1;
int index2 = 1;
string str2 = this.m_NetworkAddress;
objArray[index2] = (object) str2;
int index3 = 2;
string str3 = " port:";
objArray[index3] = (object) str3;
int index4 = 3;
// ISSUE: variable of a boxed type
__Boxed<int> local = (ValueType) this.m_NetworkPort;
objArray[index4] = (object) local;
Debug.Log((object) string.Concat(objArray));
}
// if using simulator connect that way, otherwise just complete the local network connect
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);
}
NetworkManager.s_address = this.m_NetworkAddress;
return this.client;
}
// StartClient overload that passes info on to other overload
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);
}
#endregion
// overloads to handle different config param cases for starting a Host
#region StartHost() overloads
public virtual NetworkClient StartHost(ConnectionConfig config, int maxConnections)
{
this.OnStartHost(); // this method is empty, just to be used to hook in
if (!this.StartServer(config, maxConnections)) // start a server for the game and local client to connect to
return (NetworkClient) null;
NetworkClient client = this.ConnectLocalClient();
//empty method, just to hook in and do anything with the NetworkClient before it is returned to the caller of StartHost
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.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()