Example #1
0
        public void saveSession(string module, string[] args)
        {
            if (aarBox == null)
            {
                aarBox = AAR.findAarBox(m_scene);
            }
            if (isRecording)
            {
                log("Error saving session, module is still recording");
                return;
            }
            if (!hasRecording)
            {
                log("Error saving session, there is no recorded session");
                return;
            }
            //persist the session
            string session = "";

            using (MemoryStream msCompressed = new MemoryStream())
                using (GZipStream gZipStream = new GZipStream(msCompressed, CompressionMode.Compress))
                    using (MemoryStream msDecompressed = new MemoryStream())
                    {
                        new BinaryFormatter().Serialize(msDecompressed, recordedActions);
                        byte[] byteArray = msDecompressed.ToArray();

                        gZipStream.Write(byteArray, 0, byteArray.Length);
                        gZipStream.Close();
                        session = Convert.ToBase64String(msCompressed.ToArray());
                    }
            //the recorded session events are all compressed and encoded into the string in session
            OSSL_Api osslApi = new OSSL_Api();

            osslApi.Initialize(xEngine, aarBox.RootPart, null, null);
            for (int i = 0, n = 0; i < session.Length; i += CHUNKSIZE, n++)
            {
                string sessionChunk;
                if (i + CHUNKSIZE > session.Length)
                {
                    sessionChunk = session.Substring(i, session.Length - i);
                }
                else
                {
                    sessionChunk = session.Substring(i, CHUNKSIZE);
                }
                OpenSim.Region.ScriptEngine.Shared.LSL_Types.list l = new OpenSim.Region.ScriptEngine.Shared.LSL_Types.list();
                l.Add(sessionChunk);
                string notecardName = string.Format("session-{0}-{1}", sessionId, n);
                osslApi.osMakeNotecard(notecardName, l);
            }

            log(string.Format("{0} bytes", System.Text.ASCIIEncoding.ASCII.GetByteCount(session)));
            foreach (AvatarActor a in avatars.Values)
            {
                a.appearances.Clear();
                a.appearanceCount = 0;
            }
            hasRecording = false;
        }
Example #2
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()
        {
            CheckThreatLevel(ThreatLevel.None, "osGetAvatarList");
            m_host.AddScriptLPS(1);

            LSL_List result = new LSL_List();
            World.ForEachRootScenePresence(delegate (ScenePresence avatar)
            {
                if (avatar != null && avatar.UUID != m_host.OwnerID)
                {
                    result.Add(new LSL_String(avatar.UUID.ToString()));
                    result.Add(new LSL_Vector(avatar.AbsolutePosition));
                    result.Add(new LSL_String(avatar.Name));
                }
            });

            return result;
        }
Example #3
0
        public LSL_List osMatchString(string src, string pattern, int start)
        {
            CheckThreatLevel(ThreatLevel.VeryLow, "osMatchString");
            m_host.AddScriptLPS(1);

            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 (System.Text.RegularExpressions.Group g in match.Groups)
                {
                    if (g.Success)
                    {
                        result.Add(new LSL_String(g.Value));
                        result.Add(new LSL_Integer(g.Index));
                    }
                }

                match = match.NextMatch();
            }

            return result;
        }
