1
1
mirror of https://github.com/CyberL1/MyMcRealms.git synced 2024-12-23 21:08:22 -05:00

Import from Github

This commit is contained in:
CyberL1 2024-04-20 09:20:30 +02:00
commit aa1e118775
67 changed files with 5448 additions and 0 deletions

63
.gitattributes vendored Normal file
View File

@ -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

363
.gitignore vendored Normal file
View File

@ -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

View File

@ -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

1
Minecraft-Realms-Emulator/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.env

View File

@ -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");
}
}
}

View File

@ -0,0 +1,9 @@
namespace Minecraft_Realms_Emulator
{
public enum Compatility
{
COMPATIBLE,
OTHER,
OUTDATED
}
}

View File

@ -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<Configuration> GetConfigurationAsync()
{
var configuration = _context.Configuration;
return Ok(configuration);
}
}
}

View File

@ -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<ActionResult<InviteList>> 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<InviteResponse> 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<bool> 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<bool> 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<ActionResult<World>> 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<MinecraftPlayerInfo>($"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<ActionResult<bool>> 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<ActionResult<bool>> 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);
}
}
}

View File

@ -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;
}
}
}

View File

@ -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<OpsResponse> 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<string> 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<OpsResponse> 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<string> 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);
}
}
}

View File

@ -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<ActionResult<SubscriptionResponse>> 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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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<ActionResult<ServersResponse>> 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<WorldResponse> 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<ActionResult<WorldResponse>> 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<ActionResult<World>> 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<bool> Reset(int id)
{
Console.WriteLine($"Resetting world {id}");
return Ok(true);
}
[HttpPut("{id}/open")]
public async Task<ActionResult<bool>> 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<ActionResult<bool>> 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<ActionResult<bool>> 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<ActionResult<BackupsResponse>> 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<Connection> Join(int wId)
{
var connection = _context.Connections.FirstOrDefault(x => x.World.Id == wId);
return Ok(connection);
}
}
}

View File

@ -0,0 +1,16 @@
using Microsoft.EntityFrameworkCore;
using Minecraft_Realms_Emulator.Entities;
namespace Minecraft_Realms_Emulator.Data
{
public class DataContext(DbContextOptions<DataContext> options) : DbContext(options)
{
public DbSet<World> Worlds { get; set; }
public DbSet<Subscription> Subscriptions { get; set; }
public DbSet<Connection> Connections { get; set; }
public DbSet<Backup> Backups { get; set; }
public DbSet<Invite> Invites { get; set; }
public DbSet<Player> Players { get; set; }
public DbSet<Configuration> Configuration { get; set; }
}
}

View File

@ -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; }
}
}

View File

@ -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;
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -0,0 +1,8 @@
namespace Minecraft_Realms_Emulator.Entities
{
public class Slot
{
public int SlotId { get; set; }
public string Options { get; set; } = "{}";
}
}

View File

@ -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";
}
}

View File

@ -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<Player> 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;
}
}

View File

@ -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<DataContext>();
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();
}
}
}

View File

@ -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<RequireMinecraftCookieAttribute>();
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);
}
}
}

View File

