From 5dd9a261fe8294ac300528f6771c28add0b4160f Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Tue, 13 Feb 2024 11:54:29 +0100 Subject: [PATCH] feat: world joining --- .../Controllers/JoinController.cs | 26 +++ Minecraft-Realms-Emulator/Data/DataContext.cs | 1 + .../Entities/Connection.cs | 12 ++ .../20240213104200_Connections.Designer.cs | 159 ++++++++++++++++++ .../Migrations/20240213104200_Connections.cs | 44 +++++ .../Migrations/DataContextModelSnapshot.cs | 28 +++ 6 files changed, 270 insertions(+) create mode 100644 Minecraft-Realms-Emulator/Controllers/JoinController.cs create mode 100644 Minecraft-Realms-Emulator/Entities/Connection.cs create mode 100644 Minecraft-Realms-Emulator/Migrations/20240213104200_Connections.Designer.cs create mode 100644 Minecraft-Realms-Emulator/Migrations/20240213104200_Connections.cs diff --git a/Minecraft-Realms-Emulator/Controllers/JoinController.cs b/Minecraft-Realms-Emulator/Controllers/JoinController.cs new file mode 100644 index 0000000..a0290e9 --- /dev/null +++ b/Minecraft-Realms-Emulator/Controllers/JoinController.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Mvc; +using Minecraft_Realms_Emulator.Data; +using Minecraft_Realms_Emulator.Entities; + +namespace Minecraft_Realms_Emulator.Controllers +{ + [Route("worlds/v1/{worldId}/join/pc")] + [ApiController] + public class JoinController : ControllerBase + { + private readonly DataContext _context; + + public JoinController(DataContext context) + { + _context = context; + } + + [HttpGet()] + public ActionResult Join(int worldId) + { + var connection = _context.Connections.FirstOrDefault(x => x.World.Id == worldId); + + return Ok(connection); + } + } +} diff --git a/Minecraft-Realms-Emulator/Data/DataContext.cs b/Minecraft-Realms-Emulator/Data/DataContext.cs index 547d623..4f71f2c 100644 --- a/Minecraft-Realms-Emulator/Data/DataContext.cs +++ b/Minecraft-Realms-Emulator/Data/DataContext.cs @@ -7,5 +7,6 @@ namespace Minecraft_Realms_Emulator.Data { public DbSet Worlds { get; set; } public DbSet Subscriptions { get; set; } + public DbSet Connections { get; set; } } } diff --git a/Minecraft-Realms-Emulator/Entities/Connection.cs b/Minecraft-Realms-Emulator/Entities/Connection.cs new file mode 100644 index 0000000..d8574a8 --- /dev/null +++ b/Minecraft-Realms-Emulator/Entities/Connection.cs @@ -0,0 +1,12 @@ +using Microsoft.EntityFrameworkCore; + +namespace Minecraft_Realms_Emulator.Entities +{ + [Keyless] + public class Connection + { + public World World { get; set; } + public string Address { get; set; } = string.Empty; + public bool PendingUpdate { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240213104200_Connections.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240213104200_Connections.Designer.cs new file mode 100644 index 0000000..ff2e758 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240213104200_Connections.Designer.cs @@ -0,0 +1,159 @@ +// +using System; +using System.Text.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Minecraft_Realms_Emulator.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20240213104200_Connections")] + partial class Connections + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("RemoteId") + .IsRequired() + .HasColumnType("text"); + + b.Property("StartDate") + .IsRequired() + .HasColumnType("text"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ActiveSlot") + .HasColumnType("integer"); + + b.Property("DaysLeft") + .HasColumnType("integer"); + + b.Property("Expired") + .HasColumnType("boolean"); + + b.Property("ExpiredTrial") + .HasColumnType("boolean"); + + b.Property("MaxPlayers") + .HasColumnType("integer"); + + b.Property("Member") + .HasColumnType("boolean"); + + b.Property("MinigameId") + .HasColumnType("integer"); + + b.Property("MinigameImage") + .HasColumnType("text"); + + b.Property("MinigameName") + .HasColumnType("text"); + + b.Property("Motd") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Owner") + .HasColumnType("text"); + + b.Property("OwnerUUID") + .HasColumnType("text"); + + b.Property("Players") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("RemoteSubscriptionId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Slots") + .IsRequired() + .HasColumnType("jsonb[]"); + + b.Property("State") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldType") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240213104200_Connections.cs b/Minecraft-Realms-Emulator/Migrations/20240213104200_Connections.cs new file mode 100644 index 0000000..bad3f0f --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240213104200_Connections.cs @@ -0,0 +1,44 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Connections : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Connections", + columns: table => new + { + WorldId = table.Column(type: "integer", nullable: false), + Address = table.Column(type: "text", nullable: false), + PendingUpdate = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.ForeignKey( + name: "FK_Connections_Worlds_WorldId", + column: x => x.WorldId, + principalTable: "Worlds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Connections_WorldId", + table: "Connections", + column: "WorldId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Connections"); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs index 1f3b997..5be0406 100644 --- a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs +++ b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs @@ -23,6 +23,23 @@ namespace Minecraft_Realms_Emulator.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => { b.Property("Id") @@ -122,6 +139,17 @@ namespace Minecraft_Realms_Emulator.Migrations b.ToTable("Worlds"); }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") + .WithMany() + .HasForeignKey("WorldId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("World"); + }); #pragma warning restore 612, 618 } }