Files
Fishing2Server/Hotfix/Chat/Handler/C2Chat_JoinChannelRequestHandler.cs
2025-08-12 17:28:22 +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)
{
//退出旧的频道
var oldChannel = await channelCenter.Get(oldChannelId);
if (oldChannel != null)
{
oldChannel.Exit(entity);
}
}
//加入新频道
var newChannel = await channelCenter.Get(request.Target);
if (newChannel != null)
{
newChannel.Enter(entity);
}
else
{
response.ErrorCode = ErrorCode.ChatNotChannel;
}
}
}