频道聊天相关

This commit is contained in:
2025-08-12 14:05:23 +08:00
parent 12c328d538
commit 15723850c0
17 changed files with 212 additions and 66 deletions

View File

@@ -0,0 +1,45 @@
using Fantasy;
using Fantasy.Async;
using Fantasy.Network.Interface;
namespace NB.Chat;
/// <summary>
/// 请求进入频道
/// </summary>
public class
C2Chat_JoinChannelRequestHandler : RouteRPC<ChatUnit, C2Chat_JoinChannelRequest, Caht2C_JoinChannelResponse>
{
protected override async FTask Run(ChatUnit entity, C2Chat_JoinChannelRequest request,
Caht2C_JoinChannelResponse response, Action reply)
{
var channelCenter = entity.Scene.GetComponent<ChatChannelCenterComponent>();
if (channelCenter == null)
{
response.ErrorCode = ErrorCode.ErrServer;
return;
}
var oldChannelId = entity.CurrentChannel;
if (oldChannelId > 0)
{
//退出旧的频道
if (channelCenter.TryGet(oldChannelId, out var oldChannel) && oldChannel != null)
{
oldChannel.Exit(entity);
}
}
//加入新频道
if (channelCenter.TryGet(request.Target, out var channel) && channel != null)
{
channel.Enter(entity);
}
else
{
response.ErrorCode = ErrorCode.ChatNotChannel;
}
await FTask.CompletedTask;
}
}