public void FetchInventorySimpleRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, OSDMap requestmap, ExpiringKey <UUID> BadRequests)
        {
            //m_log.DebugFormat("[FETCH INVENTORY HANDLER]: Received FetchInventory capability request {0}", request);

            if (BadRequests == null)
            {
                httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }

            OSDArray itemsRequested = (OSDArray)requestmap["items"];

            UUID[] itemIDs = new UUID[itemsRequested.Count];
            int    i       = 0;

            foreach (OSDMap osdItemId in itemsRequested)
            {
                UUID id = osdItemId["item_id"].AsUUID();
                if (!BadRequests.ContainsKey(id))
                {
                    itemIDs[i++] = id;
                }
            }

            InventoryItemBase[] items = null;
            try
            {
                // badrequests still not filled
                items = m_inventoryService.GetMultipleItems(m_agentID, itemIDs);
            }
            catch { }

            osUTF8 lsl = LLSDxmlEncode2.Start(4096);

            LLSDxmlEncode2.AddMap(lsl);

            LLSDxmlEncode2.AddElem("agent_id", m_agentID, lsl);

            if (items == null || items.Length == 0)
            {
                LLSDxmlEncode2.AddEmptyArray("items", lsl);
            }
            else
            {
                LLSDxmlEncode2.AddArray("items", lsl);
                foreach (InventoryItemBase item in items)
                {
                    if (item != null)
                    {
                        item.ToLLSDxml(lsl, 0xff);
                    }
                }
                LLSDxmlEncode2.AddEndArray(lsl);
            }

            LLSDxmlEncode2.AddEndMap(lsl);
            httpResponse.RawBuffer  = LLSDxmlEncode2.EndToBytes(lsl);
            httpResponse.StatusCode = (int)HttpStatusCode.OK;
        }
Beispiel #2
0
        private void GetEnvironmentSettings(IOSHttpResponse response, UUID agentID)
        {
            // m_log.DebugFormat("[{0}]: Environment GET handle for agentID {1} in region {2}",
            //      Name, agentID, caps.RegionName);

            ViewerEnvironment VEnv = null;
            ScenePresence     sp   = m_scene.GetScenePresence(agentID);

            if (sp == null)
            {
                response.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
                response.AddHeader("Retry-After", "5");
                return;
            }

            if (sp.Environment != null)
            {
                VEnv = sp.Environment;
            }
            else
            {
                if (m_scene.RegionInfo.EstateSettings.AllowEnvironmentOverride)
                {
                    ILandObject land = m_scene.LandChannel.GetLandObject(sp.AbsolutePosition.X, sp.AbsolutePosition.Y);
                    if (land != null && land.LandData != null && land.LandData.Environment != null)
                    {
                        VEnv = land.LandData.Environment;
                    }
                }
            }
            if (VEnv == null)
            {
                VEnv = GetRegionEnvironment();
            }

            byte[] envBytes = VEnv.ToCapWLBytes(UUID.Zero, regionID);
            if (envBytes == null)
            {
                osUTF8 sb = LLSDxmlEncode2.Start();
                LLSDxmlEncode2.AddArray(sb);
                LLSDxmlEncode2.AddMap(sb);
                LLSDxmlEncode2.AddElem("messageID", UUID.Zero, sb);
                LLSDxmlEncode2.AddElem("regionID", regionID, sb);
                LLSDxmlEncode2.AddEndMap(sb);
                LLSDxmlEncode2.AddEndArray(sb);
                response.RawBuffer = LLSDxmlEncode2.EndToBytes(sb);
            }
            else
            {
                response.RawBuffer = envBytes;
            }

            response.StatusCode = (int)HttpStatusCode.OK;
        }
        public byte[] toLLSDxml(osUTF8 sb = null)
        {
            const float scale    = 10000f;
            bool        fullLLSD = false;

            if (sb == null)
            {
                sb       = LLSDxmlEncode2.Start(1024, false);
                fullLLSD = true;
            }

            LLSDxmlEncode2.AddMap(sb);
            LLSDxmlEncode2.AddElem("NormMap", NormalMapID, sb);
            LLSDxmlEncode2.AddElem("NormOffsetX", (int)(scale * NormalOffsetX + 0.5f), sb);
            LLSDxmlEncode2.AddElem("NormOffsetY", (int)(scale * NormalOffsetY + 0.5f), sb);
            LLSDxmlEncode2.AddElem("NormRepeatX", (int)(scale * NormalRepeatX + 0.5f), sb);
            LLSDxmlEncode2.AddElem("NormRepeatY", (int)(scale * NormalRepeatY + 0.5f), sb);
            LLSDxmlEncode2.AddElem("NormRotation", (int)(scale * NormalRotation + 0.5f), sb);

            LLSDxmlEncode2.AddElem("SpecMap", SpecularMapID, sb);
            LLSDxmlEncode2.AddElem("SpecOffsetX", (int)(scale * SpecularOffsetX + 0.5f), sb);
            LLSDxmlEncode2.AddElem("SpecOffsetY", (int)(scale * SpecularOffsetY + 0.5f), sb);
            LLSDxmlEncode2.AddElem("SpecRepeatX", (int)(scale * SpecularRepeatX + 0.5f), sb);
            LLSDxmlEncode2.AddElem("SpecRepeatY", (int)(scale * SpecularRepeatY + 0.5f), sb);
            LLSDxmlEncode2.AddElem("SpecRotation", (int)(scale * SpecularRotation + 0.5f), sb);

            LLSDxmlEncode2.AddArray("SpecColor", sb);
            LLSDxmlEncode2.AddElem(SpecularLightColorR, sb);
            LLSDxmlEncode2.AddElem(SpecularLightColorG, sb);
            LLSDxmlEncode2.AddElem(SpecularLightColorB, sb);
            LLSDxmlEncode2.AddElem(255, sb);
            LLSDxmlEncode2.AddEndArray(sb);

            LLSDxmlEncode2.AddElem("SpecExp", SpecularLightExponent, sb);
            LLSDxmlEncode2.AddElem("EnvIntensity", EnvironmentIntensity, sb);
            LLSDxmlEncode2.AddElem("DiffuseAlphaMode", DiffuseAlphaMode, sb);
            LLSDxmlEncode2.AddElem("AlphaMaskCutoff", AlphaMaskCutoff, sb);

            LLSDxmlEncode2.AddEndMap(sb);

            if (fullLLSD)
            {
                return(LLSDxmlEncode2.EndToBytes(sb));
            }
            else
            {
                return(Utils.EmptyBytes); // ignored if appending
            }
        }
