PageRenderTime 31ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/Aurora/AuroraDotNetEngine/APIs/OSSL_Api.cs

https://bitbucket.org/VirtualReality/async-sim-testing
C# | 2846 lines | 2135 code | 432 blank | 279 comment | 490 complexity | 5007e9acdc0569cdeca3a8afef972619 MD5 | raw file
  1. /*
  2. * Copyright (c) Contributors, http://aurora-sim.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 Aurora-Sim 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.Collections;
  29. using System.Collections.Generic;
  30. using System.Diagnostics;
  31. using System.Globalization;
  32. using System.Linq;
  33. using System.Net;
  34. using System.Runtime.Remoting.Lifetime;
  35. using System.Text;
  36. using System.Text.RegularExpressions;
  37. using Aurora.Framework;
  38. using Aurora.Framework.ClientInterfaces;
  39. using Aurora.Framework.ConsoleFramework;
  40. using Aurora.Framework.Modules;
  41. using Aurora.Framework.PresenceInfo;
  42. using Aurora.Framework.SceneInfo;
  43. using Aurora.Framework.SceneInfo.Entities;
  44. using Aurora.Framework.Servers;
  45. using Aurora.Framework.Services;
  46. using Aurora.Framework.Services.ClassHelpers.Assets;
  47. using Aurora.Framework.Utilities;
  48. using Aurora.ScriptEngine.AuroraDotNetEngine.APIs.Interfaces;
  49. using Aurora.ScriptEngine.AuroraDotNetEngine.Runtime;
  50. using Nini.Config;
  51. using OpenMetaverse;
  52. using OpenMetaverse.StructuredData;
  53. using GridRegion = Aurora.Framework.Services.GridRegion;
  54. using Group = System.Text.RegularExpressions.Group;
  55. using LSL_Float = Aurora.ScriptEngine.AuroraDotNetEngine.LSL_Types.LSLFloat;
  56. using LSL_Integer = Aurora.ScriptEngine.AuroraDotNetEngine.LSL_Types.LSLInteger;
  57. using LSL_Key = Aurora.ScriptEngine.AuroraDotNetEngine.LSL_Types.LSLString;
  58. using LSL_List = Aurora.ScriptEngine.AuroraDotNetEngine.LSL_Types.list;
  59. using LSL_Rotation = Aurora.ScriptEngine.AuroraDotNetEngine.LSL_Types.Quaternion;
  60. using LSL_String = Aurora.ScriptEngine.AuroraDotNetEngine.LSL_Types.LSLString;
  61. using LSL_Vector = Aurora.ScriptEngine.AuroraDotNetEngine.LSL_Types.Vector3;
  62. namespace Aurora.ScriptEngine.AuroraDotNetEngine.APIs
  63. {
  64. [Serializable]
  65. public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi
  66. {
  67. internal ScriptProtectionModule ScriptProtection;
  68. internal ILSL_Api m_LSL_Api; // get a reference to the LSL API so we can call methods housed there
  69. internal bool m_OSFunctionsEnabled;
  70. internal float m_ScriptDelayFactor = 1.0f;
  71. internal float m_ScriptDistanceFactor = 1.0f;
  72. internal IScriptModulePlugin m_ScriptEngine;
  73. internal ISceneChildEntity m_host;
  74. internal UUID m_itemID;
  75. internal uint m_localID;
  76. public IScene World
  77. {
  78. get { return m_host.ParentEntity.Scene; }
  79. }
  80. //
  81. // OpenSim functions
  82. //
  83. #region IOSSL_Api Members
  84. public LSL_Integer osSetTerrainHeight(int x, int y, double val)
  85. {
  86. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight", m_host, "OSSL", m_itemID))
  87. return new LSL_Integer();
  88. if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0)
  89. OSSLError("osTerrainSetHeight: Coordinate out of bounds");
  90. if (World.Permissions.CanTerraformLand(m_host.OwnerID, new Vector3(x, y, 0)))
  91. {
  92. ITerrainChannel heightmap = World.RequestModuleInterface<ITerrainChannel>();
  93. heightmap[x, y] = (float) val;
  94. ITerrainModule terrainModule = World.RequestModuleInterface<ITerrainModule>();
  95. if (terrainModule != null) terrainModule.TaintTerrain();
  96. return 1;
  97. }
  98. else
  99. {
  100. return 0;
  101. }
  102. }
  103. public LSL_Float osGetTerrainHeight(int x, int y)
  104. {
  105. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osTerrainGetHeight", m_host, "OSSL", m_itemID))
  106. return new LSL_Float();
  107. if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0)
  108. OSSLError("osTerrainGetHeight: Coordinate out of bounds");
  109. ITerrainChannel heightmap = World.RequestModuleInterface<ITerrainChannel>();
  110. return heightmap[x, y];
  111. }
  112. public void osTerrainFlush()
  113. {
  114. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.VeryLow, "osTerrainFlush", m_host, "OSSL", m_itemID))
  115. return;
  116. ITerrainModule terrainModule = World.RequestModuleInterface<ITerrainModule>();
  117. if (terrainModule != null) terrainModule.TaintTerrain();
  118. }
  119. public int osRegionRestart(double seconds)
  120. {
  121. // This is High here because region restart is not reliable
  122. // it may result in the region staying down or becoming
  123. // unstable. This should be changed to Low or VeryLow once
  124. // The underlying functionality is fixed, since the security
  125. // as such is sound
  126. //
  127. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osRegionRestart", m_host, "OSSL", m_itemID))
  128. return new int();
  129. IRestartModule restartModule = World.RequestModuleInterface<IRestartModule>();
  130. if (World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false) && (restartModule != null))
  131. {
  132. if (seconds < 15)
  133. {
  134. restartModule.AbortRestart("Restart aborted");
  135. return 1;
  136. }
  137. List<int> times = new List<int>();
  138. while (seconds > 0)
  139. {
  140. times.Add((int) seconds);
  141. if (seconds > 300)
  142. seconds -= 120;
  143. else if (seconds > 30)
  144. seconds -= 30;
  145. else
  146. seconds -= 15;
  147. }
  148. restartModule.ScheduleRestart(UUID.Zero, "Region will restart in {0}", times.ToArray(), true);
  149. return 1;
  150. }
  151. else
  152. {
  153. return 0;
  154. }
  155. }
  156. public void osShutDown()
  157. {
  158. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osShutDown", m_host, "OSSL", m_itemID)) return;
  159. if (World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false))
  160. {
  161. MainConsole.Instance.RunCommand("shutdown");
  162. }
  163. }
  164. public void osReturnObjects(LSL_Float Parameter)
  165. {
  166. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Low, "osReturnObjects", m_host, "OSSL", m_itemID))
  167. return;
  168. Dictionary<UUID, List<ISceneEntity>> returns =
  169. new Dictionary<UUID, List<ISceneEntity>>();
  170. IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
  171. if (parcelManagement != null)
  172. {
  173. ILandObject LO = parcelManagement.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  174. IPrimCountModule primCountModule = World.RequestModuleInterface<IPrimCountModule>();
  175. IPrimCounts primCounts = primCountModule.GetPrimCounts(LO.LandData.GlobalID);
  176. if (Parameter == 0) // Owner objects
  177. {
  178. foreach (ISceneEntity obj in primCounts.Objects.Where(obj => obj.OwnerID == LO.LandData.OwnerID))
  179. {
  180. if (!returns.ContainsKey(obj.OwnerID))
  181. returns[obj.OwnerID] =
  182. new List<ISceneEntity>();
  183. returns[obj.OwnerID].Add(obj);
  184. }
  185. }
  186. if (Parameter == 1) //Everyone elses
  187. {
  188. foreach (ISceneEntity obj in primCounts.Objects.Where(obj => obj.OwnerID != LO.LandData.OwnerID &&
  189. (obj.GroupID != LO.LandData.GroupID ||
  190. LO.LandData.GroupID == UUID.Zero)))
  191. {
  192. if (!returns.ContainsKey(obj.OwnerID))
  193. returns[obj.OwnerID] =
  194. new List<ISceneEntity>();
  195. returns[obj.OwnerID].Add(obj);
  196. }
  197. }
  198. if (Parameter == 2) // Group
  199. {
  200. foreach (ISceneEntity obj in primCounts.Objects.Where(obj => obj.GroupID == LO.LandData.GroupID))
  201. {
  202. if (!returns.ContainsKey(obj.OwnerID))
  203. returns[obj.OwnerID] =
  204. new List<ISceneEntity>();
  205. returns[obj.OwnerID].Add(obj);
  206. }
  207. }
  208. foreach (List<ISceneEntity> ol in returns.Values)
  209. {
  210. if (World.Permissions.CanReturnObjects(LO, m_host.OwnerID, ol))
  211. {
  212. ILLClientInventory inventoryModule = World.RequestModuleInterface<ILLClientInventory>();
  213. if (inventoryModule != null)
  214. inventoryModule.ReturnObjects(ol.ToArray(), m_host.OwnerID);
  215. }
  216. }
  217. }
  218. }
  219. public void osReturnObject(LSL_Key userID)
  220. {
  221. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Low, "osReturnObjects", m_host, "OSSL", m_itemID))
  222. return;
  223. Dictionary<UUID, List<ISceneEntity>> returns =
  224. new Dictionary<UUID, List<ISceneEntity>>();
  225. IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
  226. if (parcelManagement != null)
  227. {
  228. ILandObject LO = parcelManagement.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  229. IPrimCountModule primCountModule = World.RequestModuleInterface<IPrimCountModule>();
  230. IPrimCounts primCounts = primCountModule.GetPrimCounts(LO.LandData.GlobalID);
  231. foreach (ISceneEntity obj in primCounts.Objects.Where(obj => obj.OwnerID == new UUID(userID.m_string)))
  232. {
  233. if (!returns.ContainsKey(obj.OwnerID))
  234. returns[obj.OwnerID] =
  235. new List<ISceneEntity>();
  236. returns[obj.OwnerID].Add(obj);
  237. }
  238. foreach (List<ISceneEntity> ol in returns.Values)
  239. {
  240. if (World.Permissions.CanReturnObjects(LO, m_host.OwnerID, ol))
  241. {
  242. ILLClientInventory inventoryModule = World.RequestModuleInterface<ILLClientInventory>();
  243. if (inventoryModule != null)
  244. inventoryModule.ReturnObjects(ol.ToArray(), m_host.OwnerID);
  245. }
  246. }
  247. }
  248. }
  249. public void osRegionNotice(string msg)
  250. {
  251. // This implementation provides absolutely no security
  252. // It's high griefing potential makes this classification
  253. // necessary
  254. //
  255. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.VeryHigh, "osRegionNotice", m_host, "OSSL", m_itemID))
  256. return;
  257. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  258. if (dm != null)
  259. dm.SendGeneralAlert(msg);
  260. }
  261. public string osSetDynamicTextureURL(string dynamicID, string contentType, string url, string extraParams,
  262. int timer)
  263. {
  264. // This may be upgraded depending on the griefing or DOS
  265. // potential, or guarded with a delay
  266. //
  267. if (
  268. !ScriptProtection.CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURL", m_host, "OSSL",
  269. m_itemID)) return "";
  270. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  271. if (dynamicID == String.Empty)
  272. {
  273. UUID createdTexture =
  274. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, UUID.Zero, contentType,
  275. url,
  276. extraParams, timer);
  277. return createdTexture.ToString();
  278. }
  279. else
  280. {
  281. UUID oldAssetID = UUID.Parse(dynamicID);
  282. UUID createdTexture =
  283. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, oldAssetID, contentType,
  284. url,
  285. extraParams, timer);
  286. return createdTexture.ToString();
  287. }
  288. }
  289. public string osSetDynamicTextureURLBlend(string dynamicID, string contentType, string url, string extraParams,
  290. int timer, int alpha)
  291. {
  292. if (
  293. !ScriptProtection.CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURLBlend", m_host, "OSSL",
  294. m_itemID)) return "";
  295. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  296. if (dynamicID == String.Empty)
  297. {
  298. UUID createdTexture =
  299. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, UUID.Zero, contentType,
  300. url,
  301. extraParams, timer, true, (byte) alpha);
  302. return createdTexture.ToString();
  303. }
  304. else
  305. {
  306. UUID oldAssetID = UUID.Parse(dynamicID);
  307. UUID createdTexture =
  308. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, oldAssetID, contentType,
  309. url,
  310. extraParams, timer, true, (byte) alpha);
  311. return createdTexture.ToString();
  312. }
  313. }
  314. public string osSetDynamicTextureURLBlendFace(string dynamicID, string contentType, string url,
  315. string extraParams,
  316. bool blend, int disp, int timer, int alpha, int face)
  317. {
  318. if (
  319. !ScriptProtection.CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURLBlendFace", m_host,
  320. "OSSL", m_itemID)) return "";
  321. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  322. if (dynamicID == String.Empty)
  323. {
  324. UUID createdTexture =
  325. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, UUID.Zero, contentType,
  326. url,
  327. extraParams, timer, blend, disp, (byte) alpha, face);
  328. return createdTexture.ToString();
  329. }
  330. else
  331. {
  332. UUID oldAssetID = UUID.Parse(dynamicID);
  333. UUID createdTexture =
  334. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, oldAssetID, contentType,
  335. url,
  336. extraParams, timer, blend, disp, (byte) alpha, face);
  337. return createdTexture.ToString();
  338. }
  339. }
  340. public string osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams,
  341. int timer)
  342. {
  343. if (
  344. !ScriptProtection.CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureData", m_host, "OSSL",
  345. m_itemID)) return "";
  346. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  347. if (textureManager != null)
  348. {
  349. if (extraParams == String.Empty)
  350. {
  351. extraParams = "256";
  352. }
  353. if (dynamicID == String.Empty)
  354. {
  355. UUID createdTexture =
  356. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, UUID.Zero,
  357. contentType, data,
  358. extraParams, timer);
  359. return createdTexture.ToString();
  360. }
  361. else
  362. {
  363. UUID oldAssetID = UUID.Parse(dynamicID);
  364. UUID createdTexture =
  365. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, oldAssetID,
  366. contentType, data,
  367. extraParams, timer);
  368. return createdTexture.ToString();
  369. }
  370. }
  371. return UUID.Zero.ToString();
  372. }
  373. public string osSetDynamicTextureDataBlend(string dynamicID, string contentType, string data, string extraParams,
  374. int timer, int alpha)
  375. {
  376. if (
  377. !ScriptProtection.CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureDataBlend", m_host, "OSSL",
  378. m_itemID)) return "";
  379. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  380. if (textureManager != null)
  381. {
  382. if (extraParams == String.Empty)
  383. {
  384. extraParams = "256";
  385. }
  386. if (dynamicID == String.Empty)
  387. {
  388. UUID createdTexture =
  389. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, UUID.Zero,
  390. contentType, data,
  391. extraParams, timer, true, (byte) alpha);
  392. return createdTexture.ToString();
  393. }
  394. else
  395. {
  396. UUID oldAssetID = UUID.Parse(dynamicID);
  397. UUID createdTexture =
  398. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, oldAssetID,
  399. contentType, data,
  400. extraParams, timer, true, (byte) alpha);
  401. return createdTexture.ToString();
  402. }
  403. }
  404. return UUID.Zero.ToString();
  405. }
  406. private enum InfoType
  407. {
  408. Nick,
  409. Name,
  410. Login,
  411. Home,
  412. Custom
  413. };
  414. private string GridUserInfo(InfoType type)
  415. {
  416. return GridUserInfo(type, "");
  417. }
  418. private string GridUserInfo(InfoType type, string key)
  419. {
  420. string retval = String.Empty;
  421. IConfigSource config = m_ScriptEngine.ConfigSource;
  422. string url = config.Configs["GridInfo"].GetString("GridInfoURI", String.Empty);
  423. if (String.IsNullOrEmpty(url))
  424. return "Configuration Error!";
  425. string verb = "/json_grid_info";
  426. OSDMap json = new OSDMap();
  427. OSDMap info = (OSDMap) Util.CombineParams(new[] {String.Format("{0}{1}", url, verb)}, 3000);
  428. if (info["Success"] != true)
  429. return "Get GridInfo Failed!";
  430. json = (OSDMap) OSDParser.DeserializeJson(info["_RawResult"].AsString());
  431. switch (type)
  432. {
  433. case InfoType.Nick:
  434. retval = json["gridnick"];
  435. break;
  436. case InfoType.Name:
  437. retval = json["gridname"];
  438. break;
  439. case InfoType.Login:
  440. retval = json["login"];
  441. break;
  442. case InfoType.Home:
  443. retval = json["home"];
  444. break;
  445. case InfoType.Custom:
  446. retval = json[key];
  447. break;
  448. default:
  449. retval = "error";
  450. break;
  451. }
  452. return retval;
  453. }
  454. public string osGetGridHomeURI() //patched from OpenSim, you can remove this comment after pull
  455. {
  456. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osGetGridHomeURI", m_host, "OSSL",
  457. m_itemID)) return "";
  458. string HomeURI = String.Empty;
  459. if (m_ScriptEngine.Config.GetString("GridInfoService") != null)
  460. HomeURI = MainServer.Instance.ServerURI + "/";
  461. return HomeURI;
  462. }
  463. public string osGetGridCustom(string key) //patched from OpenSim, you can remove this comment after pull
  464. {
  465. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osGetGridCustom", m_host, "OSSL",
  466. m_itemID)) return "";
  467. string retval = String.Empty;
  468. if (m_ScriptEngine.Config.GetString("GridInfoService") != null)
  469. retval = m_ScriptEngine.Config.GetString("gridnick", retval);
  470. return retval;
  471. }
  472. public string osGetThreatLevel(string key)
  473. {
  474. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osGetThreatLevel", m_host, "OSSL",
  475. m_itemID)) return "";
  476. string retval = String.Empty;
  477. if (m_ScriptEngine.Config.GetString("AllowedAPIs").Contains("os"))
  478. retval = m_ScriptEngine.Config.GetString("FunctionThreatLevel", retval);
  479. return retval;
  480. }
  481. public string osGetGridGatekeeperURI() //patched from OpenSim, you can remove this comment after pull
  482. {
  483. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osGetGridGatekeeperURI", m_host, "OSSL", m_itemID))
  484. return "";
  485. string gatekeeperURI = String.Empty;
  486. IConfigSource config = m_ScriptEngine.ConfigSource;
  487. if (config.Configs["GridService"] != null)
  488. gatekeeperURI = MainServer.Instance.ServerURI + "/";
  489. return gatekeeperURI;
  490. }
  491. public void osForceAttachToAvatar(int attachmentPoint)
  492. {
  493. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar", m_host, "OSSL", m_itemID))
  494. return;
  495. InitLSL();
  496. ((LSL_Api) m_LSL_Api).AttachToAvatar(attachmentPoint, false);
  497. }
  498. public void osForceDetachFromAvatar()
  499. {
  500. if (
  501. !ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osForceDetachFromAvatar", m_host, "OSSL", m_itemID))
  502. return;
  503. InitLSL();
  504. ((LSL_Api) m_LSL_Api).DetachFromAvatar();
  505. }
  506. public string osSetDynamicTextureDataBlendFace(string dynamicID, string contentType, string data,
  507. string extraParams,
  508. bool blend, int disp, int timer, int alpha, int face)
  509. {
  510. if (
  511. !ScriptProtection.CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureDataBlendFace", m_host,
  512. "OSSL", m_itemID)) return "";
  513. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  514. if (textureManager != null)
  515. {
  516. if (extraParams == String.Empty)
  517. {
  518. extraParams = "256";
  519. }
  520. if (dynamicID == String.Empty)
  521. {
  522. UUID createdTexture =
  523. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, UUID.Zero,
  524. contentType, data,
  525. extraParams, timer, blend, disp, (byte) alpha, face);
  526. return createdTexture.ToString();
  527. }
  528. else
  529. {
  530. UUID oldAssetID = UUID.Parse(dynamicID);
  531. UUID createdTexture =
  532. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, oldAssetID,
  533. contentType, data,
  534. extraParams, timer, blend, disp, (byte) alpha, face);
  535. return createdTexture.ToString();
  536. }
  537. }
  538. return UUID.Zero.ToString();
  539. }
  540. public bool osConsoleCommand(string command)
  541. {
  542. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Severe, "osConsoleCommand", m_host, "OSSL", m_itemID))
  543. return false;
  544. if (m_ScriptEngine.Config.GetBoolean("AllowosConsoleCommand", false))
  545. {
  546. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  547. {
  548. MainConsole.Instance.RunCommand(command);
  549. return true;
  550. }
  551. }
  552. return false;
  553. }
  554. public void osSetPrimFloatOnWater(int floatYN)
  555. {
  556. if (
  557. !ScriptProtection.CheckThreatLevel(ThreatLevel.VeryLow, "osSetPrimFloatOnWater", m_host, "OSSL",
  558. m_itemID)) return;
  559. if (m_host.ParentEntity != null)
  560. {
  561. if (m_host.ParentEntity.RootChild != null)
  562. {
  563. m_host.ParentEntity.RootChild.SetFloatOnWater(floatYN);
  564. }
  565. }
  566. }
  567. public DateTime osTeleportOwner(string regionName, LSL_Vector position, LSL_Vector lookat)
  568. {
  569. // Threat level None because this is what can already be done with the World Map in the viewer
  570. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osTeleportOwner", m_host, "OSSL", m_itemID))
  571. return DateTime.Now;
  572. List<GridRegion> regions = World.GridService.GetRegionsByName(World.RegionInfo.AllScopeIDs, regionName, 0, 1);
  573. // Try to link the region
  574. if (regions != null && regions.Count > 0)
  575. {
  576. GridRegion regInfo = regions[0];
  577. ulong regionHandle = regInfo.RegionHandle;
  578. return TeleportAgent(m_host.OwnerID, regionHandle,
  579. new Vector3((float) position.x, (float) position.y, (float) position.z),
  580. new Vector3((float) lookat.x, (float) lookat.y, (float) lookat.z));
  581. }
  582. return DateTime.Now;
  583. }
  584. public DateTime osTeleportOwner(LSL_Vector position, LSL_Vector lookat)
  585. {
  586. return osTeleportOwner(World.RegionInfo.RegionName, position, lookat);
  587. }
  588. public DateTime osTeleportOwner(int regionX, int regionY, LSL_Vector position, LSL_Vector lookat)
  589. {
  590. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osTeleportOwner", m_host, "OSSL", m_itemID))
  591. return DateTime.Now;
  592. GridRegion regInfo = World.GridService.GetRegionByPosition(World.RegionInfo.AllScopeIDs,
  593. (regionX*Constants.RegionSize),
  594. (regionY*Constants.RegionSize));
  595. // Try to link the region
  596. if (regInfo != null)
  597. {
  598. ulong regionHandle = regInfo.RegionHandle;
  599. return TeleportAgent(m_host.OwnerID, regionHandle,
  600. new Vector3((float) position.x, (float) position.y, (float) position.z),
  601. new Vector3((float) lookat.x, (float) lookat.y, (float) lookat.z));
  602. }
  603. return DateTime.Now;
  604. }
  605. // Teleport functions
  606. public DateTime osTeleportAgent(string agent, string regionName, LSL_Vector position, LSL_Vector lookat)
  607. {
  608. // High because there is no security check. High griefer potential
  609. //
  610. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osTeleportAgent", m_host, "OSSL", m_itemID))
  611. return DateTime.Now;
  612. UUID AgentID;
  613. if (UUID.TryParse(agent, out AgentID))
  614. {
  615. List<GridRegion> regions = World.GridService.GetRegionsByName(World.RegionInfo.AllScopeIDs, regionName,
  616. 0, 1);
  617. // Try to link the region
  618. if (regions != null && regions.Count > 0)
  619. {
  620. GridRegion regInfo = regions[0];
  621. ulong regionHandle = regInfo.RegionHandle;
  622. return TeleportAgent(AgentID, regionHandle,
  623. position.ToVector3(),
  624. lookat.ToVector3());
  625. }
  626. }
  627. return DateTime.Now;
  628. }
  629. // Teleport functions
  630. public DateTime osTeleportAgent(string agent, int regionX, int regionY, LSL_Vector position, LSL_Vector lookat)
  631. {
  632. // High because there is no security check. High griefer potential
  633. //
  634. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osTeleportAgent", m_host, "OSSL", m_itemID))
  635. return DateTime.Now;
  636. ulong regionHandle = Utils.UIntsToLong(((uint) regionX*Constants.RegionSize),
  637. ((uint) regionY*Constants.RegionSize));
  638. UUID agentId = new UUID();
  639. if (UUID.TryParse(agent, out agentId))
  640. {
  641. return TeleportAgent(agentId, regionHandle,
  642. position.ToVector3(),
  643. lookat.ToVector3());
  644. }
  645. return DateTime.Now;
  646. }
  647. public DateTime osTeleportAgent(string agent, LSL_Vector position, LSL_Vector lookat)
  648. {
  649. return osTeleportAgent(agent, World.RegionInfo.RegionName, position, lookat);
  650. }
  651. // Functions that get information from the agent itself.
  652. //
  653. // osGetAgentIP - this is used to determine the IP address of
  654. //the client. This is needed to help configure other in world
  655. //resources based on the IP address of the clients connected.
  656. //I think High is a good risk level for this, as it is an
  657. //information leak.
  658. public LSL_String osGetAgentIP(string agent)
  659. {
  660. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osGetAgentIP", m_host, "OSSL", m_itemID))
  661. return new LSL_String();
  662. UUID avatarID = (UUID) agent;
  663. IScenePresence target;
  664. if (World.TryGetScenePresence(avatarID, out target))
  665. {
  666. EndPoint ep = target.ControllingClient.GetClientEP();
  667. if (ep is IPEndPoint)
  668. {
  669. IPEndPoint ip = (IPEndPoint) ep;
  670. return new LSL_String(ip.Address.ToString());
  671. }
  672. }
  673. // fall through case, just return nothing
  674. return new LSL_String("");
  675. }
  676. // Get a list of all the avatars/agents in the region
  677. public LSL_List osGetAgents()
  678. {
  679. // threat level is None as we could get this information with an
  680. // in-world script as well, just not as efficient
  681. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osGetAgents", m_host, "OSSL", m_itemID))
  682. return new LSL_List();
  683. LSL_List result = new LSL_List();
  684. World.ForEachScenePresence(delegate(IScenePresence sp)
  685. {
  686. if (!sp.IsChildAgent)
  687. result.Add(new LSL_String(sp.Name));
  688. });
  689. return result;
  690. }
  691. // Adam's super super custom animation functions
  692. public void osAvatarPlayAnimation(string avatar, string animation)
  693. {
  694. if (
  695. !ScriptProtection.CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarPlayAnimation", m_host, "OSSL",
  696. m_itemID)) return;
  697. UUID avatarID = (UUID) avatar;
  698. IScenePresence target;
  699. if (World.TryGetScenePresence(avatarID, out target))
  700. {
  701. if (target != null)
  702. {
  703. UUID animID = new UUID();
  704. if (!UUID.TryParse(animation, out animID))
  705. {
  706. animID = UUID.Zero;
  707. lock (m_host.TaskInventory)
  708. {
  709. foreach (
  710. KeyValuePair<UUID, TaskInventoryItem> inv in
  711. m_host.TaskInventory.Where(inv => inv.Value.Name == animation))
  712. {
  713. if (inv.Value.Type == (int) AssetType.Animation)
  714. animID = inv.Value.AssetID;
  715. continue;
  716. }
  717. }
  718. }
  719. if (animID == UUID.Zero)
  720. target.Animator.AddAnimation(animation, m_host.UUID);
  721. else
  722. target.Animator.AddAnimation(animID, m_host.UUID);
  723. }
  724. }
  725. }
  726. public void osAvatarStopAnimation(string avatar, string animation)
  727. {
  728. if (
  729. !ScriptProtection.CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarStopAnimation", m_host, "OSSL",
  730. m_itemID)) return;
  731. UUID avatarID = (UUID) avatar;
  732. IScenePresence target;
  733. if (World.TryGetScenePresence(avatarID, out target))
  734. {
  735. if (target != null)
  736. {
  737. UUID animID = UUID.Zero;
  738. lock (m_host.TaskInventory)
  739. {
  740. foreach (
  741. KeyValuePair<UUID, TaskInventoryItem> inv in
  742. m_host.TaskInventory.Where(inv => inv.Value.Name == animation))
  743. {
  744. if (inv.Value.Type == (int) AssetType.Animation)
  745. animID = inv.Value.AssetID;
  746. continue;
  747. }
  748. }
  749. if (animID == UUID.Zero)
  750. target.Animator.RemoveAnimation(animation);
  751. else
  752. target.Animator.RemoveAnimation(animID);
  753. }
  754. }
  755. }
  756. //Texture draw functions
  757. public string osMovePen(string drawList, int x, int y)
  758. {
  759. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osMovePen", m_host, "OSSL", m_itemID)) return "";
  760. drawList += "MoveTo " + x + "," + y + ";";
  761. return new LSL_String(drawList);
  762. }
  763. public string osDrawLine(string drawList, int startX, int startY, int endX, int endY)
  764. {
  765. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osDrawLine", m_host, "OSSL", m_itemID)) return "";
  766. drawList += "MoveTo " + startX + "," + startY + "; LineTo " + endX + "," + endY + "; ";
  767. return new LSL_String(drawList);
  768. }
  769. public string osDrawLine(string drawList, int endX, int endY)
  770. {
  771. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osDrawLine", m_host, "OSSL", m_itemID)) return "";
  772. drawList += "LineTo " + endX + "," + endY + "; ";
  773. return new LSL_String(drawList);
  774. }
  775. public string osDrawText(string drawList, string text)
  776. {
  777. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osDrawText", m_host, "OSSL", m_itemID)) return "";
  778. drawList += "Text " + text + "; ";
  779. return new LSL_String(drawList);
  780. }
  781. public string osDrawEllipse(string drawList, int width, int height)
  782. {
  783. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osDrawEllipse", m_host, "OSSL", m_itemID))
  784. return "";
  785. drawList += "Ellipse " + width + "," + height + "; ";
  786. return new LSL_String(drawList);
  787. }
  788. public string osDrawRectangle(string drawList, int width, int height)
  789. {
  790. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osDrawRectangle", m_host, "OSSL", m_itemID))
  791. return "";
  792. drawList += "Rectangle " + width + "," + height + "; ";
  793. return new LSL_String(drawList);
  794. }
  795. public string osDrawFilledRectangle(string drawList, int width, int height)
  796. {
  797. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osDrawFilledRectangle", m_host, "OSSL", m_itemID))
  798. return "";
  799. drawList += "FillRectangle " + width + "," + height + "; ";
  800. return new LSL_String(drawList);
  801. }
  802. public string osDrawFilledPolygon(string drawList, LSL_List x, LSL_List y)
  803. {
  804. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osDrawFilledPolygon", m_host, "OSSL", m_itemID))
  805. return "";
  806. if (x.Length != y.Length || x.Length < 3)
  807. {
  808. return new LSL_String("");
  809. }
  810. drawList += "FillPolygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
  811. for (int i = 1; i < x.Length; i++)
  812. {
  813. drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
  814. }
  815. drawList += "; ";
  816. return new LSL_String(drawList);
  817. }
  818. public string osDrawPolygon(string drawList, LSL_List x, LSL_List y)
  819. {
  820. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osDrawFilledPolygon", m_host, "OSSL", m_itemID))
  821. return "";
  822. if (x.Length != y.Length || x.Length < 3)
  823. {
  824. return new LSL_String("");
  825. }
  826. drawList += "Polygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
  827. for (int i = 1; i < x.Length; i++)
  828. {
  829. drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
  830. }
  831. drawList += "; ";
  832. return new LSL_String(drawList);
  833. }
  834. public string osSetFontSize(string drawList, int fontSize)
  835. {
  836. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osSetFontSize", m_host, "OSSL", m_itemID))
  837. return "";
  838. drawList += "FontSize " + fontSize + "; ";
  839. return drawList;
  840. }
  841. public string osSetFontName(string drawList, string fontName)
  842. {
  843. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osSetFontName", m_host, "OSSL", m_itemID))
  844. return "";
  845. drawList += "FontName " + fontName + "; ";
  846. return new LSL_String(drawList);
  847. }
  848. public string osSetPenSize(string drawList, int penSize)
  849. {
  850. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osSetPenSize", m_host, "OSSL", m_itemID))
  851. return "";
  852. drawList += "PenSize " + penSize + "; ";
  853. return new LSL_String(drawList);
  854. }
  855. public string osSetPenColor(string drawList, string colour)
  856. {
  857. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osSetPenColor", m_host, "OSSL", m_itemID))
  858. return "";
  859. drawList += "PenColour " + colour + "; ";
  860. return new LSL_String(drawList);
  861. }
  862. public string osSetPenCap(string drawList, string direction, string type)
  863. {
  864. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osSetPenColor", m_host, "OSSL", m_itemID))
  865. return "";
  866. drawList += "PenCap " + direction + "," + type + "; ";
  867. return new LSL_String(drawList);
  868. }
  869. public string osDrawImage(string drawList, int width, int height, string imageUrl)
  870. {
  871. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osDrawImage", m_host, "OSSL", m_itemID))
  872. return "";
  873. drawList += "Image " + width + "," + height + "," + imageUrl + "; ";
  874. return new LSL_String(drawList);
  875. }
  876. public LSL_Vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize)
  877. {
  878. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.VeryLow, "osGetDrawStringSize", m_host, "OSSL", m_itemID))
  879. return new LSL_Vector();
  880. LSL_Vector vec = new LSL_Vector(0, 0, 0);
  881. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  882. if (textureManager != null)
  883. {
  884. double xSize, ySize;
  885. textureManager.GetDrawStringSize(contentType, text, fontName, fontSize,
  886. out xSize, out ySize);
  887. vec.x = xSize;
  888. vec.y = ySize;
  889. }
  890. return vec;
  891. }
  892. public void osSetRegionWaterHeight(double height)
  893. {
  894. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osSetRegionWaterHeight", m_host, "OSSL", m_itemID))
  895. return;
  896. //Check to make sure that the script's owner is the estate manager/master
  897. //World.Permissions.GenericEstatePermission(
  898. if (World.Permissions.IsGod(m_host.OwnerID))
  899. {
  900. World.EventManager.TriggerRequestChangeWaterHeight((float) height);
  901. }
  902. }
  903. /// <summary>
  904. /// Changes the Region Sun Settings, then Triggers a Sun Update
  905. /// </summary>
  906. /// <param name="useEstateSun">True to use Estate Sun instead of Region Sun</param>
  907. /// <param name="sunFixed">True to keep the sun stationary</param>
  908. /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
  909. public void osSetRegionSunSettings(bool useEstateSun, bool sunFixed, double sunHour)
  910. {
  911. if (
  912. !ScriptProtection.CheckThreatLevel(ThreatLevel.Nuisance, "osSetRegionSunSettings", m_host, "OSSL",
  913. m_itemID)) return;
  914. //Check to make sure that the script's owner is the estate manager/master
  915. //World.Permissions.GenericEstatePermission(
  916. if (World.Permissions.IsGod(m_host.OwnerID))
  917. {
  918. while (sunHour > 24.0)
  919. sunHour -= 24.0;
  920. while (sunHour < 0)
  921. sunHour += 24.0;
  922. World.RegionInfo.RegionSettings.UseEstateSun = useEstateSun;
  923. World.RegionInfo.RegionSettings.SunPosition = sunHour + 6; // LL Region Sun Hour is 6 to 30
  924. World.RegionInfo.RegionSettings.FixedSun = sunFixed;
  925. World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle, sunFixed, useEstateSun,
  926. (float) sunHour);
  927. }
  928. }
  929. /// <summary>
  930. /// Changes the Estate Sun Settings, then Triggers a Sun Update
  931. /// </summary>
  932. /// <param name="sunFixed">True to keep the sun stationary, false to use global time</param>
  933. /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
  934. public void osSetEstateSunSettings(bool sunFixed, double sunHour)
  935. {
  936. if (
  937. !ScriptProtection.CheckThreatLevel(ThreatLevel.Nuisance, "osSetEstateSunSettings", m_host, "OSSL",
  938. m_itemID)) return;
  939. //Check to make sure that the script's owner is the estate manager/master
  940. //World.Permissions.GenericEstatePermission(
  941. if (World.Permissions.IsGod(m_host.OwnerID))
  942. {
  943. while (sunHour > 24.0)
  944. sunHour -= 24.0;
  945. while (sunHour < 0)
  946. sunHour += 24.0;
  947. World.RegionInfo.EstateSettings.UseGlobalTime = !sunFixed;
  948. World.RegionInfo.EstateSettings.SunPosition = sunHour;
  949. World.RegionInfo.EstateSettings.FixedSun = sunFixed;
  950. World.RegionInfo.EstateSettings.Save();
  951. World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle, sunFixed,
  952. World.RegionInfo.RegionSettings.UseEstateSun,
  953. (float) sunHour);
  954. }
  955. }
  956. /// <summary>
  957. /// Return the current Sun Hour 0...24, with 0 being roughly sun-rise
  958. /// </summary>
  959. /// <returns></returns>
  960. public double osGetCurrentSunHour()
  961. {
  962. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osGetCurrentSunHour", m_host, "OSSL", m_itemID))
  963. return 0;
  964. // Must adjust for the fact that Region Sun Settings are still LL offset
  965. double sunHour = World.RegionInfo.RegionSettings.SunPosition - 6;
  966. // See if the sun module has registered itself, if so it's authoritative
  967. ISunModule module = World.RequestModuleInterface<ISunModule>();
  968. if (module != null)
  969. {
  970. sunHour = module.GetCurrentSunHour();
  971. }
  972. return sunHour;
  973. }
  974. public double osGetSunParam(string param)
  975. {
  976. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osGetSunParam", m_host, "OSSL", m_itemID))
  977. return 0;
  978. return GetSunParam(param);
  979. }
  980. private double GetSunParam(string param)
  981. {
  982. double value = 0.0;
  983. ISunModule module = World.RequestModuleInterface<ISunModule>();
  984. if (module != null)
  985. {
  986. value = module.GetSunParameter(param);
  987. }
  988. return value;
  989. }
  990. public double osSunGetParam(string param) //patched from OpenSim, you can remove this comment after pull
  991. {
  992. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osSunGetParam", m_host, "OSSL", m_itemID))
  993. return 0;
  994. double value = 0.0;
  995. ISunModule module = World.RequestModuleInterface<ISunModule>();
  996. if (module != null)
  997. {
  998. value = module.GetSunParameter(param);
  999. }
  1000. return value;
  1001. }
  1002. public void osSunSetParam(string param, double value)
  1003. //patched from OpenSim, you can remove this comment after pull
  1004. {
  1005. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osSunSetParam", m_host, "OSSL", m_itemID)) return;
  1006. ISunModule module = World.RequestModuleInterface<ISunModule>();
  1007. if (module != null)
  1008. {
  1009. module.SetSunParameter(param, value);
  1010. }
  1011. }
  1012. public void osSetSunParam(string param, double value)
  1013. {
  1014. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osSetSunParam", m_host, "OSSL", m_itemID)) return;
  1015. SetSunParam(param, value);
  1016. }
  1017. private void SetSunParam(string param, double value)
  1018. {
  1019. ISunModule module = World.RequestModuleInterface<ISunModule>();
  1020. if (module != null)
  1021. {
  1022. module.SetSunParameter(param, value);
  1023. }
  1024. }
  1025. public string osWindActiveModelPluginName()
  1026. {
  1027. if (
  1028. !ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osWindActiveModelPluginName", m_host, "OSSL",
  1029. m_itemID)) return "";
  1030. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1031. if (module != null)
  1032. {
  1033. return new LSL_String(module.WindActiveModelPluginName);
  1034. }
  1035. return new LSL_String("");
  1036. }
  1037. public void osSetWindParam(string plugin, string param, LSL_Float value)
  1038. {
  1039. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.VeryLow, "osSetWindParam", m_host, "OSSL", m_itemID))
  1040. return;
  1041. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1042. if (module != null)
  1043. {
  1044. try
  1045. {
  1046. module.WindParamSet(plugin, param, (float) value.value);
  1047. }
  1048. catch (Exception)
  1049. {
  1050. }
  1051. }
  1052. }
  1053. public LSL_Float osGetWindParam(string plugin, string param)
  1054. {
  1055. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.VeryLow, "osWindParamGet", m_host, "OSSL", m_itemID))
  1056. return new LSL_Float();
  1057. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1058. if (module != null)
  1059. {
  1060. return module.WindParamGet(plugin, param);
  1061. }
  1062. return 0.0f;
  1063. }
  1064. // Routines for creating and managing parcels programmatically
  1065. public void osParcelJoin(LSL_Vector pos1, LSL_Vector pos2)
  1066. {
  1067. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osParcelJoin", m_host, "OSSL", m_itemID)) return;
  1068. int startx = (int) (pos1.x < pos2.x ? pos1.x : pos2.x);
  1069. int starty = (int) (pos1.y < pos2.y ? pos1.y : pos2.y);
  1070. int endx = (int) (pos1.x > pos2.x ? pos1.x : pos2.x);
  1071. int endy = (int) (pos1.y > pos2.y ? pos1.y : pos2.y);
  1072. IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
  1073. if (parcelManagement != null)
  1074. {
  1075. parcelManagement.Join(startx, starty, endx, endy, m_host.OwnerID);
  1076. }
  1077. }
  1078. public void osParcelSubdivide(LSL_Vector pos1, LSL_Vector pos2)
  1079. {
  1080. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osParcelSubdivide", m_host, "OSSL", m_itemID))
  1081. return;
  1082. int startx = (int) (pos1.x < pos2.x ? pos1.x : pos2.x);
  1083. int starty = (int) (pos1.y < pos2.y ? pos1.y : pos2.y);
  1084. int endx = (int) (pos1.x > pos2.x ? pos1.x : pos2.x);
  1085. int endy = (int) (pos1.y > pos2.y ? pos1.y : pos2.y);
  1086. IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
  1087. if (parcelManagement != null)
  1088. {
  1089. parcelManagement.Subdivide(startx, starty, endx, endy, m_host.OwnerID);
  1090. }
  1091. }
  1092. public void osSetParcelDetails(LSL_Vector pos, LSL_List rules)
  1093. {
  1094. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osSetParcelDetails", m_host, "OSSL", m_itemID))
  1095. return;
  1096. // Get a reference to the land data and make sure the owner of the script
  1097. // can modify it
  1098. IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
  1099. if (parcelManagement != null)
  1100. {
  1101. ILandObject startLandObject = parcelManagement.GetLandObject((int) pos.x, (int) pos.y);
  1102. if (startLandObject == null)
  1103. {
  1104. OSSLShoutError("There is no land at that location");
  1105. return;
  1106. }
  1107. if (!World.Permissions.CanEditParcel(m_host.OwnerID, startLandObject))
  1108. {
  1109. OSSLShoutError("You do not have permission to modify the parcel");
  1110. return;
  1111. }
  1112. // Create a new land data object we can modify
  1113. // Process the rules, not sure what the impact would be of changing owner or group
  1114. for (int idx = 0; idx < rules.Length;)
  1115. {
  1116. int code = rules.GetLSLIntegerItem(idx++);
  1117. string arg = rules.GetLSLStringItem(idx++);
  1118. UUID uuid;
  1119. switch (code)
  1120. {
  1121. case 0:
  1122. startLandObject.LandData.Name = arg;
  1123. break;
  1124. case 1:
  1125. startLandObject.LandData.Description = arg;
  1126. break;
  1127. case 2:
  1128. if (
  1129. !ScriptProtection.CheckThreatLevel(ThreatLevel.VeryHigh, "osSetParcelDetails", m_host,
  1130. "OSSL", m_itemID)) return;
  1131. if (UUID.TryParse(arg, out uuid))
  1132. startLandObject.LandData.OwnerID = uuid;
  1133. break;
  1134. case 3:
  1135. if (
  1136. !ScriptProtection.CheckThreatLevel(ThreatLevel.VeryHigh, "osSetParcelDetails", m_host,
  1137. "OSSL", m_itemID)) return;
  1138. if (UUID.TryParse(arg, out uuid))
  1139. startLandObject.LandData.GroupID = uuid;
  1140. break;
  1141. }
  1142. }
  1143. parcelManagement.UpdateLandObject(startLandObject);
  1144. }
  1145. }
  1146. /// <summary>
  1147. /// Sets terrain estate texture
  1148. /// </summary>
  1149. /// <param name="level"></param>
  1150. /// <param name="texture"></param>
  1151. /// <returns></returns>
  1152. public void osSetTerrainTexture(int level, LSL_Key texture)
  1153. {
  1154. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osSetParcelDetails", m_host, "OSSL", m_itemID))
  1155. return;
  1156. //Check to make sure that the script's owner is the estate manager/master
  1157. //World.Permissions.GenericEstatePermission(
  1158. if (World.Permissions.IsGod(m_host.OwnerID))
  1159. {
  1160. if (level < 0 || level > 3)
  1161. return;
  1162. UUID textureID = new UUID();
  1163. if (!UUID.TryParse(texture, out textureID))
  1164. return;
  1165. // estate module is required
  1166. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  1167. if (estate != null)
  1168. estate.setEstateTerrainBaseTexture(level, textureID);
  1169. }
  1170. }
  1171. /// <summary>
  1172. /// Sets terrain heights of estate
  1173. /// </summary>
  1174. /// <param name="corner"></param>
  1175. /// <param name="low"></param>
  1176. /// <param name="high"></param>
  1177. /// <returns></returns>
  1178. public void osSetTerrainTextureHeight(int corner, double low, double high)
  1179. {
  1180. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osSetParcelDetails", m_host, "OSSL", m_itemID))
  1181. return;
  1182. //Check to make sure that the script's owner is the estate manager/master
  1183. //World.Permissions.GenericEstatePermission(
  1184. if (World.Permissions.IsGod(m_host.OwnerID))
  1185. {
  1186. if (corner < 0 || corner > 3)
  1187. return;
  1188. // estate module is required
  1189. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  1190. if (estate != null)
  1191. estate.setEstateTerrainTextureHeights(corner, (float) low, (float) high);
  1192. }
  1193. }
  1194. public double osList2Double(LSL_List src, int index)
  1195. {
  1196. // There is really no double type in OSSL. C# and other
  1197. // have one, but the current implementation of LSL_Types.list
  1198. // is not allowed to contain any.
  1199. // This really should be removed.
  1200. //
  1201. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osList2Double", m_host, "OSSL", m_itemID))
  1202. return 0;
  1203. if (index < 0)
  1204. {
  1205. index = src.Length + index;
  1206. }
  1207. if (index >= src.Length)
  1208. {
  1209. return 0.0;
  1210. }
  1211. return Convert.ToDouble(src.Data[index]);
  1212. }
  1213. public void osSetParcelMediaURL(string url)
  1214. {
  1215. // What actually is the difference to the LL function?
  1216. //
  1217. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL", m_host, "OSSL", m_itemID))
  1218. return;
  1219. IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
  1220. if (parcelManagement != null)
  1221. {
  1222. ILandObject land
  1223. = parcelManagement.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  1224. if (land == null || land.LandData.OwnerID != m_host.OwnerID)
  1225. return;
  1226. land.SetMediaUrl(url);
  1227. }
  1228. }
  1229. public void osSetParcelSIPAddress(string SIPAddress)
  1230. {
  1231. // What actually is the difference to the LL function?
  1232. //
  1233. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL", m_host, "OSSL", m_itemID))
  1234. return;
  1235. IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
  1236. if (parcelManagement != null)
  1237. {
  1238. ILandObject land
  1239. = parcelManagement.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  1240. if (land == null || land.LandData.OwnerID != m_host.OwnerID)
  1241. {
  1242. OSSLError("osSetParcelSIPAddress: Sorry, you need to own the land to use this function");
  1243. return;
  1244. }
  1245. // get the voice module
  1246. IVoiceModule voiceModule = World.RequestModuleInterface<IVoiceModule>();
  1247. if (voiceModule != null)
  1248. voiceModule.setLandSIPAddress(SIPAddress, land.LandData.GlobalID);
  1249. else
  1250. OSSLError("osSetParcelSIPAddress: No voice module enabled for this land");
  1251. }
  1252. }
  1253. public string osGetScriptEngineName()
  1254. {
  1255. // This gets a "high" because knowing the engine may be used
  1256. // to exploit engine-specific bugs or induce usage patterns
  1257. // that trigger engine-specific failures.
  1258. // Besides, public grid users aren't supposed to know.
  1259. //
  1260. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osGetScriptEngineName", m_host, "OSSL", m_itemID))
  1261. return "";
  1262. int scriptEngineNameIndex = 0;
  1263. if (!String.IsNullOrEmpty(m_ScriptEngine.ScriptEngineName))
  1264. {
  1265. // parse off the "ScriptEngine."
  1266. scriptEngineNameIndex = m_ScriptEngine.ScriptEngineName.IndexOf(".", scriptEngineNameIndex,
  1267. System.StringComparison.Ordinal);
  1268. scriptEngineNameIndex++; // get past delimiter
  1269. int scriptEngineNameLength = m_ScriptEngine.ScriptEngineName.Length - scriptEngineNameIndex;
  1270. // create char array then a string that is only the script engine name
  1271. Char[] scriptEngineNameCharArray = m_ScriptEngine.ScriptEngineName.ToCharArray(scriptEngineNameIndex,
  1272. scriptEngineNameLength);
  1273. String scriptEngineName = new String(scriptEngineNameCharArray);
  1274. return scriptEngineName;
  1275. }
  1276. else
  1277. {
  1278. return String.Empty;
  1279. }
  1280. }
  1281. public string osGetSimulatorVersion()
  1282. {
  1283. // High because it can be used to target attacks to known weaknesses
  1284. // This would allow a new class of griefer scripts that don't even
  1285. // require their user to know what they are doing (see script
  1286. // kiddie)
  1287. //
  1288. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osGetSimulatorVersion", m_host, "OSSL", m_itemID))
  1289. return "";
  1290. ISimulationBase simulationBase = World.RequestModuleInterface<ISimulationBase>();
  1291. if (simulationBase != null)
  1292. return simulationBase.Version;
  1293. return "";
  1294. }
  1295. private Hashtable osdToHashtable(OSDMap map)
  1296. {
  1297. Hashtable result = new Hashtable();
  1298. foreach (KeyValuePair<string, OSD> item in map)
  1299. {
  1300. result.Add(item.Key, osdToObject(item.Value));
  1301. }
  1302. return result;
  1303. }
  1304. private ArrayList osdToArray(OSDArray list)
  1305. {
  1306. ArrayList result = new ArrayList();
  1307. foreach (OSD item in list)
  1308. {
  1309. result.Add(osdToObject(item));
  1310. }
  1311. return result;
  1312. }
  1313. private Object osdToObject(OSD decoded)
  1314. {
  1315. if (decoded is OSDString)
  1316. {
  1317. return (string) decoded.AsString();
  1318. }
  1319. else if (decoded is OSDInteger)
  1320. {
  1321. return (int) decoded.AsInteger();
  1322. }
  1323. else if (decoded is OSDReal)
  1324. {
  1325. return (float) decoded.AsReal();
  1326. }
  1327. else if (decoded is OSDBoolean)
  1328. {
  1329. return (bool) decoded.AsBoolean();
  1330. }
  1331. else if (decoded is OSDMap)
  1332. {
  1333. return osdToHashtable((OSDMap) decoded);
  1334. }
  1335. else if (decoded is OSDArray)
  1336. {
  1337. return osdToArray((OSDArray) decoded);
  1338. }
  1339. else
  1340. {
  1341. return null;
  1342. }
  1343. }
  1344. public Object osParseJSONNew(string JSON) //patched from OpenSim, you can remove this comment after pull
  1345. {
  1346. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osParseJSONNew", m_host, "OSSL", m_itemID))
  1347. return new object();
  1348. try
  1349. {
  1350. OSD decoded = OSDParser.DeserializeJson(JSON);
  1351. return osdToObject(decoded);
  1352. }
  1353. catch (Exception e)
  1354. {
  1355. OSSLError("osParseJSONNew: Problems decoding JSON string " + JSON + " : " + e.Message);
  1356. return null;
  1357. }
  1358. }
  1359. public Hashtable osParseJSON(string JSON)
  1360. {
  1361. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osParseJSON", m_host, "OSSL", m_itemID))
  1362. return new Hashtable();
  1363. // see http://www.json.org/ for more details on JSON
  1364. string currentKey = null;
  1365. Stack objectStack = new Stack(); // objects in JSON can be nested so we need to keep a track of this
  1366. Hashtable jsondata = new Hashtable(); // the hashtable to be returned
  1367. try
  1368. {
  1369. // iterate through the serialised stream of tokens and store at the right depth in the hashtable
  1370. // the top level hashtable may contain more nested hashtables within it each containing an objects representation
  1371. int i = 0;
  1372. for (i = 0; i < JSON.Length; i++)
  1373. {
  1374. // MainConsole.Instance.Debug(""+JSON[i]);
  1375. switch (JSON[i])
  1376. {
  1377. case '{':
  1378. // create hashtable and add it to the stack or array if we are populating one, we can have a lot of nested objects in JSON
  1379. Hashtable currentObject = new Hashtable();
  1380. if (objectStack.Count == 0) // the stack should only be empty for the first outer object
  1381. {
  1382. objectStack.Push(jsondata);
  1383. }
  1384. else if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1385. {
  1386. // add it to the parent array
  1387. ((ArrayList) objectStack.Peek()).Add(currentObject);
  1388. objectStack.Push(currentObject);
  1389. }
  1390. else
  1391. {
  1392. // add it to the parent hashtable
  1393. if (currentKey != null) ((Hashtable) objectStack.Peek()).Add(currentKey, currentObject);
  1394. objectStack.Push(currentObject);
  1395. }
  1396. // clear the key
  1397. currentKey = null;
  1398. break;
  1399. case '}':
  1400. // pop the hashtable off the stack
  1401. objectStack.Pop();
  1402. break;
  1403. case '"': // string boundary
  1404. string tokenValue = "";
  1405. i++; // move to next char
  1406. // just loop through until the next quote mark storing the string, ignore quotes with pre-ceding \
  1407. while (JSON[i] != '"')
  1408. {
  1409. tokenValue += JSON[i];
  1410. // handle escaped double quotes \"
  1411. if (JSON[i] == '\\' && JSON[i + 1] == '"')
  1412. {
  1413. tokenValue += JSON[i + 1];
  1414. i++;
  1415. }
  1416. i++;
  1417. }
  1418. // ok we've got a string, if we've got an array on the top of the stack then we store it
  1419. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1420. {
  1421. ((ArrayList) objectStack.Peek()).Add(tokenValue);
  1422. }
  1423. else if (currentKey == null)
  1424. // no key stored and its not an array this must be a key so store it
  1425. {
  1426. currentKey = tokenValue;
  1427. }
  1428. else
  1429. {
  1430. // we have a key so lets store this value
  1431. ((Hashtable) objectStack.Peek()).Add(currentKey, tokenValue);
  1432. // now lets clear the key, we're done with it and moving on
  1433. currentKey = null;
  1434. }
  1435. break;
  1436. case ':': // key : value separator
  1437. // just ignore
  1438. break;
  1439. case ' ': // spaces
  1440. // just ignore
  1441. break;
  1442. case '[': // array start
  1443. ArrayList currentArray = new ArrayList();
  1444. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1445. {
  1446. ((ArrayList) objectStack.Peek()).Add(currentArray);
  1447. }
  1448. else
  1449. {
  1450. if (currentKey != null) ((Hashtable) objectStack.Peek()).Add(currentKey, currentArray);
  1451. // clear the key
  1452. currentKey = null;
  1453. }
  1454. objectStack.Push(currentArray);
  1455. break;
  1456. case ',': // seperator
  1457. // just ignore
  1458. break;
  1459. case ']': //Array end
  1460. // pop the array off the stack
  1461. objectStack.Pop();
  1462. break;
  1463. case 't': // we've found a character start not in quotes, it must be a boolean true
  1464. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1465. {
  1466. ((ArrayList) objectStack.Peek()).Add(true);
  1467. }
  1468. else
  1469. {
  1470. if (currentKey != null) ((Hashtable) objectStack.Peek()).Add(currentKey, true);
  1471. currentKey = null;
  1472. }
  1473. //advance the counter to the letter 'e'
  1474. i = i + 3;
  1475. break;
  1476. case 'f': // we've found a character start not in quotes, it must be a boolean false
  1477. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1478. {
  1479. ((ArrayList) objectStack.Peek()).Add(false);
  1480. }
  1481. else
  1482. {
  1483. if (currentKey != null) ((Hashtable) objectStack.Peek()).Add(currentKey, false);
  1484. currentKey = null;
  1485. }
  1486. //advance the counter to the letter 'e'
  1487. i = i + 4;
  1488. break;
  1489. case '\n': // carriage return
  1490. // just ignore
  1491. break;
  1492. case '\r': // carriage return
  1493. // just ignore
  1494. break;
  1495. default:
  1496. // ok here we're catching all numeric types int,double,long we might want to spit these up mr accurately
  1497. // but for now we'll just do them as strings
  1498. string numberValue = "";
  1499. // just loop through until the next known marker quote mark storing the string
  1500. while (JSON[i] != '"' && JSON[i] != ',' && JSON[i] != ']' && JSON[i] != '}' &&
  1501. JSON[i] != ' ')
  1502. {
  1503. numberValue += "" + JSON[i++];
  1504. }
  1505. i--; // we want to process this caracter that marked the end of this string in the main loop
  1506. // ok we've got a string, if we've got an array on the top of the stack then we store it
  1507. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1508. {
  1509. ((ArrayList) objectStack.Peek()).Add(numberValue);
  1510. }
  1511. else
  1512. {
  1513. // we have a key so lets store this value
  1514. if (currentKey != null) ((Hashtable) objectStack.Peek()).Add(currentKey, numberValue);
  1515. // now lets clear the key, we're done with it and moving on
  1516. currentKey = null;
  1517. }
  1518. break;
  1519. }
  1520. }
  1521. }
  1522. catch (Exception)
  1523. {
  1524. OSSLError("osParseJSON: The JSON string is not valid " + JSON);
  1525. }
  1526. return jsondata;
  1527. }
  1528. // send a message to to object identified by the given UUID, a script in the object must implement the dataserver function
  1529. // the dataserver function is passed the ID of the calling function and a string message
  1530. public void osMessageObject(LSL_Key objectUUID, string message)
  1531. {
  1532. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Low, "osMessageObject", m_host, "OSSL", m_itemID))
  1533. return;
  1534. object[] resobj = new object[] {new LSL_Key(m_host.UUID.ToString()), new LSL_Key(message)};
  1535. ISceneChildEntity sceneOP = World.GetSceneObjectPart(objectUUID);
  1536. m_ScriptEngine.PostObjectEvent(sceneOP.UUID, "dataserver", resobj);
  1537. }
  1538. // This needs ThreatLevel high. It is an excellent griefer tool,
  1539. // In a loop, it can cause asset bloat and DOS levels of asset
  1540. // writes.
  1541. //
  1542. public void osMakeNotecard(string notecardName, LSL_List contents)
  1543. {
  1544. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osMakeNotecard", m_host, "OSSL", m_itemID))
  1545. return;
  1546. // Create new asset
  1547. AssetBase asset = new AssetBase(UUID.Random(), notecardName, AssetType.Notecard, m_host.OwnerID)
  1548. {
  1549. Description
  1550. =
  1551. "Script Generated Notecard"
  1552. };
  1553. string notecardData = String.Empty;
  1554. for (int i = 0; i < contents.Length; i++)
  1555. {
  1556. notecardData += contents.GetLSLStringItem(i) + "\n";
  1557. }
  1558. int textLength = notecardData.Length;
  1559. notecardData = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length "
  1560. + textLength.ToString(CultureInfo.InvariantCulture) + "\n" + notecardData + "}\n";
  1561. asset.Data = Util.UTF8.GetBytes(notecardData);
  1562. asset.ID = World.AssetService.Store(asset);
  1563. // Create Task Entry
  1564. TaskInventoryItem taskItem = new TaskInventoryItem();
  1565. taskItem.ResetIDs(m_host.UUID);
  1566. taskItem.ParentID = m_host.UUID;
  1567. taskItem.CreationDate = (uint) Util.UnixTimeSinceEpoch();
  1568. taskItem.Name = asset.Name;
  1569. taskItem.Description = asset.Description;
  1570. taskItem.Type = (int) AssetType.Notecard;
  1571. taskItem.InvType = (int) InventoryType.Notecard;
  1572. taskItem.OwnerID = m_host.OwnerID;
  1573. taskItem.CreatorID = m_host.OwnerID;
  1574. taskItem.BasePermissions = (uint) PermissionMask.All;
  1575. taskItem.CurrentPermissions = (uint) PermissionMask.All;
  1576. taskItem.EveryonePermissions = 0;
  1577. taskItem.NextPermissions = (uint) PermissionMask.All;
  1578. taskItem.GroupID = m_host.GroupID;
  1579. taskItem.GroupPermissions = 0;
  1580. taskItem.Flags = 0;
  1581. taskItem.SalePrice = 0;
  1582. taskItem.SaleType = 0;
  1583. taskItem.PermsGranter = UUID.Zero;
  1584. taskItem.PermsMask = 0;
  1585. taskItem.AssetID = asset.ID;
  1586. m_host.Inventory.AddInventoryItem(taskItem, false);
  1587. }
  1588. /*Instead of using the LSL Dataserver event to pull notecard data,
  1589. this will simply read the requested line and return its data as a string.
  1590. Warning - due to the synchronous method this function uses to fetch assets, its use
  1591. may be dangerous and unreliable while running in grid mode.
  1592. */
  1593. public string osGetNotecardLine(string name, int line)
  1594. {
  1595. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine", m_host, "OSSL", m_itemID))
  1596. return "";
  1597. UUID assetID = UUID.Zero;
  1598. if (!UUID.TryParse(name, out assetID))
  1599. {
  1600. foreach (
  1601. TaskInventoryItem item in
  1602. m_host.TaskInventory.Values.Where(item => item.Type == 7 && item.Name == name))
  1603. {
  1604. assetID = item.AssetID;
  1605. }
  1606. }
  1607. if (assetID == UUID.Zero)
  1608. {
  1609. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1610. return "ERROR!";
  1611. }
  1612. if (!NotecardCache.IsCached(assetID))
  1613. {
  1614. byte[] a = World.AssetService.GetData(assetID.ToString());
  1615. if (a != null)
  1616. {
  1617. UTF8Encoding enc = new UTF8Encoding();
  1618. string data = enc.GetString(a);
  1619. NotecardCache.Cache(assetID, data);
  1620. }
  1621. else
  1622. {
  1623. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1624. return "ERROR!";
  1625. }
  1626. }
  1627. return NotecardCache.GetLine(assetID, line, 255);
  1628. }
  1629. /*Instead of using the LSL Dataserver event to pull notecard data line by line,
  1630. this will simply read the entire notecard and return its data as a string.
  1631. Warning - due to the synchronous method this function uses to fetch assets, its use
  1632. may be dangerous and unreliable while running in grid mode.
  1633. */
  1634. public string osGetNotecard(string name)
  1635. {
  1636. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard", m_host, "OSSL", m_itemID))
  1637. return "";
  1638. UUID assetID = UUID.Zero;
  1639. string NotecardData = "";
  1640. if (!UUID.TryParse(name, out assetID))
  1641. {
  1642. foreach (
  1643. TaskInventoryItem item in
  1644. m_host.TaskInventory.Values.Where(item => item.Type == 7 && item.Name == name))
  1645. {
  1646. assetID = item.AssetID;
  1647. }
  1648. }
  1649. if (assetID == UUID.Zero)
  1650. {
  1651. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1652. return "ERROR!";
  1653. }
  1654. if (!NotecardCache.IsCached(assetID))
  1655. {
  1656. byte[] a = World.AssetService.GetData(assetID.ToString());
  1657. if (a != null)
  1658. {
  1659. UTF8Encoding enc = new UTF8Encoding();
  1660. string data = enc.GetString(a);
  1661. NotecardCache.Cache(assetID, data);
  1662. }
  1663. else
  1664. {
  1665. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1666. return "ERROR!";
  1667. }
  1668. }
  1669. for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
  1670. {
  1671. NotecardData += NotecardCache.GetLine(assetID, count, 255) + "\n";
  1672. }
  1673. return NotecardData;
  1674. }
  1675. /*Instead of using the LSL Dataserver event to pull notecard data,
  1676. this will simply read the number of note card lines and return this data as an integer.
  1677. Warning - due to the synchronous method this function uses to fetch assets, its use
  1678. may be dangerous and unreliable while running in grid mode.
  1679. */
  1680. public int osGetNumberOfNotecardLines(string name)
  1681. {
  1682. if (
  1683. !ScriptProtection.CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines", m_host, "OSSL",
  1684. m_itemID)) return 0;
  1685. UUID assetID = UUID.Zero;
  1686. if (!UUID.TryParse(name, out assetID))
  1687. {
  1688. foreach (
  1689. TaskInventoryItem item in
  1690. m_host.TaskInventory.Values.Where(item => item.Type == 7 && item.Name == name))
  1691. {
  1692. assetID = item.AssetID;
  1693. }
  1694. }
  1695. if (assetID == UUID.Zero)
  1696. {
  1697. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1698. return -1;
  1699. }
  1700. if (!NotecardCache.IsCached(assetID))
  1701. {
  1702. byte[] a = World.AssetService.GetData(assetID.ToString());
  1703. if (a != null)
  1704. {
  1705. UTF8Encoding enc = new UTF8Encoding();
  1706. string data = enc.GetString(a);
  1707. NotecardCache.Cache(assetID, data);
  1708. }
  1709. else
  1710. {
  1711. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1712. return -1;
  1713. }
  1714. }
  1715. return NotecardCache.GetLines(assetID);
  1716. }
  1717. public string osAvatarName2Key(string firstname, string lastname)
  1718. {
  1719. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key", m_host, "OSSL", m_itemID))
  1720. return "";
  1721. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.AllScopeIDs,
  1722. firstname + " " + lastname);
  1723. if (null == account)
  1724. {
  1725. return UUID.Zero.ToString();
  1726. }
  1727. else
  1728. {
  1729. return account.PrincipalID.ToString();
  1730. }
  1731. }
  1732. public string osKey2Name(string id)
  1733. {
  1734. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Low, "osKey2Name", m_host, "OSSL", m_itemID)) return "";
  1735. UUID key = new UUID();
  1736. if (UUID.TryParse(id, out key))
  1737. {
  1738. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.AllScopeIDs, key);
  1739. if (null == account)
  1740. {
  1741. return "";
  1742. }
  1743. else
  1744. {
  1745. return account.Name;
  1746. }
  1747. }
  1748. else
  1749. {
  1750. return "";
  1751. }
  1752. }
  1753. /// Threat level is Moderate because intentional abuse, for instance
  1754. /// scripts that are written to be malicious only on one grid,
  1755. /// for instance in a HG scenario, are a distinct possibility.
  1756. ///
  1757. /// Use value from the config file and return it.
  1758. public string osGetGridNick()
  1759. {
  1760. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Moderate, "osGetGridNick", m_host, "OSSL", m_itemID))
  1761. return "";
  1762. string nick = "hippogrid";
  1763. IConfigSource config = m_ScriptEngine.ConfigSource;
  1764. if (config.Configs["GridInfo"] != null)
  1765. nick = config.Configs["GridInfo"].GetString("gridnick", nick);
  1766. return nick;
  1767. }
  1768. public string osGetGridName()
  1769. {
  1770. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Moderate, "osGetGridName", m_host, "OSSL", m_itemID))
  1771. return "";
  1772. string name = "the lost continent of hippo";
  1773. IConfigSource config = m_ScriptEngine.ConfigSource;
  1774. if (config.Configs["GridInfo"] != null)
  1775. name = config.Configs["GridInfo"].GetString("gridname", name);
  1776. return name;
  1777. }
  1778. public string osGetGridLoginURI()
  1779. {
  1780. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Moderate, "osGetGridLoginURI", m_host, "OSSL", m_itemID))
  1781. return "";
  1782. string loginURI = "http://127.0.0.1:9000/";
  1783. IConfigSource config = m_ScriptEngine.ConfigSource;
  1784. if (config.Configs["GridInfo"] != null)
  1785. loginURI = config.Configs["GridInfo"].GetString("login", loginURI);
  1786. return loginURI;
  1787. }
  1788. public LSL_String osFormatString(string str, LSL_List strings)
  1789. {
  1790. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Low, "osFormatString", m_host, "OSSL", m_itemID))
  1791. return new LSL_String();
  1792. return String.Format(str, strings.Data);
  1793. }
  1794. public LSL_List osMatchString(string src, string pattern, int start)
  1795. {
  1796. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osMatchString", m_host, "OSSL", m_itemID))
  1797. return new LSL_List();
  1798. LSL_List result = new LSL_List();
  1799. // Normalize indices (if negative).
  1800. // After normlaization they may still be
  1801. // negative, but that is now relative to
  1802. // the start, rather than the end, of the
  1803. // sequence.
  1804. if (start < 0)
  1805. {
  1806. start = src.Length + start;
  1807. }
  1808. if (start < 0 || start >= src.Length)
  1809. {
  1810. return result; // empty list
  1811. }
  1812. // Find matches beginning at start position
  1813. Regex matcher = new Regex(pattern);
  1814. Match match = matcher.Match(src, start);
  1815. while (match.Success)
  1816. {
  1817. foreach (Group g in match.Groups)
  1818. {
  1819. if (g.Success)
  1820. {
  1821. result.Add(new LSL_Integer(g.Value));
  1822. result.Add(new LSL_Integer(g.Index));
  1823. }
  1824. }
  1825. match = match.NextMatch();
  1826. }
  1827. return result;
  1828. }
  1829. public string osLoadedCreationDate()
  1830. {
  1831. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationDate", m_host, "OSSL", m_itemID))
  1832. return "";
  1833. return World.RegionInfo.RegionSettings.LoadedCreationDate;
  1834. }
  1835. public string osLoadedCreationTime()
  1836. {
  1837. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationTime", m_host, "OSSL", m_itemID))
  1838. return "";
  1839. return World.RegionInfo.RegionSettings.LoadedCreationTime;
  1840. }
  1841. public string osLoadedCreationID()
  1842. {
  1843. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationID", m_host, "OSSL", m_itemID))
  1844. return "";
  1845. return World.RegionInfo.RegionSettings.LoadedCreationID;
  1846. }
  1847. // Threat level is 'Low' because certain users could possibly be tricked into
  1848. // dropping an unverified script into one of their own objects, which could
  1849. // then gather the physical construction details of the object and transmit it
  1850. // to an unscrupulous third party, thus permitting unauthorized duplication of
  1851. // the object's form.
  1852. //
  1853. public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules)
  1854. {
  1855. if (
  1856. !ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams", m_host, "OSSL",
  1857. m_itemID)) return new LSL_List();
  1858. InitLSL();
  1859. LSL_List retVal = new LSL_List();
  1860. //Assign requested part directly
  1861. ISceneChildEntity part = m_host.ParentEntity.GetLinkNumPart(linknumber) as ISceneChildEntity;
  1862. //Check to see if the requested part exists (NOT null) and if so, get it's rules
  1863. if (part != null) retVal = ((LSL_Api) m_LSL_Api).GetLinkPrimitiveParams(part, rules);
  1864. //Will retun rules for specific part, or an empty list if part == null
  1865. return retVal;
  1866. }
  1867. /// <summary>
  1868. /// Get current region's map texture UUID
  1869. /// </summary>
  1870. /// <returns></returns>
  1871. public LSL_Key osGetMapTexture()
  1872. {
  1873. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osGetMapTexture", m_host, "OSSL", m_itemID))
  1874. return new LSL_Key();
  1875. return World.RegionInfo.RegionSettings.TerrainImageID.ToString();
  1876. }
  1877. /// <summary>
  1878. /// Get a region's map texture UUID by region UUID or name.
  1879. /// </summary>
  1880. /// <param name="regionName"></param>
  1881. /// <returns></returns>
  1882. public LSL_Key osGetRegionMapTexture(string regionName)
  1883. {
  1884. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osGetRegionMapTexture", m_host, "OSSL", m_itemID))
  1885. return new LSL_Key();
  1886. IScene scene = m_host.ParentEntity.Scene;
  1887. UUID key = UUID.Zero;
  1888. //If string is a key, use it. Otherwise, try to locate region by name.
  1889. GridRegion region = UUID.TryParse(regionName, out key)
  1890. ? scene.GridService.GetRegionByUUID(scene.RegionInfo.AllScopeIDs, key)
  1891. : scene.GridService.GetRegionByName(scene.RegionInfo.AllScopeIDs, regionName);
  1892. // If region was found, return the regions map texture key.
  1893. if (region != null)
  1894. key = region.TerrainImage;
  1895. return key.ToString();
  1896. }
  1897. /// <summary>
  1898. /// Return information regarding various simulator statistics (sim fps, physics fps, time
  1899. /// dilation, total number of prims, total number of active scripts, script lps, various
  1900. /// timing data, packets in/out, etc. Basically much the information that's shown in the
  1901. /// client's Statistics Bar (Ctrl-Shift-1)
  1902. /// </summary>
  1903. /// <returns>List of floats</returns>
  1904. public LSL_List osGetRegionStats()
  1905. {
  1906. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Moderate, "osGetRegionStats", m_host, "OSSL", m_itemID))
  1907. return new LSL_List();
  1908. LSL_List ret = new LSL_List();
  1909. IMonitorModule mod = World.RequestModuleInterface<IMonitorModule>();
  1910. if (mod != null)
  1911. {
  1912. float[] stats = mod.GetRegionStats(World.RegionInfo.RegionID.ToString());
  1913. for (int i = 0; i < 21; i++)
  1914. {
  1915. ret.Add(new LSL_Float(stats[i]));
  1916. }
  1917. }
  1918. return ret;
  1919. }
  1920. public int osGetSimulatorMemory()
  1921. {
  1922. if (
  1923. !ScriptProtection.CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemory", m_host, "OSSL",
  1924. m_itemID)) return 0;
  1925. long pws = Process.GetCurrentProcess().WorkingSet64;
  1926. if (pws > Int32.MaxValue)
  1927. return Int32.MaxValue;
  1928. if (pws < 0)
  1929. return 0;
  1930. return (int) pws;
  1931. }
  1932. public void osSetSpeed(LSL_Key UUID, LSL_Float SpeedModifier)
  1933. {
  1934. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Moderate, "osSetSpeed", m_host, "OSSL", m_itemID))
  1935. return;
  1936. IScenePresence avatar = World.GetScenePresence(UUID);
  1937. if (avatar != null)
  1938. {
  1939. if (avatar.UUID != m_host.OwnerID)
  1940. {
  1941. //We need to make sure that they can do this then
  1942. if (!World.Permissions.IsGod(m_host.OwnerID))
  1943. return;
  1944. }
  1945. avatar.SpeedModifier = (float) SpeedModifier;
  1946. }
  1947. }
  1948. public void osKickAvatar(LSL_String FirstName, LSL_String SurName, LSL_String alert)
  1949. {
  1950. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar", m_host, "OSSL", m_itemID))
  1951. return;
  1952. World.ForEachScenePresence(delegate(IScenePresence sp)
  1953. {
  1954. if (!sp.IsChildAgent &&
  1955. sp.Firstname == FirstName &&
  1956. sp.Lastname == SurName)
  1957. {
  1958. // kick client...
  1959. sp.ControllingClient.Kick(alert);
  1960. // ...and close on our side
  1961. IEntityTransferModule transferModule =
  1962. sp.Scene.RequestModuleInterface<IEntityTransferModule>();
  1963. if (transferModule != null)
  1964. transferModule.IncomingCloseAgent(sp.Scene, sp.UUID);
  1965. }
  1966. });
  1967. }
  1968. public LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules)
  1969. {
  1970. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osGetPrimitiveParams", m_host, "OSSL", m_itemID))
  1971. return new LSL_List();
  1972. InitLSL();
  1973. return m_LSL_Api.GetLinkPrimitiveParamsEx(prim, rules);
  1974. }
  1975. public void osSetPrimitiveParams(LSL_Key prim, LSL_List rules)
  1976. {
  1977. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osSetPrimitiveParams", m_host, "OSSL", m_itemID))
  1978. return;
  1979. InitLSL();
  1980. m_LSL_Api.SetPrimitiveParamsEx(prim, rules);
  1981. }
  1982. /// <summary>
  1983. /// Set parameters for light projection in host prim
  1984. /// </summary>
  1985. public void osSetProjectionParams(bool projection, LSL_Key texture, double fov, double focus, double amb)
  1986. {
  1987. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams", m_host, "OSSL", m_itemID))
  1988. return;
  1989. osSetProjectionParams(UUID.Zero.ToString(), projection, texture, fov, focus, amb);
  1990. }
  1991. /// <summary>
  1992. /// Set parameters for light projection with uuid of target prim
  1993. /// </summary>
  1994. public void osSetProjectionParams(LSL_Key prim, bool projection, LSL_Key texture, double fov, double focus,
  1995. double amb)
  1996. {
  1997. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams", m_host, "OSSL", m_itemID))
  1998. return;
  1999. ISceneChildEntity obj = null;
  2000. if (prim == UUID.Zero.ToString())
  2001. {
  2002. obj = m_host;
  2003. }
  2004. else
  2005. {
  2006. obj = World.GetSceneObjectPart(prim);
  2007. if (obj == null)
  2008. return;
  2009. }
  2010. obj.Shape.ProjectionEntry = projection;
  2011. obj.Shape.ProjectionTextureUUID = texture;
  2012. obj.Shape.ProjectionFOV = (float) fov;
  2013. obj.Shape.ProjectionFocus = (float) focus;
  2014. obj.Shape.ProjectionAmbiance = (float) amb;
  2015. obj.ParentEntity.HasGroupChanged = true;
  2016. obj.ScheduleUpdate(PrimUpdateFlags.FullUpdate);
  2017. }
  2018. /// <summary>
  2019. /// Like osGetAgents but returns enough info for a radar
  2020. /// </summary>
  2021. /// <returns>Strided list of the UUID, position and name of each avatar in the region</returns>
  2022. public LSL_List osGetAvatarList()
  2023. {
  2024. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "osGetAvatarList", m_host, "OSSL", m_itemID))
  2025. return new LSL_List();
  2026. LSL_List result = new LSL_List();
  2027. World.ForEachScenePresence(delegate(IScenePresence avatar)
  2028. {
  2029. if (avatar != null && avatar.UUID != m_host.OwnerID)
  2030. {
  2031. if (!avatar.IsChildAgent)
  2032. {
  2033. result.Add(new LSL_Key(avatar.UUID.ToString()));
  2034. result.Add(new LSL_Vector(avatar.AbsolutePosition.X,
  2035. avatar.AbsolutePosition.Y,
  2036. avatar.AbsolutePosition.Z));
  2037. result.Add(new LSL_String(avatar.Name));
  2038. }
  2039. }
  2040. });
  2041. return result;
  2042. }
  2043. public LSL_Integer osAddAgentToGroup(LSL_Key AgentID, LSL_String GroupName, LSL_String RequestedRole)
  2044. {
  2045. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Low, "osAddAgentToGroup", m_host, "OSSL", m_itemID))
  2046. return new LSL_Integer();
  2047. IGroupsServicesConnector m_groupData = World.RequestModuleInterface<IGroupsServicesConnector>();
  2048. // No groups module, no functionality
  2049. if (m_groupData == null)
  2050. {
  2051. OSSLShoutError("No Groups Module found for osAddAgentToGroup.");
  2052. return 0;
  2053. }
  2054. UUID roleID = UUID.Zero;
  2055. GroupRecord groupRecord = m_groupData.GetGroupRecord(m_host.OwnerID, UUID.Zero, GroupName.m_string);
  2056. if (groupRecord == null)
  2057. {
  2058. OSSLShoutError("Could not find the group.");
  2059. return 0;
  2060. }
  2061. List<GroupRolesData> roles = m_groupData.GetGroupRoles(m_host.OwnerID, groupRecord.GroupID);
  2062. foreach (GroupRolesData role in roles.Where(role => role.Name == RequestedRole.m_string))
  2063. {
  2064. roleID = role.RoleID;
  2065. }
  2066. //It takes care of permission checks in the module
  2067. m_groupData.AddAgentToGroup(m_host.OwnerID, UUID.Parse(AgentID.m_string), groupRecord.GroupID, roleID);
  2068. return 1;
  2069. }
  2070. public DateTime osRezObject(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param,
  2071. LSL_Integer isRezAtRoot, LSL_Integer doRecoil, LSL_Integer SetDieAtEdge,
  2072. LSL_Integer CheckPos)
  2073. {
  2074. InitLSL();
  2075. return m_LSL_Api.llRezPrim(inventory, pos, vel, rot, param, isRezAtRoot == 1, doRecoil == 1,
  2076. SetDieAtEdge == 1, CheckPos == 1);
  2077. }
  2078. /// <summary>
  2079. /// Convert a unix time to a llGetTimestamp() like string
  2080. /// </summary>
  2081. /// <returns></returns>
  2082. public LSL_String osUnixTimeToTimestamp(long time)
  2083. {
  2084. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.VeryLow, "osUnixTimeToTimestamp", m_host, "OSSL",
  2085. m_itemID)) return new LSL_String();
  2086. const long baseTicks = 621355968000000000;
  2087. const long tickResolution = 10000000;
  2088. long epochTicks = (time*tickResolution) + baseTicks;
  2089. DateTime date = new DateTime(epochTicks);
  2090. return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
  2091. }
  2092. /// <summary>
  2093. /// Get the description from an inventory item
  2094. /// </summary>
  2095. /// <returns>Item description</returns>
  2096. public LSL_String osGetInventoryDesc(string item)
  2097. {
  2098. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.VeryLow, "osGetInventoryDesc", m_host, "OSSL",
  2099. m_itemID)) return new LSL_String();
  2100. lock (m_host.TaskInventory)
  2101. {
  2102. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  2103. {
  2104. if (inv.Value.Name == item)
  2105. {
  2106. return inv.Value.Description.ToString(CultureInfo.InvariantCulture);
  2107. }
  2108. }
  2109. }
  2110. return new LSL_String();
  2111. }
  2112. /// <summary>
  2113. /// Invite user to the group this object is set to
  2114. /// </summary>
  2115. /// <param name="agentId"></param>
  2116. /// <returns></returns>
  2117. public LSL_Integer osInviteToGroup(LSL_Key agentId)
  2118. {
  2119. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.VeryLow, "osInviteToGroup", m_host, "OSSL", m_itemID))
  2120. return new LSL_Integer();
  2121. UUID agent = new UUID((string) agentId);
  2122. // groups module is required
  2123. IGroupsModule groupsModule = World.RequestModuleInterface<IGroupsModule>();
  2124. if (groupsModule == null) return ScriptBaseClass.FALSE;
  2125. // object has to be set to a group, but not group owned
  2126. if (m_host.GroupID == UUID.Zero || m_host.GroupID == m_host.OwnerID) return ScriptBaseClass.FALSE;
  2127. // object owner has to be in that group and required permissions
  2128. GroupMembershipData member = groupsModule.GetMembershipData(m_host.GroupID, m_host.OwnerID);
  2129. if (member == null || (member.GroupPowers & (ulong) GroupPowers.Invite) == 0) return ScriptBaseClass.FALSE;
  2130. // check if agent is in that group already
  2131. //member = groupsModule.GetMembershipData(agent, m_host.GroupID, agent);
  2132. //if (member != null) return ScriptBaseClass.FALSE;
  2133. // invited agent has to be present in this scene
  2134. if (World.GetScenePresence(agent) == null) return ScriptBaseClass.FALSE;
  2135. groupsModule.InviteGroup(null, m_host.OwnerID, m_host.GroupID, agent, UUID.Zero);
  2136. return ScriptBaseClass.TRUE;
  2137. }
  2138. /// <summary>
  2139. /// Eject user from the group this object is set to
  2140. /// </summary>
  2141. /// <param name="agentId"></param>
  2142. /// <returns></returns>
  2143. public LSL_Integer osEjectFromGroup(LSL_Key agentId)
  2144. {
  2145. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.VeryLow, "osInviteToGroup", m_host, "OSSL", m_itemID))
  2146. return new LSL_Integer();
  2147. UUID agent = new UUID((string) agentId);
  2148. // groups module is required
  2149. IGroupsModule groupsModule = World.RequestModuleInterface<IGroupsModule>();
  2150. if (groupsModule == null) return ScriptBaseClass.FALSE;
  2151. // object has to be set to a group, but not group owned
  2152. if (m_host.GroupID == UUID.Zero || m_host.GroupID == m_host.OwnerID) return ScriptBaseClass.FALSE;
  2153. // object owner has to be in that group and required permissions
  2154. GroupMembershipData member = groupsModule.GetMembershipData(m_host.GroupID, m_host.OwnerID);
  2155. if (member == null || (member.GroupPowers & (ulong) GroupPowers.Eject) == 0) return ScriptBaseClass.FALSE;
  2156. // agent has to be in that group
  2157. //member = groupsModule.GetMembershipData(agent, m_host.GroupID, agent);
  2158. //if (member == null) return ScriptBaseClass.FALSE;
  2159. // ejectee can be offline
  2160. groupsModule.EjectGroupMember(null, m_host.OwnerID, m_host.GroupID, agent);
  2161. return ScriptBaseClass.TRUE;
  2162. }
  2163. public void osCauseDamage(string avatar, double damage)
  2164. {
  2165. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osCauseDamage", m_host, "OSSL", m_itemID)) return;
  2166. UUID avatarId = new UUID(avatar);
  2167. Vector3 pos = m_host.GetWorldPosition();
  2168. IScenePresence presence = World.GetScenePresence(avatarId);
  2169. if (presence != null)
  2170. {
  2171. IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
  2172. if (parcelManagement != null)
  2173. {
  2174. LandData land = parcelManagement.GetLandObject(pos.X, pos.Y).LandData;
  2175. if ((land.Flags & (uint) ParcelFlags.AllowDamage) == (uint) ParcelFlags.AllowDamage)
  2176. {
  2177. ICombatPresence cp = presence.RequestModuleInterface<ICombatPresence>();
  2178. cp.IncurDamage(World.GetScenePresence(m_host.OwnerID), damage);
  2179. }
  2180. }
  2181. }
  2182. }
  2183. public void osCauseDamage(string avatar, double damage, string regionName, LSL_Vector position,
  2184. LSL_Vector lookat)
  2185. {
  2186. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osCauseDamage", m_host, "OSSL", m_itemID)) return;
  2187. UUID avatarId = new UUID(avatar);
  2188. Vector3 pos = m_host.GetWorldPosition();
  2189. IScenePresence presence = World.GetScenePresence(avatarId);
  2190. if (presence != null)
  2191. {
  2192. IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
  2193. if (parcelManagement != null)
  2194. {
  2195. LandData land = parcelManagement.GetLandObject(pos.X, pos.Y).LandData;
  2196. if ((land.Flags & (uint) ParcelFlags.AllowDamage) == (uint) ParcelFlags.AllowDamage)
  2197. {
  2198. ICombatPresence cp = presence.RequestModuleInterface<ICombatPresence>();
  2199. cp.IncurDamage(World.GetScenePresence(m_host.OwnerID), damage, regionName,
  2200. new Vector3((float) position.x, (float) position.y, (float) position.z),
  2201. new Vector3((float) lookat.x, (float) lookat.y, (float) lookat.z));
  2202. }
  2203. }
  2204. }
  2205. }
  2206. public void osCauseHealing(string avatar, double healing)
  2207. {
  2208. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osCauseHealing", m_host, "OSSL", m_itemID))
  2209. return;
  2210. UUID avatarId = new UUID(avatar);
  2211. IScenePresence presence = World.GetScenePresence(avatarId);
  2212. if (presence != null)
  2213. {
  2214. Vector3 pos = m_host.GetWorldPosition();
  2215. IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
  2216. if (parcelManagement != null)
  2217. {
  2218. LandData land = parcelManagement.GetLandObject(pos.X, pos.Y).LandData;
  2219. if ((land.Flags & (uint) ParcelFlags.AllowDamage) == (uint) ParcelFlags.AllowDamage)
  2220. {
  2221. ICombatPresence cp = presence.RequestModuleInterface<ICombatPresence>();
  2222. cp.IncurHealing(healing);
  2223. }
  2224. }
  2225. }
  2226. }
  2227. public LSL_Float osGetHealth(string avatar)
  2228. {
  2229. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osGetHealth", m_host, "OSSL", m_itemID))
  2230. return new LSL_Float();
  2231. UUID avatarId = new UUID(avatar);
  2232. LSL_Float health = new LSL_Float(-1);
  2233. IScenePresence presence = World.GetScenePresence(avatarId);
  2234. Vector3 pos = m_host.GetWorldPosition();
  2235. IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
  2236. if (parcelManagement != null)
  2237. {
  2238. LandData land = parcelManagement.GetLandObject(pos.X, pos.Y).LandData;
  2239. if ((land.Flags & (uint) ParcelFlags.AllowDamage) == (uint) ParcelFlags.AllowDamage)
  2240. {
  2241. ICombatPresence cp = presence.RequestModuleInterface<ICombatPresence>();
  2242. health = cp.Health;
  2243. }
  2244. }
  2245. return health;
  2246. }
  2247. #endregion
  2248. #region IScriptApi Members
  2249. public void Initialize(IScriptModulePlugin ScriptEngine, ISceneChildEntity host, uint localID, UUID itemID,
  2250. ScriptProtectionModule module)
  2251. {
  2252. m_ScriptEngine = ScriptEngine;
  2253. m_host = host;
  2254. m_localID = localID;
  2255. m_itemID = itemID;
  2256. if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  2257. m_OSFunctionsEnabled = true;
  2258. m_ScriptDelayFactor =
  2259. m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
  2260. m_ScriptDistanceFactor =
  2261. m_ScriptEngine.Config.GetFloat("ScriptDistanceLimitFactor", 1.0f);
  2262. ScriptProtection = module;
  2263. }
  2264. public IScriptApi Copy()
  2265. {
  2266. return new OSSL_Api();
  2267. }
  2268. public string Name
  2269. {
  2270. get { return "os"; }
  2271. }
  2272. public string InterfaceName
  2273. {
  2274. get { return "IOSSL_Api"; }
  2275. }
  2276. /// <summary>
  2277. /// We don't have to add any assemblies here
  2278. /// </summary>
  2279. public string[] ReferencedAssemblies
  2280. {
  2281. get { return new string[0]; }
  2282. }
  2283. /// <summary>
  2284. /// We use the default namespace, so we don't have any to add
  2285. /// </summary>
  2286. public string[] NamespaceAdditions
  2287. {
  2288. get { return new string[0]; }
  2289. }
  2290. #endregion
  2291. public void Dispose()
  2292. {
  2293. }
  2294. public override Object InitializeLifetimeService()
  2295. {
  2296. ILease lease = (ILease) base.InitializeLifetimeService();
  2297. if (lease.CurrentState == LeaseState.Initial)
  2298. {
  2299. lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
  2300. // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
  2301. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
  2302. }
  2303. return lease;
  2304. }
  2305. internal void OSSLError(string msg)
  2306. {
  2307. throw new Exception("OSSL Runtime Error: " + msg);
  2308. }
  2309. private void InitLSL()
  2310. {
  2311. if (m_LSL_Api != null)
  2312. return;
  2313. m_LSL_Api = (ILSL_Api) m_ScriptEngine.GetApi(m_itemID, "ll");
  2314. }
  2315. //
  2316. //Dumps an error message on the debug console.
  2317. //
  2318. internal void OSSLShoutError(string message)
  2319. {
  2320. if (message.Length > 1023)
  2321. message = message.Substring(0, 1023);
  2322. IChatModule chatModule = World.RequestModuleInterface<IChatModule>();
  2323. if (chatModule != null)
  2324. chatModule.SimChat(message, ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL,
  2325. m_host.ParentEntity.RootChild.AbsolutePosition, m_host.Name, m_host.UUID, true, World);
  2326. IWorldComm wComm = World.RequestModuleInterface<IWorldComm>();
  2327. wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
  2328. }
  2329. /// <summary>
  2330. /// This is the new sleep implementation that allows for us to not freeze the script thread while we run
  2331. /// </summary>
  2332. /// <param name="delay"></param>
  2333. /// <returns></returns>
  2334. protected DateTime PScriptSleep(int delay)
  2335. {
  2336. delay = (int) (delay*m_ScriptDelayFactor);
  2337. if (delay == 0)
  2338. return DateTime.Now;
  2339. return DateTime.Now.AddMilliseconds(delay);
  2340. }
  2341. public void osSetRot(UUID target, Quaternion rotation)
  2342. {
  2343. // This function has no security. It can be used to destroy
  2344. // arbitrary builds the user would normally have no rights to
  2345. //
  2346. if (!ScriptProtection.CheckThreatLevel(ThreatLevel.VeryHigh, "osSetRot", m_host, "OSSL", m_itemID)) return;
  2347. IEntity entity;
  2348. if (World.Entities.TryGetValue(target, out entity))
  2349. {
  2350. if (entity is ISceneEntity)
  2351. ((ISceneEntity) entity).Rotation = rotation;
  2352. else if (entity is IScenePresence)
  2353. (entity).Rotation = rotation;
  2354. }
  2355. else
  2356. {
  2357. OSSLError("osSetRot: Invalid target");
  2358. }
  2359. }
  2360. public DateTime TeleportAgent(UUID agentID, ulong regionHandle, Vector3 position, Vector3 lookAt)
  2361. {
  2362. IScenePresence presence = World.GetScenePresence(agentID);
  2363. if (presence != null)
  2364. {
  2365. // agent must be over owners land to avoid abuse
  2366. IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
  2367. if (parcelManagement != null)
  2368. {
  2369. if (m_host.OwnerID != parcelManagement.GetLandObject(
  2370. presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID &&
  2371. !World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false))
  2372. {
  2373. return DateTime.Now;
  2374. }
  2375. }
  2376. presence.ControllingClient.SendTeleportStart((uint) TeleportFlags.ViaLocation);
  2377. IEntityTransferModule entityTransfer = World.RequestModuleInterface<IEntityTransferModule>();
  2378. if (entityTransfer != null)
  2379. {
  2380. entityTransfer.RequestTeleportLocation(presence.ControllingClient,
  2381. regionHandle,
  2382. position,
  2383. lookAt, (uint) TeleportFlags.ViaLocation);
  2384. }
  2385. return PScriptSleep(5000);
  2386. }
  2387. return DateTime.Now;
  2388. }
  2389. }
  2390. }