mirror of
https://github.com/CyberL1/Minecraft-Realms-Emulator.git
synced 2024-12-22 04:18:21 -05:00
feat: enums
This commit is contained in:
parent
e05a82d4bc
commit
62864d58e1
@ -1,9 +0,0 @@
|
||||
namespace Minecraft_Realms_Emulator
|
||||
{
|
||||
public enum Compatility
|
||||
{
|
||||
COMPATIBLE,
|
||||
OTHER,
|
||||
OUTDATED
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Minecraft_Realms_Emulator.Attributes;
|
||||
using Minecraft_Realms_Emulator.Data;
|
||||
using Minecraft_Realms_Emulator.Enums;
|
||||
using Minecraft_Realms_Emulator.Helpers;
|
||||
using Minecraft_Realms_Emulator.Responses;
|
||||
|
||||
@ -27,14 +28,14 @@ namespace Minecraft_Realms_Emulator.Controllers
|
||||
[HttpGet("client/compatible")]
|
||||
public ActionResult<string> GetCompatible()
|
||||
{
|
||||
return Ok("COMPATIBLE");
|
||||
return Ok(nameof(VersionCompatibilityEnum.COMPATIBLE));
|
||||
}
|
||||
|
||||
[HttpGet("v1/news")]
|
||||
public ActionResult<NewsResponse> GetNews()
|
||||
{
|
||||
var config = new ConfigHelper(_context);
|
||||
var newsLink = config.GetSetting("newsLink");
|
||||
var newsLink = config.GetSetting(nameof(SettingsEnum.newsLink));
|
||||
|
||||
var news = new NewsResponse
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Minecraft_Realms_Emulator.Attributes;
|
||||
using Minecraft_Realms_Emulator.Data;
|
||||
using Minecraft_Realms_Emulator.Enums;
|
||||
using Minecraft_Realms_Emulator.Helpers;
|
||||
|
||||
namespace Minecraft_Realms_Emulator.Controllers
|
||||
@ -21,7 +22,7 @@ namespace Minecraft_Realms_Emulator.Controllers
|
||||
public ActionResult<bool> GetTrial()
|
||||
{
|
||||
var config = new ConfigHelper(_context);
|
||||
var trialMode = config.GetSetting("trialMode");
|
||||
var trialMode = config.GetSetting(nameof(SettingsEnum.trialMode));
|
||||
|
||||
return Ok(trialMode.Value);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Minecraft_Realms_Emulator.Attributes;
|
||||
using Minecraft_Realms_Emulator.Data;
|
||||
using Minecraft_Realms_Emulator.Entities;
|
||||
using Minecraft_Realms_Emulator.Enums;
|
||||
using Minecraft_Realms_Emulator.Helpers;
|
||||
using Minecraft_Realms_Emulator.Requests;
|
||||
using Minecraft_Realms_Emulator.Responses;
|
||||
@ -45,8 +46,8 @@ namespace Minecraft_Realms_Emulator.Controllers
|
||||
OwnerUUID = playerUUID,
|
||||
Name = null,
|
||||
Motd = null,
|
||||
State = "UNINITIALIZED",
|
||||
WorldType = "NORMAL",
|
||||
State = nameof(StateEnum.UNINITIALIZED),
|
||||
WorldType = nameof(WorldTypeEnum.NORMAL),
|
||||
MaxPlayers = 10,
|
||||
MinigameId = null,
|
||||
MinigameName = null,
|
||||
@ -66,7 +67,7 @@ namespace Minecraft_Realms_Emulator.Controllers
|
||||
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
|
||||
|
||||
int versionsCompared = SemVersion.Parse(gameVersion, SemVersionStyles.Strict).ComparePrecedenceTo(SemVersion.Parse(activeSlot?.Version ?? gameVersion, SemVersionStyles.Strict));
|
||||
string isCompatible = versionsCompared == 0 ? "COMPATIBLE" : versionsCompared < 0 ? "NEEDS_DOWNGRADE" : "NEEDS_UPGRADE";
|
||||
string isCompatible = versionsCompared == 0 ? nameof(CompatibilityEnum.COMPATIBLE) : versionsCompared < 0 ? nameof(CompatibilityEnum.NEEDS_DOWNGRADE) : nameof(CompatibilityEnum.NEEDS_UPGRADE);
|
||||
|
||||
WorldResponse response = new()
|
||||
{
|
||||
@ -103,7 +104,7 @@ namespace Minecraft_Realms_Emulator.Controllers
|
||||
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
|
||||
|
||||
int versionsCompared = SemVersion.Parse(gameVersion, SemVersionStyles.OptionalPatch).ComparePrecedenceTo(SemVersion.Parse(activeSlot.Version, SemVersionStyles.OptionalPatch));
|
||||
string isCompatible = versionsCompared == 0 ? "COMPATIBLE" : versionsCompared < 0 ? "NEEDS_DOWNGRADE" : "NEEDS_UPGRADE";
|
||||
string isCompatible = versionsCompared == 0 ? nameof(CompatibilityEnum.COMPATIBLE) : versionsCompared < 0 ? nameof(CompatibilityEnum.NEEDS_DOWNGRADE) : nameof(CompatibilityEnum.NEEDS_UPGRADE);
|
||||
|
||||
WorldResponse response = new()
|
||||
{
|
||||
@ -157,7 +158,7 @@ namespace Minecraft_Realms_Emulator.Controllers
|
||||
foreach (var slot in world.Slots)
|
||||
{
|
||||
int versionsCompared = SemVersion.Parse(gameVersion, SemVersionStyles.OptionalPatch).ComparePrecedenceTo(SemVersion.Parse(slot.Version, SemVersionStyles.OptionalPatch));
|
||||
string compatibility = versionsCompared == 0 ? "COMPATIBLE" : versionsCompared < 0 ? "NEEDS_DOWNGRADE" : "NEEDS_UPGRADE";
|
||||
string compatibility = versionsCompared == 0 ? nameof(CompatibilityEnum.COMPATIBLE) : versionsCompared < 0 ? nameof(CompatibilityEnum.NEEDS_DOWNGRADE) : nameof(CompatibilityEnum.NEEDS_UPGRADE);
|
||||
|
||||
slots.Add(new SlotResponse()
|
||||
{
|
||||
@ -221,17 +222,17 @@ namespace Minecraft_Realms_Emulator.Controllers
|
||||
var world = worlds.Find(w => w.Id == wId);
|
||||
|
||||
if (world == null) return NotFound("World not found");
|
||||
if (world.State != "UNINITIALIZED") return NotFound("World already initialized");
|
||||
if (world.State != nameof(StateEnum.UNINITIALIZED)) return NotFound("World already initialized");
|
||||
|
||||
var subscription = new Subscription
|
||||
{
|
||||
StartDate = DateTime.UtcNow,
|
||||
SubscriptionType = "NORMAL"
|
||||
SubscriptionType = nameof(SubscriptionTypeEnum.NORMAL)
|
||||
};
|
||||
|
||||
world.Name = body.Name;
|
||||
world.Motd = body.Description;
|
||||
world.State = "OPEN";
|
||||
world.State = nameof(StateEnum.OPEN);
|
||||
world.Subscription = subscription;
|
||||
|
||||
var config = new ConfigHelper(_context);
|
||||
@ -289,7 +290,7 @@ namespace Minecraft_Realms_Emulator.Controllers
|
||||
|
||||
if (world == null) return NotFound("World not found");
|
||||
|
||||
world.State = "OPEN";
|
||||
world.State = nameof(StateEnum.OPEN);
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
@ -306,7 +307,7 @@ namespace Minecraft_Realms_Emulator.Controllers
|
||||
|
||||
if (world == null) return NotFound("World not found");
|
||||
|
||||
world.State = "CLOSED";
|
||||
world.State = nameof(StateEnum.CLOSED);
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
|
11
Minecraft-Realms-Emulator/Enums/CompatibilityEnum.cs
Normal file
11
Minecraft-Realms-Emulator/Enums/CompatibilityEnum.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace Minecraft_Realms_Emulator.Enums
|
||||
{
|
||||
public enum CompatibilityEnum
|
||||
{
|
||||
UNVERIFIABLE,
|
||||
INCOMPATIBLE,
|
||||
NEEDS_DOWNGRADE,
|
||||
NEEDS_UPGRADE,
|
||||
COMPATIBLE
|
||||
}
|
||||
}
|
9
Minecraft-Realms-Emulator/Enums/SettingsEnum.cs
Normal file
9
Minecraft-Realms-Emulator/Enums/SettingsEnum.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace Minecraft_Realms_Emulator.Enums
|
||||
{
|
||||
public enum SettingsEnum
|
||||
{
|
||||
newsLink,
|
||||
defaultServerAddress,
|
||||
trialMode
|
||||
}
|
||||
}
|
9
Minecraft-Realms-Emulator/Enums/StateEnum.cs
Normal file
9
Minecraft-Realms-Emulator/Enums/StateEnum.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace Minecraft_Realms_Emulator.Enums
|
||||
{
|
||||
public enum StateEnum
|
||||
{
|
||||
CLOSED,
|
||||
OPEN,
|
||||
UNINITIALIZED
|
||||
}
|
||||
}
|
8
Minecraft-Realms-Emulator/Enums/SubscriptionTypeEnum.cs
Normal file
8
Minecraft-Realms-Emulator/Enums/SubscriptionTypeEnum.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace Minecraft_Realms_Emulator.Enums
|
||||
{
|
||||
public enum SubscriptionTypeEnum
|
||||
{
|
||||
NORMAL,
|
||||
RECURRING
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace Minecraft_Realms_Emulator.Enums
|
||||
{
|
||||
public enum VersionCompatibilityEnum
|
||||
{
|
||||
COMPATIBLE,
|
||||
OUTDATED,
|
||||
OTHER
|
||||
}
|
||||
}
|
11
Minecraft-Realms-Emulator/Enums/WorldTemplateTypeEnum.cs
Normal file
11
Minecraft-Realms-Emulator/Enums/WorldTemplateTypeEnum.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace Minecraft_Realms_Emulator.Enums
|
||||
{
|
||||
public enum WorldTemplateTypeEnum
|
||||
{
|
||||
WORLD_TEMPLATE,
|
||||
MINIGAME,
|
||||
ADVENTUREMAP,
|
||||
EXPERIENCE,
|
||||
INSPIRATION
|
||||
}
|
||||
}
|
11
Minecraft-Realms-Emulator/Enums/WorldTypeEnum.cs
Normal file
11
Minecraft-Realms-Emulator/Enums/WorldTypeEnum.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace Minecraft_Realms_Emulator.Enums
|
||||
{
|
||||
public enum WorldTypeEnum
|
||||
{
|
||||
NORMAL,
|
||||
MINIGAME,
|
||||
ADVENTUREMAP,
|
||||
EXPERIENCE,
|
||||
INSPIRATION
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Minecraft_Realms_Emulator.Data;
|
||||
using Minecraft_Realms_Emulator.Entities;
|
||||
using Minecraft_Realms_Emulator.Enums;
|
||||
using Minecraft_Realms_Emulator.Helpers.Config;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
@ -18,29 +19,29 @@ namespace Minecraft_Realms_Emulator.Helpers
|
||||
var config = new ConfigHelper(db);
|
||||
var settings = new Settings();
|
||||
|
||||
if (config.GetSetting("newsLink") == null)
|
||||
if (config.GetSetting(nameof(SettingsEnum.newsLink)) == null)
|
||||
{
|
||||
db.Configuration.Add(new Configuration
|
||||
{
|
||||
Key = "newsLink",
|
||||
Key = nameof(SettingsEnum.newsLink),
|
||||
Value = JsonConvert.SerializeObject(settings.NewsLink)
|
||||
});
|
||||
}
|
||||
|
||||
if (config.GetSetting("defaultServerAddress") == null)
|
||||
if (config.GetSetting(nameof(SettingsEnum.defaultServerAddress)) == null)
|
||||
{
|
||||
db.Configuration.Add(new Configuration
|
||||
{
|
||||
Key = "defaultServerAddress",
|
||||
Key = nameof(SettingsEnum.defaultServerAddress),
|
||||
Value = JsonConvert.SerializeObject(settings.DefaultServerAddress)
|
||||
});
|
||||
}
|
||||
|
||||
if (config.GetSetting("trialMode") == null)
|
||||
if (config.GetSetting(nameof(SettingsEnum.trialMode)) == null)
|
||||
{
|
||||
db.Configuration.Add(new Configuration
|
||||
{
|
||||
Key = "trialMode",
|
||||
Key = nameof(SettingsEnum.trialMode),
|
||||
Value = JsonConvert.SerializeObject(settings.TrialMode)
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user