Пример #1
0
        private void RRecv(byte[] buffer, int start, int len)
        {
            if (len < 0)
            {
                return;
            }
            int remaining = len;
            int head      = 0;

            do
            {
                UnityEngine.Debug.Assert(len >= 16);
                uint globaltime = NetUnpack.UnpacklI(buffer, head);
                uint localtime  = NetUnpack.UnpacklI(buffer, head + 4);
                uint eventtime  = NetUnpack.UnpacklI(buffer, head + 8);
                uint session    = NetUnpack.UnpacklI(buffer, head + 12);
                head      += 16;
                remaining -= 16;
                UnityEngine.Debug.Log(string.Format("localtime:{0}, eventtime:{1}, session:{2}", localtime, eventtime, session));
                if (eventtime == 0xffffffff)
                {
                    if (session == _session)
                    {
                        _timeSync.Sync((int)localtime, (int)globaltime);
                        if (_syncCb != null)
                        {
                            _connected = true;
                            _syncCb();
                        }
                        UnityEngine.Debug.Assert(remaining == 0);
                        return;
                    }
                }
                else
                {
                    if (session == _session)
                    {
                        //_timeSync.Sync((int)localtime, (int)globaltime);
                    }
                    if (remaining > 0)
                    {
                        R r = new R();
                        r.Globaltime = globaltime;
                        r.Localtime  = localtime;
                        r.Eventtime  = eventtime;
                        r.Session    = session;
                        byte[] data = new byte[remaining];
                        Array.Copy(_buffer, head, data, 0, remaining);
                        r.Data = data;
                        if (_recvCb != null)
                        {
                            _recvCb(r);
                        }
                        head      += remaining;
                        remaining -= remaining;
                    }
                }
            } while (remaining > 0);
            UnityEngine.Debug.Assert(remaining == 0);
        }
Пример #2
0
        private void RRecv(byte[] buffer, int start, int len)
        {
            if (len < 0)
            {
                return;
            }
            int remaining = len;
            int head      = 0;

            do
            {
                UnityEngine.Debug.Assert(len >= 16);
                uint globaltime = 0, localtime = 0, eventtime = 0, session = 0;
                int  offset = head;
                offset     = NetUnpack.UnpacklI(buffer, offset, out globaltime);
                offset     = NetUnpack.UnpacklI(buffer, offset, out localtime);
                offset     = NetUnpack.UnpacklI(buffer, offset, out eventtime);
                offset     = NetUnpack.UnpacklI(buffer, offset, out session);
                head      += offset;
                remaining -= offset;

                UnityEngine.Debug.Log(string.Format("localtime:{0}, eventtime:{1}, session:{2}", localtime, eventtime, session));
                if (session != _session)
                {
                    return;
                }
                if (eventtime == 0xffffffff)
                {
                    _timeSync.Sync((int)localtime, (int)globaltime);
                    _connected = true;
                    UnityEngine.Debug.Assert(remaining == 0);
                    UnityEngine.Debug.Log("package socket udp sync");
                    return;
                }
                else
                {
                    if (remaining > 0)
                    {
                        R r = new R();
                        r.Globaltime = globaltime;
                        r.Localtime  = localtime;
                        r.Eventtime  = eventtime;
                        r.Session    = session;
                        byte[] data = new byte[remaining];
                        Array.Copy(_buffer, head, data, 0, remaining);
                        r.Data = data;
                        if (_recvCb != null)
                        {
                            _recvCb(data, 0, data.Length);
                        }
                        head      += remaining;
                        remaining -= remaining;
                    }
                }
            } while (remaining > 0);
            UnityEngine.Debug.Assert(remaining == 0);
        }