using Fantasy;
using Fantasy.Async;
using Fantasy.Network.Interface;
namespace NB.Chat;
///
/// 请求进入频道
///
public class
C2Chat_JoinChannelRequestHandler : RouteRPC
{
protected override async FTask Run(ChatUnit entity, C2Chat_JoinChannelRequest request,
Caht2C_JoinChannelResponse response, Action reply)
{
var channelCenter = entity.Scene.GetComponent();
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;
}
}
}