Beispiel #1
0
        public LSL_List aaDeserializeXMLKeys(LSL_String xmlFile)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Moderate, "AADeserializeXMLKeys", m_host, "AA", m_itemID))
            {
                return(new LSL_List());
            }
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xmlFile.m_string);
            XmlNodeList children = doc.ChildNodes;
            LSL_List    keys     = new LSL_List();

            foreach (XmlNode node in children)
            {
                keys.Add(node.Name);
            }
            return(keys);
        }
Beispiel #2
0
        public LSL_List aaGetTeamMembers(LSL_String team)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Low, "AAGetTeamMembers", m_host, "AA", m_itemID))
            {
                return(new LSL_List());
            }
            List <UUID>   Members = new List <UUID>();
            ICombatModule module  = World.RequestModuleInterface <ICombatModule>();

            if (module != null)
            {
                Members = module.GetTeammates(team);
            }
            LSL_List members = new LSL_List();

            foreach (UUID member in Members)
            {
                members.Add(new LSL_Key(member.ToString()));
            }
            return(members);
        }
Beispiel #3
0
        public LSL_List botGetBotsWithTag(string tag)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Moderate, "botGetBotsWithTag", m_host, "bot", m_itemID))
            {
                return(new LSL_List());
            }
            IBotManager manager = World.RequestModuleInterface <IBotManager>();
            List <UUID> bots    = new List <UUID>();

            if (manager != null)
            {
                bots = manager.GetBotsWithTag(tag);
            }
            LSL_List b = new LSL_List();

            foreach (UUID bot in bots)
            {
                b.Add(bot.ToString());
            }

            return(b);
        }
Beispiel #4
0
 public LSL_List aaDeserializeXMLValues(LSL_String xmlFile)
 {
     if (
         !ScriptProtection.CheckThreatLevel(ThreatLevel.Moderate, "AADeserializeXMLValues", m_host, "AA",
                                            m_itemID)) return new LSL_List();
     XmlDocument doc = new XmlDocument();
     doc.LoadXml(xmlFile.m_string);
     XmlNodeList children = doc.ChildNodes;
     LSL_List values = new LSL_List();
     foreach (XmlNode node in children)
     {
         values.Add(node.InnerText);
     }
     return values;
 }
Beispiel #5
0
        public LSL_List llGetAnimationList(string id)
        {
            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
            

            LSL_List l = new LSL_List();
            ScenePresence av = World.GetScenePresence((UUID)id);
            if (av == null || av.IsChildAgent) // only if in the region
                return l;
            UUID[] anims;
            anims = av.Animator.GetAnimationArray();
            foreach (UUID foo in anims)
                l.Add(foo.ToString());
            return l;
        }
Beispiel #6
0
        public LSL_List GetLinkPrimitiveParams(SceneObjectPart part, LSL_List rules)
        {
            LSL_List res = new LSL_List();
            int idx = 0;
            while (idx < rules.Length)
            {
                int code = (int)rules.GetLSLIntegerItem(idx++);
                int remain = rules.Length - idx;
                Primitive.TextureEntry tex = part.Shape.Textures;
                int face = 0;
                if (idx < rules.Length)
                    face = (int)rules.GetLSLIntegerItem(idx++);

                Primitive.TextureEntryFace texFace = tex.GetFace((uint)face);

                if (code == (int)ScriptBaseClass.PRIM_NAME)
                {
                    res.Add(new LSL_Integer(part.Name));
                }

                if (code == (int)ScriptBaseClass.PRIM_DESC)
                {
                    res.Add(new LSL_Integer(part.Description));
                }

                if (code == (int)ScriptBaseClass.PRIM_MATERIAL)
                {
                    res.Add(new LSL_Integer(part.Material));
                }

                if (code == (int)ScriptBaseClass.PRIM_PHYSICS)
                {
                    if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) != 0)
                        res.Add(new LSL_Integer(1));
                    else
                        res.Add(new LSL_Integer(0));
                }

                if (code == (int)ScriptBaseClass.PRIM_TEMP_ON_REZ)
                {
                    if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.TemporaryOnRez) != 0)
                        res.Add(new LSL_Integer(1));
                    else
                        res.Add(new LSL_Integer(0));
                }

                if (code == (int)ScriptBaseClass.PRIM_PHANTOM)
                {
                    if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) != 0)
                        res.Add(new LSL_Integer(1));
                    else
                        res.Add(new LSL_Integer(0));
                }

                if (code == (int)ScriptBaseClass.PRIM_POSITION)
                {
                    Vector3 tmp = part.AbsolutePosition;
                    LSL_Vector v = new LSL_Vector(tmp.X,
                                                  tmp.Y,
                                                  tmp.Z);
                    // For some reason, the part.AbsolutePosition.* values do not change if the
                    // linkset is rotated; they always reflect the child prim's world position
                    // as though the linkset is unrotated. This is incompatible behavior with SL's
                    // implementation, so will break scripts imported from there (not to mention it
                    // makes it more difficult to determine a child prim's actual inworld position).
                    if (part.ParentID != 0)
                        {
                        LSL_Rotation rtmp = llGetRootRotation();
                        LSL_Vector rpos = llGetRootPosition();
                        v = ((v - rpos) * rtmp) + rpos;
                        }
                    res.Add(v);
                }

                if (code == (int)ScriptBaseClass.PRIM_SIZE)
                {
                    Vector3 tmp = part.Scale;
                    res.Add(new LSL_Vector(tmp.X,
                                                  tmp.Y,
                                                  tmp.Z));
                }

                if (code == (int)ScriptBaseClass.PRIM_ROTATION)
                {
                    res.Add(GetPartRot(part));
                }

                if (code == (int)ScriptBaseClass.PRIM_TYPE)
                {
                    // implementing box
                    PrimitiveBaseShape Shape = part.Shape;
                    int primType = (int)part.GetPrimType();
                    res.Add(new LSL_Integer(primType));
                    double topshearx = (double)(sbyte)Shape.PathShearX / 100.0; // Fix negative values for PathShearX
                    double topsheary = (double)(sbyte)Shape.PathShearY / 100.0; // and PathShearY.
                    if (primType == ScriptBaseClass.PRIM_TYPE_BOX ||
                         ScriptBaseClass.PRIM_TYPE_CYLINDER ||
                         ScriptBaseClass.PRIM_TYPE_PRISM)
                    {
                        res.Add(new LSL_Integer(Shape.ProfileCurve));
                        res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
                        res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
                        res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
                        res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
                        res.Add(new LSL_Vector(topshearx, topsheary, 0));
                    }

                    if (primType == ScriptBaseClass.PRIM_TYPE_SPHERE)
                    {
                        res.Add(new LSL_Integer(Shape.ProfileCurve));
                        res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
                        res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
                        res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
                        res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
                    }

                    if (primType == ScriptBaseClass.PRIM_TYPE_SCULPT)
                    {
                        res.Add(Shape.SculptTexture.ToString());
                        res.Add(new LSL_Integer(Shape.SculptType));
                    }
                    if (primType == ScriptBaseClass.PRIM_TYPE_RING ||
                     ScriptBaseClass.PRIM_TYPE_TUBE ||
                     ScriptBaseClass.PRIM_TYPE_TORUS)
                    {
                        // holeshape
                        res.Add(new LSL_Integer(Shape.ProfileCurve));

                        // cut
                        res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));

                        // hollow
                        res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));

                        // twist
                        res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));

                        // vector holesize
                        res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));

                        // vector topshear
                        res.Add(new LSL_Vector(topshearx, topsheary, 0));

                        // vector profilecut
                        res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));

                        // vector tapera
                        res.Add(new LSL_Vector(Shape.PathTaperX / 100.0, Shape.PathTaperY / 100.0, 0));

                        // float revolutions
                        res.Add(new LSL_Float((Shape.PathRevolutions * 0.015) + 1.0)); // Slightly inaccurate, because an unsigned
                        // byte is being used to represent the entire
                        // range of floating-point values from 1.0
                        // through 4.0 (which is how SL does it). 

                        // float radiusoffset
                        res.Add(new LSL_Float(Shape.PathRadiusOffset / 100.0));

                        // float skew
                        res.Add(new LSL_Float(Shape.PathSkew / 100.0));
                    }
                }

                if (code == (int)ScriptBaseClass.PRIM_TEXTURE)
                {
                    if (remain < 1)
                        return res;

                    if (face == ScriptBaseClass.ALL_SIDES)
                    {
                        for (face = 0; face < GetNumberOfSides(part); face++)
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint)face);

                            res.Add(new LSL_String(texface.TextureID.ToString()));
                            res.Add(new LSL_Vector(texface.RepeatU,
                                                   texface.RepeatV,
                                                   0));
                            res.Add(new LSL_Vector(texface.OffsetU,
                                                   texface.OffsetV,
                                                   0));
                            res.Add(new LSL_Float(texface.Rotation));
                        }
                    }
                    else
                    {
                        if (face >= 0 && face < GetNumberOfSides(part))
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint)face);

                            res.Add(new LSL_String(texface.TextureID.ToString()));
                            res.Add(new LSL_Vector(texface.RepeatU,
                                                   texface.RepeatV,
                                                   0));
                            res.Add(new LSL_Vector(texface.OffsetU,
                                                   texface.OffsetV,
                                                   0));
                            res.Add(new LSL_Float(texface.Rotation));
                        }
                    }
                }

                if (code == (int)ScriptBaseClass.PRIM_COLOR)
                {
                    if (remain < 1)
                        return res;

                    tex = part.Shape.Textures;
                    Color4 texcolor;
                    if (face == ScriptBaseClass.ALL_SIDES)
                    {
                        for (face = 0; face < GetNumberOfSides(part); face++)
                        {
                            texcolor = tex.GetFace((uint)face).RGBA;
                            res.Add(new LSL_Vector(texcolor.R,
                                                   texcolor.G,
                                                   texcolor.B));
                            res.Add(new LSL_Float(texcolor.A));
                        }
                    }
                    else
                    {
                        texcolor = tex.GetFace((uint)face).RGBA;
                        res.Add(new LSL_Vector(texcolor.R,
                                               texcolor.G,
                                               texcolor.B));
                        res.Add(new LSL_Float(texcolor.A));
                    }
                }

                if (code == (int)ScriptBaseClass.PRIM_BUMP_SHINY)
                {
                    if (remain < 1)
                        return res;

                    face = (int)rules.GetLSLIntegerItem(idx++);
                    texFace = tex.GetFace((uint)face);

                    if (face == ScriptBaseClass.ALL_SIDES)
                    {
                        for (face = 0; face < GetNumberOfSides(part); face++)
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                            // Convert Shininess to PRIM_SHINY_*
                            res.Add(new LSL_Integer((uint)texface.Shiny >> 6));
                            // PRIM_BUMP_*
                            res.Add(new LSL_Integer((int)texface.Bump));
                        }
                    }
                    else
                    {
                        if (face >= 0 && face < GetNumberOfSides(part))
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                            // Convert Shininess to PRIM_SHINY_*
                            res.Add(new LSL_Integer((uint)texface.Shiny >> 6));
                            // PRIM_BUMP_*
                            res.Add(new LSL_Integer((int)texface.Bump));
                        }
                    }
                }

                if (code == (int)ScriptBaseClass.PRIM_FULLBRIGHT)
                {
                    if (remain < 1)
                        return res;

                    face = (int)rules.GetLSLIntegerItem(idx++);
                    tex = part.Shape.Textures;
                    if (face == ScriptBaseClass.ALL_SIDES)
                    {
                        for (face = 0; face < GetNumberOfSides(part); face++)
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                            res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
                        }
                    }
                    else
                    {
                        if (face >= 0 && face < GetNumberOfSides(part))
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                            res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
                        }
                    }
                }

                if (code == (int)ScriptBaseClass.PRIM_FLEXIBLE)
                {
                    PrimitiveBaseShape shape = part.Shape;

                    if (shape.FlexiEntry)
                        res.Add(new LSL_Integer(1));              // active
                    else
                        res.Add(new LSL_Integer(0));
                    res.Add(new LSL_Integer(shape.FlexiSoftness));// softness
                    res.Add(new LSL_Float(shape.FlexiGravity));   // gravity
                    res.Add(new LSL_Float(shape.FlexiDrag));      // friction
                    res.Add(new LSL_Float(shape.FlexiWind));      // wind
                    res.Add(new LSL_Float(shape.FlexiTension));   // tension
                    res.Add(new LSL_Vector(shape.FlexiForceX,       // force
                                           shape.FlexiForceY,
                                           shape.FlexiForceZ));
                }

                if (code == (int)ScriptBaseClass.PRIM_TEXGEN)
                {
                    if (remain < 1)
                        return res;

                    face = (int)rules.GetLSLIntegerItem(idx++);
                    if (face == ScriptBaseClass.ALL_SIDES)
                    {
                        for (face = 0; face < GetNumberOfSides(part); face++)
                        {
                            MappingType texgen = tex.GetFace((uint)face).TexMapType;
                            // Convert MappingType to PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR etc.
                            res.Add(new LSL_Integer((uint)texgen >> 1));
                        }
                    }
                    else
                    {
                        if (face >= 0 && face < GetNumberOfSides(part))
                        {
                            MappingType texgen = tex.GetFace((uint)face).TexMapType;
                            res.Add(new LSL_Integer((uint)texgen >> 1));
                        }
                    }
                }

                if (code == (int)ScriptBaseClass.PRIM_POINT_LIGHT)
                {
                    PrimitiveBaseShape shape = part.Shape;

                    if (shape.LightEntry)
                        res.Add(new LSL_Integer(1));              // active
                    else
                        res.Add(new LSL_Integer(0));
                    res.Add(new LSL_Vector(shape.LightColorR,       // color
                                           shape.LightColorG,
                                           shape.LightColorB));
                    res.Add(new LSL_Float(shape.LightIntensity)); // intensity
                    res.Add(new LSL_Float(shape.LightRadius));    // radius
                    res.Add(new LSL_Float(shape.LightFalloff));   // falloff
                }

                if (code == (int)ScriptBaseClass.PRIM_GLOW)
                {
                    if (remain < 1)
                        return res;

                    face = (int)rules.GetLSLIntegerItem(idx++);
                    if (face == ScriptBaseClass.ALL_SIDES)
                    {
                        for (face = 0; face < GetNumberOfSides(part); face++)
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                            res.Add(new LSL_Float(texface.Glow));
                        }
                    }
                    else
                    {
                        if (face >= 0 && face < GetNumberOfSides(part))
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                            res.Add(new LSL_Float(texface.Glow));
                        }
                    }
                }

                if (code == (int)ScriptBaseClass.PRIM_TEXT)
                {
                    Color4 textColor = part.GetTextColor();
                    res.Add(part.Text);
                    res.Add(new LSL_Vector(textColor.R,
                                           textColor.G,
                                           textColor.B));
                    res.Add(new LSL_Float(textColor.A));
                }
                if (code == (int)ScriptBaseClass.PRIM_ROT_LOCAL)
                {
                    Quaternion rtmp = part.RotationOffset;
                    res.Add(new LSL_Rotation(rtmp.X, rtmp.Y, rtmp.Z, rtmp.W));
                }
            }
            return res;
        }
