From 99c0473b42c79e88b4b996c7bba52ed97d301ff8 Mon Sep 17 00:00:00 2001 From: rfi Date: Sat, 11 Nov 2023 14:28:21 +0700 Subject: [PATCH] PreFightResponse data from DB --- AscNet.Common/Database/Stage.cs | 1 + AscNet.Common/Util/Miscs.cs | 8 ++++ AscNet.GameServer/Handlers/ChatModule.cs | 2 +- AscNet.GameServer/Handlers/FightModule.cs | 55 ++++++++++++++++++++-- AscNet.GameServer/Handlers/PlayerModule.cs | 16 +++++++ AscNet.GameServer/Handlers/ShopModule.cs | 4 +- AscNet/Program.cs | 1 + 7 files changed, 79 insertions(+), 8 deletions(-) diff --git a/AscNet.Common/Database/Stage.cs b/AscNet.Common/Database/Stage.cs index 763e6a5b..aa10fce4 100644 --- a/AscNet.Common/Database/Stage.cs +++ b/AscNet.Common/Database/Stage.cs @@ -21,6 +21,7 @@ namespace AscNet.Common.Database { Stage stage = new() { + Uid = uid, Stages = new() }; foreach (var guideFight in GuideFightTableReader.Instance.All) diff --git a/AscNet.Common/Util/Miscs.cs b/AscNet.Common/Util/Miscs.cs index 96a86fc9..0f56c876 100644 --- a/AscNet.Common/Util/Miscs.cs +++ b/AscNet.Common/Util/Miscs.cs @@ -2,6 +2,14 @@ { public static class Miscs { + public static int ParseIntOr(string? s, int d) + { + if (int.TryParse(s, out var parsed)) + { + return parsed; + } + return d; + } public static byte[] HexStringToByteArray(string hex) { if (hex.Length % 2 == 1) diff --git a/AscNet.GameServer/Handlers/ChatModule.cs b/AscNet.GameServer/Handlers/ChatModule.cs index b2590a38..9285def3 100644 --- a/AscNet.GameServer/Handlers/ChatModule.cs +++ b/AscNet.GameServer/Handlers/ChatModule.cs @@ -19,7 +19,7 @@ namespace AscNet.GameServer.Handlers public static void GetWorldChannelInfoRequestHandler(Session session, Packet.Request packet) { GetWorldChannelInfoResponse getWorldChannelInfoResponse = new(); - getWorldChannelInfoResponse.ChannelInfos.Append(new() + getWorldChannelInfoResponse.ChannelInfos.Add(new() { ChannelId = 0, PlayerNum = 0 diff --git a/AscNet.GameServer/Handlers/FightModule.cs b/AscNet.GameServer/Handlers/FightModule.cs index 47105522..cecf8a95 100644 --- a/AscNet.GameServer/Handlers/FightModule.cs +++ b/AscNet.GameServer/Handlers/FightModule.cs @@ -1,4 +1,7 @@ -using AscNet.Common.MsgPack; +using AscNet.Common.Database; +using AscNet.Common.MsgPack; +using AscNet.Common.Util; +using AscNet.Table.share.fuben; using MessagePack; namespace AscNet.GameServer.Handlers @@ -87,14 +90,58 @@ namespace AscNet.GameServer.Handlers internal class FightModule { - public static object JSonConvert { get; private set; } - [RequestPacketHandler("PreFightRequest")] public static void PreFightRequestHandler(Session session, Packet.Request packet) { PreFightRequest req = MessagePackSerializer.Deserialize(packet.Content); - PreFightResponse rsp = MessagePackSerializer.Deserialize(MessagePackSerializer.ConvertFromJson($@"{{""Code"":0,""FightData"":{{""Online"":false,""FightId"":1691330911,""RoomId"":null,""OnlineMode"":0,""Seed"":631037736,""StageId"":{req.PreFightData.StageId},""RebootId"":1,""PassTimeLimit"":300,""StarsMark"":7,""MonsterLevel"":null,""EventIds"":[],""FightEventsWithLevel"":{{}},""NormalEventIds"":[1],""RoleData"":[{{""Id"":17462089,""Camp"":1,""Name"":""yarik0chka"",""IsRobot"":false,""CaptainIndex"":0,""FirstFightPos"":0,""NpcData"":{{""0"":{{""Character"":{{""Id"":1021001,""Level"":50,""Exp"":564,""Quality"":2,""InitQuality"":1,""Star"":4,""Grade"":8,""SkillList"":[{{""Id"":102101,""Level"":12}},{{""Id"":102106,""Level"":11}},{{""Id"":102111,""Level"":11}},{{""Id"":102116,""Level"":12}},{{""Id"":102117,""Level"":11}},{{""Id"":102118,""Level"":10}},{{""Id"":102121,""Level"":10}},{{""Id"":102123,""Level"":1}},{{""Id"":102122,""Level"":1}}],""EnhanceSkillList"":[],""FashionId"":6210101,""CreateTime"":1626538573,""TrustLv"":2,""TrustExp"":80,""Ability"":3387,""LiberateLv"":2,""CharacterHeadInfo"":{{""HeadFashionId"":0,""HeadFashionType"":0}}}},""Equips"":[{{""Id"":70,""TemplateId"":3035002,""CharacterId"":1021001,""Level"":45,""Exp"":60,""Breakthrough"":4,""ResonanceInfo"":[],""UnconfirmedResonanceInfo"":[],""AwakeSlotList"":[],""IsLock"":false,""CreateTime"":1626632133,""IsRecycle"":false}},{{""Id"":71,""TemplateId"":3065002,""CharacterId"":1021001,""Level"":40,""Exp"":220,""Breakthrough"":3,""ResonanceInfo"":[],""UnconfirmedResonanceInfo"":[],""AwakeSlotList"":[],""IsLock"":false,""CreateTime"":1626632133,""IsRecycle"":false}},{{""Id"":112,""TemplateId"":2025001,""CharacterId"":1021001,""Level"":45,""Exp"":160,""Breakthrough"":4,""ResonanceInfo"":[{{""Slot"":1,""Type"":1,""CharacterId"":0,""TemplateId"":20}}],""UnconfirmedResonanceInfo"":[],""AwakeSlotList"":[],""IsLock"":false,""CreateTime"":1626634841,""IsRecycle"":false}},{{""Id"":153,""TemplateId"":3025002,""CharacterId"":1021001,""Level"":45,""Exp"":10,""Breakthrough"":4,""ResonanceInfo"":[],""UnconfirmedResonanceInfo"":[],""AwakeSlotList"":[],""IsLock"":false,""CreateTime"":1626637516,""IsRecycle"":false}},{{""Id"":181,""TemplateId"":3015001,""CharacterId"":1021001,""Level"":45,""Exp"":260,""Breakthrough"":4,""ResonanceInfo"":[],""UnconfirmedResonanceInfo"":[],""AwakeSlotList"":[],""IsLock"":false,""CreateTime"":1626638512,""IsRecycle"":false}},{{""Id"":182,""TemplateId"":3045001,""CharacterId"":1021001,""Level"":45,""Exp"":10,""Breakthrough"":4,""ResonanceInfo"":[{{""Slot"":1,""Type"":1,""CharacterId"":0,""TemplateId"":27}},{{""Slot"":2,""Type"":1,""CharacterId"":0,""TemplateId"":26}}],""UnconfirmedResonanceInfo"":[],""AwakeSlotList"":[],""IsLock"":false,""CreateTime"":1626638512,""IsRecycle"":false}},{{""Id"":521,""TemplateId"":3055002,""CharacterId"":1021001,""Level"":1,""Exp"":0,""Breakthrough"":4,""ResonanceInfo"":[],""UnconfirmedResonanceInfo"":[],""AwakeSlotList"":[],""IsLock"":false,""CreateTime"":1626792402,""IsRecycle"":false}}],""AttribGroupList"":[],""CharacterSkillPlus"":null,""EquipSkillPlus"":[],""AttribReviseId"":0,""EventIds"":[],""FightEventsWithLevel"":{{}},""WeaponFashionId"":0,""Partner"":null,""IsRobot"":false,""AttrRateTable"":{{}}}}}},""CustomNpc"":null,""AssistNpcData"":null}}],""ReviseId"":0,""PlayerLevel"":0,""NpcGroupList"":null,""FightControlData"":{{""MaxFight"":0,""MaxRecommendFight"":0,""MaxShowFight"":0,""AvgFight"":0,""AvgRecommendFight"":0,""AvgShowFight"":0}},""DisableJoystick"":false,""Restartable"":false,""DisableDeadEffect"":false,""CustomData"":null,""Records"":{{}},""StStageDropData"":null}}}}")); + StageTable? stageTable = StageTableReader.Instance.FromStageId((int)req.PreFightData.StageId); + if (stageTable is null) + { + // FubenManagerCheckPreFightStageInfoNotFound + session.SendResponse(new PreFightResponse() { Code = 20003012 }, packet.Id); + return; + } + + PreFightResponse rsp = new() + { + Code = 0, + FightData = new() + { + Online = false, + FightId = req.PreFightData.StageId + (uint)Random.Shared.NextInt64(0, uint.MaxValue - req.PreFightData.StageId), + OnlineMode = 0, + Seed = (uint)Random.Shared.NextInt64(0, uint.MaxValue), + StageId = req.PreFightData.StageId, + RebootId = Miscs.ParseIntOr(stageTable.RebootId, 0), + PassTimeLimit = Miscs.ParseIntOr(stageTable.PassTimeLimit, 300), + StarsMark = 0 + } + }; + + rsp.FightData.RoleData.Add(new() + { + Id = (uint)session.player.PlayerData.Id, + Camp = 1, + Name = session.player.PlayerData.Name, + IsRobot = false, + NpcData = new() + }); + + for (int i = 0; i < req.PreFightData.CardIds.Count; i++) + { + uint cardId = req.PreFightData.CardIds[i]; + var characterData = session.character.Characters.FirstOrDefault(x => x.Id == cardId); + if (characterData is null) + continue; + + rsp.FightData.RoleData.First(x => x.Id == session.player.PlayerData.Id).NpcData.Add(i, new + { + Character = characterData, + Equips = session.character.Equips.Where(x => x.CharacterId == cardId) + }); + } + session.SendResponse(rsp, packet.Id); } diff --git a/AscNet.GameServer/Handlers/PlayerModule.cs b/AscNet.GameServer/Handlers/PlayerModule.cs index 6d456ffc..c4fc1634 100644 --- a/AscNet.GameServer/Handlers/PlayerModule.cs +++ b/AscNet.GameServer/Handlers/PlayerModule.cs @@ -1,12 +1,28 @@ using AscNet.Common.MsgPack; +using MessagePack; namespace AscNet.GameServer.Handlers { + [MessagePackObject(true)] + public class ChangePlayerMarkRequest + { + public long MaskId; + } + internal class PlayerModule { [RequestPacketHandler("ChangePlayerMarkRequest")] public static void ChangePlayerMarkRequestHandler(Session session, Packet.Request packet) { + ChangePlayerMarkRequest request = MessagePackSerializer.Deserialize(packet.Content); + + if (session.player.PlayerData.Marks is null) + { + session.log.Debug("Marks is somehow null"); + session.player.PlayerData.Marks = new(); + } + + session.player.PlayerData.Marks.Add(request.MaskId); session.SendResponse(new ChangePlayerMarkResponse(), packet.Id); } } diff --git a/AscNet.GameServer/Handlers/ShopModule.cs b/AscNet.GameServer/Handlers/ShopModule.cs index eddea8f9..d7f421b0 100644 --- a/AscNet.GameServer/Handlers/ShopModule.cs +++ b/AscNet.GameServer/Handlers/ShopModule.cs @@ -15,9 +15,7 @@ namespace AscNet.GameServer.Handlers [RequestPacketHandler("GetShopInfoReceiveRequest")] public static void GetShopInfoReceiveRequestHandler(Session session, Packet.Request packet) { - GetShopInfoRequest req = MessagePackSerializer.Deserialize(packet.Content); - - GetShopInfoResponse rsp = new GetShopInfoResponse() + GetShopInfoResponse rsp = new() { Code = 0, ClientShop = { } diff --git a/AscNet/Program.cs b/AscNet/Program.cs index 6f891887..e68356cb 100644 --- a/AscNet/Program.cs +++ b/AscNet/Program.cs @@ -10,6 +10,7 @@ namespace AscNet // TODO: Add loglevel parsing from appsettings file LoggerFactory.InitializeLogger(new Logger(typeof(Program), LogLevel.DEBUG, LogLevel.DEBUG)); LoggerFactory.Logger.Info("Starting..."); + #if DEBUG if (Common.Common.config.VerboseLevel < Common.VerboseLevel.Debug) Common.Common.config.VerboseLevel = Common.VerboseLevel.Debug;