yuanshen/Yuanshen.Gameserver/Controllers/ChatController.cs
wisedev a4b3b669a8 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.
2026-09-04 11:21:12 +03:00

44 lines
1.4 KiB
C#

using Yuanshen.Gameserver.Controllers.Attributes;
using Yuanshen.Gameserver.Controllers.Result;
using Yuanshen.Gameserver.Game;
using Yuanshen.Gameserver.Network.Session;
using Yuanshen.Protocol;
namespace Yuanshen.Gameserver.Controllers;
[NetController]
internal sealed class ChatController : ControllerBase
{
[NetCommand(CmdType.PlayerChatReq)]
public async ValueTask<IResult> OnPlayerChatReq(NetSession session, GmCommandService gm, Player player)
{
PlayerChatReq req = Packet!.DecodeBody<PlayerChatReq>();
string text = req.ChatInfo?.Text ?? string.Empty;
if (text.StartsWith('/'))
{
foreach (string line in await gm.ExecuteAsync(text))
await ReplyAsync(session, req.ChannelId, player.Uid, line);
}
else if (!string.IsNullOrEmpty(text))
{
await ReplyAsync(session, req.ChannelId, player.Uid, text);
}
return Response(CmdType.PlayerChatRsp, new PlayerChatRsp { Retcode = Retcode.RET_SUCC });
}
private static async ValueTask ReplyAsync(NetSession session, uint channelId, uint uid, string text)
{
await session.NotifyAsync(CmdType.PlayerChatNotify, new PlayerChatNotify
{
ChannelId = channelId,
ChatInfo = new ChatInfo
{
Time = (uint)DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
Uid = uid,
Text = text
}
});
}
}