Beispiel #7
0
        public LSL_List llGetObjectDetails(string id, LSL_List args)
        {
            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
            
            LSL_List ret = new LSL_List();
            UUID key = new UUID();
            if (UUID.TryParse(id, out key))
            {
                ScenePresence av = World.GetScenePresence(key);

                if (av != null)
                {
                    foreach (object o in args.Data)
                    {
                        if ((LSL_Integer)o == ScriptBaseClass.OBJECT_NAME)
                        {
                            ret.Add(av.Firstname + " " + av.Lastname);
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_DESC)
                        {
                            ret.Add("");
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_POS)
                        {
                            Vector3 tmp = av.AbsolutePosition;
                            ret.Add(new LSL_Vector((double)tmp.X, (double)tmp.Y, (double)tmp.Z));
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_ROT)
                        {
                            Quaternion rtmp = av.Rotation;
                            ret.Add(new LSL_Rotation((double)rtmp.X, (double)rtmp.Y, (double)rtmp.Z, (double)rtmp.W));
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_VELOCITY)
                        {
                            Vector3 tmp = av.Velocity;
                            ret.Add(new LSL_Vector(tmp.X, tmp.Y, tmp.Z));
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_OWNER)
                        {
                            ret.Add(id);
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_GROUP)
                        {
                            ret.Add(UUID.Zero.ToString());
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_CREATOR)
                        {
                            ret.Add(UUID.Zero.ToString());
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT)
                        {
                            IScriptModule[] modules = World.RequestModuleInterfaces<IScriptModule>();
                            int activeScripts = 0;
                            foreach (IScriptModule module in modules)
                            {
                                activeScripts += module.GetActiveScripts(av);
                            }
                            ret.Add(activeScripts);
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT)
                        {
                            IScriptModule[] modules = World.RequestModuleInterfaces<IScriptModule>();
                            int totalScripts = 0;
                            foreach (IScriptModule module in modules)
                            {
                                totalScripts += module.GetTotalScripts(av);
                            }
                            ret.Add(totalScripts);
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_SCRIPT_MEMORY)
                        {
                            ret.Add(0);
                        }
                    }
                    return ret;
                }
                SceneObjectPart obj = World.GetSceneObjectPart(key);
                if (obj != null)
                {
                    foreach (object o in args.Data)
                    {
                        if ((LSL_Integer)o == ScriptBaseClass.OBJECT_NAME)
                        {
                            ret.Add(obj.Name);
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_DESC)
                        {
                            ret.Add(obj.Description);
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_POS)
                        {
                            Vector3 tmp = obj.AbsolutePosition;
                            ret.Add(new LSL_Vector(tmp.X, tmp.Y, tmp.Z));
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_ROT)
                        {
                            Quaternion rtmp = obj.RotationOffset;
                            ret.Add(new LSL_Rotation(rtmp.X, rtmp.Y, rtmp.Z, rtmp.W));
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_VELOCITY)
                        {
                            Vector3 tmp = obj.Velocity;
                            ret.Add(new LSL_Vector(tmp.X, tmp.Y, tmp.Z));
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_OWNER)
                        {
                            ret.Add(obj.OwnerID.ToString());
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_GROUP)
                        {
                            ret.Add(obj.GroupID.ToString());
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_CREATOR)
                        {
                            ret.Add(obj.CreatorID.ToString());
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT)
                        {
                            IScriptModule[] modules = World.RequestModuleInterfaces<IScriptModule>();
                            int activeScripts = 0;
                            foreach(IScriptModule module in modules)
                            {
                                activeScripts += module.GetActiveScripts(obj);
                            }
                            ret.Add(activeScripts);
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT)
                        {
                            IScriptModule[] modules = World.RequestModuleInterfaces<IScriptModule>();
                            int totalScripts = 0;
                            foreach (IScriptModule module in modules)
                            {
                                totalScripts += module.GetTotalScripts(obj);
                            }
                            ret.Add(totalScripts);
                        }
                        else if ((LSL_Integer)o == ScriptBaseClass.OBJECT_SCRIPT_MEMORY)
                        {
                            ret.Add(0);
                        }
                    }
                    return ret;
                }
            }
            return new LSL_List();
        }
Beispiel #8
0
        ///  <summary>
        ///  Randomizes the list, be arbitrarily reordering
        ///  sublists of stride elements. As the stride approaches
        ///  the size of the list, the options become very
        ///  limited.
        ///  </summary>
        ///  <remarks>
        ///  This could take a while for very large list
        ///  sizes.
        ///  </remarks>

        public LSL_List llListRandomize(LSL_List src, int stride)
        {
            LSL_List result;
            Random rand           = new Random();

            int   chunkk;
            int[] chunks;

            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
            

            if (stride <= 0)
            {
                stride = 1;
            }

            // Stride MUST be a factor of the list length
            // If not, then return the src list. This also
            // traps those cases where stride > length.

            if (src.Length != stride && src.Length%stride == 0)
            {
                chunkk = src.Length/stride;

                chunks = new int[chunkk];

                for (int i = 0; i < chunkk; i++)
                    chunks[i] = i;

                // Knuth shuffle the chunkk index
                for (int i = chunkk - 1; i >= 1; i--)
                {
                    // Elect an unrandomized chunk to swap
                    int index = rand.Next(i + 1);
                    int tmp;

                    // and swap position with first unrandomized chunk
                    tmp = chunks[i];
                    chunks[i] = chunks[index];
                    chunks[index] = tmp;
                }

                // Construct the randomized list

                result = new LSL_List();

                for (int i = 0; i < chunkk; i++)
                {
                    for (int j = 0; j < stride; j++)
                    {
                        result.Add(src.Data[chunks[i]*stride+j]);
                    }
                }
            }
            else {
                object[] array = new object[src.Length];
                Array.Copy(src.Data, 0, array, 0, src.Length);
                result = new LSL_List(array);
            }

            return result;
        }
