Beispiel #1
0
        public void Guids()
        {
            // Creation
            Guid a = new Guid();
            byte[] bytes = a.GetBytes();
            for (int i = 0; i < 16; i++)
                Assert.IsTrue(bytes[i] == 0x00);

            // Comparison
            a = new Guid(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
                0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF }, 0);
            Guid b = new Guid(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
                0x0B, 0x0C, 0x0D, 0x0E, 0x0F }, 0);

            Assert.IsTrue(a == b, "Guid comparison operator failed, " + a.ToString() + " should equal " + 
                b.ToString());

            // From string
            a = new Guid(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
                0x0B, 0x0C, 0x0D, 0x0E, 0x0F }, 0);
            string zeroonetwo = "00010203-0405-0607-0809-0a0b0c0d0e0f";
            b = new Guid(zeroonetwo);

            Assert.IsTrue(a == b, "Guid hyphenated string constructor failed, should have " + a.ToString() + 
                " but we got " + b.ToString());

            // ToString()
            string one = a.ToString();
            string two = b.ToString();
            Assert.IsTrue(a == b);
            one = a.ToString();
            two = b.ToString();
            Assert.IsTrue(a == b);
            Assert.IsTrue(a == (Guid)zeroonetwo);

            // TODO: CRC test
        }
Beispiel #2
0
 public string VoiceAccountFromGuid(Guid id)
 {
     string result = "x" + Convert.ToBase64String(id.GetBytes());
     return result.Replace('+', '-').Replace('/', '_');
 }
Beispiel #3
0
        /// <summary>
        /// Give an inventory Folder with contents to another avatar
        /// </summary>
        /// <param name="folderID">The <seealso cref="Guid"/> of the Folder to give</param>
        /// <param name="folderName">The name of the folder</param>
        /// <param name="assetType">The type of the item from the <seealso cref="AssetType"/> enum</param>
        /// <param name="recipient">The <seealso cref="Guid"/> of the recipient</param>
        /// <param name="doEffect">true to generate a beameffect during transfer</param>
        public void GiveFolder(Guid folderID, string folderName, AssetType assetType, Guid recipient,
            bool doEffect)
        {
            byte[] bucket;

                List<InventoryItem> folderContents = new List<InventoryItem>();

                _Client.Inventory.FolderContents(folderID, _Client.Self.AgentID, false, true, InventorySortOrder.ByDate, 1000 * 15).ForEach(
                    delegate(InventoryBase ib)
                    {
                        folderContents.Add(_Client.Inventory.FetchItem(ib.Guid, _Client.Self.AgentID, 1000 * 10));
                    });
                bucket = new byte[17 * (folderContents.Count + 1)];

                //Add parent folder (first item in bucket)
                bucket[0] = (byte)assetType;
                Buffer.BlockCopy(folderID.GetBytes(), 0, bucket, 1, 16);

                //Add contents to bucket after folder
                for (int i = 1; i <= folderContents.Count; ++i)
                {
                    bucket[i * 17] = (byte)folderContents[i - 1].AssetType;
                    Buffer.BlockCopy(folderContents[i - 1].Guid.GetBytes(), 0, bucket, i * 17 + 1, 16);
                }

            _Client.Self.InstantMessage(
                    _Client.Self.Name,
                    recipient,
                    folderName,
                    Guid.NewGuid(),
                    InstantMessageDialog.InventoryOffered,
                    InstantMessageOnline.Online,
                    _Client.Self.SimPosition,
                    _Client.Network.CurrentSim.ID,
                    bucket);

            if (doEffect)
            {
                _Client.Self.BeamEffect(_Client.Self.AgentID, recipient, Vector3d.Zero,
                    _Client.Settings.DEFAULT_EFFECT_COLOR, 1f, Guid.NewGuid());
            }
        }
Beispiel #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        public void PackGuid(Guid data)
        {
            byte[] bytes = data.GetBytes();

            // Not sure if our PackBitArray function can handle 128-bit byte
            //arrays, so using this for now
            for (int i = 0; i < 16; i++)
                PackBits(bytes[i], 8);
        }