Beispiel #4
0
        private void DeleteExtEnvironmentSettings(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID agentID)
        {
            int parcel = -1;

            if (httpRequest.Query.Count > 0)
            {
                if (httpRequest.Query.ContainsKey("parcelid"))
                {
                    Int32.TryParse((string)httpRequest.Query["parcelid"], out parcel);
                }
            }

            if (parcel == -1)
            {
                StoreOnRegion(null);
                WindlightRefresh(0);
            }
            else
            {
                ILandObject land = m_scene.LandChannel.GetLandObject(parcel);
                if (land != null && land.LandData != null)
                {
                    land.StoreEnvironment(null);
                    WindlightRefresh(0, false);
                }
            }

            osUTF8 sb = LLSDxmlEncode2.Start();

            LLSDxmlEncode2.AddMap(sb);
            LLSDxmlEncode2.AddElem("messageID", UUID.Zero, sb);
            LLSDxmlEncode2.AddElem("regionID", regionID, sb);
            LLSDxmlEncode2.AddElem("success", true, sb);
            LLSDxmlEncode2.AddEndMap(sb);
            httpResponse.RawBuffer  = LLSDxmlEncode2.EndToBytes(sb);
            httpResponse.StatusCode = (int)HttpStatusCode.OK;
        }
        /// <summary>
        /// Callback for a client request for ParcelVoiceInfo
        /// </summary>
        /// <param name="scene">current scene object of the client</param>
        /// <param name="request"></param>
        /// <param name="path"></param>
        /// <param name="param"></param>
        /// <param name="agentID"></param>
        /// <param name="caps"></param>
        /// <returns></returns>
        public void ParcelVoiceInfoRequest(IOSHttpRequest request, IOSHttpResponse response, UUID agentID, Scene scene)
        {
            if (request.HttpMethod != "POST")
            {
                response.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }

            response.StatusCode = (int)HttpStatusCode.OK;

            m_log.DebugFormat(
                "[FreeSwitchVoice][PARCELVOICE]: ParcelVoiceInfoRequest() on {0} for {1}",
                scene.RegionInfo.RegionName, agentID);

            ScenePresence avatar = scene.GetScenePresence(agentID);

            if (avatar == null)
            {
                response.RawBuffer = Util.UTF8.GetBytes("<llsd>undef</llsd>");
                return;
            }

            string avatarName = avatar.Name;

            // - check whether we have a region channel in our cache
            // - if not:
            //       create it and cache it
            // - send it to the client
            // - send channel_uri: as "sip:regionID@m_sipDomain"
            try
            {
                string channelUri;

                if (null == scene.LandChannel)
                {
                    m_log.ErrorFormat("region \"{0}\": avatar \"{1}\": land data not yet available",
                                      scene.RegionInfo.RegionName, avatarName);
                    response.RawBuffer = Util.UTF8.GetBytes("<llsd>undef</llsd>");
                    return;
                }

                // get channel_uri: check first whether estate
                // settings allow voice, then whether parcel allows
                // voice, if all do retrieve or obtain the parcel
                // voice channel
                LandData land = scene.GetLandData(avatar.AbsolutePosition);

                //m_log.DebugFormat("[FreeSwitchVoice][PARCELVOICE]: region \"{0}\": Parcel \"{1}\" ({2}): avatar \"{3}\": request: {4}, path: {5}, param: {6}",
                //                  scene.RegionInfo.RegionName, land.Name, land.LocalID, avatarName, request, path, param);

                // TODO: EstateSettings don't seem to get propagated...
                if (!scene.RegionInfo.EstateSettings.AllowVoice)
                {
                    m_log.DebugFormat("[FreeSwitchVoice][PARCELVOICE]: region \"{0}\": voice not enabled in estate settings",
                                      scene.RegionInfo.RegionName);
                    channelUri = String.Empty;
                }
                else

                if (!scene.RegionInfo.EstateSettings.TaxFree && (land.Flags & (uint)ParcelFlags.AllowVoiceChat) == 0)
                {
                    //                    m_log.DebugFormat("[FreeSwitchVoice][PARCELVOICE]: region \"{0}\": Parcel \"{1}\" ({2}): avatar \"{3}\": voice not enabled for parcel",
                    //                                      scene.RegionInfo.RegionName, land.Name, land.LocalID, avatarName);
                    channelUri = String.Empty;
                }
                else
                {
                    channelUri = ChannelUri(scene, land);
                }

                // fast foward encode
                osUTF8 lsl = LLSDxmlEncode2.Start(512);
                LLSDxmlEncode2.AddMap(lsl);
                LLSDxmlEncode2.AddElem("parcel_local_id", land.LocalID, lsl);
                LLSDxmlEncode2.AddElem("region_name", scene.Name, lsl);
                LLSDxmlEncode2.AddMap("voice_credentials", lsl);
                LLSDxmlEncode2.AddElem("channel_uri", channelUri, lsl);
                //LLSDxmlEncode2.AddElem("channel_credentials", channel_credentials, lsl);
                LLSDxmlEncode2.AddEndMap(lsl);
                LLSDxmlEncode2.AddEndMap(lsl);

                response.RawBuffer = LLSDxmlEncode2.EndToBytes(lsl);
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[FreeSwitchVoice][PARCELVOICE]: region \"{0}\": avatar \"{1}\": {2}, retry later",
                                  scene.RegionInfo.RegionName, avatarName, e.Message);
                m_log.DebugFormat("[FreeSwitchVoice][PARCELVOICE]: region \"{0}\": avatar \"{1}\": {2} failed",
                                  scene.RegionInfo.RegionName, avatarName, e.ToString());

                response.RawBuffer = Util.UTF8.GetBytes("<llsd>undef</llsd>");
            }
        }
        /// <summary>
        /// Callback for a client request for Voice Account Details
        /// </summary>
        /// <param name="scene">current scene object of the client</param>
        /// <param name="request"></param>
        /// <param name="path"></param>
        /// <param name="param"></param>
        /// <param name="agentID"></param>
        /// <param name="caps"></param>
        /// <returns></returns>
        public void ProvisionVoiceAccountRequest(IOSHttpRequest request, IOSHttpResponse response, UUID agentID, Scene scene)
        {
            if (request.HttpMethod != "POST")
            {
                response.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }

            m_log.DebugFormat(
                "[FreeSwitchVoice][PROVISIONVOICE]: ProvisionVoiceAccountRequest() request for {0}", agentID.ToString());

            response.StatusCode = (int)HttpStatusCode.OK;

            ScenePresence avatar = scene.GetScenePresence(agentID);

            if (avatar == null)
            {
                System.Threading.Thread.Sleep(2000);
                avatar = scene.GetScenePresence(agentID);

                if (avatar == null)
                {
                    response.RawBuffer = Util.UTF8.GetBytes("<llsd>undef</llsd>");
                    return;
                }
            }
            string avatarName = avatar.Name;

            try
            {
                //XmlElement    resp;
                string agentname = "x" + Convert.ToBase64String(agentID.GetBytes());
                string password  = "******";//temp hack//new UUID(Guid.NewGuid()).ToString().Replace('-','Z').Substring(0,16);

                // XXX: we need to cache the voice credentials, as
                // FreeSwitch is later going to come and ask us for
                // those
                agentname = agentname.Replace('+', '-').Replace('/', '_');

                lock (m_UUIDName)
                {
                    if (m_UUIDName.ContainsKey(agentname))
                    {
                        m_UUIDName[agentname] = avatarName;
                    }
                    else
                    {
                        m_UUIDName.Add(agentname, avatarName);
                    }
                }

                string accounturl = String.Format("http://{0}:{1}{2}/", m_openSimWellKnownHTTPAddress,
                                                  m_freeSwitchServicePort, m_freeSwitchAPIPrefix);
                // fast foward encode
                osUTF8 lsl = LLSDxmlEncode2.Start();
                LLSDxmlEncode2.AddMap(lsl);
                LLSDxmlEncode2.AddElem("username", agentname, lsl);
                LLSDxmlEncode2.AddElem("password", password, lsl);
                LLSDxmlEncode2.AddElem("voice_sip_uri_hostname", m_freeSwitchRealm, lsl);
                LLSDxmlEncode2.AddElem("voice_account_server_name", accounturl, lsl);
                LLSDxmlEncode2.AddEndMap(lsl);
                response.RawBuffer = LLSDxmlEncode2.EndToBytes(lsl);
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[FreeSwitchVoice][PROVISIONVOICE]: avatar \"{0}\": {1}, retry later", avatarName, e.Message);
                m_log.DebugFormat("[FreeSwitchVoice][PROVISIONVOICE]: avatar \"{0}\": {1} failed", avatarName, e.ToString());

                response.RawBuffer = osUTF8.GetASCIIBytes("<llsd>undef</llsd>");
            }
        }
        public void ProcessRequest(IOSHttpRequest request, IOSHttpResponse response, UUID AgentId)
        {
            if (request.HttpMethod != "GET")
            {
                response.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }

            ScenePresence avatar;

            if (!m_scene.TryGetScenePresence(AgentId, out avatar) || m_scene.RegionInfo == null || m_scene.RegionInfo.EstateSettings == null)
            {
                response.StatusCode = (int)HttpStatusCode.Gone;
                return;
            }

            if (!m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
            {
                response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return;
            }

            EstateSettings regionSettings = m_scene.RegionInfo.EstateSettings;

            UUID[]      managers   = regionSettings.EstateManagers;
            UUID[]      allowed    = regionSettings.EstateAccess;
            UUID[]      groups     = regionSettings.EstateGroups;
            EstateBan[] EstateBans = regionSettings.EstateBans;

            osUTF8 sb = LLSDxmlEncode2.Start();

            LLSDxmlEncode2.AddMap(sb);

            if (allowed != null && allowed.Length > 0)
            {
                LLSDxmlEncode2.AddArray("AllowedAgents", sb);
                for (int i = 0; i < allowed.Length; ++i)
                {
                    UUID id = allowed[i];
                    if (id == UUID.Zero)
                    {
                        continue;
                    }
                    LLSDxmlEncode2.AddMap(sb);
                    LLSDxmlEncode2.AddElem("id", id, sb);
                    LLSDxmlEncode2.AddEndMap(sb);
                }
                LLSDxmlEncode2.AddEndArray(sb);
            }
            else
            {
                LLSDxmlEncode2.AddEmptyArray("AllowedAgents", sb);
            }

            if (groups != null && groups.Length > 0)
            {
                LLSDxmlEncode2.AddArray("AllowedGroups", sb);
                for (int i = 0; i < groups.Length; ++i)
                {
                    UUID id = groups[i];
                    if (id == UUID.Zero)
                    {
                        continue;
                    }
                    LLSDxmlEncode2.AddMap(sb);
                    LLSDxmlEncode2.AddElem("id", id, sb);
                    LLSDxmlEncode2.AddEndMap(sb);
                }
                LLSDxmlEncode2.AddEndArray(sb);
            }
            else
            {
                LLSDxmlEncode2.AddEmptyArray("AllowedGroups", sb);
            }

            if (EstateBans != null && EstateBans.Length > 0)
            {
                LLSDxmlEncode2.AddArray("BannedAgents", sb);
                for (int i = 0; i < EstateBans.Length; ++i)
                {
                    EstateBan ban = EstateBans[i];
                    UUID      id  = ban.BannedUserID;
                    if (id == UUID.Zero)
                    {
                        continue;
                    }
                    LLSDxmlEncode2.AddMap(sb);
                    LLSDxmlEncode2.AddElem("id", id, sb);
                    LLSDxmlEncode2.AddElem("banning_id", ban.BanningUserID, sb);
                    LLSDxmlEncode2.AddElem("last_login_date", "na", sb);     // We will not have this. This information is far at grid
                    if (ban.BanTime == 0)
                    {
                        LLSDxmlEncode2.AddElem("ban_date", "0000-00-00 00:00", sb);
                    }
                    else
                    {
                        LLSDxmlEncode2.AddElem("ban_date", (Util.ToDateTime(ban.BanTime)).ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture), sb);
                    }
                    LLSDxmlEncode2.AddEndMap(sb);
                }
                LLSDxmlEncode2.AddEndArray(sb);
            }
            else
            {
                LLSDxmlEncode2.AddEmptyArray("BannedAgents", sb);
            }

            if (managers != null && managers.Length > 0)
            {
                LLSDxmlEncode2.AddArray("Managers", sb);
                for (int i = 0; i < managers.Length; ++i)
                {
                    LLSDxmlEncode2.AddMap(sb);
                    LLSDxmlEncode2.AddElem("agent_id", managers[i], sb);
                    LLSDxmlEncode2.AddEndMap(sb);
                }
                LLSDxmlEncode2.AddEndArray(sb);
            }
            else
            {
                LLSDxmlEncode2.AddEmptyArray("Managers", sb);
            }

            LLSDxmlEncode2.AddEndMap(sb);

            response.RawBuffer  = LLSDxmlEncode2.EndToBytes(sb);
            response.StatusCode = (int)HttpStatusCode.OK;
        }