Beispiel #9
0
        public LSL_List botGetBotsWithTag (string tag)
        {
            ScriptProtection.CheckThreatLevel (ThreatLevel.Moderate, "botGetBotsWithTag", m_host, "bot");
            IBotManager manager = World.RequestModuleInterface<IBotManager> ();
            List<UUID> bots = new List<UUID> ();
            if (manager != null)
                bots = manager.GetBotsWithTag (tag);
            LSL_List b = new LSL_List ();
            foreach(UUID bot in bots)
                b.Add(bot.ToString());

            return b;
        }
Beispiel #10
0
        private LSL_List GetPrimMediaParams(int face, LSL_List rules)
        {
            IMoapModule module = World.RequestModuleInterface<IMoapModule>();
            if (null == module)
                throw new Exception("Media on a prim functions not available");

            MediaEntry me = module.GetMediaEntry(m_host, face);

            // As per http://wiki.secondlife.com/wiki/LlGetPrimMediaParams
            if (null == me)
                return new LSL_List();

            LSL_List res = new LSL_List();

            for (int i = 0; i < rules.Length; i++)
            {
                int code = (int)rules.GetLSLIntegerItem(i);

                if (code == ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE)
                {
                    // Not implemented
                    res.Add(new LSL_Integer(0));
                }

                else if (code == ScriptBaseClass.PRIM_MEDIA_CONTROLS)
                {
                    if (me.Controls == MediaControls.Standard)
                        res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD));
                    else
                        res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_MINI));
                }
                else if (code == ScriptBaseClass.PRIM_MEDIA_CURRENT_URL)
                {
                    res.Add(new LSL_String(me.CurrentURL));
                }
                else if (code == ScriptBaseClass.PRIM_MEDIA_HOME_URL)
                {
                    res.Add(new LSL_String(me.HomeURL));
                }
                else if (code == ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP)
                {
                    res.Add(me.AutoLoop ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
                }
                else if (code == ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY)
                {
                    res.Add(me.AutoPlay ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
                }
                else if (code == ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE)
                {
                    res.Add(me.AutoScale ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
                }
                else if (code == ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM)
                {
                    res.Add(me.AutoZoom ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
                }
                else if (code == ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT)
                {
                    res.Add(me.InteractOnFirstClick ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
                }
                else if (code == ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS)
                {
                    res.Add(new LSL_Integer(me.Width));
                }
                else if (code == ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS)
                {
                    res.Add(new LSL_Integer(me.Height));
                }
                else if (code == ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE)
                {
                    res.Add(me.EnableWhiteList ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
                }
                else if (code == ScriptBaseClass.PRIM_MEDIA_WHITELIST)
                {
                    string[] urls = (string[])me.WhiteList.Clone();

                    for (int j = 0; j < urls.Length; j++)
                        urls[j] = Uri.EscapeDataString(urls[j]);

                    res.Add(new LSL_String(string.Join(", ", urls)));
                }
                else if (code == ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT)
                {
                    res.Add(new LSL_Integer((int)me.InteractPermissions));
                }
                else if (code == ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL)
                {
                    res.Add(new LSL_Integer((int)me.ControlPermissions));
                }
            }

            return res;
        }
Beispiel #11
0
        public LSL_List llGetObjectDetails(string id, LSL_List args)
        {
            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
            
            LSL_List ret = new LSL_List();
            UUID key = new UUID();
            if (UUID.TryParse(id, out key))
            {
                ScenePresence av = World.GetScenePresence(key);

                if (av != null)
                {
                    foreach (object o in args.Data)
                    {
                        switch (o.ToString())
                        {
                            case "1":
                                ret.Add(av.Firstname + " " + av.Lastname);
                                break;
                            case "2":
                                ret.Add("");
                                break;
                            case "3":
                                ret.Add(new LSL_Vector((double)av.AbsolutePosition.X, (double)av.AbsolutePosition.Y, (double)av.AbsolutePosition.Z));
                                break;
                            case "4":
                                ret.Add(new LSL_Rotation((double)av.Rotation.X, (double)av.Rotation.Y, (double)av.Rotation.Z, (double)av.Rotation.W));
                                break;
                            case "5":
                                ret.Add(new LSL_Vector(av.Velocity.X, av.Velocity.Y, av.Velocity.Z));
                                break;
                            case "6":
                                ret.Add(id);
                                break;
                            case "7":
                                ret.Add(UUID.Zero.ToString());
                                break;
                            case "8":
                                ret.Add(UUID.Zero.ToString());
                                break;
                        }
                    }
                    return ret;
                }
                SceneObjectPart obj = World.GetSceneObjectPart(key);
                if (obj != null)
                {
                    foreach (object o in args.Data)
                    {
                        switch (o.ToString())
                        {
                            case "1":
                                ret.Add(obj.Name);
                                break;
                            case "2":
                                ret.Add(obj.Description);
                                break;
                            case "3":
                                ret.Add(new LSL_Vector(obj.AbsolutePosition.X, obj.AbsolutePosition.Y, obj.AbsolutePosition.Z));
                                break;
                            case "4":
                                ret.Add(new LSL_Rotation(obj.RotationOffset.X, obj.RotationOffset.Y, obj.RotationOffset.Z, obj.RotationOffset.W));
                                break;
                            case "5":
                                ret.Add(new LSL_Vector(obj.Velocity.X, obj.Velocity.Y, obj.Velocity.Z));
                                break;
                            case "6":
                                ret.Add(obj.OwnerID.ToString());
                                break;
                            case "7":
                                ret.Add(obj.GroupID.ToString());
                                break;
                            case "8":
                                ret.Add(obj.CreatorID.ToString());
                                break;
                        }
                    }
                    return ret;
                }
            }
            return new LSL_List();
        }
Beispiel #12
0
        /// <summary>
        ///     Like osGetAgents but returns enough info for a radar
        /// </summary>
        /// <returns>Strided list of the UUID, position and name of each avatar in the region</returns>
        public LSL_List osGetAvatarList()
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osGetAvatarList", m_host, "OSSL", m_itemID))
                return new LSL_List();

            LSL_List result = new LSL_List();
            World.ForEachScenePresence(delegate(IScenePresence avatar)
                                           {
                                               if (avatar != null && avatar.UUID != m_host.OwnerID)
                                               {
                                                   if (!avatar.IsChildAgent)
                                                   {
                                                       result.Add(new LSL_Key(avatar.UUID.ToString()));
                                                       result.Add(new LSL_Vector(avatar.AbsolutePosition.X,
                                                                                 avatar.AbsolutePosition.Y,
                                                                                 avatar.AbsolutePosition.Z));
                                                       result.Add(new LSL_String(avatar.Name));
                                                   }
                                               }
                                           });
            return result;
        }
Beispiel #13
0
 public LSL_List llGetParcelPrimOwners(LSL_Vector pos)
 {
     ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
     
     LandObject land = (LandObject)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
     LSL_List ret = new LSL_List();
     if (land != null)
     {
         foreach (KeyValuePair<UUID, int> detectedParams in land.GetLandObjectOwners())
         {
             ret.Add(detectedParams.Key.ToString());
             ret.Add(detectedParams.Value);
         }
     }
     ScriptSleep(2000);
     return ret;
 }
Beispiel #14
0
 /// <summary>
 /// Like osGetAgents but returns enough info for a radar
 /// </summary>
 /// <returns>Strided list of the UUID, position and name of each avatar in the region</returns>
 public LSL_List osGetAvatarList()
 {
     ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osGetAvatarList", m_host, "OSSL");
     
     LSL_List result = new LSL_List();
     World.ForEachScenePresence(delegate (ScenePresence avatar)
     {
         if (avatar != null && avatar.UUID != m_host.OwnerID)
         {
             if (!avatar.IsChildAgent)
             {
                 result.Add(avatar.UUID);
                 result.Add(avatar.AbsolutePosition);
                 result.Add(avatar.Name);
             }
         }
     });
     return result;
 }
Beispiel #15
0
 private object ParseJsonNode(OSD node)
 {
     if (node.Type == OSDType.Integer)
         return new LSL_Integer(node.AsInteger());
     if (node.Type == OSDType.Boolean)
         return new LSL_Integer(node.AsBoolean() ? 1 : 0);
     if (node.Type == OSDType.Real)
         return new LSL_Float(node.AsReal());
     if (node.Type == OSDType.UUID || node.Type == OSDType.String)
         return new LSL_String(node.AsString());
     if (node.Type == OSDType.Array)
     {
         LSL_List resp = new LSL_List();
         OSDArray ar = node as OSDArray;
         foreach (OSD o in ar)
             resp.Add(ParseJsonNode(o));
         return resp;
     }
     if (node.Type == OSDType.Map)
     {
         LSL_List resp = new LSL_List();
         OSDMap ar = node as OSDMap;
         foreach (KeyValuePair<string, OSD> o in ar)
         {
             resp.Add(new LSL_String(o.Key));
             resp.Add(ParseJsonNode(o.Value));
         }
         return resp;
     }
     throw new Exception(ScriptBaseClass.JSON_INVALID);
 }
Beispiel #16
0
        public LSL_List llGetParcelDetails(LSL_Vector pos, LSL_List param)
        {
            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");

            IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
            LSL_List ret = new LSL_List();
            if (parcelManagement != null)
            {
                LandData land = parcelManagement.GetLandObject((float)pos.x, (float)pos.y).LandData;
                if (land == null)
                {
                    return new LSL_List(0);
                }
                foreach (object o in param.Data)
                {
                    switch (o.ToString())
                    {
                        case "0":
                            ret.Add (new LSL_String (land.Name));
                            break;
                        case "1":
                            ret.Add (new LSL_String (land.Description));
                            break;
                        case "2":
                            ret.Add (new LSL_Key (land.OwnerID.ToString ()));
                            break;
                        case "3":
                            ret.Add (new LSL_Key (land.GroupID.ToString ()));
                            break;
                        case "4":
                            ret.Add(new LSL_Integer(land.Area));
                            break;
                        case "5":
                            //Returning the InfoUUID so that we can use this for landmarks outside of this region
                            // http://wiki.secondlife.com/wiki/PARCEL_DETAILS_ID
                            ret.Add (new LSL_Key (land.InfoUUID.ToString ()));
                            break;
                        default:
                            ret.Add (new LSL_Integer (0));
                            break;
                    }
                }
            }
            return ret;
        }
Beispiel #17
0
 /// <summary>
  /// Return information regarding various simulator statistics (sim fps, physics fps, time
  /// dilation, total number of prims, total number of active scripts, script lps, various
  /// timing data, packets in/out, etc. Basically much the information that's shown in the
  /// client's Statistics Bar (Ctrl-Shift-1)
  /// </summary>
  /// <returns>List of floats</returns>
  public LSL_List osGetRegionStats()
  {
      ScriptProtection.CheckThreatLevel(ThreatLevel.Moderate, "osGetRegionStats", m_host, "OSSL");
      
      LSL_List ret = new LSL_List();
      float[] stats = World.SimulatorStats;
      
      for (int i = 0; i < 21; i++)
      {
          ret.Add(new LSL_Float(stats[i]));
      }
      return ret;
  }
Beispiel #18
0
        public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
        {
            Vector3 dir = new Vector3((float)(end-start).x, (float)(end-start).y, (float)(end-start).z);
            Vector3 startvector = new Vector3((float)start.x, (float)start.y, (float)start.z);
            Vector3 endvector = new Vector3((float)end.x, (float)end.y, (float)end.z);


            int count = 0;
            int detectPhantom = 0;
            int dataFlags = 0;
            int rejectTypes = 0;

            for (int i = 0; i < options.Length; i += 2)
            {
                if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
                {
                    count = options.GetLSLIntegerItem(i + 1);
                }
                else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
                {
                    detectPhantom = options.GetLSLIntegerItem(i + 1);
                }
                else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
                {
                    dataFlags = options.GetLSLIntegerItem(i + 1);
                }
                else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
                {
                    rejectTypes = options.GetLSLIntegerItem(i + 1);
                }
            }

            LSL_List list = new LSL_List();
            List<ContactResult> results = World.PhysicsScene.RaycastWorld(startvector, dir, dir.Length(), count);

            double distance = Util.GetDistanceTo(startvector, endvector);
            if (distance == 0)
                distance = 0.001;
            Vector3 posToCheck = startvector;
            ITerrainChannel channel = World.RequestModuleInterface<ITerrainChannel>();
            List<IScenePresence> presences = new List<IScenePresence>(World.Entities.GetPresences(startvector, (float)distance));
            bool checkTerrain = !((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND);
            bool checkAgents = !((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) == ScriptBaseClass.RC_REJECT_AGENTS);
            bool checkNonPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) == ScriptBaseClass.RC_REJECT_NONPHYSICAL);
            bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL);
            for (float i = 0; i <= distance; i += 0.1f)
            {
                posToCheck = startvector  + (dir * (i / (float)distance));
                if (checkTerrain && channel[(int)(posToCheck.X + startvector.X), (int)(posToCheck.Y + startvector.Y)] < posToCheck.Z)
                {
                    ContactResult result = new ContactResult();
                    result.ConsumerID = 0;
                    result.Depth = 0;
                    result.Normal = Vector3.Zero;
                    result.Pos = posToCheck;
                    results.Add(result);
                    checkTerrain = false;
                }
                if (checkAgents)
                {
                    for (int presenceCount = 0; presenceCount < presences.Count; presenceCount++)
                    {
                        IScenePresence sp = presences[presenceCount];
                        if (sp.AbsolutePosition.ApproxEquals (posToCheck, sp.PhysicsActor.Size.X))
                        {
                            ContactResult result = new ContactResult ();
                            result.ConsumerID = sp.LocalId;
                            result.Depth = 0;
                            result.Normal = Vector3.Zero;
                            result.Pos = posToCheck;
                            results.Add (result);
                            presences.RemoveAt (presenceCount);
                            if (presenceCount > 0)
                                presenceCount--; //Reset its position since we removed this one
                        }
                    }
                }
            }
            int refcount = 0;
            foreach (ContactResult result in results)
            {
                if ((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND &&
                    result.ConsumerID == 0)
                    continue;

                IEntity entity = World.GetSceneObjectPart(result.ConsumerID);
                if (entity == null && (rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) != ScriptBaseClass.RC_REJECT_AGENTS)
                    entity = World.GetScenePresence(result.ConsumerID); //Only check if we should be looking for agents
                if (entity == null)
                {
                    list.Add(UUID.Zero);
                    if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
                        list.Add(0);
                    list.Add(result.Pos);
                    if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
                        list.Add(result.Normal);
                    continue; //Can't find it, so add UUID.Zero
                }

                /*if (detectPhantom == 0 && intersection.obj is ISceneChildEntity &&
                    ((ISceneChildEntity)intersection.obj).PhysActor == null)
                    continue;*/ //Can't do this ATM, physics engine knows only of non phantom objects

                if (entity is ISceneChildEntity && ((ISceneChildEntity)entity).PhysActor != null && ((ISceneChildEntity)entity).PhysActor.IsPhysical)
                {
                    if (!checkPhysical)
                        continue;
                }
                else if (entity is ISceneChildEntity)
                    if (!checkNonPhysical)
                        continue;

                refcount++;
                if ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) == ScriptBaseClass.RC_GET_ROOT_KEY && entity is ISceneChildEntity)
                    list.Add(((ISceneChildEntity)entity).ParentEntity.UUID);
                else
                    list.Add(entity.UUID);

                if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
                    if (entity is ISceneChildEntity)
                        list.Add(((ISceneChildEntity)entity).LinkNum);
                    else
                        list.Add(0);

                list.Add(result.Pos);
                if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
                    list.Add(result.Normal);
            }

            list.Add (refcount); //The status code, either the # of contacts, RCERR_SIM_PERF_LOW, or RCERR_CAST_TIME_EXCEEDED

            return list;
        }