Beispiel #5
0
        /// <summary>
        /// Give an inventory item to another avatar
        /// </summary>
        /// <param name="itemID">The <seealso cref="Guid"/> of the item to give</param>
        /// <param name="itemName">The name of the item</param>
        /// <param name="assetType">The type of the item from the <seealso cref="AssetType"/> enum</param>
        /// <param name="recipient">The <seealso cref="Guid"/> of the recipient</param>
        /// <param name="doEffect">true to generate a beameffect during transfer</param>
        public void GiveItem(Guid itemID, string itemName, AssetType assetType, Guid recipient,
            bool doEffect)
        {
            byte[] bucket;


                bucket = new byte[17];
                bucket[0] = (byte)assetType;
                Buffer.BlockCopy(itemID.GetBytes(), 0, bucket, 1, 16);

            _Client.Self.InstantMessage(
                    _Client.Self.Name,
                    recipient,
                    itemName,
                    Guid.NewGuid(),
                    InstantMessageDialog.InventoryOffered,
                    InstantMessageOnline.Online,
                    _Client.Self.SimPosition,
                    _Client.Network.CurrentSim.ID,
                    bucket);

            if (doEffect)
            {
                _Client.Self.BeamEffect(_Client.Self.AgentID, recipient, Vector3d.Zero,
                    _Client.Settings.DEFAULT_EFFECT_COLOR, 1f, Guid.NewGuid());
            }
        }
Beispiel #6
0
        /// <summary>
        /// Combine two Guids with the XOR operator
        /// </summary>
        /// <param name="guid">Guid to XOR with the current Guid</param>
        public static void Xor(this Guid thisGuid, Guid guid)
        {
            byte[] lhsbytes = thisGuid.GetBytes();
            byte[] rhsbytes = guid.GetBytes();
            byte[] output = new byte[16];

            for (int i = 0; i < 16; i++)
                output[i] = (byte)(lhsbytes[i] ^ rhsbytes[i]);

            thisGuid.FromBytes(output, 0);
        }
Beispiel #7
0
        /// <summary>
        /// Combine two Guids together by taking the MD5 hash of a byte array
        /// containing both Guids
        /// </summary>
        /// <param name="guid">Guid to combine with the current Guid</param>
        public static void Combine(this Guid thisGuid, Guid guid)
        {
            // Construct the buffer that MD5ed
            byte[] input = new byte[32];
            Buffer.BlockCopy(thisGuid.GetBytes(), 0, input, 0, 16);
            Buffer.BlockCopy(guid.GetBytes(), 0, input, 16, 16);

            thisGuid.FromBytes(Utils.MD5(input), 0);
        }
Beispiel #8
0
        /// <summary>
        /// Create a particle beam between an avatar and an primitive
        /// </summary>
        /// <param name="sourceAvatar"><seealso cref="Guid"/> of sources avatar</param>
        /// <param name="targetObject"><seealso cref="Guid"/> of the target</param>
        /// <param name="globalOffset"><seealso cref="Vector3d"/>global offset</param>
        /// <param name="color"><seealso cref="Color4"/>Color values of beam</param>
        /// <param name="duration">a float representing the duration the beam will last</param>
        /// <param name="effectID"><seealso cref="Guid"/> of the Effect</param>
        public void BeamEffect(Guid sourceAvatar, Guid targetObject, Vector3d globalOffset, Color4 color,
            float duration, Guid effectID)
        {
            ViewerEffectPacket effect = new ViewerEffectPacket();

            effect.AgentData.AgentID = Client.Self.AgentID;
            effect.AgentData.SessionID = Client.Self.SessionID;

            effect.Effect = new ViewerEffectPacket.EffectBlock[1];
            effect.Effect[0] = new ViewerEffectPacket.EffectBlock();
            effect.Effect[0].AgentID = Client.Self.AgentID;
            effect.Effect[0].Color = color.GetBytes();
            effect.Effect[0].Duration = duration;
            effect.Effect[0].ID = effectID;
            effect.Effect[0].Type = (byte)EffectType.Beam;

            byte[] typeData = new byte[56];
            Buffer.BlockCopy(sourceAvatar.GetBytes(), 0, typeData, 0, 16);
            Buffer.BlockCopy(targetObject.GetBytes(), 0, typeData, 16, 16);
            Buffer.BlockCopy(globalOffset.GetBytes(), 0, typeData, 32, 24);

            effect.Effect[0].TypeData = typeData;

            Client.Network.SendPacket(effect);
        }
