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; StringBuilder sb = LLSDxmlEncode.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 | GroupPowers.LandEdit), 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 OpenMetaverse.StructuredData.OSDMap) { OSDMap map = req as OpenMetaverse.StructuredData.OSDMap; if (map.TryGetValue("environment", out OSD env)) { if (VEnv == null) { // need a proper clone VEnv = m_DefaultEnv.Clone(); } OSDMap evmap = (OSDMap)env; 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); VEnv.CycleFromOSD(oenv); } catch { httpResponse.StatusCode = (int)HttpStatusCode.NotFound; return; } } 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); LLSDxmlEncode.AddMap(sb); LLSDxmlEncode.AddElem("messageID", UUID.Zero, sb); LLSDxmlEncode.AddElem("regionID", regionID, sb); LLSDxmlEncode.AddElem("success", success, sb); LLSDxmlEncode.AddEndMap(sb); httpResponse.RawBuffer = Util.UTF8NBGetbytes(LLSDxmlEncode.End(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: string response; LLSDxmlEncode.AddMap(sb); LLSDxmlEncode.AddElem("success", success, sb); if (!success) { LLSDxmlEncode.AddElem("message", message, sb); } LLSDxmlEncode.AddEndMap(sb); response = LLSDxmlEncode.End(sb); httpResponse.RawBuffer = Util.UTF8NBGetbytes(response); httpResponse.StatusCode = (int)HttpStatusCode.OK; }
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: StringBuilder sb = LLSDxmlEncode.Start(); LLSDxmlEncode.AddMap(sb); LLSDxmlEncode.AddElem("messageID", UUID.Zero, sb); LLSDxmlEncode.AddElem("regionID", regionID, sb); LLSDxmlEncode.AddElem("success", success, sb); if (!success) { LLSDxmlEncode.AddElem("fail_reason", fail_reason, sb); } LLSDxmlEncode.AddEndMap(sb); response.RawBuffer = Util.UTF8NBGetbytes(LLSDxmlEncode.End(sb)); response.StatusCode = (int)HttpStatusCode.OK; }
public void RegionLoaded(Scene scene) { if (!Enabled) { return; } m_estateModule = scene.RequestModuleInterface <IEstateModule>(); if (m_estateModule == null) { Enabled = false; return; } m_eventQueue = m_scene.RequestModuleInterface <IEventQueue>(); if (m_eventQueue == null) { Enabled = false; return; } m_assetService = m_scene.AssetService; if (m_assetService == null) { Enabled = false; return; } m_landChannel = m_scene.LandChannel; if (m_landChannel == null) { Enabled = false; return; } if (m_DefaultEnv == null) { AssetBase defEnv = m_assetService.Get(m_defaultDayAssetID); if (defEnv != null) { byte[] envData = defEnv.Data; try { OSD oenv = OSDParser.Deserialize(envData); m_DefaultEnv = new ViewerEnvironment(); m_DefaultEnv.CycleFromOSD(oenv); } catch (Exception e) { m_DefaultEnv = null; m_log.WarnFormat("[Environment {0}]: failed to decode default environment asset: {1}", m_scene.Name, e.Message); } } } if (m_DefaultEnv == null) { m_DefaultEnv = new ViewerEnvironment(); } string senv = scene.SimulationDataService.LoadRegionEnvironmentSettings(scene.RegionInfo.RegionID); if (!string.IsNullOrEmpty(senv)) { try { OSD oenv = OSDParser.Deserialize(senv); ViewerEnvironment VEnv = new ViewerEnvironment(); if (oenv is OSDArray) { VEnv.FromWLOSD(oenv); } else { VEnv.FromOSD(oenv); } scene.RegionEnvironment = VEnv; m_regionEnvVersion = VEnv.version; } catch (Exception e) { m_log.ErrorFormat("[Environment {0}] failed to load initial Environment {1}", m_scene.Name, e.Message); scene.RegionEnvironment = null; m_regionEnvVersion = -1; } } else { scene.RegionEnvironment = null; m_regionEnvVersion = -1; } m_framets = 0; UpdateEnvTime(); scene.EventManager.OnRegisterCaps += OnRegisterCaps; scene.EventManager.OnFrame += UpdateEnvTime; scene.EventManager.OnAvatarEnteringNewParcel += OnAvatarEnteringNewParcel; }