Ejemplo n.º 1
0
        public static void AddParameter(this SqlParameterCollection sqlparam, string key, object value)
        {
            var t = value?.GetType();

            if (t == typeof(Vector3))
            {
                var v = (Vector3)value;
                sqlparam.AddWithValue(key + "X", v.X);
                sqlparam.AddWithValue(key + "Y", v.Y);
                sqlparam.AddWithValue(key + "Z", v.Z);
            }
            else if (t == typeof(GridVector))
            {
                var v = (GridVector)value;
                sqlparam.AddWithValue(key + "X", (int)v.X);
                sqlparam.AddWithValue(key + "Y", (int)v.Y);
            }
            else if (t == typeof(Quaternion))
            {
                var v = (Quaternion)value;
                sqlparam.AddWithValue(key + "X", v.X);
                sqlparam.AddWithValue(key + "Y", v.Y);
                sqlparam.AddWithValue(key + "Z", v.Z);
                sqlparam.AddWithValue(key + "W", v.W);
            }
            else if (t == typeof(Color))
            {
                var v = (Color)value;
                sqlparam.AddWithValue(key + "Red", v.R);
                sqlparam.AddWithValue(key + "Green", v.G);
                sqlparam.AddWithValue(key + "Blue", v.B);
            }
            else if (t == typeof(ColorAlpha))
            {
                var v = (ColorAlpha)value;
                sqlparam.AddWithValue(key + "Red", v.R);
                sqlparam.AddWithValue(key + "Green", v.G);
                sqlparam.AddWithValue(key + "Blue", v.B);
                sqlparam.AddWithValue(key + "Alpha", v.A);
            }
            else if (t == typeof(EnvironmentController.WLVector2))
            {
                var vec = (EnvironmentController.WLVector2)value;
                sqlparam.AddWithValue(key + "X", vec.X);
                sqlparam.AddWithValue(key + "Y", vec.Y);
            }
            else if (t == typeof(EnvironmentController.WLVector4))
            {
                var vec = (EnvironmentController.WLVector4)value;
                sqlparam.AddWithValue(key + "Red", vec.X);
                sqlparam.AddWithValue(key + "Green", vec.Y);
                sqlparam.AddWithValue(key + "Blue", vec.Z);
                sqlparam.AddWithValue(key + "Value", vec.W);
            }
            else if (t == typeof(bool))
            {
                sqlparam.AddWithValue(key, (bool)value);
            }
            else if (t == typeof(UUID))
            {
                sqlparam.AddWithValue(key, (Guid)(UUID)value);
            }
            else if (t == typeof(UGUI) || t == typeof(UGUIWithName) || t == typeof(UGI) || t == typeof(Uri) || t == typeof(UEI))
            {
                sqlparam.AddWithValue(key, value.ToString());
            }
            else if (t == typeof(ParcelID))
            {
                ParcelID parcelid = (ParcelID)value;
                UUID     id       = new UUID(parcelid.GetBytes(), 0);
                sqlparam.AddWithValue(key, (Guid)id);
            }
            else if (t == typeof(AnArray))
            {
                using (var stream = new MemoryStream())
                {
                    LlsdBinary.Serialize((AnArray)value, stream);
                    sqlparam.AddWithValue(key, stream.ToArray());
                }
            }
            else if (t == typeof(Date))
            {
                sqlparam.AddWithValue(key, ((Date)value).AsLong);
            }
            else if (t == typeof(ulong))
            {
                sqlparam.AddWithValue(key, (long)(ulong)value);
            }
            else if (t == typeof(uint))
            {
                sqlparam.AddWithValue(key, (int)(uint)value);
            }
            else if (t == typeof(ushort))
            {
                sqlparam.AddWithValue(key, (short)(ushort)value);
            }
            else if (t == typeof(byte))
            {
                sqlparam.AddWithValue(key, (short)(byte)value);
            }
            else if (t == typeof(sbyte))
            {
                sqlparam.AddWithValue(key, (short)(sbyte)value);
            }
            else if (t.IsEnum)
            {
                Type utype = t.GetEnumUnderlyingType();
                if (utype == typeof(byte) || utype == typeof(sbyte) || utype == typeof(ushort))
                {
                    utype = typeof(short);
                }
                else if (utype == typeof(uint))
                {
                    utype = typeof(int);
                }
                else if (utype == typeof(ulong))
                {
                    utype = typeof(long);
                }

                sqlparam.AddWithValue(key, Convert.ChangeType(value, utype));
            }
            else
            {
                sqlparam.AddWithValue(key, value);
            }
        }
Ejemplo n.º 2
0
 public bool TryGetRequestRemoteParcel(string remoteurl, ParcelID parcelid, out ParcelMetaInfo parcelInfo)
 {
     parcelInfo = default(ParcelMetaInfo);
     return(false);
 }
