aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs430
1 files changed, 430 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
new file mode 100644
index 0000000..4cc2f0a
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
@@ -0,0 +1,430 @@
1using System;
2using System.Reflection;
3using System.Collections;
4using System.Collections.Generic;
5using System.Runtime.Remoting.Lifetime;
6using OpenMetaverse;
7using Nini.Config;
8using OpenSim;
9using OpenSim.Framework;
10using OpenSim.Region.CoreModules.World.Meta7Windlight;
11using OpenSim.Region.Framework.Interfaces;
12using OpenSim.Region.Framework.Scenes;
13using OpenSim.Region.ScriptEngine.Shared;
14using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
15using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
16using OpenSim.Region.ScriptEngine.Interfaces;
17using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
18
19using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
20using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
21using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
22using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
23using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
24using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
25using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
26
27namespace OpenSim.Region.ScriptEngine.Shared.Api
28{
29 [Serializable]
30 public class CM_Api : MarshalByRefObject, ICM_Api, IScriptApi
31 {
32 internal IScriptEngine m_ScriptEngine;
33 internal SceneObjectPart m_host;
34 internal uint m_localID;
35 internal UUID m_itemID;
36 internal bool m_CMFunctionsEnabled = false;
37 internal IScriptModuleComms m_comms = null;
38
39 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID)
40 {
41 m_ScriptEngine = ScriptEngine;
42 m_host = host;
43 m_localID = localID;
44 m_itemID = itemID;
45
46 if (m_ScriptEngine.Config.GetBoolean("AllowCareminsterFunctions", false))
47 m_CMFunctionsEnabled = true;
48
49 m_comms = m_ScriptEngine.World.RequestModuleInterface<IScriptModuleComms>();
50 if (m_comms == null)
51 m_CMFunctionsEnabled = false;
52 }
53
54 public override Object InitializeLifetimeService()
55 {
56 ILease lease = (ILease)base.InitializeLifetimeService();
57
58 if (lease.CurrentState == LeaseState.Initial)
59 {
60 lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
61 // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
62 // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
63 }
64 return lease;
65 }
66
67 public Scene World
68 {
69 get { return m_ScriptEngine.World; }
70 }
71
72 //
73 //Dumps an error message on the debug console.
74 //
75
76 internal void CMShoutError(string message)
77 {
78 if (message.Length > 1023)
79 message = message.Substring(0, 1023);
80
81 World.SimChat(Utils.StringToBytes(message),
82 ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
83
84 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
85 wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
86 }
87
88 /// <summary>
89 /// Get the current Windlight scene
90 /// </summary>
91 /// <returns>List of windlight parameters</returns>
92 public LSL_List cmGetWindlightScene(LSL_List rules)
93 {
94 if (!m_CMFunctionsEnabled)
95 {
96 CMShoutError("Careminster functions are not enabled.");
97 return new LSL_List();
98 }
99 m_host.AddScriptLPS(1);
100 RegionMeta7WindlightData wl = m_host.ParentGroup.Scene.RegionInfo.WindlightSettings;
101
102 LSL_List values = new LSL_List();
103 int idx = 0;
104 while (idx < rules.Length)
105 {
106 uint rule = (uint)rules.GetLSLIntegerItem(idx);
107 LSL_List toadd = new LSL_List();
108
109 switch (rule)
110 {
111 case (int)ScriptBaseClass.WL_AMBIENT:
112 toadd.Add(new LSL_Rotation(wl.ambient.X, wl.ambient.Y, wl.ambient.Z, wl.ambient.W));
113 break;
114 case (int)ScriptBaseClass.WL_BIG_WAVE_DIRECTION:
115 toadd.Add(new LSL_Vector(wl.bigWaveDirection.X, wl.bigWaveDirection.Y, 0.0f));
116 break;
117 case (int)ScriptBaseClass.WL_BLUE_DENSITY:
118 toadd.Add(new LSL_Rotation(wl.blueDensity.X, wl.blueDensity.Y, wl.blueDensity.Z, wl.blueDensity.W));
119 break;
120 case (int)ScriptBaseClass.WL_BLUR_MULTIPLIER:
121 toadd.Add(new LSL_Float(wl.blurMultiplier));
122 break;
123 case (int)ScriptBaseClass.WL_CLOUD_COLOR:
124 toadd.Add(new LSL_Rotation(wl.cloudColor.X, wl.cloudColor.Y, wl.cloudColor.Z, wl.cloudColor.W));
125 break;
126 case (int)ScriptBaseClass.WL_CLOUD_COVERAGE:
127 toadd.Add(new LSL_Float(wl.cloudCoverage));
128 break;
129 case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY:
130 toadd.Add(new LSL_Vector(wl.cloudDetailXYDensity.X, wl.cloudDetailXYDensity.Y, wl.cloudDetailXYDensity.Z));
131 break;
132 case (int)ScriptBaseClass.WL_CLOUD_SCALE:
133 toadd.Add(new LSL_Float(wl.cloudScale));
134 break;
135 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X:
136 toadd.Add(new LSL_Float(wl.cloudScrollX));
137 break;
138 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK:
139 toadd.Add(new LSL_Integer(wl.cloudScrollXLock ? 1 : 0));
140 break;
141 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y:
142 toadd.Add(new LSL_Float(wl.cloudScrollY));
143 break;
144 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK:
145 toadd.Add(new LSL_Integer(wl.cloudScrollYLock ? 1 : 0));
146 break;
147 case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY:
148 toadd.Add(new LSL_Vector(wl.cloudXYDensity.X, wl.cloudXYDensity.Y, wl.cloudXYDensity.Z));
149 break;
150 case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER:
151 toadd.Add(new LSL_Float(wl.densityMultiplier));
152 break;
153 case (int)ScriptBaseClass.WL_DISTANCE_MULTIPLIER:
154 toadd.Add(new LSL_Float(wl.distanceMultiplier));
155 break;
156 case (int)ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS:
157 toadd.Add(new LSL_Integer(wl.drawClassicClouds ? 1 : 0));
158 break;
159 case (int)ScriptBaseClass.WL_EAST_ANGLE:
160 toadd.Add(new LSL_Float(wl.eastAngle));
161 break;
162 case (int)ScriptBaseClass.WL_FRESNEL_OFFSET:
163 toadd.Add(new LSL_Float(wl.fresnelOffset));
164 break;
165 case (int)ScriptBaseClass.WL_FRESNEL_SCALE:
166 toadd.Add(new LSL_Float(wl.fresnelScale));
167 break;
168 case (int)ScriptBaseClass.WL_HAZE_DENSITY:
169 toadd.Add(new LSL_Float(wl.hazeDensity));
170 break;
171 case (int)ScriptBaseClass.WL_HAZE_HORIZON:
172 toadd.Add(new LSL_Float(wl.hazeHorizon));
173 break;
174 case (int)ScriptBaseClass.WL_HORIZON:
175 toadd.Add(new LSL_Rotation(wl.horizon.X, wl.horizon.Y, wl.horizon.Z, wl.horizon.W));
176 break;
177 case (int)ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION:
178 toadd.Add(new LSL_Vector(wl.littleWaveDirection.X, wl.littleWaveDirection.Y, 0.0f));
179 break;
180 case (int)ScriptBaseClass.WL_MAX_ALTITUDE:
181 toadd.Add(new LSL_Integer(wl.maxAltitude));
182 break;
183 case (int)ScriptBaseClass.WL_NORMAL_MAP_TEXTURE:
184 toadd.Add(new LSL_Key(wl.normalMapTexture.ToString()));
185 break;
186 case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE:
187 toadd.Add(new LSL_Vector(wl.reflectionWaveletScale.X, wl.reflectionWaveletScale.Y, wl.reflectionWaveletScale.Z));
188 break;
189 case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE:
190 toadd.Add(new LSL_Float(wl.refractScaleAbove));
191 break;
192 case (int)ScriptBaseClass.WL_REFRACT_SCALE_BELOW:
193 toadd.Add(new LSL_Float(wl.refractScaleBelow));
194 break;
195 case (int)ScriptBaseClass.WL_SCENE_GAMMA:
196 toadd.Add(new LSL_Float(wl.sceneGamma));
197 break;
198 case (int)ScriptBaseClass.WL_STAR_BRIGHTNESS:
199 toadd.Add(new LSL_Float(wl.starBrightness));
200 break;
201 case (int)ScriptBaseClass.WL_SUN_GLOW_FOCUS:
202 toadd.Add(new LSL_Float(wl.sunGlowFocus));
203 break;
204 case (int)ScriptBaseClass.WL_SUN_GLOW_SIZE:
205 toadd.Add(new LSL_Float(wl.sunGlowSize));
206 break;
207 case (int)ScriptBaseClass.WL_SUN_MOON_COLOR:
208 toadd.Add(new LSL_Rotation(wl.sunMoonColor.X, wl.sunMoonColor.Y, wl.sunMoonColor.Z, wl.sunMoonColor.W));
209 break;
210 case (int)ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER:
211 toadd.Add(new LSL_Float(wl.underwaterFogModifier));
212 break;
213 case (int)ScriptBaseClass.WL_WATER_COLOR:
214 toadd.Add(new LSL_Vector(wl.waterColor.X, wl.waterColor.Y, wl.waterColor.Z));
215 break;
216 case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT:
217 toadd.Add(new LSL_Float(wl.waterFogDensityExponent));
218 break;
219 }
220
221 if (toadd.Length > 0)
222 {
223 values.Add(rule);
224 values.Add(toadd.Data[0]);
225 }
226 idx++;
227 }
228
229
230 return values;
231
232 }
233
234 /// <summary>
235 /// Set the current Windlight scene
236 /// </summary>
237 /// <param name="rules"></param>
238 /// <returns>success: true or false</returns>
239 public int cmSetWindlightScene(LSL_List rules)
240 {
241 if (!m_CMFunctionsEnabled)
242 {
243 CMShoutError("Careminster functions are not enabled.");
244 return 0;
245 }
246 int success = 0;
247 m_host.AddScriptLPS(1);
248 if (Meta7WindlightModule.EnableWindlight)
249 {
250 RegionMeta7WindlightData wl = m_host.ParentGroup.Scene.RegionInfo.WindlightSettings;
251
252 LSL_List values = new LSL_List();
253 int idx = 0;
254 success = 1;
255 while (idx < rules.Length)
256 {
257 uint rule = (uint)rules.GetLSLIntegerItem(idx);
258 LSL_Types.Quaternion iQ;
259 LSL_Types.Vector3 iV;
260 switch (rule)
261 {
262 case (int)ScriptBaseClass.WL_AMBIENT:
263 idx++;
264 iQ = rules.GetQuaternionItem(idx);
265 wl.ambient = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
266 break;
267 case (int)ScriptBaseClass.WL_BIG_WAVE_DIRECTION:
268 idx++;
269 iV = rules.GetVector3Item(idx);
270 wl.bigWaveDirection = new Vector2((float)iV.x, (float)iV.y);
271 break;
272 case (int)ScriptBaseClass.WL_BLUE_DENSITY:
273 idx++;
274 iQ = rules.GetQuaternionItem(idx);
275 wl.blueDensity = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
276 break;
277 case (int)ScriptBaseClass.WL_BLUR_MULTIPLIER:
278 idx++;
279 wl.blurMultiplier = (float)rules.GetLSLFloatItem(idx);
280 break;
281 case (int)ScriptBaseClass.WL_CLOUD_COLOR:
282 idx++;
283 iQ = rules.GetQuaternionItem(idx);
284 wl.cloudColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
285 break;
286 case (int)ScriptBaseClass.WL_CLOUD_COVERAGE:
287 idx++;
288 wl.cloudCoverage = (float)rules.GetLSLFloatItem(idx);
289 break;
290 case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY:
291 idx++;
292 iV = rules.GetVector3Item(idx);
293 wl.cloudDetailXYDensity = new Vector3((float)iV.x, (float)iV.y, (float)iV.z);
294 break;
295 case (int)ScriptBaseClass.WL_CLOUD_SCALE:
296 idx++;
297 wl.cloudScale = (float)rules.GetLSLFloatItem(idx);
298 break;
299 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X:
300 idx++;
301 wl.cloudScrollX = (float)rules.GetLSLFloatItem(idx);
302 break;
303 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK:
304 idx++;
305 wl.cloudScrollXLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false;
306 break;
307 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y:
308 idx++;
309 wl.cloudScrollY = (float)rules.GetLSLFloatItem(idx);
310 break;
311 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK:
312 idx++;
313 wl.cloudScrollYLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false;
314 break;
315 case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY:
316 idx++;
317 iV = rules.GetVector3Item(idx);
318 wl.cloudDetailXYDensity = new Vector3((float)iV.x, (float)iV.y, (float)iV.z);
319 break;
320 case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER:
321 idx++;
322 wl.densityMultiplier = (float)rules.GetLSLFloatItem(idx);
323 break;
324 case (int)ScriptBaseClass.WL_DISTANCE_MULTIPLIER:
325 idx++;
326 wl.distanceMultiplier = (float)rules.GetLSLFloatItem(idx);
327 break;
328 case (int)ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS:
329 idx++;
330 wl.drawClassicClouds = rules.GetLSLIntegerItem(idx).value == 1 ? true : false;
331 break;
332 case (int)ScriptBaseClass.WL_EAST_ANGLE:
333 idx++;
334 wl.eastAngle = (float)rules.GetLSLFloatItem(idx);
335 break;
336 case (int)ScriptBaseClass.WL_FRESNEL_OFFSET:
337 idx++;
338 wl.fresnelOffset = (float)rules.GetLSLFloatItem(idx);
339 break;
340 case (int)ScriptBaseClass.WL_FRESNEL_SCALE:
341 idx++;
342 wl.fresnelScale = (float)rules.GetLSLFloatItem(idx);
343 break;
344 case (int)ScriptBaseClass.WL_HAZE_DENSITY:
345 idx++;
346 wl.hazeDensity = (float)rules.GetLSLFloatItem(idx);
347 break;
348 case (int)ScriptBaseClass.WL_HAZE_HORIZON:
349 idx++;
350 wl.hazeHorizon = (float)rules.GetLSLFloatItem(idx);
351 break;
352 case (int)ScriptBaseClass.WL_HORIZON:
353 idx++;
354 iQ = rules.GetQuaternionItem(idx);
355 wl.horizon = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
356 break;
357 case (int)ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION:
358 idx++;
359 iV = rules.GetVector3Item(idx);
360 wl.littleWaveDirection = new Vector2((float)iV.x, (float)iV.y);
361 break;
362 case (int)ScriptBaseClass.WL_MAX_ALTITUDE:
363 idx++;
364 wl.maxAltitude = (ushort)rules.GetLSLIntegerItem(idx).value;
365 break;
366 case (int)ScriptBaseClass.WL_NORMAL_MAP_TEXTURE:
367 idx++;
368 wl.normalMapTexture = new UUID(rules.GetLSLStringItem(idx).m_string);
369 break;
370 case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE:
371 idx++;
372 iV = rules.GetVector3Item(idx);
373 wl.reflectionWaveletScale = new Vector3((float)iV.x, (float)iV.y, (float)iV.z);
374 break;
375 case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE:
376 idx++;
377 wl.refractScaleAbove = (float)rules.GetLSLFloatItem(idx);
378 break;
379 case (int)ScriptBaseClass.WL_REFRACT_SCALE_BELOW:
380 idx++;
381 wl.refractScaleBelow = (float)rules.GetLSLFloatItem(idx);
382 break;
383 case (int)ScriptBaseClass.WL_SCENE_GAMMA:
384 idx++;
385 wl.sceneGamma = (float)rules.GetLSLFloatItem(idx);
386 break;
387 case (int)ScriptBaseClass.WL_STAR_BRIGHTNESS:
388 idx++;
389 wl.starBrightness = (float)rules.GetLSLFloatItem(idx);
390 break;
391 case (int)ScriptBaseClass.WL_SUN_GLOW_FOCUS:
392 idx++;
393 wl.sunGlowFocus = (float)rules.GetLSLFloatItem(idx);
394 break;
395 case (int)ScriptBaseClass.WL_SUN_GLOW_SIZE:
396 idx++;
397 wl.sunGlowSize = (float)rules.GetLSLFloatItem(idx);
398 break;
399 case (int)ScriptBaseClass.WL_SUN_MOON_COLOR:
400 idx++;
401 iQ = rules.GetQuaternionItem(idx);
402 wl.sunMoonColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
403 break;
404 case (int)ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER:
405 idx++;
406 wl.underwaterFogModifier = (float)rules.GetLSLFloatItem(idx);
407 break;
408 case (int)ScriptBaseClass.WL_WATER_COLOR:
409 idx++;
410 iV = rules.GetVector3Item(idx);
411 wl.waterColor = new Vector3((float)iV.x, (float)iV.y, (float)iV.z);
412 break;
413 case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT:
414 idx++;
415 wl.waterFogDensityExponent = (float)rules.GetLSLFloatItem(idx);
416 break;
417 default:
418 success = 0;
419 break;
420 }
421 idx++;
422 }
423 m_host.ParentGroup.Scene.StoreWindlightProfile(wl);
424
425 }
426 return success;
427 }
428
429 }
430}