feat: slot settings

This commit is contained in:
CyberL1 2024-05-21 10:28:49 +02:00
parent 91b62581c9
commit ffed3a8b4a
12 changed files with 1054 additions and 31 deletions

View File

@ -31,8 +31,8 @@ namespace Minecraft_Realms_Emulator.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).ToListAsync();
var memberWorlds = await _context.Players.Where(p => p.Uuid == playerUUID && p.Accepted).Include(p => p.World.Subscription).Select(p => p.World).ToListAsync();
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();
List<WorldResponse> allWorlds = [];
@ -51,8 +51,7 @@ namespace Minecraft_Realms_Emulator.Controllers
MinigameName = null,
MinigameImage = null,
ActiveSlot = 1,
Member = false,
ActiveVersion = gameVersion
Member = false
};
ownedWorlds.Add(world);
@ -63,7 +62,9 @@ namespace Minecraft_Realms_Emulator.Controllers
foreach (var world in ownedWorlds)
{
int versionsCompared = SemVersion.Parse(gameVersion, SemVersionStyles.Strict).ComparePrecedenceTo(SemVersion.Parse(world.ActiveVersion, SemVersionStyles.Strict));
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
int versionsCompared = SemVersion.Parse(gameVersion, SemVersionStyles.Strict).ComparePrecedenceTo(SemVersion.Parse(activeSlot?.Version ?? gameVersion, SemVersionStyles.Strict));
string isCompatible = versionsCompared == 0 ? "COMPATIBLE" : versionsCompared < 0 ? "NEEDS_DOWNGRADE" : "NEEDS_UPGRADE";
WorldResponse response = new()
@ -82,7 +83,7 @@ namespace Minecraft_Realms_Emulator.Controllers
ActiveSlot = world.ActiveSlot,
Member = world.Member,
Players = world.Players,
ActiveVersion = world.ActiveVersion,
ActiveVersion = activeSlot?.Version ?? gameVersion,
Compatibility = isCompatible
};
@ -98,7 +99,9 @@ namespace Minecraft_Realms_Emulator.Controllers
foreach (var world in memberWorlds)
{
int versionsCompared = SemVersion.Parse(gameVersion, SemVersionStyles.OptionalPatch).ComparePrecedenceTo(SemVersion.Parse(world.ActiveVersion, SemVersionStyles.OptionalPatch));
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
int versionsCompared = SemVersion.Parse(gameVersion, SemVersionStyles.OptionalPatch).ComparePrecedenceTo(SemVersion.Parse(activeSlot.Version, SemVersionStyles.OptionalPatch));
string isCompatible = versionsCompared == 0 ? "COMPATIBLE" : versionsCompared < 0 ? "NEEDS_DOWNGRADE" : "NEEDS_UPGRADE";
WorldResponse response = new()
@ -120,7 +123,7 @@ namespace Minecraft_Realms_Emulator.Controllers
DaysLeft = 0,
Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0,
ExpiredTrial = false,
ActiveVersion = world.ActiveVersion,
ActiveVersion = activeSlot.Version,
Compatibility = isCompatible
};
@ -141,13 +144,40 @@ namespace Minecraft_Realms_Emulator.Controllers
string cookie = Request.Headers.Cookie;
string gameVersion = cookie.Split(";")[2].Split("=")[1];
var world = await _context.Worlds.Include(w => w.Players).Include(w => w.Subscription).FirstOrDefaultAsync(w => w.Id == id);
var world = await _context.Worlds.Include(w => w.Players).Include(w => w.Subscription).Include(w => w.Slots).FirstOrDefaultAsync(w => w.Id == id);
if (world?.Subscription == null) return NotFound("World not found");
int versionsCompared = SemVersion.Parse(gameVersion, SemVersionStyles.OptionalPatch).ComparePrecedenceTo(SemVersion.Parse(world.ActiveVersion, SemVersionStyles.OptionalPatch));
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
int versionsCompared = SemVersion.Parse(gameVersion, SemVersionStyles.OptionalPatch).ComparePrecedenceTo(SemVersion.Parse(activeSlot.Version, SemVersionStyles.OptionalPatch));
string isCompatible = versionsCompared == 0 ? "COMPATIBLE" : versionsCompared < 0 ? "NEEDS_DOWNGRADE" : "NEEDS_UPGRADE";
List<SlotsResponse> slots = [];
foreach (var slot in world.Slots)
{
slots.Add(new SlotsResponse()
{
SlotId = slot.SlotId,
Options = JsonConvert.SerializeObject(new
{
slotName = slot.SlotName,
gameMode = slot.GameMode,
difficulty = slot.Difficulty,
spawnProtection = slot.SpawnProtection,
forceGameMode = slot.ForceGameMode,
pvp = slot.Pvp,
spawnAnimals = slot.SpawnAnimals,
spawnMonsters = slot.SpawnMonsters,
spawnNPCs = slot.SpawnNPCs,
commandBlocks = slot.CommandBlocks,
version = slot.Version,
compatibility = isCompatible
})
});
}
WorldResponse response = new()
{
Id = world.Id,
@ -162,13 +192,13 @@ namespace Minecraft_Realms_Emulator.Controllers
MinigameName = world.MinigameName,
MinigameImage = world.MinigameImage,
ActiveSlot = world.ActiveSlot,
Slots = world.Slots,
Slots = slots,
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,
ActiveVersion = world.ActiveVersion,
ActiveVersion = activeSlot.Version,
Compatibility = isCompatible
};
@ -178,6 +208,9 @@ namespace Minecraft_Realms_Emulator.Controllers
[HttpPost("{id}/initialize")]
public async Task<ActionResult<World>> Initialize(int id, WorldCreateRequest body)
{
string cookie = Request.Headers.Cookie;
string gameVersion = cookie.Split(";")[2].Split("=")[1];
var worlds = await _context.Worlds.ToListAsync();
var world = worlds.Find(w => w.Id == id);
@ -204,10 +237,28 @@ namespace Minecraft_Realms_Emulator.Controllers
Address = JsonConvert.DeserializeObject(defaultServerAddress.Value)
};
Slot slot = new()
{
World = world,
SlotId = 1,
SlotName = "",
Version = gameVersion,
GameMode = 0,
Difficulty = 2,
SpawnProtection = 0,
ForceGameMode = false,
Pvp = true,
SpawnAnimals = true,
SpawnMonsters = true,
SpawnNPCs = true,
CommandBlocks = false
};
_context.Worlds.Update(world);
_context.Subscriptions.Add(subscription);
_context.Connections.Add(connection);
_context.Slots.Add(slot);
_context.SaveChanges();
@ -271,9 +322,31 @@ namespace Minecraft_Realms_Emulator.Controllers
}
[HttpPost("{wId}/slot/{sId}")]
public bool U(int wId, int sId, object o)
public async Task<ActionResult<bool>> UpdateSlotAsync(int wId, int sId, SlotOptionsRequest body)
{
Console.WriteLine(o);
var slots = await _context.Slots.Where(s => s.World.Id == wId).ToListAsync();
var slot = slots.Find(s => s.SlotId == sId);
slot.SlotName = body.SlotName;
slot.GameMode = body.GameMode;
slot.Difficulty = body.Difficulty;
slot.SpawnProtection = body.SpawnProtection;
slot.ForceGameMode = body.ForceGameMode;
slot.Pvp = body.Pvp;
slot.SpawnAnimals = body.SpawnAnimals;
slot.SpawnMonsters = body.SpawnMonsters;
slot.SpawnNPCs = body.SpawnNPCs;
slot.CommandBlocks = body.CommandBlocks;
_context.SaveChanges();
return Ok(true);
}
[HttpPut("{wId}/slot/{sId}")]
public bool SwitchSlot(int wId, int sId)
{
Console.WriteLine($"Switching world {wId} to slot {sId}");
return true;
}

