Beispiel #1
0
    public void update()
    {
        if (!running)
        {
            return;
        }
        currentTime = TimeKit.getMillisTime();         //不能用服务器时间,可能没登录就会用timer
        int count = getCurrentCount();

        if (count > currentCount)
        {
            currentCount = count;
            if (onTimer != null)
            {
                onTimer();
            }
        }
        if (repeatCount > 0 && currentCount >= repeatCount)
        {
            stop();
            if (onComplete != null)
            {
                onComplete();
            }
            dispose = true;
        }
        if (onTimer == null && onComplete == null)
        {
            stop();
        }
    }
Beispiel #2
0
    //ping方法
    public virtual void ping()
    {
        long    time = TimeKit.getMillisTime();
        Connect c;

        Connect[] array = connectArray.ToArray();
        for (int i = array.Length - 1; i >= 0; i--)
        {
            c = array [i];
            if (c.Active)
            {
                if (c.PingTime == 0)
                {
                    c.PingTime = time;
                    //发送ping值
                    ByteBuffer data = new ByteBuffer();
                    data.writeShort(1);
                    data.writeByte(1);
                    c.send(data);
                }
                else
                {
                    c.ping = time - c.PingTime;
                }
            }
        }
    }
Beispiel #3
0
    override public void erlReceive(Connect connect, ErlKVMessage message)
    {
        long time = TimeKit.getMillisTime();

        connect.ping     = time - connect.PingTime;
        connect.PingTime = 0;
    }
Beispiel #4
0
 /** 获得当前服务器毫秒时间 */
 public static long getMillisTime()
 {
     if (Log.useUnityLog)
     {
         return(loginTime + (long)(Time.realtimeSinceStartup * 1000) - costTime);
     }
     else
     {
         return(TimeKit.getMillisTime());
     }
 }
Beispiel #5
0
 private void updateFilter(Queue <string> filter)
 {
     for (int i = 0; i < filter.Count; i++)
     {
         string[] tmp        = filter.Peek().Split('&');
         long     filterTime = Convert.ToInt64(tmp[1]);
         if (TimeKit.timeSecond(TimeKit.getMillisTime()) - TimeKit.timeSecond(filterTime) > 300)            //超过5分钟,移除
         {
             filter.Dequeue();
         }
     }
 }
Beispiel #6
0
 public virtual void receive(ByteBuffer data)
 {
     if (_portHandler == null)
     {
         return;
     }
     _activeTime = TimeKit.getMillisTime();
     try {
         _portHandler.receive(this, data);
     } catch (Exception e) {
         Log.error(this.GetType() + ", receive error, " + this, e);
     }
 }
Beispiel #7
0
    public void start(bool firstCall)
    {
        if (firstCall)
        {
            currentCount = -1;
        }
        else
        {
            currentCount = 0;
        }

        running   = true;
        startTime = TimeKit.getMillisTime();
    }
Beispiel #8
0
    /**执行ping通信返回消息的执行方法
     * */
    protected void pingHandle(Connect erlConnect, object erlMessage)
    {
        long time = TimeKit.getMillisTime();

        erlConnect.ping = time - erlConnect.PingTime;

        /**
         * pingTime += erlConnect.ping;
         * pingCount++;
         *
         * if (time - st > 1000)
         * {
         *  st = time;
         *  Debug.LogError("ping:"+(pingTime / pingCount)+"," + pingCount);
         *  pingTime = pingCount = 0;
         * }
         */
    }
Beispiel #9
0
    /**ping方法*/
    override public void ping()
    {
        long       time = TimeKit.getMillisTime();
        ErlConnect c;

        Connect[] array = connectArray.ToArray();
        for (int i = array.Length - 1; i >= 0; i--)
        {
            c = array[i] as ErlConnect;
            if (c.Active)
            {
                c.PingTime = time;
                //发送ping值
                ErlKVMessage message = new ErlKVMessage("echo");
                DataAccess.getInstance().access(c, message, pingHandle, null, DataAccess.TIMEOUT);
            }
        }
    }
Beispiel #10
0
    //整理方法
    protected void collate()
    {
        long    time = TimeKit.getMillisTime();
        Connect c;

        Connect[] array = connectArray.ToArray();
        for (int i = array.Length - 1; i >= 0; i--)
        {
            c = array [i];
            if (c.Active)
            {
                if (time < c.TimeOut + c.ActiveTime)
                {
                    continue;
                }
                c.Dispose();
                connectArray.Remove(c);
            }
        }
    }
