Пример #1
0
        public override ClientPeer CreateServerPeer(INetworkMessageRouterService sender, IConnectionDetails details, INetworkMessageSubscriptionService subService, IDisconnectionServiceHandler disconnectHandler, INetworkMessageRouteBackService routeBack)
        {
            //This shouldn't be called by the ProxyLoadBalancing server
            AppLogger.ErrorFormat("Outgoing connection attempt on Proxy to IP {0} Port {1}. Proxy should not be connecting to other peers", details.RemoteIP, details.RemotePort);

            return(null);
        }
		public ClientSendServiceSelectionStrategy(INetworkMessageRouterService routerService)
		{
			if (routerService == null)
				throw new ArgumentNullException(nameof(routerService), $"Provided {nameof(INetworkMessageRouterService)} cannot be null.");

			clientMessageRouterService = routerService; 
		}
Пример #3
0
		protected ClientPeer(ILog logger, INetworkMessageRouterService messageSender, IConnectionDetails details, INetworkMessageSubscriptionService subService,
			IDisconnectionServiceHandler disconnectHandler
#if !ENDUSER
			, INetworkMessageRouteBackService routebackService)
#else
			)
#endif
				: base(logger, messageSender, details, subService, disconnectHandler)
Пример #4
0
        public ClientSendServiceSelectionStrategy(INetworkMessageRouterService routerService)
        {
            if (routerService == null)
            {
                throw new ArgumentNullException(nameof(routerService), $"Provided {nameof(INetworkMessageRouterService)} cannot be null.");
            }

            clientMessageRouterService = routerService;
        }
Пример #5
0
        public InstanceClientSession(ILog logger, INetworkMessageRouterService sender, IConnectionDetails details,
                                     INetworkMessageSubscriptionService subService, IDisconnectionServiceHandler disconnectHandler, INetworkMessageRouteBackService routebackService,
                                     IRequestMessageHandlerService <InstanceClientSession> requestMessageHandlers)
            : base(logger, sender, details, subService, disconnectHandler, routebackService)
        {
            if (requestMessageHandlers == null)
            {
                throw new ArgumentNullException(nameof(requestMessageHandlers), $"Cannot provide a null {nameof(IRequestMessageHandlerService<InstanceClientSession>)}.");
            }

            requestMessageHandlerService = requestMessageHandlers;
        }
        /// <summary>
        /// Creates a new object that represents a game server session.
        /// </summary>
        /// <param name="logger">Logging service for this session.</param>
        /// <param name="sender">Network message sending service.</param>
        /// <param name="details">Connection details for this specific incoming game server session.</param>
        /// <param name="netMessageSubService">Subscription service for incoming messages.</param>
        /// <param name="disconnectHandler">Disconnection handler for the session.</param>
        /// <param name="requestHandler">Request payload handler for the session.</param>
        public GameServicePeerSession(ILog logger, INetworkMessageRouterService sender, IConnectionDetails details, INetworkMessageSubscriptionService netMessageSubService,
                                      IDisconnectionServiceHandler disconnectHandler, INetworkMessageRouteBackService routebackService, IRequestMessageHandlerService <GameServicePeerSession> requestHandler)
            : base(logger, sender, details, netMessageSubService, disconnectHandler, routebackService)
        {
            //We check logger null because we want to log now
            Throw <ArgumentNullException> .If.IsNull(logger)?.Now(nameof(logger), $"Logging service provided must be non-null.");

            Throw <ArgumentNullException> .If.IsNull(requestHandler)?.Now(nameof(requestHandler), $"Request handling service provided must be non-null.");

            logger.Debug("Created new a new gameserver service peer session.");

            requestHandlerService = requestHandler;
        }
        protected override ClientPeerSession CreateIncomingPeerSession(INetworkMessageRouterService sender, IConnectionDetails details, INetworkMessageSubscriptionService subService, IDisconnectionServiceHandler disconnectHandler, INetworkMessageRouteBackService routebackService)
        {
            //For now we assume that any connection is valid.
            //In the future we might filter out some IPs but most validation will be post-connection from a signed message.
            ClientPeerSession session = new InstanceClientSession(Logger, sender, details, subService, disconnectHandler, routebackService, instanceSessionRequestMessageHandlerService);

            //Register the OnDisconnect UnityEvent for when the session disconnects
            disconnectHandler.DisconnectionEventHandler += () => OnSessionDisconnected?.Invoke(session);

            //This isn't great; invoking this before returning it to the server base is not great design but it's the only way right now
            OnNewSessionCreated?.Invoke(session);

            return(session);
        }
        /// <summary>
        /// Creates a new object that represents an auth service connection.
        /// </summary>
        /// <param name="logger">Logging service for this session.</param>
        /// <param name="sender">Network message sending service.</param>
        /// <param name="details">Connection details for this specific incoming game server session.</param>
        /// <param name="netMessageSubService">Subscription service for incoming messages.</param>
        /// <param name="disconnectHandler">Disconnection handler for the session.</param>
        /// <param name="responseHandler">Request payload handler for the session.</param>
        public AuthServiceClientPeer(ILog logger, INetworkMessageRouterService messageSender, IConnectionDetails details,
                                     INetworkMessageSubscriptionService subService, IDisconnectionServiceHandler disconnectHandler, INetworkMessageRouteBackService routebackService, IResponseMessageHandlerService <AuthServiceClientPeer> responseHandler)
            : base(logger, messageSender, details, subService, disconnectHandler, routebackService)
        {
            //We check logger null because we want to log now
            Throw <ArgumentNullException> .If.IsNull(logger)?.Now(nameof(logger), $"Logging service provided must be non-null.");

            Throw <ArgumentNullException> .If.IsNull(responseHandler)?.Now(nameof(responseHandler), $"Response handling service provided must be non-null.");


            //the authservice doesn't really 'connect'
            logger.Debug($"An {nameof(AuthServiceClientPeer)} was created but not connected yet.");

            //We only have a response handler; we won't be provided with an event handler (maybe in the future) because we don't want to handle any events.
            responseHandlerService = responseHandler;
        }