Beispiel #19
0
        public LSL_List llGetObjectDetails(string id, LSL_List args)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID))
                return new LSL_List();

            LSL_List ret = new LSL_List();
            UUID key = new UUID();
            if (UUID.TryParse(id, out key))
            {
                IScenePresence av = World.GetScenePresence(key);

                if (av != null)
                {
                    foreach (object o in args.Data)
                    {
                        if ((LSL_Integer) o == ScriptBaseClass.OBJECT_NAME)
                        {
                            ret.Add(new LSL_String(av.Name));
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_DESC)
                        {
                            ret.Add(new LSL_String(""));
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_POS)
                        {
                            Vector3 tmp = av.AbsolutePosition;
                            ret.Add(new LSL_Vector(tmp.X, tmp.Y, tmp.Z));
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_ROT)
                        {
                            Quaternion rtmp = av.Rotation;
                            ret.Add(new LSL_Rotation(rtmp.X, rtmp.Y, rtmp.Z, rtmp.W));
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_VELOCITY)
                        {
                            Vector3 tmp = av.Velocity;
                            ret.Add(new LSL_Vector(tmp.X, tmp.Y, tmp.Z));
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_OWNER)
                        {
                            ret.Add(id);
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_GROUP)
                        {
                            ret.Add(UUID.Zero.ToString());
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_CREATOR)
                        {
                            ret.Add(UUID.Zero.ToString());
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT)
                        {
                            IScriptModule[] modules = World.RequestModuleInterfaces<IScriptModule>();
                            int activeScripts = modules.Sum(mod => mod.GetActiveScripts(av));
                            ret.Add(activeScripts);
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT)
                        {
                            IScriptModule[] modules = World.RequestModuleInterfaces<IScriptModule>();
                            int totalScripts = modules.Sum(mod => mod.GetTotalScripts(av));
                            ret.Add(totalScripts);
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_SCRIPT_MEMORY)
                        {
                            ret.Add(0);
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_SCRIPT_TIME)
                        {
                            IScriptModule[] modules = World.RequestModuleInterfaces<IScriptModule>();
                            int scriptTime = modules.Sum(mod => mod.GetScriptTime(m_itemID));
                            ret.Add(scriptTime);
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE)
                        {
                            ret.Add(0);
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_SERVER_COST)
                        {
                            ret.Add(0);
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_STREAMING_COST)
                        {
                            ret.Add(0);
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_PHYSICS_COST)
                        {
                            ret.Add(0);
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_CHARACTER_TIME)
                        {
                            ret.Add(0);
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_ROOT)
                        {
                            ret.Add(av.Sitting ? av.SittingOnUUID : av.UUID);
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_ATTACHED_POINT)
                        {
                            ret.Add(0);
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_PATHFINDING_TYPE)
                        {
                            ret.Add(0);
                        }
                        else
                        {
                            ret.Add(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL);
                        }
                    }
                    return ret;
                }
                ISceneChildEntity obj = World.GetSceneObjectPart(key);
                if (obj != null)
                {
                    foreach (object o in args.Data)
                    {
                        if ((LSL_Integer) o == ScriptBaseClass.OBJECT_NAME)
                        {
                            ret.Add(new LSL_String(obj.Name));
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_DESC)
                        {
                            ret.Add(new LSL_String(obj.Description));
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_POS)
                        {
                            Vector3 tmp = obj.AbsolutePosition;
                            ret.Add(new LSL_Vector(tmp.X, tmp.Y, tmp.Z));
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_ROT)
                        {
                            Quaternion rtmp = obj.GetRotationOffset();
                            ret.Add(new LSL_Rotation(rtmp.X, rtmp.Y, rtmp.Z, rtmp.W));
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_VELOCITY)
                        {
                            Vector3 tmp = obj.Velocity;
                            ret.Add(new LSL_Vector(tmp.X, tmp.Y, tmp.Z));
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_OWNER)
                        {
                            ret.Add(new LSL_Key(obj.OwnerID.ToString()));
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_GROUP)
                        {
                            ret.Add(new LSL_Key(obj.GroupID.ToString()));
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_CREATOR)
                        {
                            ret.Add(new LSL_Key(obj.CreatorID.ToString()));
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT)
                        {
                            IScriptModule[] modules = World.RequestModuleInterfaces<IScriptModule>();
                            int activeScripts = modules.Sum(mod => mod.GetActiveScripts(obj));
                            ret.Add(new LSL_Integer(activeScripts));
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT)
                        {
                            IScriptModule[] modules = World.RequestModuleInterfaces<IScriptModule>();
                            int totalScripts = modules.Sum(mod => mod.GetTotalScripts(obj));
                            ret.Add(new LSL_Integer(totalScripts));
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_SCRIPT_MEMORY)
                        {
                            ret.Add(new LSL_Integer(0));
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_CHARACTER_TIME)
                        {
                            ret.Add(0);
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_ROOT)
                        {
                            ret.Add(obj.ParentEntity.RootChild.UUID);
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_ATTACHED_POINT)
                        {
                            ret.Add(obj.ParentEntity.RootChild.AttachmentPoint);
                        }
                        else if ((LSL_Integer) o == ScriptBaseClass.OBJECT_PATHFINDING_TYPE)
                        {
                            ret.Add(0);
                        }
                        else
                        {
                            ret.Add(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL);
                        }
                    }
                    return ret;
                }
            }
            return new LSL_List();
        }
