Esempio n. 1
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;
        }
Esempio n. 2
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();

            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID))
                return new LSL_List();

            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)
            {
                int chunkk = src.Length/stride;

                int[] 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);

                    // and swap position with first unrandomized chunk
                    int 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;
        }
Esempio n. 3
0
        public LSL_List llParcelMediaQuery(LSL_List aList)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID))
                return new LSL_List();

            LSL_List list = new LSL_List();
            foreach (object t in aList.Data)
            {
                if (t != null)
                {
                    IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
                    if (parcelManagement != null)
                    {
                        LSL_Integer tmp = (LSL_Integer) t;
                        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:
                                const ParcelMediaCommandEnum mediaCommandEnum = ParcelMediaCommandEnum.Url;
                                NotImplemented("llParcelMediaQuery parameter do not supported yet: " +
                                               Enum.Parse(mediaCommandEnum.GetType(), t.ToString()));
                                break;
                        }
                    }
                }
            }
            ScriptSleep(2000);
            return list;
        }
Esempio n. 4
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;
        }
Esempio n. 5
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);
 }
Esempio n. 6
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;
 }
Esempio n. 7
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(World);

                for (int i = 0; i < 21; i++)
                {
                    ret.Add(new LSL_Float(stats[i]));
                }
            }
            return ret;
        }
Esempio n. 8
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)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID))
                return new LSL_List();

            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;
            }
            IScenePresence presence = World.GetScenePresence(objID);
            if (presence != null)
            {
                if (presence.ParentID == UUID.Zero) // not sat on an object
                {
                    LSL_Vector lower = new LSL_Vector();
                    LSL_Vector upper = new LSL_Vector();
                    if (presence.Animator.Animations.ImplicitDefaultAnimation.AnimID
                        == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
                    {
                        // This is for ground sitting avatars
                        IAvatarAppearanceModule appearance = presence.RequestModuleInterface<IAvatarAppearanceModule>();
                        if (appearance != null)
                        {
                            float height = appearance.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
                        IAvatarAppearanceModule appearance = presence.RequestModuleInterface<IAvatarAppearanceModule>();
                        if (appearance != null)
                        {
                            float height = appearance.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;
                }
                // 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
                ISceneChildEntity p = World.GetSceneObjectPart(presence.ParentID);
                objID = p.UUID;
            }
            ISceneChildEntity 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;
        }
Esempio n. 9
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();
        }
Esempio n. 10
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;
        }
Esempio n. 11
0
        public LSL_List llGetAnimationList(string id)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID))
                return new LSL_List();

            LSL_List l = new LSL_List();
            IScenePresence av = World.GetScenePresence((UUID) id);
            if (av == null || av.IsChildAgent) // only if in the region
                return l;
            UUID[] anims = av.Animator.GetAnimationArray();
            foreach (UUID foo in anims)
                l.Add(new LSL_Key(foo.ToString()));
            return l;
        }
Esempio n. 12
0
        /// <summary>
        ///     The supplied string is scanned for commas
        ///     and converted into a list. Commas are only
        ///     effective if they are encountered outside
        ///     of &apos;&lt;&apos; &apos;&gt;&apos; 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;

            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID))
                return new LSL_List();

            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(new LSL_String(src.Substring(start, length).Trim()));

            return result;
        }
Esempio n. 13
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;
            else if (count <= 0)
            {
                LSLError("You must request at least one result from llCastRay.");
                return new LSL_List();
            }

            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, count+2);
                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
                // this is supposed to happen
                if (m_host.LocalId == result.ConsumerID)
                    continue;

                if (!checkTerrain && result.ConsumerID == 0)
                    continue; //Terrain

                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()));

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

                list.Add(new LSL_Vector(result.Pos));

                if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
                {
                    Vector3 norm = result.Normal * -1;
                    list.Add(new LSL_Vector(norm));
                }

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

            list.Add(new LSL_Integer(values));

            return list;
        }