Пример #9
0
        protected Peer(ILog logger, INetworkMessageRouterService messageSender, IConnectionDetails details, INetworkMessageSubscriptionService subService,
			IDisconnectionServiceHandler disconnectHandler)
        {
            Throw<ArgumentNullException>.If.IsNull(logger)?.Now(nameof(logger));
            Throw<ArgumentNullException>.If.IsNull(messageSender)?.Now(nameof(messageSender));
            Throw<ArgumentNullException>.If.IsNull(details)?.Now(nameof(details));
            Throw<ArgumentNullException>.If.IsNull(subService)?.Now(nameof(subService));
            Throw<ArgumentNullException>.If.IsNull(disconnectHandler)?.Now(nameof(disconnectHandler));

            PeerDetails = details;
            NetworkSendService = messageSender;
            Logger = logger;
            disconnectionHandler = disconnectHandler;

            //All peers should care about status changes so we subscribe
            subService.SubscribeTo<StatusMessage>()
                .With(OnReceiveStatus);
        }
        public ClientSessionServiceContext(INetworkMessageRouterService sendService, INetworkMessageReceiver messageReceiver, INetPeer client)
        {
            if (sendService == null)
            {
                throw new ArgumentNullException(nameof(sendService));
            }
            if (messageReceiver == null)
            {
                throw new ArgumentNullException(nameof(messageReceiver));
            }
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            SendService     = sendService;
            MessageReceiver = messageReceiver;
            ClientNetPeer   = client;
        }
        /// <summary>
        /// Attempts to connect to the specified <paramref name="serverAddress"/> and <paramref name="appName"/>.
        /// Application Name is used to plex between multiple apps on the given address for certain implementations.
        /// </summary>
        /// <param name="serverAddress">Endpoint IP/Domain for the server.</param>
        /// <param name="appName">Application name of the server application at the endpoint.</param>
        /// <returns></returns>
        public bool Connect(string serverAddress, string appName)
        {
            //Register these so the user doesnt have to
            this.serializerRegiter.Register(typeof(NetworkMessage));
            this.serializerRegiter.Register(typeof(RequestMessage));
            this.serializerRegiter.Register(typeof(StatusMessage));
            this.serializerRegiter.Register(typeof(ResponseMessage));
            this.serializerRegiter.Register(typeof(EventMessage));

            //We need to register the payload types before we can even send
            //anything. Otherwise we can't serialize.
            RegisterPayloadTypes(this.serializerRegiter);

            //We simply create a new PhotonPeer which would generally be created by users
            //who normally use Photon but we store it and provide the GladNet API on top of it through this class.
            peer = new PhotonPeer(this, ConnectionProtocol.Udp);

            //This indicates if it's a valid connection attempt, not if we're actually connected.
            //Connection is NOT established after this line. It's no syncronous.
            bool isConnecting = peer.Connect(serverAddress, appName);

            //We can't really give accurate data. Photon doesn't expose it.
            PeerDetails        = new PhotonServerIConnectionDetailsAdapter(serverAddress.Split(':').First(), Int32.Parse(serverAddress.Split(':').Last()), -1);
            NetworkSendService = new UnityClientPeerNetworkMessageSenderAdapter <UnityClientPeer <TSerializationStrategy, TDeserializationStrategy, TSerializerRegistry> >(this);

            if (!isConnecting)
            {
                return(isConnecting);
            }

            //This is thread save because Unity coroutines occur on the same thread.
            //Also, this will prevent multiple poll routines.
            if (!isPollRunning)
            {
                //Start the polling process
                StartCoroutine(BeginPoll());
            }

            return(true);
        }
        public ClientPeerSession Create(INetworkMessageRouterService sender, IConnectionDetails details, INetworkMessageSubscriptionService subService, IDisconnectionServiceHandler disconnectHandler, INetworkMessageRouteBackService routeBack)
        {
            Logger.DebugFormat("Client trying to create session on Port: {0}", details.LocalPort);


            switch (portToSessionTypeConverter.ToSessionType(details.LocalPort))
            {
            case ProxySessionType.UserSession:
                Logger.Debug("Creating client session.");
                return(userPeerFactory(sender, details, subService, disconnectHandler, routeBack));

            //return userPeerFactory(GenerateTypedParameter(sender), GenerateTypedParameter(details), GenerateTypedParameter(subService), GenerateTypedParameter(disconnectHandler));

            case ProxySessionType.GameServiceSession:
                Logger.Debug("Creating new un-authenticated authservice session.");
                return(authPeerFactory(sender, details, subService, disconnectHandler, routeBack));

            case ProxySessionType.Default:
            default:
                Logger.ErrorFormat("An invalid {0} was generated from Port: {1}", nameof(ProxySessionType), details.LocalPort);
                return(null);
            }
        }
