LS_Api.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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. using System;
  28. using System.Reflection;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.Runtime.Remoting.Lifetime;
  32. using System.Threading;
  33. using OpenMetaverse;
  34. using Nini.Config;
  35. using OpenSim;
  36. using OpenSim.Framework;
  37. using OpenSim.Region.CoreModules.World.LightShare;
  38. using OpenSim.Region.Framework.Interfaces;
  39. using OpenSim.Region.Framework.Scenes;
  40. using OpenSim.Region.ScriptEngine.Shared;
  41. using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
  42. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  43. using OpenSim.Region.ScriptEngine.Interfaces;
  44. using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
  45. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  46. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  47. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  48. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  49. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  50. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  51. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  52. namespace OpenSim.Region.ScriptEngine.Shared.Api
  53. {
  54. [Serializable]
  55. public class LS_Api : MarshalByRefObject, ILS_Api, IScriptApi
  56. {
  57. internal IScriptEngine m_ScriptEngine;
  58. internal SceneObjectPart m_host;
  59. internal bool m_LSFunctionsEnabled = false;
  60. internal IScriptModuleComms m_comms = null;
  61. public void Initialize(
  62. IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, WaitHandle coopSleepHandle)
  63. {
  64. m_ScriptEngine = scriptEngine;
  65. m_host = host;
  66. if (m_ScriptEngine.Config.GetBoolean("AllowLightShareFunctions", false))
  67. m_LSFunctionsEnabled = true;
  68. m_comms = m_ScriptEngine.World.RequestModuleInterface<IScriptModuleComms>();
  69. if (m_comms == null)
  70. m_LSFunctionsEnabled = false;
  71. }
  72. public override Object InitializeLifetimeService()
  73. {
  74. ILease lease = (ILease)base.InitializeLifetimeService();
  75. if (lease.CurrentState == LeaseState.Initial)
  76. {
  77. lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
  78. // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
  79. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
  80. }
  81. return lease;
  82. }
  83. public Scene World
  84. {
  85. get { return m_ScriptEngine.World; }
  86. }
  87. /// <summary>
  88. /// Dumps an error message on the debug console.
  89. /// </summary>
  90. internal void LSShoutError(string message)
  91. {
  92. if (message.Length > 1023)
  93. message = message.Substring(0, 1023);
  94. World.SimChat(Utils.StringToBytes(message),
  95. ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  96. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  97. wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
  98. }
  99. /// <summary>
  100. /// Get the current Windlight scene
  101. /// </summary>
  102. /// <returns>List of windlight parameters</returns>
  103. public LSL_List lsGetWindlightScene(LSL_List rules)
  104. {
  105. if (!m_LSFunctionsEnabled)
  106. {
  107. LSShoutError("LightShare functions are not enabled.");
  108. return new LSL_List();
  109. }
  110. m_host.AddScriptLPS(1);
  111. RegionLightShareData wl = m_host.ParentGroup.Scene.RegionInfo.WindlightSettings;
  112. LSL_List values = new LSL_List();
  113. int idx = 0;
  114. while (idx < rules.Length)
  115. {
  116. LSL_Integer ruleInt = rules.GetLSLIntegerItem(idx);
  117. uint rule = (uint)ruleInt;
  118. LSL_List toadd = new LSL_List();
  119. switch (rule)
  120. {
  121. case (int)ScriptBaseClass.WL_AMBIENT:
  122. toadd.Add(new LSL_Rotation(wl.ambient.X, wl.ambient.Y, wl.ambient.Z, wl.ambient.W));
  123. break;
  124. case (int)ScriptBaseClass.WL_BIG_WAVE_DIRECTION:
  125. toadd.Add(new LSL_Vector(wl.bigWaveDirection.X, wl.bigWaveDirection.Y, 0.0f));
  126. break;
  127. case (int)ScriptBaseClass.WL_BLUE_DENSITY:
  128. toadd.Add(new LSL_Rotation(wl.blueDensity.X, wl.blueDensity.Y, wl.blueDensity.Z, wl.blueDensity.W));
  129. break;
  130. case (int)ScriptBaseClass.WL_BLUR_MULTIPLIER:
  131. toadd.Add(new LSL_Float(wl.blurMultiplier));
  132. break;
  133. case (int)ScriptBaseClass.WL_CLOUD_COLOR:
  134. toadd.Add(new LSL_Rotation(wl.cloudColor.X, wl.cloudColor.Y, wl.cloudColor.Z, wl.cloudColor.W));
  135. break;
  136. case (int)ScriptBaseClass.WL_CLOUD_COVERAGE:
  137. toadd.Add(new LSL_Float(wl.cloudCoverage));
  138. break;
  139. case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY:
  140. toadd.Add(new LSL_Vector(wl.cloudDetailXYDensity.X, wl.cloudDetailXYDensity.Y, wl.cloudDetailXYDensity.Z));
  141. break;
  142. case (int)ScriptBaseClass.WL_CLOUD_SCALE:
  143. toadd.Add(new LSL_Float(wl.cloudScale));
  144. break;
  145. case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X:
  146. toadd.Add(new LSL_Float(wl.cloudScrollX));
  147. break;
  148. case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK:
  149. toadd.Add(new LSL_Integer(wl.cloudScrollXLock ? 1 : 0));
  150. break;
  151. case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y:
  152. toadd.Add(new LSL_Float(wl.cloudScrollY));
  153. break;
  154. case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK:
  155. toadd.Add(new LSL_Integer(wl.cloudScrollYLock ? 1 : 0));
  156. break;
  157. case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY:
  158. toadd.Add(new LSL_Vector(wl.cloudXYDensity.X, wl.cloudXYDensity.Y, wl.cloudXYDensity.Z));
  159. break;
  160. case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER:
  161. toadd.Add(new LSL_Float(wl.densityMultiplier));
  162. break;
  163. case (int)ScriptBaseClass.WL_DISTANCE_MULTIPLIER:
  164. toadd.Add(new LSL_Float(wl.distanceMultiplier));
  165. break;
  166. case (int)ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS:
  167. toadd.Add(new LSL_Integer(wl.drawClassicClouds ? 1 : 0));
  168. break;
  169. case (int)ScriptBaseClass.WL_EAST_ANGLE:
  170. toadd.Add(new LSL_Float(wl.eastAngle));
  171. break;
  172. case (int)ScriptBaseClass.WL_FRESNEL_OFFSET:
  173. toadd.Add(new LSL_Float(wl.fresnelOffset));
  174. break;
  175. case (int)ScriptBaseClass.WL_FRESNEL_SCALE:
  176. toadd.Add(new LSL_Float(wl.fresnelScale));
  177. break;
  178. case (int)ScriptBaseClass.WL_HAZE_DENSITY:
  179. toadd.Add(new LSL_Float(wl.hazeDensity));
  180. break;
  181. case (int)ScriptBaseClass.WL_HAZE_HORIZON:
  182. toadd.Add(new LSL_Float(wl.hazeHorizon));
  183. break;
  184. case (int)ScriptBaseClass.WL_HORIZON:
  185. toadd.Add(new LSL_Rotation(wl.horizon.X, wl.horizon.Y, wl.horizon.Z, wl.horizon.W));
  186. break;
  187. case (int)ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION:
  188. toadd.Add(new LSL_Vector(wl.littleWaveDirection.X, wl.littleWaveDirection.Y, 0.0f));
  189. break;
  190. case (int)ScriptBaseClass.WL_MAX_ALTITUDE:
  191. toadd.Add(new LSL_Integer(wl.maxAltitude));
  192. break;
  193. case (int)ScriptBaseClass.WL_NORMAL_MAP_TEXTURE:
  194. toadd.Add(new LSL_Key(wl.normalMapTexture.ToString()));
  195. break;
  196. case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE:
  197. toadd.Add(new LSL_Vector(wl.reflectionWaveletScale.X, wl.reflectionWaveletScale.Y, wl.reflectionWaveletScale.Z));
  198. break;
  199. case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE:
  200. toadd.Add(new LSL_Float(wl.refractScaleAbove));
  201. break;
  202. case (int)ScriptBaseClass.WL_REFRACT_SCALE_BELOW:
  203. toadd.Add(new LSL_Float(wl.refractScaleBelow));
  204. break;
  205. case (int)ScriptBaseClass.WL_SCENE_GAMMA:
  206. toadd.Add(new LSL_Float(wl.sceneGamma));
  207. break;
  208. case (int)ScriptBaseClass.WL_STAR_BRIGHTNESS:
  209. toadd.Add(new LSL_Float(wl.starBrightness));
  210. break;
  211. case (int)ScriptBaseClass.WL_SUN_GLOW_FOCUS:
  212. toadd.Add(new LSL_Float(wl.sunGlowFocus));
  213. break;
  214. case (int)ScriptBaseClass.WL_SUN_GLOW_SIZE:
  215. toadd.Add(new LSL_Float(wl.sunGlowSize));
  216. break;
  217. case (int)ScriptBaseClass.WL_SUN_MOON_COLOR:
  218. toadd.Add(new LSL_Rotation(wl.sunMoonColor.X, wl.sunMoonColor.Y, wl.sunMoonColor.Z, wl.sunMoonColor.W));
  219. break;
  220. case (int)ScriptBaseClass.WL_SUN_MOON_POSITION:
  221. toadd.Add(new LSL_Float(wl.sunMoonPosition));
  222. break;
  223. case (int)ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER:
  224. toadd.Add(new LSL_Float(wl.underwaterFogModifier));
  225. break;
  226. case (int)ScriptBaseClass.WL_WATER_COLOR:
  227. toadd.Add(new LSL_Vector(wl.waterColor.X, wl.waterColor.Y, wl.waterColor.Z));
  228. break;
  229. case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT:
  230. toadd.Add(new LSL_Float(wl.waterFogDensityExponent));
  231. break;
  232. }
  233. if (toadd.Length > 0)
  234. {
  235. values.Add(ruleInt);
  236. values.Add(toadd.Data[0]);
  237. }
  238. idx++;
  239. }
  240. return values;
  241. }
  242. private RegionLightShareData getWindlightProfileFromRules(LSL_List rules)
  243. {
  244. RegionLightShareData wl = (RegionLightShareData)m_host.ParentGroup.Scene.RegionInfo.WindlightSettings.Clone();
  245. // LSL_List values = new LSL_List();
  246. int idx = 0;
  247. while (idx < rules.Length)
  248. {
  249. uint rule = (uint)rules.GetLSLIntegerItem(idx);
  250. LSL_Types.Quaternion iQ;
  251. LSL_Types.Vector3 iV;
  252. switch (rule)
  253. {
  254. case (int)ScriptBaseClass.WL_SUN_MOON_POSITION:
  255. idx++;
  256. wl.sunMoonPosition = (float)rules.GetLSLFloatItem(idx);
  257. break;
  258. case (int)ScriptBaseClass.WL_AMBIENT:
  259. idx++;
  260. iQ = rules.GetQuaternionItem(idx);
  261. wl.ambient = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
  262. break;
  263. case (int)ScriptBaseClass.WL_BIG_WAVE_DIRECTION:
  264. idx++;
  265. iV = rules.GetVector3Item(idx);
  266. wl.bigWaveDirection = new Vector2((float)iV.x, (float)iV.y);
  267. break;
  268. case (int)ScriptBaseClass.WL_BLUE_DENSITY:
  269. idx++;
  270. iQ = rules.GetQuaternionItem(idx);
  271. wl.blueDensity = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
  272. break;
  273. case (int)ScriptBaseClass.WL_BLUR_MULTIPLIER:
  274. idx++;
  275. wl.blurMultiplier = (float)rules.GetLSLFloatItem(idx);
  276. break;
  277. case (int)ScriptBaseClass.WL_CLOUD_COLOR:
  278. idx++;
  279. iQ = rules.GetQuaternionItem(idx);
  280. wl.cloudColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
  281. break;
  282. case (int)ScriptBaseClass.WL_CLOUD_COVERAGE:
  283. idx++;
  284. wl.cloudCoverage = (float)rules.GetLSLFloatItem(idx);
  285. break;
  286. case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY:
  287. idx++;
  288. iV = rules.GetVector3Item(idx);
  289. wl.cloudDetailXYDensity = iV;
  290. break;
  291. case (int)ScriptBaseClass.WL_CLOUD_SCALE:
  292. idx++;
  293. wl.cloudScale = (float)rules.GetLSLFloatItem(idx);
  294. break;
  295. case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X:
  296. idx++;
  297. wl.cloudScrollX = (float)rules.GetLSLFloatItem(idx);
  298. break;
  299. case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK:
  300. idx++;
  301. wl.cloudScrollXLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false;
  302. break;
  303. case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y:
  304. idx++;
  305. wl.cloudScrollY = (float)rules.GetLSLFloatItem(idx);
  306. break;
  307. case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK:
  308. idx++;
  309. wl.cloudScrollYLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false;
  310. break;
  311. case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY:
  312. idx++;
  313. iV = rules.GetVector3Item(idx);
  314. wl.cloudXYDensity = iV;
  315. break;
  316. case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER:
  317. idx++;
  318. wl.densityMultiplier = (float)rules.GetLSLFloatItem(idx);
  319. break;
  320. case (int)ScriptBaseClass.WL_DISTANCE_MULTIPLIER:
  321. idx++;
  322. wl.distanceMultiplier = (float)rules.GetLSLFloatItem(idx);
  323. break;
  324. case (int)ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS:
  325. idx++;
  326. wl.drawClassicClouds = rules.GetLSLIntegerItem(idx).value == 1 ? true : false;
  327. break;
  328. case (int)ScriptBaseClass.WL_EAST_ANGLE:
  329. idx++;
  330. wl.eastAngle = (float)rules.GetLSLFloatItem(idx);
  331. break;
  332. case (int)ScriptBaseClass.WL_FRESNEL_OFFSET:
  333. idx++;
  334. wl.fresnelOffset = (float)rules.GetLSLFloatItem(idx);
  335. break;
  336. case (int)ScriptBaseClass.WL_FRESNEL_SCALE:
  337. idx++;
  338. wl.fresnelScale = (float)rules.GetLSLFloatItem(idx);
  339. break;
  340. case (int)ScriptBaseClass.WL_HAZE_DENSITY:
  341. idx++;
  342. wl.hazeDensity = (float)rules.GetLSLFloatItem(idx);
  343. break;
  344. case (int)ScriptBaseClass.WL_HAZE_HORIZON:
  345. idx++;
  346. wl.hazeHorizon = (float)rules.GetLSLFloatItem(idx);
  347. break;
  348. case (int)ScriptBaseClass.WL_HORIZON:
  349. idx++;
  350. iQ = rules.GetQuaternionItem(idx);
  351. wl.horizon = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
  352. break;
  353. case (int)ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION:
  354. idx++;
  355. iV = rules.GetVector3Item(idx);
  356. wl.littleWaveDirection = new Vector2((float)iV.x, (float)iV.y);
  357. break;
  358. case (int)ScriptBaseClass.WL_MAX_ALTITUDE:
  359. idx++;
  360. wl.maxAltitude = (ushort)rules.GetLSLIntegerItem(idx).value;
  361. break;
  362. case (int)ScriptBaseClass.WL_NORMAL_MAP_TEXTURE:
  363. idx++;
  364. wl.normalMapTexture = new UUID(rules.GetLSLStringItem(idx).m_string);
  365. break;
  366. case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE:
  367. idx++;
  368. iV = rules.GetVector3Item(idx);
  369. wl.reflectionWaveletScale = iV;
  370. break;
  371. case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE:
  372. idx++;
  373. wl.refractScaleAbove = (float)rules.GetLSLFloatItem(idx);
  374. break;
  375. case (int)ScriptBaseClass.WL_REFRACT_SCALE_BELOW:
  376. idx++;
  377. wl.refractScaleBelow = (float)rules.GetLSLFloatItem(idx);
  378. break;
  379. case (int)ScriptBaseClass.WL_SCENE_GAMMA:
  380. idx++;
  381. wl.sceneGamma = (float)rules.GetLSLFloatItem(idx);
  382. break;
  383. case (int)ScriptBaseClass.WL_STAR_BRIGHTNESS:
  384. idx++;
  385. wl.starBrightness = (float)rules.GetLSLFloatItem(idx);
  386. break;
  387. case (int)ScriptBaseClass.WL_SUN_GLOW_FOCUS:
  388. idx++;
  389. wl.sunGlowFocus = (float)rules.GetLSLFloatItem(idx);
  390. break;
  391. case (int)ScriptBaseClass.WL_SUN_GLOW_SIZE:
  392. idx++;
  393. wl.sunGlowSize = (float)rules.GetLSLFloatItem(idx);
  394. break;
  395. case (int)ScriptBaseClass.WL_SUN_MOON_COLOR:
  396. idx++;
  397. iQ = rules.GetQuaternionItem(idx);
  398. wl.sunMoonColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
  399. break;
  400. case (int)ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER:
  401. idx++;
  402. wl.underwaterFogModifier = (float)rules.GetLSLFloatItem(idx);
  403. break;
  404. case (int)ScriptBaseClass.WL_WATER_COLOR:
  405. idx++;
  406. iV = rules.GetVector3Item(idx);
  407. wl.waterColor = iV;
  408. break;
  409. case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT:
  410. idx++;
  411. wl.waterFogDensityExponent = (float)rules.GetLSLFloatItem(idx);
  412. break;
  413. }
  414. idx++;
  415. }
  416. return wl;
  417. }
  418. /// <summary>
  419. /// Set the current Windlight scene
  420. /// </summary>
  421. /// <param name="rules"></param>
  422. /// <returns>success: true or false</returns>
  423. public int lsSetWindlightScene(LSL_List rules)
  424. {
  425. if (!m_LSFunctionsEnabled)
  426. {
  427. LSShoutError("LightShare functions are not enabled.");
  428. return 0;
  429. }
  430. if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID))
  431. {
  432. ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
  433. if (sp == null || sp.GodLevel < 200)
  434. {
  435. LSShoutError("lsSetWindlightScene can only be used by estate managers or owners.");
  436. return 0;
  437. }
  438. }
  439. int success = 0;
  440. m_host.AddScriptLPS(1);
  441. if (LightShareModule.EnableWindlight)
  442. {
  443. RegionLightShareData wl = getWindlightProfileFromRules(rules);
  444. wl.valid = true;
  445. m_host.ParentGroup.Scene.StoreWindlightProfile(wl);
  446. success = 1;
  447. }
  448. else
  449. {
  450. LSShoutError("Windlight module is disabled");
  451. return 0;
  452. }
  453. return success;
  454. }
  455. public void lsClearWindlightScene()
  456. {
  457. if (!m_LSFunctionsEnabled)
  458. {
  459. LSShoutError("LightShare functions are not enabled.");
  460. return;
  461. }
  462. if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID))
  463. {
  464. ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
  465. if (sp == null || sp.GodLevel < 200)
  466. {
  467. LSShoutError("lsSetWindlightScene can only be used by estate managers or owners.");
  468. return;
  469. }
  470. }
  471. m_host.ParentGroup.Scene.RegionInfo.WindlightSettings.valid = false;
  472. if (m_host.ParentGroup.Scene.SimulationDataService != null)
  473. m_host.ParentGroup.Scene.SimulationDataService.RemoveRegionWindlightSettings(m_host.ParentGroup.Scene.RegionInfo.RegionID);
  474. m_host.ParentGroup.Scene.EventManager.TriggerOnSaveNewWindlightProfile();
  475. }
  476. /// <summary>
  477. /// Set the current Windlight scene to a target avatar
  478. /// </summary>
  479. /// <param name="rules"></param>
  480. /// <returns>success: true or false</returns>
  481. public int lsSetWindlightSceneTargeted(LSL_List rules, LSL_Key target)
  482. {
  483. if (!m_LSFunctionsEnabled)
  484. {
  485. LSShoutError("LightShare functions are not enabled.");
  486. return 0;
  487. }
  488. if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID))
  489. {
  490. ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
  491. if (sp == null || sp.GodLevel < 200)
  492. {
  493. LSShoutError("lsSetWindlightSceneTargeted can only be used by estate managers or owners.");
  494. return 0;
  495. }
  496. }
  497. int success = 0;
  498. m_host.AddScriptLPS(1);
  499. if (LightShareModule.EnableWindlight)
  500. {
  501. RegionLightShareData wl = getWindlightProfileFromRules(rules);
  502. World.EventManager.TriggerOnSendNewWindlightProfileTargeted(wl, new UUID(target.m_string));
  503. success = 1;
  504. }
  505. else
  506. {
  507. LSShoutError("Windlight module is disabled");
  508. return 0;
  509. }
  510. return success;
  511. }
  512. }
  513. }