频道聊天相关
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;
|
||||
}
|
||||
}
|
||||
@@ -8,16 +8,7 @@ public static class ChatSceneHelper
|
||||
{
|
||||
#region 消息发送
|
||||
|
||||
/// <summary>
|
||||
/// 广播记录更新
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="record"></param>
|
||||
public static void BroadcastRecord(Scene scene, ChatContentRecord record)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 广播消息给所有人
|
||||
|
||||
@@ -1,10 +1,38 @@
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Entitas.Interface;
|
||||
using Fantasy.Helper;
|
||||
|
||||
namespace NB.Chat;
|
||||
|
||||
public class ChatChannelCenterComponentAwakeSystem : AwakeSystem<ChatChannelCenterComponent>
|
||||
{
|
||||
protected override void Awake(ChatChannelCenterComponent self)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class ChatChannelCenterComponentDestroySystem : DestroySystem<ChatChannelCenterComponent>
|
||||
{
|
||||
protected override void Destroy(ChatChannelCenterComponent self)
|
||||
{
|
||||
self.Channels.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ChatChannelCenterComponentSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <param name="channelId"></param>
|
||||
/// <param name="channel"></param>
|
||||
/// <returns></returns>
|
||||
public static bool TryGet(this ChatChannelCenterComponent self, long channelId, out ChatChannel? channel)
|
||||
{
|
||||
return self.Channels.TryGetValue(channelId, out channel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 申请创建一个频道
|
||||
/// </summary>
|
||||
@@ -26,18 +54,6 @@ public static class ChatChannelCenterComponentSystem
|
||||
return channel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <param name="channelId"></param>
|
||||
/// <param name="channel"></param>
|
||||
/// <returns></returns>
|
||||
public static bool TryGet(this ChatChannelCenterComponent self, long channelId, out ChatChannel? channel)
|
||||
{
|
||||
return self.Channels.TryGetValue(channelId, out channel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解散
|
||||
/// </summary>
|
||||
|
||||
26
Hotfix/Chat/System/ChatChannelSystem.cs
Normal file
26
Hotfix/Chat/System/ChatChannelSystem.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
namespace NB.Chat;
|
||||
|
||||
public static class ChatChannelSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// 进入频道
|
||||
/// </summary>
|
||||
/// <param name="channel"></param>
|
||||
/// <param name="unit"></param>
|
||||
public static void Enter(this ChatChannel channel, ChatUnit unit)
|
||||
{
|
||||
channel.Units.Add(unit.Id);
|
||||
unit.CurrentChannel = channel.Id;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 离开频道
|
||||
/// </summary>
|
||||
/// <param name="channel"></param>
|
||||
/// <param name="unit"></param>
|
||||
public static void Exit(this ChatChannel channel, ChatUnit unit)
|
||||
{
|
||||
channel.Units.Remove(unit.Id);
|
||||
unit.CurrentChannel = 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user