Example #4
0
        /// <summary>
        /// Get the current Windlight scene
        /// </summary>
        /// <returns>List of windlight parameters</returns>
        public LSL_List lsGetWindlightScene(LSL_List rules)
        {
            if (!m_LSFunctionsEnabled)
            {
                LSShoutError("LightShare functions are not enabled.");
                return(new LSL_List());
            }
            m_host.AddScriptLPS(1);
            RegionLightShareData wl = m_host.ParentGroup.Scene.RegionInfo.WindlightSettings;

            LSL_List values = new LSL_List();
            int      idx    = 0;

            while (idx < rules.Length)
            {
                uint     rule  = (uint)rules.GetLSLIntegerItem(idx);
                LSL_List toadd = new LSL_List();

                switch (rule)
                {
                case (int)ScriptBaseClass.WL_AMBIENT:
                    toadd.Add(new LSL_Rotation(wl.ambient.X, wl.ambient.Y, wl.ambient.Z, wl.ambient.W));
                    break;

                case (int)ScriptBaseClass.WL_BIG_WAVE_DIRECTION:
                    toadd.Add(new LSL_Vector(wl.bigWaveDirection.X, wl.bigWaveDirection.Y, 0.0f));
                    break;

                case (int)ScriptBaseClass.WL_BLUE_DENSITY:
                    toadd.Add(new LSL_Rotation(wl.blueDensity.X, wl.blueDensity.Y, wl.blueDensity.Z, wl.blueDensity.W));
                    break;

                case (int)ScriptBaseClass.WL_BLUR_MULTIPLIER:
                    toadd.Add(new LSL_Float(wl.blurMultiplier));
                    break;

                case (int)ScriptBaseClass.WL_CLOUD_COLOR:
                    toadd.Add(new LSL_Rotation(wl.cloudColor.X, wl.cloudColor.Y, wl.cloudColor.Z, wl.cloudColor.W));
                    break;

                case (int)ScriptBaseClass.WL_CLOUD_COVERAGE:
                    toadd.Add(new LSL_Float(wl.cloudCoverage));
                    break;

                case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY:
                    toadd.Add(new LSL_Vector(wl.cloudDetailXYDensity.X, wl.cloudDetailXYDensity.Y, wl.cloudDetailXYDensity.Z));
                    break;

                case (int)ScriptBaseClass.WL_CLOUD_SCALE:
                    toadd.Add(new LSL_Float(wl.cloudScale));
                    break;

                case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X:
                    toadd.Add(new LSL_Float(wl.cloudScrollX));
                    break;

                case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK:
                    toadd.Add(new LSL_Integer(wl.cloudScrollXLock ? 1 : 0));
                    break;

                case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y:
                    toadd.Add(new LSL_Float(wl.cloudScrollY));
                    break;

                case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK:
                    toadd.Add(new LSL_Integer(wl.cloudScrollYLock ? 1 : 0));
                    break;

                case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY:
                    toadd.Add(new LSL_Vector(wl.cloudXYDensity.X, wl.cloudXYDensity.Y, wl.cloudXYDensity.Z));
                    break;

                case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER:
                    toadd.Add(new LSL_Float(wl.densityMultiplier));
                    break;

                case (int)ScriptBaseClass.WL_DISTANCE_MULTIPLIER:
                    toadd.Add(new LSL_Float(wl.distanceMultiplier));
                    break;

                case (int)ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS:
                    toadd.Add(new LSL_Integer(wl.drawClassicClouds ? 1 : 0));
                    break;

                case (int)ScriptBaseClass.WL_EAST_ANGLE:
                    toadd.Add(new LSL_Float(wl.eastAngle));
                    break;

                case (int)ScriptBaseClass.WL_FRESNEL_OFFSET:
                    toadd.Add(new LSL_Float(wl.fresnelOffset));
                    break;

                case (int)ScriptBaseClass.WL_FRESNEL_SCALE:
                    toadd.Add(new LSL_Float(wl.fresnelScale));
                    break;

                case (int)ScriptBaseClass.WL_HAZE_DENSITY:
                    toadd.Add(new LSL_Float(wl.hazeDensity));
                    break;

                case (int)ScriptBaseClass.WL_HAZE_HORIZON:
                    toadd.Add(new LSL_Float(wl.hazeHorizon));
                    break;

                case (int)ScriptBaseClass.WL_HORIZON:
                    toadd.Add(new LSL_Rotation(wl.horizon.X, wl.horizon.Y, wl.horizon.Z, wl.horizon.W));
                    break;

                case (int)ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION:
                    toadd.Add(new LSL_Vector(wl.littleWaveDirection.X, wl.littleWaveDirection.Y, 0.0f));
                    break;

                case (int)ScriptBaseClass.WL_MAX_ALTITUDE:
                    toadd.Add(new LSL_Integer(wl.maxAltitude));
                    break;

                case (int)ScriptBaseClass.WL_NORMAL_MAP_TEXTURE:
                    toadd.Add(new LSL_Key(wl.normalMapTexture.ToString()));
                    break;

                case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE:
                    toadd.Add(new LSL_Vector(wl.reflectionWaveletScale.X, wl.reflectionWaveletScale.Y, wl.reflectionWaveletScale.Z));
                    break;

                case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE:
                    toadd.Add(new LSL_Float(wl.refractScaleAbove));
                    break;

                case (int)ScriptBaseClass.WL_REFRACT_SCALE_BELOW:
                    toadd.Add(new LSL_Float(wl.refractScaleBelow));
                    break;

                case (int)ScriptBaseClass.WL_SCENE_GAMMA:
                    toadd.Add(new LSL_Float(wl.sceneGamma));
                    break;

                case (int)ScriptBaseClass.WL_STAR_BRIGHTNESS:
                    toadd.Add(new LSL_Float(wl.starBrightness));
                    break;

                case (int)ScriptBaseClass.WL_SUN_GLOW_FOCUS:
                    toadd.Add(new LSL_Float(wl.sunGlowFocus));
                    break;

                case (int)ScriptBaseClass.WL_SUN_GLOW_SIZE:
                    toadd.Add(new LSL_Float(wl.sunGlowSize));
                    break;

                case (int)ScriptBaseClass.WL_SUN_MOON_COLOR:
                    toadd.Add(new LSL_Rotation(wl.sunMoonColor.X, wl.sunMoonColor.Y, wl.sunMoonColor.Z, wl.sunMoonColor.W));
                    break;

                case (int)ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER:
                    toadd.Add(new LSL_Float(wl.underwaterFogModifier));
                    break;

                case (int)ScriptBaseClass.WL_WATER_COLOR:
                    toadd.Add(new LSL_Vector(wl.waterColor.X, wl.waterColor.Y, wl.waterColor.Z));
                    break;

                case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT:
                    toadd.Add(new LSL_Float(wl.waterFogDensityExponent));
                    break;
                }

                if (toadd.Length > 0)
                {
                    values.Add(rule);
                    values.Add(toadd.Data[0]);
                }
                idx++;
            }


            return(values);
        }
Example #5
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;
        }
Example #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;

                switch (code)
                {
                    case (int)ScriptBaseClass.PRIM_MATERIAL:
                        res.Add(new LSL_Integer(part.Material));
                        break;

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

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

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

                    case (int)ScriptBaseClass.PRIM_POSITION:
                        LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X,
                                                      part.AbsolutePosition.Y,
                                                      part.AbsolutePosition.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)
                            v = ((v - llGetRootPosition()) * llGetRootRotation()) + llGetRootPosition();
                        res.Add(v);
                        break;

                    case (int)ScriptBaseClass.PRIM_SIZE:
                        res.Add(new LSL_Vector(part.Scale.X,
                                                      part.Scale.Y,
                                                      part.Scale.Z));
                        break;

                    case (int)ScriptBaseClass.PRIM_ROTATION:
                        res.Add(GetPartRot(part));
                        break;

                    case (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.
                        switch (primType)
                        {
                            case ScriptBaseClass.PRIM_TYPE_BOX:
                            case ScriptBaseClass.PRIM_TYPE_CYLINDER:
                            case ScriptBaseClass.PRIM_TYPE_PRISM:
                                res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0);    // Isolate hole shape nibble.
                                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));
                                break;

                            case ScriptBaseClass.PRIM_TYPE_SPHERE:
                                res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0);    // Isolate hole shape nibble.
                                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));
                                break;

                            case ScriptBaseClass.PRIM_TYPE_SCULPT:
                                res.Add(Shape.SculptTexture.ToString());
                                res.Add(new LSL_Integer(Shape.SculptType));
                                break;

                            case ScriptBaseClass.PRIM_TYPE_RING:
                            case ScriptBaseClass.PRIM_TYPE_TUBE:
                            case ScriptBaseClass.PRIM_TYPE_TORUS:
                                // holeshape
                                res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0);    // Isolate hole shape nibble.

                                // 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));
                                break;
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_TEXTURE:
                        if (remain < 1)
                            return res;

                        int face = (int)rules.GetLSLIntegerItem(idx++);
                        Primitive.TextureEntry 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_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));
                            }
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_COLOR:
                        if (remain < 1)
                            return res;

                        face=(int)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));
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
                        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);
                                // 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));
                            }
                        }
                        break;

                    case (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));
                            }
                        }
                        break;

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

                    case (int)ScriptBaseClass.PRIM_TEXGEN:
                        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++)
                            {
                                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));
                            }
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
                        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
                        break;

                    case (int)ScriptBaseClass.PRIM_GLOW:
                        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_Float(texface.Glow));
                            }
                        }
                        else
                        {
                            if (face >= 0 && face < GetNumberOfSides(part))
                            {
                                Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                                res.Add(new LSL_Float(texface.Glow));
                            }
                        }
                        break;

                    case (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));
                        break;
                    case (int)ScriptBaseClass.PRIM_NAME:
                        res.Add(new LSL_String(part.Name));
                        break;
                    case (int)ScriptBaseClass.PRIM_DESC:
                        res.Add(new LSL_String(part.Description));
                        break;
                    case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
                        res.Add(new LSL_Rotation(part.RotationOffset.X, part.RotationOffset.Y, part.RotationOffset.Z, part.RotationOffset.W));
                        break;
                    case (int)ScriptBaseClass.PRIM_POS_LOCAL:
                        res.Add(new LSL_Vector(GetPartLocalPos(part)));
                        break;
                }
            }
            return res;
        }
