Beispiel #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);
            }
        }