From 5d0f1791a577e8381907c6c4483f5449a1da0e50 Mon Sep 17 00:00:00 2001 From: SnowShow Date: Wed, 16 Apr 2025 11:32:16 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=82=E6=B7=BB=E5=8A=A0=20=E9=A2=91?= =?UTF-8?q?=E9=81=93=20=E4=B8=AD=E5=BF=83=E7=BB=84=E4=BB=B6=20=20=EF=BC=88?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E7=94=B3=E8=AF=B7=EF=BC=8C=20=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=20=E7=AD=89=20=E5=8A=9F=E8=83=BD=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Model/Chat/ChatChannel/ChatChannel.cs | 8 ++++ .../ChatChannel/ChatChannelCenterComponent.cs | 8 ++++ .../ChatChannelCenterComponentSystem.cs | 46 +++++++++++++++++++ .../Chat/ChatChannel/ChatChannelSystem.cs | 9 ++++ .../Hotfix/Outter/Chat/ChatComponentSystem.cs | 2 +- 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 GameServer/Server/Entity/Model/Chat/ChatChannel/ChatChannel.cs create mode 100644 GameServer/Server/Entity/Model/Chat/ChatChannel/ChatChannelCenterComponent.cs create mode 100644 GameServer/Server/Hotfix/Outter/Chat/ChatChannel/ChatChannelCenterComponentSystem.cs create mode 100644 GameServer/Server/Hotfix/Outter/Chat/ChatChannel/ChatChannelSystem.cs diff --git a/GameServer/Server/Entity/Model/Chat/ChatChannel/ChatChannel.cs b/GameServer/Server/Entity/Model/Chat/ChatChannel/ChatChannel.cs new file mode 100644 index 00000000..654b26b8 --- /dev/null +++ b/GameServer/Server/Entity/Model/Chat/ChatChannel/ChatChannel.cs @@ -0,0 +1,8 @@ + + +using Fantasy.Entitas; + +public class ChatChannel : Entity +{ + public readonly HashSet> ChatUnits = new HashSet>(); +} \ No newline at end of file diff --git a/GameServer/Server/Entity/Model/Chat/ChatChannel/ChatChannelCenterComponent.cs b/GameServer/Server/Entity/Model/Chat/ChatChannel/ChatChannelCenterComponent.cs new file mode 100644 index 00000000..822ec506 --- /dev/null +++ b/GameServer/Server/Entity/Model/Chat/ChatChannel/ChatChannelCenterComponent.cs @@ -0,0 +1,8 @@ + + +using Fantasy.Entitas; + +public class ChatChannelCenterComponent : Entity +{ + public Dictionary ChatChannels = new Dictionary(); +} \ No newline at end of file diff --git a/GameServer/Server/Hotfix/Outter/Chat/ChatChannel/ChatChannelCenterComponentSystem.cs b/GameServer/Server/Hotfix/Outter/Chat/ChatChannel/ChatChannelCenterComponentSystem.cs new file mode 100644 index 00000000..bea13cad --- /dev/null +++ b/GameServer/Server/Hotfix/Outter/Chat/ChatChannel/ChatChannelCenterComponentSystem.cs @@ -0,0 +1,46 @@ +using Fantasy.Entitas; +using Fantasy.Entitas.Interface; + +namespace Hotfix; + + +public class ChatChannelCenterComponentDestroySystem : DestroySystem +{ + protected override void Destroy(ChatChannelCenterComponent self) + { + foreach (var channel in self.ChatChannels.Values.ToArray()) + { + channel.Dispose(); + } + self.ChatChannels.Clear(); + } +} + +public static class ChatChannelCenterComponentSystem +{ + public static ChatChannel Apply(this ChatChannelCenterComponent self, long chatChannelId) + { + if (self.ChatChannels.TryGetValue(chatChannelId, out var channel)) + { + return channel; + } + + channel = Entity.Create(self.Scene,chatChannelId,true,true); + return channel; + } + + public static bool TryGetChannel(this ChatChannelCenterComponent self, long chatChannelId, out ChatChannel channel) + { + return self.ChatChannels.TryGetValue(chatChannelId, out channel); + } + + public static bool RemoveChannel(this ChatChannelCenterComponent self, long chatChannelId) + { + if (!self.ChatChannels.Remove(chatChannelId, out var channel)) + { + return false; + } + channel.Dispose(); + return true; + } +} \ No newline at end of file diff --git a/GameServer/Server/Hotfix/Outter/Chat/ChatChannel/ChatChannelSystem.cs b/GameServer/Server/Hotfix/Outter/Chat/ChatChannel/ChatChannelSystem.cs new file mode 100644 index 00000000..9d719732 --- /dev/null +++ b/GameServer/Server/Hotfix/Outter/Chat/ChatChannel/ChatChannelSystem.cs @@ -0,0 +1,9 @@ +namespace Hotfix; + + + + +public class ChatChannelSystem +{ + +} \ No newline at end of file diff --git a/GameServer/Server/Hotfix/Outter/Chat/ChatComponentSystem.cs b/GameServer/Server/Hotfix/Outter/Chat/ChatComponentSystem.cs index 247df490..2051b1ea 100644 --- a/GameServer/Server/Hotfix/Outter/Chat/ChatComponentSystem.cs +++ b/GameServer/Server/Hotfix/Outter/Chat/ChatComponentSystem.cs @@ -6,7 +6,7 @@ public class ChatComponentDestroySystem : DestroySystem { protected override void Destroy(ChatComponent self) { - foreach (var chatUnit in self.ChatUnits.Values) + foreach (var chatUnit in self.ChatUnits.Values.ToArray()) { chatUnit.Dispose(); }