频道聊天相关

This commit is contained in:
2025-08-12 14:05:23 +08:00
parent 12c328d538
commit 15723850c0
17 changed files with 212 additions and 66 deletions

View File

@@ -78,12 +78,23 @@ message Game2C_MailState // ICustomRouteMessage,GameRoute
int64 MailId = 2;
}
message C2Chat_JoinChannelRequest // ICustomRouteRequest,Caht2C_JoinChannelResponse,ChatRoute
{
int64 Target = 1; // 频道id
}
///进入频道响应
message Caht2C_JoinChannelResponse // ICustomRouteResponse
{
}
///发送聊天
message C2Chat_SendMessageRequest // ICustomRouteRequest,Caht2C_SendMessageResponse,ChatRoute
{
int32 Type = 1; //消息类型
int32 Type = 1; //消息类型 0.频道聊天 1.私聊
string Message = 2;
int64 Target = 3; //目标id如果有
int64 Target = 3; //目标id频道id或者好友id
}
///发送聊天响应

View File

@@ -1,7 +0,0 @@
using Fantasy.Entitas;
namespace NB.Chat;
public class ChatComponent : Entity
{
}

View File

@@ -1,25 +0,0 @@
namespace NB.Chat;
[Serializable]
public abstract class ChatContentData
{
}
[Serializable]
public class ChatContentNormal : ChatContentData
{
public string Content = "";
}
[Serializable]
public class ChatContentFished : ChatContentData
{
public long Id;
public int Weight;
public int Type;
}
[Serializable]
public class ChatContentRecord : ChatContentData
{
}

View File

@@ -1,4 +0,0 @@
using Fantasy.Entitas;
namespace NB.Chat;

View File

@@ -8,6 +8,11 @@ namespace NB.Chat;
/// </summary>
public class ChatChannel : Entity
{
/// <summary>
/// 频道短id
/// </summary>
[BsonElement("cid")] public uint ChannelId;
/// <summary>
/// 频道类型 0.地图 1.公开 2.私密
/// </summary>
@@ -37,9 +42,9 @@ public class ChatChannel : Entity
/// 频道地区 0全球 非0地区 如果是地图频道则表示地图位置
/// </summary>
[BsonElement("region")] public int Region;
/// <summary>
/// 当前频道在线人数
/// </summary>
[BsonElement("ids")] public readonly HashSet<long> Units = new HashSet<long>();
[BsonIgnore] public readonly HashSet<long> Units = new HashSet<long>();
}

View File

@@ -6,9 +6,19 @@ namespace NB.Chat;
public sealed class ChatUnit : Entity
{
public long GateRouteId;
public RoleSimpleInfo Role;
/// <summary>
/// 当前所在地图
/// </summary>
public long MapId;
/// <summary>
/// 当前频道
/// </summary>
public long CurrentChannel;
public override void Dispose()
{
if (IsDisposed)

8
Entity/Club/Club.cs Normal file
View File

@@ -0,0 +1,8 @@
using Fantasy.Entitas;
namespace NB.Club;
public class Club : Entity
{
}

View File

@@ -28,7 +28,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Club\" />
<Folder Include="Map\" />
</ItemGroup>

View File

@@ -287,6 +287,49 @@ namespace Fantasy
[ProtoMember(2)]
public long MailId { get; set; }
}
[ProtoContract]
public partial class C2Chat_JoinChannelRequest : AMessage, ICustomRouteRequest, IProto
{
public static C2Chat_JoinChannelRequest Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<C2Chat_JoinChannelRequest>();
}
public override void Dispose()
{
Target = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<C2Chat_JoinChannelRequest>(this);
#endif
}
[ProtoIgnore]
public Caht2C_JoinChannelResponse ResponseType { get; set; }
public uint OpCode() { return OuterOpcode.C2Chat_JoinChannelRequest; }
[ProtoIgnore]
public int RouteType => Fantasy.RouteType.ChatRoute;
[ProtoMember(1)]
public long Target { get; set; }
}
/// <summary>
/// 进入频道响应
/// </summary>
[ProtoContract]
public partial class Caht2C_JoinChannelResponse : AMessage, ICustomRouteResponse, IProto
{
public static Caht2C_JoinChannelResponse Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<Caht2C_JoinChannelResponse>();
}
public override void Dispose()
{
ErrorCode = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<Caht2C_JoinChannelResponse>(this);
#endif
}
public uint OpCode() { return OuterOpcode.Caht2C_JoinChannelResponse; }
[ProtoMember(1)]
public uint ErrorCode { get; set; }
}
/// <summary>
/// 发送聊天
/// </summary>
@@ -362,4 +405,24 @@ namespace Fantasy
[ProtoMember(1)]
public ChatMessageInfo Message { get; set; }
}
[ProtoContract]
public partial class C2G_LoginRequest1 : AMessage, IRequest, IProto
{
public static C2G_LoginRequest1 Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<C2G_LoginRequest1>();
}
public override void Dispose()
{
ToKen = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<C2G_LoginRequest1>(this);
#endif
}
[ProtoIgnore]
public G2C_LoginResponse ResponseType { get; set; }
public uint OpCode() { return OuterOpcode.C2G_LoginRequest1; }
[ProtoMember(1)]
public string ToKen { get; set; }
}
}

View File

@@ -13,8 +13,11 @@ namespace Fantasy
public const uint Game2C_GetMailsResponse = 2415929106;
public const uint Game2C_HaveMail = 2147493649;
public const uint Game2C_MailState = 2147493650;
public const uint C2Chat_SendMessageRequest = 2281711379;
public const uint Caht2C_SendMessageResponse = 2415929107;
public const uint C2Chat_JoinChannelRequest = 2281711379;
public const uint Caht2C_JoinChannelResponse = 2415929107;
public const uint C2Chat_SendMessageRequest = 2281711380;
public const uint Caht2C_SendMessageResponse = 2415929108;
public const uint Chat2C_Message = 2147493651;
public const uint C2G_LoginRequest1 = 268445459;
}
}

View File

@@ -39,4 +39,9 @@ public class ErrorCode
/// 登录自动注册没有设置地区
/// </summary>
public const uint RegisterNotRegion = 11011;
/// <summary>
/// 聊天频道不存在
/// </summary>
public const uint ChatNotChannel = 12011;
}

View 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;
}
}

View File

@@ -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>
/// 广播消息给所有人

View File

@@ -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>

View 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;
}
}