From 6cf90e55162e62f048489c49029bd9bbf884c3c3 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 11 Nov 2012 08:38:39 -0800 Subject: One more module converted: LightShareModule. --- .../CoreModules/LightShare/LightShareModule.cs | 93 +++++++++++++--------- 1 file changed, 55 insertions(+), 38 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/LightShare/LightShareModule.cs b/OpenSim/Region/CoreModules/LightShare/LightShareModule.cs index 16cbbf5..c9a263f 100644 --- a/OpenSim/Region/CoreModules/LightShare/LightShareModule.cs +++ b/OpenSim/Region/CoreModules/LightShare/LightShareModule.cs @@ -37,11 +37,12 @@ using OpenSim.Framework; using OpenSim.Region.CoreModules.Framework.InterfaceCommander; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; - +using Mono.Addins; namespace OpenSim.Region.CoreModules.World.LightShare { - public class LightShareModule : IRegionModule, ICommandableModule + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] + public class LightShareModule : INonSharedRegionModule, ICommandableModule { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private readonly Commander m_commander = new Commander("windlight"); @@ -70,12 +71,8 @@ namespace OpenSim.Region.CoreModules.World.LightShare } } - public void Initialise(Scene scene, IConfigSource config) + public void Initialise(IConfigSource config) { - m_scene = scene; - m_scene.RegisterModuleInterface(this); - m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; - // ini file settings try { @@ -86,19 +83,62 @@ namespace OpenSim.Region.CoreModules.World.LightShare m_log.Debug("[WINDLIGHT]: ini failure for enable_windlight - using default"); } - if (m_enableWindlight) - { - m_scene.EventManager.OnMakeRootAgent += EventManager_OnMakeRootAgent; - m_scene.EventManager.OnSaveNewWindlightProfile += EventManager_OnSaveNewWindlightProfile; - m_scene.EventManager.OnSendNewWindlightProfileTargeted += EventManager_OnSendNewWindlightProfileTargeted; - m_scene.LoadWindlightProfile(); - } + m_log.DebugFormat("[WINDLIGHT]: windlight module {0}", (m_enableWindlight ? "enabled" : "disabled")); + } + + public void AddRegion(Scene scene) + { + if (!m_enableWindlight) + return; + + m_scene = scene; + //m_scene.RegisterModuleInterface(this); + m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; + + m_scene.EventManager.OnMakeRootAgent += EventManager_OnMakeRootAgent; + m_scene.EventManager.OnSaveNewWindlightProfile += EventManager_OnSaveNewWindlightProfile; + m_scene.EventManager.OnSendNewWindlightProfileTargeted += EventManager_OnSendNewWindlightProfileTargeted; + m_scene.LoadWindlightProfile(); InstallCommands(); + } + + public void RemoveRegion(Scene scene) + { + if (!m_enableWindlight) + return; + + m_scene.EventManager.OnPluginConsole -= EventManager_OnPluginConsole; + + m_scene.EventManager.OnMakeRootAgent -= EventManager_OnMakeRootAgent; + m_scene.EventManager.OnSaveNewWindlightProfile -= EventManager_OnSaveNewWindlightProfile; + m_scene.EventManager.OnSendNewWindlightProfileTargeted -= EventManager_OnSendNewWindlightProfileTargeted; + + m_scene = null; + } - m_log.Debug("[WINDLIGHT]: Initialised windlight module"); + public void Close() + { + } + + public string Name + { + get { return "LightShareModule"; } } + public void RegionLoaded(Scene scene) + { + } + + public Type ReplaceableInterface + { + get { return null; } + } + + #endregion + + #region events + private List compileWindlightSettings(RegionLightShareData wl) { byte[] mBlock = new Byte[249]; @@ -186,29 +226,6 @@ namespace OpenSim.Region.CoreModules.World.LightShare m_scene.ForEachRootClient(SendProfileToClient); } - public void PostInitialise() - { - - } - - public void Close() - { - } - - public string Name - { - get { return "LightShareModule"; } - } - - public bool IsSharedModule - { - get { return false; } - } - - #endregion - - #region events - #endregion #region ICommandableModule Members -- cgit v1.1 From 37c970090401b620bf58be1d7618e3637c283cfe Mon Sep 17 00:00:00 2001 From: PixelTomsen Date: Sun, 11 Nov 2012 19:12:06 +0100 Subject: moving windlight-sources to correct namespace-named folder (world); add LightShare as Interface Signed-off-by: Diva Canto --- .../CoreModules/LightShare/EnvironmentModule.cs | 224 --------------- .../CoreModules/LightShare/LightShareModule.cs | 300 --------------------- .../World/LightShare/EnvironmentModule.cs | 224 +++++++++++++++ .../World/LightShare/LightShareModule.cs | 297 ++++++++++++++++++++ .../Framework/Interfaces/ILightShareModule.cs | 33 +++ 5 files changed, 554 insertions(+), 524 deletions(-) delete mode 100644 OpenSim/Region/CoreModules/LightShare/EnvironmentModule.cs delete mode 100644 OpenSim/Region/CoreModules/LightShare/LightShareModule.cs create mode 100644 OpenSim/Region/CoreModules/World/LightShare/EnvironmentModule.cs create mode 100644 OpenSim/Region/CoreModules/World/LightShare/LightShareModule.cs create mode 100644 OpenSim/Region/Framework/Interfaces/ILightShareModule.cs (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/LightShare/EnvironmentModule.cs b/OpenSim/Region/CoreModules/LightShare/EnvironmentModule.cs deleted file mode 100644 index 1526886..0000000 --- a/OpenSim/Region/CoreModules/LightShare/EnvironmentModule.cs +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Reflection; -using OpenMetaverse; -using OpenSim.Framework; -using OpenSim.Framework.Capabilities; -using OpenSim.Framework.Servers.HttpServer; -using OpenSim.Region.Framework.Interfaces; -using OpenSim.Region.Framework.Scenes; -using log4net; -using Nini.Config; -using Mono.Addins; - -using Caps = OpenSim.Framework.Capabilities.Caps; - - -namespace OpenSim.Region.CoreModules.World.LightShare -{ - [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "EnvironmentModule")] - - public class EnvironmentModule : INonSharedRegionModule, IEnvironmentModule - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - private Scene m_scene = null; - private UUID regionID = UUID.Zero; - private static bool Enabled = false; - - private static readonly string capsName = "EnvironmentSettings"; - private static readonly string capsBase = "/CAPS/0020/"; - - private LLSDEnvironmentSetResponse setResponse = null; - - #region INonSharedRegionModule - public void Initialise(IConfigSource source) - { - IConfig config = source.Configs["ClientStack.LindenCaps"]; - - if (null == config) - return; - - if (config.GetString("Cap_EnvironmentSettings", String.Empty) != "localhost") - { - m_log.InfoFormat("[{0}]: Module is disabled.", Name); - return; - } - - Enabled = true; - - m_log.InfoFormat("[{0}]: Module is enabled.", Name); - } - - public void Close() - { - } - - public string Name - { - get { return "EnvironmentModule"; } - } - - public Type ReplaceableInterface - { - get { return null; } - } - - public void AddRegion(Scene scene) - { - if (!Enabled) - return; - - scene.RegisterModuleInterface(this); - m_scene = scene; - regionID = scene.RegionInfo.RegionID; - } - - public void RegionLoaded(Scene scene) - { - if (!Enabled) - return; - - setResponse = new LLSDEnvironmentSetResponse(); - scene.EventManager.OnRegisterCaps += OnRegisterCaps; - } - - public void RemoveRegion(Scene scene) - { - if (Enabled) - return; - - scene.EventManager.OnRegisterCaps -= OnRegisterCaps; - m_scene = null; - } - #endregion - - #region IEnvironmentModule - public void ResetEnvironmentSettings(UUID regionUUID) - { - if (!Enabled) - return; - - m_scene.SimulationDataService.RemoveRegionEnvironmentSettings(regionUUID); - } - #endregion - - #region Events - private void OnRegisterCaps(UUID agentID, Caps caps) - { -// m_log.DebugFormat("[{0}]: Register capability for agentID {1} in region {2}", -// Name, agentID, caps.RegionName); - - string capsPath = capsBase + UUID.Random(); - - // Get handler - caps.RegisterHandler( - capsName, - new RestStreamHandler( - "GET", - capsPath, - (request, path, param, httpRequest, httpResponse) - => GetEnvironmentSettings(request, path, param, agentID, caps), - capsName, - agentID.ToString())); - - // Set handler - caps.HttpListener.AddStreamHandler( - new RestStreamHandler( - "POST", - capsPath, - (request, path, param, httpRequest, httpResponse) - => SetEnvironmentSettings(request, path, param, agentID, caps), - capsName, - agentID.ToString())); - } - #endregion - - private string GetEnvironmentSettings(string request, string path, string param, - UUID agentID, Caps caps) - { -// m_log.DebugFormat("[{0}]: Environment GET handle for agentID {1} in region {2}", -// Name, agentID, caps.RegionName); - - string env = String.Empty; - - try - { - env = m_scene.SimulationDataService.LoadRegionEnvironmentSettings(regionID); - } - catch (Exception e) - { - m_log.ErrorFormat("[{0}]: Unable to load environment settings for region {1}, Exception: {2} - {3}", - Name, caps.RegionName, e.Message, e.StackTrace); - } - - if (String.IsNullOrEmpty(env)) - env = EnvironmentSettings.EmptySettings(UUID.Zero, regionID); - - return env; - } - - private string SetEnvironmentSettings(string request, string path, string param, - UUID agentID, Caps caps) - { - -// m_log.DebugFormat("[{0}]: Environment SET handle from agentID {1} in region {2}", -// Name, agentID, caps.RegionName); - - setResponse.regionID = regionID; - setResponse.success = false; - - if (!m_scene.Permissions.CanIssueEstateCommand(agentID, false)) - { - setResponse.fail_reason = "Insufficient estate permissions, settings has not been saved."; - return LLSDHelpers.SerialiseLLSDReply(setResponse); - } - - try - { - m_scene.SimulationDataService.StoreRegionEnvironmentSettings(regionID, request); - setResponse.success = true; - - m_log.InfoFormat("[{0}]: New Environment settings has been saved from agentID {1} in region {2}", - Name, agentID, caps.RegionName); - } - catch (Exception e) - { - m_log.ErrorFormat("[{0}]: Environment settings has not been saved for region {1}, Exception: {2} - {3}", - Name, caps.RegionName, e.Message, e.StackTrace); - - setResponse.success = false; - setResponse.fail_reason = String.Format("Environment Set for region {0} has failed, settings has not been saved.", caps.RegionName); - } - - return LLSDHelpers.SerialiseLLSDReply(setResponse); - } - } -} - diff --git a/OpenSim/Region/CoreModules/LightShare/LightShareModule.cs b/OpenSim/Region/CoreModules/LightShare/LightShareModule.cs deleted file mode 100644 index c9a263f..0000000 --- a/OpenSim/Region/CoreModules/LightShare/LightShareModule.cs +++ /dev/null @@ -1,300 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using OpenMetaverse; -using log4net; -using Nini.Config; -using OpenSim.Data; -using OpenSim.Framework; -using OpenSim.Region.CoreModules.Framework.InterfaceCommander; -using OpenSim.Region.Framework.Interfaces; -using OpenSim.Region.Framework.Scenes; -using Mono.Addins; - -namespace OpenSim.Region.CoreModules.World.LightShare -{ - [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] - public class LightShareModule : INonSharedRegionModule, ICommandableModule - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private readonly Commander m_commander = new Commander("windlight"); - private Scene m_scene; - private static bool m_enableWindlight; - - #region ICommandableModule Members - - public ICommander CommandInterface - { - get { return m_commander; } - } - - #endregion - - #region IRegionModule Members - - public static bool EnableWindlight - { - get - { - return m_enableWindlight; - } - set - { - } - } - - public void Initialise(IConfigSource config) - { - // ini file settings - try - { - m_enableWindlight = config.Configs["LightShare"].GetBoolean("enable_windlight", false); - } - catch (Exception) - { - m_log.Debug("[WINDLIGHT]: ini failure for enable_windlight - using default"); - } - - m_log.DebugFormat("[WINDLIGHT]: windlight module {0}", (m_enableWindlight ? "enabled" : "disabled")); - } - - public void AddRegion(Scene scene) - { - if (!m_enableWindlight) - return; - - m_scene = scene; - //m_scene.RegisterModuleInterface(this); - m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; - - m_scene.EventManager.OnMakeRootAgent += EventManager_OnMakeRootAgent; - m_scene.EventManager.OnSaveNewWindlightProfile += EventManager_OnSaveNewWindlightProfile; - m_scene.EventManager.OnSendNewWindlightProfileTargeted += EventManager_OnSendNewWindlightProfileTargeted; - m_scene.LoadWindlightProfile(); - - InstallCommands(); - } - - public void RemoveRegion(Scene scene) - { - if (!m_enableWindlight) - return; - - m_scene.EventManager.OnPluginConsole -= EventManager_OnPluginConsole; - - m_scene.EventManager.OnMakeRootAgent -= EventManager_OnMakeRootAgent; - m_scene.EventManager.OnSaveNewWindlightProfile -= EventManager_OnSaveNewWindlightProfile; - m_scene.EventManager.OnSendNewWindlightProfileTargeted -= EventManager_OnSendNewWindlightProfileTargeted; - - m_scene = null; - } - - public void Close() - { - } - - public string Name - { - get { return "LightShareModule"; } - } - - public void RegionLoaded(Scene scene) - { - } - - public Type ReplaceableInterface - { - get { return null; } - } - - #endregion - - #region events - - private List compileWindlightSettings(RegionLightShareData wl) - { - byte[] mBlock = new Byte[249]; - int pos = 0; - - wl.waterColor.ToBytes(mBlock, 0); pos += 12; - Utils.FloatToBytes(wl.waterFogDensityExponent).CopyTo(mBlock, pos); pos += 4; - Utils.FloatToBytes(wl.underwaterFogModifier).CopyTo(mBlock, pos); pos += 4; - wl.reflectionWaveletScale.ToBytes(mBlock, pos); pos += 12; - Utils.FloatToBytes(wl.fresnelScale).CopyTo(mBlock, pos); pos += 4; - Utils.FloatToBytes(wl.fresnelOffset).CopyTo(mBlock, pos); pos += 4; - Utils.FloatToBytes(wl.refractScaleAbove).CopyTo(mBlock, pos); pos += 4; - Utils.FloatToBytes(wl.refractScaleBelow).CopyTo(mBlock, pos); pos += 4; - Utils.FloatToBytes(wl.blurMultiplier).CopyTo(mBlock, pos); pos += 4; - wl.bigWaveDirection.ToBytes(mBlock, pos); pos += 8; - wl.littleWaveDirection.ToBytes(mBlock, pos); pos += 8; - wl.normalMapTexture.ToBytes(mBlock, pos); pos += 16; - wl.horizon.ToBytes(mBlock, pos); pos += 16; - Utils.FloatToBytes(wl.hazeHorizon).CopyTo(mBlock, pos); pos += 4; - wl.blueDensity.ToBytes(mBlock, pos); pos += 16; - Utils.FloatToBytes(wl.hazeDensity).CopyTo(mBlock, pos); pos += 4; - Utils.FloatToBytes(wl.densityMultiplier).CopyTo(mBlock, pos); pos += 4; - Utils.FloatToBytes(wl.distanceMultiplier).CopyTo(mBlock, pos); pos += 4; - wl.sunMoonColor.ToBytes(mBlock, pos); pos += 16; - Utils.FloatToBytes(wl.sunMoonPosition).CopyTo(mBlock, pos); pos += 4; - wl.ambient.ToBytes(mBlock, pos); pos += 16; - Utils.FloatToBytes(wl.eastAngle).CopyTo(mBlock, pos); pos += 4; - Utils.FloatToBytes(wl.sunGlowFocus).CopyTo(mBlock, pos); pos += 4; - Utils.FloatToBytes(wl.sunGlowSize).CopyTo(mBlock, pos); pos += 4; - Utils.FloatToBytes(wl.sceneGamma).CopyTo(mBlock, pos); pos += 4; - Utils.FloatToBytes(wl.starBrightness).CopyTo(mBlock, pos); pos += 4; - wl.cloudColor.ToBytes(mBlock, pos); pos += 16; - wl.cloudXYDensity.ToBytes(mBlock, pos); pos += 12; - Utils.FloatToBytes(wl.cloudCoverage).CopyTo(mBlock, pos); pos += 4; - Utils.FloatToBytes(wl.cloudScale).CopyTo(mBlock, pos); pos += 4; - wl.cloudDetailXYDensity.ToBytes(mBlock, pos); pos += 12; - Utils.FloatToBytes(wl.cloudScrollX).CopyTo(mBlock, pos); pos += 4; - Utils.FloatToBytes(wl.cloudScrollY).CopyTo(mBlock, pos); pos += 4; - Utils.UInt16ToBytes(wl.maxAltitude).CopyTo(mBlock, pos); pos += 2; - mBlock[pos] = Convert.ToByte(wl.cloudScrollXLock); pos++; - mBlock[pos] = Convert.ToByte(wl.cloudScrollYLock); pos++; - mBlock[pos] = Convert.ToByte(wl.drawClassicClouds); pos++; - List param = new List(); - param.Add(mBlock); - return param; - } - - public void SendProfileToClient(IClientAPI client) - { - SendProfileToClient(client, m_scene.RegionInfo.WindlightSettings); - } - - public void SendProfileToClient(IClientAPI client, RegionLightShareData wl) - { - if (m_enableWindlight) - { - if (m_scene.RegionInfo.WindlightSettings.valid) - { - List param = compileWindlightSettings(wl); - client.SendGenericMessage("Windlight", param); - } - else - { - List param = new List(); - client.SendGenericMessage("WindlightReset", param); - } - } - } - - private void EventManager_OnMakeRootAgent(ScenePresence presence) - { - m_log.Debug("[WINDLIGHT]: Sending windlight scene to new client"); - SendProfileToClient(presence.ControllingClient); - } - - private void EventManager_OnSendNewWindlightProfileTargeted(RegionLightShareData wl, UUID pUUID) - { - IClientAPI client; - m_scene.TryGetClient(pUUID, out client); - SendProfileToClient(client, wl); - } - - private void EventManager_OnSaveNewWindlightProfile() - { - m_scene.ForEachRootClient(SendProfileToClient); - } - - #endregion - - #region ICommandableModule Members - - private void InstallCommands() - { - Command wlload = new Command("load", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleLoad, "Load windlight profile from the database and broadcast"); - Command wlenable = new Command("enable", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleEnable, "Enable the windlight plugin"); - Command wldisable = new Command("disable", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleDisable, "Disable the windlight plugin"); - - m_commander.RegisterCommand("load", wlload); - m_commander.RegisterCommand("enable", wlenable); - m_commander.RegisterCommand("disable", wldisable); - - m_scene.RegisterModuleCommander(m_commander); - } - - private void HandleLoad(Object[] args) - { - if (!m_enableWindlight) - { - m_log.InfoFormat("[WINDLIGHT]: Cannot load windlight profile, module disabled. Use 'windlight enable' first."); - } - else - { - m_log.InfoFormat("[WINDLIGHT]: Loading Windlight profile from database"); - m_scene.LoadWindlightProfile(); - m_log.InfoFormat("[WINDLIGHT]: Load complete"); - } - } - - private void HandleDisable(Object[] args) - { - m_log.InfoFormat("[WINDLIGHT]: Plugin now disabled"); - m_enableWindlight=false; - } - - private void HandleEnable(Object[] args) - { - m_log.InfoFormat("[WINDLIGHT]: Plugin now enabled"); - m_enableWindlight = true; - } - - /// - /// Processes commandline input. Do not call directly. - /// - /// Commandline arguments - private void EventManager_OnPluginConsole(string[] args) - { - if (args[0] == "windlight") - { - if (args.Length == 1) - { - m_commander.ProcessConsoleCommand("add", new string[0]); - return; - } - - string[] tmpArgs = new string[args.Length - 2]; - int i; - for (i = 2; i < args.Length; i++) - { - tmpArgs[i - 2] = args[i]; - } - - m_commander.ProcessConsoleCommand(args[1], tmpArgs); - } - } - #endregion - - } -} - diff --git a/OpenSim/Region/CoreModules/World/LightShare/EnvironmentModule.cs b/OpenSim/Region/CoreModules/World/LightShare/EnvironmentModule.cs new file mode 100644 index 0000000..c3cea7a --- /dev/null +++ b/OpenSim/Region/CoreModules/World/LightShare/EnvironmentModule.cs @@ -0,0 +1,224 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Reflection; +using OpenMetaverse; +using OpenSim.Framework; +using OpenSim.Framework.Capabilities; +using OpenSim.Framework.Servers.HttpServer; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using log4net; +using Nini.Config; +using Mono.Addins; + +using Caps = OpenSim.Framework.Capabilities.Caps; + + +namespace OpenSim.Region.CoreModules.World.LightShare +{ + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "EnvironmentModule")] + + public class EnvironmentModule : INonSharedRegionModule, IEnvironmentModule + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private Scene m_scene = null; + private UUID regionID = UUID.Zero; + private static bool Enabled = false; + + private static readonly string capsName = "EnvironmentSettings"; + private static readonly string capsBase = "/CAPS/0020/"; + + private LLSDEnvironmentSetResponse setResponse = null; + + #region INonSharedRegionModule + public void Initialise(IConfigSource source) + { + IConfig config = source.Configs["ClientStack.LindenCaps"]; + + if (null == config) + return; + + if (config.GetString("Cap_EnvironmentSettings", String.Empty) != "localhost") + { + m_log.InfoFormat("[{0}]: Module is disabled.", Name); + return; + } + + Enabled = true; + + m_log.InfoFormat("[{0}]: Module is enabled.", Name); + } + + public void Close() + { + } + + public string Name + { + get { return "EnvironmentModule"; } + } + + public Type ReplaceableInterface + { + get { return null; } + } + + public void AddRegion(Scene scene) + { + if (!Enabled) + return; + + scene.RegisterModuleInterface(this); + m_scene = scene; + regionID = scene.RegionInfo.RegionID; + } + + public void RegionLoaded(Scene scene) + { + if (!Enabled) + return; + + setResponse = new LLSDEnvironmentSetResponse(); + scene.EventManager.OnRegisterCaps += OnRegisterCaps; + } + + public void RemoveRegion(Scene scene) + { + if (Enabled) + return; + + scene.EventManager.OnRegisterCaps -= OnRegisterCaps; + m_scene = null; + } + #endregion + + #region IEnvironmentModule + public void ResetEnvironmentSettings(UUID regionUUID) + { + if (!Enabled) + return; + + m_scene.SimulationDataService.RemoveRegionEnvironmentSettings(regionUUID); + } + #endregion + + #region Events + private void OnRegisterCaps(UUID agentID, Caps caps) + { + // m_log.DebugFormat("[{0}]: Register capability for agentID {1} in region {2}", + // Name, agentID, caps.RegionName); + + string capsPath = capsBase + UUID.Random(); + + // Get handler + caps.RegisterHandler( + capsName, + new RestStreamHandler( + "GET", + capsPath, + (request, path, param, httpRequest, httpResponse) + => GetEnvironmentSettings(request, path, param, agentID, caps), + capsName, + agentID.ToString())); + + // Set handler + caps.HttpListener.AddStreamHandler( + new RestStreamHandler( + "POST", + capsPath, + (request, path, param, httpRequest, httpResponse) + => SetEnvironmentSettings(request, path, param, agentID, caps), + capsName, + agentID.ToString())); + } + #endregion + + private string GetEnvironmentSettings(string request, string path, string param, + UUID agentID, Caps caps) + { + // m_log.DebugFormat("[{0}]: Environment GET handle for agentID {1} in region {2}", + // Name, agentID, caps.RegionName); + + string env = String.Empty; + + try + { + env = m_scene.SimulationDataService.LoadRegionEnvironmentSettings(regionID); + } + catch (Exception e) + { + m_log.ErrorFormat("[{0}]: Unable to load environment settings for region {1}, Exception: {2} - {3}", + Name, caps.RegionName, e.Message, e.StackTrace); + } + + if (String.IsNullOrEmpty(env)) + env = EnvironmentSettings.EmptySettings(UUID.Zero, regionID); + + return env; + } + + private string SetEnvironmentSettings(string request, string path, string param, + UUID agentID, Caps caps) + { + + // m_log.DebugFormat("[{0}]: Environment SET handle from agentID {1} in region {2}", + // Name, agentID, caps.RegionName); + + setResponse.regionID = regionID; + setResponse.success = false; + + if (!m_scene.Permissions.CanIssueEstateCommand(agentID, false)) + { + setResponse.fail_reason = "Insufficient estate permissions, settings has not been saved."; + return LLSDHelpers.SerialiseLLSDReply(setResponse); + } + + try + { + m_scene.SimulationDataService.StoreRegionEnvironmentSettings(regionID, request); + setResponse.success = true; + + m_log.InfoFormat("[{0}]: New Environment settings has been saved from agentID {1} in region {2}", + Name, agentID, caps.RegionName); + } + catch (Exception e) + { + m_log.ErrorFormat("[{0}]: Environment settings has not been saved for region {1}, Exception: {2} - {3}", + Name, caps.RegionName, e.Message, e.StackTrace); + + setResponse.success = false; + setResponse.fail_reason = String.Format("Environment Set for region {0} has failed, settings has not been saved.", caps.RegionName); + } + + return LLSDHelpers.SerialiseLLSDReply(setResponse); + } + } +} + diff --git a/OpenSim/Region/CoreModules/World/LightShare/LightShareModule.cs b/OpenSim/Region/CoreModules/World/LightShare/LightShareModule.cs new file mode 100644 index 0000000..bd04ded --- /dev/null +++ b/OpenSim/Region/CoreModules/World/LightShare/LightShareModule.cs @@ -0,0 +1,297 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.Reflection; +using OpenMetaverse; +using OpenSim.Framework; +using OpenSim.Region.CoreModules.Framework.InterfaceCommander; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using log4net; +using Nini.Config; +using Mono.Addins; + +namespace OpenSim.Region.CoreModules.World.LightShare +{ + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] + public class LightShareModule : INonSharedRegionModule, ILightShareModule, ICommandableModule + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private readonly Commander m_commander = new Commander("windlight"); + private Scene m_scene; + private static bool m_enableWindlight; + + #region ICommandableModule Members + + public ICommander CommandInterface + { + get { return m_commander; } + } + + #endregion + + #region INonSharedRegionModule Members + + public void Initialise(IConfigSource config) + { + try + { + m_enableWindlight = config.Configs["LightShare"].GetBoolean("enable_windlight", false); + } + catch (Exception) + { + m_log.Debug("[WINDLIGHT]: ini failure for enable_windlight - using default"); + } + + m_log.DebugFormat("[WINDLIGHT]: windlight module {0}", (m_enableWindlight ? "enabled" : "disabled")); + } + + public void AddRegion(Scene scene) + { + if (!m_enableWindlight) + return; + + m_scene = scene; + m_scene.RegisterModuleInterface(this); + m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; + + m_scene.EventManager.OnMakeRootAgent += EventManager_OnMakeRootAgent; + m_scene.EventManager.OnSaveNewWindlightProfile += EventManager_OnSaveNewWindlightProfile; + m_scene.EventManager.OnSendNewWindlightProfileTargeted += EventManager_OnSendNewWindlightProfileTargeted; + m_scene.LoadWindlightProfile(); + + InstallCommands(); + } + + public void RemoveRegion(Scene scene) + { + if (!m_enableWindlight) + return; + + m_scene.EventManager.OnPluginConsole -= EventManager_OnPluginConsole; + + m_scene.EventManager.OnMakeRootAgent -= EventManager_OnMakeRootAgent; + m_scene.EventManager.OnSaveNewWindlightProfile -= EventManager_OnSaveNewWindlightProfile; + m_scene.EventManager.OnSendNewWindlightProfileTargeted -= EventManager_OnSendNewWindlightProfileTargeted; + + m_scene = null; + } + + public void Close() + { + } + + public string Name + { + get { return "LightShareModule"; } + } + + public void RegionLoaded(Scene scene) + { + } + + public Type ReplaceableInterface + { + get { return null; } + } + + #endregion + + public static bool EnableWindlight + { + get + { + return m_enableWindlight; + } + set + { + } + } + + #region events + + private List compileWindlightSettings(RegionLightShareData wl) + { + byte[] mBlock = new Byte[249]; + int pos = 0; + + wl.waterColor.ToBytes(mBlock, 0); pos += 12; + Utils.FloatToBytes(wl.waterFogDensityExponent).CopyTo(mBlock, pos); pos += 4; + Utils.FloatToBytes(wl.underwaterFogModifier).CopyTo(mBlock, pos); pos += 4; + wl.reflectionWaveletScale.ToBytes(mBlock, pos); pos += 12; + Utils.FloatToBytes(wl.fresnelScale).CopyTo(mBlock, pos); pos += 4; + Utils.FloatToBytes(wl.fresnelOffset).CopyTo(mBlock, pos); pos += 4; + Utils.FloatToBytes(wl.refractScaleAbove).CopyTo(mBlock, pos); pos += 4; + Utils.FloatToBytes(wl.refractScaleBelow).CopyTo(mBlock, pos); pos += 4; + Utils.FloatToBytes(wl.blurMultiplier).CopyTo(mBlock, pos); pos += 4; + wl.bigWaveDirection.ToBytes(mBlock, pos); pos += 8; + wl.littleWaveDirection.ToBytes(mBlock, pos); pos += 8; + wl.normalMapTexture.ToBytes(mBlock, pos); pos += 16; + wl.horizon.ToBytes(mBlock, pos); pos += 16; + Utils.FloatToBytes(wl.hazeHorizon).CopyTo(mBlock, pos); pos += 4; + wl.blueDensity.ToBytes(mBlock, pos); pos += 16; + Utils.FloatToBytes(wl.hazeDensity).CopyTo(mBlock, pos); pos += 4; + Utils.FloatToBytes(wl.densityMultiplier).CopyTo(mBlock, pos); pos += 4; + Utils.FloatToBytes(wl.distanceMultiplier).CopyTo(mBlock, pos); pos += 4; + wl.sunMoonColor.ToBytes(mBlock, pos); pos += 16; + Utils.FloatToBytes(wl.sunMoonPosition).CopyTo(mBlock, pos); pos += 4; + wl.ambient.ToBytes(mBlock, pos); pos += 16; + Utils.FloatToBytes(wl.eastAngle).CopyTo(mBlock, pos); pos += 4; + Utils.FloatToBytes(wl.sunGlowFocus).CopyTo(mBlock, pos); pos += 4; + Utils.FloatToBytes(wl.sunGlowSize).CopyTo(mBlock, pos); pos += 4; + Utils.FloatToBytes(wl.sceneGamma).CopyTo(mBlock, pos); pos += 4; + Utils.FloatToBytes(wl.starBrightness).CopyTo(mBlock, pos); pos += 4; + wl.cloudColor.ToBytes(mBlock, pos); pos += 16; + wl.cloudXYDensity.ToBytes(mBlock, pos); pos += 12; + Utils.FloatToBytes(wl.cloudCoverage).CopyTo(mBlock, pos); pos += 4; + Utils.FloatToBytes(wl.cloudScale).CopyTo(mBlock, pos); pos += 4; + wl.cloudDetailXYDensity.ToBytes(mBlock, pos); pos += 12; + Utils.FloatToBytes(wl.cloudScrollX).CopyTo(mBlock, pos); pos += 4; + Utils.FloatToBytes(wl.cloudScrollY).CopyTo(mBlock, pos); pos += 4; + Utils.UInt16ToBytes(wl.maxAltitude).CopyTo(mBlock, pos); pos += 2; + mBlock[pos] = Convert.ToByte(wl.cloudScrollXLock); pos++; + mBlock[pos] = Convert.ToByte(wl.cloudScrollYLock); pos++; + mBlock[pos] = Convert.ToByte(wl.drawClassicClouds); pos++; + List param = new List(); + param.Add(mBlock); + return param; + } + + public void SendProfileToClient(IClientAPI client) + { + SendProfileToClient(client, m_scene.RegionInfo.WindlightSettings); + } + + public void SendProfileToClient(IClientAPI client, RegionLightShareData wl) + { + if (m_enableWindlight) + { + if (m_scene.RegionInfo.WindlightSettings.valid) + { + List param = compileWindlightSettings(wl); + client.SendGenericMessage("Windlight", param); + } + else + { + List param = new List(); + client.SendGenericMessage("WindlightReset", param); + } + } + } + + private void EventManager_OnMakeRootAgent(ScenePresence presence) + { + m_log.Debug("[WINDLIGHT]: Sending windlight scene to new client"); + SendProfileToClient(presence.ControllingClient); + } + + private void EventManager_OnSendNewWindlightProfileTargeted(RegionLightShareData wl, UUID pUUID) + { + IClientAPI client; + m_scene.TryGetClient(pUUID, out client); + SendProfileToClient(client, wl); + } + + private void EventManager_OnSaveNewWindlightProfile() + { + m_scene.ForEachRootClient(SendProfileToClient); + } + + #endregion + + #region ICommandableModule Members + + private void InstallCommands() + { + Command wlload = new Command("load", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleLoad, "Load windlight profile from the database and broadcast"); + Command wlenable = new Command("enable", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleEnable, "Enable the windlight plugin"); + Command wldisable = new Command("disable", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleDisable, "Disable the windlight plugin"); + + m_commander.RegisterCommand("load", wlload); + m_commander.RegisterCommand("enable", wlenable); + m_commander.RegisterCommand("disable", wldisable); + + m_scene.RegisterModuleCommander(m_commander); + } + + private void HandleLoad(Object[] args) + { + if (!m_enableWindlight) + { + m_log.InfoFormat("[WINDLIGHT]: Cannot load windlight profile, module disabled. Use 'windlight enable' first."); + } + else + { + m_log.InfoFormat("[WINDLIGHT]: Loading Windlight profile from database"); + m_scene.LoadWindlightProfile(); + m_log.InfoFormat("[WINDLIGHT]: Load complete"); + } + } + + private void HandleDisable(Object[] args) + { + m_log.InfoFormat("[WINDLIGHT]: Plugin now disabled"); + m_enableWindlight = false; + } + + private void HandleEnable(Object[] args) + { + m_log.InfoFormat("[WINDLIGHT]: Plugin now enabled"); + m_enableWindlight = true; + } + + /// + /// Processes commandline input. Do not call directly. + /// + /// Commandline arguments + private void EventManager_OnPluginConsole(string[] args) + { + if (args[0] == "windlight") + { + if (args.Length == 1) + { + m_commander.ProcessConsoleCommand("add", new string[0]); + return; + } + + string[] tmpArgs = new string[args.Length - 2]; + int i; + for (i = 2; i < args.Length; i++) + { + tmpArgs[i - 2] = args[i]; + } + + m_commander.ProcessConsoleCommand(args[1], tmpArgs); + } + } + #endregion + + } +} + diff --git a/OpenSim/Region/Framework/Interfaces/ILightShareModule.cs b/OpenSim/Region/Framework/Interfaces/ILightShareModule.cs new file mode 100644 index 0000000..b5fd24f --- /dev/null +++ b/OpenSim/Region/Framework/Interfaces/ILightShareModule.cs @@ -0,0 +1,33 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +namespace OpenSim.Region.Framework.Interfaces +{ + public interface ILightShareModule + { + } +} \ No newline at end of file -- cgit v1.1