@ -0,0 +1,101 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ActiveSlot")
.HasColumnType("integer");
b.Property<int>("DaysLeft")
.HasColumnType("integer");
b.Property<bool>("Expired")
.HasColumnType("boolean");
b.Property<bool>("ExpiredTrial")
.HasColumnType("boolean");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<bool>("Member")
.HasColumnType("boolean");
b.Property<int?>("MinigameId")
.HasColumnType("integer");
b.Property<string>("MinigameImage")
.HasColumnType("text");
b.Property<string>("MinigameName")
.HasColumnType("text");
b.Property<string>("Motd")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<string[]>("Players")
.IsRequired()
.HasColumnType("text[]");
b.Property<string>("RemoteSubscriptionId")
.HasColumnType("text");
b.Property<string[]>("Slots")
.IsRequired()
.HasColumnType("text[]");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
b.Property<string>("WorldType")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Worlds");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,52 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Worlds",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
RemoteSubscriptionId = table.Column<string>(type: "text", nullable: true),
Owner = table.Column<string>(type: "text", nullable: true),
OwnerUUID = table.Column<string>(type: "text", nullable: true),
Name = table.Column<string>(type: "text", nullable: true),
Motd = table.Column<string>(type: "text", nullable: true),
State = table.Column<string>(type: "text", nullable: false),
DaysLeft = table.Column<int>(type: "integer", nullable: false),
Expired = table.Column<bool>(type: "boolean", nullable: false),
ExpiredTrial = table.Column<bool>(type: "boolean", nullable: false),
WorldType = table.Column<string>(type: "text", nullable: false),
Players = table.Column<string[]>(type: "text[]", nullable: false),
MaxPlayers = table.Column<int>(type: "integer", nullable: false),
MinigameName = table.Column<string>(type: "text", nullable: true),
MinigameId = table.Column<int>(type: "integer", nullable: true),
MinigameImage = table.Column<string>(type: "text", nullable: true),
ActiveSlot = table.Column<int>(type: "integer", nullable: false),
Slots = table.Column<string[]>(type: "text[]", nullable: false),
Member = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Worlds", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Worlds");
}
}
}

View File

@ -0,0 +1,130 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("DaysLeft")
.HasColumnType("integer");
b.Property<string>("RemoteId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StartDate")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SubscriptionType")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Subscriptions");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ActiveSlot")
.HasColumnType("integer");
b.Property<int>("DaysLeft")
.HasColumnType("integer");
b.Property<bool>("Expired")
.HasColumnType("boolean");
b.Property<bool>("ExpiredTrial")
.HasColumnType("boolean");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<bool>("Member")
.HasColumnType("boolean");
b.Property<int?>("MinigameId")
.HasColumnType("integer");
b.Property<string>("MinigameImage")
.HasColumnType("text");
b.Property<string>("MinigameName")
.HasColumnType("text");
b.Property<string>("Motd")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<string[]>("Players")
.IsRequired()
.HasColumnType("text[]");
b.Property<string>("RemoteSubscriptionId")
.IsRequired()
.HasColumnType("text");
b.Property<string[]>("Slots")
.IsRequired()
.HasColumnType("text[]");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
b.Property<string>("WorldType")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Worlds");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,56 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Subscriptions : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
RemoteId = table.Column<string>(type: "text", nullable: false),
StartDate = table.Column<string>(type: "text", nullable: false),
DaysLeft = table.Column<int>(type: "integer", nullable: false),
SubscriptionType = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Subscriptions", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Subscriptions");
migrationBuilder.AlterColumn<string>(
name: "RemoteSubscriptionId",
table: "Worlds",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
}
}
}

View File

@ -0,0 +1,131 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("DaysLeft")
.HasColumnType("integer");
b.Property<string>("RemoteId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StartDate")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SubscriptionType")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Subscriptions");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ActiveSlot")
.HasColumnType("integer");
b.Property<int>("DaysLeft")
.HasColumnType("integer");
b.Property<bool>("Expired")
.HasColumnType("boolean");
b.Property<bool>("ExpiredTrial")
.HasColumnType("boolean");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<bool>("Member")
.HasColumnType("boolean");
b.Property<int?>("MinigameId")
.HasColumnType("integer");
b.Property<string>("MinigameImage")
.HasColumnType("text");
b.Property<string>("MinigameName")
.HasColumnType("text");
b.Property<string>("Motd")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<string[]>("Players")
.IsRequired()
.HasColumnType("text[]");
b.Property<string>("RemoteSubscriptionId")
.IsRequired()
.HasColumnType("text");
b.Property<JsonDocument[]>("Slots")
.IsRequired()
.HasColumnType("jsonb[]");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
b.Property<string>("WorldType")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Worlds");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,23 @@
using System.Text.Json;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Slots : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("ALTER TABLE \"Worlds\" ALTER COLUMN \"Slots\" TYPE jsonb[] USING \"Slots\"::jsonb[]");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("ALTER TABLE \"Worlds\" ALTER COLUMN \"Slots\" TYPE text[] USING \"Slots\"::text[]");
}
}
}