Beispiel #9
0
        /// <summary>
        /// Start a particle stream between an agent and an object
        /// </summary>
        /// <param name="sourceAvatar"><seealso cref="Guid"/> Key of the source agent</param>
        /// <param name="targetObject"><seealso cref="Guid"/> Key of the target object</param>
        /// <param name="globalOffset">A <seealso cref="Vector3d"/> representing the beams offset from the source</param>
        /// <param name="type">A <seealso cref="T:PointAtType"/> which sets the avatars lookat animation</param>
        /// <param name="effectID"><seealso cref="Guid"/> of the Effect</param>
        public void LookAtEffect(Guid sourceAvatar, Guid targetObject, Vector3d globalOffset, LookAtType type,
            Guid effectID)
        {
            ViewerEffectPacket effect = new ViewerEffectPacket();

            effect.AgentData.AgentID = Client.Self.AgentID;
            effect.AgentData.SessionID = Client.Self.SessionID;

            float duration;

            switch (type)
            {
                case LookAtType.Clear:
                    duration = 0.0f;
                    break;
                case LookAtType.Hover:
                    duration = 1.0f;
                    break;
                case LookAtType.FreeLook:
                    duration = 2.0f;
                    break;
                case LookAtType.Idle:
                    duration = 3.0f;
                    break;
                case LookAtType.AutoListen:
                case LookAtType.Respond:
                    duration = 4.0f;
                    break;
                case LookAtType.None:
                case LookAtType.Select:
                case LookAtType.Focus:
                case LookAtType.Mouselook:
                    duration = Single.MaxValue / 2.0f;
                    break;
                default:
                    duration = 0.0f;
                    break;
            }

            effect.Effect = new ViewerEffectPacket.EffectBlock[1];
            effect.Effect[0] = new ViewerEffectPacket.EffectBlock();
            effect.Effect[0].AgentID = Client.Self.AgentID;
            effect.Effect[0].Color = new byte[4];
            effect.Effect[0].Duration = duration;
            effect.Effect[0].ID = effectID;
            effect.Effect[0].Type = (byte)EffectType.LookAt;

            byte[] typeData = new byte[57];
            if (sourceAvatar != Guid.Empty)
                Buffer.BlockCopy(sourceAvatar.GetBytes(), 0, typeData, 0, 16);
            if (targetObject != Guid.Empty)
                Buffer.BlockCopy(targetObject.GetBytes(), 0, typeData, 16, 16);
            typeData[56] = (byte)type;

            effect.Effect[0].TypeData = typeData;

            Client.Network.SendPacket(effect);
        }
Beispiel #10
0
        /// <summary>
        /// Start a particle stream between an agent and an object
        /// </summary>
        /// <param name="sourceAvatar"><seealso cref="Guid"/> Key of the source agent</param>
        /// <param name="targetObject"><seealso cref="Guid"/> Key of the target object</param>
        /// <param name="globalOffset"></param>
        /// <param name="type">The type from the <seealso cref="T:PointAtType"/> enum</param>
        /// <param name="effectID">A unique <seealso cref="Guid"/> for this effect</param>
        public void PointAtEffect(Guid sourceAvatar, Guid targetObject, Vector3d globalOffset, PointAtType type,
            Guid effectID)
        {
            ViewerEffectPacket effect = new ViewerEffectPacket();

            effect.AgentData.AgentID = Client.Self.AgentID;
            effect.AgentData.SessionID = Client.Self.SessionID;

            effect.Effect = new ViewerEffectPacket.EffectBlock[1];
            effect.Effect[0] = new ViewerEffectPacket.EffectBlock();
            effect.Effect[0].AgentID = Client.Self.AgentID;
            effect.Effect[0].Color = new byte[4];
            effect.Effect[0].Duration = (type == PointAtType.Clear) ? 0.0f : Single.MaxValue / 4.0f;
            effect.Effect[0].ID = effectID;
            effect.Effect[0].Type = (byte)EffectType.PointAt;

            byte[] typeData = new byte[57];
            if (sourceAvatar != Guid.Empty)
                Buffer.BlockCopy(sourceAvatar.GetBytes(), 0, typeData, 0, 16);
            if (targetObject != Guid.Empty)
                Buffer.BlockCopy(targetObject.GetBytes(), 0, typeData, 16, 16);
            Buffer.BlockCopy(globalOffset.GetBytes(), 0, typeData, 32, 24);
            typeData[56] = (byte)type;

            effect.Effect[0].TypeData = typeData;

            Client.Network.SendPacket(effect);
        }