Beispiel #1
0
		//Message responses are dispatched right after requests with this strategy. This is much different
		//than what is normally found in GladNet2 implementations.
		/// <summary>
		/// Creates a new <see cref="IWebRequestEnqueueStrategy"/> that handles requests on the calling thread
		/// and blocks.
		/// </summary>
		/// <param name="baseURL">Base string for the end-poind webserver. (Ex. www.google.com/)</param>
		/// <param name="deserializationService">Deserialization strategy for responses.</param>
		/// <param name="responseReciever">Message receiver service for dispatching recieved resposne messages.</param>
		public RestSharpCurrentThreadEnqueueRequestHandlerStrategy(string baseURL, IDeserializerStrategy deserializationService, ISerializerStrategy serializerStrategy, INetworkMessageReceiver responseReciever, int connectionAUID
#if !ENDUSER
			, INetworkMessageRouteBackService routebackService) //unfortunaly the single-threaded blocking enqueue strat needs the routeback service to function.
#endif
		{
			if (String.IsNullOrEmpty(baseURL))
				throw new ArgumentException($"Parameter {baseURL} is not valid. Either null or empty. Base URL must be the base URL of the web server. (Ex. www.google.com)");

			if (deserializationService == null)
				throw new ArgumentNullException(nameof(baseURL), $"Parameter {deserializationService} must not be null. Deserialization for incoming responses is required.");
#if !ENDUSER
			if (routebackService == null)
				throw new ArgumentNullException(nameof(routebackService), $"{nameof(RestSharpCurrentThreadEnqueueRequestHandlerStrategy)} requires {(nameof(INetworkMessageRouteBackService))} as it handles responses too.");
#endif
			serializer = serializerStrategy;
			deserializer = deserializationService;
			responseMessageRecieverService = responseReciever;

			restsharpMiddlewares = new List<IRestSharpMiddleWare>(2);

			ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
			System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;

			httpClient = new RestClient(baseURL) { Timeout = 15000 };

#if !ENDUSER
			messageRoutebackService = routebackService;
#endif
		}
Beispiel #2
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)
        /// <summary>
        /// Creates a new object that represents a client/user 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="requestHandler">Request payload handler for the session.</param>
        public UserClientPeerSession(ILog logger, INetworkMessageRouterService sender, IConnectionDetails details, INetworkMessageSubscriptionService subService, IDisconnectionServiceHandler disconnectHandler,
                                     INetworkMessageRouteBackService routebackService, IRequestMessageHandlerService <UserClientPeerSession> requestHandler)
            : base(logger, sender, 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(requestHandler)?.Now(nameof(requestHandler), $"Request handling service provided must be non-null.");

            logger.Debug("Created new client session.");

            requestHandlerService = requestHandler;
        }
 //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)));
 }
Beispiel #5
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);
Beispiel #6
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);
        //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)
        {
        }
Beispiel #8
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;
        }
        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);
        }
        public ServerPeerSession(ILog logger, INetworkMessageRouterService sender, IConnectionDetails details, INetworkMessageSubscriptionService netMessageSubService,
			IDisconnectionServiceHandler disconnectHandler, INetworkMessageRouteBackService routebackService)
            : base(logger, sender, details, netMessageSubService, disconnectHandler, routebackService)
        {
        }
Beispiel #11
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)
		{

		}
		/// <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);
		/// <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 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;
        }
        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);
            }
        }
Beispiel #17
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);
        }