/// <summary> /// Initializes a new instance of the <see cref="TcpServer"/> class. /// </summary> /// <param name="options">The options to intialize the instance with.</param> /// <param name="loggerFactory">A reference to the factory of loggers to use.</param> /// <param name="handlerSelector">A refrence to the selector of handlers for TCP messages.</param> /// <param name="clientsManager">A reference to a manager for clients.</param> /// <param name="listeners">A reference to the listeners to bind to the server.</param> /// <param name="gameworldAdapter">A reference to an adapter that will act as a client to the game world.</param> public TcpServer( IOptions <TcpServerOptions> options, ILoggerFactory loggerFactory, IHandlerSelector handlerSelector, IClientsManager clientsManager, IEnumerable <IListener> listeners, ITcpServerToGameworldAdapter gameworldAdapter) { options.ThrowIfNull(nameof(options)); loggerFactory.ThrowIfNull(nameof(loggerFactory)); handlerSelector.ThrowIfNull(nameof(handlerSelector)); listeners.ThrowIfNull(nameof(listeners)); gameworldAdapter.ThrowIfNull(nameof(gameworldAdapter)); if (!listeners.Any()) { throw new ArgumentException("No listeners found after composition.", nameof(listeners)); } DataAnnotationsValidator.ValidateObjectRecursive(options.Value); this.id = Guid.NewGuid().ToString(); this.logger = loggerFactory.CreateLogger <TcpServer>(); this.gameworldClientAdapter = gameworldAdapter; this.connectionToClientMap = new Dictionary <IConnection, IClient>(); this.clientsManager = clientsManager; this.Options = options.Value; this.BindListeners(loggerFactory, handlerSelector, listeners); }
/// <summary> /// Initializes a new instance of the <see cref="BaseProtocol"/> class. /// </summary> /// <param name="handlerSelector">A reference to the handler selector to use.</param> /// <param name="keepConnectionOpen">Optional. A value indicating whether to maintain the connection open after processing a message in the connection.</param> protected BaseProtocol(IHandlerSelector handlerSelector, bool keepConnectionOpen = true) { handlerSelector.ThrowIfNull(nameof(handlerSelector)); this.HandlerSelector = handlerSelector; this.keepConnectionOpen = keepConnectionOpen; }