Beispiel #20
0
 public LSL_List llParcelMediaQuery(LSL_List aList)
 {
     ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
     
     LSL_List list = new LSL_List();
     for (int i = 0; i < aList.Data.Length; i++)
     {
         if (aList.Data[i] != null)
         {
             IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
             if (parcelManagement != null)
             {
                 LSL_Integer tmp = (LSL_Integer)aList.Data[i];
                 switch ((ParcelMediaCommandEnum)tmp.value)
                 {
                     case ParcelMediaCommandEnum.Url:
                         list.Add(new LSL_String(parcelManagement.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).LandData.MediaURL));
                         break;
                     case ParcelMediaCommandEnum.Desc:
                         list.Add(new LSL_String(parcelManagement.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).LandData.MediaDescription));
                         break;
                     case ParcelMediaCommandEnum.Texture:
                         list.Add(new LSL_String(parcelManagement.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).LandData.MediaID.ToString()));
                         break;
                     case ParcelMediaCommandEnum.Type:
                         list.Add(new LSL_String(parcelManagement.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).LandData.MediaType));
                         break;
                     case ParcelMediaCommandEnum.Loop:
                         list.Add(new LSL_Integer(parcelManagement.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).LandData.MediaLoop ? 1 : 0));
                         break;
                     case ParcelMediaCommandEnum.LoopSet:
                         list.Add(new LSL_Integer(parcelManagement.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).LandData.MediaLoopSet));
                         break;
                     case ParcelMediaCommandEnum.Size:
                         list.Add(new LSL_String(parcelManagement.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).LandData.MediaHeight));
                         list.Add(new LSL_String(parcelManagement.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).LandData.MediaWidth));
                         break;
                     default:
                         ParcelMediaCommandEnum mediaCommandEnum = ParcelMediaCommandEnum.Url;
                         NotImplemented("llParcelMediaQuery parameter do not supported yet: " + Enum.Parse(mediaCommandEnum.GetType(), aList.Data[i].ToString()).ToString());
                         break;
                 }
             }
         }
     }
     ScriptSleep(2000);
     return list;
 }
Beispiel #21
0
        public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID))
                return new LSL_List();

            LSL_List list = new LSL_List();

            Vector3 rayStart = start.ToVector3();
            Vector3 rayEnd = end.ToVector3();
            Vector3 dir = rayEnd - rayStart;

            float dist = Vector3.Mag(dir);

            int count = 1;
            bool detectPhantom = false;
            int dataFlags = 0;
            int rejectTypes = 0;

            for (int i = 0; i < options.Length; i += 2)
            {
                if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
                    count = options.GetLSLIntegerItem(i + 1);
                else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
                    detectPhantom = (options.GetLSLIntegerItem(i + 1) > 0);
                else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
                    dataFlags = options.GetLSLIntegerItem(i + 1);
                else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
                    rejectTypes = options.GetLSLIntegerItem(i + 1);
            }

            if (count > 16)
                count = 16;

            List<ContactResult> results = new List<ContactResult>();

            bool checkTerrain = !((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND);
            bool checkAgents = !((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) == ScriptBaseClass.RC_REJECT_AGENTS);
            bool checkNonPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) == ScriptBaseClass.RC_REJECT_NONPHYSICAL);
            bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL);


            if (checkAgents)
            {
                ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd);
                foreach (ContactResult r in agentHits)
                    results.Add(r);
            }

            if (checkPhysical || checkNonPhysical || detectPhantom)
            {
                ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, checkPhysical, checkNonPhysical, detectPhantom);
                for (int iter = 0; iter < objectHits.Length; iter++)
                {
                    // Redistance the Depth because the Scene RayCaster returns distance from center to make the rezzing code simpler.
                    objectHits[iter].Depth = Vector3.Distance(objectHits[iter].Pos, rayStart);
                    results.Add(objectHits[iter]);
                }
            }

            if (checkTerrain)
            {
                ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
                if (groundContact != null)
                    results.Add((ContactResult)groundContact);
            }

            results.Sort(delegate(ContactResult a, ContactResult b)
            {
                return a.Depth.CompareTo(b.Depth);
            });

            int values = 0;
            ISceneEntity thisgrp = m_host.ParentEntity;

            foreach (ContactResult result in results)
            {
                if (result.Depth > dist)
                    continue;

                // physics ray can return colisions with host prim
                if (m_host.LocalId == result.ConsumerID)
                    continue;

                UUID itemID = UUID.Zero;
                int linkNum = 0;

                ISceneChildEntity part = World.GetSceneObjectPart(result.ConsumerID);
                // It's a prim!
                if (part != null)
                {
                    // dont detect members of same object ???
                    if (part.ParentEntity == thisgrp)
                        continue;

                    if ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) == ScriptBaseClass.RC_GET_ROOT_KEY)
                        itemID = part.ParentEntity.UUID;
                    else
                        itemID = part.UUID;

                    linkNum = part.LinkNum;
                }
                else
                {
                    IScenePresence sp = World.GetScenePresence(result.ConsumerID);
                    /// It it a boy? a girl?
                    if (sp != null)
                        itemID = sp.UUID;
                }

                list.Add(new LSL_String(itemID.ToString()));
                list.Add(new LSL_String(result.Pos.ToString()));

                if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
                    list.Add(new LSL_Integer(linkNum));

                if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
                    list.Add(new LSL_Vector(result.Normal));

                values++;
                if (values >= count)
                    break;
            }

            list.Add(new LSL_Integer(values));

            return list;
        }
Beispiel #22
0
 public LSL_List llGetParcelPrimOwners(LSL_Vector pos)
 {
     ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
     
     IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
     LSL_List ret = new LSL_List();
     if (parcelManagement != null)
     {
         ILandObject land = parcelManagement.GetLandObject((float)pos.x, (float)pos.y);
         if (land != null)
         {
             IPrimCountModule primCountModule = World.RequestModuleInterface<IPrimCountModule>();
             if (primCountModule != null)
             {
                 IPrimCounts primCounts = primCountModule.GetPrimCounts(land.LandData.GlobalID);
                 foreach (KeyValuePair<UUID, int> detectedParams in primCounts.GetAllUserCounts())
                 {
                     ret.Add(detectedParams.Key.ToString());
                     ret.Add(detectedParams.Value);
                 }
             }
         }
     }
     ScriptSleep(2000);
     return (LSL_List) ret;
 }
Beispiel #23
0
        /// <summary>
        ///     http://wiki.secondlife.com/wiki/LlGetAgentList
        ///     The list of options is currently not used in SL
        ///     scope is one of:-
        ///     AGENT_LIST_REGION - all in the region
        ///     AGENT_LIST_PARCEL - all in the same parcel as the scripted object
        ///     AGENT_LIST_PARCEL_OWNER - all in any parcel owned by the owner of the
        ///     current parcel.
        /// </summary>
        public LSL_List llGetAgentList(LSL_Integer scope, LSL_List options)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID))
                return new LSL_List();

            // the constants are 1, 2 and 4 so bits are being set, but you
            // get an error "INVALID_SCOPE" if it is anything but 1, 2 and 4
            bool regionWide = scope == ScriptBaseClass.AGENT_LIST_REGION;
            bool parcelOwned = scope == ScriptBaseClass.AGENT_LIST_PARCEL_OWNER;
            bool parcel = scope == ScriptBaseClass.AGENT_LIST_PARCEL;
            LSL_List result = new LSL_List();

            if (!regionWide && !parcelOwned && !parcel)
            {
                result.Add("INVALID_SCOPE");
                return result;
            }

            Vector3 pos;
            UUID id = UUID.Zero;

            if (parcel || parcelOwned)
            {
                pos = m_host.GetWorldPosition();
                IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
                ILandObject land = parcelManagement.GetLandObject(pos.X, pos.Y);
                if (land == null)
                {
                    id = UUID.Zero;
                }
                else
                {
                    if (parcelOwned)
                    {
                        id = land.LandData.OwnerID;
                    }
                    else
                    {
                        id = land.LandData.GlobalID;
                    }
                }
            }

            World.ForEachScenePresence(delegate(IScenePresence ssp)
                                           {
                                               // Gods are not listed in SL

                                               if (!ssp.IsDeleted && ssp.GodLevel == 0.0 && !ssp.IsChildAgent)
                                               {
                                                   if (!regionWide)
                                                   {
                                                       pos = ssp.AbsolutePosition;
                                                       IParcelManagementModule parcelManagement =
                                                           World.RequestModuleInterface<IParcelManagementModule>();
                                                       ILandObject land = parcelManagement.GetLandObject(pos.X, pos.Y);
                                                       if (land != null)
                                                       {
                                                           if (parcelOwned && land.LandData.OwnerID == id ||
                                                               parcel && land.LandData.GlobalID == id)
                                                           {
                                                               result.Add(ssp.UUID.ToString());
                                                           }
                                                       }
                                                   }
                                                   else
                                                   {
                                                       result.Add(ssp.UUID.ToString());
                                                   }
                                               }

                                               // Maximum of 100 results
                                               if (result.Length > 99)
                                               {
                                                   return;
                                               }
                                           });
            return result;
        }
