Eintoo/GameServer/Server/Hotfix/Outter/Session/SessionTimeOutComponentSystem.cs
2025-03-19 18:16:39 +08:00

64 lines
1.7 KiB
C#

using Fantasy;
using Fantasy.Entitas.Interface;
using Fantasy.Helper;
namespace Hotfix;
public static class SessionTimeOutComponentSystem
{
public static void SetInterval(this SessionTimeOutComponent self, int interval)
{
self.Interval = interval;
//self.NextTime = TimeHelper.Now + interval;
}
public static bool CheckInterval(this SessionTimeOutComponent self)
{
if (TimeHelper.Now < self.NextTime)
{
Log.Warning("请求过于频繁" + self.NextTime +"TimeOut" + TimeHelper.Now);
return false;
}
self.NextTime = TimeHelper.Now + self.Interval;
return true;
}
public static void TimeOut(this SessionTimeOutComponent self, long time)
{
var scene = self.Scene;
var parentRunTimeId = self.Parent.RuntimeId;
self.TimeId = scene.TimerComponent.Net.OnceTimer(time, () =>
{
if (self.Parent == null || parentRunTimeId != self.Parent.RuntimeId )
{
return;
}
Log.Debug($"session : {self.Parent.RuntimeId} Dispose");
self.TimeId = 0;
self.Parent.Dispose();
});
}
}
public class SessionTimeOutComponentAwakeSystem : AwakeSystem<SessionTimeOutComponent>
{
protected override void Awake(SessionTimeOutComponent self)
{
}
}
public class SessionTimeOutComponentDestroySystem : DestroySystem<SessionTimeOutComponent>
{
protected override void Destroy(SessionTimeOutComponent self)
{
if (self.TimeId != 0)
{
self.Scene.TimerComponent.Net.Remove(self.TimeId);
}
self.NextTime = 0;
self.Interval = 0;
}
}