Example #7
0
        public LSL_List llGetAnimationList(string id)
        {
            m_host.AddScriptLPS(1);

            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(new LSL_Key(foo.ToString()));
            return l;
        }
Example #8
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;

            m_host.AddScriptLPS(1);

            //  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;
        }
Example #9
0
        private LSL_List GetPrimMediaParams(int face, LSL_List rules)
        {
            IMoapModule module = m_ScriptEngine.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);

                switch (code)
                {
                    case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
                        // Not implemented
                        res.Add(new LSL_Integer(0));
                        break;

                    case 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));
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
                        res.Add(new LSL_String(me.CurrentURL));
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
                        res.Add(new LSL_String(me.HomeURL));
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
                        res.Add(me.AutoLoop ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
                        res.Add(me.AutoPlay ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
                        res.Add(me.AutoScale ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
                        res.Add(me.AutoZoom ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
                        res.Add(me.InteractOnFirstClick ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
                        res.Add(new LSL_Integer(me.Width));
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
                        res.Add(new LSL_Integer(me.Height));
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
                        res.Add(me.EnableWhiteList ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
                        break;

                    case 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)));
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
                        res.Add(new LSL_Integer((int)me.InteractPermissions));
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
                        res.Add(new LSL_Integer((int)me.ControlPermissions));
                        break;
                }
            }

            return res;
        }
Example #10
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;

                switch (code)
                {
                    case (int)ScriptBaseClass.PRIM_MATERIAL:
                        res.Add(new LSL_Integer(part.Material));
                        break;

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

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

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

                    case (int)ScriptBaseClass.PRIM_POSITION:
                        LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X,
                                                      part.AbsolutePosition.Y,
                                                      part.AbsolutePosition.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)
                            v = ((v - llGetRootPosition()) * llGetRootRotation()) + llGetRootPosition();
                        res.Add(v);
                        break;

                    case (int)ScriptBaseClass.PRIM_SIZE:
                        res.Add(new LSL_Vector(part.Scale.X,
                                                      part.Scale.Y,
                                                      part.Scale.Z));
                        break;

                    case (int)ScriptBaseClass.PRIM_ROTATION:
                        res.Add(GetPartRot(part));
                        break;

                    case (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.
                        switch (primType)
                        {
                            case ScriptBaseClass.PRIM_TYPE_BOX:
                            case ScriptBaseClass.PRIM_TYPE_CYLINDER:
                            case 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));
                                break;

                            case 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));
                                break;

                            case ScriptBaseClass.PRIM_TYPE_SCULPT:
                                res.Add(Shape.SculptTexture.ToString());
                                res.Add(new LSL_Integer(Shape.SculptType));
                                break;

                            case ScriptBaseClass.PRIM_TYPE_RING:
                            case ScriptBaseClass.PRIM_TYPE_TUBE:
                            case 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));
                                break;
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_TEXTURE:
                        if (remain < 1)
                            return res;

                        int face = (int)rules.GetLSLIntegerItem(idx++);
                        Primitive.TextureEntry 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_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));
                            }
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_COLOR:
                        if (remain < 1)
                            return res;

                        face=(int)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));
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
                        // TODO--------------
                        if (remain < 1)
                            return res;

                        face=(int)rules.GetLSLIntegerItem(idx++);

                        res.Add(new LSL_Integer(0));
                        res.Add(new LSL_Integer(0));
                        break;

                    case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
                        // TODO--------------
                        if (remain < 1)
                            return res;

                        face=(int)rules.GetLSLIntegerItem(idx++);

                        res.Add(new LSL_Integer(0));
                        break;

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

                    case (int)ScriptBaseClass.PRIM_TEXGEN:
                        // TODO--------------
                        // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
                        if (remain < 1)
                            return res;

                        face=(int)rules.GetLSLIntegerItem(idx++);

                        res.Add(new LSL_Integer(0));
                        break;

                    case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
                        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
                        break;

                    case (int)ScriptBaseClass.PRIM_GLOW:
                        // TODO--------------
                        if (remain < 1)
                            return res;

                        face=(int)rules.GetLSLIntegerItem(idx++);

                        res.Add(new LSL_Float(0));
                        break;
                    case (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));
                        break;
                }
            }
            return res;
        }
