Files
Fishing2Server/Hotfix/Chat/Handler/C2Chat_JoinChannelRequestHandler.cs
2025-08-12 14:05:23 +08:00

45 lines
1.2 KiB
C#

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