namespace ET.Server { [FriendOf(typeof (HeartBeatComponent))] public static class HeartBeatComponentSystem { public class HeartBeatComponentAwakeSystem: AwakeSystem { protected override void Awake(HeartBeatComponent self, Session session) { // 初始化 self.Session = session; self.UpdateInterval = 5; self.OutInterval = 3; self.RecordDeltaTime = 0; self.CurrentTime = 0; } } public class HeartBeatComponentUpdateSystem: UpdateSystem { protected override void Update(HeartBeatComponent self) { // 如果没有到达发包时间、直接返回 if (!((TimeHelper.ClientNowSeconds() - self.RecordDeltaTime) > self.UpdateInterval) || self.CurrentTime == 0) { return; } // 记录当前时间 self.RecordDeltaTime = TimeHelper.ClientNowSeconds(); // 移除Session if (TimeHelper.ClientNowSeconds() - self.CurrentTime <= self.OutInterval) { return; } Log.Debug($"移除Session Parent.Id = {self.Parent.Id}"); self.Session.Disconnect().Coroutine(); } } } }