Esempio n. 14
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];

            //    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)
            {
                int best = mlen;

                //    Scan for separators

                int j;
                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) || ((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) || ((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) || ((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;
        }
Esempio n. 15
0
        private void ConvertWindlightDayCycle(WindlightDayCycle cycle, int preset, int rule, ref LSL_List list)
        {
            var skyDatas = cycle.Cycle.DataSettings.Values.ToList();
            var skyData = skyDatas[preset];

            switch (rule)
            {
                case (int) ScriptBaseClass.WL_AMBIENT:
                    list.Add(new LSL_Rotation(skyData.ambient.X, skyData.ambient.Y,
                                              skyData.ambient.Z, skyData.ambient.W));
                    break;
                case (int) ScriptBaseClass.WL_SKY_BLUE_DENSITY:
                    list.Add(new LSL_Rotation(skyData.blue_density.X, skyData.blue_density.Y,
                                              skyData.blue_density.Z, skyData.blue_density.W));
                    break;
                case (int) ScriptBaseClass.WL_SKY_BLUR_HORIZON:
                    list.Add(new LSL_Rotation(skyData.blue_horizon.X, skyData.blue_horizon.Y,
                                              skyData.blue_horizon.Z, skyData.blue_horizon.W));
                    break;
                case (int) ScriptBaseClass.WL_CLOUD_COLOR:
                    list.Add(new LSL_Rotation(skyData.cloud_color.X, skyData.cloud_color.Y,
                                              skyData.cloud_color.Z, skyData.cloud_color.W));
                    break;
                case (int) ScriptBaseClass.WL_CLOUD_POS_DENSITY1:
                    list.Add(new LSL_Rotation(skyData.cloud_pos_density1.X, skyData.cloud_pos_density1.Y,
                                              skyData.cloud_pos_density1.Z, skyData.cloud_pos_density1.W));
                    break;
                case (int) ScriptBaseClass.WL_CLOUD_POS_DENSITY2:
                    list.Add(new LSL_Rotation(skyData.cloud_pos_density2.X, skyData.cloud_pos_density2.Y,
                                              skyData.cloud_pos_density2.Z, skyData.cloud_pos_density2.W));
                    break;
                case (int) ScriptBaseClass.WL_CLOUD_SCALE:
                    list.Add(new LSL_Rotation(skyData.cloud_scale.X, skyData.cloud_scale.Y,
                                              skyData.cloud_scale.Z, skyData.cloud_scale.W));
                    break;
                case (int) ScriptBaseClass.WL_CLOUD_SCROLL_X:
                    list.Add(new LSL_Float(skyData.cloud_scroll_rate.X));
                    break;
                case (int) ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK:
                    list.Add(new LSL_Integer(skyData.enable_cloud_scroll.X));
                    break;
                case (int) ScriptBaseClass.WL_CLOUD_SCROLL_Y:
                    list.Add(new LSL_Float(skyData.cloud_scroll_rate.Y));
                    break;
                case (int) ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK:
                    list.Add(new LSL_Integer(skyData.enable_cloud_scroll.Y));
                    break;
                case (int) ScriptBaseClass.WL_CLOUD_SHADOW:
                    list.Add(new LSL_Rotation(skyData.cloud_shadow.X, skyData.cloud_shadow.Y, skyData.cloud_shadow.Z,
                                              skyData.cloud_shadow.W));
                    break;
                case (int) ScriptBaseClass.WL_SKY_DENSITY_MULTIPLIER:
                    list.Add(new LSL_Rotation(skyData.density_multiplier.X, skyData.density_multiplier.Y,
                                              skyData.density_multiplier.Z, skyData.density_multiplier.W));
                    break;
                case (int) ScriptBaseClass.WL_SKY_DISTANCE_MULTIPLIER:
                    list.Add(new LSL_Rotation(skyData.distance_multiplier.X, skyData.distance_multiplier.Y,
                                              skyData.distance_multiplier.Z, skyData.distance_multiplier.W));
                    break;
                case (int) ScriptBaseClass.WL_SKY_GAMMA:
                    list.Add(new LSL_Rotation(skyData.gamma.X, skyData.gamma.Y, skyData.gamma.Z, skyData.gamma.W));
                    break;
                case (int) ScriptBaseClass.WL_SKY_GLOW:
                    list.Add(new LSL_Rotation(skyData.glow.X, skyData.glow.Y, skyData.glow.Z, skyData.glow.W));
                    break;
                case (int) ScriptBaseClass.WL_SKY_HAZE_DENSITY:
                    list.Add(new LSL_Rotation(skyData.haze_density.X, skyData.haze_density.Y, skyData.haze_density.Z,
                                              skyData.haze_density.W));
                    break;
                case (int) ScriptBaseClass.WL_SKY_HAZE_HORIZON:
                    list.Add(new LSL_Rotation(skyData.haze_horizon.X, skyData.haze_horizon.Y, skyData.haze_horizon.Z,
                                              skyData.haze_horizon.W));
                    break;
                case (int) ScriptBaseClass.WL_SKY_LIGHT_NORMALS:
                    list.Add(new LSL_Rotation(skyData.lightnorm.X, skyData.lightnorm.Y, skyData.lightnorm.Z,
                                              skyData.lightnorm.W));
                    break;
                case (int) ScriptBaseClass.WL_SKY_MAX_ALTITUDE:
                    list.Add(new LSL_Rotation(skyData.max_y.X, skyData.max_y.Y, skyData.max_y.Z, skyData.max_y.W));
                    break;
                case (int) ScriptBaseClass.WL_SKY_STAR_BRIGHTNESS:
                    list.Add(new LSL_Float(skyData.star_brightness));
                    break;
                case (int) ScriptBaseClass.WL_SKY_SUNLIGHT_COLOR:
                    list.Add(new LSL_Rotation(skyData.sunlight_color.X, skyData.sunlight_color.Y,
                                              skyData.sunlight_color.Z, skyData.sunlight_color.W));
                    break;

                case (int) ScriptBaseClass.WL_WATER_BLUR_MULTIPLIER:
                    list.Add(new LSL_Float(cycle.Water.blurMultiplier));
                    break;
                case (int) ScriptBaseClass.WL_WATER_FRESNEL_OFFSET:
                    list.Add(new LSL_Float(cycle.Water.fresnelOffset));
                    break;
                case (int) ScriptBaseClass.WL_WATER_FRESNEL_SCALE:
                    list.Add(new LSL_Float(cycle.Water.fresnelScale));
                    break;
                case (int) ScriptBaseClass.WL_WATER_NORMAL_MAP:
                    list.Add(new LSL_String(cycle.Water.normalMap));
                    break;
                case (int) ScriptBaseClass.WL_WATER_NORMAL_SCALE:
                    list.Add(new LSL_Vector(cycle.Water.normScale.X, cycle.Water.normScale.Y,
                                            cycle.Water.normScale.Z));
                    break;
                case (int) ScriptBaseClass.WL_WATER_SCALE_ABOVE:
                    list.Add(new LSL_Float(cycle.Water.scaleAbove));
                    break;
                case (int) ScriptBaseClass.WL_WATER_SCALE_BELOW:
                    list.Add(new LSL_Float(cycle.Water.scaleBelow));
                    break;
                case (int) ScriptBaseClass.WL_WATER_UNDERWATER_FOG_MODIFIER:
                    list.Add(new LSL_Float(cycle.Water.underWaterFogMod));
                    break;
                case (int) ScriptBaseClass.WL_WATER_FOG_COLOR:
                    list.Add(new LSL_Rotation(cycle.Water.waterFogColor.X, cycle.Water.waterFogColor.Y,
                                              cycle.Water.waterFogColor.Z,
                                              cycle.Water.waterFogColor.W));
                    break;
                case (int) ScriptBaseClass.WL_WATER_FOG_DENSITY:
                    list.Add(new LSL_Float(cycle.Water.waterFogDensity));
                    break;
                case (int) ScriptBaseClass.WL_WATER_BIG_WAVE_DIRECTION:
                    list.Add(new LSL_Vector(cycle.Water.wave1Dir.X,
                                            cycle.Water.wave1Dir.Y, 0.0f));
                    break;
                case (int) ScriptBaseClass.WL_WATER_LITTLE_WAVE_DIRECTION:
                    list.Add(new LSL_Vector(cycle.Water.wave2Dir.X,
                                            cycle.Water.wave2Dir.Y, 0.0f));
                    break;
            }
        }
Esempio n. 16
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)
                        ret.Add(new LSL_Key(land.GlobalID.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;
        }
Esempio n. 17
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;
 }
Esempio n. 18
0
        public LSL_List llGetParcelPrimOwners(LSL_Vector pos)
        {
            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)
            {
                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(new LSL_String(detectedParams.Key.ToString()));
                            ret.Add(new LSL_Integer(detectedParams.Value));
                        }
                    }
                }
            }
            ScriptSleep(2000);
            return ret;
        }
