完成离线消息发送和上线获取离线消息

This commit is contained in:
2025-08-13 23:44:59 +08:00
parent f8b876ca2f
commit 022cc1ac3e
39 changed files with 499 additions and 85 deletions

View File

@@ -21,6 +21,7 @@ public class
}
var channel = await channelCenter.Create(entity);
response.ChannelId = channel.Id;
}
}

View File

@@ -0,0 +1,24 @@
using Fantasy;
using Fantasy.Async;
using Fantasy.Network.Interface;
namespace NB.Chat;
public class
C2Chat_GetOfflineMessageRequestHandler : RouteRPC<ChatUnit, C2Chat_GetOfflineMessageRequest,
Caht2C_GetOfflineMessageResponse>
{
protected override async FTask Run(ChatUnit entity, C2Chat_GetOfflineMessageRequest request,
Caht2C_GetOfflineMessageResponse response,
Action reply)
{
var chatUnitManage = entity.Scene.GetComponent<ChatUnitManageComponent>();
if (chatUnitManage.NotSendMessage.TryGetValue(entity.Id, out var list))
{
response.Message.AddRange(list);
chatUnitManage.NotSendMessage.RemoveByKey(entity.Id);
}
await FTask.CompletedTask;
}
}

View File

@@ -13,6 +13,11 @@ public class
protected override async FTask Run(ChatUnit entity, C2Chat_JoinChannelRequest request,
Caht2C_JoinChannelResponse response, Action reply)
{
if (request.Target < 1)
{
response.ErrorCode = ErrorCode.ErrArgs;
return;
}
var channelCenter = entity.Scene.GetComponent<ChatChannelCenterComponent>();
if (channelCenter == null)
{

View File

@@ -11,18 +11,35 @@ public sealed class
protected override async FTask Run(ChatUnit chatUnit, C2Chat_SendMessageRequest request,
Caht2C_SendMessageResponse response, Action reply)
{
if (request.Target < 1)
{
response.ErrorCode = ErrorCode.ErrArgs;
return;
}
if (request.Type == 0) //频道聊天
{
ChatSceneHelper.BroadcastChannel(chatUnit.Scene, request.Target, new ChatMessageInfo()
{
Content = request.Message,
});
}
else if (request.Type == 1) //私聊
{
//发送私聊
ChatSceneHelper.PrivateMessage(chatUnit.Scene, chatUnit.Id, request.Target, new ChatMessageInfo()
{
Content = request.Message,
});
}
ChatSceneHelper.Broadcast(chatUnit.Scene, new ChatMessageInfo()
else if (request.Type == 3) //广播聊天
{
Content = request.Message,
});
ChatSceneHelper.BroadcastAll(chatUnit.Scene, new ChatMessageInfo()
{
Content = request.Message,
});
}
await FTask.CompletedTask;
}
}

View File

@@ -12,13 +12,11 @@ public class G2Chat_EnterRequestHandler : RouteRPC<Scene, G2Chat_EnterRequest, C
{
var roleId = request.Role.RoleId;
Log.Debug($"收到 G2Chat_EnterRequestHandler {roleId}");
// 在缓存中检查该账号是否存在
var chatUnitManageComponent = scene.GetComponent<ChatUnitManageComponent>();
var account = await chatUnitManageComponent.Online(scene, request.Role, request.GateRouteId);
response.RoleRouteId = account.RuntimeId;
await FTask.CompletedTask;
}
}

View File

@@ -0,0 +1,16 @@
using Fantasy;
using Fantasy.Async;
using Fantasy.Network.Interface;
namespace NB.Chat;
public class G2Chat_ExitRequestHandler : RouteRPC<Scene, G2Chat_ExitRequest, Chat2G_ExitResponse>
{
protected override async FTask Run(Scene scene, G2Chat_ExitRequest request, Chat2G_ExitResponse response,
Action reply)
{
// 在缓存中检查该账号是否存在
var chatUnitManageComponent = scene.GetComponent<ChatUnitManageComponent>();
await chatUnitManageComponent.Offline(scene, request.AccountId, request.GateRouteId);
}
}