Example #11
0
 public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers)
 {
     m_host.AddScriptLPS(1);
     LSL_List ret = new LSL_List();
     LSL_List spacers = new LSL_List();
     if (in_spacers.Length > 0 && separators.Length > 0)
     {
         for (int i = 0; i < in_spacers.Length; i++)
         {
             object s = in_spacers.Data[i];
             for (int j = 0; j < separators.Length; j++)
             {
                 if (separators.Data[j].ToString() == s.ToString())
                 {
                     s = null;
                     break;
                 }
             }
             if (s != null)
             {
                 spacers.Add(s);
             }
         }
     }
     object[] delimiters = new object[separators.Length + spacers.Length];
     separators.Data.CopyTo(delimiters, 0);
     spacers.Data.CopyTo(delimiters, separators.Length);
     bool dfound = false;
     do
     {
         dfound = false;
         int cindex = -1;
         string cdeli = "";
         for (int i = 0; i < delimiters.Length; i++)
         {
             int index = str.IndexOf(delimiters[i].ToString());
             bool found = index != -1;
             if (found && String.Empty != delimiters[i].ToString())
             {
                 if ((cindex > index) || (cindex == -1))
                 {
                     cindex = index;
                     cdeli = delimiters[i].ToString();
                 }
                 dfound = dfound || found;
             }
         }
         if (cindex != -1)
         {
             if (cindex > 0)
             {
                 ret.Add(new LSL_String(str.Substring(0, cindex)));
             }
             // Cannot use spacers.Contains() because spacers may be either type String or LSLString
             for (int j = 0; j < spacers.Length; j++)
             {
                 if (spacers.Data[j].ToString() == cdeli)
                 {
                     ret.Add(new LSL_String(cdeli));
                     break;
                 }
             }
             str = str.Substring(cindex + cdeli.Length);
         }
     } while (dfound);
     if (str != "")
     {
         ret.Add(new LSL_String(str));
     }
     return ret;
 }
Example #12
0
        public LSL_List llParcelMediaQuery(LSL_List aList)
        {
            m_host.AddScriptLPS(1);
            LSL_List list = new LSL_List();
            //TO DO: make the implementation for the missing commands
            //PARCEL_MEDIA_COMMAND_TEXTURE     key uuid        Use this to get or set the parcel's media texture.
            //PARCEL_MEDIA_COMMAND_URL         string url      Used to get or set the parcel's media url.
            //PARCEL_MEDIA_COMMAND_TYPE        string mime_type        Use this to get or set the parcel media MIME type (e.g. "text/html"). (1.19.1 RC0 or later)
            //PARCEL_MEDIA_COMMAND_SIZE        integer x, integer y    Use this to get or set the parcel media pixel resolution. (1.19.1 RC0 or later)
            //PARCEL_MEDIA_COMMAND_DESC        string desc     Use this to get or set the parcel media description. (1.19.1 RC0 or later)
            //PARCEL_MEDIA_COMMAND_LOOP_SET    float loop      Use this to get or set the parcel's media loop duration. (1.19.1 RC0 or later)
            for (int i = 0; i < aList.Data.Length; i++)
            {

                if (aList.Data[i] != null)
                {
                    switch ((ParcelMediaCommandEnum) aList.Data[i])
                    {
                        case ParcelMediaCommandEnum.Url:
                            list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL));
                            break;
                        case ParcelMediaCommandEnum.Desc:
                            list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).Description));
                            break;
                        case ParcelMediaCommandEnum.Texture:
                            list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaID.ToString()));
                            break;
                        default:
                            ParcelMediaCommandEnum mediaCommandEnum = ParcelMediaCommandEnum.Url;
                            NotImplemented("llParcelMediaQuery parameter do not supported yet: " + Enum.Parse(mediaCommandEnum.GetType() , aList.Data[i].ToString()).ToString());
                            break;
                    }

                }
            }
            ConditionalScriptSleep(2000);
            return list;
        }
Example #13
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;

                switch (code)
                {
                    case (int)ScriptBaseClass.PRIM_MATERIAL:
                        res.Add(new LSL_Integer(part.Material));
                        break;

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

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

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

                    case (int)ScriptBaseClass.PRIM_POSITION:
                        res.Add(new LSL_Vector(part.AbsolutePosition.X,
                                                      part.AbsolutePosition.Y,
                                                      part.AbsolutePosition.Z));
                        break;

                    case (int)ScriptBaseClass.PRIM_SIZE:
                        res.Add(new LSL_Vector(part.Scale.X,
                                                      part.Scale.Y,
                                                      part.Scale.Z));
                        break;

                    case (int)ScriptBaseClass.PRIM_ROTATION:
                        res.Add(GetPartRot(part));
                        break;

                    case (int)ScriptBaseClass.PRIM_TYPE:
                        // implementing box
                        PrimitiveBaseShape Shape = part.Shape;
                        int primType = getScriptPrimType(part.Shape);
                        res.Add(new LSL_Integer(primType));
                        switch (primType)
                        {
                            case ScriptBaseClass.PRIM_TYPE_BOX:
                            case ScriptBaseClass.PRIM_TYPE_CYLINDER:
                            case 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(Shape.PathShearX / 100.0, Shape.PathShearY / 100.0, 0));
                                break;

                            case 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));
                                break;

                            case ScriptBaseClass.PRIM_TYPE_SCULPT:
                                res.Add(Shape.SculptTexture.ToString());
                                res.Add(new LSL_Integer(Shape.SculptType));
                                break;

                            case ScriptBaseClass.PRIM_TYPE_RING:
                            case ScriptBaseClass.PRIM_TYPE_TUBE:
                            case 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(Shape.PathShearX / 100.0, Shape.PathShearY / 100.0, 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 / 50.0)); // needs fixing :(

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

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

                    case (int)ScriptBaseClass.PRIM_TEXTURE:
                        if (remain < 1)
                            return res;

                        int face = (int)rules.GetLSLIntegerItem(idx++);
                        Primitive.TextureEntry 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_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));
                            }
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_COLOR:
                        if (remain < 1)
                            return res;

                        face=(int)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));
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
                        // TODO--------------
                        if (remain < 1)
                            return res;

                        face=(int)rules.GetLSLIntegerItem(idx++);

                        res.Add(new LSL_Integer(0));
                        res.Add(new LSL_Integer(0));
                        break;

                    case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
                        // TODO--------------
                        if (remain < 1)
                            return res;

                        face=(int)rules.GetLSLIntegerItem(idx++);

                        res.Add(new LSL_Integer(0));
                        break;

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

                    case (int)ScriptBaseClass.PRIM_TEXGEN:
                        // TODO--------------
                        // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
                        if (remain < 1)
                            return res;

                        face=(int)rules.GetLSLIntegerItem(idx++);

                        res.Add(new LSL_Integer(0));
                        break;

                    case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
                        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
                        break;

                    case (int)ScriptBaseClass.PRIM_GLOW:
                        // TODO--------------
                        if (remain < 1)
                            return res;

                        face=(int)rules.GetLSLIntegerItem(idx++);

                        res.Add(new LSL_Float(0));
                        break;
                }
            }
            return res;
        }
