/// <summary> /// Initializes a basic <see cref="LiteServer{TUser}"/> with the specified <typeparamref name="TLiteServerUser"/>. /// </summary> /// <typeparam name="TLiteServerUser">Server's user type.</typeparam> /// <param name="builder">A <see cref="ILiteBuilder"/> to add server.</param> /// <param name="configure">Delegate to configure a <see cref="LiteServerOptions"/>.</param> /// <returns>The <see cref="ILiteBuilder"/>.</returns> public static ILiteBuilder AddLiteServer <TLiteServerUser>(this ILiteBuilder builder, Action <LiteServerOptions> configure) where TLiteServerUser : LiteServerUser { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } builder.Services.AddSingleton <ILiteServer <TLiteServerUser>, LiteServer <TLiteServerUser> >(serviceProvider => { var liteServerOptions = new LiteServerOptions(); configure(liteServerOptions); var server = new LiteServer <TLiteServerUser>(liteServerOptions, serviceProvider); return(server); }); builder.Services.AddHostedService(serviceProvider => { var serverInstance = serviceProvider.GetRequiredService <ILiteServer <TLiteServerUser> >(); return(new LiteServerHostedService <TLiteServerUser>(serverInstance)); }); return(builder); }
/// <summary> /// Initializes a <typeparamref name="TLiteServer"/> with the specified <typeparamref name="TLiteServerUser"/>. /// </summary> /// <typeparam name="TLiteServer">Server type.</typeparam> /// <typeparam name="TLiteServerUser">Server's user type.</typeparam> /// <param name="builder">A <see cref="ILiteBuilder"/> to add server.</param> /// <param name="configure">Delegate to configure a <see cref="LiteServerOptions"/>.</param> /// <returns>The <see cref="ILiteBuilder"/>.</returns> public static ILiteBuilder AddLiteServer <TLiteServer, TLiteServerUser>(this ILiteBuilder builder, Action <LiteServerOptions> configure) where TLiteServer : class, ILiteServer <TLiteServerUser> where TLiteServerUser : LiteServerUser { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } builder.Services.AddSingleton(serviceProvider => { var liteServerOptions = new LiteServerOptions(); configure(liteServerOptions); TLiteServer server = ActivatorUtilities.CreateInstance <TLiteServer>(serviceProvider, liteServerOptions); if (server is LiteServer <TLiteServerUser> serverInstance) { serverInstance.SetServiceProvider(serviceProvider); } return(server); }); builder.Services.AddHostedService(serviceProvider => { var serverInstance = serviceProvider.GetRequiredService <TLiteServer>(); return(new LiteServerHostedService <TLiteServerUser>(serverInstance)); }); return(builder); }
public RedstoneServer(LiteServerOptions configuration, IServiceProvider serviceProvider = null) : base(configuration, serviceProvider) { _logger = serviceProvider.GetRequiredService <ILogger <RedstoneServer> >(); _packetEncryption = serviceProvider.GetRequiredService <IMinecraftPacketEncryption>(); _serverConfiguration = serviceProvider.GetRequiredService <IOptions <ServerOptions> >(); _gameConfiguration = serviceProvider.GetRequiredService <IOptions <GameOptions> >(); _registry = serviceProvider.GetRequiredService <IRegistry>(); _worldManager = serviceProvider.GetRequiredService <IWorld>(); Events = new RedstoneServerEvents(this); }
static void Main(string[] args) { var configuration = new LiteServerOptions() { Host = "127.0.0.1", Port = 4444, ReceiveStrategy = Common.ReceiveStrategyType.Queued }; using var server = new EchoServer(configuration); server.Start(); Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("=== ECHO SERVER ==="); var configuration = new LiteServerOptions() { Host = "127.0.0.1", Port = 4444, ReceiveStrategy = ReceiveStrategyType.Queued }; using var server = new EchoServer(configuration); server.Start(); Console.ReadKey(); }
public CustomServer(LiteServerOptions options, IServiceProvider serviceProvider) : base(options, serviceProvider) { }
public EchoServer(LiteServerOptions options) : base(options) { }