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 OnPlayerChatReq(NetSession session, GmCommandService gm, Player player) { PlayerChatReq req = Packet!.DecodeBody(); 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 } }); } }