Beispiel #8
0
        public void FetchInventoryDescendentsRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, ExpiringKey <UUID> BadRequests)
        {
            //m_log.DebugFormat("[XXX]: FetchInventoryDescendentsRequest in {0}, {1}", (m_Scene == null) ? "none" : m_Scene.Name, request);

            List <LLSDFetchInventoryDescendents> folders = null;
            List <UUID> bad_folders = new List <UUID>();

            try
            {
                OSDArray foldersrequested = null;
                OSD      tmp = OSDParser.DeserializeLLSDXml(httpRequest.InputStream);
                httpRequest.InputStream.Dispose();

                OSDMap map = (OSDMap)tmp;
                if (map.TryGetValue("folders", out tmp) && tmp is OSDArray)
                {
                    foldersrequested = tmp as OSDArray;
                }

                if (foldersrequested == null || foldersrequested.Count == 0)
                {
                    httpResponse.RawBuffer = EmptyResponse;
                    return;
                }

                folders = new List <LLSDFetchInventoryDescendents>(foldersrequested.Count);
                for (int i = 0; i < foldersrequested.Count; i++)
                {
                    OSDMap mfolder = foldersrequested[i] as OSDMap;
                    UUID   id      = mfolder["folder_id"].AsUUID();
                    if (BadRequests.ContainsKey(id))
                    {
                        bad_folders.Add(id);
                    }
                    else
                    {
                        LLSDFetchInventoryDescendents llsdRequest = new LLSDFetchInventoryDescendents();
                        try
                        {
                            llsdRequest.folder_id     = id;
                            llsdRequest.owner_id      = mfolder["owner_id"].AsUUID();
                            llsdRequest.sort_order    = mfolder["sort_order"].AsInteger();
                            llsdRequest.fetch_folders = mfolder["fetch_folders"].AsBoolean();
                            llsdRequest.fetch_items   = mfolder["fetch_items"].AsBoolean();
                        }
                        catch (Exception e)
                        {
                            m_log.Debug("[WEB FETCH INV DESC HANDLER]: caught exception doing OSD deserialize" + e.Message);
                            continue;
                        }
                        folders.Add(llsdRequest);
                    }
                }
                foldersrequested = null;
                map.Clear();
                map = null;
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[FETCH INV DESC]: fail parsing request: {0}", e.Message);
                httpResponse.RawBuffer = EmptyResponse;
                return;
            }

            if (folders == null || folders.Count == 0)
            {
                if (bad_folders.Count == 0)
                {
                    httpResponse.RawBuffer = EmptyResponse;
                    return;
                }

                osUTF8 osu = OSUTF8Cached.Acquire();
                osu.AppendASCII("[WEB FETCH INV DESC HANDLER]: Unable to fetch folders owned by Unknown user:"******" ...");
                    }
                    m_log.Warn(osu.ToString());
                }

                osu.Clear();

                osu.AppendASCII("<llsd><map><key>folders</key><array /></map><map><key>bad_folders</key><array>");
                foreach (UUID bad in bad_folders)
                {
                    osu.AppendASCII("<map><key>folder_id</key><uuid>");
                    osu.AppendASCII(bad.ToString());
                    osu.AppendASCII("</uuid><key>error</key><string>Unknown</string></map>");
                }
                osu.AppendASCII("</array></map></llsd>");
                httpResponse.RawBuffer = OSUTF8Cached.GetArrayAndRelease(osu);
                return;
            }

            int total_folders = 0;
            int total_items   = 0;

            UUID requester = folders[0].owner_id;

            List <InventoryCollection> invcollSet = Fetch(folders, bad_folders, ref total_folders, ref total_items);
            //m_log.DebugFormat("[XXX]: Got {0} folders from a request of {1}", invcollSet.Count, folders.Count);

            int invcollSetCount = 0;

            if (invcollSet != null)
            {
                invcollSetCount = invcollSet.Count;
            }

            int mem = 8192 + ((256 * invcollSetCount +
                               384 * total_folders +
                               1024 * total_items +
                               128 * bad_folders.Count) & 0x7ffff000);

            osUTF8 lastresponse = LLSDxmlEncode2.Start(mem);

            if (invcollSetCount > 0)
            {
                lastresponse.AppendASCII("<map><key>folders</key><array>");
                int i = 0;
                InventoryCollection thiscoll;
                for (i = 0; i < invcollSetCount; i++)
                {
                    thiscoll      = invcollSet[i];
                    invcollSet[i] = null;

                    LLSDxmlEncode2.AddMap(lastresponse);
                    LLSDxmlEncode2.AddElem_agent_id(thiscoll.OwnerID, lastresponse);
                    LLSDxmlEncode2.AddElem("descendents", thiscoll.Descendents, lastresponse);
                    LLSDxmlEncode2.AddElem_folder_id(thiscoll.FolderID, lastresponse);

                    if (thiscoll.Folders == null || thiscoll.Folders.Count == 0)
                    {
                        LLSDxmlEncode2.AddEmptyArray("categories", lastresponse);
                    }
                    else
                    {
                        LLSDxmlEncode2.AddArray("categories", lastresponse);
                        foreach (InventoryFolderBase invFolder in thiscoll.Folders)
                        {
                            LLSDxmlEncode2.AddMap(lastresponse);

                            LLSDxmlEncode2.AddElem_folder_id(invFolder.ID, lastresponse);
                            LLSDxmlEncode2.AddElem_parent_id(invFolder.ParentID, lastresponse);
                            LLSDxmlEncode2.AddElem_name(invFolder.Name, lastresponse);
                            LLSDxmlEncode2.AddElem("type", invFolder.Type, lastresponse);
                            LLSDxmlEncode2.AddElem("preferred_type", (int)-1, lastresponse);
                            LLSDxmlEncode2.AddElem("version", invFolder.Version, lastresponse);

                            LLSDxmlEncode2.AddEndMap(lastresponse);
                        }
                        LLSDxmlEncode2.AddEndArray(lastresponse);
                    }

                    if (thiscoll.Items == null || thiscoll.Items.Count == 0)
                    {
                        LLSDxmlEncode2.AddEmptyArray("items", lastresponse);
                    }
                    else
                    {
                        LLSDxmlEncode2.AddArray("items", lastresponse);
                        foreach (InventoryItemBase invItem in thiscoll.Items)
                        {
                            invItem.ToLLSDxml(lastresponse);
                        }

                        LLSDxmlEncode2.AddEndArray(lastresponse);
                    }

                    LLSDxmlEncode2.AddElem_owner_id(thiscoll.OwnerID, lastresponse);
                    LLSDxmlEncode2.AddElem("version", thiscoll.Version, lastresponse);

                    LLSDxmlEncode2.AddEndMap(lastresponse);
                    invcollSet[i] = null;
                }
                LLSDxmlEncode2.AddEndArrayAndMap(lastresponse);
                thiscoll = null;
            }
            else
            {
                lastresponse.AppendASCII("<map><key>folders</key><array /></map>");
            }

            if (bad_folders.Count > 0)
            {
                lastresponse.AppendASCII("<map><key>bad_folders</key><array>");
                foreach (UUID bad in bad_folders)
                {
                    BadRequests.Add(bad);
                    lastresponse.AppendASCII("<map><key>folder_id</key><uuid>");
                    lastresponse.AppendASCII(bad.ToString());
                    lastresponse.AppendASCII("</uuid><key>error</key><string>Unknown</string></map>");
                }
                lastresponse.AppendASCII("</array></map>");

                StringBuilder sb = osStringBuilderCache.Acquire();
                sb.Append("[WEB FETCH INV DESC HANDLER]: Unable to fetch folders owned by ");
                sb.Append(requester.ToString());
                sb.Append(" :");
                int limit = 9;
                foreach (UUID bad in bad_folders)
                {
                    sb.Append(" ");
                    sb.Append(bad.ToString());
                    if (--limit < 0)
                    {
                        break;
                    }
                }
                if (limit < 0)
                {
                    sb.Append(" ...");
                }
                m_log.Warn(osStringBuilderCache.GetStringAndRelease(sb));
            }

            httpResponse.RawBuffer = LLSDxmlEncode2.EndToBytes(lastresponse);
        }