Пример #13
0
        public ServerPeerSession(ILog logger, INetworkMessageRouterService sender, IConnectionDetails details, INetworkMessageSubscriptionService netMessageSubService,
			IDisconnectionServiceHandler disconnectHandler, INetworkMessageRouteBackService routebackService)
            : base(logger, sender, details, netMessageSubService, disconnectHandler, routebackService)
        {
        }
		public ClientSessionServiceContext(INetworkMessageRouterService sendService, INetworkMessageReceiver messageReceiver, INetPeer client)
		{
			SendService = sendService;
			MessageReceiver = messageReceiver;
			ClientNetPeer = client;
		}
 //Resolves a TSessionType from the context provided
 private TSessionType SessionResolve <TSessionType>(IComponentContext context, INetworkMessageRouterService sender, IConnectionDetails details,
                                                    INetworkMessageSubscriptionService subService, IDisconnectionServiceHandler disconnectHandler, INetworkMessageRouteBackService routeBackService)
     where TSessionType : ClientPeerSession
 {
     return(context.Resolve <TSessionType>(GenerateTypedParameter(sender), GenerateTypedParameter(details), GenerateTypedParameter(subService), GenerateTypedParameter(disconnectHandler), GenerateTypedParameter(routeBackService)));
 }
Пример #16
0
 /// <summary>
 /// Creates a server client session (outbound) for the incoming connection request.
 /// </summary>
 /// <param name="sender">Message sending service.</param>
 /// <param name="details">Connection details.</param>
 /// <param name="subService">Subscription service for networked messages.</param>
 /// <param name="disconnectHandler">Disconnection handling service.</param>
 /// <returns>A new client session.</returns>
 public abstract GladNet.Engine.Common.ClientPeer CreateServerPeer(INetworkMessageRouterService sender, IConnectionDetails details, INetworkMessageSubscriptionService subService,
                                                                   IDisconnectionServiceHandler disconnectHandler, INetworkMessageRouteBackService routebackService);
