diff --git a/Minecraft-Realms-Emulator/Controllers/SubscriptionsController.cs b/Minecraft-Realms-Emulator/Controllers/SubscriptionsController.cs index 184a432..a818832 100644 --- a/Minecraft-Realms-Emulator/Controllers/SubscriptionsController.cs +++ b/Minecraft-Realms-Emulator/Controllers/SubscriptionsController.cs @@ -16,7 +16,7 @@ namespace Minecraft_Realms_Emulator.Controllers _context = context; } [HttpGet("{id}")] - public async Task> Get(int id) + public async Task> Get(int id) { var world = await _context.Worlds.FindAsync(id); var subscriptions = await _context.Subscriptions.ToListAsync(); @@ -25,10 +25,10 @@ namespace Minecraft_Realms_Emulator.Controllers var subscription = subscriptions.Find(s => s.World.RemoteSubscriptionId == world.RemoteSubscriptionId); - var sub = new Subscription + var sub = new SubscriptionResponse { - StartDate = subscription.StartDate, - DaysLeft = subscription.World.DaysLeft, + StartDate = ((DateTimeOffset) subscription.StartDate).ToUnixTimeMilliseconds(), + DaysLeft = (subscription.StartDate.AddDays(30) - DateTime.UtcNow).Days, SubscriptionType = subscription.SubscriptionType }; diff --git a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs index 0e9302a..35d6634 100644 --- a/Minecraft-Realms-Emulator/Controllers/WorldsController.cs +++ b/Minecraft-Realms-Emulator/Controllers/WorldsController.cs @@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore; using Minecraft_Realms_Emulator.Data; using Minecraft_Realms_Emulator.Entities; +using Minecraft_Realms_Emulator.Responses; namespace Minecraft_Realms_Emulator.Controllers { @@ -17,7 +18,7 @@ namespace Minecraft_Realms_Emulator.Controllers } [HttpGet] - public async Task> GetWorlds() + public async Task> GetWorlds() { string cookie = Request.Headers.Cookie; @@ -37,7 +38,6 @@ namespace Minecraft_Realms_Emulator.Controllers Name = null, Motd = null, State = State.UNINITIALIZED.ToString(), - DaysLeft = 30, Expired = false, ExpiredTrial = false, WorldType = WorldType.NORMAL.ToString(), @@ -60,7 +60,7 @@ namespace Minecraft_Realms_Emulator.Controllers allWorlds.AddRange(ownedWorlds); allWorlds.AddRange(memberWorlds); - ServersArray servers = new() + ServersResponse servers = new() { Servers = allWorlds }; @@ -95,7 +95,7 @@ namespace Minecraft_Realms_Emulator.Controllers var subscription = new Subscription { World = world, - StartDate = ((DateTimeOffset)DateTime.Now).ToUnixTimeMilliseconds().ToString(), + StartDate = DateTime.UtcNow, SubscriptionType = SubscriptionType.NORMAL.ToString() }; diff --git a/Minecraft-Realms-Emulator/Entities/ServersArray.cs b/Minecraft-Realms-Emulator/Entities/ServersArray.cs deleted file mode 100644 index 471e056..0000000 --- a/Minecraft-Realms-Emulator/Entities/ServersArray.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Minecraft_Realms_Emulator.Entities -{ - public class ServersArray - { - public List? Servers { get; set; } - } -} diff --git a/Minecraft-Realms-Emulator/Entities/Subscription.cs b/Minecraft-Realms-Emulator/Entities/Subscription.cs index ed08048..fdd1c0b 100644 --- a/Minecraft-Realms-Emulator/Entities/Subscription.cs +++ b/Minecraft-Realms-Emulator/Entities/Subscription.cs @@ -4,7 +4,7 @@ { public int Id { get; set; } public World World { get; set; } - public string StartDate { get; set; } = ((DateTimeOffset) DateTime.Now).ToUnixTimeMilliseconds().ToString(); + public DateTime StartDate { get; set; } = DateTime.Now; public string SubscriptionType { get; set; } = "NORMAL"; } } \ No newline at end of file diff --git a/Minecraft-Realms-Emulator/Entities/World.cs b/Minecraft-Realms-Emulator/Entities/World.cs index 6290f6b..6ddcb72 100644 --- a/Minecraft-Realms-Emulator/Entities/World.cs +++ b/Minecraft-Realms-Emulator/Entities/World.cs @@ -11,7 +11,6 @@ namespace Minecraft_Realms_Emulator.Entities public string? Name { get; set; } public string? Motd { get; set; } public string State { get; set; } = "OPEN"; - public int DaysLeft { get; set; } = 30; public bool Expired { get; set; } = false; public bool ExpiredTrial { get; set; } = false; public string WorldType { get; set; } = "NORMAL"; diff --git a/Minecraft-Realms-Emulator/Migrations/20240315212618_Calculate_daysLeft.Designer.cs b/Minecraft-Realms-Emulator/Migrations/20240315212618_Calculate_daysLeft.Designer.cs new file mode 100644 index 0000000..1a164b4 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240315212618_Calculate_daysLeft.Designer.cs @@ -0,0 +1,320 @@ +// +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("20240315212618_Calculate_daysLeft")] + partial class Calculate_daysLeft + { + /// + 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.Configuration", b => + { + b.Property("Key") + .HasColumnType("text"); + + b.Property("Value") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Key"); + + b.ToTable("Configuration"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("PendingUpdate") + .HasColumnType("boolean"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("InvitationId") + .IsRequired() + .HasColumnType("text"); + + b.Property("RecipeintUUID") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Invites"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Accepted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Online") + .HasColumnType("boolean"); + + b.Property("Operator") + .HasColumnType("boolean"); + + b.Property("Permission") + .IsRequired() + .HasColumnType("text"); + + b.Property("Uuid") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + b.ToTable("Players"); + }); + + modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("StartDate") + .HasColumnType("timestamp with time zone"); + + b.Property("SubscriptionType") + .IsRequired() + .HasColumnType("text"); + + b.Property("WorldId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("WorldId"); + + 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("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("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.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.Subscription", 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.World", b => + { + b.Navigation("Players"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/20240315212618_Calculate_daysLeft.cs b/Minecraft-Realms-Emulator/Migrations/20240315212618_Calculate_daysLeft.cs new file mode 100644 index 0000000..3d94da1 --- /dev/null +++ b/Minecraft-Realms-Emulator/Migrations/20240315212618_Calculate_daysLeft.cs @@ -0,0 +1,34 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Minecraft_Realms_Emulator.Migrations +{ + /// + public partial class Calculate_daysLeft : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "DaysLeft", + table: "Worlds"); + + migrationBuilder.Sql("ALTER TABLE \"Subscriptions\" ALTER COLUMN \"StartDate\" TYPE timestamptz USING \"StartDate\"::timestamptz"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "DaysLeft", + table: "Worlds", + type: "integer", + nullable: false, + defaultValue: 0); + + migrationBuilder.Sql("ALTER TABLE \"Subscriptions\" ALTER COLUMN \"StartDate\" TYPE text USING \"StartDate\"::text"); + } + } +} diff --git a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs index e760e0e..1d93cf1 100644 --- a/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs +++ b/Minecraft-Realms-Emulator/Migrations/DataContextModelSnapshot.cs @@ -170,9 +170,8 @@ namespace Minecraft_Realms_Emulator.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("StartDate") - .IsRequired() - .HasColumnType("text"); + b.Property("StartDate") + .HasColumnType("timestamp with time zone"); b.Property("SubscriptionType") .IsRequired() @@ -199,9 +198,6 @@ namespace Minecraft_Realms_Emulator.Migrations b.Property("ActiveSlot") .HasColumnType("integer"); - b.Property("DaysLeft") - .HasColumnType("integer"); - b.Property("Expired") .HasColumnType("boolean"); diff --git a/Minecraft-Realms-Emulator/Responses/ServersResponse.cs b/Minecraft-Realms-Emulator/Responses/ServersResponse.cs new file mode 100644 index 0000000..c74e65f --- /dev/null +++ b/Minecraft-Realms-Emulator/Responses/ServersResponse.cs @@ -0,0 +1,9 @@ +using Minecraft_Realms_Emulator.Entities; + +namespace Minecraft_Realms_Emulator.Responses +{ + public class ServersResponse + { + public List? Servers { get; set; } + } +} diff --git a/Minecraft-Realms-Emulator/Responses/Subscription.cs b/Minecraft-Realms-Emulator/Responses/SubscriptionResponse.cs similarity index 66% rename from Minecraft-Realms-Emulator/Responses/Subscription.cs rename to Minecraft-Realms-Emulator/Responses/SubscriptionResponse.cs index 1307794..59fd82f 100644 --- a/Minecraft-Realms-Emulator/Responses/Subscription.cs +++ b/Minecraft-Realms-Emulator/Responses/SubscriptionResponse.cs @@ -1,8 +1,8 @@ namespace Minecraft_Realms_Emulator.Responses { - public class Subscription + public class SubscriptionResponse { - public string StartDate { get; set; } + public long StartDate { get; set; } public int DaysLeft { get; set; } public string SubscriptionType { get; set; } } diff --git a/Minecraft-Realms-Emulator/Responses/WorldResponse.cs b/Minecraft-Realms-Emulator/Responses/WorldResponse.cs new file mode 100644 index 0000000..2e143e3 --- /dev/null +++ b/Minecraft-Realms-Emulator/Responses/WorldResponse.cs @@ -0,0 +1,27 @@ +using System.Text.Json; + +namespace Minecraft_Realms_Emulator.Entities +{ + public class WorldResponse + { + public int Id { get; set; } + public string RemoteSubscriptionId { get; set; } = Guid.NewGuid().ToString(); + public string? Owner { get; set; } + public string? OwnerUUID { get; set; } + public string? Name { get; set; } + public string? Motd { get; set; } + public string State { get; set; } = "OPEN"; + public int DaysLeft { get; set; } = 30; + public bool Expired { get; set; } = false; + public bool ExpiredTrial { get; set; } = false; + public string WorldType { get; set; } = "NORMAL"; + public List Players { get; set; } = []; + public int MaxPlayers { get; set; } = 10; + public string? MinigameName { get; set; } + public int? MinigameId { get; set; } + public string? MinigameImage { get; set; } + public int ActiveSlot { get; set; } = 1; + public JsonDocument[] Slots { get; set; } = []; + public bool Member { get; set; } = false; + } +} \ No newline at end of file