OSSL_Api.cs 78 KB

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