View File

@ -12,5 +12,6 @@ namespace Minecraft_Realms_Emulator.Data
public DbSet<Invite> Invites { get; set; }
public DbSet<Player> Players { get; set; }
public DbSet<Configuration> Configuration { get; set; }
public DbSet<Slot> Slots { get; set; }
}
}

View File

@ -1,8 +1,11 @@
namespace Minecraft_Realms_Emulator.Entities
using Minecraft_Realms_Emulator.Requests;
namespace Minecraft_Realms_Emulator.Entities
{
public class Slot
public class Slot : SlotOptionsRequest
{
public int Id { get; set; }
public World World { get; set; } = null!;
public int SlotId { get; set; }
public string Options { get; set; } = "{}";
}
}

View File

@ -1,6 +1,4 @@
using System.Text.Json;
namespace Minecraft_Realms_Emulator.Entities
namespace Minecraft_Realms_Emulator.Entities
{
public class World
{
@ -18,8 +16,7 @@ namespace Minecraft_Realms_Emulator.Entities
public int? MinigameId { get; set; }
public string? MinigameImage { get; set; }
public int ActiveSlot { get; set; } = 1;
public JsonDocument[] Slots { get; set; } = [];
public List<Slot> Slots { get; set; } = [];
public bool Member { get; set; } = false;
public string ActiveVersion { get; set; } = null!;
}
}

