internal void ContinueConnect() { byte error; // regular non-relay connect if (m_UseSimulator) { int simLatency = m_SimulatedLatency / 3; if (simLatency < 1) { simLatency = 1; } if (LogFilter.logDebug) { Debug.Log("Connect Using Simulator " + (m_SimulatedLatency / 3) + "/" + m_SimulatedLatency); } var simConfig = new ConnectionSimulatorConfig( simLatency, m_SimulatedLatency, simLatency, m_SimulatedLatency, m_PacketLoss); m_ClientConnectionId = NetworkTransport.ConnectWithSimulator(m_ClientId, m_ServerIp, m_ServerPort, 0, out error, simConfig); } else { m_ClientConnectionId = NetworkTransport.Connect(m_ClientId, m_ServerIp, m_ServerPort, 0, out error); } m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass); m_Connection.SetHandlers(m_MessageHandlers); m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId, m_HostTopology); }
void ConnectWithRelay(MatchInfo info) { m_AsyncConnect = ConnectState.Connecting; Update(); byte error; m_ClientConnectionId = NetworkTransport.ConnectToNetworkPeer( m_ClientId, info.address, info.port, 0, 0, info.networkId, Utility.GetSourceID(), info.nodeId, out error); m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass); m_Connection.SetHandlers(m_MessageHandlers); m_Connection.Initialize(info.address, m_ClientId, m_ClientConnectionId, m_HostTopology); if (error != 0) { Debug.LogError("ConnectToNetworkPeer Error: " + error); } }
void HandleConnect(int connectionId, byte error) { if (LogFilter.logDebug) { Debug.Log("NetworkServerSimple accepted client:" + connectionId); } if (error != 0) { OnConnectError(connectionId, error); return; } string address; int port; NetworkID networkId; NodeID node; byte error2; NetworkTransport.GetConnectionInfo(m_ServerHostId, connectionId, out address, out port, out networkId, out node, out error2); NetworkConnection conn = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass); conn.SetHandlers(m_MessageHandlers); conn.Initialize(address, m_ServerHostId, connectionId, m_HostTopology); // add connection at correct index while (m_Connections.Count <= connectionId) { m_Connections.Add(null); } m_Connections[connectionId] = conn; OnConnected(conn); }
private void HandleConnect(int connectionId, byte error) { if (LogFilter.logDebug) { Debug.Log("NetworkServerSimple accepted client:" + connectionId); } if (error != 0) { this.OnConnectError(connectionId, error); } else { string str; int num; NetworkID kid; NodeID eid; byte num2; NetworkTransport.GetConnectionInfo(this.m_ServerHostId, connectionId, out str, out num, out kid, out eid, out num2); NetworkConnection conn = (NetworkConnection)Activator.CreateInstance(this.m_NetworkConnectionClass); conn.SetHandlers(this.m_MessageHandlers); conn.Initialize(str, this.m_ServerHostId, connectionId, this.m_HostTopology); conn.lastError = (NetworkError)num2; while (this.m_Connections.Count <= connectionId) { this.m_Connections.Add(null); } this.m_Connections[connectionId] = conn; this.OnConnected(conn); } }
private void HandleConnect(int connectionId, byte error) { if (LogFilter.logDebug) { Debug.Log((object)("NetworkServerSimple accepted client:" + (object)connectionId)); } if ((int)error != 0) { this.OnConnectError(connectionId, error); } else { string address; int port; NetworkID network; NodeID dstNode; byte error1; NetworkTransport.GetConnectionInfo(this.m_ServerHostId, connectionId, out address, out port, out network, out dstNode, out error1); NetworkConnection instance = (NetworkConnection)Activator.CreateInstance(this.m_NetworkConnectionClass); instance.SetHandlers(this.m_MessageHandlers); instance.Initialize(address, this.m_ServerHostId, connectionId, this.m_HostTopology); while (this.m_Connections.Count <= connectionId) { this.m_Connections.Add((NetworkConnection)null); } this.m_Connections[connectionId] = instance; this.OnConnected(instance); } }
private void HandleConnect(int connectionId, byte error) { if (LogFilter.logDebug) { Debug.Log("NetworkServerSimple accepted client:" + connectionId); } if (error != 0) { this.OnConnectError(connectionId, error); } else { string networkAddress; int num; NetworkID networkID; NodeID nodeID; byte lastError; NetworkTransport.GetConnectionInfo(this.m_ServerHostId, connectionId, out networkAddress, out num, out networkID, out nodeID, out lastError); NetworkConnection networkConnection = (NetworkConnection)Activator.CreateInstance(this.m_NetworkConnectionClass); networkConnection.SetHandlers(this.m_MessageHandlers); networkConnection.Initialize(networkAddress, this.m_ServerHostId, connectionId, this.m_HostTopology); networkConnection.lastError = (NetworkError)lastError; while (this.m_Connections.Count <= connectionId) { this.m_Connections.Add(null); } this.m_Connections[connectionId] = networkConnection; this.OnConnected(networkConnection); } }
internal void ContinueConnect() { byte error; if (m_UseSimulator) { int num = m_SimulatedLatency / 3; if (num < 1) { num = 1; } if (LogFilter.logDebug) { Debug.Log("Connect Using Simulator " + m_SimulatedLatency / 3 + "/" + m_SimulatedLatency); } ConnectionSimulatorConfig conf = new ConnectionSimulatorConfig(num, m_SimulatedLatency, num, m_SimulatedLatency, m_PacketLoss); m_ClientConnectionId = NetworkTransport.ConnectWithSimulator(m_ClientId, m_ServerIp, m_ServerPort, 0, out error, conf); } else { m_ClientConnectionId = NetworkTransport.Connect(m_ClientId, m_ServerIp, m_ServerPort, 0, out error); } m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass); m_Connection.SetHandlers(m_MessageHandlers); m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId, m_HostTopology); }
internal void ContinueConnect() { byte error; // regular non-relay connect m_ClientConnectionId = NetworkTransport.Connect(m_ClientId, m_ServerIp, m_ServerPort, 0, out error); m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass); m_Connection.SetHandlers(m_MessageHandlers); m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId, m_HostTopology); }
public bool SetConnectionAtIndex(NetworkConnection conn) { while (m_Connections.Count <= conn.connectionId) { m_Connections.Add(null); } if (m_Connections[conn.connectionId] != null) { return(false); } m_Connections[conn.connectionId] = conn; conn.SetHandlers(m_MessageHandlers); return(true); }
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); }
public NetworkClient(NetworkConnection conn) { if (LogFilter.logDev) { Debug.Log("Client created version " + Version.Current); } m_MsgBuffer = new byte[65535]; m_MsgReader = new NetworkReader(m_MsgBuffer); AddClient(this); SetActive(state: true); m_Connection = conn; m_AsyncConnect = ConnectState.Connected; conn.SetHandlers(m_MessageHandlers); RegisterSystemHandlers(localClient: false); }
public NetworkClient(NetworkConnection conn) { if (LogFilter.logDev) { Debug.Log("Client created version " + Version.Current); } m_MsgBuffer = new byte[NetworkMessage.MaxMessageSize]; AddClient(this); SetActive(true); m_Connection = conn; m_AsyncConnect = ConnectState.Connected; conn.SetHandlers(m_MessageHandlers); RegisterSystemHandlers(false); }
public bool SetConnectionAtIndex(NetworkConnection conn) { while (this.m_Connections.Count <= conn.connectionId) { this.m_Connections.Add(null); } bool result; if (this.m_Connections[conn.connectionId] != null) { result = false; } else { this.m_Connections[conn.connectionId] = conn; conn.SetHandlers(this.m_MessageHandlers); result = true; } return(result); }
public NetworkClient(NetworkConnection conn) { this.m_NetworkConnectionClass = typeof(NetworkConnection); this.m_ServerIp = ""; this.m_ClientId = -1; this.m_ClientConnectionId = -1; this.m_MessageHandlers = new NetworkMessageHandlers(); this.m_AsyncConnect = ConnectState.None; this.m_RequestedServerHost = ""; if (LogFilter.logDev) { Debug.Log("Client created version " + UnityEngine.Networking.Version.Current); } this.m_MsgBuffer = new byte[0xffff]; this.m_MsgReader = new NetworkReader(this.m_MsgBuffer); AddClient(this); SetActive(true); this.m_Connection = conn; this.m_AsyncConnect = ConnectState.Connected; conn.SetHandlers(this.m_MessageHandlers); this.RegisterSystemHandlers(false); }
private void HandleConnect(int connectionId, byte error) { if (LogFilter.logDebug) { Debug.Log("NetworkServerSimple accepted client:" + connectionId); } if (error != 0) { OnConnectError(connectionId, error); return; } NetworkTransport.GetConnectionInfo(m_ServerHostId, connectionId, out string address, out int _, out NetworkID _, out NodeID _, out byte error2); NetworkConnection networkConnection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass); networkConnection.SetHandlers(m_MessageHandlers); networkConnection.Initialize(address, m_ServerHostId, connectionId, m_HostTopology); networkConnection.lastError = (NetworkError)error2; while (m_Connections.Count <= connectionId) { m_Connections.Add(null); } m_Connections[connectionId] = networkConnection; OnConnected(networkConnection); }
public void Connect(EndPoint secureTunnelEndPoint) { bool usePlatformSpecificProtocols = NetworkTransport.DoesEndPointUsePlatformProtocols(secureTunnelEndPoint); PrepareForConnect(usePlatformSpecificProtocols); if (LogFilter.logDebug) { Debug.Log("Client Connect to remoteSockAddr"); } if (secureTunnelEndPoint == null) { if (LogFilter.logError) { Debug.LogError("Connect failed: null endpoint passed in"); } m_AsyncConnect = ConnectState.Failed; return; } // Make sure it's either IPv4 or IPv6 if (secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetwork && secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetworkV6) { if (LogFilter.logError) { Debug.LogError("Connect failed: Endpoint AddressFamily must be either InterNetwork or InterNetworkV6"); } m_AsyncConnect = ConnectState.Failed; return; } // Make sure it's an Endpoint we know what to do with string endPointType = secureTunnelEndPoint.GetType().FullName; if (endPointType == "System.Net.IPEndPoint") { IPEndPoint tmp = (IPEndPoint)secureTunnelEndPoint; Connect(tmp.Address.ToString(), tmp.Port); return; } if ((endPointType != "UnityEngine.XboxOne.XboxOneEndPoint") && (endPointType != "UnityEngine.PS4.SceEndPoint")) { if (LogFilter.logError) { Debug.LogError("Connect failed: invalid Endpoint (not IPEndPoint or XboxOneEndPoint or SceEndPoint)"); } m_AsyncConnect = ConnectState.Failed; return; } byte error = 0; // regular non-relay connect m_RemoteEndPoint = secureTunnelEndPoint; m_AsyncConnect = ConnectState.Connecting; try { m_ClientConnectionId = NetworkTransport.ConnectEndPoint(m_ClientId, m_RemoteEndPoint, 0, out error); } catch (Exception ex) { if (LogFilter.logError) { Debug.LogError("Connect failed: Exception when trying to connect to EndPoint: " + ex); } m_AsyncConnect = ConnectState.Failed; return; } if (m_ClientConnectionId == 0) { if (LogFilter.logError) { Debug.LogError("Connect failed: Unable to connect to EndPoint (" + error + ")"); } m_AsyncConnect = ConnectState.Failed; return; } m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass); m_Connection.SetHandlers(m_MessageHandlers); m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId, m_HostTopology); }
public void Connect(EndPoint secureTunnelEndPoint) { PrepareForConnect(); if (LogFilter.logDebug) { Debug.Log("Client Connect to remoteSockAddr"); } if (secureTunnelEndPoint == null) { if (LogFilter.logError) { Debug.LogError("Connect failed: null endpoint passed in"); } m_AsyncConnect = ConnectState.Failed; return; } if (secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetwork && secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetworkV6) { if (LogFilter.logError) { Debug.LogError("Connect failed: Endpoint AddressFamily must be either InterNetwork or InterNetworkV6"); } m_AsyncConnect = ConnectState.Failed; return; } string fullName = secureTunnelEndPoint.GetType().FullName; if (fullName == "System.Net.IPEndPoint") { IPEndPoint iPEndPoint = (IPEndPoint)secureTunnelEndPoint; Connect(iPEndPoint.Address.ToString(), iPEndPoint.Port); return; } if (fullName != "UnityEngine.XboxOne.XboxOneEndPoint") { if (LogFilter.logError) { Debug.LogError("Connect failed: invalid Endpoint (not IPEndPoint or XboxOneEndPoint)"); } m_AsyncConnect = ConnectState.Failed; return; } byte error = 0; m_RemoteEndPoint = secureTunnelEndPoint; m_AsyncConnect = ConnectState.Connecting; try { m_ClientConnectionId = NetworkTransport.ConnectEndPoint(m_ClientId, m_RemoteEndPoint, 0, out error); } catch (Exception arg) { Debug.LogError("Connect failed: Exception when trying to connect to EndPoint: " + arg); } if (m_ClientConnectionId == 0 && LogFilter.logError) { Debug.LogError("Connect failed: Unable to connect to EndPoint (" + error + ")"); } m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass); m_Connection.SetHandlers(m_MessageHandlers); m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId, m_HostTopology); }
internal void SetHandlers(NetworkConnection conn) { conn.SetHandlers(m_MessageHandlers); }
public bool ReconnectToNewHost(EndPoint secureTunnelEndPoint) { if (!NetworkClient.active) { if (LogFilter.logError) { Debug.LogError("Reconnect - NetworkClient must be active"); } return(false); } if (m_Connection == null) { if (LogFilter.logError) { Debug.LogError("Reconnect - no old connection exists"); } return(false); } if (LogFilter.logInfo) { Debug.Log("NetworkClient Reconnect to remoteSockAddr"); } ClientScene.HandleClientDisconnect(m_Connection); ClientScene.ClearLocalPlayers(); m_Connection.Disconnect(); m_Connection = null; m_ClientId = NetworkTransport.AddHost(m_HostTopology, 0); if (secureTunnelEndPoint == null) { if (LogFilter.logError) { Debug.LogError("Reconnect failed: null endpoint passed in"); } m_AsyncConnect = ConnectState.Failed; return(false); } // Make sure it's either IPv4 or IPv6 if (secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetwork && secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetworkV6) { if (LogFilter.logError) { Debug.LogError("Reconnect failed: Endpoint AddressFamily must be either InterNetwork or InterNetworkV6"); } m_AsyncConnect = ConnectState.Failed; return(false); } // Make sure it's an Endpoint we know what to do with string endPointType = secureTunnelEndPoint.GetType().FullName; if (endPointType == "System.Net.IPEndPoint") { IPEndPoint tmp = (IPEndPoint)secureTunnelEndPoint; Connect(tmp.Address.ToString(), tmp.Port); return(m_AsyncConnect != ConnectState.Failed); } if ((endPointType != "UnityEngine.XboxOne.XboxOneEndPoint") && (endPointType != "UnityEngine.PS4.SceEndPoint")) { if (LogFilter.logError) { Debug.LogError("Reconnect failed: invalid Endpoint (not IPEndPoint or XboxOneEndPoint or SceEndPoint)"); } m_AsyncConnect = ConnectState.Failed; return(false); } byte error = 0; // regular non-relay connect m_RemoteEndPoint = secureTunnelEndPoint; m_AsyncConnect = ConnectState.Connecting; try { m_ClientConnectionId = NetworkTransport.ConnectEndPoint(m_ClientId, m_RemoteEndPoint, 0, out error); } catch (Exception ex) { if (LogFilter.logError) { Debug.LogError("Reconnect failed: Exception when trying to connect to EndPoint: " + ex); } m_AsyncConnect = ConnectState.Failed; return(false); } if (m_ClientConnectionId == 0) { if (LogFilter.logError) { Debug.LogError("Reconnect failed: Unable to connect to EndPoint (" + error + ")"); } m_AsyncConnect = ConnectState.Failed; return(false); } m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass); m_Connection.SetHandlers(m_MessageHandlers); m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId, m_HostTopology); return(true); }