协议定义
This commit is contained in:
26
Hotfix/Chat/Handler/C2Chat_CreateChannelRequestHandler.cs
Normal file
26
Hotfix/Chat/Handler/C2Chat_CreateChannelRequestHandler.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace NB.Chat;
|
||||
|
||||
/// <summary>
|
||||
/// 请求创建频道
|
||||
/// </summary>
|
||||
public class
|
||||
C2Chat_CreateChannelRequestHandler : RouteRPC<ChatUnit, C2Chat_CreateChannelRequest, Caht2C_CreateChannelResponse>
|
||||
{
|
||||
protected override async FTask Run(ChatUnit entity, C2Chat_CreateChannelRequest request,
|
||||
Caht2C_CreateChannelResponse response, Action reply)
|
||||
{
|
||||
var channelCenter = entity.Scene.GetComponent<ChatChannelCenterComponent>();
|
||||
if (channelCenter == null)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ErrServer;
|
||||
return;
|
||||
}
|
||||
|
||||
var channel = await channelCenter.Create(entity);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -24,22 +24,22 @@ public class
|
||||
if (oldChannelId > 0)
|
||||
{
|
||||
//退出旧的频道
|
||||
if (channelCenter.TryGet(oldChannelId, out var oldChannel) && oldChannel != null)
|
||||
var oldChannel = await channelCenter.Get(oldChannelId);
|
||||
if (oldChannel != null)
|
||||
{
|
||||
oldChannel.Exit(entity);
|
||||
}
|
||||
}
|
||||
|
||||
//加入新频道
|
||||
if (channelCenter.TryGet(request.Target, out var channel) && channel != null)
|
||||
var newChannel = await channelCenter.Get(request.Target);
|
||||
if (newChannel != null)
|
||||
{
|
||||
channel.Enter(entity);
|
||||
newChannel.Enter(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ChatNotChannel;
|
||||
}
|
||||
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,14 @@ public sealed class
|
||||
protected override async FTask Run(ChatUnit chatUnit, C2Chat_SendMessageRequest request,
|
||||
Caht2C_SendMessageResponse response, Action reply)
|
||||
{
|
||||
if (request.Type == 0) //频道聊天
|
||||
{
|
||||
|
||||
}
|
||||
else if (request.Type == 1) //私聊
|
||||
{
|
||||
|
||||
}
|
||||
ChatSceneHelper.Broadcast(chatUnit.Scene, new ChatMessageInfo()
|
||||
{
|
||||
Content = request.Message,
|
||||
|
||||
Reference in New Issue
Block a user