Пример #1
0
        public void Send(byte[] data)
        {
            if (_connected)
            {
                // 8 + 12 + 4 + data
                //byte[] crypt_head = new byte[8];
                byte[] head   = new byte[12];
                byte[] buffer = new byte[8 + 12 + data.Length];

                int   local  = _timeSync.LocalTime();
                int[] global = _timeSync.GlobalTime();
                NetPack.PacklI(head, 0, (uint)local);
                NetPack.PacklI(head, 4, (uint)global[0]);
                NetPack.PacklI(head, 8, (uint)_session);
                byte[] crypt_head = Crypt.hmac_hash(_secret, head);

                Array.Copy(crypt_head, buffer, 8);
                Array.Copy(head, 0, buffer, 8, 12);
                Array.Copy(data, 0, buffer, 20, data.Length);

                UnityEngine.Debug.Log(string.Format("localtime:{0}, eventtime:{1}, session:{2}", local, global[0], _session));
                _u.Send(data, 0, data.Length);
            }
            else
            {
                UnityEngine.Debug.Assert(false);
            }
        }
Пример #2
0
        public void Sync()
        {
            int now = _timeSync.LocalTime();

            byte[] buffer = new byte[12];
            NetPack.PacklI(buffer, 0, (uint)now);
            NetPack.PacklI(buffer, 4, 0xffffffff);
            NetPack.PacklI(buffer, 8, (uint)_session);
            byte[] head = Crypt.hmac_hash(_secret, buffer);
            byte[] data = new byte[8 + buffer.Length];
            Array.Copy(head, data, 8);
            Array.Copy(buffer, 0, data, 8, buffer.Length);

            _u.Send(data, 0, data.Length);
        }