using System; using System.Collections.Generic; using System.Net; using System.Net.Sockets; using UnityEngine.Networking.Match; using UnityEngine.Networking.NetworkSystem; namespace UnityEngine.Networking { // Token: 0x0200003D RID: 61 public class NetworkClient { // Token: 0x06000160 RID: 352 RVA: 0x00004CE4 File Offset: 0x00002EE4 public NetworkClient() { if (LogFilter.logDev) { Debug.Log("Client created version " + Version.Current); } this.m_MsgBuffer = new byte[65535]; this.m_MsgReader = new NetworkReader(this.m_MsgBuffer); NetworkClient.AddClient(this); } // Token: 0x06000161 RID: 353 RVA: 0x00004D88 File Offset: 0x00002F88 public NetworkClient(NetworkConnection conn) { if (LogFilter.logDev) { Debug.Log("Client created version " + Version.Current); } this.m_MsgBuffer = new byte[65535]; this.m_MsgReader = new NetworkReader(this.m_MsgBuffer); NetworkClient.AddClient(this); NetworkClient.SetActive(true); this.m_Connection = conn; this.m_AsyncConnect = NetworkClient.ConnectState.Connected; conn.SetHandlers(this.m_MessageHandlers); this.RegisterSystemHandlers(false); } // Token: 0x1700002C RID: 44 // (get) Token: 0x06000162 RID: 354 RVA: 0x00004E54 File Offset: 0x00003054 public static List allClients { get { return NetworkClient.s_Clients; } } // Token: 0x1700002D RID: 45 // (get) Token: 0x06000163 RID: 355 RVA: 0x00004E70 File Offset: 0x00003070 public static bool active { get { return NetworkClient.s_IsActive; } } // Token: 0x06000164 RID: 356 RVA: 0x00004E8A File Offset: 0x0000308A internal void SetHandlers(NetworkConnection conn) { conn.SetHandlers(this.m_MessageHandlers); } // Token: 0x1700002E RID: 46 // (get) Token: 0x06000165 RID: 357 RVA: 0x00004E9C File Offset: 0x0000309C public string serverIp { get { return this.m_ServerIp; } } // Token: 0x1700002F RID: 47 // (get) Token: 0x06000166 RID: 358 RVA: 0x00004EB8 File Offset: 0x000030B8 public int serverPort { get { return this.m_ServerPort; } } // Token: 0x17000030 RID: 48 // (get) Token: 0x06000167 RID: 359 RVA: 0x00004ED4 File Offset: 0x000030D4 public NetworkConnection connection { get { return this.m_Connection; } } // Token: 0x17000031 RID: 49 // (get) Token: 0x06000168 RID: 360 RVA: 0x00004EF0 File Offset: 0x000030F0 [Obsolete("Moved to NetworkMigrationManager.")] public PeerInfoMessage[] peers { get { return null; } } // Token: 0x17000032 RID: 50 // (get) Token: 0x06000169 RID: 361 RVA: 0x00004F08 File Offset: 0x00003108 internal int hostId { get { return this.m_ClientId; } } // Token: 0x17000033 RID: 51 // (get) Token: 0x0600016A RID: 362 RVA: 0x00004F24 File Offset: 0x00003124 public Dictionary handlers { get { return this.m_MessageHandlers.GetHandlers(); } } // Token: 0x17000034 RID: 52 // (get) Token: 0x0600016B RID: 363 RVA: 0x00004F44 File Offset: 0x00003144 public int numChannels { get { return this.m_HostTopology.DefaultConfig.ChannelCount; } } // Token: 0x17000035 RID: 53 // (get) Token: 0x0600016C RID: 364 RVA: 0x00004F6C File Offset: 0x0000316C public HostTopology hostTopology { get { return this.m_HostTopology; } } // Token: 0x17000036 RID: 54 // (get) Token: 0x0600016D RID: 365 RVA: 0x00004F88 File Offset: 0x00003188 // (set) Token: 0x0600016E RID: 366 RVA: 0x00004FA3 File Offset: 0x000031A3 public int hostPort { get { return this.m_HostPort; } set { if (value < 0) { throw new ArgumentException("Port must not be a negative number."); } if (value > 65535) { throw new ArgumentException("Port must not be greater than 65535."); } this.m_HostPort = value; } } // Token: 0x17000037 RID: 55 // (get) Token: 0x0600016F RID: 367 RVA: 0x00004FD8 File Offset: 0x000031D8 public bool isConnected { get { return this.m_AsyncConnect == NetworkClient.ConnectState.Connected; } } // Token: 0x17000038 RID: 56 // (get) Token: 0x06000170 RID: 368 RVA: 0x00004FF8 File Offset: 0x000031F8 public Type networkConnectionClass { get { return this.m_NetworkConnectionClass; } } // Token: 0x06000171 RID: 369 RVA: 0x00005013 File Offset: 0x00003213 public void SetNetworkConnectionClass() where T : NetworkConnection { this.m_NetworkConnectionClass = typeof(T); } // Token: 0x06000172 RID: 370 RVA: 0x00005028 File Offset: 0x00003228 public bool Configure(ConnectionConfig config, int maxConnections) { HostTopology hostTopology = new HostTopology(config, maxConnections); return this.Configure(hostTopology); } // Token: 0x06000173 RID: 371 RVA: 0x0000504C File Offset: 0x0000324C public bool Configure(HostTopology topology) { this.m_HostTopology = topology; return true; } // Token: 0x06000174 RID: 372 RVA: 0x00005069 File Offset: 0x00003269 public void Connect(MatchInfo matchInfo) { this.PrepareForConnect(); this.ConnectWithRelay(matchInfo); } // Token: 0x06000175 RID: 373 RVA: 0x0000507C File Offset: 0x0000327C public bool ReconnectToNewHost(string serverIp, int serverPort) { bool flag; if (!NetworkClient.active) { if (LogFilter.logError) { Debug.LogError("Reconnect - NetworkClient must be active"); } flag = false; } else if (this.m_Connection == null) { if (LogFilter.logError) { Debug.LogError("Reconnect - no old connection exists"); } flag = false; } else { if (LogFilter.logInfo) { Debug.Log(string.Concat(new object[] { "NetworkClient Reconnect ", serverIp, ":", serverPort })); } ClientScene.HandleClientDisconnect(this.m_Connection); ClientScene.ClearLocalPlayers(); this.m_Connection.Disconnect(); this.m_Connection = null; this.m_ClientId = NetworkTransport.AddHost(this.m_HostTopology, this.m_HostPort); this.m_ServerPort = serverPort; if (Application.platform == RuntimePlatform.WebGLPlayer) { this.m_ServerIp = serverIp; this.m_AsyncConnect = NetworkClient.ConnectState.Resolved; } else if (serverIp.Equals("127.0.0.1") || serverIp.Equals("localhost")) { this.m_ServerIp = "127.0.0.1"; this.m_AsyncConnect = NetworkClient.ConnectState.Resolved; } else { if (LogFilter.logDebug) { Debug.Log("Async DNS START:" + serverIp); } this.m_AsyncConnect = NetworkClient.ConnectState.Resolving; Dns.BeginGetHostAddresses(serverIp, new AsyncCallback(NetworkClient.GetHostAddressesCallback), this); } flag = true; } return flag; } // Token: 0x06000176 RID: 374 RVA: 0x000051F4 File Offset: 0x000033F4 public bool ReconnectToNewHost(EndPoint secureTunnelEndPoint) { bool flag; if (!NetworkClient.active) { if (LogFilter.logError) { Debug.LogError("Reconnect - NetworkClient must be active"); } flag = false; } else if (this.m_Connection == null) { if (LogFilter.logError) { Debug.LogError("Reconnect - no old connection exists"); } flag = false; } else { if (LogFilter.logInfo) { Debug.Log("NetworkClient Reconnect to remoteSockAddr"); } ClientScene.HandleClientDisconnect(this.m_Connection); ClientScene.ClearLocalPlayers(); this.m_Connection.Disconnect(); this.m_Connection = null; this.m_ClientId = NetworkTransport.AddHost(this.m_HostTopology, this.m_HostPort); if (secureTunnelEndPoint == null) { if (LogFilter.logError) { Debug.LogError("Reconnect failed: null endpoint passed in"); } this.m_AsyncConnect = NetworkClient.ConnectState.Failed; flag = false; } else if (secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetwork && secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetworkV6) { if (LogFilter.logError) { Debug.LogError("Reconnect failed: Endpoint AddressFamily must be either InterNetwork or InterNetworkV6"); } this.m_AsyncConnect = NetworkClient.ConnectState.Failed; flag = false; } else { string fullName = secureTunnelEndPoint.GetType().FullName; if (fullName == "System.Net.IPEndPoint") { IPEndPoint ipendPoint = (IPEndPoint)secureTunnelEndPoint; this.Connect(ipendPoint.Address.ToString(), ipendPoint.Port); flag = this.m_AsyncConnect != NetworkClient.ConnectState.Failed; } else if (fullName != "UnityEngine.XboxOne.XboxOneEndPoint" && fullName != "UnityEngine.PS4.SceEndPoint") { if (LogFilter.logError) { Debug.LogError("Reconnect failed: invalid Endpoint (not IPEndPoint or XboxOneEndPoint or SceEndPoint)"); } this.m_AsyncConnect = NetworkClient.ConnectState.Failed; flag = false; } else { byte b = 0; this.m_RemoteEndPoint = secureTunnelEndPoint; this.m_AsyncConnect = NetworkClient.ConnectState.Connecting; try { this.m_ClientConnectionId = NetworkTransport.ConnectEndPoint(this.m_ClientId, this.m_RemoteEndPoint, 0, out b); } catch (Exception ex) { if (LogFilter.logError) { Debug.LogError("Reconnect failed: Exception when trying to connect to EndPoint: " + ex); } this.m_AsyncConnect = NetworkClient.ConnectState.Failed; return false; } if (this.m_ClientConnectionId == 0) { if (LogFilter.logError) { Debug.LogError("Reconnect failed: Unable to connect to EndPoint (" + b + ")"); } this.m_AsyncConnect = NetworkClient.ConnectState.Failed; flag = false; } else { this.m_Connection = (NetworkConnection)Activator.CreateInstance(this.m_NetworkConnectionClass); this.m_Connection.SetHandlers(this.m_MessageHandlers); this.m_Connection.Initialize(this.m_ServerIp, this.m_ClientId, this.m_ClientConnectionId, this.m_HostTopology); flag = true; } } } } return flag; } // Token: 0x06000177 RID: 375 RVA: 0x000054A0 File Offset: 0x000036A0 public void ConnectWithSimulator(string serverIp, int serverPort, int latency, float packetLoss) { this.m_UseSimulator = true; this.m_SimulatedLatency = latency; this.m_PacketLoss = packetLoss; this.Connect(serverIp, serverPort); } // Token: 0x06000178 RID: 376 RVA: 0x000054C4 File Offset: 0x000036C4 private static bool IsValidIpV6(string address) { foreach (char c in address) { if (c != ':' && (c < '0' || c > '9') && (c < 'a' || c > 'f') && (c < 'A' || c > 'F')) { return false; } } return true; } // Token: 0x06000179 RID: 377 RVA: 0x00005540 File Offset: 0x00003740 public void Connect(string serverIp, int serverPort) { this.PrepareForConnect(); if (LogFilter.logDebug) { Debug.Log(string.Concat(new object[] { "Client Connect: ", serverIp, ":", serverPort })); } this.m_ServerPort = serverPort; if (Application.platform == RuntimePlatform.WebGLPlayer) { this.m_ServerIp = serverIp; this.m_AsyncConnect = NetworkClient.ConnectState.Resolved; } else if (serverIp.Equals("127.0.0.1") || serverIp.Equals("localhost")) { this.m_ServerIp = "127.0.0.1"; this.m_AsyncConnect = NetworkClient.ConnectState.Resolved; } else if (serverIp.IndexOf(":") != -1 && NetworkClient.IsValidIpV6(serverIp)) { this.m_ServerIp = serverIp; this.m_AsyncConnect = NetworkClient.ConnectState.Resolved; } else { if (LogFilter.logDebug) { Debug.Log("Async DNS START:" + serverIp); } this.m_RequestedServerHost = serverIp; this.m_AsyncConnect = NetworkClient.ConnectState.Resolving; Dns.BeginGetHostAddresses(serverIp, new AsyncCallback(NetworkClient.GetHostAddressesCallback), this); } } // Token: 0x0600017A RID: 378 RVA: 0x00005674 File Offset: 0x00003874 public void Connect(EndPoint secureTunnelEndPoint) { bool flag = NetworkTransport.DoesEndPointUsePlatformProtocols(secureTunnelEndPoint); this.PrepareForConnect(flag); if (LogFilter.logDebug) { Debug.Log("Client Connect to remoteSockAddr"); } if (secureTunnelEndPoint == null) { if (LogFilter.logError) { Debug.LogError("Connect failed: null endpoint passed in"); } this.m_AsyncConnect = NetworkClient.ConnectState.Failed; } else if (secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetwork && secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetworkV6) { if (LogFilter.logError) { Debug.LogError("Connect failed: Endpoint AddressFamily must be either InterNetwork or InterNetworkV6"); } this.m_AsyncConnect = NetworkClient.ConnectState.Failed; } else { string fullName = secureTunnelEndPoint.GetType().FullName; if (fullName == "System.Net.IPEndPoint") { IPEndPoint ipendPoint = (IPEndPoint)secureTunnelEndPoint; this.Connect(ipendPoint.Address.ToString(), ipendPoint.Port); } else if (fullName != "UnityEngine.XboxOne.XboxOneEndPoint" && fullName != "UnityEngine.PS4.SceEndPoint" && fullName != "UnityEngine.PSVita.SceEndPoint") { if (LogFilter.logError) { Debug.LogError("Connect failed: invalid Endpoint (not IPEndPoint or XboxOneEndPoint or SceEndPoint)"); } this.m_AsyncConnect = NetworkClient.ConnectState.Failed; } else { byte b = 0; this.m_RemoteEndPoint = secureTunnelEndPoint; this.m_AsyncConnect = NetworkClient.ConnectState.Connecting; try { this.m_ClientConnectionId = NetworkTransport.ConnectEndPoint(this.m_ClientId, this.m_RemoteEndPoint, 0, out b); } catch (Exception ex) { if (LogFilter.logError) { Debug.LogError("Connect failed: Exception when trying to connect to EndPoint: " + ex); } this.m_AsyncConnect = NetworkClient.ConnectState.Failed; return; } if (this.m_ClientConnectionId == 0) { if (LogFilter.logError) { Debug.LogError("Connect failed: Unable to connect to EndPoint (" + b + ")"); } this.m_AsyncConnect = NetworkClient.ConnectState.Failed; } else { this.m_Connection = (NetworkConnection)Activator.CreateInstance(this.m_NetworkConnectionClass); this.m_Connection.SetHandlers(this.m_MessageHandlers); this.m_Connection.Initialize(this.m_ServerIp, this.m_ClientId, this.m_ClientConnectionId, this.m_HostTopology); } } } } // Token: 0x0600017B RID: 379 RVA: 0x00005894 File Offset: 0x00003A94 private void PrepareForConnect() { this.PrepareForConnect(false); } // Token: 0x0600017C RID: 380 RVA: 0x000058A0 File Offset: 0x00003AA0 private void PrepareForConnect(bool usePlatformSpecificProtocols) { NetworkClient.SetActive(true); this.RegisterSystemHandlers(false); if (this.m_HostTopology == null) { ConnectionConfig connectionConfig = new ConnectionConfig(); connectionConfig.AddChannel(QosType.ReliableSequenced); connectionConfig.AddChannel(QosType.Unreliable); connectionConfig.UsePlatformSpecificProtocols = usePlatformSpecificProtocols; this.m_HostTopology = new HostTopology(connectionConfig, 8); } if (this.m_UseSimulator) { int num = this.m_SimulatedLatency / 3 - 1; if (num < 1) { num = 1; } int num2 = this.m_SimulatedLatency * 3; if (LogFilter.logDebug) { Debug.Log(string.Concat(new object[] { "AddHost Using Simulator ", num, "/", num2 })); } this.m_ClientId = NetworkTransport.AddHostWithSimulator(this.m_HostTopology, num, num2, this.m_HostPort); } else { this.m_ClientId = NetworkTransport.AddHost(this.m_HostTopology, this.m_HostPort); } } // Token: 0x0600017D RID: 381 RVA: 0x00005994 File Offset: 0x00003B94 internal static void GetHostAddressesCallback(IAsyncResult ar) { try { IPAddress[] array = Dns.EndGetHostAddresses(ar); NetworkClient networkClient = (NetworkClient)ar.AsyncState; if (array.Length == 0) { if (LogFilter.logError) { Debug.LogError("DNS lookup failed for:" + networkClient.m_RequestedServerHost); } networkClient.m_AsyncConnect = NetworkClient.ConnectState.Failed; } else { networkClient.m_ServerIp = array[0].ToString(); networkClient.m_AsyncConnect = NetworkClient.ConnectState.Resolved; if (LogFilter.logDebug) { Debug.Log(string.Concat(new string[] { "Async DNS Result:", networkClient.m_ServerIp, " for ", networkClient.m_RequestedServerHost, ": ", networkClient.m_ServerIp })); } } } catch (SocketException ex) { NetworkClient networkClient2 = (NetworkClient)ar.AsyncState; if (LogFilter.logError) { Debug.LogError("DNS resolution failed: " + ex.GetErrorCode()); } if (LogFilter.logDebug) { Debug.Log("Exception:" + ex); } networkClient2.m_AsyncConnect = NetworkClient.ConnectState.Failed; } } // Token: 0x0600017E RID: 382 RVA: 0x00005AC0 File Offset: 0x00003CC0 internal void ContinueConnect() { if (this.m_UseSimulator) { int num = this.m_SimulatedLatency / 3; if (num < 1) { num = 1; } if (LogFilter.logDebug) { Debug.Log(string.Concat(new object[] { "Connect Using Simulator ", this.m_SimulatedLatency / 3, "/", this.m_SimulatedLatency })); } ConnectionSimulatorConfig connectionSimulatorConfig = new ConnectionSimulatorConfig(num, this.m_SimulatedLatency, num, this.m_SimulatedLatency, this.m_PacketLoss); byte b; this.m_ClientConnectionId = NetworkTransport.ConnectWithSimulator(this.m_ClientId, this.m_ServerIp, this.m_ServerPort, 0, out b, connectionSimulatorConfig); } else { byte b; this.m_ClientConnectionId = NetworkTransport.Connect(this.m_ClientId, this.m_ServerIp, this.m_ServerPort, 0, out b); } this.m_Connection = (NetworkConnection)Activator.CreateInstance(this.m_NetworkConnectionClass); this.m_Connection.SetHandlers(this.m_MessageHandlers); this.m_Connection.Initialize(this.m_ServerIp, this.m_ClientId, this.m_ClientConnectionId, this.m_HostTopology); } // Token: 0x0600017F RID: 383 RVA: 0x00005BE8 File Offset: 0x00003DE8 private void ConnectWithRelay(MatchInfo info) { this.m_AsyncConnect = NetworkClient.ConnectState.Connecting; this.Update(); byte b; this.m_ClientConnectionId = NetworkTransport.ConnectToNetworkPeer(this.m_ClientId, info.address, info.port, 0, 0, info.networkId, Utility.GetSourceID(), info.nodeId, out b); this.m_Connection = (NetworkConnection)Activator.CreateInstance(this.m_NetworkConnectionClass); this.m_Connection.SetHandlers(this.m_MessageHandlers); this.m_Connection.Initialize(info.address, this.m_ClientId, this.m_ClientConnectionId, this.m_HostTopology); if (b != 0) { Debug.LogError("ConnectToNetworkPeer Error: " + b); } } // Token: 0x06000180 RID: 384 RVA: 0x00005C9C File Offset: 0x00003E9C public virtual void Disconnect() { this.m_AsyncConnect = NetworkClient.ConnectState.Disconnected; ClientScene.HandleClientDisconnect(this.m_Connection); if (this.m_Connection != null) { this.m_Connection.Disconnect(); this.m_Connection.Dispose(); this.m_Connection = null; if (this.m_ClientId != -1) { NetworkTransport.RemoveHost(this.m_ClientId); this.m_ClientId = -1; } } } // Token: 0x06000181 RID: 385 RVA: 0x00005D08 File Offset: 0x00003F08 public bool Send(short msgType, MessageBase msg) { bool flag; if (this.m_Connection != null) { if (this.m_AsyncConnect != NetworkClient.ConnectState.Connected) { if (LogFilter.logError) { Debug.LogError("NetworkClient Send when not connected to a server"); } flag = false; } else { flag = this.m_Connection.Send(msgType, msg); } } else { if (LogFilter.logError) { Debug.LogError("NetworkClient Send with no connection"); } flag = false; } return flag; } // Token: 0x06000182 RID: 386 RVA: 0x00005D80 File Offset: 0x00003F80 public bool SendWriter(NetworkWriter writer, int channelId) { bool flag; if (this.m_Connection != null) { if (this.m_AsyncConnect != NetworkClient.ConnectState.Connected) { if (LogFilter.logError) { Debug.LogError("NetworkClient SendWriter when not connected to a server"); } flag = false; } else { flag = this.m_Connection.SendWriter(writer, channelId); } } else { if (LogFilter.logError) { Debug.LogError("NetworkClient SendWriter with no connection"); } flag = false; } return flag; } // Token: 0x06000183 RID: 387 RVA: 0x00005DF8 File Offset: 0x00003FF8 public bool SendBytes(byte[] data, int numBytes, int channelId) { bool flag; if (this.m_Connection != null) { if (this.m_AsyncConnect != NetworkClient.ConnectState.Connected) { if (LogFilter.logError) { Debug.LogError("NetworkClient SendBytes when not connected to a server"); } flag = false; } else { flag = this.m_Connection.SendBytes(data, numBytes, channelId); } } else { if (LogFilter.logError) { Debug.LogError("NetworkClient SendBytes with no connection"); } flag = false; } return flag; } // Token: 0x06000184 RID: 388 RVA: 0x00005E70 File Offset: 0x00004070 public bool SendUnreliable(short msgType, MessageBase msg) { bool flag; if (this.m_Connection != null) { if (this.m_AsyncConnect != NetworkClient.ConnectState.Connected) { if (LogFilter.logError) { Debug.LogError("NetworkClient SendUnreliable when not connected to a server"); } flag = false; } else { flag = this.m_Connection.SendUnreliable(msgType, msg); } } else { if (LogFilter.logError) { Debug.LogError("NetworkClient SendUnreliable with no connection"); } flag = false; } return flag; } // Token: 0x06000185 RID: 389 RVA: 0x00005EE8 File Offset: 0x000040E8 public bool SendByChannel(short msgType, MessageBase msg, int channelId) { bool flag; if (this.m_Connection != null) { if (this.m_AsyncConnect != NetworkClient.ConnectState.Connected) { if (LogFilter.logError) { Debug.LogError("NetworkClient SendByChannel when not connected to a server"); } flag = false; } else { flag = this.m_Connection.SendByChannel(msgType, msg, channelId); } } else { if (LogFilter.logError) { Debug.LogError("NetworkClient SendByChannel with no connection"); } flag = false; } return flag; } // Token: 0x06000186 RID: 390 RVA: 0x00005F5E File Offset: 0x0000415E public void SetMaxDelay(float seconds) { if (this.m_Connection == null) { if (LogFilter.logWarn) { Debug.LogWarning("SetMaxDelay failed, not connected."); } } else { this.m_Connection.SetMaxDelay(seconds); } } // Token: 0x06000187 RID: 391 RVA: 0x00005F94 File Offset: 0x00004194 public void Shutdown() { if (LogFilter.logDebug) { Debug.Log("Shutting down client " + this.m_ClientId); } if (this.m_ClientId != -1) { NetworkTransport.RemoveHost(this.m_ClientId); this.m_ClientId = -1; } NetworkClient.RemoveClient(this); if (NetworkClient.s_Clients.Count == 0) { NetworkClient.SetActive(false); } } // Token: 0x06000188 RID: 392 RVA: 0x00006008 File Offset: 0x00004208 internal virtual void Update() { if (this.m_ClientId != -1) { switch (this.m_AsyncConnect) { case NetworkClient.ConnectState.None: case NetworkClient.ConnectState.Resolving: case NetworkClient.ConnectState.Disconnected: return; case NetworkClient.ConnectState.Resolved: this.m_AsyncConnect = NetworkClient.ConnectState.Connecting; this.ContinueConnect(); return; case NetworkClient.ConnectState.Failed: this.GenerateConnectError(11); this.m_AsyncConnect = NetworkClient.ConnectState.Disconnected; return; } if (this.m_Connection != null) { if ((int)Time.time != this.m_StatResetTime) { this.m_Connection.ResetStats(); this.m_StatResetTime = (int)Time.time; } } int num = 0; byte b; for (;;) { int num2; int num3; int num4; NetworkEventType networkEventType = NetworkTransport.ReceiveFromHost(this.m_ClientId, out num2, out num3, this.m_MsgBuffer, (int)((ushort)this.m_MsgBuffer.Length), out num4, out b); if (this.m_Connection != null) { this.m_Connection.lastError = (NetworkError)b; } if (networkEventType != NetworkEventType.Nothing) { if (LogFilter.logDev) { Debug.Log(string.Concat(new object[] { "Client event: host=", this.m_ClientId, " event=", networkEventType, " error=", b })); } } switch (networkEventType) { case NetworkEventType.DataEvent: if (b != 0) { goto Block_11; } this.m_MsgReader.SeekZero(); this.m_Connection.TransportReceive(this.m_MsgBuffer, num4, num3); break; case NetworkEventType.ConnectEvent: if (LogFilter.logDebug) { Debug.Log("Client connected"); } if (b != 0) { goto Block_10; } this.m_AsyncConnect = NetworkClient.ConnectState.Connected; this.m_Connection.InvokeHandlerNoData(32); break; case NetworkEventType.DisconnectEvent: if (LogFilter.logDebug) { Debug.Log("Client disconnected"); } this.m_AsyncConnect = NetworkClient.ConnectState.Disconnected; if (b != 0) { if (b != 6) { this.GenerateDisconnectError((int)b); } } ClientScene.HandleClientDisconnect(this.m_Connection); if (this.m_Connection != null) { this.m_Connection.InvokeHandlerNoData(33); } break; case NetworkEventType.Nothing: break; default: if (LogFilter.logError) { Debug.LogError("Unknown network message type received: " + networkEventType); } break; } if (++num >= 500) { goto Block_17; } if (this.m_ClientId == -1) { goto Block_19; } if (networkEventType == NetworkEventType.Nothing) { goto IL_2C6; } } Block_10: this.GenerateConnectError((int)b); return; Block_11: this.GenerateDataError((int)b); return; Block_17: if (LogFilter.logDebug) { Debug.Log("MaxEventsPerFrame hit (" + 500 + ")"); } Block_19: IL_2C6: if (this.m_Connection != null && this.m_AsyncConnect == NetworkClient.ConnectState.Connected) { this.m_Connection.FlushChannels(); } } } // Token: 0x06000189 RID: 393 RVA: 0x000062FD File Offset: 0x000044FD private void GenerateConnectError(int error) { if (LogFilter.logError) { Debug.LogError("UNet Client Error Connect Error: " + error); } this.GenerateError(error); } // Token: 0x0600018A RID: 394 RVA: 0x00006328 File Offset: 0x00004528 private void GenerateDataError(int error) { if (LogFilter.logError) { Debug.LogError("UNet Client Data Error: " + (NetworkError)error); } this.GenerateError(error); } // Token: 0x0600018B RID: 395 RVA: 0x00006360 File Offset: 0x00004560 private void GenerateDisconnectError(int error) { if (LogFilter.logError) { Debug.LogError("UNet Client Disconnect Error: " + (NetworkError)error); } this.GenerateError(error); } // Token: 0x0600018C RID: 396 RVA: 0x00006398 File Offset: 0x00004598 private void GenerateError(int error) { NetworkMessageDelegate networkMessageDelegate = this.m_MessageHandlers.GetHandler(34); if (networkMessageDelegate == null) { networkMessageDelegate = this.m_MessageHandlers.GetHandler(34); } if (networkMessageDelegate != null) { ErrorMessage errorMessage = new ErrorMessage(); errorMessage.errorCode = error; byte[] array = new byte[200]; NetworkWriter networkWriter = new NetworkWriter(array); errorMessage.Serialize(networkWriter); NetworkReader networkReader = new NetworkReader(array); networkMessageDelegate(new NetworkMessage { msgType = 34, reader = networkReader, conn = this.m_Connection, channelId = 0 }); } } // Token: 0x0600018D RID: 397 RVA: 0x00006436 File Offset: 0x00004636 public void GetStatsOut(out int numMsgs, out int numBufferedMsgs, out int numBytes, out int lastBufferedPerSecond) { numMsgs = 0; numBufferedMsgs = 0; numBytes = 0; lastBufferedPerSecond = 0; if (this.m_Connection != null) { this.m_Connection.GetStatsOut(out numMsgs, out numBufferedMsgs, out numBytes, out lastBufferedPerSecond); } } // Token: 0x0600018E RID: 398 RVA: 0x00006463 File Offset: 0x00004663 public void GetStatsIn(out int numMsgs, out int numBytes) { numMsgs = 0; numBytes = 0; if (this.m_Connection != null) { this.m_Connection.GetStatsIn(out numMsgs, out numBytes); } } // Token: 0x0600018F RID: 399 RVA: 0x00006488 File Offset: 0x00004688 public Dictionary GetConnectionStats() { Dictionary dictionary; if (this.m_Connection == null) { dictionary = null; } else { dictionary = this.m_Connection.packetStats; } return dictionary; } // Token: 0x06000190 RID: 400 RVA: 0x000064BA File Offset: 0x000046BA public void ResetConnectionStats() { if (this.m_Connection != null) { this.m_Connection.ResetStats(); } } // Token: 0x06000191 RID: 401 RVA: 0x000064D8 File Offset: 0x000046D8 public int GetRTT() { int num; if (this.m_ClientId == -1) { num = 0; } else { byte b; num = NetworkTransport.GetCurrentRTT(this.m_ClientId, this.m_ClientConnectionId, out b); } return num; } // Token: 0x06000192 RID: 402 RVA: 0x00006514 File Offset: 0x00004714 internal void RegisterSystemHandlers(bool localClient) { ClientScene.RegisterSystemHandlers(this, localClient); this.RegisterHandlerSafe(14, new NetworkMessageDelegate(this.OnCRC)); this.RegisterHandlerSafe(17, new NetworkMessageDelegate(NetworkConnection.OnFragment)); } // Token: 0x06000193 RID: 403 RVA: 0x00006562 File Offset: 0x00004762 private void OnCRC(NetworkMessage netMsg) { netMsg.ReadMessage(NetworkClient.s_CRCMessage); NetworkCRC.Validate(NetworkClient.s_CRCMessage.scripts, this.numChannels); } // Token: 0x06000194 RID: 404 RVA: 0x00006586 File Offset: 0x00004786 public void RegisterHandler(short msgType, NetworkMessageDelegate handler) { this.m_MessageHandlers.RegisterHandler(msgType, handler); } // Token: 0x06000195 RID: 405 RVA: 0x00006596 File Offset: 0x00004796 public void RegisterHandlerSafe(short msgType, NetworkMessageDelegate handler) { this.m_MessageHandlers.RegisterHandlerSafe(msgType, handler); } // Token: 0x06000196 RID: 406 RVA: 0x000065A6 File Offset: 0x000047A6 public void UnregisterHandler(short msgType) { this.m_MessageHandlers.UnregisterHandler(msgType); } // Token: 0x06000197 RID: 407 RVA: 0x000065B8 File Offset: 0x000047B8 public static Dictionary GetTotalConnectionStats() { Dictionary dictionary = new Dictionary(); for (int i = 0; i < NetworkClient.s_Clients.Count; i++) { NetworkClient networkClient = NetworkClient.s_Clients[i]; Dictionary connectionStats = networkClient.GetConnectionStats(); foreach (short num in connectionStats.Keys) { if (dictionary.ContainsKey(num)) { NetworkConnection.PacketStat packetStat = dictionary[num]; packetStat.count += connectionStats[num].count; packetStat.bytes += connectionStats[num].bytes; dictionary[num] = packetStat; } else { dictionary[num] = new NetworkConnection.PacketStat(connectionStats[num]); } } } return dictionary; } // Token: 0x06000198 RID: 408 RVA: 0x000066C8 File Offset: 0x000048C8 internal static void AddClient(NetworkClient client) { NetworkClient.s_Clients.Add(client); } // Token: 0x06000199 RID: 409 RVA: 0x000066D8 File Offset: 0x000048D8 internal static bool RemoveClient(NetworkClient client) { return NetworkClient.s_Clients.Remove(client); } // Token: 0x0600019A RID: 410 RVA: 0x000066F8 File Offset: 0x000048F8 internal static void UpdateClients() { for (int i = 0; i < NetworkClient.s_Clients.Count; i++) { if (NetworkClient.s_Clients[i] != null) { NetworkClient.s_Clients[i].Update(); } else { NetworkClient.s_Clients.RemoveAt(i); } } } // Token: 0x0600019B RID: 411 RVA: 0x00006753 File Offset: 0x00004953 public static void ShutdownAll() { while (NetworkClient.s_Clients.Count != 0) { NetworkClient.s_Clients[0].Shutdown(); } NetworkClient.s_Clients = new List(); NetworkClient.s_IsActive = false; ClientScene.Shutdown(); } // Token: 0x0600019C RID: 412 RVA: 0x00006791 File Offset: 0x00004991 internal static void SetActive(bool state) { if (!NetworkClient.s_IsActive && state) { NetworkTransport.Init(); } NetworkClient.s_IsActive = state; } // Token: 0x040000CF RID: 207 private Type m_NetworkConnectionClass = typeof(NetworkConnection); // Token: 0x040000D0 RID: 208 private const int k_MaxEventsPerFrame = 500; // Token: 0x040000D1 RID: 209 private static List s_Clients = new List(); // Token: 0x040000D2 RID: 210 private static bool s_IsActive; // Token: 0x040000D3 RID: 211 private HostTopology m_HostTopology; // Token: 0x040000D4 RID: 212 private int m_HostPort; // Token: 0x040000D5 RID: 213 private bool m_UseSimulator; // Token: 0x040000D6 RID: 214 private int m_SimulatedLatency; // Token: 0x040000D7 RID: 215 private float m_PacketLoss; // Token: 0x040000D8 RID: 216 private string m_ServerIp = ""; // Token: 0x040000D9 RID: 217 private int m_ServerPort; // Token: 0x040000DA RID: 218 private int m_ClientId = -1; // Token: 0x040000DB RID: 219 private int m_ClientConnectionId = -1; // Token: 0x040000DC RID: 220 private int m_StatResetTime; // Token: 0x040000DD RID: 221 private EndPoint m_RemoteEndPoint; // Token: 0x040000DE RID: 222 private static CRCMessage s_CRCMessage = new CRCMessage(); // Token: 0x040000DF RID: 223 private NetworkMessageHandlers m_MessageHandlers = new NetworkMessageHandlers(); // Token: 0x040000E0 RID: 224 protected NetworkConnection m_Connection; // Token: 0x040000E1 RID: 225 private byte[] m_MsgBuffer; // Token: 0x040000E2 RID: 226 private NetworkReader m_MsgReader; // Token: 0x040000E3 RID: 227 protected NetworkClient.ConnectState m_AsyncConnect = NetworkClient.ConnectState.None; // Token: 0x040000E4 RID: 228 private string m_RequestedServerHost = ""; // Token: 0x0200003E RID: 62 protected enum ConnectState { // Token: 0x040000E8 RID: 232 None, // Token: 0x040000E9 RID: 233 Resolving, // Token: 0x040000EA RID: 234 Resolved, // Token: 0x040000EB RID: 235 Connecting, // Token: 0x040000EC RID: 236 Connected, // Token: 0x040000ED RID: 237 Disconnected, // Token: 0x040000EE RID: 238 Failed } } }