Compare commits

...

46 Commits

Author SHA1 Message Date
ff325cf5f6 fix: update game version on slot if server has updates enabled 2024-12-19 21:06:02 +01:00
484d12463a feat: update server on start 2024-12-19 15:08:41 +01:00
0a89b6ade1 fix: logs in admin panel 2024-12-18 14:00:05 +01:00
967518dc71 oops 2024-12-14 19:36:38 +01:00
1dc7194888 fix: wait until the server is closed before returning 2024-12-14 19:30:06 +01:00
84548585ac refactor: move WorkMode setting to environment variable 2024-12-14 15:07:42 +01:00
f1a5ddd98c chore: remove non-related routes from external mode 2024-12-14 14:58:57 +01:00
6cb43fcaa3 fix: force delete server container on realm deletion 2024-12-14 14:06:30 +01:00
27a5d20888 fix: uninitialized worlds 2024-12-14 13:52:45 +01:00
b0ed4a50de fix: include minigame data on all world routes 2024-12-13 21:44:51 +01:00
8c72940c23 fix: minigane name on world configuration screen 2024-12-13 21:41:33 +01:00
4605ac5fef fix: world slots 2024-12-13 21:16:34 +01:00
54a05537c4 refactor: fix motd showing as "..." on minecraft >1.21.1, SlotsResponse.Options now has proper typing 2024-12-09 23:05:35 +01:00
d302ea46e2 refactor: move shared code to Shared directory 2024-12-09 14:30:18 +01:00
92a9177d1f create unit tests 2024-10-20 20:49:15 +02:00
c2f62fdffb fix: check if world is initialized 2024-10-20 14:26:30 +02:00
83c43ce73d make remoteSubscriptionId dummy 2024-10-20 14:22:47 +02:00
9f64fb6c82 fix: don't create world in /{wId}/createPrereleaseRealm route 2024-09-30 13:28:18 +02:00
71db9fc549 chore: update packages 2024-09-29 18:51:55 +02:00
3f100aadf6 chore: update packages 2024-08-30 09:04:47 +02:00
3ef9962bac chore: update packages 2024-07-31 16:52:52 +02:00
22ee98584b feat(sevrer): use stop command for the StopServer function 2024-07-16 17:41:21 +02:00
de45bf843e fix(server): updating realm with empty description should work now 2024-07-14 21:07:49 +02:00
f133c237ef feat(server): Get server's address from its MOTD in external mode 2024-07-14 18:16:15 +02:00
fe1c7aaf63 fix: setting rcon password for rcon-cli 2024-07-07 15:56:19 +02:00
b6a73df815 feat: change world on slot switch 2024-07-07 14:14:21 +02:00
cbecb21ea3 feat: entrypoint 2024-07-07 12:59:32 +02:00
1a3804e865 feat: make reset world work 2024-07-07 11:01:49 +02:00
28e678bce9 feat(server): attempt to op the realm owner on join 2024-07-06 18:09:07 +02:00
50042e96ad chore: update packages 2024-07-06 12:50:51 +02:00
c1353de565 feat: start server if stopped on join 2024-07-06 10:24:45 +02:00
640cc80758 feat: wait for server to be accessible on open 2024-07-06 09:06:00 +02:00
7bc0169dda feat: rcon 2024-07-05 22:05:08 +02:00
07ae7c6777 feat(server): worlds backup downloading 2024-06-30 18:31:27 +02:00
83f4a59707 feat: minigames 2024-06-30 14:53:33 +02:00
c40e29b971 fix: snapshot realms subscription, creating snapshot realms 2024-06-30 09:55:47 +02:00
54953fbd6c feat(server): snapshot worlds 2024-06-29 21:34:42 +02:00
4b7eec2057 feat: MinecraftVersionParser 2024-06-29 14:04:23 +02:00
11444c75b1 feat: more settings (OnlineMode, AutomaticRealmsCreation) 2024-06-25 08:54:11 +02:00
f9f07756ac feat: online player list 2024-06-14 09:26:55 +02:00
483bafcbf2 feat: don't send seen notifications 2024-06-12 10:06:48 +02:00
afb6a4730c feat: notifications 2024-06-11 22:41:05 +02:00
ece3d3825f feat: world templates 2024-06-11 20:21:13 +02:00
a6b70a0686 feat: error handling in POST /worlds/{id} and POST /worlds/{wId}/slot/{sId} 2024-06-11 17:45:00 +02:00
26fa8813dd feat: error class, world checking middleware 2024-06-10 14:22:26 +02:00
4a27cc028e feat(server): docker engine check before launching in REALMS mode 2024-06-07 09:38:27 +02:00
117 changed files with 5704 additions and 420 deletions

View File

@ -5,7 +5,9 @@ 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
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Panel", "Panel\Panel.csproj", "{DDDF0FE0-736D-47D5-8571-3DD7354B7917}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Panel", "Panel\Panel.csproj", "{DDDF0FE0-736D-47D5-8571-3DD7354B7917}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "UnitTests\UnitTests.csproj", "{AFF83C8C-B6CA-4707-A26E-82002822F820}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -21,6 +23,10 @@ Global
{DDDF0FE0-736D-47D5-8571-3DD7354B7917}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDDF0FE0-736D-47D5-8571-3DD7354B7917}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DDDF0FE0-736D-47D5-8571-3DD7354B7917}.Release|Any CPU.Build.0 = Release|Any CPU
{AFF83C8C-B6CA-4707-A26E-82002822F820}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AFF83C8C-B6CA-4707-A26E-82002822F820}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AFF83C8C-B6CA-4707-A26E-82002822F820}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AFF83C8C-B6CA-4707-A26E-82002822F820}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -1,14 +0,0 @@
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

@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@ -0,0 +1,422 @@
// <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.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20240611172843_Templates")]
partial class Templates
{
/// <inheritdoc />
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<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.Template", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Author")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Image")
.HasColumnType("text");
b.Property<string>("Link")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecommendedPlayers")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Trailer")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Version")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Templates");
});
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,42 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Templates : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Templates",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
Version = table.Column<string>(type: "text", nullable: false),
Author = table.Column<string>(type: "text", nullable: false),
Link = table.Column<string>(type: "text", nullable: false),
Image = table.Column<string>(type: "text", nullable: true),
Trailer = table.Column<string>(type: "text", nullable: false),
RecommendedPlayers = table.Column<string>(type: "text", nullable: false),
Type = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Templates", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Templates");
}
}
}

View File

@ -0,0 +1,465 @@
// <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.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20240611201421_Notifications")]
partial class Notifications
{
/// <inheritdoc />
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<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.Notification", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<JsonDocument>("ButtonText")
.HasColumnType("jsonb");
b.Property<bool>("Dismissable")
.HasColumnType("boolean");
b.Property<string>("Image")
.HasColumnType("text");
b.Property<JsonDocument>("Message")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("NotificationUuid")
.IsRequired()
.HasColumnType("text");
b.Property<JsonDocument>("Title")
.HasColumnType("jsonb");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.HasColumnType("text");
b.Property<JsonDocument>("UrlButton")
.HasColumnType("jsonb");
b.HasKey("Id");
b.ToTable("Notifications");
});
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.Template", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Author")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Image")
.HasColumnType("text");
b.Property<string>("Link")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecommendedPlayers")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Trailer")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Version")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Templates");
});
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,44 @@
using System.Text.Json;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Notifications : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Notifications",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
NotificationUuid = table.Column<string>(type: "text", nullable: false),
Dismissable = table.Column<bool>(type: "boolean", nullable: false),
Type = table.Column<string>(type: "text", nullable: false),
Title = table.Column<JsonDocument>(type: "jsonb", nullable: true),
Message = table.Column<JsonDocument>(type: "jsonb", nullable: false),
Image = table.Column<string>(type: "text", nullable: true),
UrlButton = table.Column<JsonDocument>(type: "jsonb", nullable: true),
Url = table.Column<string>(type: "text", nullable: true),
ButtonText = table.Column<JsonDocument>(type: "jsonb", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Notifications", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Notifications");
}
}
}

View File

@ -0,0 +1,486 @@
// <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.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20240612072111_SeenNotifications")]
partial class SeenNotifications
{
/// <inheritdoc />
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<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.Notification", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<JsonDocument>("ButtonText")
.HasColumnType("jsonb");
b.Property<bool>("Dismissable")
.HasColumnType("boolean");
b.Property<string>("Image")
.HasColumnType("text");
b.Property<JsonDocument>("Message")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("NotificationUuid")
.IsRequired()
.HasColumnType("text");
b.Property<JsonDocument>("Title")
.HasColumnType("jsonb");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.HasColumnType("text");
b.Property<JsonDocument>("UrlButton")
.HasColumnType("jsonb");
b.HasKey("Id");
b.ToTable("Notifications");
});
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.SeenNotification", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("NotificationUUID")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PlayerUUID")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("SeenNotifications");
});
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.Template", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Author")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Image")
.HasColumnType("text");
b.Property<string>("Link")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecommendedPlayers")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Trailer")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Version")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Templates");
});
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,36 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class SeenNotifications : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "SeenNotifications",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
PlayerUUID = table.Column<string>(type: "text", nullable: false),
NotificationUUID = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SeenNotifications", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "SeenNotifications");
}
}
}

View File

@ -0,0 +1,500 @@
// <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.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20240629161935_Snapshot_Worlds")]
partial class Snapshot_Worlds
{
/// <inheritdoc />
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<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.Notification", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<JsonDocument>("ButtonText")
.HasColumnType("jsonb");
b.Property<bool>("Dismissable")
.HasColumnType("boolean");
b.Property<string>("Image")
.HasColumnType("text");
b.Property<JsonDocument>("Message")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("NotificationUuid")
.IsRequired()
.HasColumnType("text");
b.Property<JsonDocument>("Title")
.HasColumnType("jsonb");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.HasColumnType("text");
b.Property<JsonDocument>("UrlButton")
.HasColumnType("jsonb");
b.HasKey("Id");
b.ToTable("Notifications");
});
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.SeenNotification", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("NotificationUUID")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PlayerUUID")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("SeenNotifications");
});
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.Template", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Author")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Image")
.HasColumnType("text");
b.Property<string>("Link")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecommendedPlayers")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Trailer")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Version")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Templates");
});
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<int?>("ParentWorldId")
.HasColumnType("integer");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
b.Property<string>("WorldType")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
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.World", "ParentWorld")
.WithMany()
.HasForeignKey("ParentWorldId");
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
}
}
}

View File

@ -0,0 +1,48 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Snapshot_Worlds : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "ParentWorldId",
table: "Worlds",
type: "integer",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_Worlds_ParentWorldId",
table: "Worlds",
column: "ParentWorldId");
migrationBuilder.AddForeignKey(
name: "FK_Worlds_Worlds_ParentWorldId",
table: "Worlds",
column: "ParentWorldId",
principalTable: "Worlds",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Worlds_Worlds_ParentWorldId",
table: "Worlds");
migrationBuilder.DropIndex(
name: "IX_Worlds_ParentWorldId",
table: "Worlds");
migrationBuilder.DropColumn(
name: "ParentWorldId",
table: "Worlds");
}
}
}

View File

@ -0,0 +1,502 @@
// <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.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20240630120218_Minigames")]
partial class Minigames
{
/// <inheritdoc />
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<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.Notification", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<JsonDocument>("ButtonText")
.HasColumnType("jsonb");
b.Property<bool>("Dismissable")
.HasColumnType("boolean");
b.Property<string>("Image")
.HasColumnType("text");
b.Property<JsonDocument>("Message")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("NotificationUuid")
.IsRequired()
.HasColumnType("text");
b.Property<JsonDocument>("Title")
.HasColumnType("jsonb");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.HasColumnType("text");
b.Property<JsonDocument>("UrlButton")
.HasColumnType("jsonb");
b.HasKey("Id");
b.ToTable("Notifications");
});
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.SeenNotification", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("NotificationUUID")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PlayerUUID")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("SeenNotifications");
});
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.Template", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Author")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Image")
.HasColumnType("text");
b.Property<string>("Link")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecommendedPlayers")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Trailer")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Version")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Templates");
});
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>("Motd")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<int?>("ParentWorldId")
.HasColumnType("integer");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,58 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Minigames : Migration
{
/// <inheritdoc />
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");
}
/// <inheritdoc />
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<string>(
name: "MinigameImage",
table: "Worlds",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "MinigameName",
table: "Worlds",
type: "text",
nullable: true);
}
}
}

View File

@ -0,0 +1,512 @@
// <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.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20240630160411_Backup_Slots")]
partial class Backup_Slots
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("BackupId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("DownloadUrl")
.IsRequired()
.HasColumnType("text");
b.Property<long>("LastModifiedDate")
.HasColumnType("bigint");
b.Property<JsonDocument>("Metadata")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("ResourcePackHash")
.HasColumnType("text");
b.Property<string>("ResourcePackUrl")
.HasColumnType("text");
b.Property<int>("Size")
.HasColumnType("integer");
b.Property<int>("SlotId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("SlotId");
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.Notification", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<JsonDocument>("ButtonText")
.HasColumnType("jsonb");
b.Property<bool>("Dismissable")
.HasColumnType("boolean");
b.Property<string>("Image")
.HasColumnType("text");
b.Property<JsonDocument>("Message")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("NotificationUuid")
.IsRequired()
.HasColumnType("text");
b.Property<JsonDocument>("Title")
.HasColumnType("jsonb");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.HasColumnType("text");
b.Property<JsonDocument>("UrlButton")
.HasColumnType("jsonb");
b.HasKey("Id");
b.ToTable("Notifications");
});
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.SeenNotification", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("NotificationUUID")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PlayerUUID")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("SeenNotifications");
});
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.Template", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Author")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Image")
.HasColumnType("text");
b.Property<string>("Link")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecommendedPlayers")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Trailer")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Version")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Templates");
});
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>("Motd")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<int?>("ParentWorldId")
.HasColumnType("integer");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
b.Property<string>("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.Slot", "Slot")
.WithMany()
.HasForeignKey("SlotId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Slot");
});
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
}
}
}

