Exemplo n.º 1
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            PrintHeader();
            PacketFactory.Initialize <NoS0575Packet>();
            var configuration = InitializeConfiguration();

            services.AddSingleton <IServerAddressesFeature>(new ServerAddressesFeature
            {
                PreferHostingUrls = true,
                Addresses         = { configuration.WebApi.ToString() }
            });
            LogLanguage.Language = configuration.Language;
            services.AddSwaggerGen(c => c.SwaggerDoc("v1", new Info {
                Title = "NosCore World API", Version = "v1"
            }));
            var keyByteArray =
                Encoding.Default.GetBytes(EncryptionHelper.Sha512(configuration.MasterCommunication.Password));
            var signinKey = new SymmetricSecurityKey(keyByteArray);

            services.AddLogging(builder => builder.AddFilter("Microsoft", LogLevel.Warning));
            services.AddAuthentication(config => config.DefaultScheme = JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(cfg =>
            {
                cfg.RequireHttpsMetadata      = false;
                cfg.SaveToken                 = true;
                cfg.TokenValidationParameters = new TokenValidationParameters
                {
                    IssuerSigningKey         = signinKey,
                    ValidAudience            = "Audience",
                    ValidIssuer              = "Issuer",
                    ValidateIssuerSigningKey = true,
                    ValidateLifetime         = true
                };
            });

            services.AddMvc(o =>
            {
                var policy = new AuthorizationPolicyBuilder()
                             .RequireAuthenticatedUser()
                             .Build();
                o.Filters.Add(new AuthorizeFilter(policy));
            }).AddApplicationPart(typeof(TokenController).GetTypeInfo().Assembly).AddControllersAsServices();
            var containerBuilder = InitializeContainer(services);

            containerBuilder.RegisterInstance(configuration).As <WorldConfiguration>();
            containerBuilder.RegisterInstance(configuration.MasterCommunication).As <MasterCommunicationConfiguration>();
            var container = containerBuilder.Build();

            PacketControllerFactory.Initialize(container);
            Logger.InitializeLogger(LogManager.GetLogger(typeof(WorldServer)));
            Task.Run(() => container.Resolve <WorldServer>().Run());
            return(new AutofacServiceProvider(container));
        }
Exemplo n.º 2
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            PrintHeader();
            PacketFactory.Initialize <NoS0575Packet>();
            var conf = InitializeConfiguration();

            services.AddSwaggerGen(c => c.SwaggerDoc("v1", new Info {
                Title = "NosCore World API", Version = "v1"
            }));
            var keyByteArray = Encoding.ASCII.GetBytes(EncryptionHelper.Sha512(conf.MasterCommunication.Password));
            var signinKey    = new SymmetricSecurityKey(keyByteArray);

            services.AddAuthentication(config => config.DefaultScheme = JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(cfg =>
            {
                cfg.RequireHttpsMetadata      = false;
                cfg.SaveToken                 = true;
                cfg.TokenValidationParameters = new TokenValidationParameters()
                {
                    IssuerSigningKey         = signinKey,
                    ValidAudience            = "Audience",
                    ValidIssuer              = "Issuer",
                    ValidateIssuerSigningKey = true,
                    ValidateLifetime         = true,
                };
            });

            services.AddMvc(o =>
            {
                var policy = new AuthorizationPolicyBuilder()
                             .RequireAuthenticatedUser()
                             .Build();
                o.Filters.Add(new AuthorizeFilter(policy));
            }).AddApplicationPart(typeof(TokenController).GetTypeInfo().Assembly).AddControllersAsServices();
            var containerBuilder = InitializeContainer(services);

            containerBuilder.RegisterInstance(conf).As <WorldConfiguration>();
            containerBuilder.RegisterInstance(conf.MasterCommunication).As <MasterCommunicationConfiguration>();
            var container = containerBuilder.Build();

            PacketControllerFactory.Initialize(container);
            Task.Run(() => container.Resolve <WorldServer>().Run());
            return(new AutofacServiceProvider(container));
        }
Exemplo n.º 3
0
 private static void InitializeControllers(IContainer container)
 {
     PacketControllerFactory.Initialize(container);
 }