Beispiel #11
0
    //AddFilterList与Filter在一个发送逻辑中是配合使用的AddfilterList负责在数据返回的时候将接受到的数据放入队列

    private void AddFilterList(string selfLastMsg, Queue <string> que, ref string cache, int sendType)
    {
        //如果msg和上次说的话一样则添加到过滤队列
        if (cache == null)
        {
            return;
        }
        if (cache == currentMsg)
        {
            currentMsg += "&" + TimeKit.getMillisTime() + "&" + selfLastMsg;
            if (que.Count == 10)   //如果过滤队列达到10条,则移除第一条
            {
                que.Dequeue();
            }
            que.Enqueue(currentMsg);
        }
        else
        {
            currentMsg = cache;
        }
    }
Beispiel #12
0
    /**access超时 */
    public void onTimer()
    {
        ErlEntry entry;

        lock (_list) {
            ErlEntry[] array = _list.ToArray();

            for (int i = 0; i < array.Length; i++)
            {
                entry = array [i] as ErlEntry;
                if (entry.timeOut <= TimeKit.getMillisTime())
                {
                    _list.Remove(entry);
                    if (entry.receiveFun == null)
                    {
                        continue;
                    }
                    ErlKVMessage  message   = new ErlKVMessage("r_timeOut");
                    List <object> tempArray = entry.argus;
                    defaultHandle(entry.connect, message);
                }
            }
        }
    }
Beispiel #13
0
 public void reset()
 {
     startTime    = TimeKit.getMillisTime();
     currentCount = 0;
     running      = true;
 }
Beispiel #14
0
    /** 连接的消息接收方法 */
    public override void receive()
    {
        if (GameManager.Instance.disconnetTest)
        {
            return;
        }

        if (!socket.Connected)
        {
            return;
        }

        ActiveTime = TimeKit.getMillisTime();
        if (socket.Available > 0)
        {
            if (!_isConnectReady)
            {
                //设置 _isConnectReady=true  connect pk receive
                //抛掉前两位
                byte[] b1 = new byte[1];
                socket.Receive(b1, SocketFlags.None);
                byte[] b2 = new byte[1];
                socket.Receive(b2, SocketFlags.None);

                byte[] b3 = new byte[4];
                socket.Receive(b3, SocketFlags.None);
                Array.Reverse(b3);
                int i = BitConverter.ToInt32(b3, 0);

                byte[] b4 = new byte[4];
                socket.Receive(b4, SocketFlags.None);
                Array.Reverse(b4);
                int ii = BitConverter.ToInt32(b4, 0);

                _sendChallengeCode    = getPK(i);
                _receiveChallengeCode = getPK(ii);
                _isConnectReady       = true;
                if (this.CallBack != null)
                {
                    this.CallBack();
                }
            }
            else
            {
                if (length <= 0)
                {
                    if (socket.Available < 2)
                    {
                        return;
                    }
                    //	length = data.readUnsignedShort ();
                    byte[] b = new byte[2];
                    socket.Receive(b, SocketFlags.None);
                    length = ByteKit.readUnsignedShort(b, 0);
                    //length = readLength ();
                }
                if (length > 0 && socket.Available >= length)
                {
                    ByteBuffer data = new ByteBuffer(length);
                    data.setTop(length);
                    socket.Receive(data.getArray(), SocketFlags.None);

                    parseMessage(data);
                }
            }
        }
    }
Beispiel #15
0
    public void access(ErlConnect connect, ErlKVMessage message, ReceiveFun receiveFun, List <object> argus, long timeOut)
    {
        ByteBuffer data = new ByteBuffer();

        message.bytesWrite(data);
        _list.Add(new ErlEntry(connect, message.getPort(), receiveFun, argus, timeOut + TimeKit.getMillisTime()));
        connect.sendErl(data, ErlConnect.ENCRYPTION, ErlConnect.CRC, ErlConnect.COMPRESS, ErlConnect.KV);
        if (timeout == null)
        {
            timeout = TimerManager.Instance.getTimer(DELAY);
            timeout.addOnTimer(onTimer);
            timeout.start();
        }
    }