/// <summary>
        /// Create new peer.
        /// </summary>
        /// <typeparam name="T">class.</typeparam>
        /// <param name="config">Peer configuration.</param>
        /// <returns>T peer class.</returns>
        public T CreatePeer <T>(IPeerConfig config) where T : class
        {
            var initRequest     = config.GetConfig <InitRequest>();
            var applicationBase = config.GetConfig <PhotonApplication>();

            if (initRequest != null)
            {
                Log.DebugFormat("Connection request on port {0}", initRequest.LocalPort);

                if (initRequest.LocalPort == ParentPort)
                {
                    var inboundPeer = new InboundPhotonPeer(initRequest);
                    inboundPeer.ServerPeer = ServerPeerFactory(inboundPeer, false);
                    return(inboundPeer as T);
                }
                else if (initRequest.LocalPort == SiblingPort)
                {
                    var inboundPeer = new InboundPhotonPeer(initRequest);
                    inboundPeer.ServerPeer = ServerPeerFactory(inboundPeer, true);
                    return(inboundPeer as T);
                }

                if (AllowPhysicalClients)
                {
                    return(ClientPeerFactory(initRequest) as T);
                }

                return(null);
            }
            else
            {
                return(SubServerClientPeerFactory() as T);
            }
        }
        public T CreatePeer <T>(IPeerConfig config) where T : class
        {
            // Client and server incomming
            var initRequest = config.GetConfig <InitRequest>();
            // When we get a response, we get the photon application it came in on.
            var applicationBase = config.GetConfig <PhotonApplication>();

            if (initRequest != null)
            {
                Log.DebugFormat("Connection request on port {0}", initRequest.LocalPort);
                if (initRequest.LocalPort == ParentPort)
                {
                    // If not sibling
                    var inboundPeer = new InboundPhotonPeer(initRequest);
                    inboundPeer.ServerPeer = ServerPeerFactory(inboundPeer, false);
                    return(inboundPeer as T);
                }
                else if (initRequest.LocalPort == SiblingPort)
                {
                    // if sibling
                    var inboundPeer = new InboundPhotonPeer(initRequest);
                    inboundPeer.ServerPeer = ServerPeerFactory(inboundPeer, true);
                    return(inboundPeer as T);
                }
                if (AllowPhysicalClients)
                {
                    return(ClientPeerFactory(initRequest) as T);
                }
                return(null);
            }
            else
            {
                return(SubServerClientPeerFactory() as T);
            }
        }
Exemplo n.º 3
0
        public T CreatePeer <T>(IPeerConfig config) where T : class
        {
            // Client and server incomming
            var initRequest = config.GetConfig <InitRequest>();
            // we requested a connection to another server
            var initResposne = config.GetConfig <InitResponse>();

            if (initRequest != null)
            {
                Log.DebugFormat("Connection request on port {0}", initRequest.LocalPort);
                if (initRequest.LocalPort == ParentPort)
                {
                    // if not a sibling
                    return(ServerPeerFactory(initRequest.Protocol, initRequest.PhotonPeer, false) as T);
                }
                else if (initRequest.LocalPort == SiblingPort)
                {
                    // if sibling
                    return(ServerPeerFactory(initRequest.Protocol, initRequest.PhotonPeer, true) as T);
                }

                if (AllowPhysicalClients)
                {
                    return(ClientPeerFactory(initRequest.Protocol, initRequest.PhotonPeer) as T);
                }

                return(null);
            }
            else if (initResposne != null)
            {
                var peerInfo = config.GetConfig <PeerInfo>();
                if (peerInfo != null)
                {
                    var serverPeer = ServerPeerFactory(initResposne.Protocol, initResposne.PhotonPeer,
                                                       peerInfo.IsSiblingConnection);

                    serverPeer.Register();

                    return(serverPeer as T);
                }

                return(null);
            }
            else
            {
                return(SubServerClientPeerFactory() as T);
            }
        }