예제 #1
0
        public async void Awake()
        {
            TimerComponent timer = Game.Scene.GetComponent <TimerComponent>();

            while (true)
            {
                try
                {
                    Log.Debug($"在线人数:{_session.Count}");
                    await timer.WaitAsync(interval);

                    //检查所有session吗,如果有时间超过指定的间隔就执行action
                    for (int i = 0; i < _session.Count; i++)
                    {
                        if (TimeHelper.ClientNowSeconds() - _session.ElementAt(i).Value > interval)
                        {
                            long key = _session.ElementAt(i).Key;
                            action?.Invoke(key);
                            _session.Remove(key);
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                }
            }
        }
예제 #2
0
        public async void Awake(long waitTime, Action action)
        {
            var timerComponent = Game.Scene.GetComponent <TimerComponent>();

            var session = this.GetParent <Session>();

            while (true)
            {
                try
                {
                    _sendTimer = TimeHelper.ClientNowSeconds();

                    await session.Call(_request);

                    _receiveTimer = TimeHelper.ClientNowSeconds();

                    // 计算延时

                    Ping = ((_receiveTimer - _sendTimer) / 2) < 0 ? 0 : (_receiveTimer - _sendTimer) / 2;

                    //Debug.Log(" 计算延时-rpcid: " + _request.RpcId + " / " + Ping);
                }
                catch (Exception e)
                {
                    // 执行断线后的操作

                    action?.Invoke();

                    Debug.Log(" 断线了: " + e.Message);
                }

                await timerComponent.WaitAsync(waitTime);
            }
        }
예제 #3
0
 public void UpdateSession(long id)
 {
     if (_sessionTimes.ContainsKey(id))
     {
         _sessionTimes[id] = TimeHelper.ClientNowSeconds();
     }
 }
예제 #4
0
        public async void Awake(long waitTime, long overtime, Action <long> action)
        {
            var timerComponent = Game.Scene.GetComponent <TimerComponent>();

            onDisconnected = action;

            while (true)
            {
                try
                {
                    Log.Info("在线人数 :" + _sessionTimes.Count.ToString());

                    await timerComponent.WaitForMilliSecondAsync(waitTime);

                    // 检查所有Session,如果有时间超过指定的间隔就执行action

                    for (int i = 0; i < _sessionTimes.Count; i++)
                    {
                        if ((TimeHelper.ClientNowSeconds() - _sessionTimes.ElementAt(i).Value) > overtime)
                        {
                            RemoveSession(_sessionTimes.ElementAt(i).Key);
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                }
            }
        }
예제 #5
0
        public async void Awake(long waitTime, long overtime, Action <long> action)
        {
            var timerComponent = Game.Scene.GetComponent <TimerComponent>();

            while (true)
            {
                try
                {
                    Console.WriteLine("在线人数 :" + _sessionTimes.Count.ToString() + " / " + Game.Scene.GetComponent <NetOuterComponent>().Count);

                    await timerComponent.WaitAsync(waitTime);

                    // 检查所有Session,如果有时间超过指定的间隔就执行action

                    for (int i = 0; i < _sessionTimes.Count; i++)
                    {
                        if ((TimeHelper.ClientNowSeconds() - _sessionTimes.ElementAt(i).Value) > overtime)
                        {
                            action?.Invoke(_sessionTimes.ElementAt(i).Key);

                            _sessionTimes.Remove(_sessionTimes.ElementAt(i).Key);
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                }
            }
        }
예제 #6
0
        public async void Awake(int waitTime, long overtime)
        {
            while (true)
            {
                try
                {
                    await Task.Delay(waitTime);

                    for (int i = 0; i < _sessionTimes.Count; i++)
                    {
                        if ((TimeHelper.ClientNowSeconds() - _sessionTimes.ElementAt(i).Value) <= overtime)
                        {
                            continue;
                        }

                        Game.Scene.GetComponent <PlayerManagerComponent>().RemoveSession(_sessionTimes.ElementAt(i).Key);

                        RemoveSession(_sessionTimes.ElementAt(i).Key);
                    }
                }
                catch (System.Exception e)
                {
                    Log.Error(e.Message);
                }
            }
        }
예제 #7
0
        //public bool isShow = true;

        //public void Update()
        //{
        //    //RecoverHp();
        //}

        /// <summary>
        /// 更新 回复血量
        /// </summary>
        /// <param name="self"></param>
        public void RecoverHp()
        {
            NumericComponent numC = this.GetParent <Unit>().GetComponent <NumericComponent>();

            if (numC[NumericType.Valuation] == numC[NumericType.MaxValuation])
            {
                return;
            }

            if (numC[NumericType.Valuation] > numC[NumericType.MaxValuation])
            {
                numC[NumericType.Valuation] = numC[NumericType.MaxValuation];

                Console.WriteLine(" type/Hp/hb/ha: " + numC.GetParent <Unit>().UnitType + " :" + numC[NumericType.Valuation] + " / " + numC[NumericType.ValuationBase] + " / " + numC[NumericType.ValuationAdd]);

                return;
            }

            if (numC[NumericType.Valuation] < numC[NumericType.MaxValuation])
            {
                if (!this.hpNull)
                {
                    this.hptimer = TimeHelper.ClientNowSeconds();
                    this.hpNull  = true;
                }

                long timeNow = TimeHelper.ClientNowSeconds();

                if ((timeNow - this.hptimer) > this.reshpTime)
                {
                    numC[NumericType.ValuationAdd] += (int)(numC[NumericType.MaxValuation] * this.reshp);
                    this.hpNull = false;
                }
            }
        }
예제 #8
0
 public void AddSession(long id)
 {
     if (IsInSession(id))
     {
         UpdateSession(id);
     }
     else
     {
         _sessionTimes.Add(id, TimeHelper.ClientNowSeconds());
     }
 }
예제 #9
0
        public void Update()
        {
            // 如果没有到达发包时间、直接返回

            if (!((TimeHelper.ClientNowSeconds() - _recordDeltaTime) > UpdateInterval) || CurrentTime == 0)
            {
                return;
            }
            // 记录当前时间
            this._recordDeltaTime = TimeHelper.ClientNowSeconds();
            if ((TimeHelper.ClientNowSeconds() - CurrentTime) > OutInterval)
            {
                Log.Info("移除Session");
                // 移除Session
                Game.Scene.GetComponent <NetOuterComponent>().Remove(this.Parent.InstanceId);
                Game.Scene.GetComponent <NetInnerComponent>().Remove(this.Parent.InstanceId);
                Game.Scene.GetComponent <GateSessionKeyComponent>().Remove(this.Parent.InstanceId);
            }
        }
예제 #10
0
        public void Update()
        {
            // 如果没有到达发包时间、直接返回
            if ((TimeHelper.ClientNowSeconds() - this._recordDeltaTime) < this.UpdateInterval || this.CurrentTime == 0)
            {
                return;
            }
            // 记录当前时间
            this._recordDeltaTime = TimeHelper.ClientNowSeconds();

            if (TimeHelper.ClientNowSeconds() - CurrentTime > OutInterval)
            {
                //Console.WriteLine("心跳失败");
                Game.Scene.GetComponent <NetOuterComponent>().Remove(this.GetParent <Entity>().Id);
            }
            else
            {
                //Console.WriteLine("心跳成功");
            }
        }
예제 #11
0
        public static long GenerateId()
        {
            long time = TimeHelper.ClientNowSeconds();

            if (time != lastTime)
            {
                value    = 0;
                lastTime = time;
            }

            if (++value > ushort.MaxValue - 1)
            {
                Log.Error($"id is not enough! value: {value}");
            }

            if (time > int.MaxValue)
            {
                Log.Error($"time > int.MaxValue value: {time}");
            }

            IdStruct idStruct = new IdStruct(appId, (uint)time, (ushort)value);

            return(idStruct.ToLong());
        }
예제 #12
0
 public void UpsertSession(long id)
 {
     _sessionTimes[id] = TimeHelper.ClientNowSeconds();
 }
예제 #13
0
 public void AddSession(long id)
 {
     _sessionTimes.Add(id, TimeHelper.ClientNowSeconds());
 }