From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Assets/Scripts/XMainClient/XServerTimeMgr.cs | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XServerTimeMgr.cs (limited to 'Client/Assets/Scripts/XMainClient/XServerTimeMgr.cs') diff --git a/Client/Assets/Scripts/XMainClient/XServerTimeMgr.cs b/Client/Assets/Scripts/XMainClient/XServerTimeMgr.cs new file mode 100644 index 00000000..ddb5f5e4 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XServerTimeMgr.cs @@ -0,0 +1,81 @@ +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); + } + } +} -- cgit v1.1-26-g67d0