View File

@ -0,0 +1,159 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("PendingUpdate")
.HasColumnType("boolean");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasIndex("WorldId");
b.ToTable("Connections");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("DaysLeft")
.HasColumnType("integer");
b.Property<string>("RemoteId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StartDate")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SubscriptionType")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Subscriptions");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ActiveSlot")
.HasColumnType("integer");
b.Property<int>("DaysLeft")
.HasColumnType("integer");
b.Property<bool>("Expired")
.HasColumnType("boolean");
b.Property<bool>("ExpiredTrial")
.HasColumnType("boolean");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<bool>("Member")
.HasColumnType("boolean");
b.Property<int?>("MinigameId")
.HasColumnType("integer");
b.Property<string>("MinigameImage")
.HasColumnType("text");
b.Property<string>("MinigameName")
.HasColumnType("text");
b.Property<string>("Motd")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<string[]>("Players")
.IsRequired()
.HasColumnType("text[]");
b.Property<string>("RemoteSubscriptionId")
.IsRequired()
.HasColumnType("text");
b.Property<JsonDocument[]>("Slots")
.IsRequired()
.HasColumnType("jsonb[]");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,44 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Connections : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Connections",
columns: table => new
{
WorldId = table.Column<int>(type: "integer", nullable: false),
Address = table.Column<string>(type: "text", nullable: false),
PendingUpdate = table.Column<bool>(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");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Connections");
}
}
}

View File

@ -0,0 +1,168 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("PendingUpdate")
.HasColumnType("boolean");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasIndex("WorldId");
b.ToTable("Connections");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("StartDate")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SubscriptionType")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Subscriptions");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ActiveSlot")
.HasColumnType("integer");
b.Property<int>("DaysLeft")
.HasColumnType("integer");
b.Property<bool>("Expired")
.HasColumnType("boolean");
b.Property<bool>("ExpiredTrial")
.HasColumnType("boolean");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<bool>("Member")
.HasColumnType("boolean");
b.Property<int?>("MinigameId")
.HasColumnType("integer");
b.Property<string>("MinigameImage")
.HasColumnType("text");
b.Property<string>("MinigameName")
.HasColumnType("text");
b.Property<string>("Motd")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<string[]>("Players")
.IsRequired()
.HasColumnType("text[]");
b.Property<string>("RemoteSubscriptionId")
.IsRequired()
.HasColumnType("text");
b.Property<JsonDocument[]>("Slots")
.IsRequired()
.HasColumnType("jsonb[]");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,60 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Subscription_v2 : Migration
{
/// <inheritdoc />
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);
}
/// <inheritdoc />
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<string>(
name: "RemoteId",
table: "Subscriptions",
type: "text",
nullable: false,
defaultValue: "");
}
}
}

View File

@ -0,0 +1,211 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("BackupId")
.IsRequired()
.HasColumnType("text");
b.Property<long>("LastModifiedDate")
.HasColumnType("bigint");
b.Property<JsonDocument>("Metadata")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("Size")
.HasColumnType("integer");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Backups");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b =>
{
b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("PendingUpdate")
.HasColumnType("boolean");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasIndex("WorldId");
b.ToTable("Connections");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("StartDate")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SubscriptionType")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Subscriptions");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ActiveSlot")
.HasColumnType("integer");
b.Property<int>("DaysLeft")
.HasColumnType("integer");
b.Property<bool>("Expired")
.HasColumnType("boolean");
b.Property<bool>("ExpiredTrial")
.HasColumnType("boolean");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<bool>("Member")
.HasColumnType("boolean");
b.Property<int?>("MinigameId")
.HasColumnType("integer");
b.Property<string>("MinigameImage")
.HasColumnType("text");
b.Property<string>("MinigameName")
.HasColumnType("text");
b.Property<string>("Motd")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<string[]>("Players")
.IsRequired()
.HasColumnType("text[]");
b.Property<string>("RemoteSubscriptionId")
.IsRequired()
.HasColumnType("text");
b.Property<JsonDocument[]>("Slots")
.IsRequired()
.HasColumnType("jsonb[]");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,51 @@
using System.Text.Json;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Backups : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Backups",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
WorldId = table.Column<int>(type: "integer", nullable: false),
BackupId = table.Column<string>(type: "text", nullable: false),
LastModifiedDate = table.Column<long>(type: "bigint", nullable: false),
Size = table.Column<int>(type: "integer", nullable: false),
Metadata = table.Column<JsonDocument>(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");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Backups");
}
}
}