View File

@ -0,0 +1,93 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Backup_Slots : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Backups_Worlds_WorldId",
table: "Backups");
migrationBuilder.RenameColumn(
name: "WorldId",
table: "Backups",
newName: "SlotId");
migrationBuilder.RenameIndex(
name: "IX_Backups_WorldId",
table: "Backups",
newName: "IX_Backups_SlotId");
migrationBuilder.AddColumn<string>(
name: "DownloadUrl",
table: "Backups",
type: "text",
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<string>(
name: "ResourcePackHash",
table: "Backups",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "ResourcePackUrl",
table: "Backups",
type: "text",
nullable: true);
migrationBuilder.AddForeignKey(
name: "FK_Backups_Slots_SlotId",
table: "Backups",
column: "SlotId",
principalTable: "Slots",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Backups_Slots_SlotId",
table: "Backups");
migrationBuilder.DropColumn(
name: "DownloadUrl",
table: "Backups");
migrationBuilder.DropColumn(
name: "ResourcePackHash",
table: "Backups");
migrationBuilder.DropColumn(
name: "ResourcePackUrl",
table: "Backups");
migrationBuilder.RenameColumn(
name: "SlotId",
table: "Backups",
newName: "WorldId");
migrationBuilder.RenameIndex(
name: "IX_Backups_SlotId",
table: "Backups",
newName: "IX_Backups_WorldId");
migrationBuilder.AddForeignKey(
name: "FK_Backups_Worlds_WorldId",
table: "Backups",
column: "WorldId",
principalTable: "Worlds",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}

View File

@ -4,7 +4,7 @@ using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Shared.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
@ -18,7 +18,7 @@ namespace Minecraft_Realms_Emulator.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.4")
.HasAnnotation("ProductVersion", "8.0.5")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@ -35,6 +35,10 @@ namespace Minecraft_Realms_Emulator.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<string>("DownloadUrl")
.IsRequired()
.HasColumnType("text");
b.Property<long>("LastModifiedDate")
.HasColumnType("bigint");
@ -42,15 +46,21 @@ namespace Minecraft_Realms_Emulator.Migrations
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("ResourcePackHash")
.HasColumnType("text");
b.Property<string>("ResourcePackUrl")
.HasColumnType("text");
b.Property<int>("Size")
.HasColumnType("integer");
b.Property<int>("WorldId")
b.Property<int>("SlotId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.HasIndex("SlotId");
b.ToTable("Backups");
});
@ -123,6 +133,49 @@ namespace Minecraft_Realms_Emulator.Migrations
b.ToTable("Invites");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Notification", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<JsonDocument>("ButtonText")
.HasColumnType("jsonb");
b.Property<bool>("Dismissable")
.HasColumnType("boolean");
b.Property<string>("Image")
.HasColumnType("text");
b.Property<JsonDocument>("Message")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("NotificationUuid")
.IsRequired()
.HasColumnType("text");
b.Property<JsonDocument>("Title")
.HasColumnType("jsonb");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.HasColumnType("text");
b.Property<JsonDocument>("UrlButton")
.HasColumnType("jsonb");
b.HasKey("Id");
b.ToTable("Notifications");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b =>
{
b.Property<int>("Id")
@ -162,6 +215,27 @@ namespace Minecraft_Realms_Emulator.Migrations
b.ToTable("Players");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.SeenNotification", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("NotificationUUID")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PlayerUUID")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("SeenNotifications");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Slot", b =>
{
b.Property<int>("Id")
@ -244,6 +318,50 @@ namespace Minecraft_Realms_Emulator.Migrations
b.ToTable("Subscriptions");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Template", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Author")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Image")
.HasColumnType("text");
b.Property<string>("Link")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecommendedPlayers")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Trailer")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Version")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Templates");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b =>
{
b.Property<int>("Id")
@ -264,12 +382,6 @@ namespace Minecraft_Realms_Emulator.Migrations
b.Property<int?>("MinigameId")
.HasColumnType("integer");
b.Property<string>("MinigameImage")
.HasColumnType("text");
b.Property<string>("MinigameName")
.HasColumnType("text");
b.Property<string>("Motd")
.HasColumnType("text");
@ -282,6 +394,9 @@ namespace Minecraft_Realms_Emulator.Migrations
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<int?>("ParentWorldId")
.HasColumnType("integer");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
@ -292,18 +407,22 @@ namespace Minecraft_Realms_Emulator.Migrations
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")
b.HasOne("Minecraft_Realms_Emulator.Entities.Slot", "Slot")
.WithMany()
.HasForeignKey("WorldId")
.HasForeignKey("SlotId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("World");
b.Navigation("Slot");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b =>
@ -361,6 +480,21 @@ namespace Minecraft_Realms_Emulator.Migrations
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");

View File

@ -10,19 +10,23 @@
<ItemGroup>
<EmbeddedResource Include="Resources\files\template\Dockerfile" />
<EmbeddedResource Include="Resources\files\template\entrypoint" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DotNetEnv" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.5">
<PackageReference Include="DotNetEnv" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
<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.4" />
<PackageReference Include="Semver" Version="2.3.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.8" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.8.0" />
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="UnitTests" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Mvc;
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Responses;
namespace Minecraft_Realms_Emulator.Modes.External
{
[Route("modes/external/[controller]")]
[ApiController]
[RequireMinecraftCookie]
public class ActivitiesController : ControllerBase
{
[HttpGet("liveplayerlist")]
public ActionResult<LivePlayerListsResponse> GetLivePlayerList()
{
LivePlayerListsResponse response = new()
{
Lists = []
};
return Ok(response);
}
}
}

View File

@ -1,10 +1,10 @@
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 Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Entities;
using Minecraft_Realms_Emulator.Shared.Requests;
using Minecraft_Realms_Emulator.Shared.Responses;
namespace Minecraft_Realms_Emulator.Modes.External
{
@ -94,6 +94,7 @@ namespace Minecraft_Realms_Emulator.Modes.External
}
[HttpPost("{wId}")]
[CheckForWorld]
[CheckRealmOwner]
public async Task<ActionResult<World>> InvitePlayer(int wId, PlayerRequest body)
{
@ -104,8 +105,6 @@ namespace Minecraft_Realms_Emulator.Modes.External
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}");
@ -138,13 +137,12 @@ namespace Minecraft_Realms_Emulator.Modes.External
}
[HttpDelete("{wId}/invite/{uuid}")]
[CheckForWorld]
[CheckRealmOwner]
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);
@ -159,6 +157,7 @@ namespace Minecraft_Realms_Emulator.Modes.External
}
[HttpDelete("{wId}")]
[CheckForWorld]
public async Task<ActionResult<bool>> LeaveWorld(int wId)
{
string cookie = Request.Headers.Cookie;
@ -166,8 +165,6 @@ namespace Minecraft_Realms_Emulator.Modes.External
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);

View File

@ -1,9 +1,9 @@
using Microsoft.AspNetCore.Mvc;
using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Enums;
using Minecraft_Realms_Emulator.Helpers;
using Minecraft_Realms_Emulator.Responses;
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Enums;
using Minecraft_Realms_Emulator.Shared.Helpers;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Responses;
namespace Minecraft_Realms_Emulator.Modes.External
{
@ -20,8 +20,23 @@ namespace Minecraft_Realms_Emulator.Modes.External
}
[HttpGet("available")]
public ActionResult<bool> GetAvailable()
public async Task<ActionResult<bool>> GetAvailable()
{
if (new ConfigHelper(_context).GetSetting(nameof(SettingsEnum.OnlineMode)).Value)
{
string cookie = Request.Headers.Cookie;
string playerUUID = cookie.Split(";")[0].Split(":")[2];
try
{
await new HttpClient().GetFromJsonAsync<MinecraftPlayerInfo>($"https://sessionserver.mojang.com/session/minecraft/profile/{playerUUID}");
}
catch
{
return Unauthorized();
}
}
return Ok(true);
}

View File

@ -0,0 +1,102 @@
using Microsoft.AspNetCore.Mvc;
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Entities;
using Minecraft_Realms_Emulator.Shared.Responses;
namespace Minecraft_Realms_Emulator.Modes.External
{
[Route("/modes/external/[controller]")]
[ApiController]
[RequireMinecraftCookie]
public class NotificationsController : ControllerBase
{
private readonly DataContext _context;
public NotificationsController(DataContext context)
{
_context = context;
}
[HttpGet]
public ActionResult<NotificationsResponse> GetNotifications()
{
string cookie = Request.Headers.Cookie;
string playerUUID = cookie.Split(";")[0].Split(":")[2];
List<NotificationResponse> notifications = [];
foreach (var notification in _context.Notifications.ToList())
{
var seen = _context.SeenNotifications.Any(n => n.PlayerUUID == playerUUID && n.NotificationUUID == notification.NotificationUuid);
if (seen)
{
continue;
}
NotificationResponse notificationResponse = new()
{
NotificationUuid = notification.NotificationUuid,
Dismissable = notification.Dismissable,
Seen = seen,
Type = notification.Type,
Title = notification.Title,
Message = notification.Message,
Image = notification.Image,
UrlButton = notification.UrlButton,
Url = notification.Url,
ButtonText = notification.ButtonText,
};
notifications.Add(notificationResponse);
}
NotificationsResponse notificationsResponse = new()
{
Notifications = notifications,
};
return Ok(notificationsResponse);
}
[HttpPost("seen")]
public ActionResult Seen(string[] notificationIds)
{
string cookie = Request.Headers.Cookie;
string playerUUID = cookie.Split(";")[0].Split(":")[2];
if (notificationIds.Length == 0)
{
ErrorResponse errorResponse = new()
{
ErrorCode = 400,
ErrorMsg = "Nothing to mark as seen"
};
return BadRequest(errorResponse);
}
foreach (var notificationId in notificationIds)
{
SeenNotification notificationSeen = new()
{
PlayerUUID = playerUUID,
NotificationUUID = notificationId
};
_context.SeenNotifications.Add(notificationSeen);
}
_context.SaveChanges();
return NoContent();
}
[HttpPost("dismiss")]
public ActionResult Dismiss(string[] notificationIds)
{
return NoContent();
}
}
}

View File