Beispiel #24
0
        /// <summary>
        /// The supplied string is scanned for commas
        /// and converted into a list. Commas are only
        /// effective if they are encountered outside
        /// of '<' '>' delimiters. Any whitespace
        /// before or after an element is trimmed.
        /// </summary>

        public LSL_List llCSV2List(string src)
        {

            LSL_List result = new LSL_List();
            int parens = 0;
            int start  = 0;
            int length = 0;

            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
            

            for (int i = 0; i < src.Length; i++)
            {
                switch (src[i])
                {
                    case '<':
                        parens++;
                        length++;
                        break;
                    case '>':
                        if (parens > 0)
                            parens--;
                        length++;
                        break;
                    case ',':
                        if (parens == 0)
                        {
                            result.Add(new LSL_String(src.Substring(start,length).Trim()));
                            start += length+1;
                            length = 0;
                        }
                        else
                        {
                            length++;
                        }
                        break;
                    default:
                        length++;
                        break;
                }
            }

            result.Add(src.Substring(start,length).Trim());

            return result;
        }
Beispiel #25
0
        public LSL_List GetLinkPrimitiveParams(ISceneChildEntity part, LSL_List rules)
        {
            LSL_List res = new LSL_List();
            int idx = 0;
            while (idx < rules.Length)
            {
                int code = rules.GetLSLIntegerItem(idx++);
                int remain = rules.Length - idx;
                Primitive.TextureEntry tex = part.Shape.Textures;
                int face = 0;

                if (code == (int) ScriptBaseClass.PRIM_NAME)
                {
                    res.Add(new LSL_String(part.Name));
                }

                else if (code == (int) ScriptBaseClass.PRIM_DESC)
                {
                    res.Add(new LSL_String(part.Description));
                }

                else if (code == (int) ScriptBaseClass.PRIM_MATERIAL)
                {
                    res.Add(new LSL_Integer(part.Material));
                }

                else if (code == (int) ScriptBaseClass.PRIM_PHYSICS)
                {
                    res.Add((part.GetEffectiveObjectFlags() & (uint) PrimFlags.Physics) != 0
                                ? new LSL_Integer(1)
                                : new LSL_Integer(0));
                }

                else if (code == (int) ScriptBaseClass.PRIM_TEMP_ON_REZ)
                {
                    res.Add((part.GetEffectiveObjectFlags() & (uint) PrimFlags.TemporaryOnRez) != 0
                                ? new LSL_Integer(1)
                                : new LSL_Integer(0));
                }

                else if (code == (int) ScriptBaseClass.PRIM_PHANTOM)
                {
                    res.Add((part.GetEffectiveObjectFlags() & (uint) PrimFlags.Phantom) != 0
                                ? new LSL_Integer(1)
                                : new LSL_Integer(0));
                }

                else if (code == (int) ScriptBaseClass.PRIM_POSITION)
                {
                    Vector3 tmp = part.AbsolutePosition;
                    LSL_Vector v = new LSL_Vector(tmp.X,
                                                  tmp.Y,
                                                  tmp.Z);
                    // For some reason, the part.AbsolutePosition.* values do not change if the
                    // linkset is rotated; they always reflect the child prim's world position
                    // as though the linkset is unrotated. This is incompatible behavior with SL's
                    // implementation, so will break scripts imported from there (not to mention it
                    // makes it more difficult to determine a child prim's actual inworld position).
                    if (part.ParentID != 0)
                    {
                        LSL_Rotation rtmp = llGetRootRotation();
                        LSL_Vector rpos = llGetRootPosition();
                        v = ((v - rpos)*rtmp) + rpos;
                    }
                    res.Add(v);
                }
                else if (code == (int) ScriptBaseClass.PRIM_POS_LOCAL)
                {
                    res.Add(GetLocalPos(part));
                }
                else if (code == (int) ScriptBaseClass.PRIM_SIZE)
                {
                    Vector3 tmp = part.Scale;
                    res.Add(new LSL_Vector(tmp.X,
                                           tmp.Y,
                                           tmp.Z));
                }

                else if (code == (int) ScriptBaseClass.PRIM_ROTATION)
                {
                    res.Add(GetPartRot(part));
                }

                else if (code == (int) ScriptBaseClass.PRIM_TYPE)
                {
                    // implementing box
                    PrimitiveBaseShape Shape = part.Shape;
                    int primType = (int) part.GetPrimType();
                    res.Add(new LSL_Integer(primType));
                    double topshearx = (sbyte) Shape.PathShearX/100.0; // Fix negative values for PathShearX
                    double topsheary = (sbyte) Shape.PathShearY/100.0; // and PathShearY.
                    if (primType == ScriptBaseClass.PRIM_TYPE_BOX ||
                        primType == ScriptBaseClass.PRIM_TYPE_CYLINDER ||
                        primType == ScriptBaseClass.PRIM_TYPE_PRISM)
                    {
                        res.Add(new LSL_Integer(Shape.ProfileCurve));
                        res.Add(new LSL_Vector(Shape.ProfileBegin/50000.0, 1 - Shape.ProfileEnd/50000.0, 0));
                        res.Add(new LSL_Float(Shape.ProfileHollow/50000.0));
                        res.Add(new LSL_Vector(Shape.PathTwistBegin/100.0, Shape.PathTwist/100.0, 0));
                        res.Add(new LSL_Vector(1 - (Shape.PathScaleX/100.0 - 1), 1 - (Shape.PathScaleY/100.0 - 1), 0));
                        res.Add(new LSL_Vector(topshearx, topsheary, 0));
                    }

                    if (primType == ScriptBaseClass.PRIM_TYPE_SPHERE)
                    {
                        res.Add(new LSL_Integer(Shape.ProfileCurve));
                        res.Add(new LSL_Vector(Shape.PathBegin/50000.0, 1 - Shape.PathEnd/50000.0, 0));
                        res.Add(new LSL_Float(Shape.ProfileHollow/50000.0));
                        res.Add(new LSL_Vector(Shape.PathTwistBegin/100.0, Shape.PathTwist/100.0, 0));
                        res.Add(new LSL_Vector(Shape.ProfileBegin/50000.0, 1 - Shape.ProfileEnd/50000.0, 0));
                    }

                    if (primType == ScriptBaseClass.PRIM_TYPE_SCULPT)
                    {
                        res.Add(Shape.SculptTexture.ToString());
                        res.Add(new LSL_Integer(Shape.SculptType));
                    }
                    if (primType == ScriptBaseClass.PRIM_TYPE_RING ||
                        primType == ScriptBaseClass.PRIM_TYPE_TUBE ||
                        primType == ScriptBaseClass.PRIM_TYPE_TORUS)
                    {
                        // holeshape
                        res.Add(new LSL_Integer(Shape.ProfileCurve));

                        // cut
                        res.Add(new LSL_Vector(Shape.PathBegin/50000.0, 1 - Shape.PathEnd/50000.0, 0));

                        // hollow
                        res.Add(new LSL_Float(Shape.ProfileHollow/50000.0));

                        // twist
                        res.Add(new LSL_Vector(Shape.PathTwistBegin/100.0, Shape.PathTwist/100.0, 0));

                        // vector holesize
                        res.Add(new LSL_Vector(1 - (Shape.PathScaleX/100.0 - 1), 1 - (Shape.PathScaleY/100.0 - 1), 0));

                        // vector topshear
                        res.Add(new LSL_Vector(topshearx, topsheary, 0));

                        // vector profilecut
                        res.Add(new LSL_Vector(Shape.ProfileBegin/50000.0, 1 - Shape.ProfileEnd/50000.0, 0));

                        // vector tapera
                        res.Add(new LSL_Vector(Shape.PathTaperX/100.0, Shape.PathTaperY/100.0, 0));

                        // float revolutions
                        res.Add(
                            new LSL_Float(Math.Round(Shape.PathRevolutions*0.015d, 2, MidpointRounding.AwayFromZero)) +
                            1.0d);
                        // Slightly inaccurate, because an unsigned byte is being used to represent
                        // the entire range of floating-point values from 1.0 through 4.0 (which is how
                        // SL does it).
                        //
                        // Using these formulas to store and retrieve PathRevolutions, it is not
                        // possible to use all values between 1.00 and 4.00. For instance, you can't
                        // represent 1.10. You can represent 1.09 and 1.11, but not 1.10. So, if you
                        // use llSetPrimitiveParams to set revolutions to 1.10 and then retreive them
                        // with llGetPrimitiveParams, you'll retrieve 1.09. You can also see a similar
                        // behavior in the viewer as you cannot set 1.10. The viewer jumps to 1.11.
                        // In SL, llSetPrimitveParams and llGetPrimitiveParams can set and get a value
                        // such as 1.10. So, SL must store and retreive the actual user input rather
                        // than only storing the encoded value.

                        // float radiusoffset
                        res.Add(new LSL_Float(Shape.PathRadiusOffset/100.0));

                        // float skew
                        res.Add(new LSL_Float(Shape.PathSkew/100.0));
                    }
                }

                else if (code == (int) ScriptBaseClass.PRIM_TEXTURE)
                {
                    if (remain < 1)
                        return res;
                    face = rules.GetLSLIntegerItem(idx++);
                    if (face == ScriptBaseClass.ALL_SIDES)
                    {
                        for (face = 0; face < GetNumberOfSides(part); face++)
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint) face);

                            res.Add(new LSL_String(texface.TextureID.ToString()));
                            res.Add(new LSL_Vector(texface.RepeatU,
                                                   texface.RepeatV,
                                                   0));
                            res.Add(new LSL_Vector(texface.OffsetU,
                                                   texface.OffsetV,
                                                   0));
                            res.Add(new LSL_Float(texface.Rotation));
                        }
                    }
                    else
                    {
                        if (face >= 0 && face < GetNumberOfSides(part))
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint) face);

                            res.Add(new LSL_String(texface.TextureID.ToString()));
                            res.Add(new LSL_Vector(texface.RepeatU,
                                                   texface.RepeatV,
                                                   0));
                            res.Add(new LSL_Vector(texface.OffsetU,
                                                   texface.OffsetV,
                                                   0));
                            res.Add(new LSL_Float(texface.Rotation));
                        }
                    }
                }

                else if (code == (int) ScriptBaseClass.PRIM_COLOR)
                {
                    if (remain < 1)
                        return res;
                    face = rules.GetLSLIntegerItem(idx++);
                    tex = part.Shape.Textures;
                    Color4 texcolor;
                    if (face == ScriptBaseClass.ALL_SIDES)
                    {
                        for (face = 0; face < GetNumberOfSides(part); face++)
                        {
                            texcolor = tex.GetFace((uint) face).RGBA;
                            res.Add(new LSL_Vector(texcolor.R,
                                                   texcolor.G,
                                                   texcolor.B));
                            res.Add(new LSL_Float(texcolor.A));
                        }
                    }
                    else
                    {
                        texcolor = tex.GetFace((uint) face).RGBA;
                        res.Add(new LSL_Vector(texcolor.R,
                                               texcolor.G,
                                               texcolor.B));
                        res.Add(new LSL_Float(texcolor.A));
                    }
                }

                else if (code == (int) ScriptBaseClass.PRIM_BUMP_SHINY)
                {
                    if (remain < 1)
                        return res;

                    face = rules.GetLSLIntegerItem(idx++);

                    if (face == ScriptBaseClass.ALL_SIDES)
                    {
                        for (face = 0; face < GetNumberOfSides(part); face++)
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint) face);
                            // Convert Shininess to PRIM_SHINY_*
                            res.Add(new LSL_Integer((uint) texface.Shiny >> 6));
                            // PRIM_BUMP_*
                            res.Add(new LSL_Integer((int) texface.Bump));
                        }
                    }
                    else
                    {
                        if (face >= 0 && face < GetNumberOfSides(part))
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint) face);
                            // Convert Shininess to PRIM_SHINY_*
                            res.Add(new LSL_Integer((uint) texface.Shiny >> 6));
                            // PRIM_BUMP_*
                            res.Add(new LSL_Integer((int) texface.Bump));
                        }
                    }
                }

                else if (code == (int) ScriptBaseClass.PRIM_FULLBRIGHT)
                {
                    if (remain < 1)
                        return res;

                    face = rules.GetLSLIntegerItem(idx++);
                    tex = part.Shape.Textures;
                    if (face == ScriptBaseClass.ALL_SIDES)
                    {
                        for (face = 0; face < GetNumberOfSides(part); face++)
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint) face);
                            res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
                        }
                    }
                    else
                    {
                        if (face >= 0 && face < GetNumberOfSides(part))
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint) face);
                            res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
                        }
                    }
                }

                else if (code == (int) ScriptBaseClass.PRIM_FLEXIBLE)
                {
                    PrimitiveBaseShape shape = part.Shape;

                    res.Add(shape.FlexiEntry ? new LSL_Integer(1) : new LSL_Integer(0));
                    res.Add(new LSL_Integer(shape.FlexiSoftness)); // softness
                    res.Add(new LSL_Float(shape.FlexiGravity)); // gravity
                    res.Add(new LSL_Float(shape.FlexiDrag)); // friction
                    res.Add(new LSL_Float(shape.FlexiWind)); // wind
                    res.Add(new LSL_Float(shape.FlexiTension)); // tension
                    res.Add(new LSL_Vector(shape.FlexiForceX, // force
                                           shape.FlexiForceY,
                                           shape.FlexiForceZ));
                }

                else if (code == (int) ScriptBaseClass.PRIM_TEXGEN)
                {
                    if (remain < 1)
                        return res;

                    face = rules.GetLSLIntegerItem(idx++);
                    if (face == ScriptBaseClass.ALL_SIDES)
                    {
                        for (face = 0; face < GetNumberOfSides(part); face++)
                        {
                            MappingType texgen = tex.GetFace((uint) face).TexMapType;
                            // Convert MappingType to PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR etc.
                            res.Add(new LSL_Integer((uint) texgen >> 1));
                        }
                    }
                    else
                    {
                        if (face >= 0 && face < GetNumberOfSides(part))
                        {
                            MappingType texgen = tex.GetFace((uint) face).TexMapType;
                            res.Add(new LSL_Integer((uint) texgen >> 1));
                        }
                    }
                }

                else if (code == (int) ScriptBaseClass.PRIM_POINT_LIGHT)
                {
                    PrimitiveBaseShape shape = part.Shape;

                    res.Add(shape.LightEntry ? new LSL_Integer(1) : new LSL_Integer(0));
                    res.Add(new LSL_Vector(shape.LightColorR, // color
                                           shape.LightColorG,
                                           shape.LightColorB));
                    res.Add(new LSL_Float(shape.LightIntensity)); // intensity
                    res.Add(new LSL_Float(shape.LightRadius)); // radius
                    res.Add(new LSL_Float(shape.LightFalloff)); // falloff
                }

                else if (code == (int) ScriptBaseClass.PRIM_GLOW)
                {
                    if (remain < 1)
                        return res;

                    face = rules.GetLSLIntegerItem(idx++);
                    if (face == ScriptBaseClass.ALL_SIDES)
                    {
                        for (face = 0; face < GetNumberOfSides(part); face++)
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint) face);
                            res.Add(new LSL_Float(texface.Glow));
                        }
                    }
                    else
                    {
                        if (face >= 0 && face < GetNumberOfSides(part))
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint) face);
                            res.Add(new LSL_Float(texface.Glow));
                        }
                    }
                }

                else if (code == (int) ScriptBaseClass.PRIM_TEXT)
                {
                    Color4 textColor = part.GetTextColor();
                    res.Add(new LSL_String(part.Text));
                    res.Add(new LSL_Vector(textColor.R,
                                           textColor.G,
                                           textColor.B));
                    res.Add(new LSL_Float(textColor.A));
                }
                else if (code == (int) ScriptBaseClass.PRIM_ROT_LOCAL)
                {
                    Quaternion rtmp = part.GetRotationOffset();
                    res.Add(new LSL_Rotation(rtmp.X, rtmp.Y, rtmp.Z, rtmp.W));
                }
                else if (code == (int) ScriptBaseClass.PRIM_OMEGA)
                {
                    Vector3 axis = part.OmegaAxis;
                    LSL_Float spinRate = part.OmegaSpinRate;
                    LSL_Float gain = part.OmegaGain;
                    res.Add(axis);
                    res.Add(spinRate);
                    res.Add(gain);
                }
                else if (code == (int) ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE)
                {
                    res.Add(new LSL_Integer(part.PhysicsType));
                }
                else if (code == (int) ScriptBaseClass.PRIM_LINK_TARGET)
                {
                    if (remain < 1)
                        continue;
                    LSL_Integer nextLink = rules.GetLSLIntegerItem(idx++);
                    List<ISceneChildEntity> entities = GetLinkParts(nextLink);
                    if (entities.Count > 0)
                        part = entities[0];
                }
            }
            return res;
        }
