feat: server work modes

This commit is contained in:
CyberL1 2024-05-23 18:21:09 +02:00
parent e7d3319b33
commit d30a2ff408
10 changed files with 49 additions and 14 deletions

View File

@ -4,6 +4,7 @@
{
newsLink,
defaultServerAddress,
trialMode
trialMode,
workMode
}
}

View File

@ -0,0 +1,7 @@
namespace Minecraft_Realms_Emulator.Enums
{
public enum WorkModeEnum
{
EXTERNAL
}
}

View File

@ -1,9 +1,12 @@
namespace Minecraft_Realms_Emulator.Helpers.Config
using Minecraft_Realms_Emulator.Enums;
namespace Minecraft_Realms_Emulator.Helpers.Config
{
public class Settings
{
public string DefaultServerAddress { get; set; } = "127.0.0.1";
public string NewsLink { get; set; } = "https://github.com/CyberL1/Minecraft-Realms-Emulator";
public bool TrialMode { get; set; } = true;
public string WorkMode { get; set; } = nameof(WorkModeEnum.EXTERNAL);
}
}

View File

@ -6,9 +6,9 @@ using Minecraft_Realms_Emulator.Entities;
using Minecraft_Realms_Emulator.Requests;
using Minecraft_Realms_Emulator.Responses;
namespace Minecraft_Realms_Emulator.Controllers
namespace Minecraft_Realms_Emulator.Modes.External.Controllers
{
[Route("[controller]")]
[Route("modes/external/[controller]")]
[ApiController]
[RequireMinecraftCookie]
public class InvitesController : ControllerBase

View File

@ -5,9 +5,9 @@ using Minecraft_Realms_Emulator.Enums;
using Minecraft_Realms_Emulator.Helpers;
using Minecraft_Realms_Emulator.Responses;
namespace Minecraft_Realms_Emulator.Controllers
namespace Minecraft_Realms_Emulator.Modes.External.Controllers
{
[Route("[controller]")]
[Route("modes/external/[controller]")]
[ApiController]
[RequireMinecraftCookie]
public class McoController : ControllerBase

View File

@ -3,9 +3,9 @@ using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Responses;
namespace Minecraft_Realms_Emulator.Controllers
namespace Minecraft_Realms_Emulator.Modes.External.Controllers
{
[Route("[controller]")]
[Route("modes/exterrnal/[controller]")]
[ApiController]
[RequireMinecraftCookie]
public class OpsController : ControllerBase

View File

@ -4,9 +4,9 @@ using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Responses;
namespace Minecraft_Realms_Emulator.Controllers
namespace Minecraft_Realms_Emulator.Modes.External.Controllers
{
[Route("[controller]")]
[Route("modes/external/[controller]")]
[ApiController]
[RequireMinecraftCookie]
public class SubscriptionsController : ControllerBase

View File

@ -4,9 +4,9 @@ using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Enums;
using Minecraft_Realms_Emulator.Helpers;
namespace Minecraft_Realms_Emulator.Controllers
namespace Minecraft_Realms_Emulator.Modes.External.Controllers
{
[Route("[controller]")]
[Route("modes/external/[controller]")]
[ApiController]
[RequireMinecraftCookie]
public class TrialController : ControllerBase

View File

@ -10,9 +10,9 @@ using Minecraft_Realms_Emulator.Responses;
using Newtonsoft.Json;
using Semver;
namespace Minecraft_Realms_Emulator.Controllers
namespace Minecraft_Realms_Emulator.Modes.External.Controllers
{
[Route("[controller]")]
[Route("modes/external/[controller]")]
[ApiController]
[RequireMinecraftCookie]
public class WorldsController : ControllerBase

View File

@ -1,5 +1,7 @@
using Microsoft.AspNetCore.Rewrite;
using Microsoft.EntityFrameworkCore;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Enums;
using Minecraft_Realms_Emulator.Helpers;
using Minecraft_Realms_Emulator.Middlewares;
using Npgsql;
@ -44,6 +46,28 @@ if (app.Environment.IsDevelopment())
app.UseMiddleware<MinecraftCookieMiddleware>();
app.UseMiddleware<CheckRealmOwnerMiddleware>();
var scope = app.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<DataContext>();
app.MapControllers();
var config = new ConfigHelper(db);
var mode = config.GetSetting(nameof(SettingsEnum.workMode));
if (mode == null)
{
Console.WriteLine("Cannot get server work mode, exiting");
Environment.Exit(1);
}
if (!Enum.IsDefined(typeof(WorkModeEnum), mode.Value))
{
Console.WriteLine("Invalid server work mode, exiting");
Environment.Exit(1);
}
var rewriteOptions = new RewriteOptions().AddRewrite(@"^(?!.*configuration)(.*)$", $"modes/{mode.Value}/$1", true);
app.UseRewriter(rewriteOptions);
Console.WriteLine($"Running in {mode.Value} mode");
app.Run();