PageRenderTime 60ms CodeModel.GetById 25ms 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

Large files files are truncated, but you can click here to view the full 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.G

Large files files are truncated, but you can click here to view the full file