From bc86311a09cb2e13f241de30ffd349fae9ba14f3 Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Sun, 11 Feb 2024 15:10:34 +0100 Subject: [PATCH] feat: world slots --- .../Controllers/WorldsController.cs | 11 +- Minecraft-Realms-Emulator/Entities/Slot.cs | 8 ++ Minecraft-Realms-Emulator/Entities/World.cs | 6 +- .../20240211135246_Slots.Designer.cs | 131 ++++++++++++++++++ .../Migrations/20240211135246_Slots.cs | 23 +++ .../Migrations/DataContextModelSnapshot.cs | 5 +- 6 files changed, 177 insertions(+), 7 deletions(-) create mode 100644 Minecraft-Realms-Emulator/Entities/Slot.cs create mode 100644 Minecraft-Realms-Emulator/Migrations/20240211135246_Slots.Designer.cs create mode 100644 Minecraft-Realms-Emulator/Migrations/20240211135246_Slots.cs diff --git a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs index 12b6c2c..c19fa2b 100644 --- a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs @@ -2,7 +2,6 @@ using Microsoft.EntityFrameworkCore; using Minecraft_Realms_Emulator.Data; using Minecraft_Realms_Emulator.Entities; -using System.Diagnostics.Eventing.Reader; namespace Minecraft_Realms_Emulator.Controllers { @@ -21,7 +20,7 @@ namespace Minecraft_Realms_Emulator.Controllers public async Task> GetWorlds() { var worlds = await _context.Worlds.ToListAsync(); - + string cookie = Request.Headers.Cookie; string playerUUID = cookie.Split(";")[0].Split(":")[2]; @@ -48,7 +47,6 @@ namespace Minecraft_Realms_Emulator.Controllers MinigameId = null, MinigameName = null, MinigameImage = null, - Slots = [], ActiveSlot = 1, Member = false }; @@ -162,5 +160,12 @@ namespace Minecraft_Realms_Emulator.Controllers return Ok(true); } + + [HttpPost("{wId}/slot/{sId}")] + public bool U(int wId, int sId, object o) + { + Console.WriteLine(o); + return true; + } } } diff --git a/Minecraft-Realms-Emulator/Entities/Slot.cs b/Minecraft-Realms-Emulator/Entities/Slot.cs new file mode 100644 index 0000000..e08d892 --- /dev/null +++ b/Minecraft-Realms-Emulator/Entities/Slot.cs @@ -0,0 +1,8 @@ +namespace Minecraft_Realms_Emulator.Entities +{ + public class Slot + { + public int SlotId { get; set; } + public string Options { get; set; } = "{}"; + } +} diff --git a/Minecraft-Realms-Emulator/Entities/World.cs b/Minecraft-Realms-Emulator/Entities/World.cs index bc23c51..6d15ed1 100644 --- a/Minecraft-Realms-Emulator/Entities/World.cs +++ b/Minecraft-Realms-Emulator/Entities/World.cs @@ -1,4 +1,6 @@ -namespace Minecraft_Realms_Emulator.Entities +using System.Text.Json; + +namespace Minecraft_Realms_Emulator.Entities { public class World { @@ -19,7 +21,7 @@ public int? MinigameId { get; set; } public string? MinigameImage { get; set; } public int ActiveSlot { get; set; } = 1; - public string[] Slots { get; set; } = []; + public JsonDocument[] Slots { get; set; } = []; public bool Member { get; set; } = false; } } \ No newline at end of file diff --git a/Minecraft-Realms-Emulator/Migrations/20240211135246_Slots.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240211135246_Slots.Designer.cs new file mode 100644 index 0000000..b99784f --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240211135246_Slots.Designer.cs @@ -0,0 +1,131 @@ +// +using System; +using System.Text.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Minecraft_Realms_Emulator.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20240211135246_Slots")] + partial class Slots + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("RemoteId") + .IsRequired() + .HasColumnType("text"); + + b.Property("StartDate") + .IsRequired() + .HasColumnType("text"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActiveSlot") + .HasColumnType("integer"); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("Expired") + .HasColumnType("boolean"); + + b.Property("ExpiredTrial") + .HasColumnType("boolean"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("Member") + .HasColumnType("boolean"); + + b.Property("MinigameId") + .HasColumnType("integer"); + + b.Property("MinigameImage") + .HasColumnType("text"); + + b.Property("MinigameName") + .HasColumnType("text"); + + b.Property("Motd") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Owner") + .HasColumnType("text"); + + b.Property("OwnerUUID") + .HasColumnType("text"); + + b.Property("Players") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("RemoteSubscriptionId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Slots") + .IsRequired() + .HasColumnType("jsonb[]"); + + b.Property("State") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240211135246_Slots.cs b/Minecraft-Realms-Emulator/Migrations/20240211135246_Slots.cs new file mode 100644 index 0000000..a040aef --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240211135246_Slots.cs @@ -0,0 +1,23 @@ +using System.Text.Json; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Slots : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql("ALTER TABLE \"Worlds\" ALTER COLUMN \"Slots\" TYPE jsonb[] USING \"Slots\"::jsonb[]"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql("ALTER TABLE \"Worlds\" ALTER COLUMN \"Slots\" TYPE text[] USING \"Slots\"::text[]"); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs index e030a58..1f3b997 100644 --- a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs +++ b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs @@ -1,5 +1,6 @@ // using System; +using System.Text.Json; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; @@ -105,9 +106,9 @@ namespace Minecraft_Realms_Emulator.Migrations .IsRequired() .HasColumnType("text"); - b.Property("Slots") + b.Property("Slots") .IsRequired() - .HasColumnType("text[]"); + .HasColumnType("jsonb[]"); b.Property("State") .IsRequired()