@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Responses;
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Responses;
namespace Minecraft_Realms_Emulator.Modes.External
{
@ -18,6 +18,7 @@ namespace Minecraft_Realms_Emulator.Modes.External
}
[HttpPost("{wId}/{uuid}")]
[CheckForWorld]
[CheckRealmOwner]
public ActionResult<OpsResponse> OpPlayer(int wId, string uuid)
{
@ -47,6 +48,7 @@ namespace Minecraft_Realms_Emulator.Modes.External
}
[HttpDelete("{wId}/{uuid}")]
[CheckForWorld]
[CheckRealmOwner]
public ActionResult<OpsResponse> DeopPlayer(int wId, string uuid)
{

View File

@ -1,8 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Responses;
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Responses;
namespace Minecraft_Realms_Emulator.Modes.External
{
@ -18,10 +18,16 @@ namespace Minecraft_Realms_Emulator.Modes.External
_context = context;
}
[HttpGet("{wId}")]
[CheckForWorld]
[CheckRealmOwner]
public async Task<ActionResult<SubscriptionResponse>> Get(int wId)
{
var world = await _context.Worlds.Include(w => w.Subscription).FirstOrDefaultAsync(w => w.Id == wId);
var world = await _context.Worlds.Include(w => w.Subscription).Include(w => w.ParentWorld.Subscription).FirstOrDefaultAsync(w => w.Id == wId);
if (world.ParentWorld != null)
{
world.Subscription = world.ParentWorld.Subscription;
}
if (world?.Subscription == null) return NotFound("Subscription not found");

View File

@ -1,8 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Enums;
using Minecraft_Realms_Emulator.Helpers;
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Enums;
using Minecraft_Realms_Emulator.Shared.Helpers;
using Minecraft_Realms_Emulator.Shared.Data;
namespace Minecraft_Realms_Emulator.Modes.External
{

View File

@ -1,14 +1,13 @@
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.Enums;
using Minecraft_Realms_Emulator.Helpers;
using Minecraft_Realms_Emulator.Requests;
using Minecraft_Realms_Emulator.Responses;
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Enums;
using Minecraft_Realms_Emulator.Shared.Helpers;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Entities;
using Minecraft_Realms_Emulator.Shared.Requests;
using Minecraft_Realms_Emulator.Shared.Responses;
using Newtonsoft.Json;
using Semver;
namespace Minecraft_Realms_Emulator.Modes.External
{
@ -33,12 +32,12 @@ 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<WorldResponse> allWorlds = [];
if (ownedWorlds.ToArray().Length == 0)
if (ownedWorlds.ToArray().Length == 0 && new ConfigHelper(_context).GetSetting(nameof(SettingsEnum.AutomaticRealmsCreation)).Value)
{
var world = new World
{
@ -49,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
};
@ -66,7 +63,7 @@ namespace Minecraft_Realms_Emulator.Modes.External
{
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
int versionsCompared = SemVersion.Parse(gameVersion, SemVersionStyles.OptionalPatch).ComparePrecedenceTo(SemVersion.Parse(activeSlot?.Version ?? gameVersion, SemVersionStyles.OptionalPatch));
int versionsCompared = new MinecraftVersionParser.MinecraftVersion(gameVersion).CompareTo(new MinecraftVersionParser.MinecraftVersion(activeSlot?.Version ?? gameVersion));
string isCompatible = versionsCompared == 0 ? nameof(CompatibilityEnum.COMPATIBLE) : versionsCompared < 0 ? nameof(CompatibilityEnum.NEEDS_DOWNGRADE) : nameof(CompatibilityEnum.NEEDS_UPGRADE);
WorldResponse response = new()
@ -76,12 +73,11 @@ namespace Minecraft_Realms_Emulator.Modes.External
OwnerUUID = world.OwnerUUID,
Name = world.Name,
Motd = world.Motd,
GameMode = activeSlot?.GameMode ?? 0,
IsHardcore = activeSlot?.Difficulty == 3,
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,
@ -89,6 +85,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;
@ -103,7 +106,7 @@ namespace Minecraft_Realms_Emulator.Modes.External
{
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
int versionsCompared = SemVersion.Parse(gameVersion, SemVersionStyles.OptionalPatch).ComparePrecedenceTo(SemVersion.Parse(activeSlot.Version, SemVersionStyles.OptionalPatch));
int versionsCompared = new MinecraftVersionParser.MinecraftVersion(gameVersion).CompareTo(new MinecraftVersionParser.MinecraftVersion(activeSlot.Version));
string isCompatible = versionsCompared == 0 ? nameof(CompatibilityEnum.COMPATIBLE) : versionsCompared < 0 ? nameof(CompatibilityEnum.NEEDS_DOWNGRADE) : nameof(CompatibilityEnum.NEEDS_UPGRADE);
WorldResponse response = new()
@ -113,12 +116,11 @@ namespace Minecraft_Realms_Emulator.Modes.External
OwnerUUID = world.OwnerUUID,
Name = world.Name,
Motd = world.Motd,
GameMode = activeSlot.GameMode,
IsHardcore = activeSlot.Difficulty == 3,
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,
@ -129,6 +131,275 @@ 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);
}
ServersResponse servers = new()
{
Servers = allWorlds
};
return Ok(servers);
}
[HttpGet("listUserWorldsOfType/any")]
public async Task<ActionResult<ServersResponse>> GetWorldsSnapshot()
{
string cookie = Request.Headers.Cookie;
string playerUUID = cookie.Split(";")[0].Split(":")[2];
string playerName = cookie.Split(";")[1].Split("=")[1];
string gameVersion = cookie.Split(";")[2].Split("=")[1];
var ownedWorlds = await _context.Worlds.Where(w => w.OwnerUUID == playerUUID || w.ParentWorld.OwnerUUID == playerUUID).Include(w => w.Subscription).Include(w => w.Slots).Include(w => w.Minigame).Include(w => w.ParentWorld).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.ParentWorld).Include(p => p.World.Minigame).Select(p => p.World).ToListAsync();
List<WorldResponse> allWorlds = [];
foreach (var world in ownedWorlds)
{
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
int versionsCompared = new MinecraftVersionParser.MinecraftVersion(gameVersion).CompareTo(new MinecraftVersionParser.MinecraftVersion(activeSlot?.Version ?? gameVersion));
string isCompatible = versionsCompared == 0 ? nameof(CompatibilityEnum.COMPATIBLE) : versionsCompared < 0 ? nameof(CompatibilityEnum.NEEDS_DOWNGRADE) : nameof(CompatibilityEnum.NEEDS_UPGRADE);
WorldResponse response = new()
{
Id = world.Id,
Owner = world.Owner,
OwnerUUID = world.OwnerUUID,
Name = world.Name,
Motd = world.Motd,
GameMode = activeSlot?.GameMode ?? 0,
IsHardcore = activeSlot?.Difficulty == 3,
State = world.State,
WorldType = world.WorldType,
MaxPlayers = world.MaxPlayers,
ActiveSlot = world.ActiveSlot,
Member = world.Member,
Players = world.Players,
ActiveVersion = activeSlot?.Version ?? gameVersion,
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;
response.Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0;
response.ExpiredTrial = false;
}
if (world.ParentWorld == null)
{
response.ParentWorldId = -1;
}
if (world.ParentWorld != null)
{
response.Owner = world.ParentWorld.Owner;
response.OwnerUUID = world.ParentWorld.OwnerUUID;
response.ParentWorldId = world.ParentWorld.Id;
response.ParentWorldName = world.ParentWorld.Name;
}
allWorlds.Add(response);
}
foreach (var world in memberWorlds)
{
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
int versionsCompared = new MinecraftVersionParser.MinecraftVersion(gameVersion).CompareTo(new MinecraftVersionParser.MinecraftVersion(activeSlot.Version));
string isCompatible = versionsCompared == 0 ? nameof(CompatibilityEnum.COMPATIBLE) : versionsCompared < 0 ? nameof(CompatibilityEnum.NEEDS_DOWNGRADE) : nameof(CompatibilityEnum.NEEDS_UPGRADE);
WorldResponse response = new()
{
Id = world.Id,
Owner = world.Owner,
OwnerUUID = world.OwnerUUID,
Name = world.Name,
Motd = world.Motd,
GameMode = activeSlot.GameMode,
IsHardcore = activeSlot.Difficulty == 3,
State = world.State,
WorldType = world.WorldType,
MaxPlayers = world.MaxPlayers,
ActiveSlot = world.ActiveSlot,
Member = world.Member,
Players = world.Players,
DaysLeft = 0,
Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0,
ExpiredTrial = false,
ActiveVersion = activeSlot.Version,
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;
}
if (world.ParentWorld != null)
{
response.Owner = world.ParentWorld.Owner;
response.OwnerUUID = world.ParentWorld.OwnerUUID;
response.ParentWorldId = world.ParentWorld.Id;
response.ParentWorldName = world.ParentWorld.Name;
}
allWorlds.Add(response);
}
ServersResponse servers = new()
{
Servers = allWorlds
};
return Ok(servers);
}
[HttpGet("listPrereleaseEligibleWorlds")]
public async Task<ActionResult<ServersResponse>> GetPrereleaseWorlds()
{
string cookie = Request.Headers.Cookie;
string playerUUID = cookie.Split(";")[0].Split(":")[2];
string playerName = cookie.Split(";")[1].Split("=")[1];
string gameVersion = cookie.Split(";")[2].Split("=")[1];
var ownedWorlds = await _context.Worlds.Where(w => w.ParentWorld != null && w.ParentWorld.OwnerUUID == playerUUID).Include(w => w.Subscription).Include(w => w.Slots).Include(w => w.ParentWorld).Include(w => w.Minigame).ToListAsync();
var memberWorlds = await _context.Players.Where(p => p.World.ParentWorld != null && p.Uuid == playerUUID && p.Accepted).Include(p => p.World.Subscription).Include(p => p.World.Slots).Include(p => p.World.ParentWorld).Include(p => p.World.Minigame).Select(p => p.World).ToListAsync();
List<WorldResponse> allWorlds = [];
if (ownedWorlds.ToArray().Length == 0 && new ConfigHelper(_context).GetSetting(nameof(SettingsEnum.AutomaticRealmsCreation)).Value)
{
var parentWorld = _context.Worlds.FirstOrDefault(w => w.OwnerUUID == playerUUID && w.ParentWorld == null);
if (parentWorld != null && parentWorld.State != nameof(StateEnum.UNINITIALIZED))
{
var world = new World
{
Name = parentWorld.Name,
Motd = null,
State = nameof(StateEnum.UNINITIALIZED),
WorldType = nameof(WorldTypeEnum.NORMAL),
MaxPlayers = 10,
Minigame = null,
ActiveSlot = 1,
Member = false,
ParentWorld = parentWorld,
};
ownedWorlds.Add(world);
_context.Worlds.Add(world);
_context.SaveChanges();
}
}
foreach (var world in ownedWorlds)
{
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
int versionsCompared = new MinecraftVersionParser.MinecraftVersion(gameVersion).CompareTo(new MinecraftVersionParser.MinecraftVersion(activeSlot?.Version ?? gameVersion));
string isCompatible = versionsCompared == 0 ? nameof(CompatibilityEnum.COMPATIBLE) : versionsCompared < 0 ? nameof(CompatibilityEnum.NEEDS_DOWNGRADE) : nameof(CompatibilityEnum.NEEDS_UPGRADE);
WorldResponse response = new()
{
Id = world.Id,
Owner = world.Owner,
OwnerUUID = world.OwnerUUID,
Name = world.Name,
Motd = world.Motd,
GameMode = activeSlot?.GameMode ?? 0,
IsHardcore = activeSlot?.Difficulty == 3,
State = world.State,
WorldType = world.WorldType,
MaxPlayers = world.MaxPlayers,
ActiveSlot = world.ActiveSlot,
Member = world.Member,
Players = world.Players,
ActiveVersion = activeSlot?.Version ?? gameVersion,
Compatibility = isCompatible,
ParentWorldId = world.ParentWorld.Id,
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;
response.Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0;
response.ExpiredTrial = false;
}
allWorlds.Add(response);
}
foreach (var world in memberWorlds)
{
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
int versionsCompared = new MinecraftVersionParser.MinecraftVersion(gameVersion).CompareTo(new MinecraftVersionParser.MinecraftVersion(activeSlot.Version));
string isCompatible = versionsCompared == 0 ? nameof(CompatibilityEnum.COMPATIBLE) : versionsCompared < 0 ? nameof(CompatibilityEnum.NEEDS_DOWNGRADE) : nameof(CompatibilityEnum.NEEDS_UPGRADE);
WorldResponse response = new()
{
Id = world.Id,
Owner = world.Owner,
OwnerUUID = world.OwnerUUID,
Name = world.Name,
Motd = world.Motd,
GameMode = activeSlot.GameMode,
IsHardcore = activeSlot.Difficulty == 3,
State = world.State,
WorldType = world.WorldType,
MaxPlayers = world.MaxPlayers,
ActiveSlot = world.ActiveSlot,
Member = world.Member,
Players = world.Players,
DaysLeft = 0,
Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0,
ExpiredTrial = false,
ActiveVersion = activeSlot.Version,
Compatibility = isCompatible
};
if (world.Minigame != null)
{
response.MinigameId = world.Minigame.Id;
response.MinigameName = world.Minigame.Name;
response.MinigameImage = world.Minigame.Image;
}
allWorlds.Add(response);
}
@ -141,15 +412,25 @@ namespace Minecraft_Realms_Emulator.Modes.External
}
[HttpGet("{wId}")]
[CheckForWorld]
[CheckRealmOwner]
public async Task<ActionResult<WorldResponse>> GetWorldById(int wId)
{
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).Include(w => w.Slots).FirstOrDefaultAsync(w => w.Id == wId);
var world = await _context.Worlds.Include(w => w.Players).Include(w => w.Subscription).Include(w => w.Slots).Include(w => w.ParentWorld.Subscription).Include(w => w.Minigame).FirstOrDefaultAsync(w => w.Id == wId);
if (world?.Subscription == null) return NotFound("World not found");
if (world.State == nameof(StateEnum.UNINITIALIZED))
{
ErrorResponse error = new()
{
ErrorCode = 400,
ErrorMsg = "Initialize the world first"
};
return StatusCode(400, error);
}
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
@ -157,7 +438,7 @@ namespace Minecraft_Realms_Emulator.Modes.External
foreach (var slot in world.Slots)
{
int versionsCompared = SemVersion.Parse(gameVersion, SemVersionStyles.OptionalPatch).ComparePrecedenceTo(SemVersion.Parse(slot.Version, SemVersionStyles.OptionalPatch));
int versionsCompared = new MinecraftVersionParser.MinecraftVersion(gameVersion).CompareTo(new MinecraftVersionParser.MinecraftVersion(slot.Version));
string compatibility = versionsCompared == 0 ? nameof(CompatibilityEnum.COMPATIBLE) : versionsCompared < 0 ? nameof(CompatibilityEnum.NEEDS_DOWNGRADE) : nameof(CompatibilityEnum.NEEDS_UPGRADE);
slots.Add(new SlotResponse()
@ -167,8 +448,9 @@ namespace Minecraft_Realms_Emulator.Modes.External
{
slotName = slot.SlotName,
gameMode = slot.GameMode,
hardcore = slot.Difficulty == 3,
difficulty = slot.Difficulty,
spawnProtection = slot.SpawnProtection,
spawnProection = slot.SpawnProtection,
forceGameMode = slot.ForceGameMode,
pvp = slot.Pvp,
spawnAnimals = slot.SpawnAnimals,
@ -183,6 +465,11 @@ namespace Minecraft_Realms_Emulator.Modes.External
var activeSlotOptions = JsonConvert.DeserializeObject<SlotOptionsResponse>(slots.Find(s => s.SlotId == activeSlot.SlotId).Options);
if (world.ParentWorld != null)
{
world.Subscription = world.ParentWorld.Subscription;
}
WorldResponse response = new()
{
Id = world.Id,
@ -190,12 +477,11 @@ namespace Minecraft_Realms_Emulator.Modes.External
OwnerUUID = world.OwnerUUID,
Name = world.Name,
Motd = world.Motd,
GameMode = activeSlot.GameMode,
IsHardcore = activeSlot.GameMode == 3,
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,
@ -207,10 +493,18 @@ 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;
}
[HttpPost("{wId}/initialize")]
[CheckForWorld]
[CheckRealmOwner]
public async Task<ActionResult<World>> Initialize(int wId, WorldCreateRequest body)
{
@ -221,8 +515,16 @@ namespace Minecraft_Realms_Emulator.Modes.External
var world = worlds.Find(w => w.Id == wId);
if (world == null) return NotFound("World not found");
if (world.State != nameof(StateEnum.UNINITIALIZED)) return NotFound("World already initialized");
if (world.State != nameof(StateEnum.UNINITIALIZED))
{
ErrorResponse errorResponse = new()
{
ErrorCode = 401,
ErrorMsg = "World already initialized",
};
return StatusCode(401, errorResponse);
}
var subscription = new Subscription
{
@ -241,7 +543,6 @@ namespace Minecraft_Realms_Emulator.Modes.External
var connection = new Connection
{
World = world,
Address = defaultServerAddress.Value
};
Slot slot = new()
@ -272,15 +573,45 @@ namespace Minecraft_Realms_Emulator.Modes.External
return Ok(world);
}
[HttpPost("{wId}/reset")]
[HttpPost("{wId}/createPrereleaseRealm")]
[CheckForWorld]
[CheckRealmOwner]
public ActionResult<bool> Reset(int wId)
public async Task<ActionResult<World>> CreatePrereleaseRealms(int wId)
{
Console.WriteLine($"Resetting world {wId}");
return Ok(true);
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 == wId);
if (world.ParentWorld.State == nameof(StateEnum.UNINITIALIZED))
{
ErrorResponse errorResponse = new()
{
ErrorCode = 401,
ErrorMsg = "You must initialize release world first",
};
return StatusCode(401, errorResponse);
}
if (world.State != nameof(StateEnum.UNINITIALIZED))
{
ErrorResponse errorResponse = new()
{
ErrorCode = 401,
ErrorMsg = "A prerealease realm is already created for this world",
};
return StatusCode(401, errorResponse);
}
return Ok(world);
}
[HttpPut("{wId}/open")]
[CheckForWorld]
[CheckRealmOwner]
public async Task<ActionResult<bool>> Open(int wId)
{
@ -288,8 +619,6 @@ namespace Minecraft_Realms_Emulator.Modes.External
var world = worlds.Find(w => w.Id == wId);
if (world == null) return NotFound("World not found");
world.State = nameof(StateEnum.OPEN);
_context.SaveChanges();
@ -298,6 +627,7 @@ namespace Minecraft_Realms_Emulator.Modes.External
}
[HttpPut("{wId}/close")]
[CheckForWorld]
[CheckRealmOwner]
public async Task<ActionResult<bool>> Close(int wId)
{
@ -305,8 +635,6 @@ namespace Minecraft_Realms_Emulator.Modes.External
var world = worlds.FirstOrDefault(w => w.Id == wId);
if (world == null) return NotFound("World not found");
world.State = nameof(StateEnum.CLOSED);
_context.SaveChanges();
@ -315,15 +643,36 @@ namespace Minecraft_Realms_Emulator.Modes.External
}
[HttpPost("{wId}")]
[CheckForWorld]
[CheckRealmOwner]
public async Task<ActionResult<bool>> UpdateWorld(int wId, WorldCreateRequest body)
public async Task<ActionResult<(bool, ErrorResponse)>> UpdateWorld(int wId, WorldCreateRequest body)
{
if (body.Name.Length > 32)
{
ErrorResponse errorResponse = new()
{
ErrorCode = 400,
ErrorMsg = "World name cannot exceed 32 characters"
};
return BadRequest(errorResponse);
}
if (body.Description?.Length > 32)
{
ErrorResponse errorResponse = new()
{
ErrorCode = 400,
ErrorMsg = "World description cannot exceed 32 characters"
};
return BadRequest(errorResponse);
}
var worlds = await _context.Worlds.ToListAsync();
var world = worlds.Find(w => w.Id == wId);
if (world == null) return NotFound("World not found");
world.Name = body.Name;
world.Motd = body.Description;
@ -332,99 +681,37 @@ namespace Minecraft_Realms_Emulator.Modes.External
return Ok(true);
}
[HttpPost("{wId}/slot/{sId}")]
[CheckRealmOwner]
public async Task<ActionResult<bool>> UpdateSlotAsync(int wId, int sId, SlotOptionsRequest body)
{
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}")]
[CheckRealmOwner]
public ActionResult<bool> SwitchSlot(int wId, int sId)
{
var world = _context.Worlds.Find(wId);
if (world == null) return NotFound("World not found");
var slot = _context.Slots.Where(s => s.World.Id == wId).Where(s => s.SlotId == sId).Any();
if (!slot)
{
string cookie = Request.Headers.Cookie;
string gameVersion = cookie.Split(";")[2].Split("=")[1];
_context.Slots.Add(new()
{
World = world,
SlotId = sId,
SlotName = "",
Version = gameVersion,
GameMode = 0,
Difficulty = 2,
SpawnProtection = 0,
ForceGameMode = false,
Pvp = true,
SpawnAnimals = true,
SpawnMonsters = true,
SpawnNPCs = true,
CommandBlocks = false
});
_context.SaveChanges();
}
world.ActiveSlot = sId;
_context.SaveChanges();
return Ok(true);
}
[HttpGet("{wId}/backups")]
[CheckRealmOwner]
public async Task<ActionResult<BackupsResponse>> GetBackups(int wId)
{
var backups = await _context.Backups.Where(b => b.World.Id == wId).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);
var connection = _context.Connections.Include(c => c.World).FirstOrDefault(x => x.World.Id == wId);
// Set the server's addrees to its MOTD
connection.Address = connection.World.Motd;
return Ok(connection);
}
[HttpDelete("{wId}")]
[CheckForWorld]
[CheckRealmOwner]
public ActionResult<bool> DeleteRealm(int wId)
{
var world = _context.Worlds.Find(wId);
if (world == null) return NotFound("World not found");
if (world.ParentWorld == null)
{
var snapshotWorld = _context.Worlds.FirstOrDefault(w => w.ParentWorld.Id == wId);
if (snapshotWorld != null)
{
_context.Worlds.Remove(snapshotWorld);
}
}
else
{
_context.Worlds.Remove(world.ParentWorld);
}
_context.Worlds.Remove(world);
_context.SaveChanges();

View File

@ -0,0 +1,69 @@
using Microsoft.AspNetCore.Mvc;
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Enums;
using Minecraft_Realms_Emulator.Shared.Helpers;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Responses;
using Newtonsoft.Json;
namespace Minecraft_Realms_Emulator.Modes.Realms
{
[Route("modes/realms/[controller]")]
[ApiController]
[RequireMinecraftCookie]
public class ActivitiesController : ControllerBase
{
private readonly DataContext _context;
public ActivitiesController(DataContext context)
{
_context = context;
}
[HttpGet("liveplayerlist")]
public ActionResult<LivePlayerListsResponse> GetLivePlayerList()
{
string cookie = Request.Headers.Cookie;
string playerUUID = cookie.Split(";")[0].Split(":")[2];
List<LivePlayerList> lists = [];
var worlds = _context.Worlds.Where(w => w.State == nameof(StateEnum.OPEN) && w.OwnerUUID == playerUUID || w.State == nameof(StateEnum.OPEN) && w.Players.Any(p => p.Uuid == playerUUID && p.Accepted)).ToList();
foreach (var world in worlds)
{
var connection = _context.Connections.Where(c => c.World.Id == world.Id).FirstOrDefault();
var query = new MinecraftServerQuery().Query(connection.Address);
if (query == null) continue;
List<object> players = [];
if (query.Players.Sample == null) continue;
foreach (var player in query.Players.Sample)
{
players.Add(new
{
playerId = player.Id.Replace("-", ""),
});
}
LivePlayerList list = new()
{
ServerId = world.Id,
PlayerList = JsonConvert.SerializeObject(players),
};
lists.Add(list);
};
LivePlayerListsResponse response = new()
{
Lists = lists
};
return Ok(response);
}
}
}

View File

@ -1,10 +1,10 @@
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 Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Entities;
using Minecraft_Realms_Emulator.Shared.Requests;
using Minecraft_Realms_Emulator.Shared.Responses;
namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
{
@ -94,6 +94,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
}
[HttpPost("{wId}")]
[CheckForWorld]
[CheckRealmOwner]
[CheckActiveSubscription]
public async Task<ActionResult<World>> InvitePlayer(int wId, PlayerRequest body)
@ -139,6 +140,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
}
[HttpDelete("{wId}/invite/{uuid}")]
[CheckForWorld]
[CheckRealmOwner]
[CheckActiveSubscription]
public async Task<ActionResult<bool>> DeleteInvite(int wId, string uuid)
@ -161,6 +163,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
}
[HttpDelete("{wId}")]
[CheckForWorld]
public async Task<ActionResult<bool>> LeaveWorld(int wId)
{
string cookie = Request.Headers.Cookie;

View File

@ -1,9 +1,9 @@
using Microsoft.AspNetCore.Mvc;
using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Enums;
using Minecraft_Realms_Emulator.Helpers;
using Minecraft_Realms_Emulator.Responses;
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Enums;
using Minecraft_Realms_Emulator.Shared.Helpers;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Responses;
namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
{
@ -20,8 +20,23 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
}
[HttpGet("available")]
public ActionResult<bool> GetAvailable()
public async Task<ActionResult<bool>> GetAvailable()
{
if (new ConfigHelper(_context).GetSetting(nameof(SettingsEnum.OnlineMode)).Value)
{
string cookie = Request.Headers.Cookie;
string playerUUID = cookie.Split(";")[0].Split(":")[2];
try
{
await new HttpClient().GetFromJsonAsync<MinecraftPlayerInfo>($"https://sessionserver.mojang.com/session/minecraft/profile/{playerUUID}");
}
catch
{
return Unauthorized();
}
}
return Ok(true);
}

View File

@ -0,0 +1,101 @@
using Microsoft.AspNetCore.Mvc;
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Entities;
using Minecraft_Realms_Emulator.Shared.Responses;
namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
{
[Route("/modes/realms/[controller]")]
[ApiController]
[RequireMinecraftCookie]
public class NotificationsController : ControllerBase
{
private readonly DataContext _context;
public NotificationsController(DataContext context)
{
_context = context;
}
[HttpGet]
public ActionResult<NotificationsResponse> GetNotifications()
{
string cookie = Request.Headers.Cookie;
string playerUUID = cookie.Split(";")[0].Split(":")[2];
List<NotificationResponse> notifications = [];
foreach (var notification in _context.Notifications.ToList())
{
var seen = _context.SeenNotifications.Any(n => n.PlayerUUID == playerUUID && n.NotificationUUID == notification.NotificationUuid);
if (seen)
{
continue;
}
NotificationResponse notificationResponse = new()
{
NotificationUuid = notification.NotificationUuid,
Dismissable = notification.Dismissable,
Seen = seen,
Type = notification.Type,
Title = notification.Title,
Message = notification.Message,
Image = notification.Image,
UrlButton = notification.UrlButton,
Url = notification.Url,
ButtonText = notification.ButtonText,
};
notifications.Add(notificationResponse);
}
NotificationsResponse notificationsResponse = new()
{
Notifications = notifications,
};
return Ok(notificationsResponse);
}
[HttpPost("seen")]
public ActionResult Seen(string[] notificationIds)
{
string cookie = Request.Headers.Cookie;
string playerUUID = cookie.Split(";")[0].Split(":")[2];
if (notificationIds.Length == 0) {
ErrorResponse errorResponse = new()
{
ErrorCode = 400,
ErrorMsg = "Nothing to mark as seen"
};
return BadRequest(errorResponse);
}
foreach (var notificationId in notificationIds)
{
SeenNotification notificationSeen = new()
{
PlayerUUID = playerUUID,
NotificationUUID = notificationId
};
_context.SeenNotifications.Add(notificationSeen);
}
_context.SaveChanges();
return NoContent();
}
[HttpPost("dismiss")]
public ActionResult Dismiss(string[] notificationIds)
{
return NoContent();
}
}
}

View File

@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Responses;
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Responses;
namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
{
@ -18,6 +18,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
}
[HttpPost("{wId}/{uuid}")]
[CheckForWorld]
[CheckRealmOwner]
[CheckActiveSubscription]
public ActionResult<OpsResponse> OpPlayer(int wId, string uuid)
@ -48,6 +49,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
}
[HttpDelete("{wId}/{uuid}")]
[CheckForWorld]
[CheckRealmOwner]
[CheckActiveSubscription]
public ActionResult<OpsResponse> DeopPlayer(int wId, string uuid)

View File

@ -1,8 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Responses;
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Responses;
namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
{
@ -18,10 +18,16 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
_context = context;
}
[HttpGet("{wId}")]
[CheckForWorld]
[CheckRealmOwner]
public async Task<ActionResult<SubscriptionResponse>> Get(int wId)
{
var world = await _context.Worlds.Include(w => w.Subscription).FirstOrDefaultAsync(w => w.Id == wId);
var world = await _context.Worlds.Include(w => w.Subscription).Include(w => w.ParentWorld.Subscription).FirstOrDefaultAsync(w => w.Id == wId);
if (world.ParentWorld != null)
{
world.Subscription = world.ParentWorld.Subscription;
}
if (world?.Subscription == null) return NotFound("Subscription not found");

View File

@ -1,8 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Enums;
using Minecraft_Realms_Emulator.Helpers;
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Enums;
using Minecraft_Realms_Emulator.Shared.Helpers;
using Minecraft_Realms_Emulator.Shared.Data;
namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
{

View File

@ -1,17 +1,16 @@
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.Enums;
using Minecraft_Realms_Emulator.Helpers;
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Enums;
using Minecraft_Realms_Emulator.Shared.Helpers;
using Minecraft_Realms_Emulator.Modes.Realms.Helpers;
using Minecraft_Realms_Emulator.Requests;
using Minecraft_Realms_Emulator.Responses;
using Newtonsoft.Json;
using Semver;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Entities;
using Minecraft_Realms_Emulator.Shared.Requests;
using Minecraft_Realms_Emulator.Shared.Responses;
using System.Net;
using System.Net.Sockets;
using Newtonsoft.Json;
namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
{
@ -36,12 +35,12 @@ 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<WorldResponse> allWorlds = [];
if (ownedWorlds.ToArray().Length == 0)
if (ownedWorlds.ToArray().Length == 0 && new ConfigHelper(_context).GetSetting(nameof(SettingsEnum.AutomaticRealmsCreation)).Value)
{
var world = new World
{
@ -52,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
};
@ -69,7 +66,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
{
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
int versionsCompared = SemVersion.Parse(gameVersion, SemVersionStyles.OptionalPatch).ComparePrecedenceTo(SemVersion.Parse(activeSlot?.Version ?? gameVersion, SemVersionStyles.Any));
int versionsCompared = new MinecraftVersionParser.MinecraftVersion(gameVersion).CompareTo(new MinecraftVersionParser.MinecraftVersion(activeSlot?.Version ?? gameVersion));
string isCompatible = versionsCompared == 0 ? nameof(CompatibilityEnum.COMPATIBLE) : versionsCompared < 0 ? nameof(CompatibilityEnum.NEEDS_DOWNGRADE) : nameof(CompatibilityEnum.NEEDS_UPGRADE);
WorldResponse response = new()
@ -79,12 +76,11 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
OwnerUUID = world.OwnerUUID,
Name = world.Name,
Motd = world.Motd,
GameMode = activeSlot?.GameMode ?? 0,
IsHardcore = activeSlot?.Difficulty == 3,
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,
@ -92,6 +88,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;
@ -106,7 +109,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
{
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
int versionsCompared = SemVersion.Parse(gameVersion, SemVersionStyles.OptionalPatch).ComparePrecedenceTo(SemVersion.Parse(activeSlot.Version, SemVersionStyles.OptionalPatch));
int versionsCompared = new MinecraftVersionParser.MinecraftVersion(gameVersion).CompareTo(new MinecraftVersionParser.MinecraftVersion(activeSlot?.Version ?? gameVersion));
string isCompatible = versionsCompared == 0 ? nameof(CompatibilityEnum.COMPATIBLE) : versionsCompared < 0 ? nameof(CompatibilityEnum.NEEDS_DOWNGRADE) : nameof(CompatibilityEnum.NEEDS_UPGRADE);
WorldResponse response = new()
@ -116,12 +119,11 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
OwnerUUID = world.OwnerUUID,
Name = world.Name,
Motd = world.Motd,
GameMode = activeSlot.GameMode,
IsHardcore = activeSlot.Difficulty == 3,
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,
@ -132,6 +134,275 @@ 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);
}
ServersResponse servers = new()
{
Servers = allWorlds
};
return Ok(servers);
}
[HttpGet("listUserWorldsOfType/any")]
public async Task<ActionResult<ServersResponse>> GetWorldsSnapshot()
{
string cookie = Request.Headers.Cookie;
string playerUUID = cookie.Split(";")[0].Split(":")[2];
string playerName = cookie.Split(";")[1].Split("=")[1];
string gameVersion = cookie.Split(";")[2].Split("=")[1];
var ownedWorlds = await _context.Worlds.Where(w => w.OwnerUUID == playerUUID || w.ParentWorld.OwnerUUID == playerUUID).Include(w => w.Subscription).Include(w => w.Slots).Include(w => w.Minigame).Include(w => w.ParentWorld).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.ParentWorld).Include(p => p.World.Minigame).Select(p => p.World).ToListAsync();
List<WorldResponse> allWorlds = [];
foreach (var world in ownedWorlds)
{
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
int versionsCompared = new MinecraftVersionParser.MinecraftVersion(gameVersion).CompareTo(new MinecraftVersionParser.MinecraftVersion(activeSlot?.Version ?? gameVersion));
string isCompatible = versionsCompared == 0 ? nameof(CompatibilityEnum.COMPATIBLE) : versionsCompared < 0 ? nameof(CompatibilityEnum.NEEDS_DOWNGRADE) : nameof(CompatibilityEnum.NEEDS_UPGRADE);
WorldResponse response = new()
{
Id = world.Id,
Owner = world.Owner,
OwnerUUID = world.OwnerUUID,
Name = world.Name,
Motd = world.Motd,
GameMode = activeSlot?.GameMode ?? 0,
IsHardcore = activeSlot?.Difficulty == 3,
State = world.State,
WorldType = world.WorldType,
MaxPlayers = world.MaxPlayers,
ActiveSlot = world.ActiveSlot,
Member = world.Member,
Players = world.Players,
ActiveVersion = activeSlot?.Version ?? gameVersion,
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;
response.Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0;
response.ExpiredTrial = false;
}
if (world.ParentWorld == null)
{
response.ParentWorldId = -1;
}
if (world.ParentWorld != null)
{
response.Owner = world.ParentWorld.Owner;
response.OwnerUUID = world.ParentWorld.OwnerUUID;
response.ParentWorldId = world.ParentWorld.Id;
response.ParentWorldName = world.ParentWorld.Name;
}
allWorlds.Add(response);
}
foreach (var world in memberWorlds)
{
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
int versionsCompared = new MinecraftVersionParser.MinecraftVersion(gameVersion).CompareTo(new MinecraftVersionParser.MinecraftVersion(activeSlot.Version));
string isCompatible = versionsCompared == 0 ? nameof(CompatibilityEnum.COMPATIBLE) : versionsCompared < 0 ? nameof(CompatibilityEnum.NEEDS_DOWNGRADE) : nameof(CompatibilityEnum.NEEDS_UPGRADE);
WorldResponse response = new()
{
Id = world.Id,
Owner = world.Owner,
OwnerUUID = world.OwnerUUID,
Name = world.Name,
Motd = world.Motd,
GameMode = activeSlot.GameMode,
IsHardcore = activeSlot.Difficulty == 3,
State = world.State,
WorldType = world.WorldType,
MaxPlayers = world.MaxPlayers,
ActiveSlot = world.ActiveSlot,
Member = world.Member,
Players = world.Players,
DaysLeft = 0,
Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0,
ExpiredTrial = false,
ActiveVersion = activeSlot.Version,
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;
}
if (world.ParentWorld != null)
{
response.Owner = world.ParentWorld.Owner;
response.OwnerUUID = world.ParentWorld.OwnerUUID;
response.ParentWorldId = world.ParentWorld.Id;
response.ParentWorldName = world.ParentWorld.Name;
}
allWorlds.Add(response);
}
ServersResponse servers = new()
{
Servers = allWorlds
};
return Ok(servers);
}
[HttpGet("listPrereleaseEligibleWorlds")]
public async Task<ActionResult<ServersResponse>> GetPrereleaseWorlds()
{
string cookie = Request.Headers.Cookie;
string playerUUID = cookie.Split(";")[0].Split(":")[2];
string playerName = cookie.Split(";")[1].Split("=")[1];
string gameVersion = cookie.Split(";")[2].Split("=")[1];
var ownedWorlds = await _context.Worlds.Where(w => w.ParentWorld != null && w.ParentWorld.OwnerUUID == playerUUID).Include(w => w.Subscription).Include(w => w.Slots).Include(w => w.ParentWorld).Include(w => w.Minigame).ToListAsync();
var memberWorlds = await _context.Players.Where(p => p.World.ParentWorld != null && p.Uuid == playerUUID && p.Accepted).Include(p => p.World.Subscription).Include(p => p.World.Slots).Include(p => p.World.ParentWorld).Include(p => p.World.Minigame).Select(p => p.World).ToListAsync();
List<WorldResponse> allWorlds = [];
if (ownedWorlds.ToArray().Length == 0 && new ConfigHelper(_context).GetSetting(nameof(SettingsEnum.AutomaticRealmsCreation)).Value)
{
var parentWorld = _context.Worlds.FirstOrDefault(w => w.OwnerUUID == playerUUID && w.ParentWorld == null);
if (parentWorld != null && parentWorld.State != nameof(StateEnum.UNINITIALIZED))
{
var world = new World
{
Name = parentWorld.Name,
Motd = null,
State = nameof(StateEnum.UNINITIALIZED),
WorldType = nameof(WorldTypeEnum.NORMAL),
MaxPlayers = 10,
Minigame = null,
ActiveSlot = 1,
Member = false,
ParentWorld = parentWorld,
};
ownedWorlds.Add(world);
_context.Worlds.Add(world);
_context.SaveChanges();
}
}
foreach (var world in ownedWorlds)
{
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
int versionsCompared = new MinecraftVersionParser.MinecraftVersion(gameVersion).CompareTo(new MinecraftVersionParser.MinecraftVersion(activeSlot?.Version ?? gameVersion));
string isCompatible = versionsCompared == 0 ? nameof(CompatibilityEnum.COMPATIBLE) : versionsCompared < 0 ? nameof(CompatibilityEnum.NEEDS_DOWNGRADE) : nameof(CompatibilityEnum.NEEDS_UPGRADE);
WorldResponse response = new()
{
Id = world.Id,
Owner = world.Owner,
OwnerUUID = world.OwnerUUID,
Name = world.Name,
Motd = world.Motd,
GameMode = activeSlot?.GameMode ?? 0,
IsHardcore = activeSlot?.Difficulty == 3,
State = world.State,
WorldType = world.WorldType,
MaxPlayers = world.MaxPlayers,
ActiveSlot = world.ActiveSlot,
Member = world.Member,
Players = world.Players,
ActiveVersion = activeSlot?.Version ?? gameVersion,
Compatibility = isCompatible,
ParentWorldId = world.ParentWorld.Id,
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;
response.Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0;
response.ExpiredTrial = false;
}
allWorlds.Add(response);
}
foreach (var world in memberWorlds)
{
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
int versionsCompared = new MinecraftVersionParser.MinecraftVersion(gameVersion).CompareTo(new MinecraftVersionParser.MinecraftVersion(activeSlot.Version));
string isCompatible = versionsCompared == 0 ? nameof(CompatibilityEnum.COMPATIBLE) : versionsCompared < 0 ? nameof(CompatibilityEnum.NEEDS_DOWNGRADE) : nameof(CompatibilityEnum.NEEDS_UPGRADE);
WorldResponse response = new()
{
Id = world.Id,
Owner = world.Owner,
OwnerUUID = world.OwnerUUID,
Name = world.Name,
Motd = world.Motd,
GameMode = activeSlot.GameMode,
IsHardcore = activeSlot.Difficulty == 3,
State = world.State,
WorldType = world.WorldType,
MaxPlayers = world.MaxPlayers,
ActiveSlot = world.ActiveSlot,
Member = world.Member,
Players = world.Players,
DaysLeft = 0,
Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0,
ExpiredTrial = false,
ActiveVersion = activeSlot.Version,
Compatibility = isCompatible
};
if (world.Minigame != null)
{
response.MinigameId = world.Minigame.Id;
response.MinigameName = world.Minigame.Name;
response.MinigameImage = world.Minigame.Image;
}
allWorlds.Add(response);
}
@ -144,15 +415,25 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
}
[HttpGet("{wId}")]
[CheckForWorld]
[CheckRealmOwner]
public async Task<ActionResult<WorldResponse>> GetWorldById(int wId)
{
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).Include(w => w.Slots).FirstOrDefaultAsync(w => w.Id == wId);
var world = await _context.Worlds.Include(w => w.Players).Include(w => w.Subscription).Include(w => w.Slots).Include(w => w.ParentWorld.Subscription).FirstOrDefaultAsync(w => w.Id == wId);
if (world?.Subscription == null) return NotFound("World not found");
if (world.State == nameof(StateEnum.UNINITIALIZED))
{
ErrorResponse error = new()
{
ErrorCode = 400,
ErrorMsg = "Initialize the world first"
};
return StatusCode(400, error);
}
Slot activeSlot = world.Slots.Find(s => s.SlotId == world.ActiveSlot);
@ -160,7 +441,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
foreach (var slot in world.Slots)
{
int versionsCompared = SemVersion.Parse(gameVersion, SemVersionStyles.OptionalPatch).ComparePrecedenceTo(SemVersion.Parse(slot.Version, SemVersionStyles.OptionalPatch));
int versionsCompared = new MinecraftVersionParser.MinecraftVersion(gameVersion).CompareTo(new MinecraftVersionParser.MinecraftVersion(activeSlot?.Version ?? gameVersion));
string compatibility = versionsCompared == 0 ? nameof(CompatibilityEnum.COMPATIBLE) : versionsCompared < 0 ? nameof(CompatibilityEnum.NEEDS_DOWNGRADE) : nameof(CompatibilityEnum.NEEDS_UPGRADE);
slots.Add(new SlotResponse()
@ -170,8 +451,9 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
{
slotName = slot.SlotName,
gameMode = slot.GameMode,
hardcore = slot.Difficulty == 3,
difficulty = slot.Difficulty,
spawnProtection = slot.SpawnProtection,
spawnProection = slot.SpawnProtection,
forceGameMode = slot.ForceGameMode,
pvp = slot.Pvp,
spawnAnimals = slot.SpawnAnimals,
@ -186,6 +468,11 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
var activeSlotOptions = JsonConvert.DeserializeObject<SlotOptionsResponse>(slots.Find(s => s.SlotId == activeSlot.SlotId).Options);
if (world.ParentWorld != null)
{
world.Subscription = world.ParentWorld.Subscription;
}
WorldResponse response = new()
{
Id = world.Id,
@ -193,12 +480,11 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
OwnerUUID = world.OwnerUUID,
Name = world.Name,
Motd = world.Motd,
GameMode = activeSlot.GameMode,
IsHardcore = activeSlot.Difficulty == 3,
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,
@ -210,10 +496,18 @@ 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;
}
[HttpPost("{wId}/initialize")]
[CheckForWorld]
[CheckRealmOwner]
public async Task<ActionResult<World>> Initialize(int wId, WorldCreateRequest body)
{
@ -223,9 +517,16 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
var worlds = await _context.Worlds.ToListAsync();
var world = worlds.Find(w => w.Id == wId);
if (world.State != nameof(StateEnum.UNINITIALIZED))
{
ErrorResponse errorResponse = new()
{
ErrorCode = 401,
ErrorMsg = "World already initialized",
};
if (world == null) return NotFound("World not found");
if (world.State != nameof(StateEnum.UNINITIALIZED)) return NotFound("World already initialized");
return StatusCode(401, errorResponse);
}
var subscription = new Subscription
{
@ -288,16 +589,62 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
return Ok(world);
}
[HttpPost("{wId}/createPrereleaseRealm")]
[CheckForWorld]
[CheckRealmOwner]
public async Task<ActionResult<World>> CreatePrereleaseRealms(int wId)
{
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 == wId);
if (world.ParentWorld.State == nameof(StateEnum.UNINITIALIZED))
{
ErrorResponse errorResponse = new()
{
ErrorCode = 401,
ErrorMsg = "You must initialize release world first",
};
return StatusCode(401, errorResponse);
}
if (world.State != nameof(StateEnum.UNINITIALIZED))
{
ErrorResponse errorResponse = new()
{
ErrorCode = 401,
ErrorMsg = "A prerealease realm is already created for this world",
};
return StatusCode(401, errorResponse);
}
return Ok(world);
}
[HttpPost("{wId}/reset")]
[CheckForWorld]
[CheckRealmOwner]
[CheckActiveSubscription]
public ActionResult<bool> Reset(int wId)
{
Console.WriteLine($"Resetting world {wId}");
var world = _context.Worlds.Find(wId);
var server = new DockerHelper(world);
server.RunCommand($"rm -rf slot-{world.ActiveSlot}");
server.RebootServer();
return Ok(true);
}
[HttpPut("{wId}/open")]
[CheckForWorld]
[CheckRealmOwner]
[CheckActiveSubscription]
public async Task<ActionResult<bool>> Open(int wId)
@ -306,18 +653,26 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
var world = worlds.Find(w => w.Id == wId);
if (world == null) return NotFound("World not found");
new DockerHelper(world).StartServer();
world.State = nameof(StateEnum.OPEN);
_context.SaveChanges();
var connection = _context.Connections.FirstOrDefault(c => c.World.Id == wId);
var query = new MinecraftServerQuery().Query(connection.Address);
while (query == null)
{
await Task.Delay(1000);
query = new MinecraftServerQuery().Query(connection.Address);
}
return Ok(true);
}
[HttpPut("{wId}/close")]
[CheckForWorld]
[CheckRealmOwner]
[CheckActiveSubscription]
public async Task<ActionResult<bool>> Close(int wId)
@ -326,28 +681,56 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
var world = worlds.FirstOrDefault(w => w.Id == wId);
if (world == null) return NotFound("World not found");
new DockerHelper(world).StopServer();
world.State = nameof(StateEnum.CLOSED);
_context.SaveChanges();
var connection = _context.Connections.FirstOrDefault(c => c.World.Id == wId);
var query = new MinecraftServerQuery().Query(connection.Address);
while (query != null)
{
await Task.Delay(1000);
query = new MinecraftServerQuery().Query(connection.Address);
}
return Ok(true);
}
[HttpPost("{wId}")]
[CheckForWorld]
[CheckRealmOwner]
[CheckActiveSubscription]
public async Task<ActionResult<bool>> UpdateWorld(int wId, WorldCreateRequest body)
public async Task<ActionResult<(bool, ErrorResponse)>> UpdateWorld(int wId, WorldCreateRequest body)
{
if (body.Name.Length > 32)
{
ErrorResponse errorResponse = new()
{
ErrorCode = 400,
ErrorMsg = "World name cannot exceed 32 characters"
};
return BadRequest(errorResponse);
}
if (body.Description?.Length > 32)
{
ErrorResponse errorResponse = new()
{
ErrorCode = 400,
ErrorMsg = "World description cannot exceed 32 characters"
};
return BadRequest(errorResponse);
}
var worlds = await _context.Worlds.ToListAsync();
var world = worlds.Find(w => w.Id == wId);
if (world == null) return NotFound("World not found");
world.Name = body.Name;
world.Motd = body.Description;
@ -357,10 +740,55 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
}
[HttpPost("{wId}/slot/{sId}")]
[CheckForWorld]
[CheckRealmOwner]
[CheckActiveSubscription]
public async Task<ActionResult<bool>> UpdateSlotAsync(int wId, int sId, SlotOptionsRequest body)
public async Task<ActionResult<(bool, ErrorResponse)>> UpdateSlot(int wId, int sId, SlotOptionsRequest body)
{
if (body.SlotName.Length > 10)
{
ErrorResponse errorResponse = new()
{
ErrorCode = 400,
ErrorMsg = "Slot name cannot exceed 10 characters"
};
return BadRequest(errorResponse);
}
if (body.SpawnProtection < 0 || body.SpawnProtection > 16)
{
ErrorResponse errorResponse = new()
{
ErrorCode = 400,
ErrorMsg = "Spawn protection can only be between 0 and 16"
};
return BadRequest(errorResponse);
}
if (!new List<int> { 0, 1, 2 }.Contains(body.GameMode))
{
ErrorResponse errorResponse = new()
{
ErrorCode = 400,
ErrorMsg = "Gamemode can only be one of 0, 1, 2"
};
return BadRequest(errorResponse);
}
if (!new List<int> { 0, 1, 2, 3 }.Contains(body.Difficulty))
{
ErrorResponse errorResponse = new()
{
ErrorCode = 400,
ErrorMsg = "Difficulty can only be one of 0, 1, 2, 3"
};
return BadRequest(errorResponse);
}
var slots = await _context.Slots.Where(s => s.World.Id == wId).ToListAsync();
var slot = slots.Find(s => s.SlotId == sId);
@ -381,14 +809,12 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
}
[HttpPut("{wId}/slot/{sId}")]
[CheckForWorld]
[CheckRealmOwner]
[CheckActiveSubscription]
public ActionResult<bool> SwitchSlot(int wId, int sId)
{
var world = _context.Worlds.Find(wId);
if (world == null) return NotFound("World not found");
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)
@ -416,17 +842,26 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
_context.SaveChanges();
}
var server = new DockerHelper(world);
server.RunCommand($"sed -i 's#level-name=slot-{world.ActiveSlot}#level-name=slot-{sId}#' server.properties");
server.RebootServer();
world.ActiveSlot = sId;
world.Minigame = null;
world.WorldType = nameof(WorldTypeEnum.NORMAL);
_context.SaveChanges();
return Ok(true);
}
[HttpGet("{wId}/backups")]
[CheckForWorld]
[CheckRealmOwner]
public async Task<ActionResult<BackupsResponse>> GetBackups(int wId)
{
var backups = await _context.Backups.Where(b => b.World.Id == wId).ToListAsync();
var backups = await _context.Backups.Where(b => b.Slot.World.Id == wId).ToListAsync();
BackupsResponse worldBackups = new()
{
@ -436,21 +871,96 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
return Ok(worldBackups);
}
[HttpGet("v1/{wId}/join/pc")]
public ActionResult<Connection> Join(int wId)
[HttpGet("{wId}/slot/{sId}/download")]
[CheckForWorld]
[CheckRealmOwner]
public ActionResult<BackupDownloadResponse> GetBackup(int wId, int sId)
{
var connection = _context.Connections.FirstOrDefault(x => x.World.Id == wId);
Backup backup = _context.Backups.Include(b => b.Slot).FirstOrDefault(b => b.Slot.World.Id == wId && b.Slot.Id == sId);
if (backup == null)
{
ErrorResponse errorResponse = new()
{
ErrorCode = 404,
ErrorMsg = "No backup found"
};
return NotFound(errorResponse);
}
BackupDownloadResponse backupDownloadResponse = new()
{
DownloadLink = backup.DownloadUrl,
ResourcePackUrl = backup.ResourcePackUrl,
ResourcePackHash = backup.ResourcePackHash,
};
return Ok(backupDownloadResponse);
}
[HttpGet("v1/{wId}/join/pc")]
public async Task<ActionResult<Connection>> Join(int wId)
{
var connection = _context.Connections.Include(c => c.World).Include(c => c.World.Slots).FirstOrDefault(x => x.World.Id == wId);
var isRunning = new DockerHelper(connection.World).IsRunning();
var query = new MinecraftServerQuery().Query(connection.Address);
if (!isRunning)
{
new DockerHelper(connection.World).StartServer();
}
while (query == null)
{
await Task.Delay(1000);
query = new MinecraftServerQuery().Query(connection.Address);
}
Slot activeSlot = connection.World.Slots.Find(s => s.SlotId == connection.World.ActiveSlot);
string cookie = Request.Headers.Cookie;
string gameVersion = cookie.Split(";")[2].Split("=")[1];
if (new MinecraftVersionParser.MinecraftVersion(activeSlot.Version).CompareTo(new MinecraftVersionParser.MinecraftVersion(gameVersion)) < 0 && new DockerHelper(connection.World).RunCommand("! test -f .no-update") == 0)
{
activeSlot.Version = gameVersion;
_context.SaveChanges();
}
string playerUUID = cookie.Split(";")[0].Split(":")[2];
if (connection.World.OwnerUUID == playerUUID)
{
new DockerHelper(connection.World).ExecuteCommand($"op {connection.World.Owner}");
}
return Ok(connection);
}
[HttpDelete("{wId}")]
[CheckForWorld]
[CheckRealmOwner]
public ActionResult<bool> DeleteRealm(int wId)
{
var world = _context.Worlds.Find(wId);
if (world == null) return NotFound("World not found");
if (world.ParentWorld == null)
{
var snapshotWorld = _context.Worlds.FirstOrDefault(w => w.ParentWorld.Id == wId);
if (snapshotWorld != null)
{
new DockerHelper(snapshotWorld).DeleteServer();
_context.Worlds.Remove(snapshotWorld);
}
}
else
{
new DockerHelper(world.ParentWorld).DeleteServer();
_context.Worlds.Remove(world.ParentWorld);
}
new DockerHelper(world).DeleteServer();
@ -459,5 +969,38 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
return Ok(true);
}
[HttpGet("templates/{type}")]
public ActionResult<TemplatesResponse> GetWorldTemplates(string type, int page, int pageSize)
{
var totalTemplates = _context.Templates.Where(t => t.Type == type).Count();
var templates = _context.Templates.Where(t => t.Type == type).Skip((page - 1) * pageSize).Take(pageSize).ToList();
TemplatesResponse templatesResponse = new()
{
Page = page,
Size = pageSize,
Total = totalTemplates,
Templates = templates
};
return Ok(templatesResponse);
}
[HttpPut("minigames/{mId}/{wId}")]
[CheckForWorld]
[CheckRealmOwner]
public ActionResult<bool> 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);
}
}
}

View File

@ -1,4 +1,4 @@
using Minecraft_Realms_Emulator.Entities;
using Minecraft_Realms_Emulator.Shared.Entities;
using System.Diagnostics;
namespace Minecraft_Realms_Emulator.Modes.Realms.Helpers
@ -17,6 +17,23 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Helpers
serverProcess.Start();
}
public bool IsRunning()
{
ProcessStartInfo containerStateProcessInfo = new();
containerStateProcessInfo.FileName = "docker";
containerStateProcessInfo.Arguments = $"inspect realm-server-{world.Id} -f {{{{.State.Running}}}}";
containerStateProcessInfo.RedirectStandardOutput = true;
Process containerStateProcess = new();
containerStateProcess.StartInfo = containerStateProcessInfo;
containerStateProcess.Start();
containerStateProcess.WaitForExit();
return bool.Parse(containerStateProcess.StandardOutput.ReadToEnd());
}
public void StartServer()
{
ProcessStartInfo serverProcessInfo = new();
@ -30,11 +47,16 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Helpers
}
public void StopServer()
{
ExecuteCommand("stop");
}
public void RebootServer()
{
ProcessStartInfo serverProcessInfo = new();
serverProcessInfo.FileName = "docker";
serverProcessInfo.Arguments = $"container stop realm-server-{world.Id}";
serverProcessInfo.Arguments = $"container restart realm-server-{world.Id}";
Process serverProcess = new();
serverProcess.StartInfo = serverProcessInfo;
@ -46,7 +68,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Helpers
ProcessStartInfo serverProcessInfo = new();
serverProcessInfo.FileName = "docker";
serverProcessInfo.Arguments = $"container rm realm-server-{world.Id}";
serverProcessInfo.Arguments = $"container rm -f realm-server-{world.Id}";
Process serverProcess = new();
serverProcess.StartInfo = serverProcessInfo;
@ -80,5 +102,34 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Helpers
}
});
}
public void ExecuteCommand(string command)
{
ProcessStartInfo commandProcessInfo = new();
commandProcessInfo.FileName = "docker";
commandProcessInfo.Arguments = $"exec realm-server-{world.Id} rcon-cli {command}";
Process commandProcess = new();
commandProcess.StartInfo = commandProcessInfo;
commandProcess.Start();
}
public int RunCommand(string command)
{
ProcessStartInfo commandProcessInfo = new();
commandProcessInfo.FileName = "docker";
commandProcessInfo.Arguments = $"exec realm-server-{world.Id} /bin/sh -c \"{command}\"";
Process commandProcess = new();
commandProcess.StartInfo = commandProcessInfo;
commandProcess.Start();
commandProcess.WaitForExit();
return commandProcess.ExitCode;
}
}
}

