private void SendAgentSetAppearance() { AgentSetAppearancePacket set = new AgentSetAppearancePacket(); set.AgentData.AgentID = Client.Self.AgentID; set.AgentData.SessionID = Client.Self.SessionID; set.AgentData.SerialNum = SetAppearanceSerialNum++; set.VisualParam = new AgentSetAppearancePacket.VisualParamBlock[218]; float AgentSizeVPHeight = 0.0f; float AgentSizeVPHeelHeight = 0.0f; float AgentSizeVPPlatformHeight = 0.0f; float AgentSizeVPHeadSize = 0.5f; float AgentSizeVPLegLength = 0.0f; float AgentSizeVPNeckLength = 0.0f; float AgentSizeVPHipLength = 0.0f; lock (Wearables.Dictionary) { // Only for debugging output int count = 0, vpIndex = 0; // Build the visual param array foreach (KeyValuePair<int, VisualParam> kvp in VisualParams.Params) { VisualParam vp = kvp.Value; // Only Group-0 parameters are sent in AgentSetAppearance packets if (vp.Group == 0) { set.VisualParam[vpIndex] = new AgentSetAppearancePacket.VisualParamBlock(); // Try and find this value in our collection of downloaded wearables foreach (WearableData data in Wearables.Dictionary.Values) { if (data.Asset != null && data.Asset.Params.ContainsKey(vp.ParamID)) { set.VisualParam[vpIndex].ParamValue = Utils.FloatToByte(data.Asset.Params[vp.ParamID], vp.MinValue, vp.MaxValue); count++; switch (vp.ParamID) { case 33: AgentSizeVPHeight = data.Asset.Params[vp.ParamID]; break; case 198: AgentSizeVPHeelHeight = data.Asset.Params[vp.ParamID]; break; case 503: AgentSizeVPPlatformHeight = data.Asset.Params[vp.ParamID]; break; case 682: AgentSizeVPHeadSize = data.Asset.Params[vp.ParamID]; break; case 692: AgentSizeVPLegLength = data.Asset.Params[vp.ParamID]; break; case 756: AgentSizeVPNeckLength = data.Asset.Params[vp.ParamID]; break; case 842: AgentSizeVPHipLength = data.Asset.Params[vp.ParamID]; break; } break; } } ++vpIndex; } } // Build the texture entry for our agent Primitive.TextureEntry te = new Primitive.TextureEntry(DEFAULT_AVATAR_TEXTURE); // Put our AgentTextures array in to TextureEntry lock (AgentTextures) { for (uint i = 0; i < AgentTextures.Length; i++) { if (AgentTextures[i] != Guid.Empty) { Primitive.TextureEntryFace face = te.CreateFace(i); face.TextureID = AgentTextures[i]; } } } foreach (WearableData data in Wearables.Dictionary.Values) { if (data.Asset != null) { foreach (KeyValuePair<TextureIndex, Guid> texture in data.Asset.Textures) { Primitive.TextureEntryFace face = te.CreateFace((uint)texture.Key); face.TextureID = texture.Value; Logger.DebugLog("Setting agent texture " + ((TextureIndex)texture.Key).ToString() + " to " + texture.Value.ToString(), Client); } } } // Set the packet TextureEntry set.ObjectData.TextureEntry = te.ToBytes(); } // FIXME: Our hackish algorithm is making squished avatars. See // http://www.OpenMetaverse.org/wiki/Agent_Size for discussion of the correct algorithm //float height = Utils.ByteToFloat(set.VisualParam[33].ParamValue, VisualParams.Params[33].MinValue, // VisualParams.Params[33].MaxValue); // Takes into account the Shoe Heel/Platform offsets but not the Head Size Offset. But seems to work. double AgentSizeBase = 1.706; // The calculation for the Head Size scalar may be incorrect. But seems to work. double AgentHeight = AgentSizeBase + (AgentSizeVPLegLength * .1918) + (AgentSizeVPHipLength * .0375) + (AgentSizeVPHeight * .12022) + (AgentSizeVPHeadSize * .01117) + (AgentSizeVPNeckLength * .038) + (AgentSizeVPHeelHeight * .08) + (AgentSizeVPPlatformHeight * .07); set.AgentData.Size = new Vector3f(0.45f, 0.6f, (float)AgentHeight); // TODO: Account for not having all the textures baked yet set.WearableData = new AgentSetAppearancePacket.WearableDataBlock[BAKED_TEXTURE_COUNT]; // Build hashes for each of the bake layers from the individual components for (int bakedIndex = 0; bakedIndex < BAKED_TEXTURE_COUNT; bakedIndex++) { Guid hash = new Guid(); for (int wearableIndex = 0; wearableIndex < WEARABLES_PER_LAYER; wearableIndex++) { WearableType type = WEARABLE_BAKE_MAP[bakedIndex][wearableIndex]; Guid assetID = GetWearableAsset(type); // Build a hash of all the texture asset IDs in this baking layer if (assetID != Guid.Empty) hash.Xor(assetID); } if (hash != Guid.Empty) { // Hash with our secret value for this baked layer hash.Xor(BAKED_TEXTURE_HASH[bakedIndex]); } // Tell the server what cached texture assetID to use for each bake layer set.WearableData[bakedIndex] = new AgentSetAppearancePacket.WearableDataBlock(); set.WearableData[bakedIndex].TextureIndex = (byte)bakedIndex; set.WearableData[bakedIndex].CacheID = hash; } // Finally, send the packet Client.Network.SendPacket(set); }
/// <summary> /// Send an Instant Message /// </summary> /// <param name="fromName">The name this IM will show up as being from</param> /// <param name="target">Key of Avatar</param> /// <param name="message">Text message being sent</param> /// <param name="imSessionID">IM session ID (to differentiate between IM windows)</param> /// <param name="dialog">Type of instant message to send</param> /// <param name="offline">Whether to IM offline avatars as well</param> /// <param name="position">Senders Position</param> /// <param name="regionID">RegionID Sender is In</param> /// <param name="binaryBucket">Packed binary data that is specific to /// the dialog type</param> public void InstantMessage(string fromName, Guid target, string message, Guid imSessionID, InstantMessageDialog dialog, InstantMessageOnline offline, Vector3f position, Guid regionID, byte[] binaryBucket) { if (target != Guid.Empty) { ImprovedInstantMessagePacket im = new ImprovedInstantMessagePacket(); if (imSessionID.Equals(Guid.Empty) || imSessionID.Equals(AgentID)) { if (AgentID == target) { imSessionID = AgentID; } else { imSessionID = target; imSessionID.Xor(AgentID); } } im.AgentData.AgentID = Client.Self.AgentID; im.AgentData.SessionID = Client.Self.SessionID; im.MessageBlock.Dialog = (byte)dialog; im.MessageBlock.FromAgentName = Utils.StringToBytes(fromName); im.MessageBlock.FromGroup = false; im.MessageBlock.ID = imSessionID; im.MessageBlock.Message = Utils.StringToBytes(message); im.MessageBlock.Offline = (byte)offline; im.MessageBlock.ToAgentID = target; if (binaryBucket != null) im.MessageBlock.BinaryBucket = binaryBucket; else im.MessageBlock.BinaryBucket = new byte[0]; // These fields are mandatory, even if we don't have valid values for them im.MessageBlock.Position = Vector3f.Zero; //TODO: Allow region id to be correctly set by caller or fetched from Client.* im.MessageBlock.RegionID = regionID; // Send the message Client.Network.SendPacket(im); } else { Logger.Log(String.Format("Suppressing instant message \"{0}\" to Guid.Empty", message), Helpers.LogLevel.Error, Client); } }
/// <summary> /// Build hashes out of the texture assetIDs for each baking layer to /// ask the simulator whether it has cached copies of each baked texture /// </summary> public void RequestCachedBakes() { Logger.DebugLog("RequestCachedBakes()", Client); List<KeyValuePair<int, Guid>> hashes = new List<KeyValuePair<int,Guid>>(); AgentCachedTexturePacket cache = new AgentCachedTexturePacket(); cache.AgentData.AgentID = Client.Self.AgentID; cache.AgentData.SessionID = Client.Self.SessionID; cache.AgentData.SerialNum = CacheCheckSerialNum; // Build hashes for each of the bake layers from the individual components for (int bakedIndex = 0; bakedIndex < BAKED_TEXTURE_COUNT; bakedIndex++) { // Don't do a cache request for a skirt bake if we're not wearing a skirt if (bakedIndex == (int)BakeType.Skirt && (!Wearables.ContainsKey(WearableType.Skirt) || Wearables.Dictionary[WearableType.Skirt].Asset.AssetID == Guid.Empty)) continue; Guid hash = new Guid(); for (int wearableIndex = 0; wearableIndex < WEARABLES_PER_LAYER; wearableIndex++) { WearableType type = WEARABLE_BAKE_MAP[bakedIndex][wearableIndex]; Guid assetID = GetWearableAsset(type); // Build a hash of all the texture asset IDs in this baking layer if (assetID != Guid.Empty) hash.Xor(assetID); } if (hash != Guid.Empty) { // Hash with our secret value for this baked layer hash.Xor(BAKED_TEXTURE_HASH[bakedIndex]); // Add this to the list of hashes to send out hashes.Add(new KeyValuePair<int, Guid>(bakedIndex, hash)); } } // Only send the packet out if there's something to check if (hashes.Count > 0) { cache.WearableData = new AgentCachedTexturePacket.WearableDataBlock[hashes.Count]; for (int i = 0; i < hashes.Count; i++) { cache.WearableData[i] = new AgentCachedTexturePacket.WearableDataBlock(); cache.WearableData[i].TextureIndex = (byte)hashes[i].Key; cache.WearableData[i].ID = hashes[i].Value; Logger.DebugLog("Checking cache for index " + cache.WearableData[i].TextureIndex + ", ID: " + cache.WearableData[i].ID, Client); } // Increment our serial number for this packet CacheCheckSerialNum++; // Send it out Client.Network.SendPacket(cache); } }
/// <summary> /// Send an Instant Message /// </summary> /// <param name="target">Target of the Instant Message</param> /// <param name="message">Text message being sent</param> public void InstantMessage(Guid target, string message) { Guid id; if (AgentID == target) { id = AgentID; } else { id = target; id.Xor(AgentID); } InstantMessage(Name, target, message, id, InstantMessageDialog.MessageFromAgent, InstantMessageOnline.Offline, this.SimPosition, Guid.Empty, new byte[0]); }