Example #14
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
            CheckThreatLevel(ThreatLevel.None, "osGetAgents");

            LSL_List result = new LSL_List();
            foreach (ScenePresence avatar in World.GetAvatars())
            {
                result.Add(avatar.Name);
            }
            return result;
        }
Example #15
0
        /// <summary>
        /// Gets params for a seated avatar in a linkset.
        /// </summary>
        /// <returns></returns>
        /// <param name='sp'></param>
        /// <param name='rules'></param>
        /// <param name='res'></param>
        public LSL_List GetAgentParams(ScenePresence sp, LSL_List rules, ref LSL_List res)
        {
            int idx = 0;
            while (idx < rules.Length)
            {
                int code = (int)rules.GetLSLIntegerItem(idx++);
                int remain = rules.Length-idx;

                switch (code)
                {
                    case (int)ScriptBaseClass.PRIM_MATERIAL:
                        res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MATERIAL_FLESH));
                        break;

                    case (int)ScriptBaseClass.PRIM_PHYSICS:
                        res.Add(ScriptBaseClass.FALSE);
                        break;

                    case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
                        res.Add(ScriptBaseClass.FALSE);
                        break;

                    case (int)ScriptBaseClass.PRIM_PHANTOM:
                        res.Add(ScriptBaseClass.FALSE);
                        break;

                    case (int)ScriptBaseClass.PRIM_POSITION:
                        res.Add(new LSL_Vector(sp.AbsolutePosition));
                        break;

                    case (int)ScriptBaseClass.PRIM_SIZE:
                        res.Add(GetAgentSize(sp));
                        break;

                    case (int)ScriptBaseClass.PRIM_ROTATION:
                        res.Add(sp.GetWorldRotation());
                        break;

                    case (int)ScriptBaseClass.PRIM_TYPE:
                        res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TYPE_BOX));
                        res.Add(new LSL_Integer(ScriptBaseClass.PRIM_HOLE_DEFAULT));
                        res.Add(new LSL_Vector(0, 1, 0));
                        res.Add(new LSL_Float(0));
                        res.Add(new LSL_Vector(0, 0, 0));
                        res.Add(new LSL_Vector(1, 1, 0));
                        res.Add(new LSL_Vector(0, 0, 0));
                        break;

                    case (int)ScriptBaseClass.PRIM_TEXTURE:
                        if (remain < 1)
                            return null;

                        int face = (int)rules.GetLSLIntegerItem(idx++);
                        if (face > 21)
                            break;

                        res.Add(new LSL_String(""));
                        res.Add(ScriptBaseClass.ZERO_VECTOR);
                        res.Add(ScriptBaseClass.ZERO_VECTOR);
                        res.Add(new LSL_Float(0));
                        break;

                    case (int)ScriptBaseClass.PRIM_COLOR:
                        if (remain < 1)
                            return null;

                        face = (int)rules.GetLSLIntegerItem(idx++);
                        if (face > 21)
                            break;

                        res.Add(ScriptBaseClass.ZERO_VECTOR);
                        res.Add(new LSL_Float(0));
                        break;

                    case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
                        if (remain < 1)
                            return null;

                        face = (int)rules.GetLSLIntegerItem(idx++);
                        if (face > 21)
                            break;

                        res.Add(ScriptBaseClass.PRIM_SHINY_NONE);
                        res.Add(ScriptBaseClass.PRIM_BUMP_NONE);
                        break;

                    case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
                        if (remain < 1)
                            return null;

                        face = (int)rules.GetLSLIntegerItem(idx++);
                        if (face > 21)
                            break;

                        res.Add(ScriptBaseClass.FALSE);
                        break;

                    case (int)ScriptBaseClass.PRIM_FLEXIBLE:
                        res.Add(ScriptBaseClass.FALSE);
                        res.Add(new LSL_Integer(0));
                        res.Add(new LSL_Float(0));
                        res.Add(new LSL_Float(0));
                        res.Add(new LSL_Float(0));
                        res.Add(new LSL_Float(0));
                        res.Add(ScriptBaseClass.ZERO_VECTOR);
                        break;

                    case (int)ScriptBaseClass.PRIM_TEXGEN:
                        if (remain < 1)
                            return null;

                        face = (int)rules.GetLSLIntegerItem(idx++);
                        if (face > 21)
                            break;

                        res.Add(ScriptBaseClass.PRIM_TEXGEN_DEFAULT);
                        break;

                    case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
                        res.Add(ScriptBaseClass.FALSE);
                        res.Add(ScriptBaseClass.ZERO_VECTOR);
                        res.Add(ScriptBaseClass.ZERO_VECTOR);
                        break;

                    case (int)ScriptBaseClass.PRIM_GLOW:
                        if (remain < 1)
                            return null;

                        face = (int)rules.GetLSLIntegerItem(idx++);
                        if (face > 21)
                            break;

                        res.Add(new LSL_Float(0));
                        break;

                    case (int)ScriptBaseClass.PRIM_TEXT:
                        res.Add(new LSL_String(""));
                        res.Add(ScriptBaseClass.ZERO_VECTOR);
                        res.Add(new LSL_Float(1));
                        break;

                    case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
                        res.Add(new LSL_Rotation(sp.Rotation));
                        break;

                    case (int)ScriptBaseClass.PRIM_POS_LOCAL:
                        res.Add(new LSL_Vector(sp.OffsetPosition));
                        break;

                    case (int)ScriptBaseClass.PRIM_SLICE:
                        res.Add(new LSL_Vector(0, 1, 0));
                        break;

                    case (int)ScriptBaseClass.PRIM_LINK_TARGET:
                        if(remain < 3)
                            return null;

                        return rules.GetSublist(idx, -1);
                }
            }

            return null;
        }