View File

@ -1,10 +1,11 @@
using Microsoft.AspNetCore.Rewrite;
using Microsoft.EntityFrameworkCore;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Enums;
using Minecraft_Realms_Emulator.Helpers;
using Minecraft_Realms_Emulator.Middlewares;
using Minecraft_Realms_Emulator.Shared.Enums;
using Minecraft_Realms_Emulator.Shared.Helpers;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Middlewares;
using Npgsql;
using System.Diagnostics;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args);
@ -32,6 +33,14 @@ builder.Services.AddDbContext<DataContext>(options =>
options.UseNpgsql(dataSource);
});
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy.WithOrigins("http://localhost:5192");
});
});
var app = builder.Build();
// Initialize database
@ -47,10 +56,10 @@ if (app.Environment.IsDevelopment())
var scope = app.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<DataContext>();
app.UseCors();
app.MapControllers();
var config = new ConfigHelper(db);
var mode = config.GetSetting(nameof(SettingsEnum.WorkMode));
var mode = Environment.GetEnvironmentVariable("WORKMODE");
if (mode == null)
{
@ -58,13 +67,13 @@ if (mode == null)
Environment.Exit(1);
}
if (!Enum.IsDefined(typeof(WorkModeEnum), mode.Value))
if (!Enum.IsDefined(typeof(WorkModeEnum), mode))
{
Console.WriteLine("Invalid server work mode, exiting");
Environment.Exit(1);
}
if (mode.Value == nameof(WorkModeEnum.REALMS))
if (mode == nameof(WorkModeEnum.REALMS))
{
var resourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
@ -88,15 +97,43 @@ if (mode.Value == nameof(WorkModeEnum.REALMS))
stream.CopyTo(file);
}
}
// Check if docker is running
try
{
ProcessStartInfo dockerProcessInfo = new();
dockerProcessInfo.FileName = "docker";
dockerProcessInfo.Arguments = "info";
Process dockerProcess = new();
dockerProcess.StartInfo = dockerProcessInfo;
dockerProcess.Start();
dockerProcess.WaitForExit();
if (dockerProcess.ExitCode != 0)
{
Console.WriteLine("Docker is required to run in REALMS work mode, but its daemon is not running.");
Environment.Exit(1);
}
}
catch
{
Console.WriteLine("Docker is required to run in REALMS work mode, but it is not installed");
Console.WriteLine("You can install it here: https://docs.docker.com/engine/install");
Environment.Exit(1);
}
}
var rewriteOptions = new RewriteOptions().AddRewrite(@"^(?!api)(.*)$", $"modes/{mode.Value}/$1", true);
var rewriteOptions = new RewriteOptions().AddRewrite(@"^(?!api)(.*)$", $"modes/{mode}/$1", true);
app.UseRewriter(rewriteOptions);
app.UseMiddleware<MinecraftCookieMiddleware>();
app.UseMiddleware<CheckRealmOwnerMiddleware>();
app.UseMiddleware<ActiveSubscriptionMiddleware>();
app.UseMiddleware<AdminKeyMiddleware>();
app.UseMiddleware<CheckForWorldMiddleware>();
app.UseMiddleware<RouteLoggingMiddleware>();
Console.WriteLine($"Running in {mode.Value} mode");
Console.WriteLine($"Running in {mode} mode");
app.Run();

