public void llSetTextureAnim(IScriptInstance script, int mode, int face, int sizex, int sizey, float start, float length, float rate) { LLPrimitive prim = script.Host as LLPrimitive; if (prim == null) { return; } Primitive.TextureAnimMode animMode = (Primitive.TextureAnimMode)mode; if (face == LSLConstants.ALL_SIDES) { face = 255; } Primitive.TextureAnimation animation = new Primitive.TextureAnimation(); animation.Flags = animMode; animation.Face = (uint)face; animation.Length = length; animation.Rate = rate; animation.SizeX = (uint)sizex; animation.SizeY = (uint)sizey; animation.Start = start; prim.Prim.TextureAnim = animation; prim.Scene.EntityAddOrUpdate(this, prim, 0, (uint)LLUpdateFlags.TextureAnim); }
public void llSetClickAction(IScriptInstance script, int action) { if (script.Host is LLPrimitive) { LLPrimitive prim = (LLPrimitive)script.Host; ClickAction clickAction = (ClickAction)action; switch (clickAction) { case ClickAction.Buy: case ClickAction.OpenMedia: case ClickAction.OpenTask: case ClickAction.Pay: case ClickAction.PlayMedia: case ClickAction.Sit: case ClickAction.Touch: prim.Prim.ClickAction = ClickAction.Buy; break; default: prim.Prim.ClickAction = ClickAction.Touch; break; } } }
private void RotateTexture(IScriptInstance script, LLPrimitive obj, float angle, int side) { int sides = GetNumberOfSides(obj); if (side >= 0 && side < sides) { // Change one face Primitive.TextureEntryFace face = obj.Prim.Textures.CreateFace((uint)side); face.Rotation = angle; obj.Scene.EntityAddOrUpdate(this, obj, 0, (uint)LLUpdateFlags.Textures); } else if (side == LSLConstants.ALL_SIDES) { // Change all of the faces for (uint i = 0; i < sides; i++) { Primitive.TextureEntryFace face = obj.Prim.Textures.GetFace(i); if (face != null) { face.Rotation = angle; } } obj.Scene.EntityAddOrUpdate(this, obj, 0, (uint)LLUpdateFlags.Textures); } }
public string llGetInventoryName(IScriptInstance script, int type, int number) { LLPrimitive prim = script.Host as LLPrimitive; if (prim == null) { return(String.Empty); } AssetType assetType = (AssetType)type; IList <LLInventoryTaskItem> items = prim.Inventory.FindAllItems(item => assetType == AssetType.Unknown || item.AssetType == assetType); if (items.Count >= number) { return(String.Empty); } SortedList <string, LLInventoryTaskItem> sortedItems = new SortedList <string, LLInventoryTaskItem>(items.Count); for (int i = 0; i < items.Count; i++) { sortedItems.Add(items[i].Name, items[i]); } return(sortedItems.Values[number].Name); }
private void SetGlow(LLPrimitive obj, float intensity, int side) { int sides = GetNumberOfSides(obj); if (side >= 0 && side < sides) { // Get or create the requested face and update Primitive.TextureEntryFace face = obj.Prim.Textures.CreateFace((uint)side); face.Glow = intensity; obj.Scene.EntityAddOrUpdate(this, obj, 0, (uint)LLUpdateFlags.Textures); } else if (side == LSLConstants.ALL_SIDES) { // Change all of the faces for (uint i = 0; i < sides; i++) { Primitive.TextureEntryFace face = obj.Prim.Textures.GetFace(i); if (face != null) { face.Glow = intensity; } } obj.Scene.EntityAddOrUpdate(this, obj, 0, (uint)LLUpdateFlags.Textures); } }
private void SetShinyBump(LLPrimitive obj, Shininess shiny, Bumpiness bump, int side) { int sides = GetNumberOfSides(obj); if (side >= 0 && side < sides) { // Get or create the requested face and update Primitive.TextureEntryFace face = obj.Prim.Textures.CreateFace((uint)side); face.Shiny = shiny; face.Bump = bump; obj.Scene.EntityAddOrUpdate(this, obj, 0, (uint)LLUpdateFlags.Textures); } else if (side == LSLConstants.ALL_SIDES) { // Change all of the faces for (uint i = 0; i < sides; i++) { Primitive.TextureEntryFace face = obj.Prim.Textures.GetFace(i); if (face != null) { face.Shiny = shiny; face.Bump = bump; } } obj.Scene.EntityAddOrUpdate(this, obj, 0, (uint)LLUpdateFlags.Textures); } }
public string llAvatarOnSitTarget(IScriptInstance script) { if (script.Host is LLPrimitive) { LLPrimitive prim = (LLPrimitive)script.Host; if (prim.SitPosition != Vector3.Zero) { ILinkable[] children = ((ILinkable)script.Host).GetChildren(); for (int i = 0, len = children.Length; i < len; i++) { if (children[i] is LLAgent) { LLAgent childAgent = (LLAgent)children[i]; if (childAgent.RelativePosition == LLUtil.GetSitTarget(prim.SitPosition, childAgent.Scale)) { return(childAgent.ID.ToString()); } } } } } return(UUID.Zero.ToString()); }
public void llLoopSound(IScriptInstance script, string sound, float volume) { LLPrimitive prim = script.Host as LLPrimitive; if (prim == null) { return; } if (prim.Prim.Sound != UUID.Zero) { llStopSound(script); } UUID soundID = KeyOrName(script, sound, AssetType.Sound); if (soundID != UUID.Zero) { prim.Prim.Sound = soundID; prim.Prim.SoundGain = Utils.Clamp(volume, 0f, 1f); prim.Prim.SoundFlags = SoundFlags.Loop; prim.Prim.SoundRadius = DEFAULT_SOUND_RADIUS; prim.Scene.EntityAddOrUpdate(this, prim, 0, (uint)LLUpdateFlags.Sound); } }
public int llGetObjectPermMask(IScriptInstance script, int mask) { if (script.Host is LLPrimitive) { LLPrimitive prim = (LLPrimitive)script.Host; switch (mask) { case LSLConstants.MASK_BASE: return((int)prim.Prim.Properties.Permissions.BaseMask); case LSLConstants.MASK_EVERYONE: return((int)prim.Prim.Properties.Permissions.EveryoneMask); case LSLConstants.MASK_GROUP: return((int)prim.Prim.Properties.Permissions.GroupMask); case LSLConstants.MASK_NEXT: return((int)prim.Prim.Properties.Permissions.NextOwnerMask); case LSLConstants.MASK_OWNER: return((int)prim.Prim.Properties.Permissions.OwnerMask); } } return(0); }
public int llGetStatus(IScriptInstance script, int flag) { if (script.Host is LLPrimitive) { LLPrimitive prim = (LLPrimitive)script.Host; switch (flag) { case LSLConstants.STATUS_ROTATE_X: return(prim.AllowRotateX ? 1 : 0); case LSLConstants.STATUS_ROTATE_Y: return(prim.AllowRotateY ? 1 : 0); case LSLConstants.STATUS_ROTATE_Z: return(prim.AllowRotateZ ? 1 : 0); case LSLConstants.STATUS_BLOCK_GRAB: return(prim.BlockGrab ? 1 : 0); default: bool value = ((int)prim.Prim.Flags & flag) == flag; if (flag == LSLConstants.STATUS_PHYSICS) { prim.DynamicsEnabled = value; } return(value ? 1 : 0); } } return(0); }
public int llGetInventoryPermMask(IScriptInstance script, string name, int mask) { LLPrimitive prim = script.Host as LLPrimitive; if (prim == null) { return(0); } LLInventoryTaskItem found = prim.Inventory.FindItem(item => item.Name == name); if (found != null) { switch (mask) { case LSLConstants.MASK_BASE: return((int)found.Permissions.BaseMask); case LSLConstants.MASK_OWNER: return((int)found.Permissions.OwnerMask); case LSLConstants.MASK_GROUP: return((int)found.Permissions.GroupMask); case LSLConstants.MASK_EVERYONE: return((int)found.Permissions.EveryoneMask); case LSLConstants.MASK_NEXT: return((int)found.Permissions.NextOwnerMask); } } return(0); }
private void RequestXferHandler(Packet packet, LLAgent agent) { RequestXferPacket request = (RequestXferPacket)packet; string filename = Utils.BytesToString(request.XferID.Filename); UUID taskInventoryID; if (filename.StartsWith("inventory_") && filename.EndsWith(".tmp") && UUID.TryParse(filename.Substring(10, 36), out taskInventoryID)) { // This is a request for a task inventory listing, which we generate on demand ISceneEntity entity; if (m_scene.TryGetEntity(taskInventoryID, out entity) && entity is LLPrimitive) { LLPrimitive prim = (LLPrimitive)entity; byte[] assetData = Encoding.UTF8.GetBytes(prim.Inventory.GetTaskInventoryAsset()); SendXferPacketPacket xfer = new SendXferPacketPacket(); xfer.XferID.ID = request.XferID.ID; if (assetData.Length < 1000) { xfer.XferID.Packet = 0 | LAST_PACKET_MARKER; xfer.DataPacket.Data = new byte[assetData.Length + 4]; Utils.IntToBytes(assetData.Length, xfer.DataPacket.Data, 0); Buffer.BlockCopy(assetData, 0, xfer.DataPacket.Data, 4, assetData.Length); m_udp.SendPacket(agent, xfer, ThrottleCategory.Asset, false); m_log.Debug("Completed single packet xfer download of " + filename); } else { xfer.XferID.Packet = 0; xfer.DataPacket.Data = new byte[1000 + 4]; Utils.IntToBytes(assetData.Length, xfer.DataPacket.Data, 0); Buffer.BlockCopy(assetData, 0, xfer.DataPacket.Data, 4, 1000); // We don't need the entire XferDownload class, just the asset data and the current packet number XferDownload download = new XferDownload(); download.AssetData = assetData; download.PacketNum = 1; download.Filename = filename; lock (currentDownloads) currentDownloads[request.XferID.ID] = download; m_udp.SendPacket(agent, xfer, ThrottleCategory.Asset, false); } } else { m_log.Warn("Could not find primitive " + taskInventoryID); } } else { m_log.Warn("Got a RequestXfer for an unknown file: " + filename); } }
private void MoveTaskInventoryHandler(Packet packet, LLAgent agent) { MoveTaskInventoryPacket move = (MoveTaskInventoryPacket)packet; if (m_inventory != null) { LLInventoryTaskItem item; ISceneEntity sourceObj; if (m_scene.TryGetEntity(move.InventoryData.LocalID, out sourceObj) && sourceObj is LLPrimitive) { LLPrimitive sourcePrim = (LLPrimitive)sourceObj; if (sourcePrim.Inventory.TryGetItem(move.InventoryData.ItemID, out item)) { InventoryBase obj; if (m_inventory.TryGetInventory(agent.ID, move.AgentData.FolderID, out obj) && obj is InventoryFolder) { LLInventoryItem invItem = new LLInventoryItem { AssetID = item.AssetID, ContentType = item.ContentType, CreationDate = item.CreationDate, CreatorID = item.CreatorID, Description = item.Description, ExtraData = item.ExtraData, ID = UUID.Random(), Name = item.Name, OwnerID = agent.ID, ParentID = move.AgentData.FolderID }; if (m_inventory.TryCreateItem(agent.ID, invItem)) { RemoveTaskInventory(agent, sourcePrim, item.ID); SendItemCreatedPacket(agent, invItem, UUID.Zero, 0); m_log.Debug(agent.Name + " moved task inventory item " + item.Name + " to agent inventory folder " + invItem.ParentID); } else { m_log.Warn(agent.Name + "attempted to move item " + move.InventoryData.ItemID + " to agent inventory folder " + move.AgentData.FolderID + " but item creation failed"); } } else { m_log.Warn(agent.Name + "attempted to move item " + move.InventoryData.ItemID + " to unknown agent inventory folder " + move.AgentData.FolderID); } } } } else { m_log.Warn(agent.Name + "attempted to move item " + move.InventoryData.ItemID + " to agent inventory, but we have no IInventoryClient"); } }
private static LLType CreatePrimitiveType(LLPrimitive pPrimitive, int pSizeInBits) { LLType type = new LLType(); type.Primitive = pPrimitive; type.SizeInBits = pSizeInBits; sTypes[type.Signature] = type; return(type); }
public int llGetNumberOfSides(IScriptInstance script) { LLPrimitive prim = script.Host as LLPrimitive; if (prim == null) { return(0); } return(GetNumberOfSides(prim)); }
private void SignalTaskInventoryChange(LLAgent agent, LLPrimitive prim) { // Send an ObjectPropertiesReply to inform the client that inventory has changed ObjectPropertiesPacket props = new ObjectPropertiesPacket(); props.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1]; props.ObjectData[0] = LLUtil.BuildEntityPropertiesBlock(prim); m_udp.SendPacket(agent, props, ThrottleCategory.Task, false); // Signal this prim for serialization m_scene.EntityAddOrUpdate(this, prim, UpdateFlags.Serialize, 0); }
private static int GetNumberOfSides(LLPrimitive obj) { int sides = obj.GetNumberOfSides(); if (obj.Prim.Type == PrimType.Sphere && obj.Prim.PrimData.ProfileHollow > 0f) { // Account for an LSL bug where this reports four sides instead of two sides += 2; } return(sides); }
public Vector3 llGetTextureScale(IScriptInstance script, int face) { LLPrimitive prim = script.Host as LLPrimitive; if (prim == null) { return(Vector3.Zero); } Primitive.TextureEntryFace teFace = prim.Prim.Textures.GetFace((uint)face); return(new Vector3(teFace.RepeatU, teFace.RepeatV, 0f)); }
public void llSitTarget(IScriptInstance script, Vector3 position, Quaternion rotation) { LLPrimitive prim = script.Host as LLPrimitive; if (prim == null) { return; } prim.SitPosition = position; prim.SitRotation = rotation; }
public void llSetRemoteScriptAccessPin(IScriptInstance script, int pin) { LLPrimitive prim = script.Host as LLPrimitive; if (prim == null) { return; } prim.RemoteScriptAccessPIN = pin; script.AddSleepMS(200); }
public void llSetPayPrice(IScriptInstance script, int defaultPrice, object[] buttons) { if (script.Host is LLPrimitive) { LLPrimitive prim = (LLPrimitive)script.Host; prim.PayPrice = defaultPrice; prim.PayPriceButtons[0] = llList2Integer(script, buttons, 0); prim.PayPriceButtons[1] = llList2Integer(script, buttons, 1); prim.PayPriceButtons[2] = llList2Integer(script, buttons, 2); prim.PayPriceButtons[3] = llList2Integer(script, buttons, 3); } }
public float llGetTextureRot(IScriptInstance script, int face) { LLPrimitive prim = script.Host as LLPrimitive; if (prim == null) { return(0f); } Primitive.TextureEntryFace teFace = prim.Prim.Textures.GetFace((uint)face); return(teFace.Rotation); }
public int llGetInventoryNumber(IScriptInstance script, int type) { LLPrimitive prim = script.Host as LLPrimitive; if (prim == null) { return(0); } AssetType assetType = (AssetType)type; return(prim.Inventory.FindAllItems(item => assetType == AssetType.Unknown || item.AssetType == assetType).Count); }
public string llGetTexture(IScriptInstance script, int side) { if (script.Host is LLPrimitive) { LLPrimitive obj = (LLPrimitive)script.Host; if (side >= 0 && side < GetNumberOfSides(obj)) { return(obj.Prim.Textures.GetFace((uint)side).TextureID.ToString()); } } return(UUID.Zero.ToString()); }
public Vector3 llGetColor(IScriptInstance script, int side) { if (script.Host is LLPrimitive) { LLPrimitive obj = (LLPrimitive)script.Host; if (side >= 0 && side < GetNumberOfSides(obj)) { Color4 color = obj.Prim.Textures.GetFace((uint)side).RGBA; return(new Vector3(color.R, color.G, color.B)); } } return(Vector3.Zero); }
public float llGetAlpha(IScriptInstance script, int side) { if (script.Host is LLPrimitive) { LLPrimitive obj = (LLPrimitive)script.Host; if (side >= 0 && side < GetNumberOfSides(obj)) { Color4 color = obj.Prim.Textures.GetFace((uint)side).RGBA; return(color.A); } } return(0.0f); }
public int llGetAttached(IScriptInstance script) { int point = -1; if (script.Host is LLPrimitive) { LLPrimitive prim = (LLPrimitive)script.Host; if (prim.Parent != null) { point = (int)prim.Prim.PrimData.AttachmentPoint; } } return(point); }
private void SetPrimShapeParams(LLPrimitive prim, int holeShape, Vector3 cut, float hollow, Vector3 twist, Vector3 topSize, Vector3 topShear) { HoleType hole = (HoleType)holeShape; if (hole != HoleType.Same && hole != HoleType.Circle && hole != HoleType.Square && hole != HoleType.Triangle) { hole = HoleType.Same; } // Clamp the cut values cut.X = Utils.Clamp(cut.X, 0f, 1f); cut.Y = Utils.Clamp(cut.Y, 0f, 1f); if (cut.Y - cut.X < 0.05f) { cut.X = cut.Y - 0.05f; if (cut.X < 0f) { cut.X = 0f; cut.Y = 0.05f; } } // Clamp hollow hollow = Utils.Clamp(hollow, 0f, 0.95f); // Clamp the twist values twist.X = Utils.Clamp(twist.X, -1f, 1f); twist.Y = Utils.Clamp(twist.Y, -1f, 1f); // Clamp the taper values topSize.X = Utils.Clamp(topSize.X, 0f, 2f); topSize.Y = Utils.Clamp(topSize.Y, 0f, 2f); // Clamp the top shear values topShear.X = Utils.Clamp(topShear.X, -0.5f, 0.5f); topShear.Y = Utils.Clamp(topShear.Y, -0.5f, 0.5f); prim.Prim.PrimData.ProfileHole = hole; prim.Prim.PrimData.ProfileBegin = cut.X; prim.Prim.PrimData.ProfileEnd = cut.Y; prim.Prim.PrimData.ProfileHollow = hollow; prim.Prim.PrimData.PathTwistBegin = twist.X; prim.Prim.PrimData.PathTwist = twist.Y; prim.Prim.PrimData.PathScaleX = topSize.Y; prim.Prim.PrimData.PathScaleY = topSize.Y; prim.Prim.PrimData.PathShearX = topShear.X; prim.Prim.PrimData.PathShearY = topShear.Y; }
private void SetText(ISceneEntity obj, string text, Vector3 color, float alpha) { if (obj is LLPrimitive) { LLPrimitive prim = (LLPrimitive)obj; prim.Prim.Text = text; prim.Prim.TextColor = new Color4( Utils.Clamp(color.X, 0f, 1f), Utils.Clamp(color.Y, 0f, 1f), Utils.Clamp(color.Z, 0f, 1f), Utils.Clamp(alpha, 0f, 1f)); prim.Scene.EntityAddOrUpdate(this, prim, UpdateFlags.FullUpdate, 0); } }
private void SetPrimShapeParams(LLPrimitive prim, int holeShape, Vector3 cut, float hollow, Vector3 twist, Vector3 dimple) { HoleType hole = (HoleType)holeShape; if (hole != HoleType.Same && hole != HoleType.Circle && hole != HoleType.Square && hole != HoleType.Triangle) { hole = HoleType.Same; } // Clamp the cut values cut.X = Utils.Clamp(cut.X, 0f, 1f); cut.Y = Utils.Clamp(cut.Y, 0f, 1f); if (cut.Y - cut.X < 0.05f) { cut.X = cut.Y - 0.05f; if (cut.X < 0f) { cut.X = 0f; cut.Y = 0.05f; } } // Clamp hollow hollow = Utils.Clamp(hollow, 0f, 0.95f); // Clamp the twist values twist.X = Utils.Clamp(twist.X, -1f, 1f); twist.Y = Utils.Clamp(twist.Y, -1f, 1f); // Clamp the dimple values dimple.X = Utils.Clamp(dimple.X, 0f, 1f); dimple.Y = Utils.Clamp(dimple.Y, 0f, 1f); if (dimple.Y - cut.X < 0.05f) { dimple.X = cut.Y - 0.05f; } prim.Prim.PrimData.ProfileHole = hole; prim.Prim.PrimData.ProfileBegin = cut.X; prim.Prim.PrimData.ProfileEnd = cut.Y; prim.Prim.PrimData.ProfileHollow = hollow; prim.Prim.PrimData.PathTwistBegin = twist.X; prim.Prim.PrimData.PathTwist = twist.Y; // TODO: Is this right? If so, what is cut for? prim.Prim.PrimData.ProfileBegin = dimple.X; prim.Prim.PrimData.ProfileEnd = dimple.Y; }
public static ObjectUpdateCompressedPacket.ObjectDataBlock CreateCompressedObjectUpdateBlock(LLPrimitive entity, uint crc) { Primitive prim = entity.Prim; #region Size calculation and field serialization CompressedFlags flags = 0; int size = 84; byte[] textBytes = null; byte[] mediaURLBytes = null; byte[] particleBytes = null; byte[] extraParamBytes = null; byte[] nameValueBytes = null; byte[] textureBytes = null; byte[] textureAnimBytes = null; flags |= CompressedFlags.HasAngularVelocity; size += 12; flags |= CompressedFlags.HasParent; size += 4; switch (prim.PrimData.PCode) { case PCode.Grass: case PCode.Tree: case PCode.NewTree: flags |= CompressedFlags.Tree; size += 2; // Size byte plus one byte break; //default: // flags |= CompressedFlags.ScratchPad; // size += 1 + prim.ScratchPad.Length; // Size byte plus length // break; } flags |= CompressedFlags.HasText; textBytes = StringToBytesNullTerminated(prim.Text); size += textBytes.Length; // Null-terminated, no size byte size += 4; // Text color flags |= CompressedFlags.MediaURL; mediaURLBytes = StringToBytesNullTerminated(prim.MediaURL); size += mediaURLBytes.Length; // Null-terminated, no size byte if (prim.ParticleSys.BurstPartCount > 0) { flags |= CompressedFlags.HasParticles; particleBytes = prim.ParticleSys.GetBytes(); size += particleBytes.Length; // Should be exactly 86 bytes } // Extra Params extraParamBytes = prim.GetExtraParamsBytes(); size += extraParamBytes.Length; if (prim.Sound != UUID.Zero) { flags |= CompressedFlags.HasSound; size += 25; // SoundID, SoundGain, SoundFlags, SoundRadius } if (prim.NameValues != null && prim.NameValues.Length > 0) { flags |= CompressedFlags.HasNameValues; nameValueBytes = StringToBytesNullTerminated(NameValue.NameValuesToString(prim.NameValues)); size += nameValueBytes.Length; } size += 23; // PrimData size += 4; // Texture Length textureBytes = prim.Textures.GetBytes(); size += textureBytes.Length; // Texture Entry flags |= CompressedFlags.TextureAnimation; size += 4; // TextureAnim Length textureAnimBytes = prim.TextureAnim.GetBytes(); size += textureAnimBytes.Length; // TextureAnim #endregion Size calculation and field serialization #region Packet serialization int pos = 0; byte[] data = new byte[size]; prim.ID.ToBytes(data, 0); // UUID pos += 16; Utils.UIntToBytes(prim.LocalID, data, pos); // LocalID pos += 4; data[pos++] = (byte)prim.PrimData.PCode; // PCode data[pos++] = prim.PrimData.State; // State Utils.UIntToBytes(crc, data, pos); // CRC pos += 4; data[pos++] = (byte)prim.PrimData.Material; // Material data[pos++] = (byte)prim.ClickAction; // ClickAction prim.Scale.ToBytes(data, pos); // Scale pos += 12; prim.Position.ToBytes(data, pos); // Position pos += 12; prim.Rotation.ToBytes(data, pos); // Rotation pos += 12; Utils.UIntToBytes((uint)flags, data, pos); // Compressed flags pos += 4; prim.OwnerID.ToBytes(data, pos); // OwnerID pos += 16; prim.AngularVelocity.ToBytes(data, pos); // Angular velocity pos += 12; Utils.UIntToBytes(prim.ParentID, data, pos); // ParentID pos += 4; if ((flags & CompressedFlags.Tree) != 0) { data[pos++] = 1; data[pos++] = (byte)prim.TreeSpecies; } //else if ((flags & CompressedFlags.ScratchPad) != 0) //{ // data[pos++] = (byte)prim.ScratchPad.Length; // Buffer.BlockCopy(prim.ScratchPad, 0, data, pos, prim.ScratchPad.Length); // pos += prim.ScratchPad.Length; //} Buffer.BlockCopy(textBytes, 0, data, pos, textBytes.Length); pos += textBytes.Length; prim.TextColor.ToBytes(data, pos, false); pos += 4; Buffer.BlockCopy(mediaURLBytes, 0, data, pos, mediaURLBytes.Length); pos += mediaURLBytes.Length; if (particleBytes != null) { Buffer.BlockCopy(particleBytes, 0, data, pos, particleBytes.Length); pos += particleBytes.Length; } // Extra Params Buffer.BlockCopy(extraParamBytes, 0, data, pos, extraParamBytes.Length); pos += extraParamBytes.Length; if ((flags & CompressedFlags.HasSound) != 0) { prim.Sound.ToBytes(data, pos); pos += 16; Utils.FloatToBytes(prim.SoundGain, data, pos); pos += 4; data[pos++] = (byte)prim.SoundFlags; Utils.FloatToBytes(prim.SoundRadius, data, pos); pos += 4; } if (nameValueBytes != null) { Buffer.BlockCopy(nameValueBytes, 0, data, pos, nameValueBytes.Length); pos += nameValueBytes.Length; } // Path PrimData data[pos++] = (byte)prim.PrimData.PathCurve; Utils.UInt16ToBytes(Primitive.PackBeginCut(prim.PrimData.PathBegin), data, pos); pos += 2; Utils.UInt16ToBytes(Primitive.PackEndCut(prim.PrimData.PathEnd), data, pos); pos += 2; data[pos++] = Primitive.PackPathScale(prim.PrimData.PathScaleX); data[pos++] = Primitive.PackPathScale(prim.PrimData.PathScaleY); data[pos++] = (byte)Primitive.PackPathShear(prim.PrimData.PathShearX); data[pos++] = (byte)Primitive.PackPathShear(prim.PrimData.PathShearY); data[pos++] = (byte)Primitive.PackPathTwist(prim.PrimData.PathTwist); data[pos++] = (byte)Primitive.PackPathTwist(prim.PrimData.PathTwistBegin); data[pos++] = (byte)Primitive.PackPathTwist(prim.PrimData.PathRadiusOffset); data[pos++] = (byte)Primitive.PackPathTaper(prim.PrimData.PathTaperX); data[pos++] = (byte)Primitive.PackPathTaper(prim.PrimData.PathTaperY); data[pos++] = Primitive.PackPathRevolutions(prim.PrimData.PathRevolutions); data[pos++] = (byte)Primitive.PackPathTwist(prim.PrimData.PathSkew); // Profile PrimData data[pos++] = prim.PrimData.profileCurve; Utils.UInt16ToBytes(Primitive.PackBeginCut(prim.PrimData.ProfileBegin), data, pos); pos += 2; Utils.UInt16ToBytes(Primitive.PackEndCut(prim.PrimData.ProfileEnd), data, pos); pos += 2; Utils.UInt16ToBytes(Primitive.PackProfileHollow(prim.PrimData.ProfileHollow), data, pos); pos += 2; // Texture Length Utils.UIntToBytes((uint)textureBytes.Length, data, pos); pos += 4; // Texture Entry Buffer.BlockCopy(textureBytes, 0, data, pos, textureBytes.Length); pos += textureBytes.Length; Utils.UIntToBytes((uint)textureAnimBytes.Length, data, pos); pos += 4; Buffer.BlockCopy(textureAnimBytes, 0, data, pos, textureAnimBytes.Length); pos += textureAnimBytes.Length; System.Diagnostics.Debug.Assert(pos == size, "Got a pos of " + pos + " instead of " + size); #endregion Packet serialization return new ObjectUpdateCompressedPacket.ObjectDataBlock { Data = data }; }
private static LLType CreatePrimitiveType(LLPrimitive pPrimitive, int pSizeInBits) { LLType type = new LLType(); type.Primitive = pPrimitive; type.SizeInBits = pSizeInBits; sTypes[type.Signature] = type; return type; }
private bool RemoveTaskInventory(LLAgent agent, LLPrimitive host, UUID itemID) { LLInventoryTaskItem item; if (host.Inventory.TryGetItem(itemID, out item)) { host.Inventory.RemoveItem(itemID); m_log.Debug(agent.Name + " removed task inventory item: " + item.Name); if (item.AssetType == AssetType.LSLText && m_scriptEngine != null) m_scriptEngine.StopScript(item.ID); SignalTaskInventoryChange(agent, host); return true; } else { m_log.Warn(agent.Name + " attempted to remove unknown task inventory item " + itemID + " from prim " + host.LocalID); return false; } }
private static PrimFlags GetUpdateFlags(LLPrimitive prim, IScenePresence sendingTo, LLPermissions m_permissions) { PrimFlags flags; if (m_permissions != null && sendingTo != null) { flags = m_permissions.GetFlagsFor(sendingTo, prim); } else { flags = PrimFlags.CastShadows | PrimFlags.ObjectCopy | PrimFlags.ObjectTransfer | PrimFlags.ObjectYouOwner | PrimFlags.ObjectModify | PrimFlags.ObjectMove | PrimFlags.ObjectOwnerModify; } return flags; }
void ObjectAddHandler(Packet packet, LLAgent agent) { if (!agent.IsVerified) { m_scene.PresenceAlert(this, agent, "You are logged in with an unverified account. Object creation is disabled."); return; } ObjectAddPacket add = (ObjectAddPacket)packet; Vector3 position = Vector3.Zero; Vector3 scale = add.ObjectData.Scale; PCode pcode = (PCode)add.ObjectData.PCode; PrimFlags flags = (PrimFlags)add.ObjectData.AddFlags; bool bypassRaycast = (add.ObjectData.BypassRaycast == 1); //bool rayEndIsIntersection = (add.ObjectData.RayEndIsIntersection == 1); #region Position Calculation if (bypassRaycast) { position = add.ObjectData.RayEnd; } else if (m_physics != null) { Vector3 direction = (add.ObjectData.RayEnd - add.ObjectData.RayStart); direction /= direction.Length(); Ray ray = new Ray(add.ObjectData.RayStart, direction); ISceneEntity collisionObj; float collisionDist; if (m_physics.FullSceneCollisionTest(true, ray, null, out collisionObj, out collisionDist)) { position = ray.GetPoint(collisionDist); } else { m_log.Warn("Full scene collision test for ray " + ray + " failed"); position = agent.ScenePosition + Vector3.UnitZ; } } position.Z += scale.Z * 0.5f; #endregion Position Calculation if (!CanAddPrims(agent, position, 1)) return; #region Foliage Handling // Set all foliage to phantom if (pcode == PCode.Grass || pcode == PCode.Tree || pcode == PCode.NewTree) { flags |= PrimFlags.Phantom; if (pcode != PCode.Grass) { // Resize based on the foliage type Tree tree = (Tree)add.ObjectData.State; switch (tree) { case Tree.Cypress1: case Tree.Cypress2: scale = new Vector3(4f, 4f, 10f); break; default: scale = new Vector3(4f, 4f, 4f); break; } } } #endregion Foliage Handling #region Prim Creation // Create an object Primitive prim = new Primitive(); prim.Flags = PrimFlags.CastShadows | PrimFlags.InventoryEmpty; prim.Flags |= (PrimFlags)add.ObjectData.AddFlags; // TODO: Security check prim.GroupID = add.AgentData.GroupID; prim.ID = UUID.Random(); prim.MediaURL = String.Empty; prim.OwnerID = agent.ID; prim.Position = position; prim.PrimData.Material = (Material)add.ObjectData.Material; prim.PrimData.PathCurve = (PathCurve)add.ObjectData.PathCurve; prim.PrimData.ProfileCurve = (ProfileCurve)add.ObjectData.ProfileCurve; prim.PrimData.PathBegin = Primitive.UnpackBeginCut(add.ObjectData.PathBegin); prim.PrimData.PathEnd = Primitive.UnpackEndCut(add.ObjectData.PathEnd); prim.PrimData.PathScaleX = Primitive.UnpackPathScale(add.ObjectData.PathScaleX); prim.PrimData.PathScaleY = Primitive.UnpackPathScale(add.ObjectData.PathScaleY); prim.PrimData.PathShearX = Primitive.UnpackPathShear((sbyte)add.ObjectData.PathShearX); prim.PrimData.PathShearY = Primitive.UnpackPathShear((sbyte)add.ObjectData.PathShearY); prim.PrimData.PathTwist = Primitive.UnpackPathTwist(add.ObjectData.PathTwist); prim.PrimData.PathTwistBegin = Primitive.UnpackPathTwist(add.ObjectData.PathTwistBegin); prim.PrimData.PathRadiusOffset = Primitive.UnpackPathTwist(add.ObjectData.PathRadiusOffset); prim.PrimData.PathTaperX = Primitive.UnpackPathTaper(add.ObjectData.PathTaperX); prim.PrimData.PathTaperY = Primitive.UnpackPathTaper(add.ObjectData.PathTaperY); prim.PrimData.PathRevolutions = Primitive.UnpackPathRevolutions(add.ObjectData.PathRevolutions); prim.PrimData.PathSkew = Primitive.UnpackPathTwist(add.ObjectData.PathSkew); prim.PrimData.ProfileBegin = Primitive.UnpackBeginCut(add.ObjectData.ProfileBegin); prim.PrimData.ProfileEnd = Primitive.UnpackEndCut(add.ObjectData.ProfileEnd); prim.PrimData.ProfileHollow = Primitive.UnpackProfileHollow(add.ObjectData.ProfileHollow); prim.PrimData.PCode = pcode; prim.Properties = new Primitive.ObjectProperties(); prim.Properties.CreationDate = DateTime.UtcNow; prim.Properties.CreatorID = agent.ID; prim.Properties.Description = String.Empty; prim.Properties.GroupID = add.AgentData.GroupID; prim.Properties.LastOwnerID = agent.ID; prim.Properties.Name = "Object"; prim.Properties.ObjectID = prim.ID; prim.Properties.OwnerID = prim.OwnerID; prim.Properties.Permissions = m_permissions.GetDefaultPermissions(); prim.Properties.SalePrice = 10; prim.Rotation = add.ObjectData.Rotation; prim.Scale = scale; prim.TextColor = Color4.Black; if (pcode == PCode.Prim) { prim.Textures = new Primitive.TextureEntry(PLYWOOD_TEXTURE); } #endregion Prim Creation // Add this prim to the scene ISceneEntity primObj = new LLPrimitive(prim, m_scene, m_primMesher); m_scene.EntityAddOrUpdate(this, primObj, UpdateFlags.FullUpdate, 0); }
private void DetachObject(LLAgent agent, LLPrimitive prim) { // FIXME: Implement }
private void SendPropertiesPacket(LLAgent agent, LLPrimitive prim, ReportType type) { ObjectPropertiesFamilyPacket props = new ObjectPropertiesFamilyPacket(); props.ObjectData.BaseMask = (uint)prim.Prim.Properties.Permissions.BaseMask; props.ObjectData.Category = (uint)prim.Prim.Properties.Category; props.ObjectData.Description = Utils.StringToBytes(prim.Prim.Properties.Description); props.ObjectData.EveryoneMask = (uint)prim.Prim.Properties.Permissions.EveryoneMask; props.ObjectData.GroupID = prim.Prim.Properties.GroupID; props.ObjectData.GroupMask = (uint)prim.Prim.Properties.Permissions.GroupMask; props.ObjectData.LastOwnerID = prim.Prim.Properties.LastOwnerID; props.ObjectData.Name = Utils.StringToBytes(prim.Prim.Properties.Name); props.ObjectData.NextOwnerMask = (uint)prim.Prim.Properties.Permissions.NextOwnerMask; props.ObjectData.ObjectID = prim.Prim.ID; props.ObjectData.OwnerID = prim.Prim.Properties.OwnerID; props.ObjectData.OwnerMask = (uint)prim.Prim.Properties.Permissions.OwnerMask; props.ObjectData.OwnershipCost = prim.Prim.Properties.OwnershipCost; props.ObjectData.RequestFlags = (uint)type; props.ObjectData.SalePrice = prim.Prim.Properties.SalePrice; props.ObjectData.SaleType = (byte)prim.Prim.Properties.SaleType; m_udp.SendPacket(agent, props, ThrottleCategory.Task, false); }
void ObjectDuplicateHandler(Packet packet, LLAgent agent) { ObjectDuplicatePacket duplicate = (ObjectDuplicatePacket)packet; PrimFlags flags = (PrimFlags)duplicate.SharedData.DuplicateFlags; Vector3 offset = duplicate.SharedData.Offset; List<LLPrimitive> duplicates = new List<LLPrimitive>(duplicate.ObjectData.Length); int count = 0; // Build the list of prims to duplicate for (int i = 0; i < duplicate.ObjectData.Length; i++) { uint dupeID = duplicate.ObjectData[i].ObjectLocalID; ISceneEntity entity; if (m_scene.TryGetEntity(dupeID, out entity) && entity is LLPrimitive) { LLPrimitive prim = (LLPrimitive)entity; PermissionMask perms = m_permissions.GetPrimPermissions(agent, prim); if (!perms.HasPermission(PermissionMask.Copy)) { m_scene.PresenceAlert(this, agent, "You do not have permission to copy one " + "or more selected objects"); return; } ILinkable[] children = prim.GetChildren(); count += 1 + children.Length; duplicates.Add(prim); } else { m_log.Warn("ObjectDuplicate sent for missing prim " + dupeID); SendSingleKillPacket(agent, dupeID); } } if (duplicates.Count == 0) return; // NOTE: Right now we only permissions check on the first duplicated item, but take into // account the total number of prims that will be duplicated. This should handle most // cases, but may not be correct as compared to other LLUDP implementations Vector3 targetPosition = duplicates[0].ScenePosition + offset; if (!CanAddPrims(agent, targetPosition, count)) return; for (int i = 0; i < duplicates.Count; i++) { LLPrimitive prim = duplicates[i]; Primitive obj = new Primitive(prim.Prim); obj.LocalID = 0; obj.ID = UUID.Zero; LLPrimitive newRoot = new LLPrimitive(obj, m_scene, m_primMesher); newRoot.RelativePosition += offset; newRoot.Prim.Properties.CreationDate = DateTime.UtcNow; m_scene.EntityAddOrUpdate(this, newRoot, UpdateFlags.FullUpdate, 0); // Duplicate any child prims ILinkable[] children = prim.GetChildren(); for (int p = 0, len = children.Length; p < len; p++) { if (children[p] is LLPrimitive) { LLPrimitive child = (LLPrimitive)children[p]; Primitive childPrim = new Primitive(child.Prim); childPrim.LocalID = 0; childPrim.ID = UUID.Zero; LLPrimitive newChild = new LLPrimitive(childPrim, m_scene, m_primMesher); newChild.SetParent(newRoot, true, false); m_scene.EntityAddOrUpdate(this, newChild, UpdateFlags.FullUpdate, 0); } } } }
private void RezSinglePrim(LLPrimitive prim, RezObjectPacket.RezDataBlock rezData, Vector3 position) { // Set the target position for root prims if (prim.Parent == null) prim.RelativePosition = position; // TODO: Is this right? prim.Prim.Flags |= (PrimFlags)rezData.ItemFlags; if (rezData.RezSelected) prim.Prim.Flags |= PrimFlags.CreateSelected; // TODO: Is this right? prim.Prim.Properties.Permissions = GetDefaultPermissions(); prim.Prim.Properties.Permissions.EveryoneMask = (PermissionMask)rezData.EveryoneMask; prim.Prim.Properties.Permissions.GroupMask = (PermissionMask)rezData.GroupMask; prim.Prim.Properties.Permissions.NextOwnerMask = (PermissionMask)rezData.NextOwnerMask; m_scene.EntityAddOrUpdate(this, prim, UpdateFlags.FullUpdate, 0); }