OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
LS_Api.cs
Go to the documentation of this file.
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.Reflection;
30 using System.Collections;
31 using System.Collections.Generic;
32 using System.Runtime.Remoting.Lifetime;
33 using System.Threading;
34 using OpenMetaverse;
35 using Nini.Config;
36 using OpenSim;
37 using OpenSim.Framework;
38 using OpenSim.Region.CoreModules.World.LightShare;
39 using OpenSim.Region.Framework.Interfaces;
40 using OpenSim.Region.Framework.Scenes;
41 using OpenSim.Region.ScriptEngine.Shared;
42 using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
43 using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
44 using OpenSim.Region.ScriptEngine.Interfaces;
45 using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
46 
54 
55 namespace OpenSim.Region.ScriptEngine.Shared.Api
56 {
57  [Serializable]
58  public class LS_Api : MarshalByRefObject, ILS_Api, IScriptApi
59  {
60  internal IScriptEngine m_ScriptEngine;
61  internal SceneObjectPart m_host;
62  internal bool m_LSFunctionsEnabled = false;
63  internal IScriptModuleComms m_comms = null;
64 
65  public void Initialize(
66  IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item)
67  {
68  m_ScriptEngine = scriptEngine;
69  m_host = host;
70 
71  if (m_ScriptEngine.Config.GetBoolean("AllowLightShareFunctions", false))
72  m_LSFunctionsEnabled = true;
73 
74  m_comms = m_ScriptEngine.World.RequestModuleInterface<IScriptModuleComms>();
75  if (m_comms == null)
76  m_LSFunctionsEnabled = false;
77  }
78 
80  {
81  ILease lease = (ILease)base.InitializeLifetimeService();
82 
83  if (lease.CurrentState == LeaseState.Initial)
84  {
85  lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
86  // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
87  // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
88  }
89  return lease;
90  }
91 
92  public Scene World
93  {
94  get { return m_ScriptEngine.World; }
95  }
96 
100  internal void LSShoutError(string message)
101  {
102  if (message.Length > 1023)
103  message = message.Substring(0, 1023);
104 
105  World.SimChat(Utils.StringToBytes(message),
106  ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
107 
108  IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
109  wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
110  }
111 
117  {
118  if (!m_LSFunctionsEnabled)
119  {
120  LSShoutError("LightShare functions are not enabled.");
121  return new LSL_List();
122  }
123  m_host.AddScriptLPS(1);
124  RegionLightShareData wl = m_host.ParentGroup.Scene.RegionInfo.WindlightSettings;
125 
126  LSL_List values = new LSL_List();
127  int idx = 0;
128  while (idx < rules.Length)
129  {
130  LSL_Integer ruleInt = rules.GetLSLIntegerItem(idx);
131  uint rule = (uint)ruleInt;
132  LSL_List toadd = new LSL_List();
133 
134  switch (rule)
135  {
136  case (int)ScriptBaseClass.WL_AMBIENT:
137  toadd.Add(new LSL_Rotation(wl.ambient.X, wl.ambient.Y, wl.ambient.Z, wl.ambient.W));
138  break;
139  case (int)ScriptBaseClass.WL_BIG_WAVE_DIRECTION:
140  toadd.Add(new LSL_Vector(wl.bigWaveDirection.X, wl.bigWaveDirection.Y, 0.0f));
141  break;
142  case (int)ScriptBaseClass.WL_BLUE_DENSITY:
143  toadd.Add(new LSL_Rotation(wl.blueDensity.X, wl.blueDensity.Y, wl.blueDensity.Z, wl.blueDensity.W));
144  break;
145  case (int)ScriptBaseClass.WL_BLUR_MULTIPLIER:
146  toadd.Add(new LSL_Float(wl.blurMultiplier));
147  break;
148  case (int)ScriptBaseClass.WL_CLOUD_COLOR:
149  toadd.Add(new LSL_Rotation(wl.cloudColor.X, wl.cloudColor.Y, wl.cloudColor.Z, wl.cloudColor.W));
150  break;
151  case (int)ScriptBaseClass.WL_CLOUD_COVERAGE:
152  toadd.Add(new LSL_Float(wl.cloudCoverage));
153  break;
154  case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY:
155  toadd.Add(new LSL_Vector(wl.cloudDetailXYDensity.X, wl.cloudDetailXYDensity.Y, wl.cloudDetailXYDensity.Z));
156  break;
157  case (int)ScriptBaseClass.WL_CLOUD_SCALE:
158  toadd.Add(new LSL_Float(wl.cloudScale));
159  break;
160  case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X:
161  toadd.Add(new LSL_Float(wl.cloudScrollX));
162  break;
163  case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK:
164  toadd.Add(new LSL_Integer(wl.cloudScrollXLock ? 1 : 0));
165  break;
166  case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y:
167  toadd.Add(new LSL_Float(wl.cloudScrollY));
168  break;
169  case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK:
170  toadd.Add(new LSL_Integer(wl.cloudScrollYLock ? 1 : 0));
171  break;
172  case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY:
173  toadd.Add(new LSL_Vector(wl.cloudXYDensity.X, wl.cloudXYDensity.Y, wl.cloudXYDensity.Z));
174  break;
175  case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER:
176  toadd.Add(new LSL_Float(wl.densityMultiplier));
177  break;
178  case (int)ScriptBaseClass.WL_DISTANCE_MULTIPLIER:
179  toadd.Add(new LSL_Float(wl.distanceMultiplier));
180  break;
181  case (int)ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS:
182  toadd.Add(new LSL_Integer(wl.drawClassicClouds ? 1 : 0));
183  break;
184  case (int)ScriptBaseClass.WL_EAST_ANGLE:
185  toadd.Add(new LSL_Float(wl.eastAngle));
186  break;
187  case (int)ScriptBaseClass.WL_FRESNEL_OFFSET:
188  toadd.Add(new LSL_Float(wl.fresnelOffset));
189  break;
190  case (int)ScriptBaseClass.WL_FRESNEL_SCALE:
191  toadd.Add(new LSL_Float(wl.fresnelScale));
192  break;
193  case (int)ScriptBaseClass.WL_HAZE_DENSITY:
194  toadd.Add(new LSL_Float(wl.hazeDensity));
195  break;
196  case (int)ScriptBaseClass.WL_HAZE_HORIZON:
197  toadd.Add(new LSL_Float(wl.hazeHorizon));
198  break;
199  case (int)ScriptBaseClass.WL_HORIZON:
200  toadd.Add(new LSL_Rotation(wl.horizon.X, wl.horizon.Y, wl.horizon.Z, wl.horizon.W));
201  break;
202  case (int)ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION:
203  toadd.Add(new LSL_Vector(wl.littleWaveDirection.X, wl.littleWaveDirection.Y, 0.0f));
204  break;
205  case (int)ScriptBaseClass.WL_MAX_ALTITUDE:
206  toadd.Add(new LSL_Integer(wl.maxAltitude));
207  break;
208  case (int)ScriptBaseClass.WL_NORMAL_MAP_TEXTURE:
209  toadd.Add(new LSL_Key(wl.normalMapTexture.ToString()));
210  break;
211  case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE:
212  toadd.Add(new LSL_Vector(wl.reflectionWaveletScale.X, wl.reflectionWaveletScale.Y, wl.reflectionWaveletScale.Z));
213  break;
214  case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE:
215  toadd.Add(new LSL_Float(wl.refractScaleAbove));
216  break;
217  case (int)ScriptBaseClass.WL_REFRACT_SCALE_BELOW:
218  toadd.Add(new LSL_Float(wl.refractScaleBelow));
219  break;
220  case (int)ScriptBaseClass.WL_SCENE_GAMMA:
221  toadd.Add(new LSL_Float(wl.sceneGamma));
222  break;
223  case (int)ScriptBaseClass.WL_STAR_BRIGHTNESS:
224  toadd.Add(new LSL_Float(wl.starBrightness));
225  break;
226  case (int)ScriptBaseClass.WL_SUN_GLOW_FOCUS:
227  toadd.Add(new LSL_Float(wl.sunGlowFocus));
228  break;
229  case (int)ScriptBaseClass.WL_SUN_GLOW_SIZE:
230  toadd.Add(new LSL_Float(wl.sunGlowSize));
231  break;
232  case (int)ScriptBaseClass.WL_SUN_MOON_COLOR:
233  toadd.Add(new LSL_Rotation(wl.sunMoonColor.X, wl.sunMoonColor.Y, wl.sunMoonColor.Z, wl.sunMoonColor.W));
234  break;
235  case (int)ScriptBaseClass.WL_SUN_MOON_POSITION:
236  toadd.Add(new LSL_Float(wl.sunMoonPosition));
237  break;
238  case (int)ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER:
239  toadd.Add(new LSL_Float(wl.underwaterFogModifier));
240  break;
241  case (int)ScriptBaseClass.WL_WATER_COLOR:
242  toadd.Add(new LSL_Vector(wl.waterColor.X, wl.waterColor.Y, wl.waterColor.Z));
243  break;
244  case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT:
245  toadd.Add(new LSL_Float(wl.waterFogDensityExponent));
246  break;
247  }
248 
249  if (toadd.Length > 0)
250  {
251  values.Add(ruleInt);
252  values.Add(toadd.Data[0]);
253  }
254  idx++;
255  }
256 
257  return values;
258  }
259 
260  private RegionLightShareData getWindlightProfileFromRules(LSL_List rules)
261  {
262  RegionLightShareData wl = (RegionLightShareData)m_host.ParentGroup.Scene.RegionInfo.WindlightSettings.Clone();
263 
264 // LSL_List values = new LSL_List();
265  int idx = 0;
266  while (idx < rules.Length)
267  {
268  uint rule;
269 
270  try
271  {
272  rule = (uint)rules.GetLSLIntegerItem(idx);
273  }
274  catch (InvalidCastException)
275  {
276  throw new InvalidCastException(string.Format("Error running rule type: arg #{0} - parameter type must be integer", idx));
277  }
278 
281  switch (rule)
282  {
283  case (int)ScriptBaseClass.WL_SUN_MOON_POSITION:
284  idx++;
285  try
286  {
287  wl.sunMoonPosition = (float)rules.GetLSLFloatItem(idx);
288  }
289  catch (InvalidCastException)
290  {
291  throw new InvalidCastException(string.Format("Error running rule WL_SUN_MOON_POSITION: arg #{0} - parameter 1 must be float", idx));
292  }
293  break;
294  case (int)ScriptBaseClass.WL_AMBIENT:
295  idx++;
296  try
297  {
298  iQ = rules.GetQuaternionItem(idx);
299  }
300  catch (InvalidCastException)
301  {
302  throw new InvalidCastException(string.Format("Error running rule WL_AMBIENT: arg #{0} - parameter 1 must be rotation", idx));
303  }
304  wl.ambient = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
305  break;
306  case (int)ScriptBaseClass.WL_BIG_WAVE_DIRECTION:
307  idx++;
308  try
309  {
310  iV = rules.GetVector3Item(idx);
311  }
312  catch (InvalidCastException)
313  {
314  throw new InvalidCastException(string.Format("Error running rule WL_BIG_WAVE_DIRECTION: arg #{0} - parameter 1 must be vector", idx));
315  }
316  wl.bigWaveDirection = new Vector2((float)iV.x, (float)iV.y);
317  break;
318  case (int)ScriptBaseClass.WL_BLUE_DENSITY:
319  idx++;
320  try
321  {
322  iQ = rules.GetQuaternionItem(idx);
323  }
324  catch (InvalidCastException)
325  {
326  throw new InvalidCastException(string.Format("Error running rule WL_BLUE_DENSITY: arg #{0} - parameter 1 must be rotation", idx));
327  }
328  wl.blueDensity = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
329  break;
330  case (int)ScriptBaseClass.WL_BLUR_MULTIPLIER:
331  idx++;
332  try
333  {
334  wl.blurMultiplier = (float)rules.GetLSLFloatItem(idx);
335  }
336  catch (InvalidCastException)
337  {
338  throw new InvalidCastException(string.Format("Error running rule WL_BLUR_MULTIPLIER: arg #{0} - parameter 1 must be float", idx));
339  }
340  break;
341  case (int)ScriptBaseClass.WL_CLOUD_COLOR:
342  idx++;
343  try
344  {
345  iQ = rules.GetQuaternionItem(idx);
346  }
347  catch (InvalidCastException)
348  {
349  throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_COLOR: arg #{0} - parameter 1 must be rotation", idx));
350  }
351  wl.cloudColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
352  break;
353  case (int)ScriptBaseClass.WL_CLOUD_COVERAGE:
354  idx++;
355  try
356  {
357  wl.cloudCoverage = (float)rules.GetLSLFloatItem(idx);
358  }
359  catch (InvalidCastException)
360  {
361  throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_COVERAGE: arg #{0} - parameter 1 must be float", idx));
362  }
363  break;
364  case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY:
365  idx++;
366  try
367  {
368  iV = rules.GetVector3Item(idx);
369  }
370  catch (InvalidCastException)
371  {
372  throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_DETAIL_XY_DENSITY: arg #{0} - parameter 1 must be vector", idx));
373  }
374  wl.cloudDetailXYDensity = iV;
375  break;
376  case (int)ScriptBaseClass.WL_CLOUD_SCALE:
377  idx++;
378  try
379  {
380  wl.cloudScale = (float)rules.GetLSLFloatItem(idx);
381  }
382  catch (InvalidCastException)
383  {
384  throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCALE: arg #{0} - parameter 1 must be float", idx));
385  }
386  break;
387  case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X:
388  idx++;
389  try
390  {
391  wl.cloudScrollX = (float)rules.GetLSLFloatItem(idx);
392  }
393  catch (InvalidCastException)
394  {
395  throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCROLL_X: arg #{0} - parameter 1 must be float", idx));
396  }
397  break;
398  case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK:
399  idx++;
400  try
401  {
402  wl.cloudScrollXLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false;
403  }
404  catch (InvalidCastException)
405  {
406  throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCROLL_Y_LOCK: arg #{0} - parameter 1 must be integer", idx));
407  }
408  break;
409  case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y:
410  idx++;
411  try
412  {
413  wl.cloudScrollY = (float)rules.GetLSLFloatItem(idx);
414  }
415  catch (InvalidCastException)
416  {
417  throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCROLL_Y: arg #{0} - parameter 1 must be float", idx));
418  }
419  break;
420  case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK:
421  idx++;
422  try
423  {
424  wl.cloudScrollYLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false;
425  }
426  catch (InvalidCastException)
427  {
428  throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCROLL_Y_LOCK: arg #{0} - parameter 1 must be integer", idx));
429  }
430  break;
431  case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY:
432  idx++;
433  try
434  {
435  iV = rules.GetVector3Item(idx);
436  }
437  catch (InvalidCastException)
438  {
439  throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_XY_DENSITY: arg #{0} - parameter 1 must be vector", idx));
440  }
441  wl.cloudXYDensity = iV;
442  break;
443  case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER:
444  idx++;
445  try
446  {
447  wl.densityMultiplier = (float)rules.GetLSLFloatItem(idx);
448  }
449  catch (InvalidCastException)
450  {
451  throw new InvalidCastException(string.Format("Error running rule WL_DENSITY_MULTIPLIER: arg #{0} - parameter 1 must be float", idx));
452  }
453  break;
454  case (int)ScriptBaseClass.WL_DISTANCE_MULTIPLIER:
455  idx++;
456  try
457  {
458  wl.distanceMultiplier = (float)rules.GetLSLFloatItem(idx);
459  }
460  catch (InvalidCastException)
461  {
462  throw new InvalidCastException(string.Format("Error running rule WL_DISTANCE_MULTIPLIER: arg #{0} - parameter 1 must be float", idx));
463  }
464  break;
465  case (int)ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS:
466  idx++;
467  try
468  {
469  wl.drawClassicClouds = rules.GetLSLIntegerItem(idx).value == 1 ? true : false;
470  }
471  catch (InvalidCastException)
472  {
473  throw new InvalidCastException(string.Format("Error running rule WL_DRAW_CLASSIC_CLOUDS: arg #{0} - parameter 1 must be integer", idx));
474  }
475  break;
476  case (int)ScriptBaseClass.WL_EAST_ANGLE:
477  idx++;
478  try
479  {
480  wl.eastAngle = (float)rules.GetLSLFloatItem(idx);
481  }
482  catch (InvalidCastException)
483  {
484  throw new InvalidCastException(string.Format("Error running rule WL_EAST_ANGLE: arg #{0} - parameter 1 must be float", idx));
485  }
486  break;
487  case (int)ScriptBaseClass.WL_FRESNEL_OFFSET:
488  idx++;
489  try
490  {
491  wl.fresnelOffset = (float)rules.GetLSLFloatItem(idx);
492  }
493  catch (InvalidCastException)
494  {
495  throw new InvalidCastException(string.Format("Error running rule WL_FRESNEL_OFFSET: arg #{0} - parameter 1 must be float", idx));
496  }
497  break;
498  case (int)ScriptBaseClass.WL_FRESNEL_SCALE:
499  idx++;
500  try
501  {
502  wl.fresnelScale = (float)rules.GetLSLFloatItem(idx);
503  }
504  catch (InvalidCastException)
505  {
506  throw new InvalidCastException(string.Format("Error running rule WL_FRESNEL_SCALE: arg #{0} - parameter 1 must be float", idx));
507  }
508  break;
509  case (int)ScriptBaseClass.WL_HAZE_DENSITY:
510  idx++;
511  try
512  {
513  wl.hazeDensity = (float)rules.GetLSLFloatItem(idx);
514  }
515  catch (InvalidCastException)
516  {
517  throw new InvalidCastException(string.Format("Error running rule WL_HAZE_DENSITY: arg #{0} - parameter 1 must be float", idx));
518  }
519  break;
520  case (int)ScriptBaseClass.WL_HAZE_HORIZON:
521  idx++;
522  try
523  {
524  wl.hazeHorizon = (float)rules.GetLSLFloatItem(idx);
525  }
526  catch (InvalidCastException)
527  {
528  throw new InvalidCastException(string.Format("Error running rule WL_HAZE_HORIZON: arg #{0} - parameter 1 must be float", idx));
529  }
530  break;
531  case (int)ScriptBaseClass.WL_HORIZON:
532  idx++;
533  try
534  {
535  iQ = rules.GetQuaternionItem(idx);
536  }
537  catch (InvalidCastException)
538  {
539  throw new InvalidCastException(string.Format("Error running rule WL_HORIZON: arg #{0} - parameter 1 must be rotation", idx));
540  }
541  wl.horizon = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
542  break;
543  case (int)ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION:
544  idx++;
545  try
546  {
547  iV = rules.GetVector3Item(idx);
548  }
549  catch (InvalidCastException)
550  {
551  throw new InvalidCastException(string.Format("Error running rule WL_LITTLE_WAVE_DIRECTION: arg #{0} - parameter 1 must be vector", idx));
552  }
553  wl.littleWaveDirection = new Vector2((float)iV.x, (float)iV.y);
554  break;
555  case (int)ScriptBaseClass.WL_MAX_ALTITUDE:
556  idx++;
557  try
558  {
559  wl.maxAltitude = (ushort)rules.GetLSLIntegerItem(idx).value;
560  }
561  catch (InvalidCastException)
562  {
563  throw new InvalidCastException(string.Format("Error running rule WL_MAX_ALTITUDE: arg #{0} - parameter 1 must be integer", idx));
564  }
565  break;
566  case (int)ScriptBaseClass.WL_NORMAL_MAP_TEXTURE:
567  idx++;
568  try
569  {
570  wl.normalMapTexture = new UUID(rules.GetLSLStringItem(idx).m_string);
571  }
572  catch (ArgumentException)
573  {
574  throw new InvalidCastException(string.Format("Error running rule WL_NORMAL_MAP_TEXTURE: arg #{0} - parameter 1 must be key", idx));
575  }
576  break;
577  case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE:
578  idx++;
579  try
580  {
581  iV = rules.GetVector3Item(idx);
582  }
583  catch (InvalidCastException)
584  {
585  throw new InvalidCastException(string.Format("Error running rule WL_REFLECTION_WAVELET_SCALE: arg #{0} - parameter 1 must be vector", idx));
586  }
587  wl.reflectionWaveletScale = iV;
588  break;
589  case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE:
590  idx++;
591  try
592  {
593  wl.refractScaleAbove = (float)rules.GetLSLFloatItem(idx);
594  }
595  catch (InvalidCastException)
596  {
597  throw new InvalidCastException(string.Format("Error running rule WL_REFRACT_SCALE_ABOVE: arg #{0} - parameter 1 must be float", idx));
598  }
599  break;
600  case (int)ScriptBaseClass.WL_REFRACT_SCALE_BELOW:
601  idx++;
602  try
603  {
604  wl.refractScaleBelow = (float)rules.GetLSLFloatItem(idx);
605  }
606  catch (InvalidCastException)
607  {
608  throw new InvalidCastException(string.Format("Error running rule WL_REFRACT_SCALE_BELOW: arg #{0} - parameter 1 must be float", idx));
609  }
610  break;
611  case (int)ScriptBaseClass.WL_SCENE_GAMMA:
612  idx++;
613  try
614  {
615  wl.sceneGamma = (float)rules.GetLSLFloatItem(idx);
616  }
617  catch (InvalidCastException)
618  {
619  throw new InvalidCastException(string.Format("Error running rule WL_SCENE_GAMMA: arg #{0} - parameter 1 must be float", idx));
620  }
621  break;
622  case (int)ScriptBaseClass.WL_STAR_BRIGHTNESS:
623  idx++;
624  try
625  {
626  wl.starBrightness = (float)rules.GetLSLFloatItem(idx);
627  }
628  catch (InvalidCastException)
629  {
630  throw new InvalidCastException(string.Format("Error running rule WL_STAR_BRIGHTNESS: arg #{0} - parameter 1 must be float", idx));
631  }
632  break;
633  case (int)ScriptBaseClass.WL_SUN_GLOW_FOCUS:
634  idx++;
635  try
636  {
637  wl.sunGlowFocus = (float)rules.GetLSLFloatItem(idx);
638  }
639  catch (InvalidCastException)
640  {
641  throw new InvalidCastException(string.Format("Error running rule WL_SUN_GLOW_FOCUS: arg #{0} - parameter 1 must be float", idx));
642  }
643  break;
644  case (int)ScriptBaseClass.WL_SUN_GLOW_SIZE:
645  idx++;
646  try
647  {
648  wl.sunGlowSize = (float)rules.GetLSLFloatItem(idx);
649  }
650  catch (InvalidCastException)
651  {
652  throw new InvalidCastException(string.Format("Error running rule WL_SUN_GLOW_SIZE: arg #{0} - parameter 1 must be float", idx));
653  }
654  break;
655  case (int)ScriptBaseClass.WL_SUN_MOON_COLOR:
656  idx++;
657  iQ = rules.GetQuaternionItem(idx);
658  try
659  {
660  wl.sunMoonColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
661  }
662  catch (InvalidCastException)
663  {
664  throw new InvalidCastException(string.Format("Error running rule WL_SUN_MOON_COLOR: arg #{0} - parameter 1 must be rotation", idx));
665  }
666  break;
667  case (int)ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER:
668  idx++;
669  try
670  {
671  wl.underwaterFogModifier = (float)rules.GetLSLFloatItem(idx);
672  }
673  catch (InvalidCastException)
674  {
675  throw new InvalidCastException(string.Format("Error running rule WL_UNDERWATER_FOG_MODIFIER: arg #{0} - parameter 1 must be float", idx));
676  }
677  break;
678  case (int)ScriptBaseClass.WL_WATER_COLOR:
679  idx++;
680  try
681  {
682  iV = rules.GetVector3Item(idx);
683  }
684  catch (InvalidCastException)
685  {
686  throw new InvalidCastException(string.Format("Error running rule WL_WATER_COLOR: arg #{0} - parameter 1 must be vector", idx));
687  }
688  wl.waterColor = iV;
689  break;
690  case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT:
691  idx++;
692  try
693  {
694  wl.waterFogDensityExponent = (float)rules.GetLSLFloatItem(idx);
695  }
696  catch (InvalidCastException)
697  {
698  throw new InvalidCastException(string.Format("Error running rule WL_WATER_FOG_DENSITY_EXPONENT: arg #{0} - parameter 1 must be float", idx));
699  }
700  break;
701  }
702  idx++;
703  }
704  return wl;
705  }
706 
712  public int lsSetWindlightScene(LSL_List rules)
713  {
714  if (!m_LSFunctionsEnabled)
715  {
716  LSShoutError("LightShare functions are not enabled.");
717  return 0;
718  }
719 
720  if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID))
721  {
722  ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
723 
724  if (sp == null || sp.GodLevel < 200)
725  {
726  LSShoutError("lsSetWindlightScene can only be used by estate managers or owners.");
727  return 0;
728  }
729  }
730 
731  int success = 0;
732  m_host.AddScriptLPS(1);
733 
735  {
737  try
738  {
739  wl = getWindlightProfileFromRules(rules);
740  }
741  catch(InvalidCastException e)
742  {
743  LSShoutError(e.Message);
744  return 0;
745  }
746  wl.valid = true;
747  m_host.ParentGroup.Scene.StoreWindlightProfile(wl);
748  success = 1;
749  }
750  else
751  {
752  LSShoutError("Windlight module is disabled");
753  return 0;
754  }
755 
756  return success;
757  }
758 
759  public void lsClearWindlightScene()
760  {
761  if (!m_LSFunctionsEnabled)
762  {
763  LSShoutError("LightShare functions are not enabled.");
764  return;
765  }
766 
767  if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID))
768  {
769  ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
770 
771  if (sp == null || sp.GodLevel < 200)
772  {
773  LSShoutError("lsSetWindlightScene can only be used by estate managers or owners.");
774  return;
775  }
776  }
777 
778  m_host.ParentGroup.Scene.RegionInfo.WindlightSettings.valid = false;
779  if (m_host.ParentGroup.Scene.SimulationDataService != null)
780  m_host.ParentGroup.Scene.SimulationDataService.RemoveRegionWindlightSettings(m_host.ParentGroup.Scene.RegionInfo.RegionID);
781 
782  m_host.ParentGroup.Scene.EventManager.TriggerOnSaveNewWindlightProfile();
783  }
784 
790  public int lsSetWindlightSceneTargeted(LSL_List rules, LSL_Key target)
791  {
792  if (!m_LSFunctionsEnabled)
793  {
794  LSShoutError("LightShare functions are not enabled.");
795  return 0;
796  }
797 
798  if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID))
799  {
800  ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
801 
802  if (sp == null || sp.GodLevel < 200)
803  {
804  LSShoutError("lsSetWindlightSceneTargeted can only be used by estate managers or owners.");
805  return 0;
806  }
807  }
808 
809  int success = 0;
810  m_host.AddScriptLPS(1);
811 
813  {
815  try
816  {
817  wl = getWindlightProfileFromRules(rules);
818  }
819  catch(InvalidCastException e)
820  {
821  LSShoutError(e.Message);
822  return 0;
823  }
824  World.EventManager.TriggerOnSendNewWindlightProfileTargeted(wl, new UUID(target.m_string));
825  success = 1;
826  }
827  else
828  {
829  LSShoutError("Windlight module is disabled");
830  return 0;
831  }
832 
833  return success;
834  }
835  }
836 }
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat LSL_Float
Definition: CM_Api.cs:48
OpenSim.Region.ScriptEngine.Shared.LSL_Types.list LSL_List
Definition: CM_Api.cs:51
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger LSL_Integer
Definition: LS_Api.cs:48
int lsSetWindlightScene(LSL_List rules)
Set the current Windlight scene
Definition: LS_Api.cs:712
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString LSL_Key
Definition: CM_Api.cs:50
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat LSL_Float
Definition: LS_Api.cs:47
OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion LSL_Rotation
Definition: LS_Api.cs:51
Represents an item in a task inventory
OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3 LSL_Vector
Definition: LS_Api.cs:53
OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3 LSL_Vector
Definition: CM_Api.cs:54
LSL_List lsGetWindlightScene(LSL_List rules)
Get the current Windlight scene
Definition: LS_Api.cs:116
An interface for a script API module to communicate with the engine it's running under ...
void Initialize(IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item)
Initialize the API
Definition: LS_Api.cs:65
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger LSL_Integer
Definition: CM_Api.cs:49
Interface for communication between OpenSim modules and in-world scripts
OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion LSL_Rotation
Definition: CM_Api.cs:52
Interactive OpenSim region server
Definition: OpenSim.cs:55
int lsSetWindlightSceneTargeted(LSL_List rules, LSL_Key target)
Set the current Windlight scene to a target avatar
Definition: LS_Api.cs:790
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger LSLInteger
Definition: CM_Constants.cs:31
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString LSL_String
Definition: CM_Api.cs:53
OpenSim.Region.ScriptEngine.Shared.LSL_Types.list LSL_List
Definition: LS_Api.cs:50
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString LSL_Key
Definition: LS_Api.cs:49