using System; using XUtliPoolLib; namespace XMainClient { internal class XServerTimeMgr : XSingleton { public static readonly long SyncTimeOut = 2000L; private long _TimeDelay = 0L; private uint _token = 0u; private PtcC2G_DelayNotify _delay = new PtcC2G_DelayNotify(); private XTimerMgr.ElapsedEventHandler _onTimerStartSyncTime = null; private RpcC2G_SyncTime syncTimeRpc = new RpcC2G_SyncTime(); public XServerTimeMgr() { this._onTimerStartSyncTime = new XTimerMgr.ElapsedEventHandler(this.OnStartSyncTime); } public override bool Init() { this.OnStartSyncTime(null); return true; } public override void Uninit() { XSingleton.singleton.KillTimer(this._token); } public long GetDelay() { return this._TimeDelay; } private void OnStartSyncTime(object param) { bool flag = XSingleton.singleton.XLoginStep == XLoginStep.Playing; if (flag) { this.syncTimeRpc.oArg.time = DateTime.Now.Ticks; XSingleton.singleton.Send(this.syncTimeRpc); } else { this.Trigger(); } } public void OnSyncTime(long sendAt, long replayAt) { double num = (double)(replayAt - sendAt) / 10000.0; this._TimeDelay = (long)num; this._delay.Data.delay = (uint)this._TimeDelay; XSingleton.singleton.Send(this._delay); this.Trigger(); } public void OnSyncTimeout() { XSingleton.singleton.AddLog("Ping time out!", null, null, null, null, null, XDebugColor.XDebug_None); bool flag = XSingleton.singleton.CurrentStage.Stage == EXStage.World && XSingleton.singleton.IsConnected() && !XSingleton.singleton.XConnect.OnReconnect && !Rpc.OnRpcDelay; if (flag) { } this._TimeDelay = XServerTimeMgr.SyncTimeOut; this.Trigger(); } private void Trigger() { XSingleton.singleton.KillTimer(this._token); this._token = XSingleton.singleton.SetGlobalTimer((float)XSingleton.singleton.PINGInterval, this._onTimerStartSyncTime, null); } } }