diff options
author | Justin Clark-Casey (justincc) | 2010-04-01 23:59:00 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2010-04-01 23:59:00 +0100 |
commit | e0eba26f7bd2258ec026a42e278420fa0938cea7 (patch) | |
tree | 39ae2410374c07ff62a52af3551888746ed36c3c /OpenSim/Region/CoreModules | |
parent | oops, add file missing from last commit (diff) | |
parent | First attempt at fixing mantis #4641. It's better but there are now some issu... (diff) | |
download | opensim-SC-e0eba26f7bd2258ec026a42e278420fa0938cea7.zip opensim-SC-e0eba26f7bd2258ec026a42e278420fa0938cea7.tar.gz opensim-SC-e0eba26f7bd2258ec026a42e278420fa0938cea7.tar.bz2 opensim-SC-e0eba26f7bd2258ec026a42e278420fa0938cea7.tar.xz |
Merge branch 'master' of ssh://justincc@opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim/Region/CoreModules')
-rw-r--r-- | OpenSim/Region/CoreModules/Framework/Library/LibraryModule.cs | 25 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/LightShare/LightShareModule.cs | 293 |
2 files changed, 314 insertions, 4 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/Library/LibraryModule.cs b/OpenSim/Region/CoreModules/Framework/Library/LibraryModule.cs index e37da9f..36dae6b 100644 --- a/OpenSim/Region/CoreModules/Framework/Library/LibraryModule.cs +++ b/OpenSim/Region/CoreModules/Framework/Library/LibraryModule.cs | |||
@@ -173,11 +173,11 @@ namespace OpenSim.Region.CoreModules.Framework.Library | |||
173 | m_log.InfoFormat("[LIBRARY MODULE]: Loading library archive {0} ({1})...", iarFileName, simpleName); | 173 | m_log.InfoFormat("[LIBRARY MODULE]: Loading library archive {0} ({1})...", iarFileName, simpleName); |
174 | simpleName = GetInventoryPathFromName(simpleName); | 174 | simpleName = GetInventoryPathFromName(simpleName); |
175 | 175 | ||
176 | InventoryArchiveReadRequest archread = new InventoryArchiveReadRequest(m_MockScene, uinfo, simpleName, iarFileName); | ||
176 | try | 177 | try |
177 | { | 178 | { |
178 | InventoryArchiveReadRequest archread = new InventoryArchiveReadRequest(m_MockScene, uinfo, simpleName, iarFileName); | ||
179 | List<InventoryNodeBase> nodes = archread.Execute(); | 179 | List<InventoryNodeBase> nodes = archread.Execute(); |
180 | if (nodes.Count == 0) | 180 | if (nodes != null && nodes.Count == 0) |
181 | { | 181 | { |
182 | // didn't find the subfolder with the given name; place it on the top | 182 | // didn't find the subfolder with the given name; place it on the top |
183 | m_log.InfoFormat("[LIBRARY MODULE]: Didn't find {0} in library. Placing archive on the top level", simpleName); | 183 | m_log.InfoFormat("[LIBRARY MODULE]: Didn't find {0} in library. Placing archive on the top level", simpleName); |
@@ -185,16 +185,33 @@ namespace OpenSim.Region.CoreModules.Framework.Library | |||
185 | archread = new InventoryArchiveReadRequest(m_MockScene, uinfo, "/", iarFileName); | 185 | archread = new InventoryArchiveReadRequest(m_MockScene, uinfo, "/", iarFileName); |
186 | archread.Execute(); | 186 | archread.Execute(); |
187 | } | 187 | } |
188 | archread.Close(); | 188 | foreach (InventoryNodeBase node in nodes) |
189 | FixPerms(node); | ||
189 | } | 190 | } |
190 | catch (Exception e) | 191 | catch (Exception e) |
191 | { | 192 | { |
192 | m_log.DebugFormat("[LIBRARY MODULE]: Exception when processing archive {0}: {1}", iarFileName, e.Message); | 193 | m_log.DebugFormat("[LIBRARY MODULE]: Exception when processing archive {0}: {1}", iarFileName, e.StackTrace); |
194 | } | ||
195 | finally | ||
196 | { | ||
197 | archread.Close(); | ||
193 | } | 198 | } |
194 | } | 199 | } |
195 | 200 | ||
196 | } | 201 | } |
197 | 202 | ||
203 | private void FixPerms(InventoryNodeBase node) | ||
204 | { | ||
205 | if (node is InventoryItemBase) | ||
206 | { | ||
207 | InventoryItemBase item = (InventoryItemBase)node; | ||
208 | item.BasePermissions = 0x7FFFFFFF; | ||
209 | item.EveryOnePermissions = 0x7FFFFFFF; | ||
210 | item.CurrentPermissions = 0x7FFFFFFF; | ||
211 | item.NextPermissions = 0x7FFFFFFF; | ||
212 | } | ||
213 | } | ||
214 | |||
198 | private void DumpLibrary() | 215 | private void DumpLibrary() |
199 | { | 216 | { |
200 | InventoryFolderImpl lib = m_Library.LibraryRootFolder; | 217 | InventoryFolderImpl lib = m_Library.LibraryRootFolder; |
diff --git a/OpenSim/Region/CoreModules/LightShare/LightShareModule.cs b/OpenSim/Region/CoreModules/LightShare/LightShareModule.cs new file mode 100644 index 0000000..e6cab1d --- /dev/null +++ b/OpenSim/Region/CoreModules/LightShare/LightShareModule.cs | |||
@@ -0,0 +1,293 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using OpenMetaverse; | ||
33 | using log4net; | ||
34 | using Nini.Config; | ||
35 | using OpenSim.Data; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.CoreModules.Framework.InterfaceCommander; | ||
38 | using OpenSim.Region.Framework.Interfaces; | ||
39 | using OpenSim.Region.Framework.Scenes; | ||
40 | |||
41 | |||
42 | namespace OpenSim.Region.CoreModules.World.LightShare | ||
43 | { | ||
44 | public class LightShareModule : IRegionModule, ICommandableModule | ||
45 | { | ||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | private readonly Commander m_commander = new Commander("windlight"); | ||
48 | private Scene m_scene; | ||
49 | private static bool m_enableWindlight; | ||
50 | |||
51 | #region ICommandableModule Members | ||
52 | |||
53 | public ICommander CommandInterface | ||
54 | { | ||
55 | get { return m_commander; } | ||
56 | } | ||
57 | |||
58 | #endregion | ||
59 | |||
60 | #region IRegionModule Members | ||
61 | |||
62 | public static bool EnableWindlight | ||
63 | { | ||
64 | get | ||
65 | { | ||
66 | return m_enableWindlight; | ||
67 | } | ||
68 | set | ||
69 | { | ||
70 | } | ||
71 | } | ||
72 | |||
73 | public void Initialise(Scene scene, IConfigSource config) | ||
74 | { | ||
75 | m_scene = scene; | ||
76 | m_scene.RegisterModuleInterface<IRegionModule>(this); | ||
77 | m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; | ||
78 | |||
79 | // ini file settings | ||
80 | try | ||
81 | { | ||
82 | m_enableWindlight = config.Configs["LightShare"].GetBoolean("enable_windlight", false); | ||
83 | } | ||
84 | catch (Exception) | ||
85 | { | ||
86 | m_log.Debug("[WINDLIGHT]: ini failure for enable_windlight - using default"); | ||
87 | } | ||
88 | |||
89 | if (m_enableWindlight) | ||
90 | { | ||
91 | m_scene.EventManager.OnMakeRootAgent += EventManager_OnMakeRootAgent; | ||
92 | m_scene.EventManager.OnSaveNewWindlightProfile += EventManager_OnSaveNewWindlightProfile; | ||
93 | m_scene.EventManager.OnSendNewWindlightProfileTargeted += EventManager_OnSendNewWindlightProfileTargeted; | ||
94 | } | ||
95 | |||
96 | InstallCommands(); | ||
97 | |||
98 | m_log.Debug("[WINDLIGHT]: Initialised windlight module"); | ||
99 | } | ||
100 | |||
101 | private List<byte[]> compileWindlightSettings(RegionLightShareData wl) | ||
102 | { | ||
103 | byte[] mBlock = new Byte[249]; | ||
104 | int pos = 0; | ||
105 | |||
106 | wl.waterColor.ToBytes(mBlock, 0); pos += 12; | ||
107 | Utils.FloatToBytes(wl.waterFogDensityExponent).CopyTo(mBlock, pos); pos += 4; | ||
108 | Utils.FloatToBytes(wl.underwaterFogModifier).CopyTo(mBlock, pos); pos += 4; | ||
109 | wl.reflectionWaveletScale.ToBytes(mBlock, pos); pos += 12; | ||
110 | Utils.FloatToBytes(wl.fresnelScale).CopyTo(mBlock, pos); pos += 4; | ||
111 | Utils.FloatToBytes(wl.fresnelOffset).CopyTo(mBlock, pos); pos += 4; | ||
112 | Utils.FloatToBytes(wl.refractScaleAbove).CopyTo(mBlock, pos); pos += 4; | ||
113 | Utils.FloatToBytes(wl.refractScaleBelow).CopyTo(mBlock, pos); pos += 4; | ||
114 | Utils.FloatToBytes(wl.blurMultiplier).CopyTo(mBlock, pos); pos += 4; | ||
115 | wl.bigWaveDirection.ToBytes(mBlock, pos); pos += 8; | ||
116 | wl.littleWaveDirection.ToBytes(mBlock, pos); pos += 8; | ||
117 | wl.normalMapTexture.ToBytes(mBlock, pos); pos += 16; | ||
118 | wl.horizon.ToBytes(mBlock, pos); pos += 16; | ||
119 | Utils.FloatToBytes(wl.hazeHorizon).CopyTo(mBlock, pos); pos += 4; | ||
120 | wl.blueDensity.ToBytes(mBlock, pos); pos += 16; | ||
121 | Utils.FloatToBytes(wl.hazeDensity).CopyTo(mBlock, pos); pos += 4; | ||
122 | Utils.FloatToBytes(wl.densityMultiplier).CopyTo(mBlock, pos); pos += 4; | ||
123 | Utils.FloatToBytes(wl.distanceMultiplier).CopyTo(mBlock, pos); pos += 4; | ||
124 | wl.sunMoonColor.ToBytes(mBlock, pos); pos += 16; | ||
125 | Utils.FloatToBytes(wl.sunMoonPosition).CopyTo(mBlock, pos); pos += 4; | ||
126 | wl.ambient.ToBytes(mBlock, pos); pos += 16; | ||
127 | Utils.FloatToBytes(wl.eastAngle).CopyTo(mBlock, pos); pos += 4; | ||
128 | Utils.FloatToBytes(wl.sunGlowFocus).CopyTo(mBlock, pos); pos += 4; | ||
129 | Utils.FloatToBytes(wl.sunGlowSize).CopyTo(mBlock, pos); pos += 4; | ||
130 | Utils.FloatToBytes(wl.sceneGamma).CopyTo(mBlock, pos); pos += 4; | ||
131 | Utils.FloatToBytes(wl.starBrightness).CopyTo(mBlock, pos); pos += 4; | ||
132 | wl.cloudColor.ToBytes(mBlock, pos); pos += 16; | ||
133 | wl.cloudXYDensity.ToBytes(mBlock, pos); pos += 12; | ||
134 | Utils.FloatToBytes(wl.cloudCoverage).CopyTo(mBlock, pos); pos += 4; | ||
135 | Utils.FloatToBytes(wl.cloudScale).CopyTo(mBlock, pos); pos += 4; | ||
136 | wl.cloudDetailXYDensity.ToBytes(mBlock, pos); pos += 12; | ||
137 | Utils.FloatToBytes(wl.cloudScrollX).CopyTo(mBlock, pos); pos += 4; | ||
138 | Utils.FloatToBytes(wl.cloudScrollY).CopyTo(mBlock, pos); pos += 4; | ||
139 | Utils.UInt16ToBytes(wl.maxAltitude).CopyTo(mBlock, pos); pos += 2; | ||
140 | mBlock[pos] = Convert.ToByte(wl.cloudScrollXLock); pos++; | ||
141 | mBlock[pos] = Convert.ToByte(wl.cloudScrollYLock); pos++; | ||
142 | mBlock[pos] = Convert.ToByte(wl.drawClassicClouds); pos++; | ||
143 | List<byte[]> param = new List<byte[]>(); | ||
144 | param.Add(mBlock); | ||
145 | return param; | ||
146 | } | ||
147 | public void SendProfileToClient(ScenePresence presence) | ||
148 | { | ||
149 | IClientAPI client = presence.ControllingClient; | ||
150 | if (m_enableWindlight) | ||
151 | { | ||
152 | if (presence.IsChildAgent == false) | ||
153 | { | ||
154 | List<byte[]> param = compileWindlightSettings(m_scene.RegionInfo.WindlightSettings); | ||
155 | client.SendGenericMessage("Windlight", param); | ||
156 | } | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | //We probably don't want to spam chat with this.. probably | ||
161 | //m_log.Debug("[WINDLIGHT]: Module disabled"); | ||
162 | } | ||
163 | } | ||
164 | public void SendProfileToClient(ScenePresence presence, RegionLightShareData wl) | ||
165 | { | ||
166 | IClientAPI client = presence.ControllingClient; | ||
167 | if (m_enableWindlight) | ||
168 | { | ||
169 | if (presence.IsChildAgent == false) | ||
170 | { | ||
171 | List<byte[]> param = compileWindlightSettings(wl); | ||
172 | client.SendGenericMessage("Windlight", param); | ||
173 | } | ||
174 | } | ||
175 | else | ||
176 | { | ||
177 | //We probably don't want to spam chat with this.. probably | ||
178 | //m_log.Debug("[WINDLIGHT]: Module disabled"); | ||
179 | } | ||
180 | } | ||
181 | private void EventManager_OnMakeRootAgent(ScenePresence presence) | ||
182 | { | ||
183 | m_log.Debug("[WINDLIGHT]: Sending windlight scene to new client"); | ||
184 | SendProfileToClient(presence); | ||
185 | } | ||
186 | private void EventManager_OnSendNewWindlightProfileTargeted(RegionLightShareData wl, UUID pUUID) | ||
187 | { | ||
188 | ScenePresence Sc; | ||
189 | if (m_scene.TryGetScenePresence(pUUID,out Sc)) | ||
190 | { | ||
191 | SendProfileToClient(Sc,wl); | ||
192 | } | ||
193 | } | ||
194 | private void EventManager_OnSaveNewWindlightProfile() | ||
195 | { | ||
196 | m_scene.ForEachScenePresence(SendProfileToClient); | ||
197 | } | ||
198 | |||
199 | public void PostInitialise() | ||
200 | { | ||
201 | |||
202 | } | ||
203 | |||
204 | public void Close() | ||
205 | { | ||
206 | } | ||
207 | |||
208 | public string Name | ||
209 | { | ||
210 | get { return "LightShareModule"; } | ||
211 | } | ||
212 | |||
213 | public bool IsSharedModule | ||
214 | { | ||
215 | get { return false; } | ||
216 | } | ||
217 | |||
218 | #endregion | ||
219 | |||
220 | #region events | ||
221 | |||
222 | #endregion | ||
223 | |||
224 | #region ICommandableModule Members | ||
225 | |||
226 | private void InstallCommands() | ||
227 | { | ||
228 | Command wlload = new Command("load", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleLoad, "Load windlight profile from the database and broadcast"); | ||
229 | Command wlenable = new Command("enable", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleEnable, "Enable the windlight plugin"); | ||
230 | Command wldisable = new Command("disable", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleDisable, "Enable the windlight plugin"); | ||
231 | |||
232 | m_commander.RegisterCommand("load", wlload); | ||
233 | m_commander.RegisterCommand("enable", wlenable); | ||
234 | m_commander.RegisterCommand("disable", wldisable); | ||
235 | |||
236 | m_scene.RegisterModuleCommander(m_commander); | ||
237 | } | ||
238 | |||
239 | private void HandleLoad(Object[] args) | ||
240 | { | ||
241 | if (!m_enableWindlight) | ||
242 | { | ||
243 | m_log.InfoFormat("[WINDLIGHT]: Cannot load windlight profile, module disabled. Use 'windlight enable' first."); | ||
244 | } | ||
245 | else | ||
246 | { | ||
247 | m_log.InfoFormat("[WINDLIGHT]: Loading Windlight profile from database"); | ||
248 | m_scene.LoadWindlightProfile(); | ||
249 | m_log.InfoFormat("[WINDLIGHT]: Load complete"); | ||
250 | } | ||
251 | } | ||
252 | |||
253 | private void HandleDisable(Object[] args) | ||
254 | { | ||
255 | m_log.InfoFormat("[WINDLIGHT]: Plugin now disabled"); | ||
256 | m_enableWindlight=false; | ||
257 | } | ||
258 | |||
259 | private void HandleEnable(Object[] args) | ||
260 | { | ||
261 | m_log.InfoFormat("[WINDLIGHT]: Plugin now enabled"); | ||
262 | m_enableWindlight = true; | ||
263 | } | ||
264 | |||
265 | /// <summary> | ||
266 | /// Processes commandline input. Do not call directly. | ||
267 | /// </summary> | ||
268 | /// <param name="args">Commandline arguments</param> | ||
269 | private void EventManager_OnPluginConsole(string[] args) | ||
270 | { | ||
271 | if (args[0] == "windlight") | ||
272 | { | ||
273 | if (args.Length == 1) | ||
274 | { | ||
275 | m_commander.ProcessConsoleCommand("add", new string[0]); | ||
276 | return; | ||
277 | } | ||
278 | |||
279 | string[] tmpArgs = new string[args.Length - 2]; | ||
280 | int i; | ||
281 | for (i = 2; i < args.Length; i++) | ||
282 | { | ||
283 | tmpArgs[i - 2] = args[i]; | ||
284 | } | ||
285 | |||
286 | m_commander.ProcessConsoleCommand(args[1], tmpArgs); | ||
287 | } | ||
288 | } | ||
289 | #endregion | ||
290 | |||
291 | } | ||
292 | } | ||
293 | |||