diff --git a/Minecraft-Realms-Emulator/Entities/World.cs b/Minecraft-Realms-Emulator/Entities/World.cs index 2d29781..6063a4b 100644 --- a/Minecraft-Realms-Emulator/Entities/World.cs +++ b/Minecraft-Realms-Emulator/Entities/World.cs @@ -12,9 +12,7 @@ public string WorldType { get; set; } = "NORMAL"; public List Players { get; set; } = []; public int MaxPlayers { get; set; } = 10; - public string? MinigameName { get; set; } - public int? MinigameId { get; set; } - public string? MinigameImage { get; set; } + public Template? Minigame { get; set; } public int ActiveSlot { get; set; } = 1; public List Slots { get; set; } = []; public bool Member { get; set; } = false; diff --git a/Minecraft-Realms-Emulator/Migrations/20240630120218_Minigames.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240630120218_Minigames.Designer.cs new file mode 100644 index 0000000..894a60f --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240630120218_Minigames.Designer.cs @@ -0,0 +1,502 @@ +// +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("20240630120218_Minigames")] + partial class Minigames + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BackupId") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastModifiedDate") + .HasColumnType("bigint"); + + b.Property("Metadata") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Size") + .HasColumnType("integer"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Backups"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Configuration", b => + { + b.Property("Key") + .HasColumnType("text"); + + b.Property("Value") + .IsRequired() + .HasColumnType("jsonb"); + + b.HasKey("Key"); + + b.ToTable("Configuration"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("InvitationId") + .IsRequired() + .HasColumnType("text"); + + b.Property("RecipeintUUID") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Invites"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Notification", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ButtonText") + .HasColumnType("jsonb"); + + b.Property("Dismissable") + .HasColumnType("boolean"); + + b.Property("Image") + .HasColumnType("text"); + + b.Property("Message") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("NotificationUuid") + .IsRequired() + .HasColumnType("text"); + + b.Property("Title") + .HasColumnType("jsonb"); + + b.Property("Type") + .IsRequired() + .HasColumnType("text"); + + b.Property("Url") + .HasColumnType("text"); + + b.Property("UrlButton") + .HasColumnType("jsonb"); + + b.HasKey("Id"); + + b.ToTable("Notifications"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Accepted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Online") + .HasColumnType("boolean"); + + b.Property("Operator") + .HasColumnType("boolean"); + + b.Property("Permission") + .IsRequired() + .HasColumnType("text"); + + b.Property("Uuid") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Players"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.SeenNotification", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("NotificationUUID") + .IsRequired() + .HasColumnType("text"); + + b.Property("PlayerUUID") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("SeenNotifications"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Slot", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CommandBlocks") + .HasColumnType("boolean"); + + b.Property("Difficulty") + .HasColumnType("integer"); + + b.Property("ForceGameMode") + .HasColumnType("boolean"); + + b.Property("GameMode") + .HasColumnType("integer"); + + b.Property("Pvp") + .HasColumnType("boolean"); + + b.Property("SlotId") + .HasColumnType("integer"); + + b.Property("SlotName") + .IsRequired() + .HasColumnType("text"); + + b.Property("SpawnAnimals") + .HasColumnType("boolean"); + + b.Property("SpawnMonsters") + .HasColumnType("boolean"); + + b.Property("SpawnNPCs") + .HasColumnType("boolean"); + + b.Property("SpawnProtection") + .HasColumnType("integer"); + + b.Property("Version") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Slots"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StartDate") + .HasColumnType("timestamp with time zone"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId") + .IsUnique(); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Template", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Author") + .IsRequired() + .HasColumnType("text"); + + b.Property("Image") + .HasColumnType("text"); + + b.Property("Link") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("RecommendedPlayers") + .IsRequired() + .HasColumnType("text"); + + b.Property("Trailer") + .IsRequired() + .HasColumnType("text"); + + b.Property("Type") + .IsRequired() + .HasColumnType("text"); + + b.Property("Version") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Templates"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActiveSlot") + .HasColumnType("integer"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("Member") + .HasColumnType("boolean"); + + b.Property("MinigameId") + .HasColumnType("integer"); + + b.Property("Motd") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Owner") + .HasColumnType("text"); + + b.Property("OwnerUUID") + .HasColumnType("text"); + + b.Property("ParentWorldId") + .HasColumnType("integer"); + + b.Property("State") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("MinigameId"); + + b.HasIndex("ParentWorldId"); + + 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.Slot", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany("Slots") + .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.HasOne("Minecraft_Realms_Emulator.Entities.Template", "Minigame") + .WithMany() + .HasForeignKey("MinigameId"); + + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "ParentWorld") + .WithMany() + .HasForeignKey("ParentWorldId"); + + b.Navigation("Minigame"); + + b.Navigation("ParentWorld"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Navigation("Players"); + + b.Navigation("Slots"); + + b.Navigation("Subscription"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240630120218_Minigames.cs b/Minecraft-Realms-Emulator/Migrations/20240630120218_Minigames.cs new file mode 100644 index 0000000..a2dd133 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240630120218_Minigames.cs @@ -0,0 +1,58 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Minigames : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "MinigameImage", + table: "Worlds"); + + migrationBuilder.DropColumn( + name: "MinigameName", + table: "Worlds"); + + migrationBuilder.CreateIndex( + name: "IX_Worlds_MinigameId", + table: "Worlds", + column: "MinigameId"); + + migrationBuilder.AddForeignKey( + name: "FK_Worlds_Templates_MinigameId", + table: "Worlds", + column: "MinigameId", + principalTable: "Templates", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Worlds_Templates_MinigameId", + table: "Worlds"); + + migrationBuilder.DropIndex( + name: "IX_Worlds_MinigameId", + table: "Worlds"); + + migrationBuilder.AddColumn( + name: "MinigameImage", + table: "Worlds", + type: "text", + nullable: true); + + migrationBuilder.AddColumn( + name: "MinigameName", + table: "Worlds", + type: "text", + nullable: true); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs index bff3f50..39cf6fb 100644 --- a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs +++ b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs @@ -372,12 +372,6 @@ namespace Minecraft_Realms_Emulator.Migrations b.Property("MinigameId") .HasColumnType("integer"); - b.Property("MinigameImage") - .HasColumnType("text"); - - b.Property("MinigameName") - .HasColumnType("text"); - b.Property("Motd") .HasColumnType("text"); @@ -403,6 +397,8 @@ namespace Minecraft_Realms_Emulator.Migrations b.HasKey("Id"); + b.HasIndex("MinigameId"); + b.HasIndex("ParentWorldId"); b.ToTable("Worlds"); @@ -476,10 +472,16 @@ namespace Minecraft_Realms_Emulator.Migrations modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => { + b.HasOne("Minecraft_Realms_Emulator.Entities.Template", "Minigame") + .WithMany() + .HasForeignKey("MinigameId"); + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "ParentWorld") .WithMany() .HasForeignKey("ParentWorldId"); + b.Navigation("Minigame"); + b.Navigation("ParentWorld"); }); diff --git a/Minecraft-Realms-Emulator/Modes/External/WorldsController.cs b/Minecraft-Realms-Emulator/Modes/External/WorldsController.cs index 27a23fa..c62331e 100644 --- a/Minecraft-Realms-Emulator/Modes/External/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Modes/External/WorldsController.cs @@ -32,8 +32,8 @@ namespace Minecraft_Realms_Emulator.Modes.External string playerName = cookie.Split(";")[1].Split("=")[1]; string gameVersion = cookie.Split(";")[2].Split("=")[1]; - var ownedWorlds = await _context.Worlds.Where(w => w.OwnerUUID == playerUUID).Include(w => w.Subscription).Include(w => w.Slots).ToListAsync(); - var memberWorlds = await _context.Players.Where(p => p.Uuid == playerUUID && p.Accepted).Include(p => p.World.Subscription).Include(p => p.World.Slots).Select(p => p.World).ToListAsync(); + var ownedWorlds = await _context.Worlds.Where(w => w.OwnerUUID == playerUUID).Include(w => w.Subscription).Include(w => w.Slots).Include(w => w.Minigame).ToListAsync(); + var memberWorlds = await _context.Players.Where(p => p.Uuid == playerUUID && p.Accepted).Include(p => p.World.Subscription).Include(p => p.World.Slots).Include(p => p.World.Minigame).Select(p => p.World).ToListAsync(); List allWorlds = []; @@ -48,9 +48,7 @@ namespace Minecraft_Realms_Emulator.Modes.External State = nameof(StateEnum.UNINITIALIZED), WorldType = nameof(WorldTypeEnum.NORMAL), MaxPlayers = 10, - MinigameId = null, - MinigameName = null, - MinigameImage = null, + Minigame = null, ActiveSlot = 1, Member = false }; @@ -78,9 +76,6 @@ namespace Minecraft_Realms_Emulator.Modes.External 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, @@ -88,6 +83,13 @@ namespace Minecraft_Realms_Emulator.Modes.External Compatibility = isCompatible }; + if (world.Minigame != null) + { + response.MinigameId = world.Minigame.Id; + response.MinigameName = world.Minigame.Name; + response.MinigameImage = world.Minigame.Image; + } + if (world.Subscription != null) { response.DaysLeft = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days; @@ -115,9 +117,6 @@ namespace Minecraft_Realms_Emulator.Modes.External 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, @@ -128,6 +127,13 @@ namespace Minecraft_Realms_Emulator.Modes.External Compatibility = isCompatible }; + if (world.Minigame != null) + { + response.MinigameId = world.Minigame.Id; + response.MinigameName = world.Minigame.Name; + response.MinigameImage = world.Minigame.Image; + } + allWorlds.Add(response); } @@ -170,9 +176,6 @@ namespace Minecraft_Realms_Emulator.Modes.External 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, @@ -180,6 +183,13 @@ namespace Minecraft_Realms_Emulator.Modes.External Compatibility = isCompatible }; + if (world.Minigame != null) + { + response.MinigameId = world.Minigame.Id; + response.MinigameName = world.Minigame.Name; + response.MinigameImage = world.Minigame.Image; + } + if (world.Subscription != null) { response.DaysLeft = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days; @@ -220,9 +230,6 @@ namespace Minecraft_Realms_Emulator.Modes.External 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, @@ -233,6 +240,13 @@ namespace Minecraft_Realms_Emulator.Modes.External Compatibility = isCompatible }; + if (world.Minigame != null) + { + response.MinigameId = world.Minigame.Id; + response.MinigameName = world.Minigame.Name; + response.MinigameImage = world.Minigame.Image; + } + if (world.ParentWorld == null) { response.ParentWorldId = -1; @@ -284,9 +298,7 @@ namespace Minecraft_Realms_Emulator.Modes.External State = nameof(StateEnum.UNINITIALIZED), WorldType = nameof(WorldTypeEnum.NORMAL), MaxPlayers = 10, - MinigameId = null, - MinigameName = null, - MinigameImage = null, + Minigame = null, ActiveSlot = 1, Member = false, ParentWorld = parentWorld, @@ -316,9 +328,6 @@ namespace Minecraft_Realms_Emulator.Modes.External 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, @@ -328,6 +337,13 @@ namespace Minecraft_Realms_Emulator.Modes.External ParentWorldName = world.ParentWorld.Name, }; + if (world.Minigame != null) + { + response.MinigameId = world.Minigame.Id; + response.MinigameName = world.Minigame.Name; + response.MinigameImage = world.Minigame.Image; + } + if (world.Subscription != null) { response.DaysLeft = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days; @@ -355,9 +371,6 @@ namespace Minecraft_Realms_Emulator.Modes.External 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, @@ -368,6 +381,13 @@ namespace Minecraft_Realms_Emulator.Modes.External Compatibility = isCompatible }; + if (world.Minigame != null) + { + response.MinigameId = world.Minigame.Id; + response.MinigameName = world.Minigame.Name; + response.MinigameImage = world.Minigame.Image; + } + allWorlds.Add(response); } @@ -436,9 +456,6 @@ namespace Minecraft_Realms_Emulator.Modes.External State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, - MinigameId = world.MinigameId, - MinigameName = world.MinigameName, - MinigameImage = world.MinigameImage, ActiveSlot = world.ActiveSlot, Slots = slots, Member = world.Member, @@ -450,6 +467,13 @@ namespace Minecraft_Realms_Emulator.Modes.External Compatibility = activeSlotOptions.Compatibility }; + if (world.Minigame != null) + { + response.MinigameId = world.Minigame.Id; + response.MinigameName = world.Minigame.Name; + response.MinigameImage = world.Minigame.Image; + } + return response; } @@ -718,8 +742,7 @@ namespace Minecraft_Realms_Emulator.Modes.External [CheckRealmOwner] public ActionResult SwitchSlot(int wId, int sId) { - var world = _context.Worlds.Find(wId); - + var world = _context.Worlds.Include(w => w.Minigame).FirstOrDefault(w => w.Id == wId); var slot = _context.Slots.Where(s => s.World.Id == wId).Where(s => s.SlotId == sId).Any(); if (!slot) @@ -748,6 +771,9 @@ namespace Minecraft_Realms_Emulator.Modes.External } world.ActiveSlot = sId; + world.Minigame = null; + world.WorldType = nameof(WorldTypeEnum.NORMAL); + _context.SaveChanges(); return Ok(true); @@ -819,5 +845,21 @@ namespace Minecraft_Realms_Emulator.Modes.External return Ok(templatesResponse); } + + [HttpPut("minigames/{mId}/{wId}")] + [CheckForWorld] + [CheckRealmOwner] + public ActionResult SwitchToMinigame(int mId, int wId) + { + var world = _context.Worlds.Find(wId); + var minigame = _context.Templates.FirstOrDefault(t => t.Type == nameof(WorldTemplateTypeEnum.MINIGAME) && t.Id == mId); + + world.Minigame = minigame; + world.WorldType = nameof(WorldTypeEnum.MINIGAME); + + _context.SaveChanges(); + + return Ok(true); + } } } diff --git a/Minecraft-Realms-Emulator/Modes/Realms/Controllers/WorldsController.cs b/Minecraft-Realms-Emulator/Modes/Realms/Controllers/WorldsController.cs index 3dfb160..b97245d 100644 --- a/Minecraft-Realms-Emulator/Modes/Realms/Controllers/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Modes/Realms/Controllers/WorldsController.cs @@ -35,8 +35,8 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers string playerName = cookie.Split(";")[1].Split("=")[1]; string gameVersion = cookie.Split(";")[2].Split("=")[1]; - var ownedWorlds = await _context.Worlds.Where(w => w.OwnerUUID == playerUUID).Include(w => w.Subscription).Include(w => w.Slots).ToListAsync(); - var memberWorlds = await _context.Players.Where(p => p.Uuid == playerUUID && p.Accepted).Include(p => p.World.Subscription).Include(p => p.World.Slots).Select(p => p.World).ToListAsync(); + var ownedWorlds = await _context.Worlds.Where(w => w.OwnerUUID == playerUUID).Include(w => w.Subscription).Include(w => w.Slots).Include(w => w.Minigame).ToListAsync(); + var memberWorlds = await _context.Players.Where(p => p.Uuid == playerUUID && p.Accepted).Include(p => p.World.Subscription).Include(p => p.World.Slots).Include(p => p.World.Minigame).Select(p => p.World).ToListAsync(); List allWorlds = []; @@ -51,9 +51,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers State = nameof(StateEnum.UNINITIALIZED), WorldType = nameof(WorldTypeEnum.NORMAL), MaxPlayers = 10, - MinigameId = null, - MinigameName = null, - MinigameImage = null, + Minigame = null, ActiveSlot = 1, Member = false }; @@ -81,9 +79,6 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers 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, @@ -91,6 +86,13 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers Compatibility = isCompatible }; + if (world.Minigame != null) + { + response.MinigameId = world.Minigame.Id; + response.MinigameName = world.Minigame.Name; + response.MinigameImage = world.Minigame.Image; + } + if (world.Subscription != null) { response.DaysLeft = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days; @@ -118,9 +120,6 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers 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, @@ -131,6 +130,13 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers Compatibility = isCompatible }; + if (world.Minigame != null) + { + response.MinigameId = world.Minigame.Id; + response.MinigameName = world.Minigame.Name; + response.MinigameImage = world.Minigame.Image; + } + allWorlds.Add(response); } @@ -173,9 +179,6 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers 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, @@ -183,6 +186,13 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers Compatibility = isCompatible }; + if (world.Minigame != null) + { + response.MinigameId = world.Minigame.Id; + response.MinigameName = world.Minigame.Name; + response.MinigameImage = world.Minigame.Image; + } + if (world.Subscription != null) { response.DaysLeft = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days; @@ -223,9 +233,6 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers 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, @@ -236,6 +243,13 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers Compatibility = isCompatible }; + if (world.Minigame != null) + { + response.MinigameId = world.Minigame.Id; + response.MinigameName = world.Minigame.Name; + response.MinigameImage = world.Minigame.Image; + } + if (world.ParentWorld == null) { response.ParentWorldId = -1; @@ -287,9 +301,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers State = nameof(StateEnum.UNINITIALIZED), WorldType = nameof(WorldTypeEnum.NORMAL), MaxPlayers = 10, - MinigameId = null, - MinigameName = null, - MinigameImage = null, + Minigame = null, ActiveSlot = 1, Member = false, ParentWorld = parentWorld, @@ -319,9 +331,6 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers 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, @@ -331,6 +340,13 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers ParentWorldName = world.ParentWorld.Name, }; + if (world.Minigame != null) + { + response.MinigameId = world.Minigame.Id; + response.MinigameName = world.Minigame.Name; + response.MinigameImage = world.Minigame.Image; + } + if (world.Subscription != null) { response.DaysLeft = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days; @@ -358,9 +374,6 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers 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, @@ -371,6 +384,13 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers Compatibility = isCompatible }; + if (world.Minigame != null) + { + response.MinigameId = world.Minigame.Id; + response.MinigameName = world.Minigame.Name; + response.MinigameImage = world.Minigame.Image; + } + allWorlds.Add(response); } @@ -439,9 +459,6 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers State = world.State, WorldType = world.WorldType, MaxPlayers = world.MaxPlayers, - MinigameId = world.MinigameId, - MinigameName = world.MinigameName, - MinigameImage = world.MinigameImage, ActiveSlot = world.ActiveSlot, Slots = slots, Member = world.Member, @@ -453,6 +470,13 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers Compatibility = activeSlotOptions.Compatibility }; + if (world.Minigame != null) + { + response.MinigameId = world.Minigame.Id; + response.MinigameName = world.Minigame.Name; + response.MinigameImage = world.Minigame.Image; + } + return response; } @@ -789,8 +813,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers [CheckActiveSubscription] public ActionResult SwitchSlot(int wId, int sId) { - var world = _context.Worlds.Find(wId); - + var world = _context.Worlds.Include(w => w.Minigame).FirstOrDefault(w => w.Id == wId); var slot = _context.Slots.Where(s => s.World.Id == wId).Where(s => s.SlotId == sId).Any(); if (!slot) @@ -819,6 +842,9 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers } world.ActiveSlot = sId; + world.Minigame = null; + world.WorldType = nameof(WorldTypeEnum.NORMAL); + _context.SaveChanges(); return Ok(true); @@ -894,5 +920,21 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers return Ok(templatesResponse); } + + [HttpPut("minigames/{mId}/{wId}")] + [CheckForWorld] + [CheckRealmOwner] + public ActionResult SwitchToMinigame(int mId, int wId) + { + var world = _context.Worlds.Find(wId); + var minigame = _context.Templates.FirstOrDefault(t => t.Type == nameof(WorldTemplateTypeEnum.MINIGAME) && t.Id == mId); + + world.Minigame = minigame; + world.WorldType = nameof(WorldTypeEnum.MINIGAME); + + _context.SaveChanges(); + + return Ok(true); + } } } diff --git a/Minecraft-Realms-Emulator/Responses/WorldResponse.cs b/Minecraft-Realms-Emulator/Responses/WorldResponse.cs index 26bf20f..7c96f96 100644 --- a/Minecraft-Realms-Emulator/Responses/WorldResponse.cs +++ b/Minecraft-Realms-Emulator/Responses/WorldResponse.cs @@ -13,5 +13,8 @@ namespace Minecraft_Realms_Emulator.Entities public string ActiveVersion { get; set; } = null!; public int? ParentWorldId { get; set; } public string? ParentWorldName { get; set; } + public int? MinigameId { get; set; } + public string? MinigameName { get; set; } + public string? MinigameImage { get; set; } } } \ No newline at end of file