Ejemplo n.º 3
0
        public void HttpRequestHandler(HttpRequest httpreq)
        {
            if (httpreq.CallerIP != m_RemoteIP)
            {
                httpreq.ErrorResponse(HttpStatusCode.Forbidden, "Forbidden");
                return;
            }

            var parts = httpreq.RawUrl.Substring(1).Split('/');

            if (parts.Length == 3)
            {
                if (httpreq.ContentType != "application/llsd+xml")
                {
                    httpreq.ErrorResponse(HttpStatusCode.UnsupportedMediaType, "Unsupported Media Type");
                    return;
                }
                if (httpreq.Method != "POST")
                {
                    httpreq.ErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed");
                    return;
                }

                Map reqmap;
                try
                {
                    IValue iv = LlsdXml.Deserialize(httpreq.Body);
                    reqmap = iv as Map;
                }
                catch
                {
                    httpreq.ErrorResponse(HttpStatusCode.BadRequest, "Bad Request");
                    return;
                }
                UUID parcelID;
                if (reqmap == null || !reqmap.TryGetValue("parcel_id", out parcelID))
                {
                    httpreq.ErrorResponse(HttpStatusCode.BadRequest, "Misformatted LLSD-XML");
                    return;
                }

                var parcelPos = new ParcelID(parcelID.GetBytes(), 0);

                ParcelInfo pinfo;
                if (!m_Scene.Parcels.TryGetValue(parcelPos.Location, out pinfo))
                {
                    httpreq.ErrorResponse(HttpStatusCode.Gone, "Gone");
                    return;
                }

                var resdata = new Map
                {
                    { "ScriptResourceDetails", m_ServerURI + httpreq.RawUrl + "/Details/" + pinfo.ID.ToString() },
                    { "ScriptResourceSummary", m_ServerURI + httpreq.RawUrl + "/Summary/" + pinfo.ID.ToString() }
                };

                using (HttpResponse res = httpreq.BeginResponse("application/llsd+xml"))
                    using (Stream s = res.GetOutputStream())
                    {
                        LlsdXml.Serialize(resdata, s);
                    }
            }
            else if (parts.Length == 5)
            {
                UUID parcelID;
                if (!UUID.TryParse(parts[4], out parcelID))
                {
                    httpreq.ErrorResponse(HttpStatusCode.NotFound, "Not found");
                    return;
                }

                if (httpreq.Method != "GET")
                {
                    httpreq.ErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed");
                    return;
                }

                switch (parts[3])
                {
                case "Details":
                    HandleDetailsReport(httpreq, parcelID);
                    break;

                case "Summary":
                    HandleSummaryReport(httpreq, parcelID);
                    break;

                default:
                    httpreq.ErrorResponse(HttpStatusCode.NotFound, "Not found");
                    break;
                }
            }
            else
            {
                httpreq.ErrorResponse(HttpStatusCode.NotFound, "Not found");
            }
        }
Ejemplo n.º 4
0
        public void HandleRemoteParcelRequest(ViewerAgent agent, AgentCircuit circuit, HttpRequest req)
        {
            if (req.CallerIP != circuit.RemoteIP)
            {
                req.ErrorResponse(HttpStatusCode.Forbidden, "Forbidden");
                return;
            }
            if (req.Method != "POST")
            {
                req.ErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed");
                return;
            }

            Map reqmap;

            try
            {
                reqmap = LlsdXml.Deserialize(req.Body) as Map;
            }
            catch
            {
                req.ErrorResponse(HttpStatusCode.BadRequest, "Bad request");
                return;
            }

            if (reqmap == null)
            {
                req.ErrorResponse(HttpStatusCode.BadRequest, "Bad request");
                return;
            }

            SceneInterface scene = circuit.Scene;

            if (scene == null)
            {
                req.ErrorResponse(HttpStatusCode.BadRequest, "Bad request");
                return;
            }

            AnArray locationArray;
            IValue  iv_target;
            var     parcelid = new ParcelID();

            if (reqmap.TryGetValue("location", out locationArray))
            {
                uint x = locationArray[0].AsUInt;
                uint y = locationArray[1].AsUInt;

                if (reqmap.TryGetValue("region_handle", out iv_target))
                {
                    byte[]     regHandleBytes = (BinaryData)iv_target;
                    var        v = new GridVector(regHandleBytes, 0);
                    RegionInfo rInfo;

                    if (v == scene.GridPosition)
                    {
                        parcelid = new ParcelID(v, new Vector3(x, y, 0));
                    }
                    else if (scene.GridService.TryGetValue(v, out rInfo))
                    {
                        /* shift coordinate to actual region begin */
                        Vector3 offset = (Vector3)v - rInfo.Location;
                        offset.X += x;
                        offset.Y += y;
                        /* ensure that the position is inside region */
                        if (offset.X > rInfo.Size.X)
                        {
                            offset.X = rInfo.Size.X;
                        }
                        if (offset.Y > rInfo.Size.Y)
                        {
                            offset.Y = rInfo.Size.Y;
                        }
                        parcelid = new ParcelID(rInfo.Location, offset);
                    }
                }
                else if (reqmap.TryGetValue("region_id", out iv_target))
                {
                    SceneInterface remoteSceneLocal;
                    RegionInfo     rInfo;
                    if (m_Scenes.TryGetValue(iv_target.AsUUID, out remoteSceneLocal))
                    {
                        parcelid = new ParcelID(remoteSceneLocal.GridPosition, new Vector3(x, y, 0));
                    }
                    else if (scene.GridService.TryGetValue(iv_target.AsUUID, out rInfo))
                    {
                        parcelid = new ParcelID(rInfo.Location, new Vector3(x, y, 0));
                    }
                }
            }

            var resmap = new Map
            {
                ["parcel_id"] = new UUID(parcelid.GetBytes(), 0)
            };

            using (HttpResponse res = req.BeginResponse("application/llsd+xml"))
            {
                using (Stream s = res.GetOutputStream())
                {
                    LlsdXml.Serialize(resmap, s);
                }
            }
        }