View File

@ -0,0 +1,382 @@
// <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("20240521071345_Slots_Table")]
partial class Slots_Table
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.4")
.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.Slot", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("CommandBlocks")
.HasColumnType("boolean");
b.Property<int>("Difficulty")
.HasColumnType("integer");
b.Property<bool>("ForceGameMode")
.HasColumnType("boolean");
b.Property<int>("GameMode")
.HasColumnType("integer");
b.Property<bool>("Pvp")
.HasColumnType("boolean");
b.Property<int>("SlotId")
.HasColumnType("integer");
b.Property<string>("SlotName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("SpawnAnimals")
.HasColumnType("boolean");
b.Property<bool>("SpawnMonsters")
.HasColumnType("boolean");
b.Property<bool>("SpawnNPCs")
.HasColumnType("boolean");
b.Property<int>("SpawnProtection")
.HasColumnType("integer");
b.Property<string>("Version")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Slots");
});
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<string>("ActiveVersion")
.IsRequired()
.HasColumnType("text");
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>("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.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.Navigation("Players");
b.Navigation("Slots");
b.Navigation("Subscription");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,70 @@
using System.Text.Json;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Slots_Table : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Slots",
table: "Worlds");
migrationBuilder.CreateTable(
name: "Slots",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
WorldId = table.Column<int>(type: "integer", nullable: false),
SlotId = table.Column<int>(type: "integer", nullable: false),
SlotName = table.Column<string>(type: "text", nullable: false),
Version = table.Column<string>(type: "text", nullable: false),
GameMode = table.Column<int>(type: "integer", nullable: false),
Difficulty = table.Column<int>(type: "integer", nullable: false),
SpawnProtection = table.Column<int>(type: "integer", nullable: false),
ForceGameMode = table.Column<bool>(type: "boolean", nullable: false),
Pvp = table.Column<bool>(type: "boolean", nullable: false),
SpawnAnimals = table.Column<bool>(type: "boolean", nullable: false),
SpawnMonsters = table.Column<bool>(type: "boolean", nullable: false),
SpawnNPCs = table.Column<bool>(type: "boolean", nullable: false),
CommandBlocks = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Slots", x => x.Id);
table.ForeignKey(
name: "FK_Slots_Worlds_WorldId",
column: x => x.WorldId,
principalTable: "Worlds",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Slots_WorldId",
table: "Slots",
column: "WorldId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Slots");
migrationBuilder.AddColumn<JsonDocument[]>(
name: "Slots",
table: "Worlds",
type: "jsonb[]",
nullable: false,
defaultValue: new JsonDocument[0]);
}
}
}

View File

