Exemplo n.º 1
0
    private void ConnectInternal(IP2PAddress address)
    {
        this.StartInternal();
        this.m_AmIMaster = false;
        P2PAddressUnet p2PAddressUnet = address as P2PAddressUnet;

        if (p2PAddressUnet != null)
        {
            if (p2PAddressUnet.m_IP.Equals("localhost"))
            {
                p2PAddressUnet.m_IP = "127.0.0.1";
            }
            else if (p2PAddressUnet.m_IP.IndexOf(":") != -1 && !P2PSession.IsValidIpV6(p2PAddressUnet.m_IP) && P2PLogFilter.logError)
            {
                Debug.LogError("Invalid ipv6 address " + p2PAddressUnet.m_IP);
            }
        }
        int networkConnectionId;

        if (this.m_UseSimulator)
        {
            int num = this.m_SimulatedLatency / 3;
            if (num < 1)
            {
                num = 1;
            }
            if (P2PLogFilter.logDebug)
            {
                Debug.Log(string.Concat(new object[]
                {
                    "Connect Using Simulator ",
                    this.m_SimulatedLatency / 3,
                    "/",
                    this.m_SimulatedLatency
                }));
            }
            ConnectionSimulatorConfig config = new ConnectionSimulatorConfig(num, this.m_SimulatedLatency, num, this.m_SimulatedLatency, this.m_PacketLoss);
            byte b;
            networkConnectionId = P2PTransportLayer.Instance.ConnectWithSimulator(address, out b, config);
        }
        else
        {
            byte b;
            networkConnectionId = P2PTransportLayer.Instance.Connect(address, out b);
        }
        P2PConnection p2PConnection = (P2PConnection)Activator.CreateInstance(typeof(P2PConnection));

        p2PConnection.SetHandlers(this.m_MessageHandlers);
        P2PPeer p2PPeer = null;

        for (int i = 0; i < this.m_PendingPeers.Count; i++)
        {
            if (this.m_PendingPeers[i].IsSameAddress(address))
            {
                p2PPeer = this.m_PendingPeers[i];
                this.m_PendingPeers.RemoveAt(i);
                break;
            }
        }
        if (p2PPeer == null)
        {
            p2PPeer           = new P2PPeer();
            p2PPeer.m_Address = address;
        }
        if (!this.m_RemotePeersInternal.Contains(p2PPeer))
        {
            this.m_RemotePeersInternal.Add(p2PPeer);
        }
        p2PConnection.Initialize(p2PPeer, networkConnectionId, P2PSession.s_HostTopology);
        this.SetConnectionAtIndex(p2PConnection);
        if (this.Status == P2PSession.ESessionStatus.Idle)
        {
            this.Status = P2PSession.ESessionStatus.Connecting;
        }
    }