View File

@ -0,0 +1,219 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("BackupId")
.IsRequired()
.HasColumnType("text");
b.Property<long>("LastModifiedDate")
.HasColumnType("bigint");
b.Property<JsonDocument>("Metadata")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("Size")
.HasColumnType("integer");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Backups");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("PendingUpdate")
.HasColumnType("boolean");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Connections");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("StartDate")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SubscriptionType")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Subscriptions");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ActiveSlot")
.HasColumnType("integer");
b.Property<int>("DaysLeft")
.HasColumnType("integer");
b.Property<bool>("Expired")
.HasColumnType("boolean");
b.Property<bool>("ExpiredTrial")
.HasColumnType("boolean");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<bool>("Member")
.HasColumnType("boolean");
b.Property<int?>("MinigameId")
.HasColumnType("integer");
b.Property<string>("MinigameImage")
.HasColumnType("text");
b.Property<string>("MinigameName")
.HasColumnType("text");
b.Property<string>("Motd")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<string[]>("Players")
.IsRequired()
.HasColumnType("text[]");
b.Property<string>("RemoteSubscriptionId")
.IsRequired()
.HasColumnType("text");
b.Property<JsonDocument[]>("Slots")
.IsRequired()
.HasColumnType("jsonb[]");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Connections_Id : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "Id",
table: "Connections",
type: "integer",
nullable: false,
defaultValue: 0)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
migrationBuilder.AddPrimaryKey(
name: "PK_Connections",
table: "Connections",
column: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_Connections",
table: "Connections");
migrationBuilder.DropColumn(
name: "Id",
table: "Connections");
}
}
}

View File

@ -0,0 +1,259 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("BackupId")
.IsRequired()
.HasColumnType("text");
b.Property<long>("LastModifiedDate")
.HasColumnType("bigint");
b.Property<JsonDocument>("Metadata")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("Size")
.HasColumnType("integer");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Backups");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("PendingUpdate")
.HasColumnType("boolean");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Connections");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("InvitationId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecipeintUUID")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Invites");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("StartDate")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SubscriptionType")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Subscriptions");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ActiveSlot")
.HasColumnType("integer");
b.Property<int>("DaysLeft")
.HasColumnType("integer");
b.Property<bool>("Expired")
.HasColumnType("boolean");
b.Property<bool>("ExpiredTrial")
.HasColumnType("boolean");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<bool>("Member")
.HasColumnType("boolean");
b.Property<int?>("MinigameId")
.HasColumnType("integer");
b.Property<string>("MinigameImage")
.HasColumnType("text");
b.Property<string>("MinigameName")
.HasColumnType("text");
b.Property<string>("Motd")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<string[]>("Players")
.IsRequired()
.HasColumnType("text[]");
b.Property<string>("RemoteSubscriptionId")
.IsRequired()
.HasColumnType("text");
b.Property<JsonDocument[]>("Slots")
.IsRequired()
.HasColumnType("jsonb[]");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,50 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Invites : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Invites",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
InvitationId = table.Column<string>(type: "text", nullable: false),
RecipeintUUID = table.Column<string>(type: "text", nullable: false),
WorldId = table.Column<int>(type: "integer", nullable: false),
Date = table.Column<DateTime>(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");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Invites");
}
}
}

View File

