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.
This commit is contained in:
wisedev 2026-09-04 11:21:12 +03:00
parent 62205c8062
commit a4b3b669a8
10 changed files with 20 additions and 26 deletions

View file

@ -111,7 +111,7 @@ internal sealed class AccountController : ControllerBase
return Response(CmdType.PlayerLoginRsp, new PlayerLoginRsp
{
Retcode = 0,
Retcode = Retcode.RET_SUCC,
GameBiz = "hk4e_global"
});
}

View file

@ -17,14 +17,14 @@ internal sealed class AvatarController : ControllerBase
SetUpAvatarTeamReq req = Packet!.DecodeBody<SetUpAvatarTeamReq>();
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
});

View file

@ -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)

View file

@ -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<uint, uint> 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();

View file

@ -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)
});

View file

@ -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<IResult> 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<IResult> 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<IResult> OnSceneTransToPointReq(NetSession session, GameState state, Player player, ScenePointTable points, ILogger<MiscController> 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<IResult> OnMarkMapReq()
{
MarkMapReq req = Packet!.DecodeBody<MarkMapReq>();
MarkMapRsp rsp = new() { Retcode = 0 };
MarkMapRsp rsp = new() { Retcode = Retcode.RET_SUCC };
if (req.Mark is not null)
rsp.MarkList.Add(req.Mark);

View file

@ -12,7 +12,6 @@ namespace Yuanshen.Gameserver.Controllers;
[NetController]
internal sealed class ShopController : ControllerBase
{
private const uint ActionReasonShop = 4;
[NetCommand(CmdType.GetShopmallDataReq)]
public ValueTask<IResult> 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);

View file

@ -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
};

View file

@ -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);

View file

@ -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,