频道聊天相关
This commit is contained in:
45
Hotfix/Chat/Handler/C2Chat_JoinChannelRequestHandler.cs
Normal file
45
Hotfix/Chat/Handler/C2Chat_JoinChannelRequestHandler.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user