@ -0,0 +1,310 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("BackupId")
.IsRequired()
.HasColumnType("text");
b.Property<long>("LastModifiedDate")
.HasColumnType("bigint");
b.Property<JsonDocument>("Metadata")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("Size")
.HasColumnType("integer");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Backups");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("PendingUpdate")
.HasColumnType("boolean");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Connections");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("InvitationId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecipeintUUID")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Invites");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("Accepted")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Online")
.HasColumnType("boolean");
b.Property<bool>("Operator")
.HasColumnType("boolean");
b.Property<string>("Permission")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Uuid")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Players");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("StartDate")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SubscriptionType")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Subscriptions");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ActiveSlot")
.HasColumnType("integer");
b.Property<int>("DaysLeft")
.HasColumnType("integer");
b.Property<bool>("Expired")
.HasColumnType("boolean");
b.Property<bool>("ExpiredTrial")
.HasColumnType("boolean");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<bool>("Member")
.HasColumnType("boolean");
b.Property<int?>("MinigameId")
.HasColumnType("integer");
b.Property<string>("MinigameImage")
.HasColumnType("text");
b.Property<string>("MinigameName")
.HasColumnType("text");
b.Property<string>("Motd")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<string>("RemoteSubscriptionId")
.IsRequired()
.HasColumnType("text");
b.Property<JsonDocument[]>("Slots")
.IsRequired()
.HasColumnType("jsonb[]");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,63 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Players : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Players",
table: "Worlds");
migrationBuilder.CreateTable(
name: "Players",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
Uuid = table.Column<string>(type: "text", nullable: false),
Operator = table.Column<bool>(type: "boolean", nullable: false),
Accepted = table.Column<bool>(type: "boolean", nullable: false),
Online = table.Column<bool>(type: "boolean", nullable: false),
Permission = table.Column<string>(type: "text", nullable: false),
WorldId = table.Column<int>(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");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Players");
migrationBuilder.AddColumn<string[]>(
name: "Players",
table: "Worlds",
type: "text[]",
nullable: false,
defaultValue: new string[0]);
}
}
}

View File

@ -0,0 +1,324 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("BackupId")
.IsRequired()
.HasColumnType("text");
b.Property<long>("LastModifiedDate")
.HasColumnType("bigint");
b.Property<JsonDocument>("Metadata")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("Size")
.HasColumnType("integer");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Backups");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Configuration", b =>
{
b.Property<string>("Key")
.HasColumnType("text");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("text");
b.HasKey("Key");
b.ToTable("Configuration");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("PendingUpdate")
.HasColumnType("boolean");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Connections");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("InvitationId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecipeintUUID")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Invites");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("Accepted")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Online")
.HasColumnType("boolean");
b.Property<bool>("Operator")
.HasColumnType("boolean");
b.Property<string>("Permission")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Uuid")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Players");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("StartDate")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SubscriptionType")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Subscriptions");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ActiveSlot")
.HasColumnType("integer");
b.Property<int>("DaysLeft")
.HasColumnType("integer");
b.Property<bool>("Expired")
.HasColumnType("boolean");
b.Property<bool>("ExpiredTrial")
.HasColumnType("boolean");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<bool>("Member")
.HasColumnType("boolean");
b.Property<int?>("MinigameId")
.HasColumnType("integer");
b.Property<string>("MinigameImage")
.HasColumnType("text");
b.Property<string>("MinigameName")
.HasColumnType("text");
b.Property<string>("Motd")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<string>("RemoteSubscriptionId")
.IsRequired()
.HasColumnType("text");
b.Property<JsonDocument[]>("Slots")
.IsRequired()
.HasColumnType("jsonb[]");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Configuration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Configuration",
columns: table => new
{
Key = table.Column<string>(type: "text", nullable: false),
Value = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Configuration", x => x.Key);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Configuration");
}
}
}

View File

