Initialize() public method

This inializes the internal data structures of a NetworkConnection object, including channel buffers.

public Initialize ( string networkAddress, int networkHostId, int networkConnectionId, HostTopology hostTopology ) : void
networkAddress string The host or IP connected to.
networkHostId int The transport hostId for the connection.
networkConnectionId int The transport connectionId for the connection.
hostTopology HostTopology The topology to be used.
return void
Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 6
0
 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    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);
     }
 }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
 internal void InternalUpdate()
 {
     if (this.m_ServerId == -1 || !NetworkTransport.IsStarted)
     return;
       int num = 0;
       byte error1;
       if (this.m_RelaySlotId != -1)
       {
     NetworkEventType networkEventType = NetworkTransport.ReceiveRelayEventFromHost(this.m_ServerId, out error1);
     if (networkEventType != NetworkEventType.Nothing && LogFilter.logDebug)
       Debug.Log((object) ("NetGroup event:" + (object) networkEventType));
     if (networkEventType == NetworkEventType.ConnectEvent && LogFilter.logDebug)
       Debug.Log((object) "NetGroup server connected");
     if (networkEventType == NetworkEventType.DisconnectEvent && LogFilter.logDebug)
       Debug.Log((object) "NetGroup server disconnected");
       }
       NetworkEventType networkEventType1;
       do
       {
     int connectionId;
     int channelId;
     int receivedSize;
     networkEventType1 = NetworkTransport.ReceiveFromHost(this.m_ServerId, out connectionId, out channelId, this.m_MsgBuffer, (int) (ushort) this.m_MsgBuffer.Length, out receivedSize, out error1);
     if (networkEventType1 != NetworkEventType.Nothing && LogFilter.logDev)
     {
       object[] objArray = new object[6];
       int index1 = 0;
       string str1 = "Server event: host=";
       objArray[index1] = (object) str1;
       int index2 = 1;
       // ISSUE: variable of a boxed type
       __Boxed<int> local1 = (ValueType) this.m_ServerId;
       objArray[index2] = (object) local1;
       int index3 = 2;
       string str2 = " event=";
       objArray[index3] = (object) str2;
       int index4 = 3;
       // ISSUE: variable of a boxed type
       __Boxed<NetworkEventType> local2 = (Enum) networkEventType1;
       objArray[index4] = (object) local2;
       int index5 = 4;
       string str3 = " error=";
       objArray[index5] = (object) str3;
       int index6 = 5;
       // ISSUE: variable of a boxed type
       __Boxed<byte> local3 = (ValueType) error1;
       objArray[index6] = (object) local3;
       Debug.Log((object) string.Concat(objArray));
     }
     switch (networkEventType1)
     {
       case NetworkEventType.DataEvent:
     NetworkConnection conn = this.m_Connections.Get(connectionId);
     if ((int) error1 != 0)
     {
       this.GenerateDataError(conn, (int) error1);
       return;
     }
     NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Incoming, (short) 29, "msg", 1);
     if (conn != null)
     {
       this.m_MsgReader.SeekZero();
       conn.HandleMessage(this.m_MessageHandlers.GetHandlers(), this.m_MsgReader, receivedSize, channelId);
       goto case 3;
     }
     else if (LogFilter.logError)
     {
       Debug.LogError((object) "Unknown connection data event?!?");
       goto case 3;
     }
     else
       goto case 3;
       case NetworkEventType.ConnectEvent:
     if (LogFilter.logDebug)
       Debug.Log((object) ("Server accepted client:" + (object) connectionId));
     if ((int) error1 != 0)
     {
       this.GenerateConnectError((int) error1);
       return;
     }
     string address;
     int port;
     NetworkID network;
     NodeID dstNode;
     byte error2;
     NetworkTransport.GetConnectionInfo(this.m_ServerId, connectionId, out address, out port, out network, out dstNode, out error2);
     NetworkConnection networkConnection = new NetworkConnection();
     networkConnection.Initialize(address, this.m_ServerId, connectionId, this.m_hostTopology);
     networkConnection.SetMaxDelay(this.m_MaxDelay);
     this.m_Connections.Add(connectionId, networkConnection);
     this.m_MessageHandlers.InvokeHandlerNoData((short) 32, networkConnection);
     if (this.m_SendPeerInfo)
       this.SendNetworkInfo(networkConnection);
     this.SendCRC(networkConnection);
     goto case 3;
       case NetworkEventType.DisconnectEvent:
     NetworkConnection @unsafe = this.m_Connections.GetUnsafe(connectionId);
     if ((int) error1 != 0 && (int) error1 != 6)
       this.GenerateDisconnectError(@unsafe, (int) error1);
     this.m_Connections.Remove(connectionId);
     if (@unsafe != null)
     {
       this.m_MessageHandlers.InvokeHandlerNoData((short) 33, @unsafe);
       for (int index = 0; index < @unsafe.playerControllers.Count; ++index)
       {
         if ((UnityEngine.Object) @unsafe.playerControllers[index].gameObject != (UnityEngine.Object) null && LogFilter.logWarn)
           Debug.LogWarning((object) "Player not destroyed when connection disconnected.");
       }
       if (LogFilter.logDebug)
         Debug.Log((object) ("Server lost client:" + (object) connectionId));
       @unsafe.RemoveObservers();
       @unsafe.Dispose();
     }
     else if (LogFilter.logDebug)
       Debug.Log((object) "Connection is null in disconnect event");
     if (this.m_SendPeerInfo)
     {
       this.SendNetworkInfo(@unsafe);
       goto case 3;
     }
     else
       goto case 3;
       case NetworkEventType.Nothing:
     if (++num >= 500)
     {
       if (LogFilter.logDebug)
       {
         Debug.Log((object) ("kMaxEventsPerFrame hit (" + (object) 500 + ")"));
         goto label_47;
       }
       else
         goto label_47;
     }
     else
       continue;
       default:
     if (LogFilter.logError)
     {
       Debug.LogError((object) ("Unknown network message type received: " + (object) networkEventType1));
       goto case 3;
     }
     else
       goto case 3;
     }
       }
       while (networkEventType1 != NetworkEventType.Nothing);
     label_47:
       this.UpdateServerObjects();
       for (int localIndex = this.m_Connections.LocalIndex; localIndex < this.m_Connections.Count; ++localIndex)
       {
     NetworkConnection networkConnection = this.m_Connections.Get(localIndex);
     if (networkConnection != null)
       networkConnection.FlushInternalBuffer();
       }
 }