Example #16
0
        public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
        {
            LSL_List list = new LSL_List();

            m_host.AddScriptLPS(1);

            Vector3 rayStart = start;
            Vector3 rayEnd = end;
            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 (World.SupportsRayCastFiltered())
            {
                if (dist == 0)
                    return list;

                RayFilterFlags rayfilter = RayFilterFlags.ClosestAndBackCull;
                if (checkTerrain)
                    rayfilter |= RayFilterFlags.land;
//                if (checkAgents)
//                    rayfilter |= RayFilterFlags.agent;
                if (checkPhysical)
                    rayfilter |= RayFilterFlags.physical;
                if (checkNonPhysical)
                    rayfilter |= RayFilterFlags.nonphysical;
                if (detectPhantom)
                    rayfilter |= RayFilterFlags.LSLPhantom;

                Vector3 direction = dir * ( 1/dist);

                if(rayfilter == 0)
                {
                    list.Add(new LSL_Integer(0));
                    return list;
                }

                // get some more contacts to sort ???
                int physcount = 4 * count;
                if (physcount > 20)
                    physcount = 20;

                object physresults;
                physresults = World.RayCastFiltered(rayStart, direction, dist, physcount, rayfilter);

                if (physresults == null)
                {
                    list.Add(new LSL_Integer(-3)); // timeout error
                    return list;
                }

                results = (List<ContactResult>)physresults;

                // for now physics doesn't detect sitted avatars so do it outside physics
                if (checkAgents)
                {
                    ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd);
                    foreach (ContactResult r in agentHits)
                        results.Add(r);
                }

                // TODO: Replace this with a better solution. ObjectIntersection can only
                // detect nonphysical phantoms. They are detected by virtue of being
                // nonphysical (e.g. no PhysActor) so will not conflict with detecting
                // physicsl phantoms as done by the physics scene
                // We don't want anything else but phantoms here.
                if (detectPhantom)
                {
                    ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, false, false, true);
                    foreach (ContactResult r in objectHits)
                        results.Add(r);
                }
            }
            else
            {
                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;
            SceneObjectGroup thisgrp = m_host.ParentGroup;

            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;

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

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

                    linkNum = part.LinkNum;
                }
                else
                {
                    ScenePresence 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;
        }
Example #17
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;

            m_host.AddScriptLPS(1);

            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;
        }
Example #18
0
        public LSL_List llGetObjectDetails(string id, LSL_List args)
        {
            m_host.AddScriptLPS(1);
            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();
        }
Example #19
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)
        {
            m_host.AddScriptLPS(1);

            // 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;
            }

            ILandObject land;
            Vector3 pos;
            UUID id = UUID.Zero;
            if (parcel || parcelOwned)
            {
                pos = m_host.ParentGroup.RootPart.GetWorldPosition();
                land = World.LandChannel.GetLandObject(pos.X, pos.Y);
                if (land == null)
                {
                    id = UUID.Zero;
                }
                else
                {
                    if (parcelOwned)
                    {
                        id = land.LandData.OwnerID;
                    }
                    else
                    {
                        id = land.LandData.GlobalID;
                    }
                }
            }
            List<UUID> presenceIds = new List<UUID>();

            World.ForEachRootScenePresence(
                delegate (ScenePresence ssp)
                {
                    // Gods are not listed in SL
                    if (!ssp.IsDeleted && ssp.GodLevel == 0.0 && !ssp.IsChildAgent)
                    {
                        if (!regionWide)
                        {
                            pos = ssp.AbsolutePosition;
                            land = World.LandChannel.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;
        }
Example #20
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()
        {
            CheckThreatLevel(ThreatLevel.None, "osGetAvatarList");

            LSL_List result = new LSL_List();
            World.ForEachScenePresence(delegate (ScenePresence avatar)
            {
                if (avatar != null && avatar.UUID != m_host.OwnerID)
                {
                    if (avatar.IsChildAgent == false)
                    {
                        result.Add(avatar.UUID);
                        result.Add(avatar.AbsolutePosition);
                        result.Add(avatar.Name);
                    }
                }
            });
            return result;
        }
Example #21
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)
        {
            m_host.AddScriptLPS(1);
            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 == 0) // not sat on an object
                {
                    LSL_Vector lower;
                    LSL_Vector upper;
                    if (presence.Animator.Animations.DefaultAnimation.AnimID
                        == DefaultAvatarAnimations.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 / 2.0f;
                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;
        }
Example #22
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
            CheckThreatLevel(ThreatLevel.None, "osGetAgents");

            LSL_List result = new LSL_List();
            World.ForEachScenePresence(delegate(ScenePresence sp)
            {
                if (!sp.IsChildAgent)
                    result.Add(sp.Name);
            });
            return result;
        }
Example #23
0
        private LSL_List GetPrimMediaParams(SceneObjectPart part, int face, LSL_List rules)
        {
            // LSL Spec http://wiki.secondlife.com/wiki/LlGetPrimMediaParams says to fail silently if face is invalid
            // TODO: Need to correctly handle case where a face has no media (which gives back an empty list).
            // Assuming silently fail means give back an empty list.  Ideally, need to check this.
            if (face < 0 || face > part.GetNumberOfSides() - 1)
                return new LSL_List();

            IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
            if (null == module)
                return new LSL_List();

            MediaEntry me = module.GetMediaEntry(part, 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);

                switch (code)
                {
                    case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
                        // Not implemented
                        res.Add(new LSL_Integer(0));
                        break;

                    case 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));
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
                        res.Add(new LSL_String(me.CurrentURL));
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
                        res.Add(new LSL_String(me.HomeURL));
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
                        res.Add(me.AutoLoop ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
                        res.Add(me.AutoPlay ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
                        res.Add(me.AutoScale ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
                        res.Add(me.AutoZoom ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
                        res.Add(me.InteractOnFirstClick ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
                        res.Add(new LSL_Integer(me.Width));
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
                        res.Add(new LSL_Integer(me.Height));
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
                        res.Add(me.EnableWhiteList ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
                        break;

                    case 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)));
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
                        res.Add(new LSL_Integer((int)me.InteractPermissions));
                        break;

                    case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
                        res.Add(new LSL_Integer((int)me.ControlPermissions));
                        break;

                    default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
                }
            }

            return res;
        }
Example #24
0
 public LSL_List llGetParcelPrimOwners(LSL_Vector pos)
 {
     m_host.AddScriptLPS(1);
     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(new LSL_String(detectedParams.Key.ToString()));
             ret.Add(new LSL_Integer(detectedParams.Value));
         }
     }
     ScriptSleep(2000);
     return ret;
 }
