PageRenderTime 33ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs

https://gitlab.com/N3X15/VoxelSim
C# | 2284 lines | 1680 code | 323 blank | 281 comment | 280 complexity | e2b81603fc578df7d35bb8977f6f1d56 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Runtime.Remoting.Lifetime;
  31. using System.Text;
  32. using System.Net;
  33. using System.Threading;
  34. using OpenMetaverse;
  35. using Nini.Config;
  36. using OpenSim;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Console;
  39. using OpenSim.Region.CoreModules.Avatar.NPC;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.Framework.Scenes;
  42. using OpenSim.Region.ScriptEngine.Shared;
  43. using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
  44. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  45. using OpenSim.Region.ScriptEngine.Interfaces;
  46. using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
  47. using TPFlags = OpenSim.Framework.Constants.TeleportFlags;
  48. using OpenSim.Services.Interfaces;
  49. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  50. using System.Text.RegularExpressions;
  51. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  52. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  53. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  54. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  55. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  56. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  57. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  58. namespace OpenSim.Region.ScriptEngine.Shared.Api
  59. {
  60. //////////////////////////////////////////////////////////////
  61. //
  62. // Level description
  63. //
  64. // None - Function is no threat at all. It doesn't constitute
  65. // an threat to either users or the system and has no
  66. // known side effects
  67. //
  68. // Nuisance - Abuse of this command can cause a nuisance to the
  69. // region operator, such as log message spew
  70. //
  71. // VeryLow - Extreme levels ob abuse of this function can cause
  72. // impaired functioning of the region, or very gullible
  73. // users can be tricked into experiencing harmless effects
  74. //
  75. // Low - Intentional abuse can cause crashes or malfunction
  76. // under certain circumstances, which can easily be rectified,
  77. // or certain users can be tricked into certain situations
  78. // in an avoidable manner.
  79. //
  80. // Moderate - Intentional abuse can cause denial of service and crashes
  81. // with potential of data or state loss, or trusting users
  82. // can be tricked into embarrassing or uncomfortable
  83. // situationsa.
  84. //
  85. // High - Casual abuse can cause impaired functionality or temporary
  86. // denial of service conditions. Intentional abuse can easily
  87. // cause crashes with potential data loss, or can be used to
  88. // trick experienced and cautious users into unwanted situations,
  89. // or changes global data permanently and without undo ability
  90. // Malicious scripting can allow theft of content
  91. //
  92. // VeryHigh - Even normal use may, depending on the number of instances,
  93. // or frequency of use, result in severe service impairment
  94. // or crash with loss of data, or can be used to cause
  95. // unwanted or harmful effects on users without giving the
  96. // user a means to avoid it.
  97. //
  98. // Severe - Even casual use is a danger to region stability, or function
  99. // allows console or OS command execution, or function allows
  100. // taking money without consent, or allows deletion or
  101. // modification of user data, or allows the compromise of
  102. // sensitive data by design.
  103. class FunctionPerms
  104. {
  105. public List<UUID> AllowedCreators;
  106. public List<UUID> AllowedOwners;
  107. public FunctionPerms()
  108. {
  109. AllowedCreators = new List<UUID>();
  110. AllowedOwners = new List<UUID>();
  111. }
  112. }
  113. [Serializable]
  114. public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi
  115. {
  116. internal IScriptEngine m_ScriptEngine;
  117. internal ILSL_Api m_LSL_Api = null; // get a reference to the LSL API so we can call methods housed there
  118. internal SceneObjectPart m_host;
  119. internal uint m_localID;
  120. internal UUID m_itemID;
  121. internal bool m_OSFunctionsEnabled = false;
  122. internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow;
  123. internal float m_ScriptDelayFactor = 1.0f;
  124. internal float m_ScriptDistanceFactor = 1.0f;
  125. internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
  126. public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID)
  127. {
  128. m_ScriptEngine = ScriptEngine;
  129. m_host = host;
  130. m_localID = localID;
  131. m_itemID = itemID;
  132. if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  133. m_OSFunctionsEnabled = true;
  134. m_ScriptDelayFactor =
  135. m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
  136. m_ScriptDistanceFactor =
  137. m_ScriptEngine.Config.GetFloat("ScriptDistanceLimitFactor", 1.0f);
  138. string risk = m_ScriptEngine.Config.GetString("OSFunctionThreatLevel", "VeryLow");
  139. switch (risk)
  140. {
  141. case "None":
  142. m_MaxThreatLevel = ThreatLevel.None;
  143. break;
  144. case "VeryLow":
  145. m_MaxThreatLevel = ThreatLevel.VeryLow;
  146. break;
  147. case "Low":
  148. m_MaxThreatLevel = ThreatLevel.Low;
  149. break;
  150. case "Moderate":
  151. m_MaxThreatLevel = ThreatLevel.Moderate;
  152. break;
  153. case "High":
  154. m_MaxThreatLevel = ThreatLevel.High;
  155. break;
  156. case "VeryHigh":
  157. m_MaxThreatLevel = ThreatLevel.VeryHigh;
  158. break;
  159. case "Severe":
  160. m_MaxThreatLevel = ThreatLevel.Severe;
  161. break;
  162. default:
  163. break;
  164. }
  165. }
  166. public override Object InitializeLifetimeService()
  167. {
  168. ILease lease = (ILease)base.InitializeLifetimeService();
  169. if (lease.CurrentState == LeaseState.Initial)
  170. {
  171. lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
  172. // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
  173. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
  174. }
  175. return lease;
  176. }
  177. public Scene World
  178. {
  179. get { return m_ScriptEngine.World; }
  180. }
  181. internal void OSSLError(string msg)
  182. {
  183. throw new Exception("OSSL Runtime Error: " + msg);
  184. }
  185. private void InitLSL()
  186. {
  187. if (m_LSL_Api != null)
  188. return;
  189. m_LSL_Api = (ILSL_Api)m_ScriptEngine.GetApi(m_itemID, "LSL");
  190. }
  191. //
  192. //Dumps an error message on the debug console.
  193. //
  194. internal void OSSLShoutError(string message)
  195. {
  196. if (message.Length > 1023)
  197. message = message.Substring(0, 1023);
  198. World.SimChat(Utils.StringToBytes(message),
  199. ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  200. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  201. wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
  202. }
  203. public void CheckThreatLevel(ThreatLevel level, string function)
  204. {
  205. if (!m_OSFunctionsEnabled)
  206. OSSLError(String.Format("{0} permission denied. All OS functions are disabled.", function)); // throws
  207. if (!m_FunctionPerms.ContainsKey(function))
  208. {
  209. FunctionPerms perms = new FunctionPerms();
  210. m_FunctionPerms[function] = perms;
  211. string ownerPerm = m_ScriptEngine.Config.GetString("Allow_" + function, "");
  212. string creatorPerm = m_ScriptEngine.Config.GetString("Creators_" + function, "");
  213. if (ownerPerm == "" && creatorPerm == "")
  214. {
  215. // Default behavior
  216. perms.AllowedOwners = null;
  217. perms.AllowedCreators = null;
  218. }
  219. else
  220. {
  221. bool allowed;
  222. if (bool.TryParse(ownerPerm, out allowed))
  223. {
  224. // Boolean given
  225. if (allowed)
  226. {
  227. // Allow globally
  228. perms.AllowedOwners.Add(UUID.Zero);
  229. }
  230. }
  231. else
  232. {
  233. string[] ids = ownerPerm.Split(new char[] {','});
  234. foreach (string id in ids)
  235. {
  236. string current = id.Trim();
  237. UUID uuid;
  238. if (UUID.TryParse(current, out uuid))
  239. {
  240. if (uuid != UUID.Zero)
  241. perms.AllowedOwners.Add(uuid);
  242. }
  243. }
  244. ids = creatorPerm.Split(new char[] {','});
  245. foreach (string id in ids)
  246. {
  247. string current = id.Trim();
  248. UUID uuid;
  249. if (UUID.TryParse(current, out uuid))
  250. {
  251. if (uuid != UUID.Zero)
  252. perms.AllowedCreators.Add(uuid);
  253. }
  254. }
  255. }
  256. }
  257. }
  258. // If the list is null, then the value was true / undefined
  259. // Threat level governs permissions in this case
  260. //
  261. // If the list is non-null, then it is a list of UUIDs allowed
  262. // to use that particular function. False causes an empty
  263. // list and therefore means "no one"
  264. //
  265. // To allow use by anyone, the list contains UUID.Zero
  266. //
  267. if (m_FunctionPerms[function].AllowedOwners == null)
  268. {
  269. // Allow / disallow by threat level
  270. if (level > m_MaxThreatLevel)
  271. OSSLError(
  272. String.Format(
  273. "{0} permission denied. Allowed threat level is {1} but function threat level is {2}.",
  274. function, m_MaxThreatLevel, level));
  275. }
  276. else
  277. {
  278. if (!m_FunctionPerms[function].AllowedOwners.Contains(UUID.Zero))
  279. {
  280. // Not anyone. Do detailed checks
  281. if (m_FunctionPerms[function].AllowedOwners.Contains(m_host.OwnerID))
  282. {
  283. // prim owner is in the list of allowed owners
  284. return;
  285. }
  286. TaskInventoryItem ti = m_host.Inventory.GetInventoryItem(m_itemID);
  287. if (ti == null)
  288. {
  289. OSSLError(
  290. String.Format("{0} permission error. Can't find script in prim inventory.",
  291. function));
  292. }
  293. if (!m_FunctionPerms[function].AllowedCreators.Contains(ti.CreatorID))
  294. OSSLError(
  295. String.Format("{0} permission denied. Script creator is not in the list of users allowed to execute this function and prim owner also has no permission.",
  296. function));
  297. if (ti.CreatorID != ti.OwnerID)
  298. {
  299. if ((ti.CurrentPermissions & (uint)PermissionMask.Modify) != 0)
  300. OSSLError(
  301. String.Format("{0} permission denied. Script permissions error.",
  302. function));
  303. }
  304. }
  305. }
  306. }
  307. protected void ScriptSleep(int delay)
  308. {
  309. delay = (int)((float)delay * m_ScriptDelayFactor);
  310. if (delay == 0)
  311. return;
  312. System.Threading.Thread.Sleep(delay);
  313. }
  314. //
  315. // OpenSim functions
  316. //
  317. public LSL_Integer osTerrainSetHeight(int x, int y, double val)
  318. {
  319. CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight");
  320. m_host.AddScriptLPS(1);
  321. if (x > ((int)Constants.RegionSize - 1) || x < 0 || y > ((int)Constants.RegionSize - 1) || y < 0)
  322. OSSLError("osTerrainSetHeight: Coordinate out of bounds");
  323. if (World.Permissions.CanTerraformLand(m_host.OwnerID, new Vector3(x, y, 0)))
  324. {
  325. int initial_height=(int)World.GetGroundHeight(x,y);
  326. if(initial_height>(int)val)
  327. {
  328. for(int z=initial_height;z<(int)val;z++)
  329. {
  330. (World.Voxels as VoxelChannel).SetVoxel(x,y,z,0x01);
  331. }
  332. }
  333. else if(initial_height<(int)val)
  334. {
  335. for(int z=initial_height;z>(int)val;z++)
  336. {
  337. (World.Voxels as VoxelChannel).SetVoxel(x,y,z,0x01);
  338. }
  339. }
  340. return 1;
  341. }
  342. else
  343. {
  344. return 0;
  345. }
  346. }
  347. public LSL_Float osTerrainGetHeight(int x, int y)
  348. {
  349. CheckThreatLevel(ThreatLevel.None, "osTerrainGetHeight");
  350. m_host.AddScriptLPS(1);
  351. if (x > ((int)Constants.RegionSize - 1) || x < 0 || y > ((int)Constants.RegionSize - 1) || y < 0)
  352. OSSLError("osTerrainGetHeight: Coordinate out of bounds");
  353. return World.GetGroundHeight(x,y);
  354. }
  355. public void osTerrainFlush()
  356. {
  357. CheckThreatLevel(ThreatLevel.VeryLow, "osTerrainFlush");
  358. ITerrainModule terrainModule = World.RequestModuleInterface<ITerrainModule>();
  359. if (terrainModule != null) terrainModule.TaintTerrain();
  360. }
  361. public int osRegionRestart(double seconds)
  362. {
  363. // This is High here because region restart is not reliable
  364. // it may result in the region staying down or becoming
  365. // unstable. This should be changed to Low or VeryLow once
  366. // The underlying functionality is fixed, since the security
  367. // as such is sound
  368. //
  369. CheckThreatLevel(ThreatLevel.High, "osRegionRestart");
  370. m_host.AddScriptLPS(1);
  371. if (World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false))
  372. {
  373. World.Restart((float)seconds);
  374. return 1;
  375. }
  376. else
  377. {
  378. return 0;
  379. }
  380. }
  381. public void osRegionNotice(string msg)
  382. {
  383. // This implementation provides absolutely no security
  384. // It's high griefing potential makes this classification
  385. // necessary
  386. //
  387. CheckThreatLevel(ThreatLevel.VeryHigh, "osRegionNotice");
  388. m_host.AddScriptLPS(1);
  389. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  390. if (dm != null)
  391. dm.SendGeneralAlert(msg);
  392. }
  393. public void osSetRot(UUID target, Quaternion rotation)
  394. {
  395. // This function has no security. It can be used to destroy
  396. // arbitrary builds the user would normally have no rights to
  397. //
  398. CheckThreatLevel(ThreatLevel.VeryHigh, "osSetRot");
  399. m_host.AddScriptLPS(1);
  400. if (World.Entities.ContainsKey(target))
  401. {
  402. EntityBase entity;
  403. if (World.Entities.TryGetValue(target, out entity))
  404. {
  405. if (entity is SceneObjectGroup)
  406. ((SceneObjectGroup)entity).Rotation = rotation;
  407. else if (entity is ScenePresence)
  408. ((ScenePresence)entity).Rotation = rotation;
  409. }
  410. }
  411. else
  412. {
  413. OSSLError("osSetRot: Invalid target");
  414. }
  415. }
  416. public string osSetDynamicTextureURL(string dynamicID, string contentType, string url, string extraParams,
  417. int timer)
  418. {
  419. // This may be upgraded depending on the griefing or DOS
  420. // potential, or guarded with a delay
  421. //
  422. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURL");
  423. m_host.AddScriptLPS(1);
  424. if (dynamicID == String.Empty)
  425. {
  426. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  427. UUID createdTexture =
  428. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  429. extraParams, timer);
  430. return createdTexture.ToString();
  431. }
  432. else
  433. {
  434. //TODO update existing dynamic textures
  435. }
  436. return UUID.Zero.ToString();
  437. }
  438. public string osSetDynamicTextureURLBlend(string dynamicID, string contentType, string url, string extraParams,
  439. int timer, int alpha)
  440. {
  441. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURLBlend");
  442. m_host.AddScriptLPS(1);
  443. if (dynamicID == String.Empty)
  444. {
  445. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  446. UUID createdTexture =
  447. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  448. extraParams, timer, true, (byte) alpha);
  449. return createdTexture.ToString();
  450. }
  451. else
  452. {
  453. //TODO update existing dynamic textures
  454. }
  455. return UUID.Zero.ToString();
  456. }
  457. public string osSetDynamicTextureURLBlendFace(string dynamicID, string contentType, string url, string extraParams,
  458. bool blend, int disp, int timer, int alpha, int face)
  459. {
  460. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURLBlendFace");
  461. m_host.AddScriptLPS(1);
  462. if (dynamicID == String.Empty)
  463. {
  464. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  465. UUID createdTexture =
  466. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  467. extraParams, timer, blend, disp, (byte) alpha, face);
  468. return createdTexture.ToString();
  469. }
  470. else
  471. {
  472. //TODO update existing dynamic textures
  473. }
  474. return UUID.Zero.ToString();
  475. }
  476. public string osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams,
  477. int timer)
  478. {
  479. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureData");
  480. m_host.AddScriptLPS(1);
  481. if (dynamicID == String.Empty)
  482. {
  483. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  484. if (textureManager != null)
  485. {
  486. if (extraParams == String.Empty)
  487. {
  488. extraParams = "256";
  489. }
  490. UUID createdTexture =
  491. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  492. extraParams, timer);
  493. return createdTexture.ToString();
  494. }
  495. }
  496. else
  497. {
  498. //TODO update existing dynamic textures
  499. }
  500. return UUID.Zero.ToString();
  501. }
  502. public string osSetDynamicTextureDataBlend(string dynamicID, string contentType, string data, string extraParams,
  503. int timer, int alpha)
  504. {
  505. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureDataBlend");
  506. m_host.AddScriptLPS(1);
  507. if (dynamicID == String.Empty)
  508. {
  509. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  510. if (textureManager != null)
  511. {
  512. if (extraParams == String.Empty)
  513. {
  514. extraParams = "256";
  515. }
  516. UUID createdTexture =
  517. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  518. extraParams, timer, true, (byte) alpha);
  519. return createdTexture.ToString();
  520. }
  521. }
  522. else
  523. {
  524. //TODO update existing dynamic textures
  525. }
  526. return UUID.Zero.ToString();
  527. }
  528. public string osSetDynamicTextureDataBlendFace(string dynamicID, string contentType, string data, string extraParams,
  529. bool blend, int disp, int timer, int alpha, int face)
  530. {
  531. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureDataBlendFace");
  532. m_host.AddScriptLPS(1);
  533. if (dynamicID == String.Empty)
  534. {
  535. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  536. if (textureManager != null)
  537. {
  538. if (extraParams == String.Empty)
  539. {
  540. extraParams = "256";
  541. }
  542. UUID createdTexture =
  543. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  544. extraParams, timer, blend, disp, (byte) alpha, face);
  545. return createdTexture.ToString();
  546. }
  547. }
  548. else
  549. {
  550. //TODO update existing dynamic textures
  551. }
  552. return UUID.Zero.ToString();
  553. }
  554. public bool osConsoleCommand(string command)
  555. {
  556. CheckThreatLevel(ThreatLevel.Severe, "osConsoleCommand");
  557. m_host.AddScriptLPS(1);
  558. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  559. {
  560. MainConsole.Instance.RunCommand(command);
  561. return true;
  562. }
  563. return false;
  564. }
  565. public void osSetPrimFloatOnWater(int floatYN)
  566. {
  567. CheckThreatLevel(ThreatLevel.VeryLow, "osSetPrimFloatOnWater");
  568. m_host.AddScriptLPS(1);
  569. if (m_host.ParentGroup != null)
  570. {
  571. if (m_host.ParentGroup.RootPart != null)
  572. {
  573. m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN);
  574. }
  575. }
  576. }
  577. // Teleport functions
  578. public void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  579. {
  580. // High because there is no security check. High griefer potential
  581. //
  582. CheckThreatLevel(ThreatLevel.High, "osTeleportAgent");
  583. m_host.AddScriptLPS(1);
  584. UUID agentId = new UUID();
  585. if (UUID.TryParse(agent, out agentId))
  586. {
  587. ScenePresence presence = World.GetScenePresence(agentId);
  588. if (presence != null)
  589. {
  590. // agent must be over owners land to avoid abuse
  591. if (m_host.OwnerID
  592. == World.LandChannel.GetLandObject(
  593. presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
  594. {
  595. // Check for hostname , attempt to make a hglink
  596. // and convert the regionName to the target region
  597. if (regionName.Contains(".") && regionName.Contains(":"))
  598. {
  599. List<GridRegion> regions = World.GridService.GetRegionsByName(World.RegionInfo.ScopeID, regionName, 1);
  600. // Try to link the region
  601. if (regions != null && regions.Count > 0)
  602. {
  603. GridRegion regInfo = regions[0];
  604. regionName = regInfo.RegionName;
  605. }
  606. }
  607. World.RequestTeleportLocation(presence.ControllingClient, regionName,
  608. new Vector3((float)position.x, (float)position.y, (float)position.z),
  609. new Vector3((float)lookat.x, (float)lookat.y, (float)lookat.z), (uint)TPFlags.ViaLocation);
  610. ScriptSleep(5000);
  611. }
  612. }
  613. }
  614. }
  615. // Teleport functions
  616. public void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  617. {
  618. // High because there is no security check. High griefer potential
  619. //
  620. CheckThreatLevel(ThreatLevel.High, "osTeleportAgent");
  621. ulong regionHandle = Util.UIntsToLong(((uint)regionX * (uint)Constants.RegionSize), ((uint)regionY * (uint)Constants.RegionSize));
  622. m_host.AddScriptLPS(1);
  623. UUID agentId = new UUID();
  624. if (UUID.TryParse(agent, out agentId))
  625. {
  626. ScenePresence presence = World.GetScenePresence(agentId);
  627. if (presence != null)
  628. {
  629. // agent must be over owners land to avoid abuse
  630. if (m_host.OwnerID
  631. == World.LandChannel.GetLandObject(
  632. presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
  633. {
  634. World.RequestTeleportLocation(presence.ControllingClient, regionHandle,
  635. new Vector3((float)position.x, (float)position.y, (float)position.z),
  636. new Vector3((float)lookat.x, (float)lookat.y, (float)lookat.z), (uint)TPFlags.ViaLocation);
  637. ScriptSleep(5000);
  638. }
  639. }
  640. }
  641. }
  642. public void osTeleportAgent(string agent, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  643. {
  644. osTeleportAgent(agent, World.RegionInfo.RegionName, position, lookat);
  645. }
  646. // Functions that get information from the agent itself.
  647. //
  648. // osGetAgentIP - this is used to determine the IP address of
  649. //the client. This is needed to help configure other in world
  650. //resources based on the IP address of the clients connected.
  651. //I think High is a good risk level for this, as it is an
  652. //information leak.
  653. public string osGetAgentIP(string agent)
  654. {
  655. CheckThreatLevel(ThreatLevel.High, "osGetAgentIP");
  656. UUID avatarID = (UUID)agent;
  657. m_host.AddScriptLPS(1);
  658. if (World.Entities.ContainsKey((UUID)agent) && World.Entities[avatarID] is ScenePresence)
  659. {
  660. ScenePresence target = (ScenePresence)World.Entities[avatarID];
  661. EndPoint ep = target.ControllingClient.GetClientEP();
  662. if (ep is IPEndPoint)
  663. {
  664. IPEndPoint ip = (IPEndPoint)ep;
  665. return ip.Address.ToString();
  666. }
  667. }
  668. // fall through case, just return nothing
  669. return "";
  670. }
  671. // Get a list of all the avatars/agents in the region
  672. public LSL_List osGetAgents()
  673. {
  674. // threat level is None as we could get this information with an
  675. // in-world script as well, just not as efficient
  676. CheckThreatLevel(ThreatLevel.None, "osGetAgents");
  677. LSL_List result = new LSL_List();
  678. World.ForEachScenePresence(delegate(ScenePresence sp)
  679. {
  680. if (!sp.IsChildAgent)
  681. result.Add(sp.Name);
  682. });
  683. return result;
  684. }
  685. // Adam's super super custom animation functions
  686. public void osAvatarPlayAnimation(string avatar, string animation)
  687. {
  688. CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarPlayAnimation");
  689. UUID avatarID = (UUID)avatar;
  690. m_host.AddScriptLPS(1);
  691. if (World.Entities.ContainsKey((UUID)avatar) && World.Entities[avatarID] is ScenePresence)
  692. {
  693. ScenePresence target = (ScenePresence)World.Entities[avatarID];
  694. if (target != null)
  695. {
  696. UUID animID=UUID.Zero;
  697. lock (m_host.TaskInventory)
  698. {
  699. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  700. {
  701. if (inv.Value.Name == animation)
  702. {
  703. if (inv.Value.Type == (int)AssetType.Animation)
  704. animID = inv.Value.AssetID;
  705. continue;
  706. }
  707. }
  708. }
  709. if (animID == UUID.Zero)
  710. target.Animator.AddAnimation(animation, m_host.UUID);
  711. else
  712. target.Animator.AddAnimation(animID, m_host.UUID);
  713. }
  714. }
  715. }
  716. public void osAvatarStopAnimation(string avatar, string animation)
  717. {
  718. CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarStopAnimation");
  719. UUID avatarID = (UUID)avatar;
  720. m_host.AddScriptLPS(1);
  721. if (World.Entities.ContainsKey(avatarID) && World.Entities[avatarID] is ScenePresence)
  722. {
  723. ScenePresence target = (ScenePresence)World.Entities[avatarID];
  724. if (target != null)
  725. {
  726. UUID animID=UUID.Zero;
  727. lock (m_host.TaskInventory)
  728. {
  729. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  730. {
  731. if (inv.Value.Name == animation)
  732. {
  733. if (inv.Value.Type == (int)AssetType.Animation)
  734. animID = inv.Value.AssetID;
  735. continue;
  736. }
  737. }
  738. }
  739. if (animID == UUID.Zero)
  740. target.Animator.RemoveAnimation(animation);
  741. else
  742. target.Animator.RemoveAnimation(animID);
  743. }
  744. }
  745. }
  746. //Texture draw functions
  747. public string osMovePen(string drawList, int x, int y)
  748. {
  749. CheckThreatLevel(ThreatLevel.None, "osMovePen");
  750. m_host.AddScriptLPS(1);
  751. drawList += "MoveTo " + x + "," + y + ";";
  752. return drawList;
  753. }
  754. public string osDrawLine(string drawList, int startX, int startY, int endX, int endY)
  755. {
  756. CheckThreatLevel(ThreatLevel.None, "osDrawLine");
  757. m_host.AddScriptLPS(1);
  758. drawList += "MoveTo "+ startX+","+ startY +"; LineTo "+endX +","+endY +"; ";
  759. return drawList;
  760. }
  761. public string osDrawLine(string drawList, int endX, int endY)
  762. {
  763. CheckThreatLevel(ThreatLevel.None, "osDrawLine");
  764. m_host.AddScriptLPS(1);
  765. drawList += "LineTo " + endX + "," + endY + "; ";
  766. return drawList;
  767. }
  768. public string osDrawText(string drawList, string text)
  769. {
  770. CheckThreatLevel(ThreatLevel.None, "osDrawText");
  771. m_host.AddScriptLPS(1);
  772. drawList += "Text " + text + "; ";
  773. return drawList;
  774. }
  775. public string osDrawEllipse(string drawList, int width, int height)
  776. {
  777. CheckThreatLevel(ThreatLevel.None, "osDrawEllipse");
  778. m_host.AddScriptLPS(1);
  779. drawList += "Ellipse " + width + "," + height + "; ";
  780. return drawList;
  781. }
  782. public string osDrawRectangle(string drawList, int width, int height)
  783. {
  784. CheckThreatLevel(ThreatLevel.None, "osDrawRectangle");
  785. m_host.AddScriptLPS(1);
  786. drawList += "Rectangle " + width + "," + height + "; ";
  787. return drawList;
  788. }
  789. public string osDrawFilledRectangle(string drawList, int width, int height)
  790. {
  791. CheckThreatLevel(ThreatLevel.None, "osDrawFilledRectangle");
  792. m_host.AddScriptLPS(1);
  793. drawList += "FillRectangle " + width + "," + height + "; ";
  794. return drawList;
  795. }
  796. public string osDrawFilledPolygon(string drawList, LSL_List x, LSL_List y)
  797. {
  798. CheckThreatLevel(ThreatLevel.None, "osDrawFilledPolygon");
  799. m_host.AddScriptLPS(1);
  800. if (x.Length != y.Length || x.Length < 3)
  801. {
  802. return "";
  803. }
  804. drawList += "FillPolygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
  805. for (int i = 1; i < x.Length; i++)
  806. {
  807. drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
  808. }
  809. drawList += "; ";
  810. return drawList;
  811. }
  812. public string osDrawPolygon(string drawList, LSL_List x, LSL_List y)
  813. {
  814. CheckThreatLevel(ThreatLevel.None, "osDrawFilledPolygon");
  815. m_host.AddScriptLPS(1);
  816. if (x.Length != y.Length || x.Length < 3)
  817. {
  818. return "";
  819. }
  820. drawList += "Polygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
  821. for (int i = 1; i < x.Length; i++)
  822. {
  823. drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
  824. }
  825. drawList += "; ";
  826. return drawList;
  827. }
  828. public string osSetFontSize(string drawList, int fontSize)
  829. {
  830. CheckThreatLevel(ThreatLevel.None, "osSetFontSize");
  831. m_host.AddScriptLPS(1);
  832. drawList += "FontSize "+ fontSize +"; ";
  833. return drawList;
  834. }
  835. public string osSetFontName(string drawList, string fontName)
  836. {
  837. CheckThreatLevel(ThreatLevel.None, "osSetFontName");
  838. m_host.AddScriptLPS(1);
  839. drawList += "FontName "+ fontName +"; ";
  840. return drawList;
  841. }
  842. public string osSetPenSize(string drawList, int penSize)
  843. {
  844. CheckThreatLevel(ThreatLevel.None, "osSetPenSize");
  845. m_host.AddScriptLPS(1);
  846. drawList += "PenSize " + penSize + "; ";
  847. return drawList;
  848. }
  849. public string osSetPenColour(string drawList, string colour)
  850. {
  851. CheckThreatLevel(ThreatLevel.None, "osSetPenColour");
  852. m_host.AddScriptLPS(1);
  853. drawList += "PenColour " + colour + "; ";
  854. return drawList;
  855. }
  856. public string osSetPenCap(string drawList, string direction, string type)
  857. {
  858. CheckThreatLevel(ThreatLevel.None, "osSetPenColour");
  859. m_host.AddScriptLPS(1);
  860. drawList += "PenCap " + direction + "," + type + "; ";
  861. return drawList;
  862. }
  863. public string osDrawImage(string drawList, int width, int height, string imageUrl)
  864. {
  865. CheckThreatLevel(ThreatLevel.None, "osDrawImage");
  866. m_host.AddScriptLPS(1);
  867. drawList +="Image " +width + "," + height+ ","+ imageUrl +"; " ;
  868. return drawList;
  869. }
  870. public LSL_Vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize)
  871. {
  872. CheckThreatLevel(ThreatLevel.VeryLow, "osGetDrawStringSize");
  873. m_host.AddScriptLPS(1);
  874. LSL_Vector vec = new LSL_Vector(0,0,0);
  875. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  876. if (textureManager != null)
  877. {
  878. double xSize, ySize;
  879. textureManager.GetDrawStringSize(contentType, text, fontName, fontSize,
  880. out xSize, out ySize);
  881. vec.x = xSize;
  882. vec.y = ySize;
  883. }
  884. return vec;
  885. }
  886. public void osSetStateEvents(int events)
  887. {
  888. // This function is a hack. There is no reason for it's existence
  889. // anymore, since state events now work properly.
  890. // It was probably added as a crutch or debugging aid, and
  891. // should be removed
  892. //
  893. CheckThreatLevel(ThreatLevel.High, "osSetStateEvents");
  894. m_host.SetScriptEvents(m_itemID, events);
  895. }
  896. public void osSetRegionWaterHeight(double height)
  897. {
  898. CheckThreatLevel(ThreatLevel.High, "osSetRegionWaterHeight");
  899. m_host.AddScriptLPS(1);
  900. //Check to make sure that the script's owner is the estate manager/master
  901. //World.Permissions.GenericEstatePermission(
  902. if (World.Permissions.IsGod(m_host.OwnerID))
  903. {
  904. World.EventManager.TriggerRequestChangeWaterHeight((float)height);
  905. }
  906. }
  907. /// <summary>
  908. /// Changes the Region Sun Settings, then Triggers a Sun Update
  909. /// </summary>
  910. /// <param name="useEstateSun">True to use Estate Sun instead of Region Sun</param>
  911. /// <param name="sunFixed">True to keep the sun stationary</param>
  912. /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
  913. public void osSetRegionSunSettings(bool useEstateSun, bool sunFixed, double sunHour)
  914. {
  915. CheckThreatLevel(ThreatLevel.Nuisance, "osSetRegionSunSettings");
  916. m_host.AddScriptLPS(1);
  917. //Check to make sure that the script's owner is the estate manager/master
  918. //World.Permissions.GenericEstatePermission(
  919. if (World.Permissions.IsGod(m_host.OwnerID))
  920. {
  921. while (sunHour > 24.0)
  922. sunHour -= 24.0;
  923. while (sunHour < 0)
  924. sunHour += 24.0;
  925. World.RegionInfo.RegionSettings.UseEstateSun = useEstateSun;
  926. World.RegionInfo.RegionSettings.SunPosition = sunHour + 6; // LL Region Sun Hour is 6 to 30
  927. World.RegionInfo.RegionSettings.FixedSun = sunFixed;
  928. World.RegionInfo.RegionSettings.Save();
  929. World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle, sunFixed, useEstateSun, (float)sunHour);
  930. }
  931. }
  932. /// <summary>
  933. /// Changes the Estate Sun Settings, then Triggers a Sun Update
  934. /// </summary>
  935. /// <param name="sunFixed">True to keep the sun stationary, false to use global time</param>
  936. /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
  937. public void osSetEstateSunSettings(bool sunFixed, double sunHour)
  938. {
  939. CheckThreatLevel(ThreatLevel.Nuisance, "osSetEstateSunSettings");
  940. m_host.AddScriptLPS(1);
  941. //Check to make sure that the script's owner is the estate manager/master
  942. //World.Permissions.GenericEstatePermission(
  943. if (World.Permissions.IsGod(m_host.OwnerID))
  944. {
  945. while (sunHour > 24.0)
  946. sunHour -= 24.0;
  947. while (sunHour < 0)
  948. sunHour += 24.0;
  949. World.RegionInfo.EstateSettings.UseGlobalTime = !sunFixed;
  950. World.RegionInfo.EstateSettings.SunPosition = sunHour;
  951. World.RegionInfo.EstateSettings.FixedSun = sunFixed;
  952. World.RegionInfo.EstateSettings.Save();
  953. World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle, sunFixed, World.RegionInfo.RegionSettings.UseEstateSun, (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. CheckThreatLevel(ThreatLevel.None, "osGetCurrentSunHour");
  963. m_host.AddScriptLPS(1);
  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 osSunGetParam(string param)
  975. {
  976. CheckThreatLevel(ThreatLevel.None, "osSunGetParam");
  977. m_host.AddScriptLPS(1);
  978. double value = 0.0;
  979. ISunModule module = World.RequestModuleInterface<ISunModule>();
  980. if (module != null)
  981. {
  982. value = module.GetSunParameter(param);
  983. }
  984. return value;
  985. }
  986. public void osSunSetParam(string param, double value)
  987. {
  988. CheckThreatLevel(ThreatLevel.None, "osSunSetParam");
  989. m_host.AddScriptLPS(1);
  990. ISunModule module = World.RequestModuleInterface<ISunModule>();
  991. if (module != null)
  992. {
  993. module.SetSunParameter(param, value);
  994. }
  995. }
  996. public string osWindActiveModelPluginName()
  997. {
  998. CheckThreatLevel(ThreatLevel.None, "osWindActiveModelPluginName");
  999. m_host.AddScriptLPS(1);
  1000. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1001. if (module != null)
  1002. {
  1003. return module.WindActiveModelPluginName;
  1004. }
  1005. return String.Empty;
  1006. }
  1007. public void osWindParamSet(string plugin, string param, float value)
  1008. {
  1009. CheckThreatLevel(ThreatLevel.VeryLow, "osWindParamSet");
  1010. m_host.AddScriptLPS(1);
  1011. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1012. if (module != null)
  1013. {
  1014. try
  1015. {
  1016. module.WindParamSet(plugin, param, value);
  1017. }
  1018. catch (Exception) { }
  1019. }
  1020. }
  1021. public float osWindParamGet(string plugin, string param)
  1022. {
  1023. CheckThreatLevel(ThreatLevel.VeryLow, "osWindParamGet");
  1024. m_host.AddScriptLPS(1);
  1025. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1026. if (module != null)
  1027. {
  1028. return module.WindParamGet(plugin, param);
  1029. }
  1030. return 0.0f;
  1031. }
  1032. // Routines for creating and managing parcels programmatically
  1033. public void osParcelJoin(LSL_Vector pos1, LSL_Vector pos2)
  1034. {
  1035. CheckThreatLevel(ThreatLevel.High, "osParcelJoin");
  1036. m_host.AddScriptLPS(1);
  1037. int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
  1038. int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
  1039. int endx = (int)(pos1.x > pos2.x ? pos1.x : pos2.x);
  1040. int endy = (int)(pos1.y > pos2.y ? pos1.y : pos2.y);
  1041. World.LandChannel.Join(startx,starty,endx,endy,m_host.OwnerID);
  1042. }
  1043. public void osParcelSubdivide(LSL_Vector pos1, LSL_Vector pos2)
  1044. {
  1045. CheckThreatLevel(ThreatLevel.High, "osParcelSubdivide");
  1046. m_host.AddScriptLPS(1);
  1047. int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
  1048. int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
  1049. int endx = (int)(pos1.x > pos2.x ? pos1.x : pos2.x);
  1050. int endy = (int)(pos1.y > pos2.y ? pos1.y : pos2.y);
  1051. World.LandChannel.Subdivide(startx,starty,endx,endy,m_host.OwnerID);
  1052. }
  1053. public void osParcelSetDetails(LSL_Vector pos, LSL_List rules)
  1054. {
  1055. CheckThreatLevel(ThreatLevel.High, "osParcelSetDetails");
  1056. m_host.AddScriptLPS(1);
  1057. // Get a reference to the land data and make sure the owner of the script
  1058. // can modify it
  1059. ILandObject startLandObject = World.LandChannel.GetLandObject((int)pos.x, (int)pos.y);
  1060. if (startLandObject == null)
  1061. {
  1062. OSSLShoutError("There is no land at that location");
  1063. return;
  1064. }
  1065. if (! World.Permissions.CanEditParcel(m_host.OwnerID, startLandObject))
  1066. {
  1067. OSSLShoutError("You do not have permission to modify the parcel");
  1068. return;
  1069. }
  1070. // Create a new land data object we can modify
  1071. LandData newLand = startLandObject.LandData.Copy();
  1072. UUID uuid;
  1073. // Process the rules, not sure what the impact would be of changing owner or group
  1074. for (int idx = 0; idx < rules.Length;)
  1075. {
  1076. int code = rules.GetLSLIntegerItem(idx++);
  1077. string arg = rules.GetLSLStringItem(idx++);
  1078. switch (code)
  1079. {
  1080. case 0:
  1081. newLand.Name = arg;
  1082. break;
  1083. case 1:
  1084. newLand.Description = arg;
  1085. break;
  1086. case 2:
  1087. CheckThreatLevel(ThreatLevel.VeryHigh, "osParcelSetDetails");
  1088. if (UUID.TryParse(arg , out uuid))
  1089. newLand.OwnerID = uuid;
  1090. break;
  1091. case 3:
  1092. CheckThreatLevel(ThreatLevel.VeryHigh, "osParcelSetDetails");
  1093. if (UUID.TryParse(arg , out uuid))
  1094. newLand.GroupID = uuid;
  1095. break;
  1096. }
  1097. }
  1098. World.LandChannel.UpdateLandObject(newLand.LocalID,newLand);
  1099. }
  1100. public double osList2Double(LSL_Types.list src, int index)
  1101. {
  1102. // There is really no double type in OSSL. C# and other
  1103. // have one, but the current implementation of LSL_Types.list
  1104. // is not allowed to contain any.
  1105. // This really should be removed.
  1106. //
  1107. CheckThreatLevel(ThreatLevel.None, "osList2Double");
  1108. m_host.AddScriptLPS(1);
  1109. if (index < 0)
  1110. {
  1111. index = src.Length + index;
  1112. }
  1113. if (index >= src.Length)
  1114. {
  1115. return 0.0;
  1116. }
  1117. return Convert.ToDouble(src.Data[index]);
  1118. }
  1119. public void osSetParcelMediaURL(string url)
  1120. {
  1121. // What actually is the difference to the LL function?
  1122. //
  1123. CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL");
  1124. m_host.AddScriptLPS(1);
  1125. ILandObject land
  1126. = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  1127. if (land.LandData.OwnerID != m_host.OwnerID)
  1128. return;
  1129. land.SetMediaUrl(url);
  1130. }
  1131. public void osSetParcelSIPAddress(string SIPAddress)
  1132. {
  1133. // What actually is the difference to the LL function?
  1134. //
  1135. CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL");
  1136. m_host.AddScriptLPS(1);
  1137. ILandObject land
  1138. = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  1139. if (land.LandData.OwnerID != m_host.OwnerID)
  1140. {
  1141. OSSLError("osSetParcelSIPAddress: Sorry, you need to own the land to use this function");
  1142. return;
  1143. }
  1144. // get the voice module
  1145. IVoiceModule voiceModule = World.RequestModuleInterface<IVoiceModule>();
  1146. if (voiceModule != null)
  1147. voiceModule.setLandSIPAddress(SIPAddress,land.LandData.GlobalID);
  1148. else
  1149. OSSLError("osSetParcelSIPAddress: No voice module enabled for this land");
  1150. }
  1151. public string osGetScriptEngineName()
  1152. {
  1153. // This gets a "high" because knowing the engine may be used
  1154. // to exploit engine-specific bugs or induce usage patterns
  1155. // that trigger engine-specific failures.
  1156. // Besides, public grid users aren't supposed to know.
  1157. //
  1158. CheckThreatLevel(ThreatLevel.High, "osGetScriptEngineName");
  1159. m_host.AddScriptLPS(1);
  1160. int scriptEngineNameIndex = 0;
  1161. if (!String.IsNullOrEmpty(m_ScriptEngine.ScriptEngineName))
  1162. {
  1163. // parse off the "ScriptEngine."
  1164. scriptEngineNameIndex = m_ScriptEngine.ScriptEngineName.IndexOf(".", scriptEngineNameIndex);
  1165. scriptEngineNameIndex++; // get past delimiter
  1166. int scriptEngineNameLength = m_ScriptEngine.ScriptEngineName.Length - scriptEngineNameIndex;
  1167. // create char array then a string that is only the script engine name
  1168. Char[] scriptEngineNameCharArray = m_ScriptEngine.ScriptEngineName.ToCharArray(scriptEngineNameIndex, scriptEngineNameLength);
  1169. String scriptEngineName = new String(scriptEngineNameCharArray);
  1170. return scriptEngineName;
  1171. }
  1172. else
  1173. {
  1174. return String.Empty;
  1175. }
  1176. }
  1177. public string osGetSimulatorVersion()
  1178. {
  1179. // High because it can be used to target attacks to known weaknesses
  1180. // This would allow a new class of griefer scripts that don't even
  1181. // require their user to know what they are doing (see script
  1182. // kiddie)
  1183. //
  1184. CheckThreatLevel(ThreatLevel.High,"osGetSimulatorVersion");
  1185. m_host.AddScriptLPS(1);
  1186. return m_ScriptEngine.World.GetSimulatorVersion();
  1187. }
  1188. public Hashtable osParseJSON(string JSON)
  1189. {
  1190. CheckThreatLevel(ThreatLevel.None, "osParseJSON");
  1191. m_host.AddScriptLPS(1);
  1192. // see http://www.json.org/ for more details on JSON
  1193. string currentKey = null;
  1194. Stack objectStack = new Stack(); // objects in JSON can be nested so we need to keep a track of this
  1195. Hashtable jsondata = new Hashtable(); // the hashtable to be returned
  1196. int i = 0;
  1197. try
  1198. {
  1199. // iterate through the serialised stream of tokens and store at the right depth in the hashtable
  1200. // the top level hashtable may contain more nested hashtables within it each containing an objects representation
  1201. for (i = 0; i < JSON.Length; i++)
  1202. {
  1203. // m_log.Debug(""+JSON[i]);
  1204. switch (JSON[i])
  1205. {
  1206. case '{':
  1207. // 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
  1208. Hashtable currentObject = new Hashtable();
  1209. if (objectStack.Count == 0) // the stack should only be empty for the first outer object
  1210. {
  1211. objectStack.Push(jsondata);
  1212. }
  1213. else if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1214. {
  1215. // add it to the parent array
  1216. ((ArrayList)objectStack.Peek()).Add(currentObject);
  1217. objectStack.Push(currentObject);
  1218. }
  1219. else
  1220. {
  1221. // add it to the parent hashtable
  1222. ((Hashtable)objectStack.Peek()).Add(currentKey,currentObject);
  1223. objectStack.Push(currentObject);
  1224. }
  1225. // clear the key
  1226. currentKey = null;
  1227. break;
  1228. case '}':
  1229. // pop the hashtable off the stack
  1230. objectStack.Pop();
  1231. break;
  1232. case '"':// string boundary
  1233. string tokenValue = "";
  1234. i++; // move to next char
  1235. // just loop through until the next quote mark storing the string, ignore quotes with pre-ceding \
  1236. while (JSON[i] != '"')
  1237. {
  1238. tokenValue += JSON[i];
  1239. // handle escaped double quotes \"
  1240. if (JSON[i] == '\\' && JSON[i+1] == '"')
  1241. {
  1242. tokenValue += JSON[i+1];
  1243. i++;
  1244. }
  1245. i++;
  1246. }
  1247. // ok we've got a string, if we've got an array on the top of the stack then we store it
  1248. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1249. {
  1250. ((ArrayList)objectStack.Peek()).Add(tokenValue);
  1251. }
  1252. else if (currentKey == null) // no key stored and its not an array this must be a key so store it
  1253. {
  1254. currentKey = tokenValue;
  1255. }
  1256. else
  1257. {
  1258. // we have a key so lets store this value
  1259. ((Hashtable)objectStack.Peek()).Add(currentKey,tokenValue);
  1260. // now lets clear the key, we're done with it and moving on
  1261. currentKey = null;
  1262. }
  1263. break;
  1264. case ':':// key : value separator
  1265. // just ignore
  1266. break;
  1267. case ' ':// spaces
  1268. // just ignore
  1269. break;
  1270. case '[': // array start
  1271. ArrayList currentArray = new ArrayList();
  1272. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1273. {
  1274. ((ArrayList)objectStack.Peek()).Add(currentArray);
  1275. }
  1276. else
  1277. {
  1278. ((Hashtable)objectStack.Peek()).Add(currentKey,currentArray);
  1279. // clear the key
  1280. currentKey = null;
  1281. }
  1282. objectStack.Push(currentArray);
  1283. break;
  1284. case ',':// seperator
  1285. // just ignore
  1286. break;
  1287. case ']'://Array end
  1288. // pop the array off the stack
  1289. objectStack.Pop();
  1290. break;
  1291. case 't': // we've found a character start not in quotes, it must be a boolean true
  1292. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1293. {
  1294. ((ArrayList)objectStack.Peek()).Add(true);
  1295. }
  1296. else
  1297. {
  1298. ((Hashtable)objectStack.Peek()).Add(currentKey,true);
  1299. currentKey = null;
  1300. }
  1301. //advance the counter to the letter 'e'
  1302. i = i + 3;
  1303. break;
  1304. case 'f': // we've found a character start not in quotes, it must be a boolean false
  1305. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1306. {
  1307. ((ArrayList)objectStack.Peek()).Add(false);
  1308. }
  1309. else
  1310. {
  1311. ((Hashtable)objectStack.Peek()).Add(currentKey,false);
  1312. currentKey = null;
  1313. }
  1314. //advance the counter to the letter 'e'
  1315. i = i + 4;
  1316. break;
  1317. case '\n':// carriage return
  1318. // just ignore
  1319. break;
  1320. case '\r':// carriage return
  1321. // just ignore
  1322. break;
  1323. default:
  1324. // ok here we're catching all numeric types int,double,long we might want to spit these up mr accurately
  1325. // but for now we'll just do them as strings
  1326. string numberValue = "";
  1327. // just loop through until the next known marker quote mark storing the string
  1328. while (JSON[i] != '"' && JSON[i] != ',' && JSON[i] != ']' && JSON[i] != '}' && JSON[i] != ' ')
  1329. {
  1330. numberValue += "" + JSON[i++];
  1331. }
  1332. i--; // we want to process this caracter that marked the end of this string in the main loop
  1333. // ok we've got a string, if we've got an array on the top of the stack then we store it
  1334. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1335. {
  1336. ((ArrayList)objectStack.Peek()).Add(numberValue);
  1337. }
  1338. else
  1339. {
  1340. // we have a key so lets store this value
  1341. ((Hashtable)objectStack.Peek()).Add(currentKey,numberValue);
  1342. // now lets clear the key, we're done with it and moving on
  1343. currentKey = null;
  1344. }
  1345. break;
  1346. }
  1347. }
  1348. }
  1349. catch(Exception)
  1350. {
  1351. OSSLError("osParseJSON: The JSON string is not valid " + JSON) ;
  1352. }
  1353. return jsondata;
  1354. }
  1355. // send a message to to object identified by the given UUID, a script in the object must implement the dataserver function
  1356. // the dataserver function is passed the ID of the calling function and a string message
  1357. public void osMessageObject(LSL_Key objectUUID, string message)
  1358. {
  1359. CheckThreatLevel(ThreatLevel.Low, "osMessageObject");
  1360. m_host.AddScriptLPS(1);
  1361. object[] resobj = new object[] { new LSL_Types.LSLString(m_host.UUID.ToString()), new LSL_Types.LSLString(message) };
  1362. SceneObjectPart sceneOP = World.GetSceneObjectPart(new UUID(objectUUID));
  1363. m_ScriptEngine.PostObjectEvent(
  1364. sceneOP.LocalId, new EventParams(
  1365. "dataserver", resobj, new DetectParams[0]));
  1366. }
  1367. // This needs ThreatLevel high. It is an excellent griefer tool,
  1368. // In a loop, it can cause asset bloat and DOS levels of asset
  1369. // writes.
  1370. //
  1371. public void osMakeNotecard(string notecardName, LSL_Types.list contents)
  1372. {
  1373. CheckThreatLevel(ThreatLevel.High, "osMakeNotecard");
  1374. m_host.AddScriptLPS(1);
  1375. // Create new asset
  1376. AssetBase asset = new AssetBase(UUID.Random(), notecardName, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString());
  1377. asset.Description = "Script Generated Notecard";
  1378. string notecardData = String.Empty;
  1379. for (int i = 0; i < contents.Length; i++) {
  1380. notecardData += contents.GetLSLStringItem(i) + "\n";
  1381. }
  1382. int textLength = notecardData.Length;
  1383. notecardData = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length "
  1384. + textLength.ToString() + "\n" + notecardData + "}\n";
  1385. asset.Data = Util.UTF8.GetBytes(notecardData);
  1386. World.AssetService.Store(asset);
  1387. // Create Task Entry
  1388. TaskInventoryItem taskItem=new TaskInventoryItem();
  1389. taskItem.ResetIDs(m_host.UUID);
  1390. taskItem.ParentID = m_host.UUID;
  1391. taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch();
  1392. taskItem.Name = asset.Name;
  1393. taskItem.Description = asset.Description;
  1394. taskItem.Type = (int)AssetType.Notecard;
  1395. taskItem.InvType = (int)InventoryType.Notecard;
  1396. taskItem.OwnerID = m_host.OwnerID;
  1397. taskItem.CreatorID = m_host.OwnerID;
  1398. taskItem.BasePermissions = (uint)PermissionMask.All;
  1399. taskItem.CurrentPermissions = (uint)PermissionMask.All;
  1400. taskItem.EveryonePermissions = 0;
  1401. taskItem.NextPermissions = (uint)PermissionMask.All;
  1402. taskItem.GroupID = m_host.GroupID;
  1403. taskItem.GroupPermissions = 0;
  1404. taskItem.Flags = 0;
  1405. taskItem.PermsGranter = UUID.Zero;
  1406. taskItem.PermsMask = 0;
  1407. taskItem.AssetID = asset.FullID;
  1408. m_host.Inventory.AddInventoryItem(taskItem, false);
  1409. }
  1410. /*Instead of using the LSL Dataserver event to pull notecard data,
  1411. this will simply read the requested line and return its data as a string.
  1412. Warning - due to the synchronous method this function uses to fetch assets, its use
  1413. may be dangerous and unreliable while running in grid mode.
  1414. */
  1415. public string osGetNotecardLine(string name, int line)
  1416. {
  1417. CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine");
  1418. m_host.AddScriptLPS(1);
  1419. UUID assetID = UUID.Zero;
  1420. if (!UUID.TryParse(name, out assetID))
  1421. {
  1422. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  1423. {
  1424. if (item.Type == 7 && item.Name == name)
  1425. {
  1426. assetID = item.AssetID;
  1427. }
  1428. }
  1429. }
  1430. if (assetID == UUID.Zero)
  1431. {
  1432. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1433. return "ERROR!";
  1434. }
  1435. if (!NotecardCache.IsCached(assetID))
  1436. {
  1437. AssetBase a = World.AssetService.Get(assetID.ToString());
  1438. if (a != null)
  1439. {
  1440. System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
  1441. string data = enc.GetString(a.Data);
  1442. NotecardCache.Cache(assetID, data);
  1443. }
  1444. else
  1445. {
  1446. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1447. return "ERROR!";
  1448. }
  1449. };
  1450. return NotecardCache.GetLine(assetID, line, 255);
  1451. }
  1452. /*Instead of using the LSL Dataserver event to pull notecard data line by line,
  1453. this will simply read the entire notecard and return its data as a string.
  1454. Warning - due to the synchronous method this function uses to fetch assets, its use
  1455. may be dangerous and unreliable while running in grid mode.
  1456. */
  1457. public string osGetNotecard(string name)
  1458. {
  1459. CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard");
  1460. m_host.AddScriptLPS(1);
  1461. UUID assetID = UUID.Zero;
  1462. string NotecardData = "";
  1463. if (!UUID.TryParse(name, out assetID))
  1464. {
  1465. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  1466. {
  1467. if (item.Type == 7 && item.Name == name)
  1468. {
  1469. assetID = item.AssetID;
  1470. }
  1471. }
  1472. }
  1473. if (assetID == UUID.Zero)
  1474. {
  1475. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1476. return "ERROR!";
  1477. }
  1478. if (!NotecardCache.IsCached(assetID))
  1479. {
  1480. AssetBase a = World.AssetService.Get(assetID.ToString());
  1481. if (a != null)
  1482. {
  1483. System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
  1484. string data = enc.GetString(a.Data);
  1485. NotecardCache.Cache(assetID, data);
  1486. }
  1487. else
  1488. {
  1489. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1490. return "ERROR!";
  1491. }
  1492. };
  1493. for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
  1494. {
  1495. NotecardData += NotecardCache.GetLine(assetID, count, 255) + "\n";
  1496. }
  1497. return NotecardData;
  1498. }
  1499. /*Instead of using the LSL Dataserver event to pull notecard data,
  1500. this will simply read the number of note card lines and return this data as an integer.
  1501. Warning - due to the synchronous method this function uses to fetch assets, its use
  1502. may be dangerous and unreliable while running in grid mode.
  1503. */
  1504. public int osGetNumberOfNotecardLines(string name)
  1505. {
  1506. CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines");
  1507. m_host.AddScriptLPS(1);
  1508. UUID assetID = UUID.Zero;
  1509. if (!UUID.TryParse(name, out assetID))
  1510. {
  1511. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  1512. {
  1513. if (item.Type == 7 && item.Name == name)
  1514. {
  1515. assetID = item.AssetID;
  1516. }
  1517. }
  1518. }
  1519. if (assetID == UUID.Zero)
  1520. {
  1521. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1522. return -1;
  1523. }
  1524. if (!NotecardCache.IsCached(assetID))
  1525. {
  1526. AssetBase a = World.AssetService.Get(assetID.ToString());
  1527. if (a != null)
  1528. {
  1529. System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
  1530. string data = enc.GetString(a.Data);
  1531. NotecardCache.Cache(assetID, data);
  1532. }
  1533. else
  1534. {
  1535. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1536. return -1;
  1537. }
  1538. };
  1539. return NotecardCache.GetLines(assetID);
  1540. }
  1541. public string osAvatarName2Key(string firstname, string lastname)
  1542. {
  1543. CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key");
  1544. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, firstname, lastname);
  1545. if (null == account)
  1546. {
  1547. return UUID.Zero.ToString();
  1548. }
  1549. else
  1550. {
  1551. return account.PrincipalID.ToString();
  1552. }
  1553. }
  1554. public string osKey2Name(string id)
  1555. {
  1556. CheckThreatLevel(ThreatLevel.Low, "osKey2Name");
  1557. UUID key = new UUID();
  1558. if (UUID.TryParse(id, out key))
  1559. {
  1560. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, key);
  1561. if (null == account)
  1562. {
  1563. return "";
  1564. }
  1565. else
  1566. {
  1567. return account.Name;
  1568. }
  1569. }
  1570. else
  1571. {
  1572. return "";
  1573. }
  1574. }
  1575. /// Threat level is Moderate because intentional abuse, for instance
  1576. /// scripts that are written to be malicious only on one grid,
  1577. /// for instance in a HG scenario, are a distinct possibility.
  1578. ///
  1579. /// Use value from the config file and return it.
  1580. ///
  1581. public string osGetGridNick()
  1582. {
  1583. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridNick");
  1584. m_host.AddScriptLPS(1);
  1585. string nick = "hippogrid";
  1586. IConfigSource config = m_ScriptEngine.ConfigSource;
  1587. if (config.Configs["GridInfo"] != null)
  1588. nick = config.Configs["GridInfo"].GetString("gridnick", nick);
  1589. return nick;
  1590. }
  1591. public string osGetGridName()
  1592. {
  1593. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridName");
  1594. m_host.AddScriptLPS(1);
  1595. string name = "the lost continent of hippo";
  1596. IConfigSource config = m_ScriptEngine.ConfigSource;
  1597. if (config.Configs["GridInfo"] != null)
  1598. name = config.Configs["GridInfo"].GetString("gridname", name);
  1599. return name;
  1600. }
  1601. public string osGetGridLoginURI()
  1602. {
  1603. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridLoginURI");
  1604. m_host.AddScriptLPS(1);
  1605. string loginURI = "http://127.0.0.1:9000/";
  1606. IConfigSource config = m_ScriptEngine.ConfigSource;
  1607. if (config.Configs["GridInfo"] != null)
  1608. loginURI = config.Configs["GridInfo"].GetString("login", loginURI);
  1609. return loginURI;
  1610. }
  1611. public LSL_String osFormatString(string str, LSL_List strings)
  1612. {
  1613. CheckThreatLevel(ThreatLevel.Low, "osFormatString");
  1614. m_host.AddScriptLPS(1);
  1615. return String.Format(str, strings.Data);
  1616. }
  1617. public LSL_List osMatchString(string src, string pattern, int start)
  1618. {
  1619. CheckThreatLevel(ThreatLevel.High, "osMatchString");
  1620. m_host.AddScriptLPS(1);
  1621. LSL_List result = new LSL_List();
  1622. // Normalize indices (if negative).
  1623. // After normlaization they may still be
  1624. // negative, but that is now relative to
  1625. // the start, rather than the end, of the
  1626. // sequence.
  1627. if (start < 0)
  1628. {
  1629. start = src.Length + start;
  1630. }
  1631. if (start < 0 || start >= src.Length)
  1632. {
  1633. return result; // empty list
  1634. }
  1635. // Find matches beginning at start position
  1636. Regex matcher = new Regex(pattern);
  1637. Match match = matcher.Match(src, start);
  1638. if (match.Success)
  1639. {
  1640. foreach (System.Text.RegularExpressions.Group g in match.Groups)
  1641. {
  1642. if (g.Success)
  1643. {
  1644. result.Add(g.Value);
  1645. result.Add(g.Index);
  1646. }
  1647. }
  1648. }
  1649. return result;
  1650. }
  1651. public string osLoadedCreationDate()
  1652. {
  1653. CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationDate");
  1654. m_host.AddScriptLPS(1);
  1655. return World.RegionInfo.RegionSettings.LoadedCreationDate;
  1656. }
  1657. public string osLoadedCreationTime()
  1658. {
  1659. CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationTime");
  1660. m_host.AddScriptLPS(1);
  1661. return World.RegionInfo.RegionSettings.LoadedCreationTime;
  1662. }
  1663. public string osLoadedCreationID()
  1664. {
  1665. CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationID");
  1666. m_host.AddScriptLPS(1);
  1667. return World.RegionInfo.RegionSettings.LoadedCreationID;
  1668. }
  1669. // Threat level is 'Low' because certain users could possibly be tricked into
  1670. // dropping an unverified script into one of their own objects, which could
  1671. // then gather the physical construction details of the object and transmit it
  1672. // to an unscrupulous third party, thus permitting unauthorized duplication of
  1673. // the object's form.
  1674. //
  1675. public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules)
  1676. {
  1677. CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams");
  1678. m_host.AddScriptLPS(1);
  1679. InitLSL();
  1680. LSL_List retVal = new LSL_List();
  1681. List<SceneObjectPart> parts = ((LSL_Api)m_LSL_Api).GetLinkParts(linknumber);
  1682. foreach (SceneObjectPart part in parts)
  1683. {
  1684. retVal += ((LSL_Api)m_LSL_Api).GetLinkPrimitiveParams(part, rules);
  1685. }
  1686. return retVal;
  1687. }
  1688. public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, LSL_Key cloneFrom)
  1689. {
  1690. CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
  1691. //QueueUserWorkItem
  1692. INPCModule module = World.RequestModuleInterface<INPCModule>();
  1693. if (module != null)
  1694. {
  1695. UUID x = module.CreateNPC(firstname,
  1696. lastname,
  1697. new Vector3((float) position.x, (float) position.y, (float) position.z),
  1698. World,
  1699. new UUID(cloneFrom));
  1700. return new LSL_Key(x.ToString());
  1701. }
  1702. return new LSL_Key(UUID.Zero.ToString());
  1703. }
  1704. public void osNpcMoveTo(LSL_Key npc, LSL_Vector position)
  1705. {
  1706. CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo");
  1707. INPCModule module = World.RequestModuleInterface<INPCModule>();
  1708. if (module != null)
  1709. {
  1710. Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z);
  1711. module.Autopilot(new UUID(npc.m_string), World, pos);
  1712. }
  1713. }
  1714. public void osNpcSay(LSL_Key npc, string message)
  1715. {
  1716. CheckThreatLevel(ThreatLevel.High, "osNpcSay");
  1717. INPCModule module = World.RequestModuleInterface<INPCModule>();
  1718. if (module != null)
  1719. {
  1720. module.Say(new UUID(npc.m_string), World, message);
  1721. }
  1722. }
  1723. public void osNpcRemove(LSL_Key npc)
  1724. {
  1725. CheckThreatLevel(ThreatLevel.High, "osNpcRemove");
  1726. INPCModule module = World.RequestModuleInterface<INPCModule>();
  1727. if (module != null)
  1728. {
  1729. module.DeleteNPC(new UUID(npc.m_string), World);
  1730. }
  1731. }
  1732. /// <summary>
  1733. /// Get current region's map texture UUID
  1734. /// </summary>
  1735. /// <returns></returns>
  1736. public LSL_Key osGetMapTexture()
  1737. {
  1738. CheckThreatLevel(ThreatLevel.None, "osGetMapTexture");
  1739. return m_ScriptEngine.World.RegionInfo.RegionSettings.TerrainImageID.ToString();
  1740. }
  1741. /// <summary>
  1742. /// Get a region's map texture UUID by region UUID or name.
  1743. /// </summary>
  1744. /// <param name="regionName"></param>
  1745. /// <returns></returns>
  1746. public LSL_Key osGetRegionMapTexture(string regionName)
  1747. {
  1748. CheckThreatLevel(ThreatLevel.High, "osGetRegionMapTexture");
  1749. Scene scene = m_ScriptEngine.World;
  1750. UUID key = UUID.Zero;
  1751. GridRegion region;
  1752. //If string is a key, use it. Otherwise, try to locate region by name.
  1753. if (UUID.TryParse(regionName, out key))
  1754. region = scene.GridService.GetRegionByUUID(UUID.Zero, key);
  1755. else
  1756. region = scene.GridService.GetRegionByName(UUID.Zero, regionName);
  1757. // If region was found, return the regions map texture key.
  1758. if (region != null)
  1759. key = region.TerrainImage;
  1760. ScriptSleep(1000);
  1761. return key.ToString();
  1762. }
  1763. /// <summary>
  1764. /// Return information regarding various simulator statistics (sim fps, physics fps, time
  1765. /// dilation, total number of prims, total number of active scripts, script lps, various
  1766. /// timing data, packets in/out, etc. Basically much the information that's shown in the
  1767. /// client's Statistics Bar (Ctrl-Shift-1)
  1768. /// </summary>
  1769. /// <returns>List of floats</returns>
  1770. public LSL_List osGetRegionStats()
  1771. {
  1772. CheckThreatLevel(ThreatLevel.Moderate, "osGetRegionStats");
  1773. m_host.AddScriptLPS(1);
  1774. LSL_List ret = new LSL_List();
  1775. float[] stats = World.SimulatorStats;
  1776. for (int i = 0; i < 21; i++)
  1777. {
  1778. ret.Add(new LSL_Float(stats[i]));
  1779. }
  1780. return ret;
  1781. }
  1782. public int osGetSimulatorMemory()
  1783. {
  1784. CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemory");
  1785. m_host.AddScriptLPS(1);
  1786. long pws = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64;
  1787. if (pws > Int32.MaxValue)
  1788. return Int32.MaxValue;
  1789. if (pws < 0)
  1790. return 0;
  1791. return (int)pws;
  1792. }
  1793. public void osSetSpeed(string UUID, float SpeedModifier)
  1794. {
  1795. CheckThreatLevel(ThreatLevel.Moderate, "osSetSpeed");
  1796. m_host.AddScriptLPS(1);
  1797. ScenePresence avatar = World.GetScenePresence(new UUID(UUID));
  1798. avatar.SpeedModifier = SpeedModifier;
  1799. }
  1800. public void osKickAvatar(string FirstName,string SurName,string alert)
  1801. {
  1802. CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
  1803. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  1804. {
  1805. World.ForEachScenePresence(delegate(ScenePresence sp)
  1806. {
  1807. if (!sp.IsChildAgent &&
  1808. sp.Firstname == FirstName &&
  1809. sp.Lastname == SurName)
  1810. {
  1811. // kick client...
  1812. if (alert != null)
  1813. sp.ControllingClient.Kick(alert);
  1814. // ...and close on our side
  1815. sp.Scene.IncomingCloseAgent(sp.UUID);
  1816. }
  1817. });
  1818. }
  1819. }
  1820. public void osCauseDamage(string avatar, double damage)
  1821. {
  1822. CheckThreatLevel(ThreatLevel.High, "osCauseDamage");
  1823. m_host.AddScriptLPS(1);
  1824. UUID avatarId = new UUID(avatar);
  1825. Vector3 pos = m_host.GetWorldPosition();
  1826. ScenePresence presence = World.GetScenePresence(avatarId);
  1827. if (presence != null)
  1828. {
  1829. LandData land = World.GetLandData((float)pos.X, (float)pos.Y);
  1830. if ((land.Flags & (uint)ParcelFlags.AllowDamage) == (uint)ParcelFlags.AllowDamage)
  1831. {
  1832. float health = presence.Health;
  1833. health -= (float)damage;
  1834. presence.setHealthWithUpdate(health);
  1835. if (health <= 0)
  1836. {
  1837. float healthliveagain = 100;
  1838. presence.ControllingClient.SendAgentAlertMessage("You died!", true);
  1839. presence.setHealthWithUpdate(healthliveagain);
  1840. presence.Scene.TeleportClientHome(presence.UUID, presence.ControllingClient);
  1841. }
  1842. }
  1843. }
  1844. }
  1845. public void osCauseHealing(string avatar, double healing)
  1846. {
  1847. CheckThreatLevel(ThreatLevel.High, "osCauseHealing");
  1848. m_host.AddScriptLPS(1);
  1849. UUID avatarId = new UUID(avatar);
  1850. ScenePresence presence = World.GetScenePresence(avatarId);
  1851. Vector3 pos = m_host.GetWorldPosition();
  1852. bool result = World.ScriptDanger(m_host.LocalId, new Vector3((float)pos.X, (float)pos.Y, (float)pos.Z));
  1853. if (result)
  1854. {
  1855. if (presence != null)
  1856. {
  1857. float health = presence.Health;
  1858. health += (float)healing;
  1859. if (health >= 100)
  1860. {
  1861. health = 100;
  1862. }
  1863. presence.setHealthWithUpdate(health);
  1864. }
  1865. }
  1866. }
  1867. public LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules)
  1868. {
  1869. CheckThreatLevel(ThreatLevel.High, "osGetPrimitiveParams");
  1870. m_host.AddScriptLPS(1);
  1871. return m_LSL_Api.GetLinkPrimitiveParamsEx(prim, rules);
  1872. }
  1873. public void osSetPrimitiveParams(LSL_Key prim, LSL_List rules)
  1874. {
  1875. CheckThreatLevel(ThreatLevel.High, "osGetPrimitiveParams");
  1876. m_host.AddScriptLPS(1);
  1877. m_LSL_Api.SetPrimitiveParamsEx(prim, rules);
  1878. }
  1879. /// <summary>
  1880. /// Set parameters for light projection in host prim
  1881. /// </summary>
  1882. public void osSetProjectionParams(bool projection, LSL_Key texture, double fov, double focus, double amb)
  1883. {
  1884. CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams");
  1885. osSetProjectionParams(UUID.Zero.ToString(), projection, texture, fov, focus, amb);
  1886. }
  1887. /// <summary>
  1888. /// Set parameters for light projection with uuid of target prim
  1889. /// </summary>
  1890. public void osSetProjectionParams(LSL_Key prim, bool projection, LSL_Key texture, double fov, double focus, double amb)
  1891. {
  1892. CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams");
  1893. m_host.AddScriptLPS(1);
  1894. SceneObjectPart obj = null;
  1895. if (prim == UUID.Zero.ToString())
  1896. {
  1897. obj = m_host;
  1898. }
  1899. else
  1900. {
  1901. obj = World.GetSceneObjectPart(new UUID(prim));
  1902. if (obj == null)
  1903. return;
  1904. }
  1905. obj.Shape.ProjectionEntry = projection;
  1906. obj.Shape.ProjectionTextureUUID = new UUID(texture);
  1907. obj.Shape.ProjectionFOV = (float)fov;
  1908. obj.Shape.ProjectionFocus = (float)focus;
  1909. obj.Shape.ProjectionAmbiance = (float)amb;
  1910. obj.ParentGroup.HasGroupChanged = true;
  1911. obj.ScheduleFullUpdate();
  1912. }
  1913. /// <summary>
  1914. /// Like osGetAgents but returns enough info for a radar
  1915. /// </summary>
  1916. /// <returns>Strided list of the UUID, position and name of each avatar in the region</returns>
  1917. public LSL_List osGetAvatarList()
  1918. {
  1919. CheckThreatLevel(ThreatLevel.None, "osGetAvatarList");
  1920. LSL_List result = new LSL_List();
  1921. World.ForEachScenePresence(delegate (ScenePresence avatar)
  1922. {
  1923. if (avatar != null && avatar.UUID != m_host.OwnerID)
  1924. {
  1925. if (avatar.IsChildAgent == false)
  1926. {
  1927. result.Add(avatar.UUID);
  1928. result.Add(avatar.AbsolutePosition);
  1929. result.Add(avatar.Name);
  1930. }
  1931. }
  1932. });
  1933. return result;
  1934. }
  1935. }
  1936. }