Beispiel #9
0
        private void SetEnvironmentSettings(IOSHttpRequest request, IOSHttpResponse response, UUID agentID)
        {
            // m_log.DebugFormat("[{0}]: Environment SET handle from agentID {1} in region {2}",
            //       Name, agentID, caps.RegionName);

            bool   success     = false;
            string fail_reason = "";

            if (!m_scene.Permissions.CanIssueEstateCommand(agentID, false))
            {
                fail_reason = "Insufficient estate permissions, settings has not been saved.";
                goto Error;
            }

            ScenePresence sp = m_scene.GetScenePresence(agentID);

            if (sp == null || sp.IsChildAgent || sp.IsNPC)
            {
                response.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }

            if (sp.Environment != null)
            {
                fail_reason = "The environment you see is a forced one. Disable if on control object or tp out and back to region";
                goto Error;
            }

            ILandObject land = m_scene.LandChannel.GetLandObject(sp.AbsolutePosition.X, sp.AbsolutePosition.Y);

            if (land != null && land.LandData != null && land.LandData.Environment != null)
            {
                fail_reason = "The parcel where you are has own environment set. You need a updated viewer to change environment";
                goto Error;
            }
            try
            {
                ViewerEnvironment VEnv = new ViewerEnvironment();
                OSD env = OSDParser.Deserialize(request.InputStream);
                VEnv.FromWLOSD(env);

                StoreOnRegion(VEnv);

                WindlightRefresh(0);

                m_log.InfoFormat("[{0}]: New Environment settings has been saved from agentID {1} in region {2}",
                                 Name, agentID, m_scene.Name);
                success = true;
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[{0}]: Environment settings has not been saved for region {1}, Exception: {2} - {3}",
                                  Name, m_scene.Name, e.Message, e.StackTrace);

                success     = false;
                fail_reason = String.Format("Environment Set for region {0} has failed, settings not saved.", m_scene.Name);
            }

