From a4b3b669a8a0e1509e127f157bdda016f3fa9c84 Mon Sep 17 00:00:00 2001 From: wisedev Date: Fri, 4 Sep 2026 11:21:12 +0300 Subject: [PATCH] Use the named retcode and reason constants Half the handlers were still answering with a bare 0 or -1 even though the whole retcode table is generated. Values on the wire are unchanged, they just read properly now. Same for the item hint reasons. ActionReasonType is a generated enum and we were redeclaring six of its members as private consts in four different files. --- Yuanshen.Gameserver/Controllers/AccountController.cs | 2 +- Yuanshen.Gameserver/Controllers/AvatarController.cs | 8 ++++---- Yuanshen.Gameserver/Controllers/ChatController.cs | 2 +- Yuanshen.Gameserver/Controllers/GadgetController.cs | 6 ++---- Yuanshen.Gameserver/Controllers/GmTalkController.cs | 2 +- Yuanshen.Gameserver/Controllers/MiscController.cs | 12 ++++++------ Yuanshen.Gameserver/Controllers/ShopController.cs | 3 +-- Yuanshen.Gameserver/Game/CombatManager.cs | 4 +--- Yuanshen.Gameserver/Game/GmCommandService.cs | 3 +-- Yuanshen.SDK/Handlers/RegionHandler.cs | 4 ++-- 10 files changed, 20 insertions(+), 26 deletions(-) diff --git a/Yuanshen.Gameserver/Controllers/AccountController.cs b/Yuanshen.Gameserver/Controllers/AccountController.cs index fddafa4..afecc29 100644 --- a/Yuanshen.Gameserver/Controllers/AccountController.cs +++ b/Yuanshen.Gameserver/Controllers/AccountController.cs @@ -111,7 +111,7 @@ internal sealed class AccountController : ControllerBase return Response(CmdType.PlayerLoginRsp, new PlayerLoginRsp { - Retcode = 0, + Retcode = Retcode.RET_SUCC, GameBiz = "hk4e_global" }); } diff --git a/Yuanshen.Gameserver/Controllers/AvatarController.cs b/Yuanshen.Gameserver/Controllers/AvatarController.cs index a87d7da..6a0f7e7 100644 --- a/Yuanshen.Gameserver/Controllers/AvatarController.cs +++ b/Yuanshen.Gameserver/Controllers/AvatarController.cs @@ -17,14 +17,14 @@ internal sealed class AvatarController : ControllerBase SetUpAvatarTeamReq req = Packet!.DecodeBody(); if (req.AvatarTeamGuidList.Count == 0) - return Response(CmdType.SetUpAvatarTeamRsp, new SetUpAvatarTeamRsp { Retcode = -1 }); + return Response(CmdType.SetUpAvatarTeamRsp, new SetUpAvatarTeamRsp { Retcode = Retcode.RET_FAIL }); await sceneManager.SetupTeamAsync(req.TeamId, req.AvatarTeamGuidList, req.CurAvatarGuid); await persistence.SaveAsync(); SetUpAvatarTeamRsp rsp = new() { - Retcode = 0, + Retcode = Retcode.RET_SUCC, TeamId = req.TeamId, CurAvatarGuid = player.CurrentAvatarGuid }; @@ -43,7 +43,7 @@ internal sealed class AvatarController : ControllerBase return Response(CmdType.ChangeAvatarRsp, new ChangeAvatarRsp { - Retcode = 0, + Retcode = Retcode.RET_SUCC, CurrGuid = req.Guid, SkillId = req.SkillId }); @@ -102,7 +102,7 @@ internal sealed class AvatarController : ControllerBase return Response(CmdType.WearEquipRsp, new WearEquipRsp { - Retcode = 0, + Retcode = Retcode.RET_SUCC, AvatarGuid = req.AvatarGuid, EquipGuid = req.EquipGuid }); diff --git a/Yuanshen.Gameserver/Controllers/ChatController.cs b/Yuanshen.Gameserver/Controllers/ChatController.cs index e90a92a..7af7432 100644 --- a/Yuanshen.Gameserver/Controllers/ChatController.cs +++ b/Yuanshen.Gameserver/Controllers/ChatController.cs @@ -25,7 +25,7 @@ internal sealed class ChatController : ControllerBase await ReplyAsync(session, req.ChannelId, player.Uid, text); } - return Response(CmdType.PlayerChatRsp, new PlayerChatRsp { Retcode = 0 }); + return Response(CmdType.PlayerChatRsp, new PlayerChatRsp { Retcode = Retcode.RET_SUCC }); } private static async ValueTask ReplyAsync(NetSession session, uint channelId, uint uid, string text) diff --git a/Yuanshen.Gameserver/Controllers/GadgetController.cs b/Yuanshen.Gameserver/Controllers/GadgetController.cs index 7d5028a..aecef51 100644 --- a/Yuanshen.Gameserver/Controllers/GadgetController.cs +++ b/Yuanshen.Gameserver/Controllers/GadgetController.cs @@ -13,8 +13,6 @@ namespace Yuanshen.Gameserver.Controllers; internal sealed class GadgetController : ControllerBase { private const uint ChestOpenedState = 102; - private const uint ActionReasonOpenChest = 39; - private const uint ActionReasonGather = 11; private const uint MoraItemId = 202; private const uint PrimogemItemId = 201; @@ -55,7 +53,7 @@ internal sealed class GadgetController : ControllerBase await scene.SetGadgetStateAsync(gadget, ChestOpenedState, false); Dictionary rolled = drops.Roll(gadget.Node.DropId, Random); - await GrantAsync(session, player, drops, excel, gadget, rolled, ActionReasonOpenChest); + await GrantAsync(session, player, drops, excel, gadget, rolled, (uint)ActionReasonType.ActionReasonOpenChest); await persistence.SaveAsync(); @@ -89,7 +87,7 @@ internal sealed class GadgetController : ControllerBase if (rolled.Count == 0 && gadget.Node.GatherItemId != 0) rolled[gadget.Node.GatherItemId] = 1; - await GrantAsync(session, player, drops, excel, gadget, rolled, ActionReasonGather); + await GrantAsync(session, player, drops, excel, gadget, rolled, (uint)ActionReasonType.ActionReasonGather); await scene.DespawnGadgetAsync(gadget, VisionType.VisionGatherEscape); await persistence.SaveAsync(); diff --git a/Yuanshen.Gameserver/Controllers/GmTalkController.cs b/Yuanshen.Gameserver/Controllers/GmTalkController.cs index 6b73128..08e4b9a 100644 --- a/Yuanshen.Gameserver/Controllers/GmTalkController.cs +++ b/Yuanshen.Gameserver/Controllers/GmTalkController.cs @@ -25,7 +25,7 @@ internal sealed class GmTalkController : ControllerBase return Response(CmdType.GmTalkRsp, new GmTalkRsp { - Retcode = 0, + Retcode = Retcode.RET_SUCC, Msg = message, Retmsg = string.Join('\n', reply) }); diff --git a/Yuanshen.Gameserver/Controllers/MiscController.cs b/Yuanshen.Gameserver/Controllers/MiscController.cs index ace7ead..0955bc8 100644 --- a/Yuanshen.Gameserver/Controllers/MiscController.cs +++ b/Yuanshen.Gameserver/Controllers/MiscController.cs @@ -29,7 +29,7 @@ internal sealed class MiscController : ControllerBase GetScenePointRsp rsp = new() { - Retcode = 0, + Retcode = Retcode.RET_SUCC, SceneId = req.SceneId, BelongUid = player.Uid }; @@ -50,7 +50,7 @@ internal sealed class MiscController : ControllerBase GetSceneAreaRsp rsp = new() { - Retcode = 0, + Retcode = Retcode.RET_SUCC, SceneId = req.SceneId }; @@ -64,7 +64,7 @@ internal sealed class MiscController : ControllerBase public ValueTask OnGetPlayerSocialDetailReq(Player player) => ValueTask.FromResult(Response(CmdType.GetPlayerSocialDetailRsp, new GetPlayerSocialDetailRsp { - Retcode = 0, + Retcode = Retcode.RET_SUCC, DetailData = new SocialDetail { Uid = player.Uid, @@ -77,7 +77,7 @@ internal sealed class MiscController : ControllerBase [NetCommand(CmdType.GetPlayerBlacklistReq)] public ValueTask OnGetPlayerBlacklistReq() - => ValueTask.FromResult(Response(CmdType.GetPlayerBlacklistRsp, new GetPlayerBlacklistRsp { Retcode = 0 })); + => ValueTask.FromResult(Response(CmdType.GetPlayerBlacklistRsp, new GetPlayerBlacklistRsp { Retcode = Retcode.RET_SUCC })); [NetCommand(CmdType.SceneTransToPointReq)] public async ValueTask OnSceneTransToPointReq(NetSession session, GameState state, Player player, ScenePointTable points, ILogger logger) @@ -105,7 +105,7 @@ internal sealed class MiscController : ControllerBase return Response(CmdType.SceneTransToPointRsp, new SceneTransToPointRsp { - Retcode = 0, + Retcode = Retcode.RET_SUCC, SceneId = req.SceneId, PointId = req.PointId }); @@ -115,7 +115,7 @@ internal sealed class MiscController : ControllerBase public ValueTask OnMarkMapReq() { MarkMapReq req = Packet!.DecodeBody(); - MarkMapRsp rsp = new() { Retcode = 0 }; + MarkMapRsp rsp = new() { Retcode = Retcode.RET_SUCC }; if (req.Mark is not null) rsp.MarkList.Add(req.Mark); diff --git a/Yuanshen.Gameserver/Controllers/ShopController.cs b/Yuanshen.Gameserver/Controllers/ShopController.cs index 78075c6..f3289f2 100644 --- a/Yuanshen.Gameserver/Controllers/ShopController.cs +++ b/Yuanshen.Gameserver/Controllers/ShopController.cs @@ -12,7 +12,6 @@ namespace Yuanshen.Gameserver.Controllers; [NetController] internal sealed class ShopController : ControllerBase { - private const uint ActionReasonShop = 4; [NetCommand(CmdType.GetShopmallDataReq)] public ValueTask OnGetShopmallDataReq(ExcelTableCollection excel) @@ -106,7 +105,7 @@ internal sealed class ShopController : ControllerBase await session.NotifyAsync(CmdType.StoreItemChangeNotify, store); await session.NotifyAsync(CmdType.PlayerPropNotify, player.BuildCurrencyProps()); - ItemAddHintNotify hint = new() { Reason = ActionReasonShop }; + ItemAddHintNotify hint = new() { Reason = (uint)ActionReasonType.ActionReasonShop }; hint.ItemList.Add(new ItemHint { ItemId = goods.ItemId, Count = gained, IsNew = false }); await session.NotifyAsync(CmdType.ItemAddHintNotify, hint); diff --git a/Yuanshen.Gameserver/Game/CombatManager.cs b/Yuanshen.Gameserver/Game/CombatManager.cs index f1919eb..ed56bd5 100644 --- a/Yuanshen.Gameserver/Game/CombatManager.cs +++ b/Yuanshen.Gameserver/Game/CombatManager.cs @@ -9,8 +9,6 @@ internal sealed class CombatManager { private const uint FightPropCurHp = 1010; private const uint FightPropMaxHp = 2000; - private const uint ActionReasonMonsterDie = 37; - private const uint ActionReasonMonsterEnvAnimal = 8; private const uint MoraItemId = 202; private const uint PrimogemItemId = 201; @@ -104,7 +102,7 @@ internal sealed class CombatManager StoreItemChangeNotify store = new() { StoreType = StoreType.StorePack }; ItemAddHintNotify hint = new() { - Reason = monster.IsWildlife ? ActionReasonMonsterEnvAnimal : ActionReasonMonsterDie, + Reason = monster.IsWildlife ? (uint)ActionReasonType.ActionReasonMonsterEnvAnimal : (uint)ActionReasonType.ActionReasonMonsterDie, Position = monster.Pos, IsPositionValid = true }; diff --git a/Yuanshen.Gameserver/Game/GmCommandService.cs b/Yuanshen.Gameserver/Game/GmCommandService.cs index 4b77054..7895b67 100644 --- a/Yuanshen.Gameserver/Game/GmCommandService.cs +++ b/Yuanshen.Gameserver/Game/GmCommandService.cs @@ -10,7 +10,6 @@ internal sealed class GmCommandService { private const int TeamSize = 4; private const uint MoraItemId = 202; - private const uint ActionReasonTrifle = 3; private const uint MaxConstellation = 6; private readonly Player _player; @@ -419,7 +418,7 @@ internal sealed class GmCommandService await _session.NotifyAsync(CmdType.StoreItemChangeNotify, notify); - ItemAddHintNotify hint = new() { Reason = ActionReasonTrifle }; + ItemAddHintNotify hint = new() { Reason = (uint)ActionReasonType.ActionReasonTrifle }; hint.ItemList.Add(new ItemHint { ItemId = itemId, Count = count, IsNew = false }); await _session.NotifyAsync(CmdType.ItemAddHintNotify, hint); diff --git a/Yuanshen.SDK/Handlers/RegionHandler.cs b/Yuanshen.SDK/Handlers/RegionHandler.cs index 44d90a8..9c6cb83 100644 --- a/Yuanshen.SDK/Handlers/RegionHandler.cs +++ b/Yuanshen.SDK/Handlers/RegionHandler.cs @@ -19,7 +19,7 @@ public static class RegionHandler { QueryRegionListHttpRsp rsp = new() { - Retcode = 0, + Retcode = Retcode.RET_SUCC, EnableLoginPc = true, ClientCustomConfigEncrypted = ByteString.CopyFromUtf8(CLIENT_CUSTOM_CONFIG), Servers = @@ -41,7 +41,7 @@ public static class RegionHandler { QueryCurrRegionHttpRsp rsp = new() { - Retcode = 0, + Retcode = Retcode.RET_SUCC, RegionInfo = new RegionInfo { Ip = GATESERVER_IP,