Пример #17
0
 /// <summary>
 /// Creates a client session for the incoming connection request.
 /// </summary>
 /// <param name="sender">Message sending service.</param>
 /// <param name="details">Connection details.</param>
 /// <param name="subService">Subscription service for networked messages.</param>
 /// <param name="disconnectHandler">Disconnection handling service.</param>
 /// <returns>A new client session.</returns>
 protected abstract ClientPeerSession CreateClientSession(INetworkMessageRouterService sender, IConnectionDetails details, INetworkMessageSubscriptionService subService,
                                                          IDisconnectionServiceHandler disconnectHandler, INetworkMessageRouteBackService routebackService);
Пример #18
0
        //Right now there isn't anything extra in a Lidgren peer. It needs to be used so that it
        //can be a future vector for delivering features to lidgren peers.

        public LidgrenClientPeer(ILog logger, INetworkMessageRouterService messageSender, IConnectionDetails details, INetworkMessageSubscriptionService subService, IDisconnectionServiceHandler disconnectHandler, INetworkMessageRouteBackService routebackService)
            : base(logger, messageSender, details, subService, disconnectHandler, routebackService)
        {
        }
		/// <summary>
		/// Creates a client session for the incoming connection request.
		/// </summary>
		/// <param name="sender">Message sending service.</param>
		/// <param name="details">Connection details.</param>
		/// <param name="subService">Subscription service for networked messages.</param>
		/// <param name="disconnectHandler">Disconnection handling service.</param>
		/// <returns>A new client session.</returns>
		protected abstract ClientPeerSession CreateClientSession(INetworkMessageRouterService sender, IConnectionDetails details, INetworkMessageSubscriptionService subService,
			IDisconnectionServiceHandler disconnectHandler, INetworkMessageRouteBackService routebackService);
		/// <summary>
		/// Creates a server client session (outbound) for the incoming connection request.
		/// </summary>
		/// <param name="sender">Message sending service.</param>
		/// <param name="details">Connection details.</param>
		/// <param name="subService">Subscription service for networked messages.</param>
		/// <param name="disconnectHandler">Disconnection handling service.</param>
		/// <returns>A new client session.</returns>
		public abstract GladNet.Engine.Common.ClientPeer CreateServerPeer(INetworkMessageRouterService sender, IConnectionDetails details, INetworkMessageSubscriptionService subService,
			IDisconnectionServiceHandler disconnectHandler, INetworkMessageRouteBackService routebackService);
Пример #21
0
 protected override ClientPeerSession CreateClientSession(INetworkMessageRouterService sender, IConnectionDetails details, INetworkMessageSubscriptionService subService, IDisconnectionServiceHandler disconnectHandler, INetworkMessageRouteBackService routeBack)
 {
     return(peerFactory.Create(sender, details, subService, disconnectHandler, routeBack));
 }
		//Right now there isn't anything extra in a Lidgren peer. It needs to be used so that it
		//can be a future vector for delivering features to lidgren peers.

		public LidgrenClientPeer(ILog logger, INetworkMessageRouterService messageSender, IConnectionDetails details, INetworkMessageSubscriptionService subService, IDisconnectionServiceHandler disconnectHandler, INetworkMessageRouteBackService routebackService) 
			: base(logger, messageSender, details, subService, disconnectHandler, routebackService)
		{

		}