using GameChannel.Consumers; using GameChannel.Network; using GameChannel.RecurrentJobs; using GameChannel.Services; using GameChannel.Ticks; using GameChannel.Utils; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Hosting; using PhoenixLib.Configuration; using PhoenixLib.DAL; using PhoenixLib.DAL.Redis; using PhoenixLib.Events; using PhoenixLib.Logging; using PhoenixLib.Scheduler.ReactiveX; using PhoenixLib.ServiceBus.Extensions; using Plugin.Act4; using Plugin.CoreImpl; using Plugin.FamilyImpl; using Plugin.PlayerLogs; using Plugin.QuestImpl; using Plugin.Raids; using Plugin.RainbowBattle; using Plugin.ResourceLoader; using Plugin.TimeSpaces; using WingsAPI.Communication.Punishment; using WingsAPI.Communication.ServerApi; using WingsAPI.Communication.Services.Messages; using WingsAPI.Plugins; using WingsAPI.Plugins.Exceptions; using WingsEmu.Commands; using WingsEmu.Commands.Interfaces; using WingsEmu.Communication.gRPC.Extensions; using WingsEmu.Game.Commands; using WingsEmu.Game.Logs; using WingsEmu.Health.Extensions; using WingsEmu.Packets; using WingsEmu.Plugins.BasicImplementations; using WingsEmu.Plugins.BasicImplementations.Algorithms; using WingsEmu.Plugins.BasicImplementations.BCards; using WingsEmu.Plugins.DistributedGameEvents; using WingsEmu.Plugins.DistributedGameEvents.Consumer; using WingsEmu.Plugins.DistributedGameEvents.Mails; using WingsEmu.Plugins.DistributedGameEvents.PlayerEvents; using WingsEmu.Plugins.DistributedGameEvents.Relation; using WingsEmu.Plugins.Essentials; using WingsEmu.Plugins.GameEvents; using WingsEmu.Plugins.PacketHandling; using WingsEmu.Plugins.PacketHandling.Customization; namespace GameChannel { public class Startup { private static ServiceProvider GetPluginsProvider() { var pluginBuilder = new ServiceCollection(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); pluginBuilder.AddTransient(); return pluginBuilder.BuildServiceProvider(); } // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddGrpc(options => { options.MaxReceiveMessageSize = null; options.MaxSendMessageSize = null; }); //No idea if this SerializableWorld thingy has to be removed in the future, but I need this info for loading or not loading Act4 thingies. services.AddSingleton(WorldServerSingleton.Instance); var loader = new GameServerLoader { Type = WorldServerSingleton.Instance.ChannelType }; using ServiceProvider plugins = GetPluginsProvider(); foreach (IDependencyInjectorPlugin plugin in plugins.GetServices()) { try { Log.Debug($"[PLUGIN_LOADER] Loading generic plugin {plugin.Name}..."); plugin.AddDependencies(services); } catch (PluginException e) { Log.Error($"{plugin.Name} : plugin.OnLoad", e); } } foreach (IGameServerPlugin plugin in plugins.GetServices()) { try { Log.Debug($"[PLUGIN_LOADER] Loading game plugin {plugin.Name}..."); plugin.AddDependencies(services, loader); } catch (PluginException e) { Log.Error($"{plugin.Name} : plugin.OnLoad", e); } } services.TryAddSingleton(); services.AddPhoenixLogging(); // add redis services.TryAddSingleton(s => RedisConfiguration.FromEnv()); services.TryAddSingleton(s => s.GetRequiredService().GetConnectionMultiplexer()); services.AddMaintenanceMode(); services.AddYamlConfigurationHelper(); services.AddSingleton(s => new PacketSerializer()); // client session factory services.AddTransient(); services.TryAddTransient(typeof(IMapper<,>), typeof(MapsterMapper<,>)); services.AddServerApiServiceClient(); services.AddGrpcSessionServiceClient(); services.AddGrpcMailServiceClient(); services.AddGrpcRelationServiceClient(); services.AddGrpcClusterStatusServiceClient(); services.AddClusterCharacterServiceClient(); services.AddTranslationsGrpcClient(); services.AddTickSystem(); services.AddMqttConfigurationFromEnv(); services.AddMessagePublisher(); services.AddMessagePublisher(); services.AddMessagePublisher(); services.AddMessageSubscriber(); services.AddMessageSubscriber(); services.AddMessageSubscriber(); services.AddMessagePublisher(); services.AddMessageSubscriber(); services.AddMessageSubscriber(); services.AddMessageSubscriber(); services.AddMessageSubscriber(); services.AddMessageSubscriber(); services.AddMessageSubscriber(); services.AddMessageSubscriber(); services.AddMessageSubscriber(); services.AddMessageSubscriber(); services.AddMessageSubscriber(); services.AddMessageSubscriber(); services.AddMessagePublisher(); services.AddMessageSubscriber(); services.AddMessageSubscriber(); services.AddEventPipeline(); services.AddHostedService(); services.AddSingleton(); services.AddSingleton(provider => (PlayerLogManager)provider.GetService()); /* * Helpers to remove */ services.AddScheduler(); services.AddCron(); services.AddSingleton(); services.AddSingleton(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseEndpoints(e => e.MapControllers()); } } }