Beispiel #26
0
        /// <summary>
        /// Elements in the source list starting with 0 and then
        /// every i+stride. If the stride is negative then the scan
        /// is backwards producing an inverted result.
        /// Only those elements that are also in the specified
        /// range are included in the result.
        /// </summary>

        public LSL_List llList2ListStrided(LSL_List src, int start, int end, int stride)
        {

            LSL_List result = new LSL_List();
            int[] si = new int[2];
            int[] ei = new int[2];
            bool twopass = false;

            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
            

            //  First step is always to deal with negative indices

            if (start < 0)
                start = src.Length+start;
            if (end   < 0)
                end   = src.Length+end;

            //  Out of bounds indices are OK, just trim them
            //  accordingly

            if (start > src.Length)
                start = src.Length;

            if (end > src.Length)
                end = src.Length;

            if (stride == 0)
                stride = 1;

            //  There may be one or two ranges to be considered

            if (start != end)
            {

                if (start <= end)
                {
                   si[0] = start;
                   ei[0] = end;
                }
                else
                {
                   si[1] = start;
                   ei[1] = src.Length;
                   si[0] = 0;
                   ei[0] = end;
                   twopass = true;
                }

                //  The scan always starts from the beginning of the
                //  source list, but members are only selected if they
                //  fall within the specified sub-range. The specified
                //  range values are inclusive.
                //  A negative stride reverses the direction of the
                //  scan producing an inverted list as a result.

                if (stride > 0)
                {
                    for (int i = 0; i < src.Length; i += stride)
                    {
                        if (i<=ei[0] && i>=si[0])
                            result.Add(src.Data[i]);
                        if (twopass && i>=si[1] && i<=ei[1])
                            result.Add(src.Data[i]);
                    }
                }
                else if (stride < 0)
                {
                    for (int i = src.Length - 1; i >= 0; i += stride)
                    {
                        if (i <= ei[0] && i >= si[0])
                            result.Add(src.Data[i]);
                        if (twopass && i >= si[1] && i <= ei[1])
                            result.Add(src.Data[i]);
                    }
                }
            }
            else
            {
                if (start%stride == 0)
                {
                    result.Add(src.Data[start]);
                }
            }

            return result;
        }
Beispiel #27
0
        public LSL_List llGetParcelDetails(LSL_Vector pos, LSL_List param)
        {
            if(!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID)) return new LSL_List();

            IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
            LSL_List ret = new LSL_List();
            if (parcelManagement != null)
            {
                LandData land = parcelManagement.GetLandObject((float)pos.x, (float)pos.y).LandData;
                if (land == null)
                {
                    return new LSL_List(0);
                }
                foreach (object o in param.Data)
                {
                    if((LSL_Integer)o == ScriptBaseClass.PARCEL_DETAILS_NAME)
                        ret.Add (new LSL_String (land.Name));
                    else if ((LSL_Integer)o == ScriptBaseClass.PARCEL_DETAILS_DESC)
                        ret.Add (new LSL_String (land.Description));
                    else if ((LSL_Integer)o == ScriptBaseClass.PARCEL_DETAILS_OWNER)
                        ret.Add (new LSL_Key (land.OwnerID.ToString ()));
                    else if ((LSL_Integer)o == ScriptBaseClass.PARCEL_DETAILS_GROUP)
                        ret.Add (new LSL_Key (land.GroupID.ToString ()));
                    else if ((LSL_Integer)o == ScriptBaseClass.PARCEL_DETAILS_AREA)
                        ret.Add(new LSL_Integer(land.Area));
                    else if ((LSL_Integer)o == ScriptBaseClass.PARCEL_DETAILS_ID)
                        //Returning the InfoUUID so that we can use this for landmarks outside of this region
                        // http://wiki.secondlife.com/wiki/PARCEL_DETAILS_ID
                        ret.Add (new LSL_Key (land.InfoUUID.ToString ()));
                    else if ((LSL_Integer)o == ScriptBaseClass.PARCEL_DETAILS_PRIVACY)
                        ret.Add (new LSL_Integer (land.Private ? 1 : 0));
                    else
                        ret.Add (new LSL_Integer (0));
                }
            }
            return ret;
        }
