Esempio n. 1
0
        protected override void Load(ContainerBuilder builder)
        {
            //We need to create and manually resolve the dependencies for the AuthService since it uses a different GladNet2 implementation as the other
            //session objects
            builder.Register(con =>
            {
                IConnectionDetails details = new GladNet.PhotonServer.Server.PhotonServerIConnectionDetailsAdapter(IPAddress.Any.ToString(), 5, 5);                 //this is a hack. We need an AUID

                //Publisher: INetworkReciever, SubService and etc.
                NetworkMessagePublisher publisher = new NetworkMessagePublisher();

                //TODO: Change this to a task-based/async multithreaded strategy when it's implemented
                //This is the message sending service for web clients
                //It doesn't usually need a publisher but right now we use a singlethreaded blocking implementation

                //TODO: Make it so that we don't need to resolve the routeback service.
                WebPeerClientMessageSender webMessageSender = new WebPeerClientMessageSender(new RestSharpCurrentThreadEnqueueRequestHandlerStrategy(OutboundConnectionSettings.Default.AuthServiceIP, con.Resolve <IDeserializerStrategy>(), publisher, details.ConnectionID, con.Resolve <INetworkMessageRouteBackService>()));

                //Because this differs in GladNet implementation we must resolve some of these depencencies manually
                AuthServiceClientPeer peer = new AuthServiceClientPeer(con.Resolve <ILog>(), webMessageSender, new WebClientPeerDetails(OutboundConnectionSettings.Default.AuthServiceIP, -1, details.ConnectionID), publisher, con.Resolve <IDisconnectionServiceHandler>(), con.Resolve <INetworkMessageRouteBackService>(), con.Resolve <IResponseMessageHandlerService <AuthServiceClientPeer> >());

                //TODO: Use ping the webserver so we can give a real status
                //Because this is web service we don't really connect to it like the other RUDP connections so we should spoof the NetStatus
                publisher.OnNetworkMessageReceive(new GladNet.PhotonServer.Common.PhotonStatusMessageAdapter(NetStatus.Connected), null);

                return(peer);
            })
            .AsSelf()
            .SingleInstance();
        }
Esempio n. 2
0
        protected GladNetOutboundS2SPeer CreateOutBoundPeer()
        {
            //Services needed to have an outbound peer
            NetworkMessagePublisher      publisher            = new NetworkMessagePublisher();
            IDisconnectionServiceHandler disconnectionHandler = new PhotonServerIDisconnectionServiceHandlerAdapter();


            return(new GladNetOutboundS2SPeer(this, publisher, this.Deserializer, disconnectionHandler));
        }
Esempio n. 3
0
        /// <inheritdoc />
        public ClientPeerSession Create(IConnectionDetails connectionDetails, NetConnection connection)
        {
            if (connectionDetails == null)
            {
                throw new ArgumentNullException(nameof(connectionDetails));
            }
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            //Build the message router service
            LidgrenNetworkMessageRouterService    routerService         = new LidgrenServerNetworkMessageRouterService(new LidgrenNetworkMessageFactory(), connection, Serializer);
            NetworkMessagePublisher               basicMessagePublisher = new NetworkMessagePublisher();
            DefaultNetworkMessageRouteBackService routebackService      = new DefaultNetworkMessageRouteBackService(NetPeerAUIDService, PeerLogger);
            DefaultDisconnectionServiceHandler    disconnectionHandler  = new DefaultDisconnectionServiceHandler();

            //TODO: Clean this up
            disconnectionHandler.DisconnectionEventHandler += () => PeerServiceCollection.Remove(connectionDetails.ConnectionID);

            //Try to create the incoming peer; consumers of the library may reject the connection.
            ClientPeerSession session = ManagedSessionFactory.CreateIncomingPeerSession(routerService, connectionDetails, basicMessagePublisher, disconnectionHandler, routebackService);

            if (session == null)
            {
                return(null);
            }

            if (session.PeerDetails.ConnectionID == 0)
            {
                throw new InvalidOperationException("Generated peer has an unset connection ID.");
            }

            //Create a service context for the server.
            ClientSessionServiceContext serviceContext = new ClientSessionServiceContext(routerService, basicMessagePublisher, session);

            //Enter AUID lock
            PeerServiceCollection.syncObj.EnterWriteLock();
            try
            {
                PeerServiceCollection.Add(session.PeerDetails.ConnectionID, serviceContext);
            }
            finally
            {
                PeerServiceCollection.syncObj.ExitWriteLock();
            }

            return(session);
        }
Esempio n. 4
0
        /// <summary>
        /// Called internally by Photon when a peer is attempting to connect.
        /// Services the connection attempt.
        /// </summary>
        /// <param name="initRequest">Request details.</param>
        /// <returns></returns>
        protected override PeerBase CreatePeer(InitRequest initRequest)
        {
            //Create the details so that the consumer of this class, who extends it, can indicate if this is a request we should service
            //AKA should a peer be made
            IConnectionDetails details = new PhotonServerIConnectionDetailsAdapter(initRequest.RemoteIP, initRequest.RemotePort, initRequest.LocalPort);

            //If we should service the peer
            if (ShouldServiceIncomingPeerConnect(details))
            {
                //Unlike in PhotonServer we have the expectation that they WILL be creating a peer since they said they would
                //Because of this we'll be creating the actual PeerBase in advance.
                NetworkMessagePublisher      publisher            = new NetworkMessagePublisher();
                IDisconnectionServiceHandler disconnectionHandler = new PhotonServerIDisconnectionServiceHandlerAdapter();

                //Build the peer first since it's required for the network message sender
                GladNetClientPeer peerBase = new GladNetClientPeer(initRequest, publisher, Deserializer, disconnectionHandler);
                //We should make the ClientPeerSession now
                ClientPeerSession session = CreateClientSession(new PhotonServerINetworkMessageSenderClientAdapter(peerBase, Serializer), details, publisher, disconnectionHandler, routebackService);

                if (session == null)
                {
                    peerBase.Disconnect();
                    return(null);
                }

                //Add the ID to the AUID map service and setup removal
                auidMapService.Add(details.ConnectionID, session);
                disconnectionHandler.DisconnectionEventHandler += () => auidMapService.Remove(details.ConnectionID);

                //This must be done to keep alive the reference of the session
                //Otherwise GC will clean it up (WARNING: This will create circular reference and cause a leak if you do not null the peer out eventually)
                peerBase.GladNetPeer = session;

                return(peerBase);
            }
            else
            {
                //Disconnect the client if they're not going to have a peer serviced
                initRequest.PhotonPeer.DisconnectClient();

                return(null);
            }
        }