From 5d39e1c6be6906d5a336d3c13b996d4ca3a445f4 Mon Sep 17 00:00:00 2001 From: rfi Date: Thu, 22 Feb 2024 06:50:42 +0700 Subject: [PATCH] fleet db --- BLHX.Server.Common/Database/Player.cs | 11 + .../20240221233630_FleetsDB.Designer.cs | 215 ++++++++++++++++++ .../Player/20240221233630_FleetsDB.cs | 47 ++++ .../Player/PlayerContextModelSnapshot.cs | 10 +- BLHX.Server.Game/Handlers/P12.cs | 23 +- BLHX.Server.Game/Handlers/P24.cs | 9 +- 6 files changed, 306 insertions(+), 9 deletions(-) create mode 100644 BLHX.Server.Common/Migrations/Player/20240221233630_FleetsDB.Designer.cs create mode 100644 BLHX.Server.Common/Migrations/Player/20240221233630_FleetsDB.cs diff --git a/BLHX.Server.Common/Database/Player.cs b/BLHX.Server.Common/Database/Player.cs index 70187bc..ed61484 100644 --- a/BLHX.Server.Common/Database/Player.cs +++ b/BLHX.Server.Common/Database/Player.cs @@ -1,4 +1,5 @@ using BLHX.Server.Common.Proto.common; +using BLHX.Server.Common.Proto.p12; using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -48,6 +49,14 @@ namespace BLHX.Server.Common.Database { e.Property(b => b.DisplayInfo) .HasJsonConversion(); + e.Property(b => b.Fleets) + .HasJsonConversion() + .HasDefaultValue(new List() { + new() { Id = 1, ShipLists = [1, 2] }, + new() { Id = 2 }, + new() { Id = 11 }, + new() { Id = 12 } + }); e.Property(b => b.Adv) .HasDefaultValue(""); e.HasMany(b => b.Resources) @@ -102,6 +111,8 @@ namespace BLHX.Server.Common.Database public Displayinfo DisplayInfo { get; set; } public DateTime CreatedAt { get; set; } + public List Fleets { get; set; } = null!; + public virtual ICollection Resources { get; set; } = []; public virtual ICollection Ships { get; set; } = []; diff --git a/BLHX.Server.Common/Migrations/Player/20240221233630_FleetsDB.Designer.cs b/BLHX.Server.Common/Migrations/Player/20240221233630_FleetsDB.Designer.cs new file mode 100644 index 0000000..7c237b0 --- /dev/null +++ b/BLHX.Server.Common/Migrations/Player/20240221233630_FleetsDB.Designer.cs @@ -0,0 +1,215 @@ +// +using System; +using BLHX.Server.Common.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BLHX.Server.Common.Migrations.Player +{ + [DbContext(typeof(PlayerContext))] + [Migration("20240221233630_FleetsDB")] + partial class FleetsDB + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.2") + .HasAnnotation("Proxies:ChangeTracking", false) + .HasAnnotation("Proxies:CheckEquality", false) + .HasAnnotation("Proxies:LazyLoading", true); + + modelBuilder.Entity("BLHX.Server.Common.Database.Player", b => + { + b.Property("Uid") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Adv") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("TEXT") + .HasDefaultValue(""); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DisplayInfo") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Exp") + .HasColumnType("INTEGER"); + + b.Property("Fleets") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("jsonb") + .HasDefaultValue("[{\"Id\":1,\"Name\":null,\"ShipLists\":[1,2],\"Commanders\":[]},{\"Id\":2,\"Name\":null,\"ShipLists\":[],\"Commanders\":[]},{\"Id\":11,\"Name\":null,\"ShipLists\":[],\"Commanders\":[]},{\"Id\":12,\"Name\":null,\"ShipLists\":[],\"Commanders\":[]}]"); + + b.Property("Level") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Token") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Uid"); + + b.HasIndex("Token") + .IsUnique(); + + b.ToTable("Players"); + }); + + modelBuilder.Entity("BLHX.Server.Common.Database.PlayerResource", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("PlayerUid") + .HasColumnType("INTEGER"); + + b.Property("Num") + .HasColumnType("INTEGER"); + + b.HasKey("Id", "PlayerUid"); + + b.HasIndex("PlayerUid"); + + b.ToTable("Resources"); + }); + + modelBuilder.Entity("BLHX.Server.Common.Database.PlayerShip", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ActivityNpc") + .HasColumnType("INTEGER"); + + b.Property("BluePrintFlag") + .HasColumnType("INTEGER"); + + b.Property("CommanderId") + .HasColumnType("INTEGER"); + + b.Property("CommonFlag") + .HasColumnType("INTEGER"); + + b.Property("CoreLists") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("Energy") + .HasColumnType("INTEGER"); + + b.Property("EquipInfoLists") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Exp") + .HasColumnType("INTEGER"); + + b.Property("Intimacy") + .HasColumnType("INTEGER"); + + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("LastChangeName") + .HasColumnType("TEXT"); + + b.Property("Level") + .HasColumnType("INTEGER"); + + b.Property("MetaRepairLists") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("PlayerUid") + .HasColumnType("INTEGER"); + + b.Property("Proficiency") + .HasColumnType("INTEGER"); + + b.Property("Propose") + .HasColumnType("INTEGER"); + + b.Property("SkillIdLists") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("SkinId") + .HasColumnType("INTEGER"); + + b.Property("State") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("StrengthLists") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("TemplateId") + .HasColumnType("INTEGER"); + + b.Property("TransformLists") + .IsRequired() + .HasColumnType("jsonb"); + + b.HasKey("Id"); + + b.HasIndex("PlayerUid"); + + b.ToTable("Ships"); + }); + + modelBuilder.Entity("BLHX.Server.Common.Database.PlayerResource", b => + { + b.HasOne("BLHX.Server.Common.Database.Player", "Player") + .WithMany("Resources") + .HasForeignKey("PlayerUid") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Player"); + }); + + modelBuilder.Entity("BLHX.Server.Common.Database.PlayerShip", b => + { + b.HasOne("BLHX.Server.Common.Database.Player", "Player") + .WithMany("Ships") + .HasForeignKey("PlayerUid") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Player"); + }); + + modelBuilder.Entity("BLHX.Server.Common.Database.Player", b => + { + b.Navigation("Resources"); + + b.Navigation("Ships"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BLHX.Server.Common/Migrations/Player/20240221233630_FleetsDB.cs b/BLHX.Server.Common/Migrations/Player/20240221233630_FleetsDB.cs new file mode 100644 index 0000000..1b2355b --- /dev/null +++ b/BLHX.Server.Common/Migrations/Player/20240221233630_FleetsDB.cs @@ -0,0 +1,47 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BLHX.Server.Common.Migrations.Player +{ + /// + public partial class FleetsDB : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Adv", + table: "Players", + type: "TEXT", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "TEXT"); + + migrationBuilder.AddColumn( + name: "Fleets", + table: "Players", + type: "jsonb", + nullable: false, + defaultValue: "[{\"Id\":1,\"Name\":null,\"ShipLists\":[1,2],\"Commanders\":[]},{\"Id\":2,\"Name\":null,\"ShipLists\":[],\"Commanders\":[]},{\"Id\":11,\"Name\":null,\"ShipLists\":[],\"Commanders\":[]},{\"Id\":12,\"Name\":null,\"ShipLists\":[],\"Commanders\":[]}]"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Fleets", + table: "Players"); + + migrationBuilder.AlterColumn( + name: "Adv", + table: "Players", + type: "TEXT", + nullable: false, + oldClrType: typeof(string), + oldType: "TEXT", + oldDefaultValue: ""); + } + } +} diff --git a/BLHX.Server.Common/Migrations/Player/PlayerContextModelSnapshot.cs b/BLHX.Server.Common/Migrations/Player/PlayerContextModelSnapshot.cs index d4869c7..c1c1774 100644 --- a/BLHX.Server.Common/Migrations/Player/PlayerContextModelSnapshot.cs +++ b/BLHX.Server.Common/Migrations/Player/PlayerContextModelSnapshot.cs @@ -29,7 +29,9 @@ namespace BLHX.Server.Common.Migrations.Player b.Property("Adv") .IsRequired() - .HasColumnType("TEXT"); + .ValueGeneratedOnAdd() + .HasColumnType("TEXT") + .HasDefaultValue(""); b.Property("CreatedAt") .HasColumnType("TEXT"); @@ -41,6 +43,12 @@ namespace BLHX.Server.Common.Migrations.Player b.Property("Exp") .HasColumnType("INTEGER"); + b.Property("Fleets") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("jsonb") + .HasDefaultValue("[{\"Id\":1,\"Name\":null,\"ShipLists\":[1,2],\"Commanders\":[]},{\"Id\":2,\"Name\":null,\"ShipLists\":[],\"Commanders\":[]},{\"Id\":11,\"Name\":null,\"ShipLists\":[],\"Commanders\":[]},{\"Id\":12,\"Name\":null,\"ShipLists\":[],\"Commanders\":[]}]"); + b.Property("Level") .HasColumnType("INTEGER"); diff --git a/BLHX.Server.Game/Handlers/P12.cs b/BLHX.Server.Game/Handlers/P12.cs index a1cbc1e..3ac204c 100644 --- a/BLHX.Server.Game/Handlers/P12.cs +++ b/BLHX.Server.Game/Handlers/P12.cs @@ -1,9 +1,23 @@ -using BLHX.Server.Common.Proto.p12; +using BLHX.Server.Common.Proto; +using BLHX.Server.Common.Proto.p12; namespace BLHX.Server.Game.Handlers { internal static class P12 { + [PacketHandler(Command.Cs12102, SaveDataAfterRun = true)] + static void UpdateFleetHandler(Connection connection, Packet packet) + { + var fleet = packet.Decode(); + var toUpdate = connection.player.Fleets.Find(x => x.Id == fleet.Id); + + if (toUpdate is not null) + toUpdate.ShipLists = fleet.ShipLists; + else + connection.player.Fleets.Add(new() { Id = fleet.Id, ShipLists = fleet.ShipLists }); + + connection.Send(new Sc12103()); + } } static class P12ConnectionNotifyExtensions @@ -30,12 +44,7 @@ namespace BLHX.Server.Game.Handlers { connection.Send(new Sc12101() { - GroupLists = [ - new Groupinfo() { Id = 1, ShipLists = [1, 2] }, - new Groupinfo() { Id = 2 }, - new Groupinfo() { Id = 11 }, - new Groupinfo() { Id = 12 } - ] + GroupLists = connection.player.Fleets }); } } diff --git a/BLHX.Server.Game/Handlers/P24.cs b/BLHX.Server.Game/Handlers/P24.cs index 7c37cd4..cea3aa9 100644 --- a/BLHX.Server.Game/Handlers/P24.cs +++ b/BLHX.Server.Game/Handlers/P24.cs @@ -8,7 +8,14 @@ namespace BLHX.Server.Game.Handlers [PacketHandler(Command.Cs24020)] static void LimitChallengeHandler(Connection connection, Packet packet) { - connection.Send(new Sc24021()); + connection.Send(new Sc24021() + { + Awards = [ + new() { Key = 10025, Value = 0 }, + new() { Key = 10026, Value = 0 }, + new() { Key = 10027, Value = 0 } + ] + }); } } }