diff --git a/BLHX.Server.Common/Utils/DateTimeExtensions.cs b/BLHX.Server.Common/Utils/DateTimeExtensions.cs new file mode 100644 index 0000000..8c085be --- /dev/null +++ b/BLHX.Server.Common/Utils/DateTimeExtensions.cs @@ -0,0 +1,14 @@ +namespace BLHX.Server.Common.Utils +{ + public static class DateTimeExtensions + { + public static int GetWeekOfMonth(this DateTime date) + { + int dayOfMonth = date.Day; + DateTime firstDayOfMonth = new(date.Year, date.Month, 1); + DayOfWeek firstDayOfWeek = firstDayOfMonth.DayOfWeek; + int offset = (dayOfMonth + (int)firstDayOfWeek - 1) / 7; + return offset + 1; + } + } +} diff --git a/BLHX.Server.Game/Connection.cs b/BLHX.Server.Game/Connection.cs index 6b0b6c3..4807531 100644 --- a/BLHX.Server.Game/Connection.cs +++ b/BLHX.Server.Game/Connection.cs @@ -1,7 +1,7 @@ using BLHX.Server.Common.Database; using BLHX.Server.Common.Proto; -using BLHX.Server.Common.Proto.p11; using BLHX.Server.Common.Utils; +using BLHX.Server.Game.Handlers; using ProtoBuf; using System.Buffers.Binary; using System.Net; @@ -117,6 +117,13 @@ namespace BLHX.Server.Game ns.Write(sendBuf); } + public void InitClientData() + { + this.NotifyPlayerData(); + this.NotifyStatisticsInit(); + this.NotifyShipData(); + } + public void SendHttpResponse(string rsp, string type = "text/plain") { tcpClient.GetStream().Write(Encoding.UTF8.GetBytes( diff --git a/BLHX.Server.Game/Handlers/P11.cs b/BLHX.Server.Game/Handlers/P11.cs index 192d12e..e2b5f8e 100644 --- a/BLHX.Server.Game/Handlers/P11.cs +++ b/BLHX.Server.Game/Handlers/P11.cs @@ -8,9 +8,7 @@ namespace BLHX.Server.Game.Handlers [PacketHandler(Command.Cs11001)] static void ServerTimeHandler(Connection connection, Packet packet) { - connection.NotifyPlayerData(); - connection.NotifyStatisticsInit(); - connection.NotifyShipData(); + connection.InitClientData(); connection.Send(new Sc11002() { Timestamp = (uint)DateTimeOffset.Now.ToUnixTimeSeconds(), @@ -19,6 +17,18 @@ namespace BLHX.Server.Game.Handlers }); } + [PacketHandler(Command.Cs11603)] + static void FetchSecondaryPasswordHandler(Connection connection, Packet packet) + { + connection.Send(new Sc11604()); + } + + [PacketHandler(Command.Cs11017)] + static void StageDropListHandler(Connection connection, Packet packet) + { + connection.Send(new Sc11018()); + } + [PacketHandler(Command.Cs11401)] static void ChangeChatRoomHandler(Connection connection, Packet packet) { @@ -51,7 +61,10 @@ namespace BLHX.Server.Game.Handlers GmFlag = 1, Rank = 1, GuideIndex = 1, + ChatRoomId = 1, RegisterTime = (uint)new DateTimeOffset(connection.player.CreatedAt).ToUnixTimeSeconds(), + ShipCount = (uint)connection.player.Ships.Count, + CommanderBagMax = 40, Display = connection.player.DisplayInfo, Appreciation = new() }); diff --git a/BLHX.Server.Game/Handlers/P12.cs b/BLHX.Server.Game/Handlers/P12.cs index 53e9405..a9e6a4c 100644 --- a/BLHX.Server.Game/Handlers/P12.cs +++ b/BLHX.Server.Game/Handlers/P12.cs @@ -18,5 +18,18 @@ namespace BLHX.Server.Game.Handlers }); } } + + public static void NotifyFleetData(this Connection connection) + { + if (connection.player is not null) + { + connection.Send(new Sc12101() + { + GroupLists = [ + new Groupinfo() { Id = 1, ShipLists = [1, 2] } + ] + }); + } + } } } diff --git a/BLHX.Server.Game/Handlers/P18.cs b/BLHX.Server.Game/Handlers/P18.cs new file mode 100644 index 0000000..48be597 --- /dev/null +++ b/BLHX.Server.Game/Handlers/P18.cs @@ -0,0 +1,17 @@ +using BLHX.Server.Common.Proto; +using BLHX.Server.Common.Proto.p18; + +namespace BLHX.Server.Game.Handlers +{ + internal static class P18 + { + [PacketHandler(Command.Cs18001)] + static void SeasonInfoHandler(Connection connection, Packet packet) + { + connection.Send(new Sc18002() + { + Rank = 1 + }); + } + } +} diff --git a/BLHX.Server.Game/Handlers/P24.cs b/BLHX.Server.Game/Handlers/P24.cs new file mode 100644 index 0000000..7c37cd4 --- /dev/null +++ b/BLHX.Server.Game/Handlers/P24.cs @@ -0,0 +1,14 @@ +using BLHX.Server.Common.Proto; +using BLHX.Server.Common.Proto.p24; + +namespace BLHX.Server.Game.Handlers +{ + internal static class P24 + { + [PacketHandler(Command.Cs24020)] + static void LimitChallengeHandler(Connection connection, Packet packet) + { + connection.Send(new Sc24021()); + } + } +} diff --git a/BLHX.Server.Game/Handlers/P26.cs b/BLHX.Server.Game/Handlers/P26.cs new file mode 100644 index 0000000..ee8ec57 --- /dev/null +++ b/BLHX.Server.Game/Handlers/P26.cs @@ -0,0 +1,14 @@ +using BLHX.Server.Common.Proto; +using BLHX.Server.Common.Proto.p26; + +namespace BLHX.Server.Game.Handlers +{ + internal static class P26 + { + [PacketHandler(Command.Cs26101)] + static void MiniGameHandler(Connection connection, Packet packet) + { + connection.Send(new Sc26102()); + } + } +} diff --git a/BLHX.Server.Game/Handlers/P27.cs b/BLHX.Server.Game/Handlers/P27.cs new file mode 100644 index 0000000..4a6266c --- /dev/null +++ b/BLHX.Server.Game/Handlers/P27.cs @@ -0,0 +1,53 @@ +using BLHX.Server.Common.Proto; +using BLHX.Server.Common.Proto.p27; +using BLHX.Server.Common.Utils; + +namespace BLHX.Server.Game.Handlers +{ + internal static class P27 + { + [PacketHandler(Command.Cs27000)] + static void EducateHandler(Connection connection, Packet packet) + { + connection.Send(new Sc27001() + { + Child = new() + { + Tid = 1, + CurTime = new() { Month = (uint)DateTimeOffset.Now.Month, Week = (uint)DateTime.Now.GetWeekOfMonth(), Day = (uint)DateTimeOffset.Now.AddDays(-1).DayOfWeek }, + Mood = 50, + Money = 20, + Attrs = [ + new ChildAttr() { Id = 101, Val = 0 }, + new ChildAttr() { Id = 102, Val = 0 }, + new ChildAttr() { Id = 103, Val = 0 }, + new ChildAttr() { Id = 104, Val = 0 }, + new ChildAttr() { Id = 201, Val = 0 }, + new ChildAttr() { Id = 202, Val = 0 }, + new ChildAttr() { Id = 203, Val = 0 }, + new ChildAttr() { Id = 301, Val = 0 }, + new ChildAttr() { Id = 302, Val = 0 }, + new ChildAttr() { Id = 303, Val = 0 }, + new ChildAttr() { Id = 304, Val = 0 }, + new ChildAttr() { Id = 305, Val = 0 }, + new ChildAttr() { Id = 306, Val = 0 } + ], + Favor = new() { Lv = 1, Exp = 0 }, + Tasks = [ + new ChildTask() { Id = 101, Progress = 0 }, + new ChildTask() { Id = 102, Progress = 0 }, + new ChildTask() { Id = 103, Progress = 0 }, + ], + CanTriggerHomeEvent = 1, + NewGamePlusCount = 1 + } + }); + } + + [PacketHandler(Command.Cs27010)] + static void EducateEndingsHandler(Connection connection, Packet packet) + { + connection.Send(new Sc27011()); + } + } +} diff --git a/BLHX.Server.Game/Handlers/P34.cs b/BLHX.Server.Game/Handlers/P34.cs new file mode 100644 index 0000000..080205f --- /dev/null +++ b/BLHX.Server.Game/Handlers/P34.cs @@ -0,0 +1,18 @@ +using BLHX.Server.Common.Proto; +using BLHX.Server.Common.Proto.p34; + +namespace BLHX.Server.Game.Handlers +{ + internal static class P34 + { + [PacketHandler(Command.Cs34001)] + static void GetMetaPTHandler(Connection connection, Packet packet) + { + var req = packet.Decode(); + connection.Send(new Sc34002() + { + MetaShipLists = req.GroupIds.Select(x => new MetaShipInfo() { GroupId = x }).ToList() + }); + } + } +} diff --git a/BLHX.Server.Game/Handlers/P60.cs b/BLHX.Server.Game/Handlers/P60.cs new file mode 100644 index 0000000..af069c0 --- /dev/null +++ b/BLHX.Server.Game/Handlers/P60.cs @@ -0,0 +1,35 @@ +using BLHX.Server.Common.Proto; +using BLHX.Server.Common.Proto.p60; + +namespace BLHX.Server.Game.Handlers +{ + internal static class P60 + { + [PacketHandler(Command.Cs60037)] + static void GuildInfoHandler(Connection connection, Packet packet) + { + connection.Send(new Sc60000() + { + Guild = new() + { + DonateTasks = [1], + TechIds = [8, 0, 18, 6, 8, 0, 16, 0, 24, 0, 24, 0, 40, 0, 48, 0, 56, 0, 64, 0], + BenefitTime = 1, + WeeklyTaskFlag = 1 + } + }); + } + + [PacketHandler(Command.Cs60102)] + static void GuildUserInfoHandler(Connection connection, Packet packet) + { + connection.Send(new Sc60103() + { + UserInfo = new() + { + DonateTasks = [1, 20, 4] + } + }); + } + } +} diff --git a/BLHX.Server.Game/Handlers/P62.cs b/BLHX.Server.Game/Handlers/P62.cs new file mode 100644 index 0000000..3376d7d --- /dev/null +++ b/BLHX.Server.Game/Handlers/P62.cs @@ -0,0 +1,14 @@ +using BLHX.Server.Common.Proto; +using BLHX.Server.Common.Proto.p62; + +namespace BLHX.Server.Game.Handlers +{ + internal static class P62 + { + [PacketHandler(Command.Cs62100)] + static void GuildPublicUserDataHandler(Connection connection, Packet packet) + { + connection.Send(new Sc62101()); + } + } +} diff --git a/BLHX.Server.PcapParser/PcapParser.cs b/BLHX.Server.PcapParser/PcapParser.cs index a660340..bdbfede 100644 --- a/BLHX.Server.PcapParser/PcapParser.cs +++ b/BLHX.Server.PcapParser/PcapParser.cs @@ -30,8 +30,7 @@ namespace BLHX.Server.PcapParser // Open the capture file using (PacketCommunicator communicator = - selectedDevice.Open(65536, // portion of the packet to capture - // 65536 guarantees that the whole packet will be captured on all the link layers + selectedDevice.Open(65536, // portion of the packet to capture, 65536 guarantees that the whole packet will be captured on all the link layers PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode 1000)) // read timeout {