PageRenderTime 43ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/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

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

  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. 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 …

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