yuanshen/Yuanshen.Gameserver/Controllers/ChatController.cs
wisedev 61cc2055cf First working version of the server
KCP gameserver with packet dispatch, scene streaming, combat, gacha and the
shop, plus a small HTTP server for the login flow and the wish history page.

Game data under assets is pulled out of the client instead of being typed by
hand. The excel tables come from the packed bin container and the spawn points
from the compiled scene scripts.
2026-09-04 02:06:53 +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 = 0 });
}
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
}
});
}
}