62 lines
2.3 KiB
C#
62 lines
2.3 KiB
C#
using Microsoft.AspNetCore.StaticFiles;
|
|
using Microsoft.Extensions.FileProviders;
|
|
using ReboundEmulator.Core;
|
|
using ReboundEmulator.Core.Rooms;
|
|
|
|
namespace ReboundEmulator
|
|
{
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
Sessions.Init(builder.Configuration["SessionSecret"] ?? "change-me");
|
|
|
|
// Add services to the container.
|
|
|
|
builder.Services.AddControllersWithViews();
|
|
|
|
// Add Game Server Hosted Service
|
|
builder.Services.AddHostedService<TCPGameServer>();
|
|
|
|
var app = builder.Build();
|
|
|
|
var publicAssetsRoot = Path.Combine(AppContext.BaseDirectory, "StaticFiles", "PublicAssets");
|
|
Directory.CreateDirectory(publicAssetsRoot); // avoid a startup crash if it doesn't exist yet, public assets (images, sounds, etc)
|
|
|
|
var configRoot = Path.Combine(AppContext.BaseDirectory, "StaticFiles", "Configs");
|
|
Directory.CreateDirectory(configRoot); // configs
|
|
|
|
var jarArchiveRoot = Path.Combine(AppContext.BaseDirectory, "StaticFiles", "JARs");
|
|
Directory.CreateDirectory(jarArchiveRoot); // jar files
|
|
|
|
var contentTypeProvider = new FileExtensionContentTypeProvider();
|
|
contentTypeProvider.Mappings[".au"] = "audio/basic"; // Java applet sound format
|
|
contentTypeProvider.Mappings[".dat"] = "application/octet-stream"; // Gameblend_GPD binary configs
|
|
|
|
app.UseStaticFiles(new StaticFileOptions
|
|
{
|
|
FileProvider = new PhysicalFileProvider(publicAssetsRoot),
|
|
RequestPath = "", // serve at the site root, matching real paths like /applet/images/chat/welcome.jpg
|
|
ContentTypeProvider = contentTypeProvider,
|
|
ServeUnknownFileTypes = true,
|
|
DefaultContentType = "application/octet-stream"
|
|
});
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
app.MapFlashGateway();
|
|
|
|
// Define Rooms For CDL Games
|
|
RoomManager.LoadFromFile(Path.Combine(AppContext.BaseDirectory, "StaticFiles", "rooms.json"));
|
|
|
|
app.Run();
|
|
}
|
|
}
|
|
}
|