44 lines
1.0 KiB
C#
44 lines
1.0 KiB
C#
|
using ET;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
|
|||
|
namespace ET
|
|||
|
{
|
|||
|
public class GateSessionDisposeComponentDestroySystem : DestroySystem<GateSessionDisposeComponent>
|
|||
|
{
|
|||
|
public override void Destroy(GateSessionDisposeComponent self)
|
|||
|
{
|
|||
|
Log.Error($"掉线了");
|
|||
|
self.ReConnect();
|
|||
|
}
|
|||
|
}
|
|||
|
public class GateSessionDisposeComponent : Entity
|
|||
|
{
|
|||
|
private int timeInterval = 10 * 1000;
|
|||
|
private int reCount = 100;
|
|||
|
private long timerId;
|
|||
|
public void ReConnect()
|
|||
|
{
|
|||
|
timerId = TimerComponent.Instance.NewRepeatedTimer(timeInterval, () =>
|
|||
|
{
|
|||
|
ReduceCount();
|
|||
|
LoginHelper.ReLogin();
|
|||
|
});
|
|||
|
}
|
|||
|
private void ReduceCount()
|
|||
|
{
|
|||
|
reCount--;
|
|||
|
if (reCount <= 0)
|
|||
|
{
|
|||
|
Init();
|
|||
|
}
|
|||
|
}
|
|||
|
public void Init()
|
|||
|
{
|
|||
|
reCount = 100;
|
|||
|
if(timerId!=0)
|
|||
|
TimerComponent.Instance.Remove(timerId);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|