From eeb0ddf64f2cf8f2ad64782aed17c0d42269e9ea Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Tue, 20 Feb 2024 19:14:02 +0100 Subject: [PATCH] feat: invites --- .../Controllers/InvitesController.cs | 150 ++++++++++ Minecraft-Realms-Emulator/Data/DataContext.cs | 1 + Minecraft-Realms-Emulator/Entities/Invite.cs | 11 + Minecraft-Realms-Emulator/Entities/Player.cs | 20 ++ Minecraft-Realms-Emulator/Entities/World.cs | 2 +- .../20240220092334_Invites.Designer.cs | 259 ++++++++++++++++++ .../Migrations/20240220092334_Invites.cs | 50 ++++ .../20240220110531_Worlds_Players.Designer.cs | 259 ++++++++++++++++++ .../20240220110531_Worlds_Players.cs | 23 ++ .../Migrations/DataContextModelSnapshot.cs | 44 ++- .../Responses/InviteList.cs | 16 ++ .../Responses/MinecraftPlayerInfo.cs | 9 + 12 files changed, 841 insertions(+), 3 deletions(-) create mode 100644 Minecraft-Realms-Emulator/Controllers/InvitesController.cs create mode 100644 Minecraft-Realms-Emulator/Entities/Invite.cs create mode 100644 Minecraft-Realms-Emulator/Entities/Player.cs create mode 100644 Minecraft-Realms-Emulator/Migrations/20240220092334_Invites.Designer.cs create mode 100644 Minecraft-Realms-Emulator/Migrations/20240220092334_Invites.cs create mode 100644 Minecraft-Realms-Emulator/Migrations/20240220110531_Worlds_Players.Designer.cs create mode 100644 Minecraft-Realms-Emulator/Migrations/20240220110531_Worlds_Players.cs create mode 100644 Minecraft-Realms-Emulator/Responses/InviteList.cs create mode 100644 Minecraft-Realms-Emulator/Responses/MinecraftPlayerInfo.cs diff --git a/Minecraft-Realms-Emulator/Controllers/InvitesController.cs b/Minecraft-Realms-Emulator/Controllers/InvitesController.cs new file mode 100644 index 0000000..2b20e45 --- /dev/null +++ b/Minecraft-Realms-Emulator/Controllers/InvitesController.cs @@ -0,0 +1,150 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Minecraft_Realms_Emulator.Data; +using Minecraft_Realms_Emulator.Entities; +using Minecraft_Realms_Emulator.Responses; +using System; +using System.Text.Json; + +namespace Minecraft_Realms_Emulator.Controllers +{ + [Route("[controller]")] + [ApiController] + public class InvitesController : ControllerBase + { + private readonly DataContext _context; + + public InvitesController(DataContext context) + { + _context = context; + } + + [HttpGet("pending")] + public async Task> GetInvites() + { + string cookie = Request.Headers.Cookie; + string playerUUID = cookie.Split(";")[0].Split(":")[2]; + + var invites = await _context.Invites.Where(i => i.RecipeintUUID == playerUUID).Include(i => i.World).ToListAsync(); + + List invitesList = []; + + foreach (var invite in invites) + { + InviteResponse inv = new() + { + InvitationId = invite.InvitationId, + WorldName = invite.World.Name, + WorldOwnerName = invite.World.Owner, + WorldOwnerUuid = invite.World.OwnerUUID, + Date = ((DateTimeOffset) invite.Date).ToUnixTimeMilliseconds(), + }; + + invitesList.Add(inv); + } + + InviteList inviteListRespone = new() + { + Invites = invitesList + }; + + return Ok(inviteListRespone); + } + [HttpPut("accept/{id}")] + public ActionResult AcceptInvite(string id) + { + var invite = _context.Invites.FirstOrDefault(i => i.InvitationId == id); + + if (invite == null) return NotFound("Invite not found"); + _context.Invites.Remove(invite); + + _context.SaveChanges(); + + return Ok(true); + } + + [HttpPut("reject/{id}")] + public async Task> RejectInvite(string id) + { + var invite = _context.Invites.Include(i => i.World).FirstOrDefault(i => i.InvitationId == id); + + if (invite == null) return NotFound("Invite not found"); + + _context.Invites.Remove(invite); + + string cookie = Request.Headers.Cookie; + string playerUUID = cookie.Split(";")[0].Split(":")[2]; + + World world = await _context.Worlds.FindAsync(invite.World.Id); + var playerIndex = world.Players.FindIndex(p => p.RootElement.GetProperty("uuid").ToString() == playerUUID); + + world.Players.RemoveAt(playerIndex); + + _context.SaveChanges(); + + return Ok(true); + } + + [HttpPost("{wId}")] + public async Task> InvitePlayer(int wId, Player body) + { + string cookie = Request.Headers.Cookie; + string playerName = cookie.Split(";")[1].Split("=")[1]; + + if (body.Name == playerName) return Forbid("You cannot invite yourself"); + + var world = await _context.Worlds.FirstOrDefaultAsync(w => w.Id == wId); + + if (world == null) return NotFound("World not found"); + + if (world.Players.Exists(p => p.RootElement.GetProperty("name").ToString() == body.Name)) return NotFound("Player already invited"); + + // Get player UUID + var playerInfo = await new HttpClient().GetFromJsonAsync($"https://api.mojang.com/users/profiles/minecraft/{body.Name}"); + body.Uuid = playerInfo.Id; + + JsonDocument player = JsonDocument.Parse(JsonSerializer.Serialize(body)); + world.Players.Add(player); + + _context.Worlds.Update(world); + + Invite invite = new() + { + InvitationId = Guid.NewGuid().ToString(), + World = world, + RecipeintUUID = body.Uuid, + Date = DateTime.UtcNow, + }; + + _context.Invites.Add(invite); + + _context.SaveChanges(); + + return Ok(world); + } + + [HttpDelete("{wId}/invite/{uuid}")] + public async Task> DeleteInvite(int wId, string uuid) + { + Console.WriteLine($"{wId} - {uuid}"); + + var world = await _context.Worlds.FirstOrDefaultAsync(w => w.Id == wId); + + if (world == null) return NotFound("World not found"); + + var players = world.Players.ToList(); + + var playerIndex = world.Players.FindIndex(p => p.RootElement.GetProperty("uuid").ToString() == uuid); + + world.Players.RemoveAt(playerIndex); + + var invite = await _context.Invites.FirstOrDefaultAsync(i => i.RecipeintUUID == uuid); + + if (invite != null) _context.Invites.Remove(invite); + + _context.SaveChanges(); + + return Ok(true); + } + } +} diff --git a/Minecraft-Realms-Emulator/Data/DataContext.cs b/Minecraft-Realms-Emulator/Data/DataContext.cs index 417bbf4..2d8c5b8 100644 --- a/Minecraft-Realms-Emulator/Data/DataContext.cs +++ b/Minecraft-Realms-Emulator/Data/DataContext.cs @@ -9,5 +9,6 @@ namespace Minecraft_Realms_Emulator.Data public DbSet Subscriptions { get; set; } public DbSet Connections { get; set; } public DbSet Backups { get; set; } + public DbSet Invites { get; set; } } } diff --git a/Minecraft-Realms-Emulator/Entities/Invite.cs b/Minecraft-Realms-Emulator/Entities/Invite.cs new file mode 100644 index 0000000..af4223a --- /dev/null +++ b/Minecraft-Realms-Emulator/Entities/Invite.cs @@ -0,0 +1,11 @@ +namespace Minecraft_Realms_Emulator.Entities +{ + public class Invite + { + public int Id { get; set; } + public string InvitationId { get; set; }= string.Empty; + public string RecipeintUUID { get; set; } = string.Empty; + public World World { get; set; } + public DateTime Date { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Entities/Player.cs b/Minecraft-Realms-Emulator/Entities/Player.cs new file mode 100644 index 0000000..2e0bbd1 --- /dev/null +++ b/Minecraft-Realms-Emulator/Entities/Player.cs @@ -0,0 +1,20 @@ +using System.Text.Json.Serialization; + +namespace Minecraft_Realms_Emulator.Entities +{ + public class Player + { + [JsonPropertyName("name")] + public string Name { get; set; } = string.Empty; + [JsonPropertyName("uuid")] + public string Uuid { get; set; } = string.Empty; + [JsonPropertyName("operator")] + public bool Operator { get; set; } + [JsonPropertyName("accepted")] + public bool Accepted { get; set; } + [JsonPropertyName("online")] + public bool Online { get; set; } + [JsonPropertyName("permission")] + public string Permission { get; set; } = "MEMBER"; + } +} diff --git a/Minecraft-Realms-Emulator/Entities/World.cs b/Minecraft-Realms-Emulator/Entities/World.cs index 6d15ed1..45d6ec5 100644 --- a/Minecraft-Realms-Emulator/Entities/World.cs +++ b/Minecraft-Realms-Emulator/Entities/World.cs @@ -15,7 +15,7 @@ namespace Minecraft_Realms_Emulator.Entities public bool Expired { get; set; } = false; public bool ExpiredTrial { get; set; } = false; public string WorldType { get; set; } = "NORMAL"; - public string[] Players { get; set; } = []; + public List Players { get; set; } = []; public int MaxPlayers { get; set; } = 10; public string? MinigameName { get; set; } public int? MinigameId { get; set; } diff --git a/Minecraft-Realms-Emulator/Migrations/20240220092334_Invites.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240220092334_Invites.Designer.cs new file mode 100644 index 0000000..5ae8fd5 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240220092334_Invites.Designer.cs @@ -0,0 +1,259 @@ +// +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("20240220092334_Invites")] + partial class Invites + { + /// + 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.Backup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BackupId") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastModifiedDate") + .HasColumnType("bigint"); + + b.Property("Metadata") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Size") + .HasColumnType("integer"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Backups"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("InvitationId") + .IsRequired() + .HasColumnType("text"); + + b.Property("RecipeintUUID") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Invites"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StartDate") + .IsRequired() + .HasColumnType("text"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + 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.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.Subscription", 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/20240220092334_Invites.cs b/Minecraft-Realms-Emulator/Migrations/20240220092334_Invites.cs new file mode 100644 index 0000000..753d699 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240220092334_Invites.cs @@ -0,0 +1,50 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Invites : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Invites", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + InvitationId = table.Column(type: "text", nullable: false), + RecipeintUUID = table.Column(type: "text", nullable: false), + WorldId = table.Column(type: "integer", nullable: false), + Date = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Invites", x => x.Id); + table.ForeignKey( + name: "FK_Invites_Worlds_WorldId", + column: x => x.WorldId, + principalTable: "Worlds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Invites_WorldId", + table: "Invites", + column: "WorldId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Invites"); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240220110531_Worlds_Players.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240220110531_Worlds_Players.Designer.cs new file mode 100644 index 0000000..c983e37 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240220110531_Worlds_Players.Designer.cs @@ -0,0 +1,259 @@ +// +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("20240220110531_Worlds_Players")] + partial class Worlds_Players + { + /// + 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.Backup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BackupId") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastModifiedDate") + .HasColumnType("bigint"); + + b.Property("Metadata") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Size") + .HasColumnType("integer"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Backups"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("InvitationId") + .IsRequired() + .HasColumnType("text"); + + b.Property("RecipeintUUID") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Invites"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StartDate") + .IsRequired() + .HasColumnType("text"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + 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("jsonb[]"); + + 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.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.Subscription", 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/20240220110531_Worlds_Players.cs b/Minecraft-Realms-Emulator/Migrations/20240220110531_Worlds_Players.cs new file mode 100644 index 0000000..64d7662 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240220110531_Worlds_Players.cs @@ -0,0 +1,23 @@ +using System.Text.Json; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Worlds_Players : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql("ALTER TABLE \"Worlds\" ALTER COLUMN \"Players\" TYPE jsonb[] USING \"Players\"::jsonb[]"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql("ALTER TABLE \"Worlds\" ALTER COLUMN \"Players\" TYPE text[] USING \"Players\"::text[]"); + } + } +} \ No newline at end of file diff --git a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs index 8d9e37b..fd2df2b 100644 --- a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs +++ b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs @@ -80,6 +80,35 @@ namespace Minecraft_Realms_Emulator.Migrations b.ToTable("Connections"); }); + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("InvitationId") + .IsRequired() + .HasColumnType("text"); + + b.Property("RecipeintUUID") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Invites"); + }); + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => { b.Property("Id") @@ -153,9 +182,9 @@ namespace Minecraft_Realms_Emulator.Migrations b.Property("OwnerUUID") .HasColumnType("text"); - b.Property("Players") + b.Property("Players") .IsRequired() - .HasColumnType("text[]"); + .HasColumnType("jsonb[]"); b.Property("RemoteSubscriptionId") .IsRequired() @@ -200,6 +229,17 @@ namespace Minecraft_Realms_Emulator.Migrations 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.Subscription", b => { b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World") diff --git a/Minecraft-Realms-Emulator/Responses/InviteList.cs b/Minecraft-Realms-Emulator/Responses/InviteList.cs new file mode 100644 index 0000000..949a7bf --- /dev/null +++ b/Minecraft-Realms-Emulator/Responses/InviteList.cs @@ -0,0 +1,16 @@ +namespace Minecraft_Realms_Emulator.Responses +{ + public class InviteList + { + public List Invites { get; set; } + } + + public class InviteResponse + { + public string InvitationId { get; set; } = string.Empty; + public string WorldName { get; set; } = string.Empty; + public string WorldOwnerName { get; set; } = string.Empty; + public string WorldOwnerUuid { get; set; } = string.Empty; + public long Date { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Responses/MinecraftPlayerInfo.cs b/Minecraft-Realms-Emulator/Responses/MinecraftPlayerInfo.cs new file mode 100644 index 0000000..d3915fe --- /dev/null +++ b/Minecraft-Realms-Emulator/Responses/MinecraftPlayerInfo.cs @@ -0,0 +1,9 @@ +namespace Minecraft_Realms_Emulator.Responses +{ + public class MinecraftPlayerInfo + { + public string Id { get; set; } = string.Empty; + public string Name { get; set; } = string.Empty; + public object Result { get; set; } + } +}