From 15723850c0cf4bce7213fdbc456d386ce3ccdf77 Mon Sep 17 00:00:00 2001
From: BobSong <605277374@qq.com>
Date: Tue, 12 Aug 2025 14:05:23 +0800
Subject: [PATCH] =?UTF-8?q?=E9=A2=91=E9=81=93=E8=81=8A=E5=A4=A9=E7=9B=B8?=
=?UTF-8?q?=E5=85=B3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../NetworkProtocol/Outer/OuterMessage.proto | 15 ++++-
Entity/Chat/ChatComponent.cs | 7 ---
Entity/Chat/ChatContentBase.cs | 25 --------
Entity/Chat/ChatMessageRecord.cs | 4 --
.../ChatChannelCenterComponent.cs | 0
.../ChatUnitManageComponent.cs | 0
Entity/Chat/{ => Entity}/ChatChannel.cs | 9 ++-
Entity/Chat/{ => Entity}/ChatUnit.cs | 12 +++-
Entity/Club/Club.cs | 8 +++
Entity/Entity.csproj | 1 -
.../Generate/NetworkProtocol/OuterMessage.cs | 63 +++++++++++++++++++
.../Generate/NetworkProtocol/OuterOpcode.cs | 7 ++-
Entity/Model/Def/ErrorCode.cs | 5 ++
.../C2Chat_JoinChannelRequestHandler.cs | 45 +++++++++++++
Hotfix/Chat/Helper/ChatSceneHelper.cs | 11 +---
.../ChatChannelCenterComponentSystem.cs | 40 ++++++++----
Hotfix/Chat/System/ChatChannelSystem.cs | 26 ++++++++
17 files changed, 212 insertions(+), 66 deletions(-)
delete mode 100644 Entity/Chat/ChatComponent.cs
delete mode 100644 Entity/Chat/ChatContentBase.cs
delete mode 100644 Entity/Chat/ChatMessageRecord.cs
rename Entity/Chat/{ => Component}/ChatChannelCenterComponent.cs (100%)
rename Entity/Chat/{ => Component}/ChatUnitManageComponent.cs (100%)
rename Entity/Chat/{ => Entity}/ChatChannel.cs (84%)
rename Entity/Chat/{ => Entity}/ChatUnit.cs (65%)
create mode 100644 Entity/Club/Club.cs
create mode 100644 Hotfix/Chat/Handler/C2Chat_JoinChannelRequestHandler.cs
create mode 100644 Hotfix/Chat/System/ChatChannelSystem.cs
diff --git a/Config/NetworkProtocol/Outer/OuterMessage.proto b/Config/NetworkProtocol/Outer/OuterMessage.proto
index 851848b..e969873 100644
--- a/Config/NetworkProtocol/Outer/OuterMessage.proto
+++ b/Config/NetworkProtocol/Outer/OuterMessage.proto
@@ -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
}
///发送聊天响应
diff --git a/Entity/Chat/ChatComponent.cs b/Entity/Chat/ChatComponent.cs
deleted file mode 100644
index 9ee62ac..0000000
--- a/Entity/Chat/ChatComponent.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-using Fantasy.Entitas;
-
-namespace NB.Chat;
-
-public class ChatComponent : Entity
-{
-}
\ No newline at end of file
diff --git a/Entity/Chat/ChatContentBase.cs b/Entity/Chat/ChatContentBase.cs
deleted file mode 100644
index 058088a..0000000
--- a/Entity/Chat/ChatContentBase.cs
+++ /dev/null
@@ -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
-{
-}
\ No newline at end of file
diff --git a/Entity/Chat/ChatMessageRecord.cs b/Entity/Chat/ChatMessageRecord.cs
deleted file mode 100644
index 0e5fa5c..0000000
--- a/Entity/Chat/ChatMessageRecord.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-using Fantasy.Entitas;
-
-namespace NB.Chat;
-
diff --git a/Entity/Chat/ChatChannelCenterComponent.cs b/Entity/Chat/Component/ChatChannelCenterComponent.cs
similarity index 100%
rename from Entity/Chat/ChatChannelCenterComponent.cs
rename to Entity/Chat/Component/ChatChannelCenterComponent.cs
diff --git a/Entity/Chat/ChatUnitManageComponent.cs b/Entity/Chat/Component/ChatUnitManageComponent.cs
similarity index 100%
rename from Entity/Chat/ChatUnitManageComponent.cs
rename to Entity/Chat/Component/ChatUnitManageComponent.cs
diff --git a/Entity/Chat/ChatChannel.cs b/Entity/Chat/Entity/ChatChannel.cs
similarity index 84%
rename from Entity/Chat/ChatChannel.cs
rename to Entity/Chat/Entity/ChatChannel.cs
index 1bb0766..ac12b3f 100644
--- a/Entity/Chat/ChatChannel.cs
+++ b/Entity/Chat/Entity/ChatChannel.cs
@@ -8,6 +8,11 @@ namespace NB.Chat;
///
public class ChatChannel : Entity
{
+ ///
+ /// 频道短id
+ ///
+ [BsonElement("cid")] public uint ChannelId;
+
///
/// 频道类型 0.地图 1.公开 2.私密
///
@@ -37,9 +42,9 @@ public class ChatChannel : Entity
/// 频道地区 0,全球 非0地区 如果是地图频道则表示地图位置
///
[BsonElement("region")] public int Region;
-
+
///
/// 当前频道在线人数
///
- [BsonElement("ids")] public readonly HashSet Units = new HashSet();
+ [BsonIgnore] public readonly HashSet Units = new HashSet();
}
\ No newline at end of file
diff --git a/Entity/Chat/ChatUnit.cs b/Entity/Chat/Entity/ChatUnit.cs
similarity index 65%
rename from Entity/Chat/ChatUnit.cs
rename to Entity/Chat/Entity/ChatUnit.cs
index ca20e98..78bcd04 100644
--- a/Entity/Chat/ChatUnit.cs
+++ b/Entity/Chat/Entity/ChatUnit.cs
@@ -6,9 +6,19 @@ namespace NB.Chat;
public sealed class ChatUnit : Entity
{
public long GateRouteId;
-
+
public RoleSimpleInfo Role;
+ ///
+ /// 当前所在地图
+ ///
+ public long MapId;
+
+ ///
+ /// 当前频道
+ ///
+ public long CurrentChannel;
+
public override void Dispose()
{
if (IsDisposed)
diff --git a/Entity/Club/Club.cs b/Entity/Club/Club.cs
new file mode 100644
index 0000000..13f00c7
--- /dev/null
+++ b/Entity/Club/Club.cs
@@ -0,0 +1,8 @@
+using Fantasy.Entitas;
+
+namespace NB.Club;
+
+public class Club : Entity
+{
+
+}
\ No newline at end of file
diff --git a/Entity/Entity.csproj b/Entity/Entity.csproj
index ae06c88..caaa6e3 100644
--- a/Entity/Entity.csproj
+++ b/Entity/Entity.csproj
@@ -28,7 +28,6 @@
-
diff --git a/Entity/Generate/NetworkProtocol/OuterMessage.cs b/Entity/Generate/NetworkProtocol/OuterMessage.cs
index 1682b43..f01561b 100644
--- a/Entity/Generate/NetworkProtocol/OuterMessage.cs
+++ b/Entity/Generate/NetworkProtocol/OuterMessage.cs
@@ -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();
+ }
+ public override void Dispose()
+ {
+ Target = default;
+#if FANTASY_NET || FANTASY_UNITY
+ GetScene().MessagePoolComponent.Return(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; }
+ }
+ ///
+ /// 进入频道响应
+ ///
+ [ProtoContract]
+ public partial class Caht2C_JoinChannelResponse : AMessage, ICustomRouteResponse, IProto
+ {
+ public static Caht2C_JoinChannelResponse Create(Scene scene)
+ {
+ return scene.MessagePoolComponent.Rent();
+ }
+ public override void Dispose()
+ {
+ ErrorCode = default;
+#if FANTASY_NET || FANTASY_UNITY
+ GetScene().MessagePoolComponent.Return(this);
+#endif
+ }
+ public uint OpCode() { return OuterOpcode.Caht2C_JoinChannelResponse; }
+ [ProtoMember(1)]
+ public uint ErrorCode { get; set; }
+ }
///
/// 发送聊天
///
@@ -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();
+ }
+ public override void Dispose()
+ {
+ ToKen = default;
+#if FANTASY_NET || FANTASY_UNITY
+ GetScene().MessagePoolComponent.Return(this);
+#endif
+ }
+ [ProtoIgnore]
+ public G2C_LoginResponse ResponseType { get; set; }
+ public uint OpCode() { return OuterOpcode.C2G_LoginRequest1; }
+ [ProtoMember(1)]
+ public string ToKen { get; set; }
+ }
}
diff --git a/Entity/Generate/NetworkProtocol/OuterOpcode.cs b/Entity/Generate/NetworkProtocol/OuterOpcode.cs
index c686785..62a9e0e 100644
--- a/Entity/Generate/NetworkProtocol/OuterOpcode.cs
+++ b/Entity/Generate/NetworkProtocol/OuterOpcode.cs
@@ -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;
}
}
diff --git a/Entity/Model/Def/ErrorCode.cs b/Entity/Model/Def/ErrorCode.cs
index ac96af0..676eeb2 100644
--- a/Entity/Model/Def/ErrorCode.cs
+++ b/Entity/Model/Def/ErrorCode.cs
@@ -39,4 +39,9 @@ public class ErrorCode
/// 登录自动注册没有设置地区
///
public const uint RegisterNotRegion = 11011;
+
+ ///
+ /// 聊天频道不存在
+ ///
+ public const uint ChatNotChannel = 12011;
}
\ No newline at end of file
diff --git a/Hotfix/Chat/Handler/C2Chat_JoinChannelRequestHandler.cs b/Hotfix/Chat/Handler/C2Chat_JoinChannelRequestHandler.cs
new file mode 100644
index 0000000..722c4d4
--- /dev/null
+++ b/Hotfix/Chat/Handler/C2Chat_JoinChannelRequestHandler.cs
@@ -0,0 +1,45 @@
+using Fantasy;
+using Fantasy.Async;
+using Fantasy.Network.Interface;
+
+namespace NB.Chat;
+
+///
+/// 请求进入频道
+///
+public class
+ C2Chat_JoinChannelRequestHandler : RouteRPC
+{
+ protected override async FTask Run(ChatUnit entity, C2Chat_JoinChannelRequest request,
+ Caht2C_JoinChannelResponse response, Action reply)
+ {
+ var channelCenter = entity.Scene.GetComponent();
+ 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;
+ }
+}
\ No newline at end of file
diff --git a/Hotfix/Chat/Helper/ChatSceneHelper.cs b/Hotfix/Chat/Helper/ChatSceneHelper.cs
index 477ac98..a279fcf 100644
--- a/Hotfix/Chat/Helper/ChatSceneHelper.cs
+++ b/Hotfix/Chat/Helper/ChatSceneHelper.cs
@@ -8,16 +8,7 @@ public static class ChatSceneHelper
{
#region 消息发送
- ///
- /// 广播记录更新
- ///
- ///
- ///
- public static void BroadcastRecord(Scene scene, ChatContentRecord record)
- {
-
- }
-
+
///
/// 广播消息给所有人
diff --git a/Hotfix/Chat/System/ChatChannelCenterComponentSystem.cs b/Hotfix/Chat/System/ChatChannelCenterComponentSystem.cs
index fa5c977..8ae1b4f 100644
--- a/Hotfix/Chat/System/ChatChannelCenterComponentSystem.cs
+++ b/Hotfix/Chat/System/ChatChannelCenterComponentSystem.cs
@@ -1,10 +1,38 @@
using Fantasy.Entitas;
+using Fantasy.Entitas.Interface;
using Fantasy.Helper;
namespace NB.Chat;
+public class ChatChannelCenterComponentAwakeSystem : AwakeSystem
+{
+ protected override void Awake(ChatChannelCenterComponent self)
+ {
+ }
+}
+
+public class ChatChannelCenterComponentDestroySystem : DestroySystem
+{
+ protected override void Destroy(ChatChannelCenterComponent self)
+ {
+ self.Channels.Clear();
+ }
+}
+
public static class ChatChannelCenterComponentSystem
{
+ ///
+ /// 获取
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static bool TryGet(this ChatChannelCenterComponent self, long channelId, out ChatChannel? channel)
+ {
+ return self.Channels.TryGetValue(channelId, out channel);
+ }
+
///
/// 申请创建一个频道
///
@@ -26,18 +54,6 @@ public static class ChatChannelCenterComponentSystem
return channel;
}
- ///
- /// 获取
- ///
- ///
- ///
- ///
- ///
- public static bool TryGet(this ChatChannelCenterComponent self, long channelId, out ChatChannel? channel)
- {
- return self.Channels.TryGetValue(channelId, out channel);
- }
-
///
/// 解散
///
diff --git a/Hotfix/Chat/System/ChatChannelSystem.cs b/Hotfix/Chat/System/ChatChannelSystem.cs
new file mode 100644
index 0000000..4625d55
--- /dev/null
+++ b/Hotfix/Chat/System/ChatChannelSystem.cs
@@ -0,0 +1,26 @@
+namespace NB.Chat;
+
+public static class ChatChannelSystem
+{
+ ///
+ /// 进入频道
+ ///
+ ///
+ ///
+ public static void Enter(this ChatChannel channel, ChatUnit unit)
+ {
+ channel.Units.Add(unit.Id);
+ unit.CurrentChannel = channel.Id;
+ }
+
+ ///
+ /// 离开频道
+ ///
+ ///
+ ///
+ public static void Exit(this ChatChannel channel, ChatUnit unit)
+ {
+ channel.Units.Remove(unit.Id);
+ unit.CurrentChannel = 0;
+ }
+}
\ No newline at end of file