CTT/Unity/Assets/Hotfix/Logic/Model/Game/Entity/Common/GateSessionDisposeComponent.cs

49 lines
1.1 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using ET;
using System;
using System.Collections.Generic;
namespace ET
{
2021-06-07 13:58:51 +08:00
public class GateSessionDisposeComponentDestroySystem: DestroySystem<GateSessionDisposeComponent>
2021-04-08 20:09:59 +08:00
{
2021-06-07 13:58:51 +08:00
public override void Destroy(GateSessionDisposeComponent self)
{
2021-04-08 20:09:59 +08:00
Log.Error($"掉线了");
self.ReConnect();
2021-06-07 13:58:51 +08:00
}
2021-04-08 20:09:59 +08:00
}
2021-06-07 13:58:51 +08:00
public class GateSessionDisposeComponent: Entity
2021-04-08 20:09:59 +08:00
{
private int timeInterval = 10 * 1000;
private int reCount = 100;
private long timerId;
2021-06-07 13:58:51 +08:00
2021-04-08 20:09:59 +08:00
public void ReConnect()
{
timerId = TimerComponent.Instance.NewRepeatedTimer(timeInterval, () =>
{
2021-06-07 13:58:51 +08:00
if (ReduceCount())
LoginHelper.ReLogin();
2021-04-08 20:09:59 +08:00
});
}
2021-06-07 13:58:51 +08:00
private bool ReduceCount()
2021-04-08 20:09:59 +08:00
{
reCount--;
if (reCount <= 0)
{
2021-06-07 13:58:51 +08:00
if (timerId != 0)
TimerComponent.Instance.Remove(timerId);
return false;
2021-04-08 20:09:59 +08:00
}
2021-06-07 13:58:51 +08:00
return true;
2021-04-08 20:09:59 +08:00
}
2021-06-07 13:58:51 +08:00
2021-04-08 20:09:59 +08:00
public void Init()
{
reCount = 100;
}
}
2021-06-07 13:58:51 +08:00
}