mirror of
https://github.com/CyberL1/Minecraft-Realms-Emulator.git
synced 2024-12-22 04:18:21 -05:00
feat: server work modes
This commit is contained in:
parent
e7d3319b33
commit
d30a2ff408
@ -4,6 +4,7 @@
|
||||
{
|
||||
newsLink,
|
||||
defaultServerAddress,
|
||||
trialMode
|
||||
trialMode,
|
||||
workMode
|
||||
}
|
||||
}
|
||||
|
7
Minecraft-Realms-Emulator/Enums/WorkModeEnum.cs
Normal file
7
Minecraft-Realms-Emulator/Enums/WorkModeEnum.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Minecraft_Realms_Emulator.Enums
|
||||
{
|
||||
public enum WorkModeEnum
|
||||
{
|
||||
EXTERNAL
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user