From d052bd193575d1b6c14af49fd0e6e1b4fe842841 Mon Sep 17 00:00:00 2001 From: rfi Date: Wed, 21 Feb 2024 10:46:58 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=80=20strictly=20necessary=20login=20n?= =?UTF-8?q?itifies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BLHX.Server.Common/Data/JSON.cs | 13 ++++--------- BLHX.Server.Game/Connection.cs | 27 ++++++++++++++++++++++++++- BLHX.Server.Game/Handlers/P11.cs | 5 +++++ BLHX.Server.Game/Handlers/P12.cs | 10 +++++++++- BLHX.Server.Game/Handlers/P13.cs | 16 ++++++++++++++++ BLHX.Server.Game/Handlers/P15.cs | 24 ++++++++++++++++++++++++ BLHX.Server.Game/Handlers/P16.cs | 16 ++++++++++++++++ BLHX.Server.Game/Handlers/P19.cs | 22 ++++++++++++++++++++++ BLHX.Server.Game/Handlers/P22.cs | 23 +++++++++++++++++++++++ BLHX.Server.Game/Handlers/P26.cs | 7 +++++++ BLHX.Server.Game/Packet.cs | 14 +++++++------- BLHX.Server/Program.cs | 3 +++ 12 files changed, 162 insertions(+), 18 deletions(-) create mode 100644 BLHX.Server.Game/Handlers/P13.cs create mode 100644 BLHX.Server.Game/Handlers/P15.cs create mode 100644 BLHX.Server.Game/Handlers/P16.cs create mode 100644 BLHX.Server.Game/Handlers/P19.cs create mode 100644 BLHX.Server.Game/Handlers/P22.cs diff --git a/BLHX.Server.Common/Data/JSON.cs b/BLHX.Server.Common/Data/JSON.cs index fd9c030..35ef17c 100644 --- a/BLHX.Server.Common/Data/JSON.cs +++ b/BLHX.Server.Common/Data/JSON.cs @@ -4,6 +4,7 @@ namespace BLHX.Server.Common.Data; public static class JSON { + public static JsonSerializerOptions serializerOptions = new() { IncludeFields = true, WriteIndented = true }; public static string ConfigPath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config.json"); public static string ShareConfigPath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\sharecfgdata\\"); @@ -15,22 +16,16 @@ public static class JSON Save(path, obj); } - return JsonSerializer.Deserialize(File.ReadAllText(path)); + return JsonSerializer.Deserialize(File.ReadAllText(path), serializerOptions) ?? new T(); } public static void Save(string path, T obj) { - File.WriteAllText(path, JsonSerializer.Serialize(obj, new JsonSerializerOptions() - { - WriteIndented = true - })); + File.WriteAllText(path, JsonSerializer.Serialize(obj, serializerOptions)); } public static string Stringify(T obj) { - return JsonSerializer.Serialize(obj, new JsonSerializerOptions() - { - WriteIndented = true - }); + return JsonSerializer.Serialize(obj, serializerOptions); } } diff --git a/BLHX.Server.Game/Connection.cs b/BLHX.Server.Game/Connection.cs index 4807531..587eedf 100644 --- a/BLHX.Server.Game/Connection.cs +++ b/BLHX.Server.Game/Connection.cs @@ -1,4 +1,5 @@ -using BLHX.Server.Common.Database; +using BLHX.Server.Common.Data; +using BLHX.Server.Common.Database; using BLHX.Server.Common.Proto; using BLHX.Server.Common.Utils; using BLHX.Server.Game.Handlers; @@ -117,11 +118,35 @@ namespace BLHX.Server.Game ns.Write(sendBuf); } + void SendPacket(Packet packet) + { + var ns = tcpClient.GetStream(); + + byte[] sendBuf = GC.AllocateUninitializedArray(Packet.LENGTH_SIZE + Packet.HEADER_SIZE + packet.bytes.Length); + BinaryPrimitives.WriteUInt16BigEndian(sendBuf, (ushort)(packet.bytes.Length + Packet.HEADER_SIZE)); + sendBuf[Packet.LENGTH_SIZE] = 0; + BinaryPrimitives.WriteUInt16BigEndian(sendBuf.AsSpan(Packet.LENGTH_SIZE + 1), (ushort)packet.command); + BinaryPrimitives.WriteUInt16BigEndian(sendBuf.AsSpan(Packet.HEADER_SIZE), NextPacketIdx); + packet.bytes.CopyTo(sendBuf.AsSpan(Packet.LENGTH_SIZE + Packet.HEADER_SIZE)); + + ns.Write(sendBuf); + } + public void InitClientData() { this.NotifyPlayerData(); + this.NotifyRefluxData(); + this.NotifyGameRoom(); this.NotifyStatisticsInit(); this.NotifyShipData(); + this.NotifyShipSkinData(); + this.NotifyFleetData(); + this.NotifyShopMonthData(); + this.NotifyChapterData(); + this.NotifyBagData(); + this.NotifyDormData(); + this.NotifyNavalAcademy(); + // SendPacket(new() { bytes = Convert.FromBase64String("CAEQABgAIAAyBQjqBxABMgUI6QcQATIFCNcIEAEyBQjQCBABMgUIlQoQATIFCJoKEAEyBQjTCBABMgUIzggQATIFCM8IEAEyBQiYChABMgUIlgoQATIFCNEIEAEyBQjSCBABMgUI2AgQATgBQAJK/gEIARIQCgQxMTEyEBYYDSABMAA4ABIQCgQxMTA2EAwYFyABMAA4ABIQCgQxMTA1EBYYDyABMAA4ABIQCgQxMzAyEBgYDCABMAA4ABIQCgQxMzA0EBgYFCABMAA4ABIQCgQxMTAzEAwYDCABMAA4ABIQCgQxMTAyEBEYDCABMAA4ABIQCgQxMTA3EBcYFCABMAA4ABIQCgQxMzA2EBAYGCABMAA4ABIQCgQxMzAxEBQYGCABMAA4ABIQCgQxMTA0EBAYDCABMAA4ABIQCgQxMTExEBYYFiACMAA4ABIQCgQxMDAxEAAYACABMAA4ABIQCgQxMDAyEAAYACABMAA4AFAAWABgAGj/o82uBnIA"), command = Command.Sc19001 }); } public void SendHttpResponse(string rsp, string type = "text/plain") diff --git a/BLHX.Server.Game/Handlers/P11.cs b/BLHX.Server.Game/Handlers/P11.cs index e2b5f8e..b153e2b 100644 --- a/BLHX.Server.Game/Handlers/P11.cs +++ b/BLHX.Server.Game/Handlers/P11.cs @@ -70,5 +70,10 @@ namespace BLHX.Server.Game.Handlers }); } } + + public static void NotifyRefluxData(this Connection connection) + { + connection.Send(new Sc11752()); + } } } diff --git a/BLHX.Server.Game/Handlers/P12.cs b/BLHX.Server.Game/Handlers/P12.cs index a9e6a4c..a1cbc1e 100644 --- a/BLHX.Server.Game/Handlers/P12.cs +++ b/BLHX.Server.Game/Handlers/P12.cs @@ -19,6 +19,11 @@ namespace BLHX.Server.Game.Handlers } } + public static void NotifyShipSkinData(this Connection connection) + { + connection.Send(new Sc12201()); + } + public static void NotifyFleetData(this Connection connection) { if (connection.player is not null) @@ -26,7 +31,10 @@ namespace BLHX.Server.Game.Handlers connection.Send(new Sc12101() { GroupLists = [ - new Groupinfo() { Id = 1, ShipLists = [1, 2] } + new Groupinfo() { Id = 1, ShipLists = [1, 2] }, + new Groupinfo() { Id = 2 }, + new Groupinfo() { Id = 11 }, + new Groupinfo() { Id = 12 } ] }); } diff --git a/BLHX.Server.Game/Handlers/P13.cs b/BLHX.Server.Game/Handlers/P13.cs new file mode 100644 index 0000000..86794c2 --- /dev/null +++ b/BLHX.Server.Game/Handlers/P13.cs @@ -0,0 +1,16 @@ +using BLHX.Server.Common.Proto.p13; + +namespace BLHX.Server.Game.Handlers +{ + internal static class P13 + { + } + + static class P13ConnectionNotifyExtensions + { + public static void NotifyChapterData(this Connection connection) + { + connection.Send(new Sc13001() { ReactChapter = new() }); + } + } +} diff --git a/BLHX.Server.Game/Handlers/P15.cs b/BLHX.Server.Game/Handlers/P15.cs new file mode 100644 index 0000000..84a39bb --- /dev/null +++ b/BLHX.Server.Game/Handlers/P15.cs @@ -0,0 +1,24 @@ +using BLHX.Server.Common.Proto.p15; + +namespace BLHX.Server.Game.Handlers +{ + internal static class P15 + { + } + + static class P15ConnectionNotifyExtensions + { + public static void NotifyBagData(this Connection connection) + { + connection.Send(new Sc15001() + { + ItemLists = [ + new Iteminfo() { Id = 20001, Count = 5 }, + new Iteminfo() { Id = 15003, Count = 10 }, + new Iteminfo() { Id = 50002, Count = 10 }, + new Iteminfo() { Id = 50001, Count = 10 } + ] + }); + } + } +} diff --git a/BLHX.Server.Game/Handlers/P16.cs b/BLHX.Server.Game/Handlers/P16.cs new file mode 100644 index 0000000..99d56ce --- /dev/null +++ b/BLHX.Server.Game/Handlers/P16.cs @@ -0,0 +1,16 @@ +using BLHX.Server.Common.Proto.p16; + +namespace BLHX.Server.Game.Handlers +{ + internal static class P16 + { + } + + static class P16ConnectionNotifyExtensions + { + public static void NotifyShopMonthData(this Connection connection) + { + connection.Send(new Sc16200() { Month = (uint)DateTime.Now.Month }); + } + } +} diff --git a/BLHX.Server.Game/Handlers/P19.cs b/BLHX.Server.Game/Handlers/P19.cs new file mode 100644 index 0000000..63ffac0 --- /dev/null +++ b/BLHX.Server.Game/Handlers/P19.cs @@ -0,0 +1,22 @@ +using BLHX.Server.Common.Proto.p19; + +namespace BLHX.Server.Game.Handlers +{ + internal static class P19 + { + } + + static class P19ConnectionNotifyExtensions + { + public static void NotifyDormData(this Connection connection) + { + connection.Send(new Sc19001() + { + Lv = 1, + FloorNum = 1, + ExpPos = 2, + LoadTime = (uint)DateTimeOffset.Now.ToUnixTimeSeconds() + }); + } + } +} diff --git a/BLHX.Server.Game/Handlers/P22.cs b/BLHX.Server.Game/Handlers/P22.cs new file mode 100644 index 0000000..8b02c75 --- /dev/null +++ b/BLHX.Server.Game/Handlers/P22.cs @@ -0,0 +1,23 @@ +using BLHX.Server.Common.Proto.p22; + +namespace BLHX.Server.Game.Handlers +{ + internal static class P22 + { + } + + static class P22ConnectionNotifyExtensions + { + public static void NotifyNavalAcademy(this Connection connection) + { + connection.Send(new Sc22001() + { + OilWellLevel = 1, + GoldWellLevel = 1, + ClassLv = 1, + Class = new(), + SkillClassNum = 2 + }); + } + } +} diff --git a/BLHX.Server.Game/Handlers/P26.cs b/BLHX.Server.Game/Handlers/P26.cs index ee8ec57..8d965b3 100644 --- a/BLHX.Server.Game/Handlers/P26.cs +++ b/BLHX.Server.Game/Handlers/P26.cs @@ -11,4 +11,11 @@ namespace BLHX.Server.Game.Handlers connection.Send(new Sc26102()); } } + static class P26ConnectionNotifyExtensions + { + public static void NotifyGameRoom(this Connection connection) + { + connection.Send(new Sc26120()); + } + } } diff --git a/BLHX.Server.Game/Packet.cs b/BLHX.Server.Game/Packet.cs index d57cac8..f3962db 100644 --- a/BLHX.Server.Game/Packet.cs +++ b/BLHX.Server.Game/Packet.cs @@ -6,15 +6,15 @@ using System.Reflection; namespace BLHX.Server.Game { - readonly struct Packet + struct Packet { public const int LENGTH_SIZE = 2; public const int HEADER_SIZE = 5; - public readonly ushort length; - public readonly byte flag; - public readonly Command command; - public readonly ushort id; - public readonly byte[] bytes; + public ushort length; + public byte flag; + public Command command; + public ushort id; + public byte[] bytes; public Packet(byte[] recv) { @@ -26,7 +26,7 @@ namespace BLHX.Server.Game Array.Copy(recv, HEADER_SIZE + LENGTH_SIZE, bytes, 0, length - HEADER_SIZE); } - public T Decode() where T : IExtensible => Serializer.Deserialize(bytes.AsSpan()); + public readonly T Decode() where T : IExtensible => Serializer.Deserialize(bytes.AsSpan()); } static class PacketFactory diff --git a/BLHX.Server/Program.cs b/BLHX.Server/Program.cs index de6ac73..2faa63a 100644 --- a/BLHX.Server/Program.cs +++ b/BLHX.Server/Program.cs @@ -1,4 +1,5 @@ using BLHX.Server.Common.Data; +using BLHX.Server.Common.Database; using BLHX.Server.Common.Utils; using BLHX.Server.Game; using BLHX.Server.Sdk; @@ -14,6 +15,8 @@ internal class Program Logger.c.Log($"Version {Assembly.GetEntryAssembly()?.GetCustomAttribute()?.InformationalVersion}"); Logger.c.Log("Starting..."); + // Preload + System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(DBManager).TypeHandle); Config.Load(); if (Config.Instance.Address == "127.0.0.1") {