聊天频道相关

This commit is contained in:
bob
2025-08-08 18:21:11 +08:00
parent 61496d4616
commit 7a93c0f8f1
23 changed files with 256 additions and 95 deletions

View File

@@ -10,7 +10,7 @@ public sealed class
protected override async FTask Run(ChatUnit chatUnit, C2Chat_SendMessageRequest request,
Caht2C_SendMessageResponse response, Action reply)
{
ChatSceneHelper.Broadcast(chatUnit.Scene, request.Message);
// ChatSceneHelper.Broadcast(chatUnit.Scene, request.Message);
await FTask.CompletedTask;
}
}

View File

@@ -5,16 +5,18 @@ using NB.Game;
namespace NB.Chat;
public class G2Chat_EnterRequestHandler: RouteRPC<Scene, G2Chat_EnterRequest, Chat2G_EnterResponse>
public class G2Chat_EnterRequestHandler : RouteRPC<Scene, G2Chat_EnterRequest, Chat2G_EnterResponse>
{
protected override async FTask Run(Scene scene, G2Chat_EnterRequest request, Chat2G_EnterResponse response,
Action reply)
{
Log.Debug($"收到 G2Chat_EnterRequestHandler {request.AccountId}");
var roleId = request.Role.RoleId;
Log.Debug($"收到 G2Chat_EnterRequestHandler {roleId}");
// 在缓存中检查该账号是否存在
var chatUnitManageComponent = scene.GetComponent<ChatUnitManageComponent>();
var account = await chatUnitManageComponent.Online(scene, request.AccountId, request.GateRouteId);
var account = await chatUnitManageComponent.Online(scene, request.Role, request.GateRouteId);
response.RoleRouteId = account.RuntimeId;
await FTask.CompletedTask;

View File

@@ -1,39 +0,0 @@
using Fantasy;
namespace NB.Chat;
public static class ChatChannelHelper
{
/// <summary>
/// 申请一个频道
/// </summary>
/// <param name="scene"></param>
/// <param name="channelId"></param>
/// <returns></returns>
public static ChatChannelComponent Apply(Scene scene, long channelId)
{
return scene.GetComponent<ChatChannelCenterComponent>().Apply(channelId);
}
/// <summary>
/// 尝试获取一个频道
/// </summary>
/// <param name="scene"></param>
/// <param name="channelId"></param>
/// <param name="channel"></param>
/// <returns></returns>
public static bool TryGet(Scene scene, long channelId, out ChatChannelComponent? channel)
{
return scene.GetComponent<ChatChannelCenterComponent>().TryGet(channelId, out channel);
}
/// <summary>
/// 解散频道
/// </summary>
/// <param name="scene"></param>
/// <param name="channelId"></param>
public static void Disband(Scene scene, long channelId)
{
scene.GetComponent<ChatChannelCenterComponent>().Disband(channelId);
}
}

View File

@@ -6,17 +6,29 @@ namespace NB.Chat;
public static class ChatSceneHelper
{
#region
/// <summary>
/// 广播消息
/// 广播记录更新
/// </summary>
/// <param name="scene"></param>
/// <param name="record"></param>
public static void BroadcastRecord(Scene scene, ChatContentRecord record)
{
}
/// <summary>
/// 广播消息给所有人
/// </summary>
/// <param name="scene"></param>
/// <param name="message"></param>
public static void Broadcast(Scene scene, string message)
public static void Broadcast(Scene scene, ChatMessageInfo message)
{
Log.Info("广播消息===");
//发送给所有Gate服务器让Gate转发给其他客户端
var gateConfigs = SceneConfigData.Instance.GetSceneBySceneType(SceneType.Gate);
var sendMessage = new Chat2G_ChatMessage()
{
Message = message
@@ -29,7 +41,12 @@ public static class ChatSceneHelper
}
}
public static async FTask<long> Online(Scene scene, long accountID, long gateRuntimeId)
#endregion
#region 线线
public static async FTask<long> Online(Scene scene, RoleSimpleInfo roleSimple, long gateRuntimeId)
{
var gameSceneConfig = GetSceneConfig();
var gameRouteId = gameSceneConfig.RouteId;
@@ -37,7 +54,7 @@ public static class ChatSceneHelper
var gameResponse = (Chat2G_EnterResponse)await scene.NetworkMessagingComponent.CallInnerRoute(
gameRouteId, new G2Chat_EnterRequest()
{
AccountId = accountID,
Role = roleSimple,
GateRouteId = gateRuntimeId
});
@@ -48,14 +65,13 @@ public static class ChatSceneHelper
return gameResponse.RoleRouteId;
}
private static SceneConfig GetSceneConfig()
{
var gameSceneConfigs = SceneConfigData.Instance.GetSceneBySceneType(SceneType.Chat);
return gameSceneConfigs.First();
}
#endregion
}

View File

@@ -1,23 +1,27 @@
using Fantasy.Entitas;
using Fantasy.Helper;
namespace NB.Chat;
public static class ChatChannelCenterComponentSystem
{
/// <summary>
/// 申请
/// 申请创建一个频道
/// </summary>
/// <param name="self"></param>
/// <param name="unit"></param>
/// <param name="channelId"></param>
/// <returns></returns>
public static ChatChannelComponent Apply(this ChatChannelCenterComponent self, long channelId)
public static ChatChannel Apply(this ChatChannelCenterComponent self, ChatUnit unit, long channelId)
{
if (self.Channels.TryGetValue(channelId, out var channel))
{
return channel;
}
channel = Entity.Create<ChatChannelComponent>(self.Scene, channelId, true, true);
channel = Entity.Create<ChatChannel>(self.Scene, channelId, true, true);
channel.Creator = unit.RoleId;
channel.CreateTime = TimeHelper.Now;
self.Channels.Add(channelId, channel);
return channel;
}
@@ -29,7 +33,7 @@ public static class ChatChannelCenterComponentSystem
/// <param name="channelId"></param>
/// <param name="channel"></param>
/// <returns></returns>
public static bool TryGet(this ChatChannelCenterComponent self, long channelId, out ChatChannelComponent? channel)
public static bool TryGet(this ChatChannelCenterComponent self, long channelId, out ChatChannel? channel)
{
return self.Channels.TryGetValue(channelId, out channel);
}

View File

@@ -13,21 +13,29 @@ public static class ChatUnitManageComponentSystem
/// </summary>
/// <param name="self"></param>
/// <param name="scene"></param>
/// <param name="accountId"></param>
/// <param name="roleSimpleInfo"></param>
/// <param name="gateRouteId"></param>
public static async FTask<ChatUnit> Online(this ChatUnitManageComponent self, Scene scene, long accountId,
public static async FTask<ChatUnit?> Online(this ChatUnitManageComponent self, Scene scene, RoleSimpleInfo roleSimpleInfo,
long gateRouteId)
{
var accountId = roleSimpleInfo.RoleId;
if (!self.TryGet(accountId, out var account))
{
account = ChatUnitFactory.Create(scene, accountId);
self.Add(account);
}
account.GateRouteId = gateRouteId;
if (account != null)
{
account.GateRouteId = gateRouteId;
account.RoleId = accountId;
account.Head = roleSimpleInfo.Head;
account.Level = roleSimpleInfo.Level;
account.NickName = roleSimpleInfo.NickName;
account.Country = roleSimpleInfo.Country;
}
await FTask.CompletedTask;
return account;
}