@ -0,0 +1,378 @@
// <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("20240521080804_World_ActiveVersion_From_Slot")]
partial class World_ActiveVersion_From_Slot
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.4")
.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.Slot", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("CommandBlocks")
.HasColumnType("boolean");
b.Property<int>("Difficulty")
.HasColumnType("integer");
b.Property<bool>("ForceGameMode")
.HasColumnType("boolean");
b.Property<int>("GameMode")
.HasColumnType("integer");
b.Property<bool>("Pvp")
.HasColumnType("boolean");
b.Property<int>("SlotId")
.HasColumnType("integer");
b.Property<string>("SlotName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("SpawnAnimals")
.HasColumnType("boolean");
b.Property<bool>("SpawnMonsters")
.HasColumnType("boolean");
b.Property<bool>("SpawnNPCs")
.HasColumnType("boolean");
b.Property<int>("SpawnProtection")
.HasColumnType("integer");
b.Property<string>("Version")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Slots");
});
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<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.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.Navigation("Players");
b.Navigation("Slots");
b.Navigation("Subscription");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class World_ActiveVersion_From_Slot : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ActiveVersion",
table: "Worlds");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "ActiveVersion",
table: "Worlds",
type: "text",
nullable: false,
defaultValue: "");
}
}
}

View File

@ -162,6 +162,62 @@ namespace Minecraft_Realms_Emulator.Migrations
b.ToTable("Players");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Slot", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("CommandBlocks")
.HasColumnType("boolean");
b.Property<int>("Difficulty")
.HasColumnType("integer");
b.Property<bool>("ForceGameMode")
.HasColumnType("boolean");
b.Property<int>("GameMode")
.HasColumnType("integer");
b.Property<bool>("Pvp")
.HasColumnType("boolean");
b.Property<int>("SlotId")
.HasColumnType("integer");
b.Property<string>("SlotName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("SpawnAnimals")
.HasColumnType("boolean");
b.Property<bool>("SpawnMonsters")
.HasColumnType("boolean");
b.Property<bool>("SpawnNPCs")
.HasColumnType("boolean");
b.Property<int>("SpawnProtection")
.HasColumnType("integer");
b.Property<string>("Version")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Slots");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b =>
{
b.Property<int>("Id")
@ -199,10 +255,6 @@ namespace Minecraft_Realms_Emulator.Migrations
b.Property<int>("ActiveSlot")
.HasColumnType("integer");
b.Property<string>("ActiveVersion")
.IsRequired()
.HasColumnType("text");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
@ -230,10 +282,6 @@ namespace Minecraft_Realms_Emulator.Migrations
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<JsonDocument[]>("Slots")
.IsRequired()
.HasColumnType("jsonb[]");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
@ -291,6 +339,17 @@ namespace Minecraft_Realms_Emulator.Migrations
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")
@ -306,6 +365,8 @@ namespace Minecraft_Realms_Emulator.Migrations
{
b.Navigation("Players");
b.Navigation("Slots");
b.Navigation("Subscription");
});
#pragma warning restore 612, 618

View File

@ -0,0 +1,17 @@
namespace Minecraft_Realms_Emulator.Requests
{
public class SlotOptionsRequest
{
public string SlotName { get; set; } = null!;
public string Version { get; set; } = null!;
public int GameMode { get; set; }
public int Difficulty { get; set; }
public int SpawnProtection { get; set; }
public bool ForceGameMode { get; set; }
public bool Pvp { get; set; }
public bool SpawnAnimals { get; set; }
public bool SpawnMonsters { get; set; }
public bool SpawnNPCs { get; set; }
public bool CommandBlocks { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace Minecraft_Realms_Emulator.Responses
{
public class SlotsResponse
{
public int SlotId { get; set; }
public string Options { get; set; } = null!;
}
}

View File

@ -1,4 +1,6 @@
namespace Minecraft_Realms_Emulator.Entities
using Minecraft_Realms_Emulator.Responses;
namespace Minecraft_Realms_Emulator.Entities
{
public class WorldResponse : World
{
@ -7,5 +9,7 @@
public bool Expired { get; set; } = false;
public bool ExpiredTrial { get; set; } = false;
public string Compatibility { get; set; } = null!;
public List<SlotsResponse> Slots { get; set; } = null!;
public string ActiveVersion { get; set; } = null!;
}
}