View File

@ -1,15 +1,17 @@
FROM eclipse-temurin:21
FROM eclipse-temurin:21-jre-alpine
WORKDIR /server
COPY . .
RUN mkdir mc
RUN apk upgrade
RUN apk add openssl curl jq
RUN wget -O rcon-cli.tar.gz https://github.com/itzg/rcon-cli/releases/download/1.6.7/rcon-cli_1.6.7_linux_amd64.tar.gz
RUN tar xzf rcon-cli.tar.gz
RUN rm rcon-cli.tar.gz
RUN mv rcon-cli /bin/rcon-cli
WORKDIR mc
RUN wget -O server.jar https://piston-data.mojang.com/v1/objects/145ff0858209bcfc164859ba735d4199aafa1eea/server.jar
EXPOSE 25565
RUN java -jar server.jar
RUN echo eula=true > eula.txt
CMD ["java", "-jar", "server.jar"]
ENTRYPOINT ["/entrypoint"]

View File

@ -0,0 +1,22 @@
#!/bin/sh
RCON_PASSWORD="$(openssl rand -hex 20)"
[ ! -f /root/.rcon-cli.yaml ] && echo "password: $RCON_PASSWORD" > /root/.rcon-cli.yaml
[ ! -f eula.txt ] && echo "eula=true" > eula.txt
if [ ! -f server.properties ]; then
echo "enable-rcon=true" >> server.properties
echo "rcon.password=$RCON_PASSWORD" >> server.properties
echo "level-name=slot-1" >> server.properties
fi
# Download latest server.jar
if [ ! -f .no-update ]; then
VERSION_URL=$(curl https://piston-meta.mojang.com/mc/game/version_manifest_v2.json | jq -r '.latest.release as $latest | .versions | to_entries[] | select(.value.id == $latest) | .value.url')
SERVER_URL=$(curl $VERSION_URL | jq -r .downloads.server.url)
wget -O server.jar $SERVER_URL
fi
java -jar server.jar

View File

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

View File

@ -1,9 +0,0 @@
using Minecraft_Realms_Emulator.Requests;
namespace Minecraft_Realms_Emulator.Responses
{
public class SlotOptionsResponse : SlotOptionsRequest
{
public string Compatibility { get; set; } = null!;
}
}

View File

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

View File

@ -1,15 +0,0 @@
using Minecraft_Realms_Emulator.Responses;
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;
public string Compatibility { get; set; } = null!;
public List<SlotResponse> Slots { get; set; } = null!;
public string ActiveVersion { get; set; } = null!;
}
}

