forked from SoDOff-Project/sodoff

* add support for old missions API (aka "steps missions") * config option to disable loading non SoD Data (used only for missions and achievements for now) * make AuthenticateUser endpoint compatible with games that use e-mail as login * add api keys for lands * add GetGameCurrency endpoint * allow create empty stores and add store "8" (empty) --------- Co-authored-by: Robert Paciorek <robert@opcode.eu.org>
71 lines
2.6 KiB
C#
71 lines
2.6 KiB
C#
using Microsoft.AspNetCore.Mvc.Formatters;
|
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
|
using sodoff.Configuration;
|
|
using sodoff.Middleware;
|
|
using sodoff.Model;
|
|
using sodoff.Services;
|
|
using sodoff.Utils;
|
|
using System.Xml;
|
|
using System.Net;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Add services to the container.
|
|
|
|
builder.Services.Configure<AssetServerConfig>(builder.Configuration.GetSection("AssetServer"));
|
|
builder.Services.Configure<ApiServerConfig>(builder.Configuration.GetSection("ApiServer"));
|
|
builder.Services.AddControllers(options => {
|
|
options.OutputFormatters.Add(new XmlSerializerOutputFormatter(new XmlWriterSettings() { OmitXmlDeclaration = false }));
|
|
options.OutputFormatters.RemoveType<HttpNoContentOutputFormatter>();
|
|
options.Filters.Add<LogRequestOnError>();
|
|
});
|
|
builder.Services.AddDbContext<DBContext>();
|
|
|
|
// create Modding Service singleton here ... do this before start http server to avoid serve invalid assets list
|
|
builder.Services.AddSingleton<ModdingService>(new ModdingService());
|
|
// other singletons will be created at first use ...
|
|
builder.Services.AddSingleton<MissionStoreSingleton>();
|
|
builder.Services.AddSingleton<AchievementStoreSingleton>();
|
|
builder.Services.AddSingleton<ItemService>();
|
|
builder.Services.AddSingleton<StoreService>();
|
|
builder.Services.AddSingleton<DisplayNamesService>();
|
|
builder.Services.AddSingleton<MMOConfigService>();
|
|
builder.Services.AddSingleton<WorldIdService>();
|
|
|
|
builder.Services.AddScoped<KeyValueService>();
|
|
builder.Services.AddScoped<MissionService>();
|
|
builder.Services.AddScoped<RoomService>();
|
|
builder.Services.AddScoped<InventoryService>();
|
|
builder.Services.AddScoped<AchievementService>();
|
|
builder.Services.AddScoped<GameDataService>();
|
|
builder.Services.AddScoped<ProfileService>();
|
|
builder.Services.AddScoped<NeighborhoodService>();
|
|
|
|
bool assetServer = builder.Configuration.GetSection("AssetServer").GetValue<bool>("Enabled");
|
|
string assetIP = builder.Configuration.GetSection("AssetServer").GetValue<string>("ListenIP");
|
|
int assetPort = builder.Configuration.GetSection("AssetServer").GetValue<int>("Port");
|
|
if (assetServer)
|
|
builder.Services.Configure<KestrelServerOptions>(options => {
|
|
if (String.IsNullOrEmpty(assetIP) || assetIP == "*")
|
|
options.ListenAnyIP(assetPort);
|
|
else
|
|
options.Listen(IPAddress.Parse(assetIP), assetPort);
|
|
});
|
|
|
|
var app = builder.Build();
|
|
|
|
using var scope = app.Services.CreateScope();
|
|
|
|
scope.ServiceProvider.GetRequiredService<DBContext>().Database.EnsureCreated();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
if (assetServer)
|
|
app.UseMiddleware<AssetMiddleware>();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run();
|