@ -0,0 +1,323 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("BackupId")
.IsRequired()
.HasColumnType("text");
b.Property<long>("LastModifiedDate")
.HasColumnType("bigint");
b.Property<JsonDocument>("Metadata")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("Size")
.HasColumnType("integer");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Backups");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Configuration", b =>
{
b.Property<string>("Key")
.HasColumnType("text");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("text");
b.HasKey("Key");
b.ToTable("Configuration");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("PendingUpdate")
.HasColumnType("boolean");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Connections");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("InvitationId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecipeintUUID")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Invites");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("Accepted")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Online")
.HasColumnType("boolean");
b.Property<bool>("Operator")
.HasColumnType("boolean");
b.Property<string>("Permission")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Uuid")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Players");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("StartDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("SubscriptionType")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Subscriptions");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ActiveSlot")
.HasColumnType("integer");
b.Property<int>("DaysLeft")
.HasColumnType("integer");
b.Property<bool>("Expired")
.HasColumnType("boolean");
b.Property<bool>("ExpiredTrial")
.HasColumnType("boolean");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<bool>("Member")
.HasColumnType("boolean");
b.Property<int?>("MinigameId")
.HasColumnType("integer");
b.Property<string>("MinigameImage")
.HasColumnType("text");
b.Property<string>("MinigameName")
.HasColumnType("text");
b.Property<string>("Motd")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<string>("RemoteSubscriptionId")
.IsRequired()
.HasColumnType("text");
b.Property<JsonDocument[]>("Slots")
.IsRequired()
.HasColumnType("jsonb[]");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Subscriptions_StartDate_Readable_Field : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("ALTER TABLE \"Subscriptions\" ALTER COLUMN \"StartDate\" TYPE timestamptz USING \"StartDate\"::timestamptz");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("ALTER TABLE \"Subscriptions\" ALTER COLUMN \"StartDate\" TYPE text USING \"StartDate\"::text");
}
}
}

View File

@ -0,0 +1,313 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("BackupId")
.IsRequired()
.HasColumnType("text");
b.Property<long>("LastModifiedDate")
.HasColumnType("bigint");
b.Property<JsonDocument>("Metadata")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("Size")
.HasColumnType("integer");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Backups");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Configuration", b =>
{
b.Property<string>("Key")
.HasColumnType("text");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("text");
b.HasKey("Key");
b.ToTable("Configuration");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("PendingUpdate")
.HasColumnType("boolean");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Connections");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("InvitationId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecipeintUUID")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Invites");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("Accepted")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Online")
.HasColumnType("boolean");
b.Property<bool>("Operator")
.HasColumnType("boolean");
b.Property<string>("Permission")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Uuid")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Players");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("StartDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("SubscriptionType")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId")
.IsUnique();
b.ToTable("Subscriptions");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ActiveSlot")
.HasColumnType("integer");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<bool>("Member")
.HasColumnType("boolean");
b.Property<int?>("MinigameId")
.HasColumnType("integer");
b.Property<string>("MinigameImage")
.HasColumnType("text");
b.Property<string>("MinigameName")
.HasColumnType("text");
b.Property<string>("Motd")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<JsonDocument[]>("Slots")
.IsRequired()
.HasColumnType("jsonb[]");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,81 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Worlds_Subscription_field : Migration
{
/// <inheritdoc />
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);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_Subscriptions_WorldId",
table: "Subscriptions");
migrationBuilder.AddColumn<int>(
name: "DaysLeft",
table: "Worlds",
type: "integer",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<bool>(
name: "Expired",
table: "Worlds",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<bool>(
name: "ExpiredTrial",
table: "Worlds",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<string>(
name: "RemoteSubscriptionId",
table: "Worlds",
type: "text",
nullable: false,
defaultValue: "");
migrationBuilder.CreateIndex(
name: "IX_Subscriptions_WorldId",
table: "Subscriptions",
column: "WorldId");
}
}
}

View File

