public void StoreOnRegion(ViewerEnvironment VEnv)
 {
     try
     {
         if (VEnv == null)
         {
             m_scene.SimulationDataService.RemoveRegionEnvironmentSettings(regionID);
             m_scene.RegionEnvironment = null;
             m_regionEnvVersion        = -1;
         }
         else
         {
             m_regionEnvVersion++;
             VEnv.version = m_regionEnvVersion;
             OSD env = VEnv.ToOSD();
             //m_scene.SimulationDataService.StoreRegionEnvironmentSettings(regionID, OSDParser.SerializeLLSDXmlString(env));
             m_scene.SimulationDataService.StoreRegionEnvironmentSettings(regionID, OSDParser.SerializeLLSDNotationFull(env));
             m_scene.RegionEnvironment = VEnv;
         }
         m_framets = 0;
         UpdateEnvTime();
     }
     catch (Exception e)
     {
         m_log.ErrorFormat("[Environment {0}] failed to store Environment {1}", m_scene.Name, e.Message);
     }
 }
        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);
                }
            }

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

            if (sp != null && sp.Environment != null)
            {
                if (parcelid == -1)
                {
                    VEnv = sp.Environment;
                }
                else
                {
                    OSD def = ViewerEnvironment.DefaultToOSD(regionID, parcelid);
                    httpResponse.RawBuffer  = OSDParser.SerializeLLSDXmlToBytes(def);
                    httpResponse.StatusCode = (int)HttpStatusCode.OK;
                    return;
                }
            }
            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;
                }
            }

            OSDMap map  = new OSDMap();
            OSDMap cenv = (OSDMap)VEnv.ToOSD();

            cenv["parcel_id"]  = parcelid;
            cenv["region_id"]  = regionID;
            map["environment"] = cenv;
            map["parcel_id"]   = parcelid;
            map["success"]     = true;

            string env = OSDParser.SerializeLLSDXmlString(map);

            if (String.IsNullOrEmpty(env))
            {
                StringBuilder sb = LLSDxmlEncode.Start();
                LLSDxmlEncode.AddArray(sb);
                LLSDxmlEncode.AddMap(sb);
                LLSDxmlEncode.AddElem("messageID", UUID.Zero, sb);
                LLSDxmlEncode.AddElem("regionID", regionID, sb);
                LLSDxmlEncode.AddEndMap(sb);
                LLSDxmlEncode.AddEndArray(sb);
                env = LLSDxmlEncode.End(sb);
            }

            httpResponse.RawBuffer  = Util.UTF8NBGetbytes(env);
            httpResponse.StatusCode = (int)HttpStatusCode.OK;
        }