49 lines
1.1 KiB
C#
49 lines
1.1 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, () =>
|
|
{
|
|
if (ReduceCount())
|
|
LoginHelper.ReLogin(this.ZoneScene());
|
|
});
|
|
}
|
|
|
|
private bool ReduceCount()
|
|
{
|
|
reCount--;
|
|
if (reCount <= 0)
|
|
{
|
|
if (timerId != 0)
|
|
TimerComponent.Instance.Remove(timerId);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
reCount = 100;
|
|
}
|
|
}
|
|
} |