commit aa1e118775c37f5f7fb2082196d9b018daf46860 Author: CyberL1 Date: Sat Apr 20 09:20:30 2024 +0200 Import from Github diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9491a2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,363 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Oo]ut/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd \ No newline at end of file diff --git a/Minecraft-Realms-Emulator.sln b/Minecraft-Realms-Emulator.sln new file mode 100644 index 0000000..e229d1e --- /dev/null +++ b/Minecraft-Realms-Emulator.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34511.84 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Minecraft-Realms-Emulator", "Minecraft-Realms-Emulator\Minecraft-Realms-Emulator.csproj", "{A9A21AAF-EF1B-4723-9407-51FD6B831B98}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A9A21AAF-EF1B-4723-9407-51FD6B831B98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A9A21AAF-EF1B-4723-9407-51FD6B831B98}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A9A21AAF-EF1B-4723-9407-51FD6B831B98}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A9A21AAF-EF1B-4723-9407-51FD6B831B98}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {BA6B23CA-D2DE-4AD2-9958-A8A4E3976210} + EndGlobalSection +EndGlobal diff --git a/Minecraft-Realms-Emulator/.gitignore b/Minecraft-Realms-Emulator/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/Minecraft-Realms-Emulator/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/Minecraft-Realms-Emulator/Attributes/RequireMinecraftCookieAttribute.cs b/Minecraft-Realms-Emulator/Attributes/RequireMinecraftCookieAttribute.cs new file mode 100644 index 0000000..6bf810f --- /dev/null +++ b/Minecraft-Realms-Emulator/Attributes/RequireMinecraftCookieAttribute.cs @@ -0,0 +1,15 @@ +namespace Minecraft_Realms_Emulator.Attributes +{ + [AttributeUsage(AttributeTargets.Class)] + public class RequireMinecraftCookieAttribute : Attribute + { + public RequireMinecraftCookieAttribute() + { + } + + public bool HasMinecraftCookie(string cookie) + { + return cookie.Contains("sid") && cookie.Contains("user") && cookie.Contains("version"); + } + } +} diff --git a/Minecraft-Realms-Emulator/Compatibility.cs b/Minecraft-Realms-Emulator/Compatibility.cs new file mode 100644 index 0000000..9377d81 --- /dev/null +++ b/Minecraft-Realms-Emulator/Compatibility.cs @@ -0,0 +1,9 @@ +namespace Minecraft_Realms_Emulator +{ + public enum Compatility + { + COMPATIBLE, + OTHER, + OUTDATED + } +} diff --git a/Minecraft-Realms-Emulator/Controllers/ConfigurationController.cs b/Minecraft-Realms-Emulator/Controllers/ConfigurationController.cs new file mode 100644 index 0000000..84fce0a --- /dev/null +++ b/Minecraft-Realms-Emulator/Controllers/ConfigurationController.cs @@ -0,0 +1,25 @@ +using Microsoft.AspNetCore.Mvc; +using Minecraft_Realms_Emulator.Data; +using Minecraft_Realms_Emulator.Entities; + +namespace Minecraft_Realms_Emulator.Controllers +{ + [Route("[controller]")] + [ApiController] + public class ConfigurationController : ControllerBase + { + private readonly DataContext _context; + + public ConfigurationController(DataContext context) + { + _context = context; + } + + [HttpGet] + public ActionResult GetConfigurationAsync() + { + var configuration = _context.Configuration; + return Ok(configuration); + } + } +} \ No newline at end of file diff --git a/Minecraft-Realms-Emulator/Controllers/InvitesController.cs b/Minecraft-Realms-Emulator/Controllers/InvitesController.cs new file mode 100644 index 0000000..76ca189 --- /dev/null +++ b/Minecraft-Realms-Emulator/Controllers/InvitesController.cs @@ -0,0 +1,178 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Minecraft_Realms_Emulator.Attributes; +using Minecraft_Realms_Emulator.Data; +using Minecraft_Realms_Emulator.Entities; +using Minecraft_Realms_Emulator.Requests; +using Minecraft_Realms_Emulator.Responses; + +namespace Minecraft_Realms_Emulator.Controllers +{ + [Route("[controller]")] + [ApiController] + [RequireMinecraftCookie] + public class InvitesController : ControllerBase + { + private readonly DataContext _context; + + public InvitesController(DataContext context) + { + _context = context; + } + + [HttpGet("pending")] + public async Task> GetInvites() + { + string cookie = Request.Headers.Cookie; + string playerUUID = cookie.Split(";")[0].Split(":")[2]; + + var invites = await _context.Invites.Where(i => i.RecipeintUUID == playerUUID).Include(i => i.World).ToListAsync(); + + List invitesList = []; + + foreach (var invite in invites) + { + InviteResponse inv = new() + { + InvitationId = invite.InvitationId, + WorldName = invite.World.Name, + WorldOwnerName = invite.World.Owner, + WorldOwnerUuid = invite.World.OwnerUUID, + Date = ((DateTimeOffset) invite.Date).ToUnixTimeMilliseconds(), + }; + + invitesList.Add(inv); + } + + InviteList inviteListRespone = new() + { + Invites = invitesList + }; + + return Ok(inviteListRespone); + } + [HttpPut("accept/{id}")] + public ActionResult AcceptInvite(string id) + { + string cookie = Request.Headers.Cookie; + string playerUUID = cookie.Split(";")[0].Split(":")[2]; + + var invite = _context.Invites.Include(i => i.World).FirstOrDefault(i => i.InvitationId == id); + + if (invite == null) return NotFound("Invite not found"); + + var player = _context.Players.Where(p => p.World.Id == invite.World.Id).FirstOrDefault(p => p.Uuid == playerUUID); + + player.Accepted = true; + + _context.Invites.Remove(invite); + + _context.SaveChanges(); + + return Ok(true); + } + + [HttpPut("reject/{id}")] + public ActionResult RejectInvite(string id) + { + var invite = _context.Invites.Include(i => i.World).FirstOrDefault(i => i.InvitationId == id); + + if (invite == null) return NotFound("Invite not found"); + + _context.Invites.Remove(invite); + + string cookie = Request.Headers.Cookie; + string playerUUID = cookie.Split(";")[0].Split(":")[2]; + + var player = _context.Players.Where(p => p.World.Id == invite.World.Id).FirstOrDefault(p => p.Uuid == playerUUID); + + _context.Players.Remove(player); + + _context.SaveChanges(); + + return Ok(true); + } + + [HttpPost("{wId}")] + public async Task> InvitePlayer(int wId, PlayerRequest body) + { + string cookie = Request.Headers.Cookie; + string playerName = cookie.Split(";")[1].Split("=")[1]; + + if (body.Name == playerName) return Forbid("You cannot invite yourself"); + + var world = await _context.Worlds.Include(w => w.Players).FirstOrDefaultAsync(w => w.Id == wId); + + if (world == null) return NotFound("World not found"); + + // Get player UUID + var playerInfo = await new HttpClient().GetFromJsonAsync($"https://api.mojang.com/users/profiles/minecraft/{body.Name}"); + + var playerInDB = await _context.Players.Where(p => p.World.Id == wId).FirstOrDefaultAsync(p => p.Uuid == playerInfo.Id); + + if (playerInDB?.Uuid == playerInfo.Id) return BadRequest("Player already invited"); + + Player player = new() + { + Name = body.Name, + Uuid = playerInfo.Id, + World = world + }; + + _context.Players.Add(player); + + Invite invite = new() + { + InvitationId = Guid.NewGuid().ToString(), + World = world, + RecipeintUUID = playerInfo.Id, + Date = DateTime.UtcNow, + }; + + _context.Invites.Add(invite); + + _context.SaveChanges(); + + return Ok(world); + } + + [HttpDelete("{wId}/invite/{uuid}")] + public async Task> DeleteInvite(int wId, string uuid) + { + var world = await _context.Worlds.FirstOrDefaultAsync(w => w.Id == wId); + + if (world == null) return NotFound("World not found"); + + var player = _context.Players.Where(p => p.World.Id == wId).FirstOrDefault(p => p.Uuid == uuid); + + _context.Players.Remove(player); + + var invite = await _context.Invites.FirstOrDefaultAsync(i => i.RecipeintUUID == uuid); + + if (invite != null) _context.Invites.Remove(invite); + + _context.SaveChanges(); + + return Ok(true); + } + + [HttpDelete("{wId}")] + public async Task> LeaveWorld(int wId) + { + string cookie = Request.Headers.Cookie; + string playerUUID = cookie.Split(";")[0].Split(":")[2]; + + var world = await _context.Worlds.FirstOrDefaultAsync(w => w.Id == wId); + + if (world == null) return NotFound("World not found"); + + var player = _context.Players.Where(p => p.World.Id == wId).FirstOrDefault(p => p.Uuid == playerUUID); + + _context.Players.Remove(player); + + _context.SaveChanges(); + + return Ok(true); + } + } +} diff --git a/Minecraft-Realms-Emulator/Controllers/McoController.cs b/Minecraft-Realms-Emulator/Controllers/McoController.cs new file mode 100644 index 0000000..f03e93a --- /dev/null +++ b/Minecraft-Realms-Emulator/Controllers/McoController.cs @@ -0,0 +1,46 @@ +using Microsoft.AspNetCore.Mvc; +using Minecraft_Realms_Emulator.Attributes; +using Minecraft_Realms_Emulator.Data; +using Minecraft_Realms_Emulator.Responses; +using Newtonsoft.Json; + +namespace Minecraft_Realms_Emulator.Controllers +{ + [Route("[controller]")] + [ApiController] + [RequireMinecraftCookie] + public class McoController : ControllerBase + { + private readonly DataContext _context; + + public McoController(DataContext context) + { + _context = context; + } + + [HttpGet("available")] + public bool GetAvailable() + { + return true; + } + + [HttpGet("client/compatible")] + public string GetCompatible() + { + return Compatility.COMPATIBLE.ToString(); + } + + [HttpGet("v1/news")] + public NewsResponse GetNews() + { + var newsLink = _context.Configuration.FirstOrDefault(s => s.Key == "newsLink"); + + var news = new NewsResponse + { + NewsLink = JsonConvert.DeserializeObject(newsLink.Value), + }; + + return news; + } + } +} \ No newline at end of file diff --git a/Minecraft-Realms-Emulator/Controllers/OpsController.cs b/Minecraft-Realms-Emulator/Controllers/OpsController.cs new file mode 100644 index 0000000..72f1338 --- /dev/null +++ b/Minecraft-Realms-Emulator/Controllers/OpsController.cs @@ -0,0 +1,76 @@ +using Microsoft.AspNetCore.Mvc; +using Minecraft_Realms_Emulator.Attributes; +using Minecraft_Realms_Emulator.Data; +using Minecraft_Realms_Emulator.Responses; + +namespace Minecraft_Realms_Emulator.Controllers +{ + [Route("[controller]")] + [ApiController] + [RequireMinecraftCookie] + public class OpsController : ControllerBase + { + private readonly DataContext _context; + + public OpsController(DataContext context) + { + _context = context; + } + + [HttpPost("{wId}/{uuid}")] + public ActionResult OpPlayer(int wId, string uuid) + { + var ops = _context.Players.Where(p => p.World.Id == wId && p.Operator == true).ToList(); + var player = _context.Players.Where(p => p.World.Id == wId).FirstOrDefault(p => p.Uuid == uuid); + + List opNames = []; + + foreach (var op in ops) + { + opNames.Add(op.Name); + } + + player.Permission = "OPERATOR"; + player.Operator = true; + + _context.SaveChanges(); + + opNames.Add(player.Name); + + var opsResponse = new OpsResponse + { + Ops = opNames + }; + + return Ok(opsResponse); + } + + [HttpDelete("{wId}/{uuid}")] + public ActionResult DeopPlayer(int wId, string uuid) + { + var ops = _context.Players.Where(p => p.World.Id == wId && p.Operator == true).ToList(); + var player = _context.Players.Where(p => p.World.Id == wId).FirstOrDefault(p => p.Uuid == uuid); + + List opNames = []; + + foreach (var op in ops) + { + opNames.Add(op.Name); + } + + player.Permission = "MEMBER"; + player.Operator = false; + + _context.SaveChanges(); + + opNames.Remove(player.Name); + + var opsResponse = new OpsResponse + { + Ops = opNames + }; + + return Ok(opsResponse); + } + } +} diff --git a/Minecraft-Realms-Emulator/Controllers/SubscriptionsController.cs b/Minecraft-Realms-Emulator/Controllers/SubscriptionsController.cs new file mode 100644 index 0000000..e29d145 --- /dev/null +++ b/Minecraft-Realms-Emulator/Controllers/SubscriptionsController.cs @@ -0,0 +1,37 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Minecraft_Realms_Emulator.Attributes; +using Minecraft_Realms_Emulator.Data; +using Minecraft_Realms_Emulator.Responses; + +namespace Minecraft_Realms_Emulator.Controllers +{ + [Route("[controller]")] + [ApiController] + [RequireMinecraftCookie] + public class SubscriptionsController : ControllerBase + { + private readonly DataContext _context; + + public SubscriptionsController(DataContext context) + { + _context = context; + } + [HttpGet("{id}")] + public async Task> Get(int id) + { + var world = await _context.Worlds.Include(w => w.Subscription).FirstOrDefaultAsync(w => w.Id == id); + + if (world?.Subscription == null) return NotFound("Subscription not found"); + + var sub = new SubscriptionResponse + { + StartDate = ((DateTimeOffset)world.Subscription.StartDate).ToUnixTimeMilliseconds(), + DaysLeft = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days, + SubscriptionType = world.Subscription.SubscriptionType + }; + + return Ok(sub); + } + } +} diff --git a/Minecraft-Realms-Emulator/Controllers/TrialController.cs b/Minecraft-Realms-Emulator/Controllers/TrialController.cs new file mode 100644 index 0000000..b75fb56 --- /dev/null +++ b/Minecraft-Realms-Emulator/Controllers/TrialController.cs @@ -0,0 +1,24 @@ +using Microsoft.AspNetCore.Mvc; +using Minecraft_Realms_Emulator.Attributes; +using Minecraft_Realms_Emulator.Data; + +namespace Minecraft_Realms_Emulator.Controllers +{ + [Route("[controller]")] + [ApiController] + [RequireMinecraftCookie] + public class TrialController : ControllerBase + { + private readonly DataContext _context; + + public TrialController(DataContext context) + { + _context = context; + } + + [HttpGet(Name = "GetTrial")] + public bool Get() { + return bool.Parse(_context.Configuration.FirstOrDefault(x => x.Key == "trialMode").Value); + } + } +} diff --git a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs new file mode 100644 index 0000000..0e80380 --- /dev/null +++ b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs @@ -0,0 +1,279 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Minecraft_Realms_Emulator.Attributes; +using Minecraft_Realms_Emulator.Data; +using Minecraft_Realms_Emulator.Entities; +using Minecraft_Realms_Emulator.Requests; +using Minecraft_Realms_Emulator.Responses; +using Newtonsoft.Json; + +namespace Minecraft_Realms_Emulator.Controllers +{ + [Route("[controller]")] + [ApiController] + [RequireMinecraftCookie] + public class WorldsController : ControllerBase + { + private readonly DataContext _context; + + public WorldsController(DataContext context) + { + _context = context; + } + + [HttpGet] + public async Task> GetWorlds() + { + string cookie = Request.Headers.Cookie; + + string playerUUID = cookie.Split(";")[0].Split(":")[2]; + string playerName = cookie.Split(";")[1].Split("=")[1]; + + var ownedWorlds = await _context.Worlds.Where(w => w.OwnerUUID == playerUUID).Include(w => w.Subscription).ToListAsync(); + var memberWorlds = await _context.Players.Where(p => p.Uuid == playerUUID && p.Accepted).Include(p => p.World.Subscription).Select(p => p.World).ToListAsync(); + + List allWorlds = []; + + if (ownedWorlds.ToArray().Length == 0) + { + var world = new World + { + Owner = playerName, + OwnerUUID = playerUUID, + Name = null, + Motd = null, + State = "UNINITIALIZED", + WorldType = "NORMAL", + MaxPlayers = 10, + MinigameId = null, + MinigameName = null, + MinigameImage = null, + ActiveSlot = 1, + Member = false + }; + + ownedWorlds.Add(world); + _context.Worlds.Add(world); + + _context.SaveChanges(); + } + + foreach (var world in ownedWorlds) + { + WorldResponse response = new() + { + Id = world.Id, + Owner = world.Owner, + OwnerUUID = world.OwnerUUID, + Name = world.Name, + Motd = world.Motd, + State = world.State, + WorldType = world.WorldType, + MaxPlayers = world.MaxPlayers, + MinigameId = world.MinigameId, + MinigameName = world.MinigameName, + MinigameImage = world.MinigameImage, + ActiveSlot = world.ActiveSlot, + Member = world.Member, + Players = world.Players + }; + + if (world.Subscription != null) + { + response.DaysLeft = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days; + response.Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0; + response.ExpiredTrial = false; + } + + allWorlds.Add(response); + } + + foreach (var world in memberWorlds) + { + WorldResponse response = new() + { + Id = world.Id, + Owner = world.Owner, + OwnerUUID = world.OwnerUUID, + Name = world.Name, + Motd = world.Motd, + State = world.State, + WorldType = world.WorldType, + MaxPlayers = world.MaxPlayers, + MinigameId = world.MinigameId, + MinigameName = world.MinigameName, + MinigameImage = world.MinigameImage, + ActiveSlot = world.ActiveSlot, + Member = world.Member, + Players = world.Players, + DaysLeft = 0, + Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0, + ExpiredTrial = false + }; + + allWorlds.Add(response); + } + + ServersResponse servers = new() + { + Servers = allWorlds + }; + + return Ok(servers); + } + + [HttpGet("{id}")] + public async Task> GetWorldById(int id) + { + var world = await _context.Worlds.Include(w => w.Players).Include(w => w.Subscription).FirstOrDefaultAsync(w => w.Id == id); + + if (world?.Subscription == null) return NotFound("World not found"); + + WorldResponse response = new() + { + Id = world.Id, + Owner = world.Owner, + OwnerUUID = world.OwnerUUID, + Name = world.Name, + Motd = world.Motd, + State = world.State, + WorldType = world.WorldType, + MaxPlayers = world.MaxPlayers, + MinigameId = world.MinigameId, + MinigameName = world.MinigameName, + MinigameImage = world.MinigameImage, + ActiveSlot = world.ActiveSlot, + Member = world.Member, + Players = world.Players, + DaysLeft = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days, + Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0, + ExpiredTrial = false + }; + + return response; + } + + [HttpPost("{id}/initialize")] + public async Task> Initialize(int id, WorldCreateRequest body) + { + var worlds = await _context.Worlds.ToListAsync(); + + var world = worlds.Find(w => w.Id == id); + + if (world == null) return NotFound("World not found"); + if (world.State != "UNINITIALIZED") return NotFound("World already initialized"); + + var subscription = new Subscription + { + StartDate = DateTime.UtcNow, + SubscriptionType = "NORMAL" + }; + + world.Name = body.Name; + world.Motd = body.Description; + world.State = "OPEN"; + world.Subscription = subscription; + + var defaultServerAddress = _context.Configuration.FirstOrDefault(x => x.Key == "defaultServerAddress"); + + var connection = new Connection + { + World = world, + Address = JsonConvert.DeserializeObject(defaultServerAddress.Value) + }; + + _context.Worlds.Update(world); + + _context.Subscriptions.Add(subscription); + _context.Connections.Add(connection); + + _context.SaveChanges(); + + return Ok(world); + } + + [HttpPost("{id}/reset")] + public ActionResult Reset(int id) + { + Console.WriteLine($"Resetting world {id}"); + return Ok(true); + } + + [HttpPut("{id}/open")] + public async Task> Open(int id) + { + var worlds = await _context.Worlds.ToListAsync(); + + var world = worlds.Find(w => w.Id == id); + + if (world == null) return NotFound("World not found"); + + world.State = "OPEN"; + + _context.SaveChanges(); + + return Ok(true); + } + + [HttpPut("{id}/close")] + public async Task> Close(int id) + { + var worlds = await _context.Worlds.ToListAsync(); + + var world = worlds.FirstOrDefault(w => w.Id == id); + + if (world == null) return NotFound("World not found"); + + world.State = "CLOSED"; + + _context.SaveChanges(); + + return Ok(true); + } + + [HttpPost("{id}")] + public async Task> UpdateWorld(int id, WorldCreateRequest body) + { + var worlds = await _context.Worlds.ToListAsync(); + + var world = worlds.Find(w => w.Id == id); + + if (world == null) return NotFound("World not found"); + + world.Name = body.Name; + world.Motd = body.Description; + + _context.SaveChanges(); + + return Ok(true); + } + + [HttpPost("{wId}/slot/{sId}")] + public bool U(int wId, int sId, object o) + { + Console.WriteLine(o); + return true; + } + + [HttpGet("{Id}/backups")] + public async Task> GetBackups(int id) + { + var backups = await _context.Backups.Where(b => b.World.Id == id).ToListAsync(); + + BackupsResponse worldBackups = new() + { + Backups = backups + }; + + return Ok(worldBackups); + } + + [HttpGet("v1/{wId}/join/pc")] + public ActionResult Join(int wId) + { + var connection = _context.Connections.FirstOrDefault(x => x.World.Id == wId); + + return Ok(connection); + } + } +} diff --git a/Minecraft-Realms-Emulator/Data/DataContext.cs b/Minecraft-Realms-Emulator/Data/DataContext.cs new file mode 100644 index 0000000..e2562b8 --- /dev/null +++ b/Minecraft-Realms-Emulator/Data/DataContext.cs @@ -0,0 +1,16 @@ +using Microsoft.EntityFrameworkCore; +using Minecraft_Realms_Emulator.Entities; + +namespace Minecraft_Realms_Emulator.Data +{ + public class DataContext(DbContextOptions options) : DbContext(options) + { + public DbSet Worlds { get; set; } + public DbSet Subscriptions { get; set; } + public DbSet Connections { get; set; } + public DbSet Backups { get; set; } + public DbSet Invites { get; set; } + public DbSet Players { get; set; } + public DbSet Configuration { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Entities/Backup.cs b/Minecraft-Realms-Emulator/Entities/Backup.cs new file mode 100644 index 0000000..fc2eb8d --- /dev/null +++ b/Minecraft-Realms-Emulator/Entities/Backup.cs @@ -0,0 +1,14 @@ +using System.Text.Json; + +namespace Minecraft_Realms_Emulator.Entities +{ + public class Backup + { + public int Id { get; set; } + public World World { get; set; } + public string BackupId { get; set; } + public long LastModifiedDate { get; set; } + public int Size { get; set; } + public JsonDocument Metadata { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Entities/Configuration.cs b/Minecraft-Realms-Emulator/Entities/Configuration.cs new file mode 100644 index 0000000..54c3aae --- /dev/null +++ b/Minecraft-Realms-Emulator/Entities/Configuration.cs @@ -0,0 +1,13 @@ +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Minecraft_Realms_Emulator.Entities +{ + [PrimaryKey(nameof(Key))] + public class Configuration + { + public string Key { get; set; } = string.Empty; + [Column(TypeName = "jsonb")] + public dynamic Value { get; set; } = string.Empty; + } +} diff --git a/Minecraft-Realms-Emulator/Entities/Connection.cs b/Minecraft-Realms-Emulator/Entities/Connection.cs new file mode 100644 index 0000000..2cdce45 --- /dev/null +++ b/Minecraft-Realms-Emulator/Entities/Connection.cs @@ -0,0 +1,10 @@ +namespace Minecraft_Realms_Emulator.Entities +{ + public class Connection + { + public int Id { get; set; } + public World World { get; set; } + public string Address { get; set; } = string.Empty; + public bool PendingUpdate { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Entities/Invite.cs b/Minecraft-Realms-Emulator/Entities/Invite.cs new file mode 100644 index 0000000..af4223a --- /dev/null +++ b/Minecraft-Realms-Emulator/Entities/Invite.cs @@ -0,0 +1,11 @@ +namespace Minecraft_Realms_Emulator.Entities +{ + public class Invite + { + public int Id { get; set; } + public string InvitationId { get; set; }= string.Empty; + public string RecipeintUUID { get; set; } = string.Empty; + public World World { get; set; } + public DateTime Date { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Entities/Player.cs b/Minecraft-Realms-Emulator/Entities/Player.cs new file mode 100644 index 0000000..af84435 --- /dev/null +++ b/Minecraft-Realms-Emulator/Entities/Player.cs @@ -0,0 +1,14 @@ +namespace Minecraft_Realms_Emulator.Entities +{ + public class Player + { + public int Id { get; set; } + public string Name { get; set; } = string.Empty; + public string Uuid { get; set; } = string.Empty; + public bool Operator { get; set; } + public bool Accepted { get; set; } + public bool Online { get; set; } + public string Permission { get; set; } = "MEMBER"; + public World World { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Entities/Slot.cs b/Minecraft-Realms-Emulator/Entities/Slot.cs new file mode 100644 index 0000000..e08d892 --- /dev/null +++ b/Minecraft-Realms-Emulator/Entities/Slot.cs @@ -0,0 +1,8 @@ +namespace Minecraft_Realms_Emulator.Entities +{ + public class Slot + { + public int SlotId { get; set; } + public string Options { get; set; } = "{}"; + } +} diff --git a/Minecraft-Realms-Emulator/Entities/Subscription.cs b/Minecraft-Realms-Emulator/Entities/Subscription.cs new file mode 100644 index 0000000..dfdc03f --- /dev/null +++ b/Minecraft-Realms-Emulator/Entities/Subscription.cs @@ -0,0 +1,11 @@ +namespace Minecraft_Realms_Emulator.Entities +{ + public class Subscription + { + public int Id { get; set; } + public int WorldId { get; set; } + public World World { get; set; } = null!; + public DateTime StartDate { get; set; } = DateTime.Now; + public string SubscriptionType { get; set; } = "NORMAL"; + } +} \ No newline at end of file diff --git a/Minecraft-Realms-Emulator/Entities/World.cs b/Minecraft-Realms-Emulator/Entities/World.cs new file mode 100644 index 0000000..cbee5ca --- /dev/null +++ b/Minecraft-Realms-Emulator/Entities/World.cs @@ -0,0 +1,24 @@ +using System.Text.Json; + +namespace Minecraft_Realms_Emulator.Entities +{ + public class World + { + public int Id { get; set; } + public Subscription? Subscription { get; set; } + public string? Owner { get; set; } + public string? OwnerUUID { get; set; } + public string? Name { get; set; } + public string? Motd { get; set; } + public string State { get; set; } = "OPEN"; + public string WorldType { get; set; } = "NORMAL"; + public List Players { get; set; } = []; + public int MaxPlayers { get; set; } = 10; + public string? MinigameName { get; set; } + public int? MinigameId { get; set; } + public string? MinigameImage { get; set; } + public int ActiveSlot { get; set; } = 1; + public JsonDocument[] Slots { get; set; } = []; + public bool Member { get; set; } = false; + } +} \ No newline at end of file diff --git a/Minecraft-Realms-Emulator/Helpers/Database.cs b/Minecraft-Realms-Emulator/Helpers/Database.cs new file mode 100644 index 0000000..c59f9ba --- /dev/null +++ b/Minecraft-Realms-Emulator/Helpers/Database.cs @@ -0,0 +1,52 @@ +using Microsoft.EntityFrameworkCore; +using Minecraft_Realms_Emulator.Data; +using Minecraft_Realms_Emulator.Entities; + +namespace Minecraft_Realms_Emulator.Helpers +{ + public class Database + { + public static void Initialize(WebApplication app) + { + var scope = app.Services.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + + db.Database.Migrate(); + + if (db.Configuration.FirstOrDefault(s => s.Key == "newsLink") == null) + { + var newsLink = new Configuration + { + Key = "newsLink", + Value = "\"https://github.com/CyberL1/Minecraft-Realms-Emulator\"" + }; + + db.Configuration.Add(newsLink); + } + + if (db.Configuration.FirstOrDefault(s => s.Key == "defaultServerAddress") == null) + { + var defaultServerAddress = new Configuration + { + Key = "defaultServerAddress", + Value = "\"127.0.0.1\"" + }; + + db.Configuration.Add(defaultServerAddress); + } + + if (db.Configuration.FirstOrDefault(x => x.Key == "trialMode") == null) + { + var trialMode = new Configuration + { + Key = "trialMode", + Value = true + }; + + db.Configuration.Add(trialMode); + } + + db.SaveChanges(); + } + } +} diff --git a/Minecraft-Realms-Emulator/Middlewares/MinecraftCookieMiddleware.cs b/Minecraft-Realms-Emulator/Middlewares/MinecraftCookieMiddleware.cs new file mode 100644 index 0000000..1f34861 --- /dev/null +++ b/Minecraft-Realms-Emulator/Middlewares/MinecraftCookieMiddleware.cs @@ -0,0 +1,34 @@ +using Minecraft_Realms_Emulator.Attributes; +using System.Text; + +namespace Minecraft_Realms_Emulator.Middlewares +{ + public class MinecraftCookieMiddleware(RequestDelegate next) + { + private readonly RequestDelegate _next = next; + + public async Task Invoke(HttpContext httpContext) + { + var endpoint = httpContext.GetEndpoint(); + var attribute = endpoint?.Metadata.GetMetadata(); + + if (attribute == null) + { + await _next(httpContext); + return; + } + + if (httpContext.Request.Headers.Cookie.ToString() == "") + { + httpContext.Response.StatusCode = 401; + await httpContext.Response.Body.WriteAsync(Encoding.UTF8.GetBytes("Authorization required")); + return; + } + + string cookie = httpContext.Request.Headers.Cookie.ToString(); + if (!attribute.HasMinecraftCookie(cookie)) throw new UnauthorizedAccessException("Malformed cookie header"); + + await _next(httpContext); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240202175209_Initial.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240202175209_Initial.Designer.cs new file mode 100644 index 0000000..734c86b --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240202175209_Initial.Designer.cs @@ -0,0 +1,101 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Minecraft_Realms_Emulator.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20240202175209_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActiveSlot") + .HasColumnType("integer"); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("Expired") + .HasColumnType("boolean"); + + b.Property("ExpiredTrial") + .HasColumnType("boolean"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("Member") + .HasColumnType("boolean"); + + b.Property("MinigameId") + .HasColumnType("integer"); + + b.Property("MinigameImage") + .HasColumnType("text"); + + b.Property("MinigameName") + .HasColumnType("text"); + + b.Property("Motd") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Owner") + .HasColumnType("text"); + + b.Property("OwnerUUID") + .HasColumnType("text"); + + b.Property("Players") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("RemoteSubscriptionId") + .HasColumnType("text"); + + b.Property("Slots") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("State") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240202175209_Initial.cs b/Minecraft-Realms-Emulator/Migrations/20240202175209_Initial.cs new file mode 100644 index 0000000..c293d3b --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240202175209_Initial.cs @@ -0,0 +1,52 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Worlds", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + RemoteSubscriptionId = table.Column(type: "text", nullable: true), + Owner = table.Column(type: "text", nullable: true), + OwnerUUID = table.Column(type: "text", nullable: true), + Name = table.Column(type: "text", nullable: true), + Motd = table.Column(type: "text", nullable: true), + State = table.Column(type: "text", nullable: false), + DaysLeft = table.Column(type: "integer", nullable: false), + Expired = table.Column(type: "boolean", nullable: false), + ExpiredTrial = table.Column(type: "boolean", nullable: false), + WorldType = table.Column(type: "text", nullable: false), + Players = table.Column(type: "text[]", nullable: false), + MaxPlayers = table.Column(type: "integer", nullable: false), + MinigameName = table.Column(type: "text", nullable: true), + MinigameId = table.Column(type: "integer", nullable: true), + MinigameImage = table.Column(type: "text", nullable: true), + ActiveSlot = table.Column(type: "integer", nullable: false), + Slots = table.Column(type: "text[]", nullable: false), + Member = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Worlds", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Worlds"); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240203132410_Subscriptions.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240203132410_Subscriptions.Designer.cs new file mode 100644 index 0000000..4a03f81 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240203132410_Subscriptions.Designer.cs @@ -0,0 +1,130 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Minecraft_Realms_Emulator.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20240203132410_Subscriptions")] + partial class Subscriptions + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("RemoteId") + .IsRequired() + .HasColumnType("text"); + + b.Property("StartDate") + .IsRequired() + .HasColumnType("text"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActiveSlot") + .HasColumnType("integer"); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("Expired") + .HasColumnType("boolean"); + + b.Property("ExpiredTrial") + .HasColumnType("boolean"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("Member") + .HasColumnType("boolean"); + + b.Property("MinigameId") + .HasColumnType("integer"); + + b.Property("MinigameImage") + .HasColumnType("text"); + + b.Property("MinigameName") + .HasColumnType("text"); + + b.Property("Motd") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Owner") + .HasColumnType("text"); + + b.Property("OwnerUUID") + .HasColumnType("text"); + + b.Property("Players") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("RemoteSubscriptionId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Slots") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("State") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240203132410_Subscriptions.cs b/Minecraft-Realms-Emulator/Migrations/20240203132410_Subscriptions.cs new file mode 100644 index 0000000..081d76e --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240203132410_Subscriptions.cs @@ -0,0 +1,56 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Subscriptions : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "RemoteSubscriptionId", + table: "Worlds", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.CreateTable( + name: "Subscriptions", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + RemoteId = table.Column(type: "text", nullable: false), + StartDate = table.Column(type: "text", nullable: false), + DaysLeft = table.Column(type: "integer", nullable: false), + SubscriptionType = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Subscriptions", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Subscriptions"); + + migrationBuilder.AlterColumn( + name: "RemoteSubscriptionId", + table: "Worlds", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240211135246_Slots.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240211135246_Slots.Designer.cs new file mode 100644 index 0000000..b99784f --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240211135246_Slots.Designer.cs @@ -0,0 +1,131 @@ +// +using System; +using System.Text.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Minecraft_Realms_Emulator.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20240211135246_Slots")] + partial class Slots + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("RemoteId") + .IsRequired() + .HasColumnType("text"); + + b.Property("StartDate") + .IsRequired() + .HasColumnType("text"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActiveSlot") + .HasColumnType("integer"); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("Expired") + .HasColumnType("boolean"); + + b.Property("ExpiredTrial") + .HasColumnType("boolean"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("Member") + .HasColumnType("boolean"); + + b.Property("MinigameId") + .HasColumnType("integer"); + + b.Property("MinigameImage") + .HasColumnType("text"); + + b.Property("MinigameName") + .HasColumnType("text"); + + b.Property("Motd") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Owner") + .HasColumnType("text"); + + b.Property("OwnerUUID") + .HasColumnType("text"); + + b.Property("Players") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("RemoteSubscriptionId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Slots") + .IsRequired() + .HasColumnType("jsonb[]"); + + b.Property("State") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240211135246_Slots.cs b/Minecraft-Realms-Emulator/Migrations/20240211135246_Slots.cs new file mode 100644 index 0000000..a040aef --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240211135246_Slots.cs @@ -0,0 +1,23 @@ +using System.Text.Json; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Slots : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql("ALTER TABLE \"Worlds\" ALTER COLUMN \"Slots\" TYPE jsonb[] USING \"Slots\"::jsonb[]"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql("ALTER TABLE \"Worlds\" ALTER COLUMN \"Slots\" TYPE text[] USING \"Slots\"::text[]"); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240213104200_Connections.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240213104200_Connections.Designer.cs new file mode 100644 index 0000000..ff2e758 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240213104200_Connections.Designer.cs @@ -0,0 +1,159 @@ +// +using System; +using System.Text.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Minecraft_Realms_Emulator.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20240213104200_Connections")] + partial class Connections + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("RemoteId") + .IsRequired() + .HasColumnType("text"); + + b.Property("StartDate") + .IsRequired() + .HasColumnType("text"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActiveSlot") + .HasColumnType("integer"); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("Expired") + .HasColumnType("boolean"); + + b.Property("ExpiredTrial") + .HasColumnType("boolean"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("Member") + .HasColumnType("boolean"); + + b.Property("MinigameId") + .HasColumnType("integer"); + + b.Property("MinigameImage") + .HasColumnType("text"); + + b.Property("MinigameName") + .HasColumnType("text"); + + b.Property("Motd") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Owner") + .HasColumnType("text"); + + b.Property("OwnerUUID") + .HasColumnType("text"); + + b.Property("Players") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("RemoteSubscriptionId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Slots") + .IsRequired() + .HasColumnType("jsonb[]"); + + b.Property("State") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240213104200_Connections.cs b/Minecraft-Realms-Emulator/Migrations/20240213104200_Connections.cs new file mode 100644 index 0000000..bad3f0f --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240213104200_Connections.cs @@ -0,0 +1,44 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Connections : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Connections", + columns: table => new + { + WorldId = table.Column(type: "integer", nullable: false), + Address = table.Column(type: "text", nullable: false), + PendingUpdate = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.ForeignKey( + name: "FK_Connections_Worlds_WorldId", + column: x => x.WorldId, + principalTable: "Worlds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Connections_WorldId", + table: "Connections", + column: "WorldId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Connections"); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240213121346_Subscription_v2.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240213121346_Subscription_v2.Designer.cs new file mode 100644 index 0000000..0a8858b --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240213121346_Subscription_v2.Designer.cs @@ -0,0 +1,168 @@ +// +using System; +using System.Text.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Minecraft_Realms_Emulator.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20240213121346_Subscription_v2")] + partial class Subscription_v2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StartDate") + .IsRequired() + .HasColumnType("text"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActiveSlot") + .HasColumnType("integer"); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("Expired") + .HasColumnType("boolean"); + + b.Property("ExpiredTrial") + .HasColumnType("boolean"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("Member") + .HasColumnType("boolean"); + + b.Property("MinigameId") + .HasColumnType("integer"); + + b.Property("MinigameImage") + .HasColumnType("text"); + + b.Property("MinigameName") + .HasColumnType("text"); + + b.Property("Motd") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Owner") + .HasColumnType("text"); + + b.Property("OwnerUUID") + .HasColumnType("text"); + + b.Property("Players") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("RemoteSubscriptionId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Slots") + .IsRequired() + .HasColumnType("jsonb[]"); + + b.Property("State") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240213121346_Subscription_v2.cs b/Minecraft-Realms-Emulator/Migrations/20240213121346_Subscription_v2.cs new file mode 100644 index 0000000..7a4781a --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240213121346_Subscription_v2.cs @@ -0,0 +1,60 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Subscription_v2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "RemoteId", + table: "Subscriptions"); + + migrationBuilder.RenameColumn( + name: "DaysLeft", + table: "Subscriptions", + newName: "WorldId"); + + migrationBuilder.CreateIndex( + name: "IX_Subscriptions_WorldId", + table: "Subscriptions", + column: "WorldId"); + + migrationBuilder.AddForeignKey( + name: "FK_Subscriptions_Worlds_WorldId", + table: "Subscriptions", + column: "WorldId", + principalTable: "Worlds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Subscriptions_Worlds_WorldId", + table: "Subscriptions"); + + migrationBuilder.DropIndex( + name: "IX_Subscriptions_WorldId", + table: "Subscriptions"); + + migrationBuilder.RenameColumn( + name: "WorldId", + table: "Subscriptions", + newName: "DaysLeft"); + + migrationBuilder.AddColumn( + name: "RemoteId", + table: "Subscriptions", + type: "text", + nullable: false, + defaultValue: ""); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240214154708_Backups.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240214154708_Backups.Designer.cs new file mode 100644 index 0000000..6881576 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240214154708_Backups.Designer.cs @@ -0,0 +1,211 @@ +// +using System; +using System.Text.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Minecraft_Realms_Emulator.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20240214154708_Backups")] + partial class Backups + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BackupId") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastModifiedDate") + .HasColumnType("bigint"); + + b.Property("Metadata") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Size") + .HasColumnType("integer"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Backups"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StartDate") + .IsRequired() + .HasColumnType("text"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActiveSlot") + .HasColumnType("integer"); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("Expired") + .HasColumnType("boolean"); + + b.Property("ExpiredTrial") + .HasColumnType("boolean"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("Member") + .HasColumnType("boolean"); + + b.Property("MinigameId") + .HasColumnType("integer"); + + b.Property("MinigameImage") + .HasColumnType("text"); + + b.Property("MinigameName") + .HasColumnType("text"); + + b.Property("Motd") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Owner") + .HasColumnType("text"); + + b.Property("OwnerUUID") + .HasColumnType("text"); + + b.Property("Players") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("RemoteSubscriptionId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Slots") + .IsRequired() + .HasColumnType("jsonb[]"); + + b.Property("State") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240214154708_Backups.cs b/Minecraft-Realms-Emulator/Migrations/20240214154708_Backups.cs new file mode 100644 index 0000000..34e563a --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240214154708_Backups.cs @@ -0,0 +1,51 @@ +using System.Text.Json; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Backups : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Backups", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + WorldId = table.Column(type: "integer", nullable: false), + BackupId = table.Column(type: "text", nullable: false), + LastModifiedDate = table.Column(type: "bigint", nullable: false), + Size = table.Column(type: "integer", nullable: false), + Metadata = table.Column(type: "jsonb", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Backups", x => x.Id); + table.ForeignKey( + name: "FK_Backups_Worlds_WorldId", + column: x => x.WorldId, + principalTable: "Worlds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Backups_WorldId", + table: "Backups", + column: "WorldId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Backups"); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240218160304_Connections_Id.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240218160304_Connections_Id.Designer.cs new file mode 100644 index 0000000..6c670f8 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240218160304_Connections_Id.Designer.cs @@ -0,0 +1,219 @@ +// +using System; +using System.Text.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Minecraft_Realms_Emulator.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20240218160304_Connections_Id")] + partial class Connections_Id + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BackupId") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastModifiedDate") + .HasColumnType("bigint"); + + b.Property("Metadata") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Size") + .HasColumnType("integer"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Backups"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StartDate") + .IsRequired() + .HasColumnType("text"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActiveSlot") + .HasColumnType("integer"); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("Expired") + .HasColumnType("boolean"); + + b.Property("ExpiredTrial") + .HasColumnType("boolean"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("Member") + .HasColumnType("boolean"); + + b.Property("MinigameId") + .HasColumnType("integer"); + + b.Property("MinigameImage") + .HasColumnType("text"); + + b.Property("MinigameName") + .HasColumnType("text"); + + b.Property("Motd") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Owner") + .HasColumnType("text"); + + b.Property("OwnerUUID") + .HasColumnType("text"); + + b.Property("Players") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("RemoteSubscriptionId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Slots") + .IsRequired() + .HasColumnType("jsonb[]"); + + b.Property("State") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240218160304_Connections_Id.cs b/Minecraft-Realms-Emulator/Migrations/20240218160304_Connections_Id.cs new file mode 100644 index 0000000..f223cf3 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240218160304_Connections_Id.cs @@ -0,0 +1,40 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Connections_Id : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Id", + table: "Connections", + type: "integer", + nullable: false, + defaultValue: 0) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.AddPrimaryKey( + name: "PK_Connections", + table: "Connections", + column: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey( + name: "PK_Connections", + table: "Connections"); + + migrationBuilder.DropColumn( + name: "Id", + table: "Connections"); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240220092334_Invites.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240220092334_Invites.Designer.cs new file mode 100644 index 0000000..5ae8fd5 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240220092334_Invites.Designer.cs @@ -0,0 +1,259 @@ +// +using System; +using System.Text.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Minecraft_Realms_Emulator.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20240220092334_Invites")] + partial class Invites + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BackupId") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastModifiedDate") + .HasColumnType("bigint"); + + b.Property("Metadata") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Size") + .HasColumnType("integer"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Backups"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("InvitationId") + .IsRequired() + .HasColumnType("text"); + + b.Property("RecipeintUUID") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Invites"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StartDate") + .IsRequired() + .HasColumnType("text"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActiveSlot") + .HasColumnType("integer"); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("Expired") + .HasColumnType("boolean"); + + b.Property("ExpiredTrial") + .HasColumnType("boolean"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("Member") + .HasColumnType("boolean"); + + b.Property("MinigameId") + .HasColumnType("integer"); + + b.Property("MinigameImage") + .HasColumnType("text"); + + b.Property("MinigameName") + .HasColumnType("text"); + + b.Property("Motd") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Owner") + .HasColumnType("text"); + + b.Property("OwnerUUID") + .HasColumnType("text"); + + b.Property("Players") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("RemoteSubscriptionId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Slots") + .IsRequired() + .HasColumnType("jsonb[]"); + + b.Property("State") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240220092334_Invites.cs b/Minecraft-Realms-Emulator/Migrations/20240220092334_Invites.cs new file mode 100644 index 0000000..753d699 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240220092334_Invites.cs @@ -0,0 +1,50 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Invites : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Invites", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + InvitationId = table.Column(type: "text", nullable: false), + RecipeintUUID = table.Column(type: "text", nullable: false), + WorldId = table.Column(type: "integer", nullable: false), + Date = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Invites", x => x.Id); + table.ForeignKey( + name: "FK_Invites_Worlds_WorldId", + column: x => x.WorldId, + principalTable: "Worlds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Invites_WorldId", + table: "Invites", + column: "WorldId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Invites"); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240221131108_Players.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240221131108_Players.Designer.cs new file mode 100644 index 0000000..03a631f --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240221131108_Players.Designer.cs @@ -0,0 +1,310 @@ +// +using System; +using System.Text.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Minecraft_Realms_Emulator.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20240221131108_Players")] + partial class Players + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BackupId") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastModifiedDate") + .HasColumnType("bigint"); + + b.Property("Metadata") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Size") + .HasColumnType("integer"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Backups"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("InvitationId") + .IsRequired() + .HasColumnType("text"); + + b.Property("RecipeintUUID") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Invites"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Accepted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Online") + .HasColumnType("boolean"); + + b.Property("Operator") + .HasColumnType("boolean"); + + b.Property("Permission") + .IsRequired() + .HasColumnType("text"); + + b.Property("Uuid") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Players"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StartDate") + .IsRequired() + .HasColumnType("text"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActiveSlot") + .HasColumnType("integer"); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("Expired") + .HasColumnType("boolean"); + + b.Property("ExpiredTrial") + .HasColumnType("boolean"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("Member") + .HasColumnType("boolean"); + + b.Property("MinigameId") + .HasColumnType("integer"); + + b.Property("MinigameImage") + .HasColumnType("text"); + + b.Property("MinigameName") + .HasColumnType("text"); + + b.Property("Motd") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Owner") + .HasColumnType("text"); + + b.Property("OwnerUUID") + .HasColumnType("text"); + + b.Property("RemoteSubscriptionId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Slots") + .IsRequired() + .HasColumnType("jsonb[]"); + + b.Property("State") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany("Players") + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Navigation("Players"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240221131108_Players.cs b/Minecraft-Realms-Emulator/Migrations/20240221131108_Players.cs new file mode 100644 index 0000000..2b091ae --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240221131108_Players.cs @@ -0,0 +1,63 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Players : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Players", + table: "Worlds"); + + migrationBuilder.CreateTable( + name: "Players", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + Uuid = table.Column(type: "text", nullable: false), + Operator = table.Column(type: "boolean", nullable: false), + Accepted = table.Column(type: "boolean", nullable: false), + Online = table.Column(type: "boolean", nullable: false), + Permission = table.Column(type: "text", nullable: false), + WorldId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Players", x => x.Id); + table.ForeignKey( + name: "FK_Players_Worlds_WorldId", + column: x => x.WorldId, + principalTable: "Worlds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Players_WorldId", + table: "Players", + column: "WorldId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Players"); + + migrationBuilder.AddColumn( + name: "Players", + table: "Worlds", + type: "text[]", + nullable: false, + defaultValue: new string[0]); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240301214442_Configuration.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240301214442_Configuration.Designer.cs new file mode 100644 index 0000000..40c432d --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240301214442_Configuration.Designer.cs @@ -0,0 +1,324 @@ +// +using System; +using System.Text.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Minecraft_Realms_Emulator.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20240301214442_Configuration")] + partial class Configuration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BackupId") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastModifiedDate") + .HasColumnType("bigint"); + + b.Property("Metadata") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Size") + .HasColumnType("integer"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Backups"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Configuration", b => + { + b.Property("Key") + .HasColumnType("text"); + + b.Property("Value") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Key"); + + b.ToTable("Configuration"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("InvitationId") + .IsRequired() + .HasColumnType("text"); + + b.Property("RecipeintUUID") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Invites"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Accepted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Online") + .HasColumnType("boolean"); + + b.Property("Operator") + .HasColumnType("boolean"); + + b.Property("Permission") + .IsRequired() + .HasColumnType("text"); + + b.Property("Uuid") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Players"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StartDate") + .IsRequired() + .HasColumnType("text"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActiveSlot") + .HasColumnType("integer"); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("Expired") + .HasColumnType("boolean"); + + b.Property("ExpiredTrial") + .HasColumnType("boolean"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("Member") + .HasColumnType("boolean"); + + b.Property("MinigameId") + .HasColumnType("integer"); + + b.Property("MinigameImage") + .HasColumnType("text"); + + b.Property("MinigameName") + .HasColumnType("text"); + + b.Property("Motd") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Owner") + .HasColumnType("text"); + + b.Property("OwnerUUID") + .HasColumnType("text"); + + b.Property("RemoteSubscriptionId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Slots") + .IsRequired() + .HasColumnType("jsonb[]"); + + b.Property("State") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany("Players") + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Navigation("Players"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240301214442_Configuration.cs b/Minecraft-Realms-Emulator/Migrations/20240301214442_Configuration.cs new file mode 100644 index 0000000..6817710 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240301214442_Configuration.cs @@ -0,0 +1,33 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Configuration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Configuration", + columns: table => new + { + Key = table.Column(type: "text", nullable: false), + Value = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Configuration", x => x.Key); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Configuration"); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240315231009_Subscriptions_StartDate_Readable_Field.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240315231009_Subscriptions_StartDate_Readable_Field.Designer.cs new file mode 100644 index 0000000..ec79e39 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240315231009_Subscriptions_StartDate_Readable_Field.Designer.cs @@ -0,0 +1,323 @@ +// +using System; +using System.Text.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Minecraft_Realms_Emulator.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20240315231009_Subscriptions_StartDate_Readable_Field")] + partial class Subscriptions_StartDate_Readable_Field + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BackupId") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastModifiedDate") + .HasColumnType("bigint"); + + b.Property("Metadata") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Size") + .HasColumnType("integer"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Backups"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Configuration", b => + { + b.Property("Key") + .HasColumnType("text"); + + b.Property("Value") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Key"); + + b.ToTable("Configuration"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("InvitationId") + .IsRequired() + .HasColumnType("text"); + + b.Property("RecipeintUUID") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Invites"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Accepted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Online") + .HasColumnType("boolean"); + + b.Property("Operator") + .HasColumnType("boolean"); + + b.Property("Permission") + .IsRequired() + .HasColumnType("text"); + + b.Property("Uuid") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Players"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StartDate") + .HasColumnType("timestamp with time zone"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActiveSlot") + .HasColumnType("integer"); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("Expired") + .HasColumnType("boolean"); + + b.Property("ExpiredTrial") + .HasColumnType("boolean"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("Member") + .HasColumnType("boolean"); + + b.Property("MinigameId") + .HasColumnType("integer"); + + b.Property("MinigameImage") + .HasColumnType("text"); + + b.Property("MinigameName") + .HasColumnType("text"); + + b.Property("Motd") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Owner") + .HasColumnType("text"); + + b.Property("OwnerUUID") + .HasColumnType("text"); + + b.Property("RemoteSubscriptionId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Slots") + .IsRequired() + .HasColumnType("jsonb[]"); + + b.Property("State") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany("Players") + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Navigation("Players"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240315231009_Subscriptions_StartDate_Readable_Field.cs b/Minecraft-Realms-Emulator/Migrations/20240315231009_Subscriptions_StartDate_Readable_Field.cs new file mode 100644 index 0000000..cb8070a --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240315231009_Subscriptions_StartDate_Readable_Field.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Subscriptions_StartDate_Readable_Field : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql("ALTER TABLE \"Subscriptions\" ALTER COLUMN \"StartDate\" TYPE timestamptz USING \"StartDate\"::timestamptz"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql("ALTER TABLE \"Subscriptions\" ALTER COLUMN \"StartDate\" TYPE text USING \"StartDate\"::text"); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240317120329_Worlds_Subscription_field.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240317120329_Worlds_Subscription_field.Designer.cs new file mode 100644 index 0000000..1ec7ffa --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240317120329_Worlds_Subscription_field.Designer.cs @@ -0,0 +1,313 @@ +// +using System; +using System.Text.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Minecraft_Realms_Emulator.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20240317120329_Worlds_Subscription_field")] + partial class Worlds_Subscription_field + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BackupId") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastModifiedDate") + .HasColumnType("bigint"); + + b.Property("Metadata") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Size") + .HasColumnType("integer"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Backups"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Configuration", b => + { + b.Property("Key") + .HasColumnType("text"); + + b.Property("Value") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Key"); + + b.ToTable("Configuration"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("InvitationId") + .IsRequired() + .HasColumnType("text"); + + b.Property("RecipeintUUID") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Invites"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Accepted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Online") + .HasColumnType("boolean"); + + b.Property("Operator") + .HasColumnType("boolean"); + + b.Property("Permission") + .IsRequired() + .HasColumnType("text"); + + b.Property("Uuid") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Players"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StartDate") + .HasColumnType("timestamp with time zone"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId") + .IsUnique(); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActiveSlot") + .HasColumnType("integer"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("Member") + .HasColumnType("boolean"); + + b.Property("MinigameId") + .HasColumnType("integer"); + + b.Property("MinigameImage") + .HasColumnType("text"); + + b.Property("MinigameName") + .HasColumnType("text"); + + b.Property("Motd") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Owner") + .HasColumnType("text"); + + b.Property("OwnerUUID") + .HasColumnType("text"); + + b.Property("Slots") + .IsRequired() + .HasColumnType("jsonb[]"); + + b.Property("State") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany("Players") + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithOne("Subscription") + .HasForeignKey("Minecraft_Realms_Emulator.Entities.Subscription", "WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Navigation("Players"); + + b.Navigation("Subscription"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240317120329_Worlds_Subscription_field.cs b/Minecraft-Realms-Emulator/Migrations/20240317120329_Worlds_Subscription_field.cs new file mode 100644 index 0000000..6813e98 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240317120329_Worlds_Subscription_field.cs @@ -0,0 +1,81 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Worlds_Subscription_field : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_Subscriptions_WorldId", + table: "Subscriptions"); + + migrationBuilder.DropColumn( + name: "DaysLeft", + table: "Worlds"); + + migrationBuilder.DropColumn( + name: "Expired", + table: "Worlds"); + + migrationBuilder.DropColumn( + name: "ExpiredTrial", + table: "Worlds"); + + migrationBuilder.DropColumn( + name: "RemoteSubscriptionId", + table: "Worlds"); + + migrationBuilder.CreateIndex( + name: "IX_Subscriptions_WorldId", + table: "Subscriptions", + column: "WorldId", + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_Subscriptions_WorldId", + table: "Subscriptions"); + + migrationBuilder.AddColumn( + name: "DaysLeft", + table: "Worlds", + type: "integer", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "Expired", + table: "Worlds", + type: "boolean", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "ExpiredTrial", + table: "Worlds", + type: "boolean", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "RemoteSubscriptionId", + table: "Worlds", + type: "text", + nullable: false, + defaultValue: ""); + + migrationBuilder.CreateIndex( + name: "IX_Subscriptions_WorldId", + table: "Subscriptions", + column: "WorldId"); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240414062222_Configuration_Json.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240414062222_Configuration_Json.Designer.cs new file mode 100644 index 0000000..55479b4 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240414062222_Configuration_Json.Designer.cs @@ -0,0 +1,313 @@ +// +using System; +using System.Text.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Minecraft_Realms_Emulator.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20240414062222_Configuration_Json")] + partial class Configuration_Json + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BackupId") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastModifiedDate") + .HasColumnType("bigint"); + + b.Property("Metadata") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Size") + .HasColumnType("integer"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Backups"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Configuration", b => + { + b.Property("Key") + .HasColumnType("text"); + + b.Property("Value") + .IsRequired() + .HasColumnType("jsonb"); + + b.HasKey("Key"); + + b.ToTable("Configuration"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("InvitationId") + .IsRequired() + .HasColumnType("text"); + + b.Property("RecipeintUUID") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Invites"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Accepted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Online") + .HasColumnType("boolean"); + + b.Property("Operator") + .HasColumnType("boolean"); + + b.Property("Permission") + .IsRequired() + .HasColumnType("text"); + + b.Property("Uuid") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Players"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StartDate") + .HasColumnType("timestamp with time zone"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId") + .IsUnique(); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActiveSlot") + .HasColumnType("integer"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("Member") + .HasColumnType("boolean"); + + b.Property("MinigameId") + .HasColumnType("integer"); + + b.Property("MinigameImage") + .HasColumnType("text"); + + b.Property("MinigameName") + .HasColumnType("text"); + + b.Property("Motd") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Owner") + .HasColumnType("text"); + + b.Property("OwnerUUID") + .HasColumnType("text"); + + b.Property("Slots") + .IsRequired() + .HasColumnType("jsonb[]"); + + b.Property("State") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany("Players") + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithOne("Subscription") + .HasForeignKey("Minecraft_Realms_Emulator.Entities.Subscription", "WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Navigation("Players"); + + b.Navigation("Subscription"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240414062222_Configuration_Json.cs b/Minecraft-Realms-Emulator/Migrations/20240414062222_Configuration_Json.cs new file mode 100644 index 0000000..0e8ca69 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240414062222_Configuration_Json.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Configuration_Json : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql("ALTER TABLE \"Configuration\" ALTER COLUMN \"Value\" TYPE jsonb USING \"Value\"::jsonb"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql("ALTER TABLE \"Configuration\" ALTER COLUMN \"Value\" TYPE text USING \"Value\"::text"); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs new file mode 100644 index 0000000..12d1c8f --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs @@ -0,0 +1,310 @@ +// +using System; +using System.Text.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Minecraft_Realms_Emulator.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + [DbContext(typeof(DataContext))] + partial class DataContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BackupId") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastModifiedDate") + .HasColumnType("bigint"); + + b.Property("Metadata") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Size") + .HasColumnType("integer"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Backups"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Configuration", b => + { + b.Property("Key") + .HasColumnType("text"); + + b.Property("Value") + .IsRequired() + .HasColumnType("jsonb"); + + b.HasKey("Key"); + + b.ToTable("Configuration"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("InvitationId") + .IsRequired() + .HasColumnType("text"); + + b.Property("RecipeintUUID") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Invites"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Accepted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Online") + .HasColumnType("boolean"); + + b.Property("Operator") + .HasColumnType("boolean"); + + b.Property("Permission") + .IsRequired() + .HasColumnType("text"); + + b.Property("Uuid") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Players"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StartDate") + .HasColumnType("timestamp with time zone"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId") + .IsUnique(); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActiveSlot") + .HasColumnType("integer"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("Member") + .HasColumnType("boolean"); + + b.Property("MinigameId") + .HasColumnType("integer"); + + b.Property("MinigameImage") + .HasColumnType("text"); + + b.Property("MinigameName") + .HasColumnType("text"); + + b.Property("Motd") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Owner") + .HasColumnType("text"); + + b.Property("OwnerUUID") + .HasColumnType("text"); + + b.Property("Slots") + .IsRequired() + .HasColumnType("jsonb[]"); + + b.Property("State") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany("Players") + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithOne("Subscription") + .HasForeignKey("Minecraft_Realms_Emulator.Entities.Subscription", "WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Navigation("Players"); + + b.Navigation("Subscription"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Minecraft-Realms-Emulator.csproj b/Minecraft-Realms-Emulator/Minecraft-Realms-Emulator.csproj new file mode 100644 index 0000000..82c31c9 --- /dev/null +++ b/Minecraft-Realms-Emulator/Minecraft-Realms-Emulator.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + true + Minecraft_Realms_Emulator + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + diff --git a/Minecraft-Realms-Emulator/Minecraft-Realms-Emulator.http b/Minecraft-Realms-Emulator/Minecraft-Realms-Emulator.http new file mode 100644 index 0000000..308cded --- /dev/null +++ b/Minecraft-Realms-Emulator/Minecraft-Realms-Emulator.http @@ -0,0 +1,16 @@ +@Minecraft_Realms_Emulator_HostAddress = http://localhost:8080 + +GET {{Minecraft_Realms_Emulator_HostAddress}}/mco/available +Accept: application/json + +### + +GET {{Minecraft_Realms_Emulator_HostAddress}}/mco/client/compatible +Accept: application/json + +### + +GET {{Minecraft_Realms_Emulator_HostAddress}}/worlds +Accept: application/json + +### \ No newline at end of file diff --git a/Minecraft-Realms-Emulator/Program.cs b/Minecraft-Realms-Emulator/Program.cs new file mode 100644 index 0000000..6fec2a4 --- /dev/null +++ b/Minecraft-Realms-Emulator/Program.cs @@ -0,0 +1,48 @@ +using Microsoft.EntityFrameworkCore; +using Minecraft_Realms_Emulator.Data; +using Minecraft_Realms_Emulator.Helpers; +using Minecraft_Realms_Emulator.Middlewares; +using Npgsql; + +var builder = WebApplication.CreateBuilder(args); +DotNetEnv.Env.Load(); + +if (Environment.GetEnvironmentVariable("CONNECTION_STRING") == null) +{ + Console.WriteLine("CONNECTION_STRING environment variable missing"); + return; +} + +// Add services to the container. + +builder.Services.AddControllers().AddJsonOptions(x => x.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var dataSourceBuilder = new NpgsqlDataSourceBuilder(Environment.GetEnvironmentVariable("CONNECTION_STRING")); +dataSourceBuilder.EnableDynamicJson(); +var dataSource = dataSourceBuilder.Build(); + +builder.Services.AddDbContext(options => +{ + options.UseNpgsql(dataSource); +}); + +var app = builder.Build(); + +// Initialize database +Database.Initialize(app); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseMiddleware(); + +app.MapControllers(); + +app.Run(); diff --git a/Minecraft-Realms-Emulator/Properties/launchSettings.json b/Minecraft-Realms-Emulator/Properties/launchSettings.json new file mode 100644 index 0000000..49068ad --- /dev/null +++ b/Minecraft-Realms-Emulator/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:35751", + "sslPort": 0 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:8080", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Minecraft-Realms-Emulator/Requests/PlayerRequest.cs b/Minecraft-Realms-Emulator/Requests/PlayerRequest.cs new file mode 100644 index 0000000..20f9c1a --- /dev/null +++ b/Minecraft-Realms-Emulator/Requests/PlayerRequest.cs @@ -0,0 +1,13 @@ +namespace Minecraft_Realms_Emulator.Requests +{ + public class PlayerRequest + { + public int Id { get; set; } + public string Name { get; set; } = string.Empty; + public string Uuid { get; set; } = string.Empty; + public bool Operator { get; set; } + public bool Accepted { get; set; } + public bool Online { get; set; } + public string Permission { get; set; } = "MEMBER"; + } +} diff --git a/Minecraft-Realms-Emulator/Requests/WorldCreateRequest.cs b/Minecraft-Realms-Emulator/Requests/WorldCreateRequest.cs new file mode 100644 index 0000000..d47a274 --- /dev/null +++ b/Minecraft-Realms-Emulator/Requests/WorldCreateRequest.cs @@ -0,0 +1,8 @@ +namespace Minecraft_Realms_Emulator.Requests +{ + public class WorldCreateRequest + { + public string? Name { get; set; } + public string? Description { get; set; } + } +} \ No newline at end of file diff --git a/Minecraft-Realms-Emulator/Responses/BackupsResponse.cs b/Minecraft-Realms-Emulator/Responses/BackupsResponse.cs new file mode 100644 index 0000000..8c0742e --- /dev/null +++ b/Minecraft-Realms-Emulator/Responses/BackupsResponse.cs @@ -0,0 +1,9 @@ +using Minecraft_Realms_Emulator.Entities; + +namespace Minecraft_Realms_Emulator.Responses +{ + public class BackupsResponse + { + public List Backups { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Responses/InviteList.cs b/Minecraft-Realms-Emulator/Responses/InviteList.cs new file mode 100644 index 0000000..949a7bf --- /dev/null +++ b/Minecraft-Realms-Emulator/Responses/InviteList.cs @@ -0,0 +1,16 @@ +namespace Minecraft_Realms_Emulator.Responses +{ + public class InviteList + { + public List Invites { get; set; } + } + + public class InviteResponse + { + public string InvitationId { get; set; } = string.Empty; + public string WorldName { get; set; } = string.Empty; + public string WorldOwnerName { get; set; } = string.Empty; + public string WorldOwnerUuid { get; set; } = string.Empty; + public long Date { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Responses/MinecraftPlayerInfo.cs b/Minecraft-Realms-Emulator/Responses/MinecraftPlayerInfo.cs new file mode 100644 index 0000000..d3915fe --- /dev/null +++ b/Minecraft-Realms-Emulator/Responses/MinecraftPlayerInfo.cs @@ -0,0 +1,9 @@ +namespace Minecraft_Realms_Emulator.Responses +{ + public class MinecraftPlayerInfo + { + public string Id { get; set; } = string.Empty; + public string Name { get; set; } = string.Empty; + public object Result { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Responses/NewsResponse.cs b/Minecraft-Realms-Emulator/Responses/NewsResponse.cs new file mode 100644 index 0000000..ce8deba --- /dev/null +++ b/Minecraft-Realms-Emulator/Responses/NewsResponse.cs @@ -0,0 +1,7 @@ +namespace Minecraft_Realms_Emulator.Responses +{ + public class NewsResponse + { + public string NewsLink { get; set; } = string.Empty; + } +} diff --git a/Minecraft-Realms-Emulator/Responses/OpsResponse.cs b/Minecraft-Realms-Emulator/Responses/OpsResponse.cs new file mode 100644 index 0000000..48e5827 --- /dev/null +++ b/Minecraft-Realms-Emulator/Responses/OpsResponse.cs @@ -0,0 +1,7 @@ +namespace Minecraft_Realms_Emulator.Responses +{ + public class OpsResponse + { + public List Ops { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Responses/ServersResponse.cs b/Minecraft-Realms-Emulator/Responses/ServersResponse.cs new file mode 100644 index 0000000..01c3e96 --- /dev/null +++ b/Minecraft-Realms-Emulator/Responses/ServersResponse.cs @@ -0,0 +1,9 @@ +using Minecraft_Realms_Emulator.Entities; + +namespace Minecraft_Realms_Emulator.Responses +{ + public class ServersResponse + { + public List? Servers { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Responses/SubscriptionResponse.cs b/Minecraft-Realms-Emulator/Responses/SubscriptionResponse.cs new file mode 100644 index 0000000..59fd82f --- /dev/null +++ b/Minecraft-Realms-Emulator/Responses/SubscriptionResponse.cs @@ -0,0 +1,9 @@ +namespace Minecraft_Realms_Emulator.Responses +{ + public class SubscriptionResponse + { + public long StartDate { get; set; } + public int DaysLeft { get; set; } + public string SubscriptionType { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Responses/WorldResponse.cs b/Minecraft-Realms-Emulator/Responses/WorldResponse.cs new file mode 100644 index 0000000..233f340 --- /dev/null +++ b/Minecraft-Realms-Emulator/Responses/WorldResponse.cs @@ -0,0 +1,10 @@ +namespace Minecraft_Realms_Emulator.Entities +{ + public class WorldResponse : World + { + public string RemoteSubscriptionId { get; set; } = Guid.NewGuid().ToString(); + public int DaysLeft { get; set; } = 30; + public bool Expired { get; set; } = false; + public bool ExpiredTrial { get; set; } = false; + } +} \ No newline at end of file diff --git a/Minecraft-Realms-Emulator/appsettings.Development.json b/Minecraft-Realms-Emulator/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Minecraft-Realms-Emulator/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Minecraft-Realms-Emulator/appsettings.json b/Minecraft-Realms-Emulator/appsettings.json new file mode 100644 index 0000000..23160a4 --- /dev/null +++ b/Minecraft-Realms-Emulator/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}