begin new and last rework
This commit is contained in:
@@ -1,10 +1,69 @@
|
||||
namespace OwnChar.Server
|
||||
using OwnChar.Data;
|
||||
using OwnChar.Plugins;
|
||||
using OwnChar.ServerNew.Api.Endpoint;
|
||||
using OwnChar.ServerNew.Api.Endpoint.Implementations;
|
||||
using OwnChar.ServerNew.Api.Plugins;
|
||||
using Pilz.Configuration;
|
||||
using Pilz.Plugins;
|
||||
using Pilz.Plugins.Advanced;
|
||||
|
||||
namespace OwnChar.ServerNew;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
internal class Program
|
||||
public static string? AppTempFolder { get; private set; }
|
||||
public static ISettingsManager? SettingsManager { get; private set; }
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
static void Main(string[] args)
|
||||
// Load settings
|
||||
AppTempFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "OwnChar", "Server");
|
||||
Directory.CreateDirectory(AppTempFolder);
|
||||
SettingsManager = new SettingsManager(Path.Combine(AppTempFolder, "Settings.json"), true);
|
||||
|
||||
// Create server context
|
||||
var server = new ServerContext(SettingsManager.Instance);
|
||||
|
||||
// Load plugins
|
||||
var pluginPath = Path.Combine(AppTempFolder, "Plugins");
|
||||
Directory.CreateDirectory(pluginPath);
|
||||
var pluginPaths = Directory.GetDirectories(pluginPath, "*", SearchOption.TopDirectoryOnly).Select(n => Path.Combine(n, n + ".dll")).ToArray();
|
||||
OwnCharPlugins.Instance.LoadPlugins(pluginPaths, new OwnCharServerPluginInitParams(server));
|
||||
|
||||
// Add services to the container.
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddAuthorization();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
// Build app
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
Console.WriteLine("Hello, World!");
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
app.UseHttpsRedirection();
|
||||
app.UseAuthorization();
|
||||
|
||||
// Built-in endpoints
|
||||
var apibuilder = new ApiBuilder(app);
|
||||
new LoginApi(server).Initialize(apibuilder);
|
||||
new UsersApi(server).Initialize(apibuilder);
|
||||
new GroupsApi(server).Initialize(apibuilder);
|
||||
new CharactersApi(server).Initialize(apibuilder);
|
||||
|
||||
// Plugin endpoints
|
||||
var endpoints = PluginFeatureController.Instance.Features.Get(ApiEndpointFeature.FeatureType).OfType<IApiEndpoint>();
|
||||
if (endpoints.Any())
|
||||
{
|
||||
foreach (var endpoint in endpoints)
|
||||
endpoint.Initialize(apibuilder);
|
||||
}
|
||||
|
||||
// Run server
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user