Example #25
0
        public LSL_List llParcelMediaQuery(LSL_List aList)
        {
            m_host.AddScriptLPS(1);
            LSL_List list = new LSL_List();
            //TO DO: make the implementation for the missing commands
            //PARCEL_MEDIA_COMMAND_LOOP_SET    float loop      Use this to get or set the parcel's media loop duration. (1.19.1 RC0 or later)
            for (int i = 0; i < aList.Data.Length; i++)
            {

                if (aList.Data[i] != null)
                {
                    switch ((ParcelMediaCommandEnum) aList.Data[i])
                    {
                        case ParcelMediaCommandEnum.Url:
                            list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL));
                            break;
                        case ParcelMediaCommandEnum.Desc:
                            list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).Description));
                            break;
                        case ParcelMediaCommandEnum.Texture:
                            list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaID.ToString()));
                            break;
                        case ParcelMediaCommandEnum.Type:
                            list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaType));
                            break;
                        case ParcelMediaCommandEnum.Size:
                            list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaWidth));
                            list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaHeight));
                            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;
        }
Example #26
0
 public LSL_List llGetParcelDetails(LSL_Vector pos, LSL_List param)
 {
     m_host.AddScriptLPS(1);
     LandData land = World.GetLandData((float)pos.x, (float)pos.y);
     if (land == null)
     {
         return new LSL_List(0);
     }
     LSL_List ret = new LSL_List();
     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":
                 ret.Add(new LSL_Key(land.GlobalID.ToString()));
                 break;
             default:
                 ret.Add(new LSL_Integer(0));
                 break;
         }
     }
     return ret;
 }
Example #27
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
            CheckThreatLevel(ThreatLevel.None, "osGetAgents");
            m_host.AddScriptLPS(1);

            LSL_List result = new LSL_List();
            World.ForEachRootScenePresence(delegate(ScenePresence sp)
            {
                result.Add(new LSL_String(sp.Name));
            });
            return result;
        }
