From 3db55540ae88b8bcee5852992eeda60ec6f398b9 Mon Sep 17 00:00:00 2001 From: SnowShow Date: Wed, 16 Apr 2025 11:53:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=81=8A=E5=A4=A9=E9=A2=91?= =?UTF-8?q?=E9=81=93=E5=81=87=E5=A6=82=20=E8=81=8A=E5=A4=A9=E9=A2=91?= =?UTF-8?q?=E9=81=93=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Model/Chat/ChatChannel/ChatChannel.cs | 2 +- ...hatComponent.cs => ChatManageComponent.cs} | 2 +- .../Server/Hotfix/OnCreateScene_InitEvent.cs | 3 +- .../Chat/ChatChannel/ChatChannelSystem.cs | 55 ++++++++++++++++++- ...System.cs => ChatManageComponentSystem.cs} | 10 ++-- .../ChatChannelCenterComponentHelper.cs | 22 ++++++++ .../Outter/Chat/Helper/ChatComponentHelper.cs | 4 +- 7 files changed, 85 insertions(+), 13 deletions(-) rename GameServer/Server/Entity/Model/Chat/{ChatComponent.cs => ChatManageComponent.cs} (74%) rename GameServer/Server/Hotfix/Outter/Chat/{ChatComponentSystem.cs => ChatManageComponentSystem.cs} (66%) create mode 100644 GameServer/Server/Hotfix/Outter/Chat/Helper/ChatChannelCenterComponentHelper.cs diff --git a/GameServer/Server/Entity/Model/Chat/ChatChannel/ChatChannel.cs b/GameServer/Server/Entity/Model/Chat/ChatChannel/ChatChannel.cs index 654b26b8..ba17bff1 100644 --- a/GameServer/Server/Entity/Model/Chat/ChatChannel/ChatChannel.cs +++ b/GameServer/Server/Entity/Model/Chat/ChatChannel/ChatChannel.cs @@ -4,5 +4,5 @@ using Fantasy.Entitas; public class ChatChannel : Entity { - public readonly HashSet> ChatUnits = new HashSet>(); + public readonly HashSet ChatUnits = new HashSet(); } \ No newline at end of file diff --git a/GameServer/Server/Entity/Model/Chat/ChatComponent.cs b/GameServer/Server/Entity/Model/Chat/ChatManageComponent.cs similarity index 74% rename from GameServer/Server/Entity/Model/Chat/ChatComponent.cs rename to GameServer/Server/Entity/Model/Chat/ChatManageComponent.cs index 76ab7def..b8142262 100644 --- a/GameServer/Server/Entity/Model/Chat/ChatComponent.cs +++ b/GameServer/Server/Entity/Model/Chat/ChatManageComponent.cs @@ -2,7 +2,7 @@ using Fantasy.Entitas; -public class ChatComponent : Entity +public class ChatManageComponent : Entity { public readonly Dictionary ChatUnits = new Dictionary(); } \ No newline at end of file diff --git a/GameServer/Server/Hotfix/OnCreateScene_InitEvent.cs b/GameServer/Server/Hotfix/OnCreateScene_InitEvent.cs index d1325646..96be4385 100644 --- a/GameServer/Server/Hotfix/OnCreateScene_InitEvent.cs +++ b/GameServer/Server/Hotfix/OnCreateScene_InitEvent.cs @@ -22,7 +22,8 @@ public class OnCreateScene_InitEvent : AsyncEventSystem break; case SceneType.Chat: - scene.AddComponent(); + scene.AddComponent(); + scene.AddComponent(); break; } diff --git a/GameServer/Server/Hotfix/Outter/Chat/ChatChannel/ChatChannelSystem.cs b/GameServer/Server/Hotfix/Outter/Chat/ChatChannel/ChatChannelSystem.cs index 9d719732..468a7466 100644 --- a/GameServer/Server/Hotfix/Outter/Chat/ChatChannel/ChatChannelSystem.cs +++ b/GameServer/Server/Hotfix/Outter/Chat/ChatChannel/ChatChannelSystem.cs @@ -1,9 +1,58 @@ -namespace Hotfix; +using Fantasy; + +namespace Hotfix; -public class ChatChannelSystem +public static class ChatChannelSystem { - + + public static void SendMessage(this ChatChannel self, string message) + { + var chatUnitManage = self.Scene.GetComponent(); + + + } + + /// + /// 进入聊天频道 + /// + /// + /// + /// + public static bool JoinChatChannel(this ChatChannel self, long chatUnitId) + { + var chatUnitManage = self.Scene.GetComponent(); + + if (!chatUnitManage.ChatUnits.TryGetValue(chatUnitId,out _)) + { + return false; + } + + self.ChatUnits.Add(chatUnitId); + return true; + } + + /// + /// 退出聊天频道 + /// + /// + /// + public static void ExitChatChannel(this ChatChannel self, long chatUnitId) + { + var chatUnitManage = self.Scene.GetComponent(); + + if (!self.ChatUnits.Contains(chatUnitId)) + { + return; + } + self.ChatUnits.Remove(chatUnitId); + + if (self.ChatUnits.Count == 0) + { + self.Dispose(); + } + } + } \ No newline at end of file diff --git a/GameServer/Server/Hotfix/Outter/Chat/ChatComponentSystem.cs b/GameServer/Server/Hotfix/Outter/Chat/ChatManageComponentSystem.cs similarity index 66% rename from GameServer/Server/Hotfix/Outter/Chat/ChatComponentSystem.cs rename to GameServer/Server/Hotfix/Outter/Chat/ChatManageComponentSystem.cs index 2051b1ea..7fee08dd 100644 --- a/GameServer/Server/Hotfix/Outter/Chat/ChatComponentSystem.cs +++ b/GameServer/Server/Hotfix/Outter/Chat/ChatManageComponentSystem.cs @@ -2,9 +2,9 @@ using Fantasy.Entitas.Interface; namespace Hotfix; -public class ChatComponentDestroySystem : DestroySystem +public class ChatManageComponentDestroySystem : DestroySystem { - protected override void Destroy(ChatComponent self) + protected override void Destroy(ChatManageComponent self) { foreach (var chatUnit in self.ChatUnits.Values.ToArray()) { @@ -15,9 +15,9 @@ public class ChatComponentDestroySystem : DestroySystem } } -public static class ChatComponentSystem +public static class ChatManageComponentSystem { - public static void AddChatUnit(this ChatComponent self,ChatUnit chatUnit) + public static void AddChatUnit(this ChatManageComponent self,ChatUnit chatUnit) { if (self.ChatUnits.ContainsKey(chatUnit.RuntimeId)) { @@ -27,7 +27,7 @@ public static class ChatComponentSystem self.ChatUnits.Add(chatUnit.RuntimeId, chatUnit); } - public static void RemoveChatUnit(this ChatComponent self, long accountId) + public static void RemoveChatUnit(this ChatManageComponent self, long accountId) { if (!self.ChatUnits.Remove(accountId,out var chatUnit)) { diff --git a/GameServer/Server/Hotfix/Outter/Chat/Helper/ChatChannelCenterComponentHelper.cs b/GameServer/Server/Hotfix/Outter/Chat/Helper/ChatChannelCenterComponentHelper.cs new file mode 100644 index 00000000..4cc15a6e --- /dev/null +++ b/GameServer/Server/Hotfix/Outter/Chat/Helper/ChatChannelCenterComponentHelper.cs @@ -0,0 +1,22 @@ +using Fantasy; + +namespace Hotfix; + +public static class ChatChannelCenterComponentHelper +{ + public static ChatChannel Apply(Scene scene, long chatChannelId) + { + return scene.GetComponent().Apply(chatChannelId); + } + + + public static bool TryGetChannel(Scene scene, long chatChannelId,out ChatChannel channel) + { + return scene.GetComponent().TryGetChannel(chatChannelId,out channel); + } + + public static bool RemoveChannel(Scene scene, long chatChannelId) + { + return scene.GetComponent().RemoveChannel(chatChannelId); + } +} \ No newline at end of file diff --git a/GameServer/Server/Hotfix/Outter/Chat/Helper/ChatComponentHelper.cs b/GameServer/Server/Hotfix/Outter/Chat/Helper/ChatComponentHelper.cs index fe6d342b..aa425e67 100644 --- a/GameServer/Server/Hotfix/Outter/Chat/Helper/ChatComponentHelper.cs +++ b/GameServer/Server/Hotfix/Outter/Chat/Helper/ChatComponentHelper.cs @@ -6,12 +6,12 @@ public class ChatComponentHelper { public static void AddChatUnit(Scene scene,ChatUnit chatUnit) { - scene.GetComponent().AddChatUnit(chatUnit); + scene.GetComponent().AddChatUnit(chatUnit); } public static void RemoveChatUnit(Scene scene,long accountId) { - scene.GetComponent().RemoveChatUnit(accountId); + scene.GetComponent().RemoveChatUnit(accountId); } } \ No newline at end of file