feat: more settings (OnlineMode, AutomaticRealmsCreation)

This commit is contained in:
CyberL1 2024-06-25 08:54:11 +02:00
parent f9f07756ac
commit 11444c75b1
6 changed files with 39 additions and 5 deletions

View File

@ -5,6 +5,8 @@
NewsLink,
DefaultServerAddress,
TrialMode,
WorkMode
WorkMode,
OnlineMode,
AutomaticRealmsCreation
}
}

View File

@ -8,5 +8,7 @@ namespace Minecraft_Realms_Emulator.Helpers.Config
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);
public bool OnlineMode { get; set; } = false;
public bool AutomaticRealmsCreation { get; set; } = true;
}
}

View File

@ -20,8 +20,23 @@ namespace Minecraft_Realms_Emulator.Modes.External
}
[HttpGet("available")]
public ActionResult<bool> GetAvailable()
public async Task<ActionResult<bool>> GetAvailable()
{
if (new ConfigHelper(_context).GetSetting(nameof(SettingsEnum.OnlineMode)).Value)
{
string cookie = Request.Headers.Cookie;
string playerUUID = cookie.Split(";")[0].Split(":")[2];
try
{
await new HttpClient().GetFromJsonAsync<MinecraftPlayerInfo>($"https://sessionserver.mojang.com/session/minecraft/profile/{playerUUID}");
}
catch
{
return Unauthorized();
}
}
return Ok(true);
}

View File

@ -38,7 +38,7 @@ namespace Minecraft_Realms_Emulator.Modes.External
List<WorldResponse> allWorlds = [];
if (ownedWorlds.ToArray().Length == 0)
if (ownedWorlds.ToArray().Length == 0 && new ConfigHelper(_context).GetSetting(nameof(SettingsEnum.AutomaticRealmsCreation)).Value)
{
var world = new World
{

View File

@ -20,8 +20,23 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
}
[HttpGet("available")]
public ActionResult<bool> GetAvailable()
public async Task<ActionResult<bool>> GetAvailable()
{
if (new ConfigHelper(_context).GetSetting(nameof(SettingsEnum.OnlineMode)).Value)
{
string cookie = Request.Headers.Cookie;
string playerUUID = cookie.Split(";")[0].Split(":")[2];
try
{
await new HttpClient().GetFromJsonAsync<MinecraftPlayerInfo>($"https://sessionserver.mojang.com/session/minecraft/profile/{playerUUID}");
}
catch
{
return Unauthorized();
}
}
return Ok(true);
}

View File

@ -41,7 +41,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
List<WorldResponse> allWorlds = [];
if (ownedWorlds.ToArray().Length == 0)
if (ownedWorlds.ToArray().Length == 0 && new ConfigHelper(_context).GetSetting(nameof(SettingsEnum.AutomaticRealmsCreation)).Value)
{
var world = new World
{