Example #28
0
        public LSL_List llGetObjectDetails(string id, LSL_List args)
        {
            m_host.AddScriptLPS(1);

            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 (int.Parse(o.ToString()))
                        {
                            case ScriptBaseClass.OBJECT_NAME:
                                ret.Add(new LSL_String(av.Firstname + " " + av.Lastname));
                                break;
                            case ScriptBaseClass.OBJECT_DESC:
                                ret.Add(new LSL_String(""));
                                break;
                            case ScriptBaseClass.OBJECT_POS:
                                ret.Add(new LSL_Vector((double)av.AbsolutePosition.X, (double)av.AbsolutePosition.Y, (double)av.AbsolutePosition.Z));
                                break;
                            case ScriptBaseClass.OBJECT_ROT:
                                ret.Add(new LSL_Rotation((double)av.Rotation.X, (double)av.Rotation.Y, (double)av.Rotation.Z, (double)av.Rotation.W));
                                break;
                            case ScriptBaseClass.OBJECT_VELOCITY:
                                ret.Add(new LSL_Vector(av.Velocity.X, av.Velocity.Y, av.Velocity.Z));
                                break;
                            case ScriptBaseClass.OBJECT_OWNER:
                                ret.Add(new LSL_String(id));
                                break;
                            case ScriptBaseClass.OBJECT_GROUP:
                                ret.Add(new LSL_String(UUID.Zero.ToString()));
                                break;
                            case ScriptBaseClass.OBJECT_CREATOR:
                                ret.Add(new LSL_String(UUID.Zero.ToString()));
                                break;
                            // For the following 8 see the Object version below
                            case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
                                ret.Add(new LSL_Integer(av.RunningScriptCount()));
                                break;
                            case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
                                ret.Add(new LSL_Integer(av.ScriptCount()));
                                break;
                            case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
                                ret.Add(new LSL_Integer(av.RunningScriptCount() * 16384));
                                break;
                            case ScriptBaseClass.OBJECT_SCRIPT_TIME:
                                ret.Add(new LSL_Float(av.ScriptExecutionTime() / 1000.0f));
                                break;
                            case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
                                ret.Add(new LSL_Integer(1));
                                break;
                            case ScriptBaseClass.OBJECT_SERVER_COST:
                                ret.Add(new LSL_Float(0));
                                break;
                            case ScriptBaseClass.OBJECT_STREAMING_COST:
                                ret.Add(new LSL_Float(0));
                                break;
                            case ScriptBaseClass.OBJECT_PHYSICS_COST:
                                ret.Add(new LSL_Float(0));
                                break;
                            default:
                                // Invalid or unhandled constant.
                                ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
                                break;
                        }
                    }

                    return ret;
                }

                SceneObjectPart obj = World.GetSceneObjectPart(key);
                if (obj != null)
                {
                    foreach (object o in args.Data)
                    {
                        switch (int.Parse(o.ToString()))
                        {
                            case ScriptBaseClass.OBJECT_NAME:
                                ret.Add(new LSL_String(obj.Name));
                                break;
                            case ScriptBaseClass.OBJECT_DESC:
                                ret.Add(new LSL_String(obj.Description));
                                break;
                            case ScriptBaseClass.OBJECT_POS:
                                ret.Add(new LSL_Vector(obj.AbsolutePosition.X, obj.AbsolutePosition.Y, obj.AbsolutePosition.Z));
                                break;
                            case ScriptBaseClass.OBJECT_ROT:
                                ret.Add(new LSL_Rotation(obj.RotationOffset.X, obj.RotationOffset.Y, obj.RotationOffset.Z, obj.RotationOffset.W));
                                break;
                            case ScriptBaseClass.OBJECT_VELOCITY:
                                ret.Add(new LSL_Vector(obj.Velocity.X, obj.Velocity.Y, obj.Velocity.Z));
                                break;
                            case ScriptBaseClass.OBJECT_OWNER:
                                ret.Add(new LSL_String(obj.OwnerID.ToString()));
                                break;
                            case ScriptBaseClass.OBJECT_GROUP:
                                ret.Add(new LSL_String(obj.GroupID.ToString()));
                                break;
                            case ScriptBaseClass.OBJECT_CREATOR:
                                ret.Add(new LSL_String(obj.CreatorID.ToString()));
                                break;
                            case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
                                ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount()));
                                break;
                            case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
                                ret.Add(new LSL_Integer(obj.ParentGroup.ScriptCount()));
                                break;
                            case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
                                // The value returned in SL for mono scripts is 65536 * number of active scripts
                                // and 16384 * number of active scripts for LSO. since llGetFreememory
                                // is coded to give the LSO value use it here
                                ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount() * 16384));
                                break;
                            case ScriptBaseClass.OBJECT_SCRIPT_TIME:
                                // Average cpu time in seconds per simulator frame expended on all scripts in the object
                                ret.Add(new LSL_Float(obj.ParentGroup.ScriptExecutionTime() / 1000.0f));
                                break;
                            case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
                                // according to the SL wiki A prim or linkset will have prim
                                // equivalent of the number of prims in a linkset if it does not
                                // contain a mesh anywhere in the link set or is not a normal prim
                                // The value returned in SL for normal prims is prim count
                                ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
                                break;
                            // The following 3 costs I have intentionaly coded to return zero. They are part of
                            // "Land Impact" calculations. These calculations are probably not applicable
                            // to OpenSim and are not yet complete in SL
                            case ScriptBaseClass.OBJECT_SERVER_COST:
                                // The linden calculation is here
                                // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
                                // The value returned in SL for normal prims looks like the prim count
                                ret.Add(new LSL_Float(0));
                                break;
                            case ScriptBaseClass.OBJECT_STREAMING_COST:
                                // The linden calculation is here
                                // http://wiki.secondlife.com/wiki/Mesh/Mesh_Streaming_Cost
                                // The value returned in SL for normal prims looks like the prim count * 0.06
                                ret.Add(new LSL_Float(0));
                                break;
                            case ScriptBaseClass.OBJECT_PHYSICS_COST:
                                // The linden calculation is here
                                // http://wiki.secondlife.com/wiki/Mesh/Mesh_physics
                                // The value returned in SL for normal prims looks like the prim count
                                ret.Add(new LSL_Float(0));
                                break;
                            default:
                                // Invalid or unhandled constant.
                                ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
                                break;
                        }
                    }

                    return ret;
                }
            }
            
            return new LSL_List();
        }
Example #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()
  {
      CheckThreatLevel(ThreatLevel.Moderate, "osGetRegionStats");
      m_host.AddScriptLPS(1);
      LSL_List ret = new LSL_List();
      float[] stats = World.StatsReporter.LastReportedSimStats;
      
      for (int i = 0; i < 21; i++)
      {
          ret.Add(new LSL_Float(stats[i]));
      }
      return ret;
  }
Example #30
0
        public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
        {
            m_host.AddScriptLPS(1);

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

            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)
                {
                    World.ForEachRootScenePresence(delegate(ScenePresence sp)
                    {
                        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);
                        }
                    });
                }
            }

            int refcount = 0;
            foreach (ContactResult result in results)
            {
                if ((rejectTypes & ScriptBaseClass.RC_REJECT_LAND)
                    == ScriptBaseClass.RC_REJECT_LAND && result.ConsumerID == 0)
                    continue;

                ISceneEntity 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 SceneObjectPart)
                {
                    PhysicsActor pa = ((SceneObjectPart)entity).PhysActor;

                    if (pa != null && pa.IsPhysical)
                    {
                        if (!checkPhysical)
                            continue;
                    }
                    else
                    {
                        if (!checkNonPhysical)
                            continue;
                    }
                }

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

                if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
                {
                    if (entity is SceneObjectPart)
                        list.Add(((SceneObjectPart)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;
        }
Example #31
0
        public LSL_List osGetNumberOfAttachments(LSL_Key avatar, LSL_List attachmentPoints)
        {
            CheckThreatLevel(ThreatLevel.Moderate, "osGetNumberOfAttachments");

            m_host.AddScriptLPS(1);

            UUID targetUUID;
            ScenePresence target;
            LSL_List resp = new LSL_List();

            if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out targetUUID) && World.TryGetScenePresence(targetUUID, out target))
            {
                foreach (object point in attachmentPoints.Data)
                {
                    LSL_Integer ipoint = new LSL_Integer(
                        (point is LSL_Integer || point is int || point is uint) ?
                            (int)point :
                            0
                    );
                    resp.Add(ipoint);
                    if (ipoint == 0)
                    {
                        // indicates zero attachments
                        resp.Add(new LSL_Integer(0));
                    }
                    else
                    {
                        // gets the number of attachments on the attachment point
                        resp.Add(new LSL_Integer(target.GetAttachments((uint)ipoint).Count));
                    }
                }
            }

            return resp;
        }
Example #32
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;

            m_host.AddScriptLPS(1);

            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;
        }