Eintoo/GameServer/Server/Hotfix/Outter/Chat/ChatManageComponentSystem.cs
2025-04-22 15:31:25 +08:00

39 lines
1.1 KiB
C#

using Fantasy;
using Fantasy.Entitas.Interface;
namespace Hotfix;
public class ChatManageComponentDestroySystem : DestroySystem<ChatManageComponent>
{
protected override void Destroy(ChatManageComponent self)
{
foreach (var chatUnit in self.ChatUnits.Values.ToArray())
{
chatUnit.Dispose();
}
self.ChatUnits.Clear();
}
}
public static class ChatManageComponentSystem
{
public static void AddChatUnit(this ChatManageComponent self,ChatUnit chatUnit)
{
if (self.ChatUnits.ContainsKey(chatUnit.RuntimeId))
{
Log.Debug($" chat unit already added: {chatUnit.AccountId} {chatUnit.GameName} ");
return;
}
self.ChatUnits.Add(chatUnit.RuntimeId, chatUnit);
}
public static void RemoveChatUnit(this ChatManageComponent self, long accountId)
{
if (!self.ChatUnits.Remove(accountId,out var chatUnit))
{
Log.Debug($" chat unit is not exist: {accountId} ");
return;
}
chatUnit.Dispose();
}
}