View File

@ -1,6 +1,4 @@
using Minecraft_Realms_Emulator.Entities;
namespace Minecraft_Realms_Emulator.Attributes
namespace Minecraft_Realms_Emulator.Shared.Attributes
{
[AttributeUsage(AttributeTargets.Method)]
public class CheckActiveSubscription : Attribute

View File

@ -0,0 +1,13 @@
using Minecraft_Realms_Emulator.Shared.Entities;
namespace Minecraft_Realms_Emulator.Shared.Attributes
{
[AttributeUsage(AttributeTargets.Method)]
public class CheckForWorldAttribute : Attribute
{
public bool WorldExists(World world)
{
return world != null;
}
}
}

View File

@ -1,4 +1,4 @@
namespace Minecraft_Realms_Emulator.Attributes
namespace Minecraft_Realms_Emulator.Shared.Attributes
{
[AttributeUsage(AttributeTargets.Method)]
public class CheckRealmOwnerAttribute : Attribute

View File

@ -1,4 +1,4 @@
namespace Minecraft_Realms_Emulator.Attributes
namespace Minecraft_Realms_Emulator.Shared.Attributes
{
[AttributeUsage(AttributeTargets.Class)]
public class RequireAdminKeyAttribute : Attribute

View File

@ -1,4 +1,4 @@
namespace Minecraft_Realms_Emulator.Attributes
namespace Minecraft_Realms_Emulator.Shared.Attributes
{
[AttributeUsage(AttributeTargets.Class)]
public class RequireMinecraftCookieAttribute : Attribute

View File

@ -1,10 +1,10 @@
using Microsoft.AspNetCore.Mvc;
using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Entities;
using Minecraft_Realms_Emulator.Helpers;
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Helpers;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Entities;
namespace Minecraft_Realms_Emulator.Controllers.Admin
namespace Minecraft_Realms_Emulator.Shared.Controllers.Admin
{
[Route("api/admin/[controller]")]
[ApiController]

View File

@ -1,10 +1,10 @@
using Microsoft.AspNetCore.Mvc;
using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Entities;
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Modes.Realms.Helpers;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Entities;
namespace Minecraft_Realms_Emulator.Controllers.Admin
namespace Minecraft_Realms_Emulator.Shared.Controllers.Admin
{
[Route("api/admin/[controller]")]
[ApiController]
@ -27,7 +27,9 @@ namespace Minecraft_Realms_Emulator.Controllers.Admin
}
[HttpGet("{wId}")]
public ActionResult<World> GetWorld(int wId) {
[CheckForWorld]
public ActionResult<World> GetWorld(int wId)
{
var world = _context.Worlds.ToList().Find(w => w.Id == wId);
return Ok(world);
@ -59,12 +61,10 @@ namespace Minecraft_Realms_Emulator.Controllers.Admin
}
[HttpPut("{wId}/open")]
[CheckForWorld]
public ActionResult<bool> OpenServer(int wId)
{
var world = _context.Worlds.ToList().Find(w => w.Id == wId);
if (world == null) return BadRequest("World not found");
world.State = "OPEN";
_context.SaveChanges();
@ -74,12 +74,11 @@ namespace Minecraft_Realms_Emulator.Controllers.Admin
}
[HttpPut("{wId}/close")]
[CheckForWorld]
public ActionResult<bool> CloseServer(int wId)
{
var world = _context.Worlds.ToList().Find(w => w.Id == wId);
if (world == null) return BadRequest("World not found");
world.State = "CLOSED";
_context.SaveChanges();

View File

@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Minecraft_Realms_Emulator.Entities;
using Minecraft_Realms_Emulator.Shared.Entities;
namespace Minecraft_Realms_Emulator.Data
namespace Minecraft_Realms_Emulator.Shared.Data
{
public class DataContext(DbContextOptions<DataContext> options) : DbContext(options)
{
@ -13,5 +13,8 @@ namespace Minecraft_Realms_Emulator.Data
public DbSet<Player> Players { get; set; }
public DbSet<Configuration> Configuration { get; set; }
public DbSet<Slot> Slots { get; set; }
public DbSet<Template> Templates { get; set; }
public DbSet<Notification> Notifications { get; set; }
public DbSet<SeenNotification> SeenNotifications { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using System.Text.Json;
namespace Minecraft_Realms_Emulator.Shared.Entities
{
public class Backup
{
public int Id { get; set; }
public Slot Slot { get; set; } = null!;
public string BackupId { get; set; } = null!;
public long LastModifiedDate { get; set; }
public int Size { get; set; }
public JsonDocument Metadata { get; set; } = null!;
public string DownloadUrl { get; set; } = null!;
public string? ResourcePackUrl { get; set; } = null!;
public string? ResourcePackHash { get; set; } = null!;
}
}

View File

@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Minecraft_Realms_Emulator.Entities
namespace Minecraft_Realms_Emulator.Shared.Entities
{
[PrimaryKey(nameof(Key))]
public class Configuration

View File

@ -1,4 +1,4 @@
namespace Minecraft_Realms_Emulator.Entities
namespace Minecraft_Realms_Emulator.Shared.Entities
{
public class Connection
{

View File

@ -1,9 +1,9 @@
namespace Minecraft_Realms_Emulator.Entities
namespace Minecraft_Realms_Emulator.Shared.Entities
{
public class Invite
{
public int Id { get; set; }
public string InvitationId { get; set; }= string.Empty;
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,18 @@
using System.Text.Json;
namespace Minecraft_Realms_Emulator.Shared.Entities
{
public class Notification
{
public int Id { get; set; }
public string NotificationUuid { get; set; } = null!;
public bool Dismissable { get; set; }
public string Type { get; set; } = null!;
public JsonDocument? Title { get; set; } = null!;
public JsonDocument Message { get; set; } = null!;
public string? Image { get; set; } = null!;
public JsonDocument? UrlButton { get; set; } = null!;
public string? Url { get; set; } = null!;
public JsonDocument? ButtonText { get; set; } = null!;
}
}

View File

@ -1,4 +1,4 @@
namespace Minecraft_Realms_Emulator.Entities
namespace Minecraft_Realms_Emulator.Shared.Entities
{
public class Player
{

View File

@ -0,0 +1,9 @@
namespace Minecraft_Realms_Emulator.Shared.Entities
{
public class SeenNotification
{
public int Id { get; set; }
public string PlayerUUID { get; set; } = null!;
public string NotificationUUID { get; set; } = null!;
}
}

View File

@ -1,6 +1,6 @@
using Minecraft_Realms_Emulator.Requests;
using Minecraft_Realms_Emulator.Shared.Requests;
namespace Minecraft_Realms_Emulator.Entities
namespace Minecraft_Realms_Emulator.Shared.Entities
{
public class Slot : SlotOptionsRequest
{

View File

@ -1,4 +1,4 @@
namespace Minecraft_Realms_Emulator.Entities
namespace Minecraft_Realms_Emulator.Shared.Entities
{
public class Subscription
{

View File

@ -0,0 +1,15 @@
namespace Minecraft_Realms_Emulator.Shared.Entities
{
public class Template
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Version { get; set; } = string.Empty;
public string Author { get; set; } = string.Empty;
public string Link { get; set; } = string.Empty;
public string? Image { get; set; }
public string Trailer { get; set; } = string.Empty;
public string RecommendedPlayers { get; set; } = string.Empty;
public string Type { get; set; } = null!;
}
}

View File

@ -1,4 +1,4 @@
namespace Minecraft_Realms_Emulator.Entities
namespace Minecraft_Realms_Emulator.Shared.Entities
{
public class World
{
@ -12,11 +12,10 @@
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 Template? Minigame { get; set; }
public int ActiveSlot { get; set; } = 1;
public List<Slot> Slots { get; set; } = [];
public bool Member { get; set; } = false;
public World? ParentWorld { get; set; }
}
}

View File

@ -1,4 +1,4 @@
namespace Minecraft_Realms_Emulator.Enums
namespace Minecraft_Realms_Emulator.Shared.Enums
{
public enum CompatibilityEnum
{

View File

@ -1,10 +1,11 @@
namespace Minecraft_Realms_Emulator.Enums
namespace Minecraft_Realms_Emulator.Shared.Enums
{
public enum SettingsEnum
{
NewsLink,
DefaultServerAddress,
TrialMode,
WorkMode
OnlineMode,
AutomaticRealmsCreation
}
}

View File

@ -1,4 +1,4 @@
namespace Minecraft_Realms_Emulator.Enums
namespace Minecraft_Realms_Emulator.Shared.Enums
{
public enum StateEnum
{

View File

@ -1,4 +1,4 @@
namespace Minecraft_Realms_Emulator.Enums
namespace Minecraft_Realms_Emulator.Shared.Enums
{
public enum SubscriptionTypeEnum
{

View File

@ -1,4 +1,4 @@
namespace Minecraft_Realms_Emulator.Enums
namespace Minecraft_Realms_Emulator.Shared.Enums
{
public enum VersionCompatibilityEnum
{

View File

@ -1,4 +1,4 @@
namespace Minecraft_Realms_Emulator.Enums
namespace Minecraft_Realms_Emulator.Shared.Enums
{
public enum WorkModeEnum
{

View File

@ -1,4 +1,4 @@
namespace Minecraft_Realms_Emulator.Enums
namespace Minecraft_Realms_Emulator.Shared.Enums
{
public enum WorldTemplateTypeEnum
{

View File

@ -1,4 +1,4 @@
namespace Minecraft_Realms_Emulator.Enums
namespace Minecraft_Realms_Emulator.Shared.Enums
{
public enum WorldTypeEnum
{

View File

@ -1,8 +1,8 @@
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Entities;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Entities;
using Newtonsoft.Json;
namespace Minecraft_Realms_Emulator.Helpers
namespace Minecraft_Realms_Emulator.Shared.Helpers
{
public class ConfigHelper
{

View File

@ -1,12 +1,11 @@
using Minecraft_Realms_Emulator.Enums;
namespace Minecraft_Realms_Emulator.Helpers.Config
namespace Minecraft_Realms_Emulator.Shared.Helpers.Config
{
public class Settings
{
public string DefaultServerAddress { get; set; } = "127.0.0.1";
public string NewsLink { get; set; } = "https://github.com/CyberL1/Minecraft-Realms-Emulator";
public bool TrialMode { get; set; } = true;
public string WorkMode { get; set; } = nameof(WorkModeEnum.EXTERNAL);
public bool OnlineMode { get; set; } = false;
public bool AutomaticRealmsCreation { get; set; } = true;
}
}

View File

@ -1,10 +1,10 @@
using Microsoft.EntityFrameworkCore;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Entities;
using Minecraft_Realms_Emulator.Helpers.Config;
using Minecraft_Realms_Emulator.Shared.Entities;
using Minecraft_Realms_Emulator.Shared.Helpers.Config;
using Minecraft_Realms_Emulator.Shared.Data;
using Newtonsoft.Json;
namespace Minecraft_Realms_Emulator.Helpers
namespace Minecraft_Realms_Emulator.Shared.Helpers
{
public class Database
{

View File

@ -0,0 +1,98 @@
using Minecraft_Realms_Emulator.Shared.Responses;
using Newtonsoft.Json;
using System.Net.Sockets;
using System.Text;
namespace Minecraft_Realms_Emulator.Shared.Helpers
{
public class MinecraftServerQuery
{
public MinecraftServerQueryRepsonse? Query(string address)
{
string server = address.Split(':')[0];
int port = address.Contains(':') ? int.Parse(address.Split(':')[1]) : 25565;
try
{
using (TcpClient client = new())
{
client.Connect(server, port);
using (NetworkStream stream = client.GetStream())
using (BinaryWriter writer = new(stream))
using (BinaryReader reader = new(stream))
{
// Send Handshake packet (https://wiki.vg/Protocol#Handshake)
byte[] handshakePacket = CreateHandshakePacket(server, port);
writer.Write((byte)handshakePacket.Length); // Packet length
writer.Write(handshakePacket); // Packet data
// Send Status Request packet (https://wiki.vg/Protocol#Request)
writer.Write((byte)0x01); // Packet length
writer.Write((byte)0x00); // Packet ID (Request)
// Read the response length
int length = ReadVarInt(reader);
// Read the response packet ID
int packetId = ReadVarInt(reader);
if (packetId != 0x00) throw new Exception("Invalid packet ID");
// Read the JSON length
int jsonLength = ReadVarInt(reader);
// Read the JSON response
byte[] jsonData = reader.ReadBytes(jsonLength);
string json = Encoding.UTF8.GetString(jsonData);
return JsonConvert.DeserializeObject<MinecraftServerQueryRepsonse>(json);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
return null;
}
}
private static byte[] CreateHandshakePacket(string server, int port)
{
using (MemoryStream ms = new MemoryStream())
{
using (BinaryWriter writer = new BinaryWriter(ms))
{
WriteVarInt(writer, 0x00); // Packet ID (Handshake)
WriteVarInt(writer, 754); // Protocol version (754 for Minecraft 1.16.5)
WriteVarInt(writer, server.Length); // Server address length
writer.Write(Encoding.UTF8.GetBytes(server)); // Server address
writer.Write((ushort)port); // Server port
WriteVarInt(writer, 1); // Next state (1 for status)
return ms.ToArray();
}
}
}
private static int ReadVarInt(BinaryReader reader)
{
int value = 0;
int size = 0;
int b;
while (((b = reader.ReadByte()) & 0x80) == 0x80)
{
value |= (b & 0x7F) << (size++ * 7);
if (size > 5) throw new Exception("VarInt is too big");
}
return value | (b << (size * 7));
}
private static void WriteVarInt(BinaryWriter writer, int value)
{
while ((value & 0xFFFFFF80) != 0)
{
writer.Write((byte)((value & 0x7F) | 0x80));
value >>= 7;
}
writer.Write((byte)(value & 0x7F));
}
}
}

View File

@ -0,0 +1,76 @@
using System.Text.RegularExpressions;
namespace Minecraft_Realms_Emulator.Shared.Helpers
{
public class MinecraftVersionParser
{
public class MinecraftVersion : IComparable<MinecraftVersion>
{
public int Major { get; private set; }
public int Minor { get; private set; }
public int Patch { get; private set; }
public string PreRelease { get; private set; }
public string Snapshot { get; private set; }
private static readonly Regex VersionRegex = new(@"^(\d+)\.(\d+)(\.(\d+))?(-[a-zA-Z0-9\-]+)?$|^(\d{2})w(\d{2})([a-z])$");
public MinecraftVersion(string version)
{
var match = VersionRegex.Match(version);
if (!match.Success)
{
throw new ArgumentException("Invalid version format", nameof(version));
}
if (match.Groups[1].Success)
{
Major = int.Parse(match.Groups[1].Value);
Minor = int.Parse(match.Groups[2].Value);
Patch = match.Groups[4].Success ? int.Parse(match.Groups[4].Value) : 0;
PreRelease = match.Groups[5].Success ? match.Groups[5].Value.Substring(1) : null;
}
else if (match.Groups[6].Success)
{
Major = 0;
Minor = int.Parse(match.Groups[6].Value);
Patch = int.Parse(match.Groups[7].Value);
Snapshot = match.Groups[8].Value;
}
}
public int CompareTo(MinecraftVersion other)
{
if (other == null) return 1;
if (Snapshot != null && other.Snapshot != null)
{
int minorComparisonS = Minor.CompareTo(other.Minor);
if (minorComparisonS != 0) return minorComparisonS;
int patchComparisonS = Patch.CompareTo(other.Patch);
if (patchComparisonS != 0) return patchComparisonS;
return string.Compare(Snapshot, other.Snapshot, StringComparison.Ordinal);
}
if (Snapshot != null) return -1;
if (other.Snapshot != null) return 1;
int majorComparison = Major.CompareTo(other.Major);
if (majorComparison != 0) return majorComparison;
int minorComparison = Minor.CompareTo(other.Minor);
if (minorComparison != 0) return minorComparison;
int patchComparison = Patch.CompareTo(other.Patch);
if (patchComparison != 0) return patchComparison;
if (PreRelease == null && other.PreRelease == null) return 0;
if (PreRelease == null) return 1;
if (other.PreRelease == null) return -1;
return string.Compare(PreRelease, other.PreRelease, StringComparison.Ordinal);
}
}
}
}

View File

@ -1,8 +1,9 @@
using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Entities;
using Microsoft.EntityFrameworkCore;
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Entities;
namespace Minecraft_Realms_Emulator.Middlewares
namespace Minecraft_Realms_Emulator.Shared.Middlewares
{
public class ActiveSubscriptionMiddleware(RequestDelegate next)
{
@ -19,10 +20,15 @@ namespace Minecraft_Realms_Emulator.Middlewares
return;
}
Subscription subscription = db.Subscriptions.First(s => s.World.Id == int.Parse(httpContext.Request.RouteValues["wId"].ToString()));
Console.WriteLine(attribute.IsSubscriptionActive(subscription.StartDate));
var wId = int.Parse(httpContext.Request.RouteValues["wId"].ToString());
World world = db.Worlds.Include(w => w.Subscription).Include(w => w.ParentWorld.Subscription).FirstOrDefault(w => w.Id == wId);
if (!attribute.IsSubscriptionActive(subscription.StartDate))
if (world.ParentWorld?.Subscription != null)
{
world = world.ParentWorld;
}
if (!attribute.IsSubscriptionActive(world.Subscription.StartDate))
{
httpContext.Response.StatusCode = 403;
await httpContext.Response.WriteAsync("You don't have an active subscription for this world");

View File

@ -1,6 +1,6 @@
using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Shared.Attributes;
namespace Minecraft_Realms_Emulator.Middlewares
namespace Minecraft_Realms_Emulator.Shared.Middlewares
{
public class AdminKeyMiddleware(RequestDelegate next)
{

View File

@ -0,0 +1,41 @@
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Entities;
using Minecraft_Realms_Emulator.Shared.Responses;
namespace Minecraft_Realms_Emulator.Shared.Middlewares
{
public class CheckForWorldMiddleware(RequestDelegate next)
{
private readonly RequestDelegate _next = next;
public async Task Invoke(HttpContext httpContext, DataContext db)
{
var endpoint = httpContext.GetEndpoint();
var attribute = endpoint?.Metadata.GetMetadata<CheckForWorldAttribute>();
if (attribute == null)
{
await _next(httpContext);
return;
}
World world = db.Worlds.FirstOrDefault(w => w.Id == int.Parse(httpContext.Request.RouteValues["wId"].ToString()));
if (!attribute.WorldExists(world))
{
ErrorResponse errorResponse = new()
{
ErrorCode = 404,
ErrorMsg = "World not found"
};
httpContext.Response.StatusCode = 404;
await httpContext.Response.WriteAsJsonAsync(errorResponse);
return;
}
await _next(httpContext);
}
}
}

View File

@ -1,8 +1,9 @@
using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Entities;
using Microsoft.EntityFrameworkCore;
using Minecraft_Realms_Emulator.Shared.Attributes;
using Minecraft_Realms_Emulator.Shared.Data;
using Minecraft_Realms_Emulator.Shared.Entities;
namespace Minecraft_Realms_Emulator.Middlewares
namespace Minecraft_Realms_Emulator.Shared.Middlewares
{
public class CheckRealmOwnerMiddleware(RequestDelegate next)
{
@ -20,9 +21,9 @@ namespace Minecraft_Realms_Emulator.Middlewares
}
string playerUUID = httpContext.Request.Headers.Cookie.ToString().Split(";")[0].Split(":")[2];
World world = db.Worlds.Find(int.Parse(httpContext.Request.RouteValues["wId"].ToString()));
World world = db.Worlds.Include(w => w.ParentWorld).FirstOrDefault(w => w.Id == int.Parse(httpContext.Request.RouteValues["wId"].ToString()));
if (world != null && !attribute.IsRealmOwner(playerUUID, world.OwnerUUID))
if (world != null && !attribute.IsRealmOwner(playerUUID, world.ParentWorld == null ? world.OwnerUUID : world.ParentWorld.OwnerUUID))
{
httpContext.Response.StatusCode = 403;
await httpContext.Response.WriteAsync("You don't own this world");

View File

@ -1,7 +1,7 @@
using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Shared.Attributes;
using System.Text;
namespace Minecraft_Realms_Emulator.Middlewares
namespace Minecraft_Realms_Emulator.Shared.Middlewares
{
public class MinecraftCookieMiddleware(RequestDelegate next)
{

View File

@ -0,0 +1,14 @@
namespace Minecraft_Realms_Emulator.Shared.Middlewares
{
public class RouteLoggingMiddleware(RequestDelegate next)
{
private readonly RequestDelegate _next = next;
public async Task Invoke(HttpContext httpContext)
{
Console.WriteLine($"{httpContext.Request.Method} {httpContext.Request.Path}{httpContext.Request.QueryString}");
await _next(httpContext);
}
}
}

View File

@ -1,4 +1,4 @@
namespace Minecraft_Realms_Emulator.Requests
namespace Minecraft_Realms_Emulator.Shared.Requests
{
public class PlayerRequest
{

View File

@ -1,4 +1,4 @@
namespace Minecraft_Realms_Emulator.Requests
namespace Minecraft_Realms_Emulator.Shared.Requests
{
public class SlotOptionsRequest
{

View File

@ -1,4 +1,4 @@
namespace Minecraft_Realms_Emulator.Requests
namespace Minecraft_Realms_Emulator.Shared.Requests
{
public class WorldCreateRequest
{

View File

@ -0,0 +1,9 @@
namespace Minecraft_Realms_Emulator.Shared.Responses
{
public class BackupDownloadResponse
{
public string DownloadLink { get; set; } = null!;
public string? ResourcePackUrl { get; set; }
public string? ResourcePackHash { get; set; }
}
}

View File

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

View File

@ -0,0 +1,8 @@
namespace Minecraft_Realms_Emulator.Shared.Responses
{
public class ErrorResponse
{
public int ErrorCode { get; set; }
public string ErrorMsg { get; set; } = string.Empty;
}
}

Some files were not shown because too many files have changed in this diff Show More