Esempio n. 19
0
        public LSL_List aaWindlightGetDayCycle()
        {
            IEnvironmentSettingsModule environmentSettings = World.RequestModuleInterface<IEnvironmentSettingsModule>();
            if (environmentSettings == null)
                return new LSL_List(new object[2] {ScriptBaseClass.WL_ERROR, ScriptBaseClass.WL_ERROR_NO_SCENE_SET});
            WindlightDayCycle cycle = environmentSettings.GetCurrentDayCycle();
            if (cycle == null)
                return new LSL_List(new object[2] {ScriptBaseClass.WL_ERROR, ScriptBaseClass.WL_ERROR_NO_SCENE_SET});

            if (cycle.Cycle.IsStaticDayCycle)
                return new LSL_List(new object[3] {0, -1, cycle.Cycle.DataSettings["-1"].preset_name});

            LSL_List list = new LSL_List();

            int i = 0;
            foreach (var key in cycle.Cycle.DataSettings)
            {
                list.Add(i++);
                list.Add(key.Key);
                list.Add(key.Value.preset_name);
            }
            return list;
        }
Esempio n. 20
0
        public LSL_List GetLinkPrimitiveParams(ISceneChildEntity part, LSL_List rules, bool allowOpenSimParams)
        {
            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];
                }
                else if (code == (int)ScriptBaseClass.OS_PRIM_PROJECTION)
                {
                    if (!allowOpenSimParams)
                        return null;
                    res.Add((LSL_Integer)(
                            part.Shape.ProjectionEntry ? 1 : 0));
                    res.Add((LSL_Key)part.Shape.ProjectionTextureUUID.ToString());
                    res.Add((LSL_Float)part.Shape.ProjectionFOV);
                    res.Add((LSL_Float)part.Shape.ProjectionFocus);
                    res.Add((LSL_Float)part.Shape.ProjectionAmbiance);
                }
                else if (code == (int)ScriptBaseClass.OS_PRIM_VELOCITY)
                {
                    if (!allowOpenSimParams)
                        return null;
                    res.Add(new LSL_Vector(part.Velocity));
                }
                else if (code == (int)ScriptBaseClass.OS_PRIM_ACCELERATION)
                {
                    if (!allowOpenSimParams)
                        return null;
                    res.Add(new LSL_Vector(part.Acceleration));
                }
            }
            return res;
        }
Esempio n. 21
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;
        }
Esempio n. 22
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;

            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID))
                return new LSL_List();

            //  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;
        }
Esempio n. 23
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;
        }
Esempio n. 24
0
        private LSL_List GetPrimMediaParams(ISceneChildEntity obj, 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(obj, 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)
                {
                    res.Add(me.Controls == MediaControls.Standard
                                ? new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD)
                                : 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;
        }