Beispiel #28
0
        /// <summary>
        /// A partial implementation.
        /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetBoundingBox
        /// So far only valid for standing/flying/ground sitting avatars and single prim objects.
        /// If the object has multiple prims and/or a sitting avatar then the bounding
        /// box is for the root prim only.
        /// </summary>
        public LSL_List llGetBoundingBox(string obj)
        {
            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
            
            UUID objID = UUID.Zero;
            LSL_List result = new LSL_List();
            if (!UUID.TryParse(obj, out objID))
            {
                result.Add(new LSL_Vector());
                result.Add(new LSL_Vector());
                return result;
            }
            ScenePresence presence = World.GetScenePresence(objID);
            if (presence != null)
            {
                if (presence.ParentID == UUID.Zero) // not sat on an object
                {
                    LSL_Vector lower;
                    LSL_Vector upper;
                    if (presence.Animator.Animations.DefaultAnimation.AnimID 
                        == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
                    {
                        // This is for ground sitting avatars
                        float height = presence.Appearance.AvatarHeight / 2.66666667f;
                        lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
                        upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
                    }
                    else
                    {
                        // This is for standing/flying avatars
                        float height = presence.Appearance.AvatarHeight / 2.0f;
                        lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
                        upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
                    }
                    result.Add(lower);
                    result.Add(upper);
                    return result;
                }
                else
                {
                    // sitting on an object so we need the bounding box of that
                    // which should include the avatar so set the UUID to the
                    // UUID of the object the avatar is sat on and allow it to fall through
                    // to processing an object
                    SceneObjectPart p = World.GetSceneObjectPart(presence.ParentID);
                    objID = p.UUID;
                }
            }
            SceneObjectPart part = World.GetSceneObjectPart(objID);
            // Currently only works for single prims without a sitting avatar
            if (part != null)
            {
                Vector3 halfSize = part.Scale * 0.5f;
                LSL_Vector lower = new LSL_Vector(halfSize.X * -1.0f, halfSize.Y * -1.0f, halfSize.Z * -1.0f);
                LSL_Vector upper = new LSL_Vector(halfSize.X, halfSize.Y, halfSize.Z);
                result.Add(lower);
                result.Add(upper);
                return result;
            }

            // Not found so return empty values
            result.Add(new LSL_Vector());
            result.Add(new LSL_Vector());
            return result;
        }
Beispiel #29
0
        /// <summary>
        ///     Return information regarding various simulator statistics (sim fps, physics fps, time
        ///     dilation, total number of prims, total number of active scripts, script lps, various
        ///     timing data, packets in/out, etc. Basically much the information that's shown in the
        ///     client's Statistics Bar (Ctrl-Shift-1)
        /// </summary>
        /// <returns>List of floats</returns>
        public LSL_List osGetRegionStats()
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Moderate, "osGetRegionStats", m_host, "OSSL", m_itemID))
                return new LSL_List();

            LSL_List ret = new LSL_List();
            IMonitorModule mod = World.RequestModuleInterface<IMonitorModule>();
            if (mod != null)
            {
                float[] stats = mod.GetRegionStats();

                for (int i = 0; i < 21; i++)
                {
                    ret.Add(new LSL_Float(stats[i]));
                }
            }
            return ret;
        }
Beispiel #30
0
        //  <summary>
        //  Scan the string supplied in 'src' and
        //  tokenize it based upon two sets of
        //  tokenizers provided in two lists,
        //  separators and spacers.
        //  </summary>
        //
        //  <remarks>
        //  Separators demarcate tokens and are
        //  elided as they are encountered. Spacers
        //  also demarcate tokens, but are themselves
        //  retained as tokens.
        //
        //  Both separators and spacers may be arbitrarily
        //  long strings. i.e. ":::".
        //
        //  The function returns an ordered list
        //  representing the tokens found in the supplied
        //  sources string. If two successive tokenizers
        //  are encountered, then a NULL entry is added
        //  to the list.
        //
        //  It is a precondition that the source and
        //  toekizer lisst are non-null. If they are null,
        //  then a null pointer exception will be thrown
        //  while their lengths are being determined.
        //
        //  A small amount of working memoryis required
        //  of approximately 8*#tokenizers.
        //
        //  There are many ways in which this function
        //  can be implemented, this implementation is
        //  fairly naive and assumes that when the
        //  function is invooked with a short source
        //  string and/or short lists of tokenizers, then
        //  performance will not be an issue.
        //
        //  In order to minimize the perofrmance
        //  effects of long strings, or large numbers
        //  of tokeizers, the function skips as far as
        //  possible whenever a toekenizer is found,
        //  and eliminates redundant tokenizers as soon
        //  as is possible.
        //
        //  The implementation tries to avoid any copying
        //  of arrays or other objects.
        //  </remarks>

        private LSL_List ParseString(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
        {
            int beginning = 0;
            int srclen = src.Length;
            int seplen = separators.Length;
            object[] separray = separators.Data;
            int spclen = spacers.Length;
            object[] spcarray = spacers.Data;
            int mlen = seplen + spclen;

            int[] offset = new int[mlen + 1];
            bool[] active = new bool[mlen];

            int best;
            int j;

            //    Initial capacity reduces resize cost

            LSL_List tokens = new LSL_List();

            //    All entries are initially valid

            for (int i = 0; i < mlen; i++)
                active[i] = true;

            offset[mlen] = srclen;

            while (beginning < srclen)
            {

                best = mlen;    // as bad as it gets

                //    Scan for separators

                for (j = 0; j < seplen; j++)
                {
                    if (separray[j].ToString() == String.Empty)
                        active[j] = false;

                    if (active[j])
                    {
                        // scan all of the markers
                        if ((offset[j] = src.IndexOf(separray[j].ToString(), beginning)) == -1)
                        {
                            // not present at all
                            active[j] = false;
                        }
                        else
                        {
                            // present and correct
                            if (offset[j] < offset[best])
                            {
                                // closest so far
                                best = j;
                                if (offset[best] == beginning)
                                    break;
                            }
                        }
                    }
                }

                //    Scan for spacers

                if (offset[best] != beginning)
                {
                    for (j = seplen; (j < mlen) && (offset[best] > beginning); j++)
                    {
                        if (spcarray[j - seplen].ToString() == String.Empty)
                            active[j] = false;

                        if (active[j])
                        {
                            // scan all of the markers
                            if ((offset[j] = src.IndexOf(spcarray[j - seplen].ToString(), beginning)) == -1)
                            {
                                // not present at all
                                active[j] = false;
                            }
                            else
                            {
                                // present and correct
                                if (offset[j] < offset[best])
                                {
                                    // closest so far
                                    best = j;
                                }
                            }
                        }
                    }
                }

                //    This is the normal exit from the scanning loop

                if (best == mlen)
                {
                    // no markers were found on this pass
                    // so we're pretty much done
                    if ((keepNulls) || ((!keepNulls) && (srclen - beginning) > 0))
                        tokens.Add(new LSL_String(src.Substring(beginning, srclen - beginning)));
                    break;
                }

                //    Otherwise we just add the newly delimited token
                //    and recalculate where the search should continue.
                if ((keepNulls) || ((!keepNulls) && (offset[best] - beginning) > 0))
                    tokens.Add(new LSL_String(src.Substring(beginning, offset[best] - beginning)));

                if (best < seplen)
                {
                    beginning = offset[best] + (separray[best].ToString()).Length;
                }
                else
                {
                    beginning = offset[best] + (spcarray[best - seplen].ToString()).Length;
                    string str = spcarray[best - seplen].ToString();
                    if ((keepNulls) || ((!keepNulls) && (str.Length > 0)))
                        tokens.Add(new LSL_String(str));
                }
            }

            //    This an awkward an not very intuitive boundary case. If the
            //    last substring is a tokenizer, then there is an implied trailing
            //    null list entry. Hopefully the single comparison will not be too
            //    arduous. Alternatively the 'break' could be replced with a return
            //    but that's shabby programming.

            if ((beginning == srclen) && (keepNulls))
            {
                if (srclen != 0)
                    tokens.Add(new LSL_String(""));
            }

            return tokens;
        }
Beispiel #31
0
        public LSL_List osMatchString(string src, string pattern, int start)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osMatchString", m_host, "OSSL", m_itemID))
                return new LSL_List();

            LSL_List result = new LSL_List();

            // Normalize indices (if negative).
            // After normlaization they may still be
            // negative, but that is now relative to
            // the start, rather than the end, of the
            // sequence.
            if (start < 0)
            {
                start = src.Length + start;
            }

            if (start < 0 || start >= src.Length)
            {
                return result; // empty list
            }

            // Find matches beginning at start position
            Regex matcher = new Regex(pattern);
            Match match = matcher.Match(src, start);
            while (match.Success)
            {
                foreach (Group g in match.Groups)
                {
                    if (g.Success)
                    {
                        result.Add(new LSL_Integer(g.Value));
                        result.Add(new LSL_Integer(g.Index));
                    }
                }
                match = match.NextMatch();
            }

            return result;
        }
Beispiel #32
0
 public LSL_List aaGetTeamMembers(LSL_String team)
 {
     if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Low, "AAGetTeamMembers", m_host, "AA", m_itemID))
         return new LSL_List();
     List<UUID> Members = new List<UUID>();
     ICombatModule module = World.RequestModuleInterface<ICombatModule>();
     if (module != null)
     {
         Members = module.GetTeammates(team);
     }
     LSL_List members = new LSL_List();
     foreach (UUID member in Members)
         members.Add(new LSL_Key(member.ToString()));
     return members;
 }
Beispiel #33
0
        // Get a list of all the avatars/agents in the region
        public LSL_List osGetAgents()
        {
            // threat level is None as we could get this information with an
            // in-world script as well, just not as efficient
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osGetAgents", m_host, "OSSL", m_itemID))
                return new LSL_List();

            LSL_List result = new LSL_List();
            World.ForEachScenePresence(delegate(IScenePresence sp)
                                           {
                                               if (!sp.IsChildAgent)
                                                   result.Add(new LSL_String(sp.Name));
                                           });
            return result;
        }