@ -0,0 +1,313 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("BackupId")
.IsRequired()
.HasColumnType("text");
b.Property<long>("LastModifiedDate")
.HasColumnType("bigint");
b.Property<JsonDocument>("Metadata")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("Size")
.HasColumnType("integer");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Backups");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Configuration", b =>
{
b.Property<string>("Key")
.HasColumnType("text");
b.Property<object>("Value")
.IsRequired()
.HasColumnType("jsonb");
b.HasKey("Key");
b.ToTable("Configuration");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("PendingUpdate")
.HasColumnType("boolean");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Connections");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("InvitationId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecipeintUUID")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Invites");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("Accepted")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Online")
.HasColumnType("boolean");
b.Property<bool>("Operator")
.HasColumnType("boolean");
b.Property<string>("Permission")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Uuid")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Players");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("StartDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("SubscriptionType")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId")
.IsUnique();
b.ToTable("Subscriptions");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ActiveSlot")
.HasColumnType("integer");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<bool>("Member")
.HasColumnType("boolean");
b.Property<int?>("MinigameId")
.HasColumnType("integer");
b.Property<string>("MinigameImage")
.HasColumnType("text");
b.Property<string>("MinigameName")
.HasColumnType("text");
b.Property<string>("Motd")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<JsonDocument[]>("Slots")
.IsRequired()
.HasColumnType("jsonb[]");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Configuration_Json : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("ALTER TABLE \"Configuration\" ALTER COLUMN \"Value\" TYPE jsonb USING \"Value\"::jsonb");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("ALTER TABLE \"Configuration\" ALTER COLUMN \"Value\" TYPE text USING \"Value\"::text");
}
}
}

View File

@ -0,0 +1,310 @@
// <auto-generated />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("BackupId")
.IsRequired()
.HasColumnType("text");
b.Property<long>("LastModifiedDate")
.HasColumnType("bigint");
b.Property<JsonDocument>("Metadata")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("Size")
.HasColumnType("integer");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Backups");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Configuration", b =>
{
b.Property<string>("Key")
.HasColumnType("text");
b.Property<object>("Value")
.IsRequired()
.HasColumnType("jsonb");
b.HasKey("Key");
b.ToTable("Configuration");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("PendingUpdate")
.HasColumnType("boolean");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Connections");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("InvitationId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecipeintUUID")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Invites");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("Accepted")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Online")
.HasColumnType("boolean");
b.Property<bool>("Operator")
.HasColumnType("boolean");
b.Property<string>("Permission")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Uuid")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Players");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("StartDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("SubscriptionType")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId")
.IsUnique();
b.ToTable("Subscriptions");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ActiveSlot")
.HasColumnType("integer");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<bool>("Member")
.HasColumnType("boolean");
b.Property<int?>("MinigameId")
.HasColumnType("integer");
b.Property<string>("MinigameImage")
.HasColumnType("text");
b.Property<string>("MinigameName")
.HasColumnType("text");
b.Property<string>("Motd")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<JsonDocument[]>("Slots")
.IsRequired()
.HasColumnType("jsonb[]");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<RootNamespace>Minecraft_Realms_Emulator</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetEnv" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
</Project>

View File

@ -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
###

View File

@ -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<DataContext>(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<MinecraftCookieMiddleware>();
app.MapControllers();
app.Run();

View File

@ -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"
}
}
}
}

View File

@ -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";
}
}

View File

@ -0,0 +1,8 @@
namespace Minecraft_Realms_Emulator.Requests
{
public class WorldCreateRequest
{
public string? Name { get; set; }
public string? Description { get; set; }
}
}

View File

@ -0,0 +1,9 @@
using Minecraft_Realms_Emulator.Entities;
namespace Minecraft_Realms_Emulator.Responses
{
public class BackupsResponse
{
public List<Backup> Backups { get; set; }
}
}

View File

@ -0,0 +1,16 @@
namespace Minecraft_Realms_Emulator.Responses
{
public class InviteList
{
public List<InviteResponse> 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; }
}
}

View File

@ -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; }
}
}

View File

@ -0,0 +1,7 @@
namespace Minecraft_Realms_Emulator.Responses
{
public class NewsResponse
{
public string NewsLink { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,7 @@
namespace Minecraft_Realms_Emulator.Responses
{
public class OpsResponse
{
public List<string> Ops { get; set; }
}
}

View File

@ -0,0 +1,9 @@
using Minecraft_Realms_Emulator.Entities;
namespace Minecraft_Realms_Emulator.Responses
{
public class ServersResponse
{
public List<WorldResponse>? Servers { get; set; }
}
}

View File

@ -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; }
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}