aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/LightShare
diff options
context:
space:
mode:
authorPixelTomsen2012-11-11 19:12:06 +0100
committerDiva Canto2012-11-11 11:17:40 -0800
commit37c970090401b620bf58be1d7618e3637c283cfe (patch)
tree1f2bb4a849124369413c05e36b25737c69eee1e0 /OpenSim/Region/CoreModules/LightShare
parentremove entry OpenGridProtocol in OpenSimDefaults.ini - module was deleted (diff)
downloadopensim-SC_OLD-37c970090401b620bf58be1d7618e3637c283cfe.zip
opensim-SC_OLD-37c970090401b620bf58be1d7618e3637c283cfe.tar.gz
opensim-SC_OLD-37c970090401b620bf58be1d7618e3637c283cfe.tar.bz2
opensim-SC_OLD-37c970090401b620bf58be1d7618e3637c283cfe.tar.xz
moving windlight-sources to correct namespace-named folder (world); add LightShare as Interface
Signed-off-by: Diva Canto <diva@metaverseink.com>
Diffstat (limited to 'OpenSim/Region/CoreModules/LightShare')
-rw-r--r--OpenSim/Region/CoreModules/LightShare/EnvironmentModule.cs224
-rw-r--r--OpenSim/Region/CoreModules/LightShare/LightShareModule.cs300
2 files changed, 0 insertions, 524 deletions
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 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Reflection;
30using OpenMetaverse;
31using OpenSim.Framework;
32using OpenSim.Framework.Capabilities;
33using OpenSim.Framework.Servers.HttpServer;
34using OpenSim.Region.Framework.Interfaces;
35using OpenSim.Region.Framework.Scenes;
36using log4net;
37using Nini.Config;
38using Mono.Addins;
39
40using Caps = OpenSim.Framework.Capabilities.Caps;
41
42
43namespace OpenSim.Region.CoreModules.World.LightShare
44{
45 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "EnvironmentModule")]
46
47 public class EnvironmentModule : INonSharedRegionModule, IEnvironmentModule
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private Scene m_scene = null;
52 private UUID regionID = UUID.Zero;
53 private static bool Enabled = false;
54
55 private static readonly string capsName = "EnvironmentSettings";
56 private static readonly string capsBase = "/CAPS/0020/";
57
58 private LLSDEnvironmentSetResponse setResponse = null;
59
60 #region INonSharedRegionModule
61 public void Initialise(IConfigSource source)
62 {
63 IConfig config = source.Configs["ClientStack.LindenCaps"];
64
65 if (null == config)
66 return;
67
68 if (config.GetString("Cap_EnvironmentSettings", String.Empty) != "localhost")
69 {
70 m_log.InfoFormat("[{0}]: Module is disabled.", Name);
71 return;
72 }
73
74 Enabled = true;
75
76 m_log.InfoFormat("[{0}]: Module is enabled.", Name);
77 }
78
79 public void Close()
80 {
81 }
82
83 public string Name
84 {
85 get { return "EnvironmentModule"; }
86 }
87
88 public Type ReplaceableInterface
89 {
90 get { return null; }
91 }
92
93 public void AddRegion(Scene scene)
94 {
95 if (!Enabled)
96 return;
97
98 scene.RegisterModuleInterface<IEnvironmentModule>(this);
99 m_scene = scene;
100 regionID = scene.RegionInfo.RegionID;
101 }
102
103 public void RegionLoaded(Scene scene)
104 {
105 if (!Enabled)
106 return;
107
108 setResponse = new LLSDEnvironmentSetResponse();
109 scene.EventManager.OnRegisterCaps += OnRegisterCaps;
110 }
111
112 public void RemoveRegion(Scene scene)
113 {
114 if (Enabled)
115 return;
116
117 scene.EventManager.OnRegisterCaps -= OnRegisterCaps;
118 m_scene = null;
119 }
120 #endregion
121
122 #region IEnvironmentModule
123 public void ResetEnvironmentSettings(UUID regionUUID)
124 {
125 if (!Enabled)
126 return;
127
128 m_scene.SimulationDataService.RemoveRegionEnvironmentSettings(regionUUID);
129 }
130 #endregion
131
132 #region Events
133 private void OnRegisterCaps(UUID agentID, Caps caps)
134 {
135// m_log.DebugFormat("[{0}]: Register capability for agentID {1} in region {2}",
136// Name, agentID, caps.RegionName);
137
138 string capsPath = capsBase + UUID.Random();
139
140 // Get handler
141 caps.RegisterHandler(
142 capsName,
143 new RestStreamHandler(
144 "GET",
145 capsPath,
146 (request, path, param, httpRequest, httpResponse)
147 => GetEnvironmentSettings(request, path, param, agentID, caps),
148 capsName,
149 agentID.ToString()));
150
151 // Set handler
152 caps.HttpListener.AddStreamHandler(
153 new RestStreamHandler(
154 "POST",
155 capsPath,
156 (request, path, param, httpRequest, httpResponse)
157 => SetEnvironmentSettings(request, path, param, agentID, caps),
158 capsName,
159 agentID.ToString()));
160 }
161 #endregion
162
163 private string GetEnvironmentSettings(string request, string path, string param,
164 UUID agentID, Caps caps)
165 {
166// m_log.DebugFormat("[{0}]: Environment GET handle for agentID {1} in region {2}",
167// Name, agentID, caps.RegionName);
168
169 string env = String.Empty;
170
171 try
172 {
173 env = m_scene.SimulationDataService.LoadRegionEnvironmentSettings(regionID);
174 }
175 catch (Exception e)
176 {
177 m_log.ErrorFormat("[{0}]: Unable to load environment settings for region {1}, Exception: {2} - {3}",
178 Name, caps.RegionName, e.Message, e.StackTrace);
179 }
180
181 if (String.IsNullOrEmpty(env))
182 env = EnvironmentSettings.EmptySettings(UUID.Zero, regionID);
183
184 return env;
185 }
186
187 private string SetEnvironmentSettings(string request, string path, string param,
188 UUID agentID, Caps caps)
189 {
190
191// m_log.DebugFormat("[{0}]: Environment SET handle from agentID {1} in region {2}",
192// Name, agentID, caps.RegionName);
193
194 setResponse.regionID = regionID;
195 setResponse.success = false;
196
197 if (!m_scene.Permissions.CanIssueEstateCommand(agentID, false))
198 {
199 setResponse.fail_reason = "Insufficient estate permissions, settings has not been saved.";
200 return LLSDHelpers.SerialiseLLSDReply(setResponse);
201 }
202
203 try
204 {
205 m_scene.SimulationDataService.StoreRegionEnvironmentSettings(regionID, request);
206 setResponse.success = true;
207
208 m_log.InfoFormat("[{0}]: New Environment settings has been saved from agentID {1} in region {2}",
209 Name, agentID, caps.RegionName);
210 }
211 catch (Exception e)
212 {
213 m_log.ErrorFormat("[{0}]: Environment settings has not been saved for region {1}, Exception: {2} - {3}",
214 Name, caps.RegionName, e.Message, e.StackTrace);
215
216 setResponse.success = false;
217 setResponse.fail_reason = String.Format("Environment Set for region {0} has failed, settings has not been saved.", caps.RegionName);
218 }
219
220 return LLSDHelpers.SerialiseLLSDReply(setResponse);
221 }
222 }
223}
224
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 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
32using OpenMetaverse;
33using log4net;
34using Nini.Config;
35using OpenSim.Data;
36using OpenSim.Framework;
37using OpenSim.Region.CoreModules.Framework.InterfaceCommander;
38using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Region.Framework.Scenes;
40using Mono.Addins;
41
42namespace OpenSim.Region.CoreModules.World.LightShare
43{
44 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
45 public class LightShareModule : INonSharedRegionModule, ICommandableModule
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 private readonly Commander m_commander = new Commander("windlight");
49 private Scene m_scene;
50 private static bool m_enableWindlight;
51
52 #region ICommandableModule Members
53
54 public ICommander CommandInterface
55 {
56 get { return m_commander; }
57 }
58
59 #endregion
60
61 #region IRegionModule Members
62
63 public static bool EnableWindlight
64 {
65 get
66 {
67 return m_enableWindlight;
68 }
69 set
70 {
71 }
72 }
73
74 public void Initialise(IConfigSource config)
75 {
76 // ini file settings
77 try
78 {
79 m_enableWindlight = config.Configs["LightShare"].GetBoolean("enable_windlight", false);
80 }
81 catch (Exception)
82 {
83 m_log.Debug("[WINDLIGHT]: ini failure for enable_windlight - using default");
84 }
85
86 m_log.DebugFormat("[WINDLIGHT]: windlight module {0}", (m_enableWindlight ? "enabled" : "disabled"));
87 }
88
89 public void AddRegion(Scene scene)
90 {
91 if (!m_enableWindlight)
92 return;
93
94 m_scene = scene;
95 //m_scene.RegisterModuleInterface<IRegionModule>(this);
96 m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
97
98 m_scene.EventManager.OnMakeRootAgent += EventManager_OnMakeRootAgent;
99 m_scene.EventManager.OnSaveNewWindlightProfile += EventManager_OnSaveNewWindlightProfile;
100 m_scene.EventManager.OnSendNewWindlightProfileTargeted += EventManager_OnSendNewWindlightProfileTargeted;
101 m_scene.LoadWindlightProfile();
102
103 InstallCommands();
104 }
105
106 public void RemoveRegion(Scene scene)
107 {
108 if (!m_enableWindlight)
109 return;
110
111 m_scene.EventManager.OnPluginConsole -= EventManager_OnPluginConsole;
112
113 m_scene.EventManager.OnMakeRootAgent -= EventManager_OnMakeRootAgent;
114 m_scene.EventManager.OnSaveNewWindlightProfile -= EventManager_OnSaveNewWindlightProfile;
115 m_scene.EventManager.OnSendNewWindlightProfileTargeted -= EventManager_OnSendNewWindlightProfileTargeted;
116
117 m_scene = null;
118 }
119
120 public void Close()
121 {
122 }
123
124 public string Name
125 {
126 get { return "LightShareModule"; }
127 }
128
129 public void RegionLoaded(Scene scene)
130 {
131 }
132
133 public Type ReplaceableInterface
134 {
135 get { return null; }
136 }
137
138 #endregion
139
140 #region events
141
142 private List<byte[]> compileWindlightSettings(RegionLightShareData wl)
143 {
144 byte[] mBlock = new Byte[249];
145 int pos = 0;
146
147 wl.waterColor.ToBytes(mBlock, 0); pos += 12;
148 Utils.FloatToBytes(wl.waterFogDensityExponent).CopyTo(mBlock, pos); pos += 4;
149 Utils.FloatToBytes(wl.underwaterFogModifier).CopyTo(mBlock, pos); pos += 4;
150 wl.reflectionWaveletScale.ToBytes(mBlock, pos); pos += 12;
151 Utils.FloatToBytes(wl.fresnelScale).CopyTo(mBlock, pos); pos += 4;
152 Utils.FloatToBytes(wl.fresnelOffset).CopyTo(mBlock, pos); pos += 4;
153 Utils.FloatToBytes(wl.refractScaleAbove).CopyTo(mBlock, pos); pos += 4;
154 Utils.FloatToBytes(wl.refractScaleBelow).CopyTo(mBlock, pos); pos += 4;
155 Utils.FloatToBytes(wl.blurMultiplier).CopyTo(mBlock, pos); pos += 4;
156 wl.bigWaveDirection.ToBytes(mBlock, pos); pos += 8;
157 wl.littleWaveDirection.ToBytes(mBlock, pos); pos += 8;
158 wl.normalMapTexture.ToBytes(mBlock, pos); pos += 16;
159 wl.horizon.ToBytes(mBlock, pos); pos += 16;
160 Utils.FloatToBytes(wl.hazeHorizon).CopyTo(mBlock, pos); pos += 4;
161 wl.blueDensity.ToBytes(mBlock, pos); pos += 16;
162 Utils.FloatToBytes(wl.hazeDensity).CopyTo(mBlock, pos); pos += 4;
163 Utils.FloatToBytes(wl.densityMultiplier).CopyTo(mBlock, pos); pos += 4;
164 Utils.FloatToBytes(wl.distanceMultiplier).CopyTo(mBlock, pos); pos += 4;
165 wl.sunMoonColor.ToBytes(mBlock, pos); pos += 16;
166 Utils.FloatToBytes(wl.sunMoonPosition).CopyTo(mBlock, pos); pos += 4;
167 wl.ambient.ToBytes(mBlock, pos); pos += 16;
168 Utils.FloatToBytes(wl.eastAngle).CopyTo(mBlock, pos); pos += 4;
169 Utils.FloatToBytes(wl.sunGlowFocus).CopyTo(mBlock, pos); pos += 4;
170 Utils.FloatToBytes(wl.sunGlowSize).CopyTo(mBlock, pos); pos += 4;
171 Utils.FloatToBytes(wl.sceneGamma).CopyTo(mBlock, pos); pos += 4;
172 Utils.FloatToBytes(wl.starBrightness).CopyTo(mBlock, pos); pos += 4;
173 wl.cloudColor.ToBytes(mBlock, pos); pos += 16;
174 wl.cloudXYDensity.ToBytes(mBlock, pos); pos += 12;
175 Utils.FloatToBytes(wl.cloudCoverage).CopyTo(mBlock, pos); pos += 4;
176 Utils.FloatToBytes(wl.cloudScale).CopyTo(mBlock, pos); pos += 4;
177 wl.cloudDetailXYDensity.ToBytes(mBlock, pos); pos += 12;
178 Utils.FloatToBytes(wl.cloudScrollX).CopyTo(mBlock, pos); pos += 4;
179 Utils.FloatToBytes(wl.cloudScrollY).CopyTo(mBlock, pos); pos += 4;
180 Utils.UInt16ToBytes(wl.maxAltitude).CopyTo(mBlock, pos); pos += 2;
181 mBlock[pos] = Convert.ToByte(wl.cloudScrollXLock); pos++;
182 mBlock[pos] = Convert.ToByte(wl.cloudScrollYLock); pos++;
183 mBlock[pos] = Convert.ToByte(wl.drawClassicClouds); pos++;
184 List<byte[]> param = new List<byte[]>();
185 param.Add(mBlock);
186 return param;
187 }
188
189 public void SendProfileToClient(IClientAPI client)
190 {
191 SendProfileToClient(client, m_scene.RegionInfo.WindlightSettings);
192 }
193
194 public void SendProfileToClient(IClientAPI client, RegionLightShareData wl)
195 {
196 if (m_enableWindlight)
197 {
198 if (m_scene.RegionInfo.WindlightSettings.valid)
199 {
200 List<byte[]> param = compileWindlightSettings(wl);
201 client.SendGenericMessage("Windlight", param);
202 }
203 else
204 {
205 List<byte[]> param = new List<byte[]>();
206 client.SendGenericMessage("WindlightReset", param);
207 }
208 }
209 }
210
211 private void EventManager_OnMakeRootAgent(ScenePresence presence)
212 {
213 m_log.Debug("[WINDLIGHT]: Sending windlight scene to new client");
214 SendProfileToClient(presence.ControllingClient);
215 }
216
217 private void EventManager_OnSendNewWindlightProfileTargeted(RegionLightShareData wl, UUID pUUID)
218 {
219 IClientAPI client;
220 m_scene.TryGetClient(pUUID, out client);
221 SendProfileToClient(client, wl);
222 }
223
224 private void EventManager_OnSaveNewWindlightProfile()
225 {
226 m_scene.ForEachRootClient(SendProfileToClient);
227 }
228
229 #endregion
230
231 #region ICommandableModule Members
232
233 private void InstallCommands()
234 {
235 Command wlload = new Command("load", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleLoad, "Load windlight profile from the database and broadcast");
236 Command wlenable = new Command("enable", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleEnable, "Enable the windlight plugin");
237 Command wldisable = new Command("disable", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleDisable, "Disable the windlight plugin");
238
239 m_commander.RegisterCommand("load", wlload);
240 m_commander.RegisterCommand("enable", wlenable);
241 m_commander.RegisterCommand("disable", wldisable);
242
243 m_scene.RegisterModuleCommander(m_commander);
244 }
245
246 private void HandleLoad(Object[] args)
247 {
248 if (!m_enableWindlight)
249 {
250 m_log.InfoFormat("[WINDLIGHT]: Cannot load windlight profile, module disabled. Use 'windlight enable' first.");
251 }
252 else
253 {
254 m_log.InfoFormat("[WINDLIGHT]: Loading Windlight profile from database");
255 m_scene.LoadWindlightProfile();
256 m_log.InfoFormat("[WINDLIGHT]: Load complete");
257 }
258 }
259
260 private void HandleDisable(Object[] args)
261 {
262 m_log.InfoFormat("[WINDLIGHT]: Plugin now disabled");
263 m_enableWindlight=false;
264 }
265
266 private void HandleEnable(Object[] args)
267 {
268 m_log.InfoFormat("[WINDLIGHT]: Plugin now enabled");
269 m_enableWindlight = true;
270 }
271
272 /// <summary>
273 /// Processes commandline input. Do not call directly.
274 /// </summary>
275 /// <param name="args">Commandline arguments</param>
276 private void EventManager_OnPluginConsole(string[] args)
277 {
278 if (args[0] == "windlight")
279 {
280 if (args.Length == 1)
281 {
282 m_commander.ProcessConsoleCommand("add", new string[0]);
283 return;
284 }
285
286 string[] tmpArgs = new string[args.Length - 2];
287 int i;
288 for (i = 2; i < args.Length; i++)
289 {
290 tmpArgs[i - 2] = args[i];
291 }
292
293 m_commander.ProcessConsoleCommand(args[1], tmpArgs);
294 }
295 }
296 #endregion
297
298 }
299}
300