Error:
            osUTF8 sb = LLSDxmlEncode2.Start();

            LLSDxmlEncode2.AddMap(sb);
            LLSDxmlEncode2.AddElem("messageID", UUID.Zero, sb);
            LLSDxmlEncode2.AddElem("regionID", regionID, sb);
            LLSDxmlEncode2.AddElem("success", success, sb);
            if (!success)
            {
                LLSDxmlEncode2.AddElem("fail_reason", fail_reason, sb);
            }
            LLSDxmlEncode2.AddEndMap(sb);
            response.RawBuffer  = LLSDxmlEncode2.EndToBytes(sb);
            response.StatusCode = (int)HttpStatusCode.OK;
        }
Beispiel #10
0
        private void SetExtEnvironmentSettings(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID agentID, Caps caps)
        {
            bool   success = false;
            string message = "Could not process request";
            int    parcel  = -1;
            int    track   = -1;

            osUTF8 sb = LLSDxmlEncode2.Start();

            ScenePresence sp = m_scene.GetScenePresence(agentID);

            if (sp == null || sp.IsChildAgent || sp.IsNPC)
            {
                message = "Could not locate your avatar";
                goto Error;
            }

            if (httpRequest.Query.Count > 0)
            {
                if (httpRequest.Query.ContainsKey("parcelid"))
                {
                    if (!Int32.TryParse((string)httpRequest.Query["parcelid"], out parcel))
                    {
                        message = "Failed to decode request";
                        goto Error;
                    }
                }
                if (httpRequest.Query.ContainsKey("trackno"))
                {
                    if (!Int32.TryParse((string)httpRequest.Query["trackno"], out track))
                    {
                        message = "Failed to decode request";
                        goto Error;
                    }
                }
                if (track != -1)
                {
                    message = "Environment Track not supported";
                    goto Error;
                }
            }


            ViewerEnvironment VEnv = m_scene.RegionEnvironment;
            ILandObject       lchannel;

            if (parcel == -1)
            {
                if (!m_scene.Permissions.CanIssueEstateCommand(agentID, false))
                {
                    message = "Insufficient estate permissions, settings has not been saved.";
                    goto Error;
                }
                VEnv     = m_scene.RegionEnvironment;
                lchannel = null;
            }
            else
            {
                lchannel = m_landChannel.GetLandObject(parcel);
                if (lchannel == null || lchannel.LandData == null)
                {
                    message = "Could not locate requested parcel";
                    goto Error;
                }

                if (!m_scene.Permissions.CanEditParcelProperties(agentID, lchannel, GroupPowers.AllowEnvironment, true)) // wrong
                {
                    message = "No permission to change parcel environment";
                    goto Error;
                }
                VEnv = lchannel.LandData.Environment;
            }

            try
            {
                OSD req = OSDParser.Deserialize(httpRequest.InputStream);
                if (req is OSDMap)
                {
                    OSDMap map = req as OSDMap;
                    if (map.TryGetValue("environment", out OSD env))
                    {
                        if (VEnv == null)
                        {
                            // need a proper clone
                            VEnv = m_DefaultEnv.Clone();
                        }

                        OSDMap evmap = env as OSDMap;
                        if (evmap.TryGetValue("day_asset", out OSD tmp) && !evmap.ContainsKey("day_cycle"))
                        {
                            string    id    = tmp.AsString();
                            AssetBase asset = m_assetService.Get(id);
                            if (asset == null || asset.Data == null || asset.Data.Length == 0)
                            {
                                httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
                                return;
                            }
                            try
                            {
                                OSD oenv = OSDParser.Deserialize(asset.Data);
                                evmap.TryGetValue("day_name", out tmp);
                                if (tmp is OSDString)
                                {
                                    VEnv.FromAssetOSD(tmp.AsString(), oenv);
                                }
                                else
                                {
                                    VEnv.FromAssetOSD(null, oenv);
                                }
                            }
                            catch
                            {
                                httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
                                return;
                            }
                        }
                        else
                        {
                            VEnv.FromOSD(env);
                        }

                        if (lchannel == null)
                        {
                            StoreOnRegion(VEnv);
                            m_log.InfoFormat("[{0}]: ExtEnvironment region {1} settings from agentID {2} saved",
                                             Name, caps.RegionName, agentID);
                        }
                        else
                        {
                            lchannel.StoreEnvironment(VEnv);
                            m_log.InfoFormat("[{0}]: ExtEnvironment parcel {1} of region {2}  settings from agentID {3} saved",
                                             Name, parcel, caps.RegionName, agentID);
                        }

                        WindlightRefresh(0, lchannel == null);
                        success = true;
                    }
                }
                else if (req is OSDArray)
                {
                    VEnv = new ViewerEnvironment();
                    VEnv.FromWLOSD(req);
                    StoreOnRegion(VEnv);
                    success = true;

                    WindlightRefresh(0);

                    m_log.InfoFormat("[{0}]: ExtEnvironment region {1} settings from agentID {2} saved",
                                     Name, caps.RegionName, agentID);

                    LLSDxmlEncode2.AddMap(sb);
                    LLSDxmlEncode2.AddElem("messageID", UUID.Zero, sb);
                    LLSDxmlEncode2.AddElem("regionID", regionID, sb);
                    LLSDxmlEncode2.AddElem("success", success, sb);
                    LLSDxmlEncode2.AddEndMap(sb);
                    httpResponse.RawBuffer  = LLSDxmlEncode2.EndToBytes(sb);
                    httpResponse.StatusCode = (int)HttpStatusCode.OK;
                    return;
                }
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[{0}]: ExtEnvironment settings not saved for region {1}, Exception: {2} - {3}",
                                  Name, caps.RegionName, e.Message, e.StackTrace);

                success = false;
                message = String.Format("ExtEnvironment Set for region {0} has failed, settings not saved.", caps.RegionName);
            }

Error:
            LLSDxmlEncode2.AddMap(sb);
            LLSDxmlEncode2.AddElem("success", success, sb);
            if (!success)
            {
                LLSDxmlEncode2.AddElem("message", message, sb);
            }
            LLSDxmlEncode2.AddEndMap(sb);

            httpResponse.RawBuffer  = LLSDxmlEncode2.EndToBytes(sb);
            httpResponse.StatusCode = (int)HttpStatusCode.OK;
        }
Beispiel #11
0
        private void GetExtEnvironmentSettings(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID agentID)
        {
            int parcelid = -1;

            if (httpRequest.Query.Count > 0)
            {
                if (httpRequest.Query.ContainsKey("parcelid"))
                {
                    Int32.TryParse((string)httpRequest.Query["parcelid"], out parcelid);
                }
            }

            ScenePresence sp = m_scene.GetScenePresence(agentID);

            if (sp == null)
            {
                httpResponse.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
                httpResponse.AddHeader("Retry-After", "5");
                return;
            }

            ViewerEnvironment VEnv = null;

            if (sp.Environment != null)
            {
                VEnv = sp.Environment;
            }
            else if (parcelid == -1)
            {
                VEnv = GetRegionEnvironment();
            }
            else
            {
                if (m_scene.RegionInfo.EstateSettings.AllowEnvironmentOverride)
                {
                    ILandObject land = m_scene.LandChannel.GetLandObject(parcelid);
                    if (land != null && land.LandData != null && land.LandData.Environment != null)
                    {
                        VEnv = land.LandData.Environment;
                    }
                }
                if (VEnv == null)
                {
                    OSD def = ViewerEnvironment.DefaultToOSD(regionID, parcelid);
                    httpResponse.RawBuffer  = OSDParser.SerializeLLSDXmlToBytes(def);
                    httpResponse.StatusCode = (int)HttpStatusCode.OK;
                    return;
                }
            }

            byte[] envBytes = VEnv.ToCapBytes(regionID, parcelid);
            if (envBytes == null)
            {
                osUTF8 sb = LLSDxmlEncode2.Start();
                LLSDxmlEncode2.AddArray(sb);
                LLSDxmlEncode2.AddMap(sb);
                LLSDxmlEncode2.AddElem("messageID", UUID.Zero, sb);
                LLSDxmlEncode2.AddElem("regionID", regionID, sb);
                LLSDxmlEncode2.AddEndMap(sb);
                LLSDxmlEncode2.AddEndArray(sb);
                httpResponse.RawBuffer = LLSDxmlEncode2.EndToBytes(sb);
            }
            else
            {
                httpResponse.RawBuffer = envBytes;
            }

            httpResponse.StatusCode = (int)HttpStatusCode.OK;
        }