OSSL_Api.cs 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230
  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. World.Heightmap[x, y] = val;
  326. return 1;
  327. }
  328. else
  329. {
  330. return 0;
  331. }
  332. }
  333. public LSL_Float osTerrainGetHeight(int x, int y)
  334. {
  335. CheckThreatLevel(ThreatLevel.None, "osTerrainGetHeight");
  336. m_host.AddScriptLPS(1);
  337. if (x > ((int)Constants.RegionSize - 1) || x < 0 || y > ((int)Constants.RegionSize - 1) || y < 0)
  338. OSSLError("osTerrainGetHeight: Coordinate out of bounds");
  339. return World.Heightmap[x, y];
  340. }
  341. public void osTerrainFlush()
  342. {
  343. CheckThreatLevel(ThreatLevel.VeryLow, "osTerrainFlush");
  344. ITerrainModule terrainModule = World.RequestModuleInterface<ITerrainModule>();
  345. if (terrainModule != null) terrainModule.TaintTerrain();
  346. }
  347. public int osRegionRestart(double seconds)
  348. {
  349. // This is High here because region restart is not reliable
  350. // it may result in the region staying down or becoming
  351. // unstable. This should be changed to Low or VeryLow once
  352. // The underlying functionality is fixed, since the security
  353. // as such is sound
  354. //
  355. CheckThreatLevel(ThreatLevel.High, "osRegionRestart");
  356. m_host.AddScriptLPS(1);
  357. if (World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false))
  358. {
  359. World.Restart((float)seconds);
  360. return 1;
  361. }
  362. else
  363. {
  364. return 0;
  365. }
  366. }
  367. public void osRegionNotice(string msg)
  368. {
  369. // This implementation provides absolutely no security
  370. // It's high griefing potential makes this classification
  371. // necessary
  372. //
  373. CheckThreatLevel(ThreatLevel.VeryHigh, "osRegionNotice");
  374. m_host.AddScriptLPS(1);
  375. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  376. if (dm != null)
  377. dm.SendGeneralAlert(msg);
  378. }
  379. public void osSetRot(UUID target, Quaternion rotation)
  380. {
  381. // This function has no security. It can be used to destroy
  382. // arbitrary builds the user would normally have no rights to
  383. //
  384. CheckThreatLevel(ThreatLevel.VeryHigh, "osSetRot");
  385. m_host.AddScriptLPS(1);
  386. if (World.Entities.ContainsKey(target))
  387. {
  388. EntityBase entity;
  389. if (World.Entities.TryGetValue(target, out entity))
  390. {
  391. if (entity is SceneObjectGroup)
  392. ((SceneObjectGroup)entity).Rotation = rotation;
  393. else if (entity is ScenePresence)
  394. ((ScenePresence)entity).Rotation = rotation;
  395. }
  396. }
  397. else
  398. {
  399. OSSLError("osSetRot: Invalid target");
  400. }
  401. }
  402. public string osSetDynamicTextureURL(string dynamicID, string contentType, string url, string extraParams,
  403. int timer)
  404. {
  405. // This may be upgraded depending on the griefing or DOS
  406. // potential, or guarded with a delay
  407. //
  408. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURL");
  409. m_host.AddScriptLPS(1);
  410. if (dynamicID == String.Empty)
  411. {
  412. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  413. UUID createdTexture =
  414. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  415. extraParams, timer);
  416. return createdTexture.ToString();
  417. }
  418. else
  419. {
  420. //TODO update existing dynamic textures
  421. }
  422. return UUID.Zero.ToString();
  423. }
  424. public string osSetDynamicTextureURLBlend(string dynamicID, string contentType, string url, string extraParams,
  425. int timer, int alpha)
  426. {
  427. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURLBlend");
  428. m_host.AddScriptLPS(1);
  429. if (dynamicID == String.Empty)
  430. {
  431. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  432. UUID createdTexture =
  433. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  434. extraParams, timer, true, (byte) alpha);
  435. return createdTexture.ToString();
  436. }
  437. else
  438. {
  439. //TODO update existing dynamic textures
  440. }
  441. return UUID.Zero.ToString();
  442. }
  443. public string osSetDynamicTextureURLBlendFace(string dynamicID, string contentType, string url, string extraParams,
  444. bool blend, int disp, int timer, int alpha, int face)
  445. {
  446. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURLBlendFace");
  447. m_host.AddScriptLPS(1);
  448. if (dynamicID == String.Empty)
  449. {
  450. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  451. UUID createdTexture =
  452. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  453. extraParams, timer, blend, disp, (byte) alpha, face);
  454. return createdTexture.ToString();
  455. }
  456. else
  457. {
  458. //TODO update existing dynamic textures
  459. }
  460. return UUID.Zero.ToString();
  461. }
  462. public string osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams,
  463. int timer)
  464. {
  465. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureData");
  466. m_host.AddScriptLPS(1);
  467. if (dynamicID == String.Empty)
  468. {
  469. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  470. if (textureManager != null)
  471. {
  472. if (extraParams == String.Empty)
  473. {
  474. extraParams = "256";
  475. }
  476. UUID createdTexture =
  477. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  478. extraParams, timer);
  479. return createdTexture.ToString();
  480. }
  481. }
  482. else
  483. {
  484. //TODO update existing dynamic textures
  485. }
  486. return UUID.Zero.ToString();
  487. }
  488. public string osSetDynamicTextureDataBlend(string dynamicID, string contentType, string data, string extraParams,
  489. int timer, int alpha)
  490. {
  491. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureDataBlend");
  492. m_host.AddScriptLPS(1);
  493. if (dynamicID == String.Empty)
  494. {
  495. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  496. if (textureManager != null)
  497. {
  498. if (extraParams == String.Empty)
  499. {
  500. extraParams = "256";
  501. }
  502. UUID createdTexture =
  503. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  504. extraParams, timer, true, (byte) alpha);
  505. return createdTexture.ToString();
  506. }
  507. }
  508. else
  509. {
  510. //TODO update existing dynamic textures
  511. }
  512. return UUID.Zero.ToString();
  513. }
  514. public string osSetDynamicTextureDataBlendFace(string dynamicID, string contentType, string data, string extraParams,
  515. bool blend, int disp, int timer, int alpha, int face)
  516. {
  517. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureDataBlendFace");
  518. m_host.AddScriptLPS(1);
  519. if (dynamicID == String.Empty)
  520. {
  521. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  522. if (textureManager != null)
  523. {
  524. if (extraParams == String.Empty)
  525. {
  526. extraParams = "256";
  527. }
  528. UUID createdTexture =
  529. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  530. extraParams, timer, blend, disp, (byte) alpha, face);
  531. return createdTexture.ToString();
  532. }
  533. }
  534. else
  535. {
  536. //TODO update existing dynamic textures
  537. }
  538. return UUID.Zero.ToString();
  539. }
  540. public bool osConsoleCommand(string command)
  541. {
  542. CheckThreatLevel(ThreatLevel.Severe, "osConsoleCommand");
  543. m_host.AddScriptLPS(1);
  544. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  545. {
  546. MainConsole.Instance.RunCommand(command);
  547. return true;
  548. }
  549. return false;
  550. }
  551. public void osSetPrimFloatOnWater(int floatYN)
  552. {
  553. CheckThreatLevel(ThreatLevel.VeryLow, "osSetPrimFloatOnWater");
  554. m_host.AddScriptLPS(1);
  555. if (m_host.ParentGroup != null)
  556. {
  557. if (m_host.ParentGroup.RootPart != null)
  558. {
  559. m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN);
  560. }
  561. }
  562. }
  563. // Teleport functions
  564. public void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  565. {
  566. // High because there is no security check. High griefer potential
  567. //
  568. CheckThreatLevel(ThreatLevel.High, "osTeleportAgent");
  569. m_host.AddScriptLPS(1);
  570. UUID agentId = new UUID();
  571. if (UUID.TryParse(agent, out agentId))
  572. {
  573. ScenePresence presence = World.GetScenePresence(agentId);
  574. if (presence != null)
  575. {
  576. // agent must be over owners land to avoid abuse
  577. if (m_host.OwnerID
  578. == World.LandChannel.GetLandObject(
  579. presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
  580. {
  581. // Check for hostname , attempt to make a hglink
  582. // and convert the regionName to the target region
  583. if (regionName.Contains(".") && regionName.Contains(":"))
  584. {
  585. List<GridRegion> regions = World.GridService.GetRegionsByName(World.RegionInfo.ScopeID, regionName, 1);
  586. // Try to link the region
  587. if (regions != null && regions.Count > 0)
  588. {
  589. GridRegion regInfo = regions[0];
  590. regionName = regInfo.RegionName;
  591. }
  592. }
  593. presence.ControllingClient.SendTeleportLocationStart();
  594. World.RequestTeleportLocation(presence.ControllingClient, regionName,
  595. new Vector3((float)position.x, (float)position.y, (float)position.z),
  596. new Vector3((float)lookat.x, (float)lookat.y, (float)lookat.z), (uint)TPFlags.ViaLocation);
  597. ScriptSleep(5000);
  598. }
  599. }
  600. }
  601. }
  602. // Teleport functions
  603. public void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  604. {
  605. // High because there is no security check. High griefer potential
  606. //
  607. CheckThreatLevel(ThreatLevel.High, "osTeleportAgent");
  608. ulong regionHandle = Util.UIntsToLong(((uint)regionX * (uint)Constants.RegionSize), ((uint)regionY * (uint)Constants.RegionSize));
  609. m_host.AddScriptLPS(1);
  610. UUID agentId = new UUID();
  611. if (UUID.TryParse(agent, out agentId))
  612. {
  613. ScenePresence presence = World.GetScenePresence(agentId);
  614. if (presence != null)
  615. {
  616. // agent must be over owners land to avoid abuse
  617. if (m_host.OwnerID
  618. == World.LandChannel.GetLandObject(
  619. presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
  620. {
  621. presence.ControllingClient.SendTeleportLocationStart();
  622. World.RequestTeleportLocation(presence.ControllingClient, regionHandle,
  623. new Vector3((float)position.x, (float)position.y, (float)position.z),
  624. new Vector3((float)lookat.x, (float)lookat.y, (float)lookat.z), (uint)TPFlags.ViaLocation);
  625. ScriptSleep(5000);
  626. }
  627. }
  628. }
  629. }
  630. public void osTeleportAgent(string agent, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  631. {
  632. osTeleportAgent(agent, World.RegionInfo.RegionName, position, lookat);
  633. }
  634. // Functions that get information from the agent itself.
  635. //
  636. // osGetAgentIP - this is used to determine the IP address of
  637. //the client. This is needed to help configure other in world
  638. //resources based on the IP address of the clients connected.
  639. //I think High is a good risk level for this, as it is an
  640. //information leak.
  641. public string osGetAgentIP(string agent)
  642. {
  643. CheckThreatLevel(ThreatLevel.High, "osGetAgentIP");
  644. UUID avatarID = (UUID)agent;
  645. m_host.AddScriptLPS(1);
  646. if (World.Entities.ContainsKey((UUID)agent) && World.Entities[avatarID] is ScenePresence)
  647. {
  648. ScenePresence target = (ScenePresence)World.Entities[avatarID];
  649. EndPoint ep = target.ControllingClient.GetClientEP();
  650. if (ep is IPEndPoint)
  651. {
  652. IPEndPoint ip = (IPEndPoint)ep;
  653. return ip.Address.ToString();
  654. }
  655. }
  656. // fall through case, just return nothing
  657. return "";
  658. }
  659. // Get a list of all the avatars/agents in the region
  660. public LSL_List osGetAgents()
  661. {
  662. // threat level is None as we could get this information with an
  663. // in-world script as well, just not as efficient
  664. CheckThreatLevel(ThreatLevel.None, "osGetAgents");
  665. LSL_List result = new LSL_List();
  666. World.ForEachScenePresence(delegate(ScenePresence sp)
  667. {
  668. if (!sp.IsChildAgent)
  669. result.Add(sp.Name);
  670. });
  671. return result;
  672. }
  673. // Adam's super super custom animation functions
  674. public void osAvatarPlayAnimation(string avatar, string animation)
  675. {
  676. CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarPlayAnimation");
  677. UUID avatarID = (UUID)avatar;
  678. m_host.AddScriptLPS(1);
  679. if (World.Entities.ContainsKey((UUID)avatar) && World.Entities[avatarID] is ScenePresence)
  680. {
  681. ScenePresence target = (ScenePresence)World.Entities[avatarID];
  682. if (target != null)
  683. {
  684. UUID animID=UUID.Zero;
  685. lock (m_host.TaskInventory)
  686. {
  687. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  688. {
  689. if (inv.Value.Name == animation)
  690. {
  691. if (inv.Value.Type == (int)AssetType.Animation)
  692. animID = inv.Value.AssetID;
  693. continue;
  694. }
  695. }
  696. }
  697. if (animID == UUID.Zero)
  698. target.Animator.AddAnimation(animation, m_host.UUID);
  699. else
  700. target.Animator.AddAnimation(animID, m_host.UUID);
  701. }
  702. }
  703. }
  704. public void osAvatarStopAnimation(string avatar, string animation)
  705. {
  706. CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarStopAnimation");
  707. UUID avatarID = (UUID)avatar;
  708. m_host.AddScriptLPS(1);
  709. if (World.Entities.ContainsKey(avatarID) && World.Entities[avatarID] is ScenePresence)
  710. {
  711. ScenePresence target = (ScenePresence)World.Entities[avatarID];
  712. if (target != null)
  713. {
  714. UUID animID=UUID.Zero;
  715. lock (m_host.TaskInventory)
  716. {
  717. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  718. {
  719. if (inv.Value.Name == animation)
  720. {
  721. if (inv.Value.Type == (int)AssetType.Animation)
  722. animID = inv.Value.AssetID;
  723. continue;
  724. }
  725. }
  726. }
  727. if (animID == UUID.Zero)
  728. target.Animator.RemoveAnimation(animation);
  729. else
  730. target.Animator.RemoveAnimation(animID);
  731. }
  732. }
  733. }
  734. //Texture draw functions
  735. public string osMovePen(string drawList, int x, int y)
  736. {
  737. CheckThreatLevel(ThreatLevel.None, "osMovePen");
  738. m_host.AddScriptLPS(1);
  739. drawList += "MoveTo " + x + "," + y + ";";
  740. return drawList;
  741. }
  742. public string osDrawLine(string drawList, int startX, int startY, int endX, int endY)
  743. {
  744. CheckThreatLevel(ThreatLevel.None, "osDrawLine");
  745. m_host.AddScriptLPS(1);
  746. drawList += "MoveTo "+ startX+","+ startY +"; LineTo "+endX +","+endY +"; ";
  747. return drawList;
  748. }
  749. public string osDrawLine(string drawList, int endX, int endY)
  750. {
  751. CheckThreatLevel(ThreatLevel.None, "osDrawLine");
  752. m_host.AddScriptLPS(1);
  753. drawList += "LineTo " + endX + "," + endY + "; ";
  754. return drawList;
  755. }
  756. public string osDrawText(string drawList, string text)
  757. {
  758. CheckThreatLevel(ThreatLevel.None, "osDrawText");
  759. m_host.AddScriptLPS(1);
  760. drawList += "Text " + text + "; ";
  761. return drawList;
  762. }
  763. public string osDrawEllipse(string drawList, int width, int height)
  764. {
  765. CheckThreatLevel(ThreatLevel.None, "osDrawEllipse");
  766. m_host.AddScriptLPS(1);
  767. drawList += "Ellipse " + width + "," + height + "; ";
  768. return drawList;
  769. }
  770. public string osDrawRectangle(string drawList, int width, int height)
  771. {
  772. CheckThreatLevel(ThreatLevel.None, "osDrawRectangle");
  773. m_host.AddScriptLPS(1);
  774. drawList += "Rectangle " + width + "," + height + "; ";
  775. return drawList;
  776. }
  777. public string osDrawFilledRectangle(string drawList, int width, int height)
  778. {
  779. CheckThreatLevel(ThreatLevel.None, "osDrawFilledRectangle");
  780. m_host.AddScriptLPS(1);
  781. drawList += "FillRectangle " + width + "," + height + "; ";
  782. return drawList;
  783. }
  784. public string osDrawFilledPolygon(string drawList, LSL_List x, LSL_List y)
  785. {
  786. CheckThreatLevel(ThreatLevel.None, "osDrawFilledPolygon");
  787. m_host.AddScriptLPS(1);
  788. if (x.Length != y.Length || x.Length < 3)
  789. {
  790. return "";
  791. }
  792. drawList += "FillPolygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
  793. for (int i = 1; i < x.Length; i++)
  794. {
  795. drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
  796. }
  797. drawList += "; ";
  798. return drawList;
  799. }
  800. public string osDrawPolygon(string drawList, LSL_List x, LSL_List y)
  801. {
  802. CheckThreatLevel(ThreatLevel.None, "osDrawFilledPolygon");
  803. m_host.AddScriptLPS(1);
  804. if (x.Length != y.Length || x.Length < 3)
  805. {
  806. return "";
  807. }
  808. drawList += "Polygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
  809. for (int i = 1; i < x.Length; i++)
  810. {
  811. drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
  812. }
  813. drawList += "; ";
  814. return drawList;
  815. }
  816. public string osSetFontSize(string drawList, int fontSize)
  817. {
  818. CheckThreatLevel(ThreatLevel.None, "osSetFontSize");
  819. m_host.AddScriptLPS(1);
  820. drawList += "FontSize "+ fontSize +"; ";
  821. return drawList;
  822. }
  823. public string osSetFontName(string drawList, string fontName)
  824. {
  825. CheckThreatLevel(ThreatLevel.None, "osSetFontName");
  826. m_host.AddScriptLPS(1);
  827. drawList += "FontName "+ fontName +"; ";
  828. return drawList;
  829. }
  830. public string osSetPenSize(string drawList, int penSize)
  831. {
  832. CheckThreatLevel(ThreatLevel.None, "osSetPenSize");
  833. m_host.AddScriptLPS(1);
  834. drawList += "PenSize " + penSize + "; ";
  835. return drawList;
  836. }
  837. public string osSetPenColour(string drawList, string colour)
  838. {
  839. CheckThreatLevel(ThreatLevel.None, "osSetPenColour");
  840. m_host.AddScriptLPS(1);
  841. drawList += "PenColour " + colour + "; ";
  842. return drawList;
  843. }
  844. public string osSetPenCap(string drawList, string direction, string type)
  845. {
  846. CheckThreatLevel(ThreatLevel.None, "osSetPenColour");
  847. m_host.AddScriptLPS(1);
  848. drawList += "PenCap " + direction + "," + type + "; ";
  849. return drawList;
  850. }
  851. public string osDrawImage(string drawList, int width, int height, string imageUrl)
  852. {
  853. CheckThreatLevel(ThreatLevel.None, "osDrawImage");
  854. m_host.AddScriptLPS(1);
  855. drawList +="Image " +width + "," + height+ ","+ imageUrl +"; " ;
  856. return drawList;
  857. }
  858. public LSL_Vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize)
  859. {
  860. CheckThreatLevel(ThreatLevel.VeryLow, "osGetDrawStringSize");
  861. m_host.AddScriptLPS(1);
  862. LSL_Vector vec = new LSL_Vector(0,0,0);
  863. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  864. if (textureManager != null)
  865. {
  866. double xSize, ySize;
  867. textureManager.GetDrawStringSize(contentType, text, fontName, fontSize,
  868. out xSize, out ySize);
  869. vec.x = xSize;
  870. vec.y = ySize;
  871. }
  872. return vec;
  873. }
  874. public void osSetStateEvents(int events)
  875. {
  876. // This function is a hack. There is no reason for it's existence
  877. // anymore, since state events now work properly.
  878. // It was probably added as a crutch or debugging aid, and
  879. // should be removed
  880. //
  881. CheckThreatLevel(ThreatLevel.High, "osSetStateEvents");
  882. m_host.SetScriptEvents(m_itemID, events);
  883. }
  884. public void osSetRegionWaterHeight(double height)
  885. {
  886. CheckThreatLevel(ThreatLevel.High, "osSetRegionWaterHeight");
  887. m_host.AddScriptLPS(1);
  888. //Check to make sure that the script's owner is the estate manager/master
  889. //World.Permissions.GenericEstatePermission(
  890. if (World.Permissions.IsGod(m_host.OwnerID))
  891. {
  892. World.EventManager.TriggerRequestChangeWaterHeight((float)height);
  893. }
  894. }
  895. /// <summary>
  896. /// Changes the Region Sun Settings, then Triggers a Sun Update
  897. /// </summary>
  898. /// <param name="useEstateSun">True to use Estate Sun instead of Region Sun</param>
  899. /// <param name="sunFixed">True to keep the sun stationary</param>
  900. /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
  901. public void osSetRegionSunSettings(bool useEstateSun, bool sunFixed, double sunHour)
  902. {
  903. CheckThreatLevel(ThreatLevel.Nuisance, "osSetRegionSunSettings");
  904. m_host.AddScriptLPS(1);
  905. //Check to make sure that the script's owner is the estate manager/master
  906. //World.Permissions.GenericEstatePermission(
  907. if (World.Permissions.IsGod(m_host.OwnerID))
  908. {
  909. while (sunHour > 24.0)
  910. sunHour -= 24.0;
  911. while (sunHour < 0)
  912. sunHour += 24.0;
  913. World.RegionInfo.RegionSettings.UseEstateSun = useEstateSun;
  914. World.RegionInfo.RegionSettings.SunPosition = sunHour + 6; // LL Region Sun Hour is 6 to 30
  915. World.RegionInfo.RegionSettings.FixedSun = sunFixed;
  916. World.RegionInfo.RegionSettings.Save();
  917. World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle, sunFixed, useEstateSun, (float)sunHour);
  918. }
  919. }
  920. /// <summary>
  921. /// Changes the Estate Sun Settings, then Triggers a Sun Update
  922. /// </summary>
  923. /// <param name="sunFixed">True to keep the sun stationary, false to use global time</param>
  924. /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
  925. public void osSetEstateSunSettings(bool sunFixed, double sunHour)
  926. {
  927. CheckThreatLevel(ThreatLevel.Nuisance, "osSetEstateSunSettings");
  928. m_host.AddScriptLPS(1);
  929. //Check to make sure that the script's owner is the estate manager/master
  930. //World.Permissions.GenericEstatePermission(
  931. if (World.Permissions.IsGod(m_host.OwnerID))
  932. {
  933. while (sunHour > 24.0)
  934. sunHour -= 24.0;
  935. while (sunHour < 0)
  936. sunHour += 24.0;
  937. World.RegionInfo.EstateSettings.UseGlobalTime = !sunFixed;
  938. World.RegionInfo.EstateSettings.SunPosition = sunHour;
  939. World.RegionInfo.EstateSettings.FixedSun = sunFixed;
  940. World.RegionInfo.EstateSettings.Save();
  941. World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle, sunFixed, World.RegionInfo.RegionSettings.UseEstateSun, (float)sunHour);
  942. }
  943. }
  944. /// <summary>
  945. /// Return the current Sun Hour 0...24, with 0 being roughly sun-rise
  946. /// </summary>
  947. /// <returns></returns>
  948. public double osGetCurrentSunHour()
  949. {
  950. CheckThreatLevel(ThreatLevel.None, "osGetCurrentSunHour");
  951. m_host.AddScriptLPS(1);
  952. // Must adjust for the fact that Region Sun Settings are still LL offset
  953. double sunHour = World.RegionInfo.RegionSettings.SunPosition - 6;
  954. // See if the sun module has registered itself, if so it's authoritative
  955. ISunModule module = World.RequestModuleInterface<ISunModule>();
  956. if (module != null)
  957. {
  958. sunHour = module.GetCurrentSunHour();
  959. }
  960. return sunHour;
  961. }
  962. public double osSunGetParam(string param)
  963. {
  964. CheckThreatLevel(ThreatLevel.None, "osSunGetParam");
  965. m_host.AddScriptLPS(1);
  966. double value = 0.0;
  967. ISunModule module = World.RequestModuleInterface<ISunModule>();
  968. if (module != null)
  969. {
  970. value = module.GetSunParameter(param);
  971. }
  972. return value;
  973. }
  974. public void osSunSetParam(string param, double value)
  975. {
  976. CheckThreatLevel(ThreatLevel.None, "osSunSetParam");
  977. m_host.AddScriptLPS(1);
  978. ISunModule module = World.RequestModuleInterface<ISunModule>();
  979. if (module != null)
  980. {
  981. module.SetSunParameter(param, value);
  982. }
  983. }
  984. public string osWindActiveModelPluginName()
  985. {
  986. CheckThreatLevel(ThreatLevel.None, "osWindActiveModelPluginName");
  987. m_host.AddScriptLPS(1);
  988. IWindModule module = World.RequestModuleInterface<IWindModule>();
  989. if (module != null)
  990. {
  991. return module.WindActiveModelPluginName;
  992. }
  993. return String.Empty;
  994. }
  995. public void osWindParamSet(string plugin, string param, float value)
  996. {
  997. CheckThreatLevel(ThreatLevel.VeryLow, "osWindParamSet");
  998. m_host.AddScriptLPS(1);
  999. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1000. if (module != null)
  1001. {
  1002. try
  1003. {
  1004. module.WindParamSet(plugin, param, value);
  1005. }
  1006. catch (Exception) { }
  1007. }
  1008. }
  1009. public float osWindParamGet(string plugin, string param)
  1010. {
  1011. CheckThreatLevel(ThreatLevel.VeryLow, "osWindParamGet");
  1012. m_host.AddScriptLPS(1);
  1013. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1014. if (module != null)
  1015. {
  1016. return module.WindParamGet(plugin, param);
  1017. }
  1018. return 0.0f;
  1019. }
  1020. // Routines for creating and managing parcels programmatically
  1021. public void osParcelJoin(LSL_Vector pos1, LSL_Vector pos2)
  1022. {
  1023. CheckThreatLevel(ThreatLevel.High, "osParcelJoin");
  1024. m_host.AddScriptLPS(1);
  1025. int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
  1026. int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
  1027. int endx = (int)(pos1.x > pos2.x ? pos1.x : pos2.x);
  1028. int endy = (int)(pos1.y > pos2.y ? pos1.y : pos2.y);
  1029. World.LandChannel.Join(startx,starty,endx,endy,m_host.OwnerID);
  1030. }
  1031. public void osParcelSubdivide(LSL_Vector pos1, LSL_Vector pos2)
  1032. {
  1033. CheckThreatLevel(ThreatLevel.High, "osParcelSubdivide");
  1034. m_host.AddScriptLPS(1);
  1035. int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
  1036. int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
  1037. int endx = (int)(pos1.x > pos2.x ? pos1.x : pos2.x);
  1038. int endy = (int)(pos1.y > pos2.y ? pos1.y : pos2.y);
  1039. World.LandChannel.Subdivide(startx,starty,endx,endy,m_host.OwnerID);
  1040. }
  1041. public void osParcelSetDetails(LSL_Vector pos, LSL_List rules)
  1042. {
  1043. CheckThreatLevel(ThreatLevel.High, "osParcelSetDetails");
  1044. m_host.AddScriptLPS(1);
  1045. // Get a reference to the land data and make sure the owner of the script
  1046. // can modify it
  1047. ILandObject startLandObject = World.LandChannel.GetLandObject((int)pos.x, (int)pos.y);
  1048. if (startLandObject == null)
  1049. {
  1050. OSSLShoutError("There is no land at that location");
  1051. return;
  1052. }
  1053. if (! World.Permissions.CanEditParcel(m_host.OwnerID, startLandObject))
  1054. {
  1055. OSSLShoutError("You do not have permission to modify the parcel");
  1056. return;
  1057. }
  1058. // Create a new land data object we can modify
  1059. LandData newLand = startLandObject.LandData.Copy();
  1060. UUID uuid;
  1061. // Process the rules, not sure what the impact would be of changing owner or group
  1062. for (int idx = 0; idx < rules.Length; )
  1063. {
  1064. int code = rules.GetLSLIntegerItem(idx++);
  1065. string arg = rules.GetLSLStringItem(idx++);
  1066. switch (code)
  1067. {
  1068. case 0:
  1069. newLand.Name = arg;
  1070. break;
  1071. case 1:
  1072. newLand.Description = arg;
  1073. break;
  1074. case 2:
  1075. CheckThreatLevel(ThreatLevel.VeryHigh, "osParcelSetDetails");
  1076. if (UUID.TryParse(arg , out uuid))
  1077. newLand.OwnerID = uuid;
  1078. break;
  1079. case 3:
  1080. CheckThreatLevel(ThreatLevel.VeryHigh, "osParcelSetDetails");
  1081. if (UUID.TryParse(arg , out uuid))
  1082. newLand.GroupID = uuid;
  1083. break;
  1084. }
  1085. }
  1086. World.LandChannel.UpdateLandObject(newLand.LocalID,newLand);
  1087. }
  1088. public double osList2Double(LSL_Types.list src, int index)
  1089. {
  1090. // There is really no double type in OSSL. C# and other
  1091. // have one, but the current implementation of LSL_Types.list
  1092. // is not allowed to contain any.
  1093. // This really should be removed.
  1094. //
  1095. CheckThreatLevel(ThreatLevel.None, "osList2Double");
  1096. m_host.AddScriptLPS(1);
  1097. if (index < 0)
  1098. {
  1099. index = src.Length + index;
  1100. }
  1101. if (index >= src.Length)
  1102. {
  1103. return 0.0;
  1104. }
  1105. return Convert.ToDouble(src.Data[index]);
  1106. }
  1107. public void osSetParcelMediaURL(string url)
  1108. {
  1109. // What actually is the difference to the LL function?
  1110. //
  1111. CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL");
  1112. m_host.AddScriptLPS(1);
  1113. ILandObject land
  1114. = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  1115. if (land.LandData.OwnerID != m_host.OwnerID)
  1116. return;
  1117. land.SetMediaUrl(url);
  1118. }
  1119. public void osSetParcelSIPAddress(string SIPAddress)
  1120. {
  1121. // What actually is the difference to the LL function?
  1122. //
  1123. CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL");
  1124. m_host.AddScriptLPS(1);
  1125. ILandObject land
  1126. = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  1127. if (land.LandData.OwnerID != m_host.OwnerID)
  1128. {
  1129. OSSLError("osSetParcelSIPAddress: Sorry, you need to own the land to use this function");
  1130. return;
  1131. }
  1132. // get the voice module
  1133. IVoiceModule voiceModule = World.RequestModuleInterface<IVoiceModule>();
  1134. if (voiceModule != null)
  1135. voiceModule.setLandSIPAddress(SIPAddress,land.LandData.GlobalID);
  1136. else
  1137. OSSLError("osSetParcelSIPAddress: No voice module enabled for this land");
  1138. }
  1139. public string osGetScriptEngineName()
  1140. {
  1141. // This gets a "high" because knowing the engine may be used
  1142. // to exploit engine-specific bugs or induce usage patterns
  1143. // that trigger engine-specific failures.
  1144. // Besides, public grid users aren't supposed to know.
  1145. //
  1146. CheckThreatLevel(ThreatLevel.High, "osGetScriptEngineName");
  1147. m_host.AddScriptLPS(1);
  1148. int scriptEngineNameIndex = 0;
  1149. if (!String.IsNullOrEmpty(m_ScriptEngine.ScriptEngineName))
  1150. {
  1151. // parse off the "ScriptEngine."
  1152. scriptEngineNameIndex = m_ScriptEngine.ScriptEngineName.IndexOf(".", scriptEngineNameIndex);
  1153. scriptEngineNameIndex++; // get past delimiter
  1154. int scriptEngineNameLength = m_ScriptEngine.ScriptEngineName.Length - scriptEngineNameIndex;
  1155. // create char array then a string that is only the script engine name
  1156. Char[] scriptEngineNameCharArray = m_ScriptEngine.ScriptEngineName.ToCharArray(scriptEngineNameIndex, scriptEngineNameLength);
  1157. String scriptEngineName = new String(scriptEngineNameCharArray);
  1158. return scriptEngineName;
  1159. }
  1160. else
  1161. {
  1162. return String.Empty;
  1163. }
  1164. }
  1165. public string osGetSimulatorVersion()
  1166. {
  1167. // High because it can be used to target attacks to known weaknesses
  1168. // This would allow a new class of griefer scripts that don't even
  1169. // require their user to know what they are doing (see script
  1170. // kiddie)
  1171. //
  1172. CheckThreatLevel(ThreatLevel.High,"osGetSimulatorVersion");
  1173. m_host.AddScriptLPS(1);
  1174. return m_ScriptEngine.World.GetSimulatorVersion();
  1175. }
  1176. public Hashtable osParseJSON(string JSON)
  1177. {
  1178. CheckThreatLevel(ThreatLevel.None, "osParseJSON");
  1179. m_host.AddScriptLPS(1);
  1180. // see http://www.json.org/ for more details on JSON
  1181. string currentKey = null;
  1182. Stack objectStack = new Stack(); // objects in JSON can be nested so we need to keep a track of this
  1183. Hashtable jsondata = new Hashtable(); // the hashtable to be returned
  1184. int i = 0;
  1185. try
  1186. {
  1187. // iterate through the serialised stream of tokens and store at the right depth in the hashtable
  1188. // the top level hashtable may contain more nested hashtables within it each containing an objects representation
  1189. for (i = 0; i < JSON.Length; i++)
  1190. {
  1191. // m_log.Debug(""+JSON[i]);
  1192. switch (JSON[i])
  1193. {
  1194. case '{':
  1195. // 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
  1196. Hashtable currentObject = new Hashtable();
  1197. if (objectStack.Count == 0) // the stack should only be empty for the first outer object
  1198. {
  1199. objectStack.Push(jsondata);
  1200. }
  1201. else if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1202. {
  1203. // add it to the parent array
  1204. ((ArrayList)objectStack.Peek()).Add(currentObject);
  1205. objectStack.Push(currentObject);
  1206. }
  1207. else
  1208. {
  1209. // add it to the parent hashtable
  1210. ((Hashtable)objectStack.Peek()).Add(currentKey,currentObject);
  1211. objectStack.Push(currentObject);
  1212. }
  1213. // clear the key
  1214. currentKey = null;
  1215. break;
  1216. case '}':
  1217. // pop the hashtable off the stack
  1218. objectStack.Pop();
  1219. break;
  1220. case '"':// string boundary
  1221. string tokenValue = "";
  1222. i++; // move to next char
  1223. // just loop through until the next quote mark storing the string, ignore quotes with pre-ceding \
  1224. while (JSON[i] != '"')
  1225. {
  1226. tokenValue += JSON[i];
  1227. // handle escaped double quotes \"
  1228. if (JSON[i] == '\\' && JSON[i+1] == '"')
  1229. {
  1230. tokenValue += JSON[i+1];
  1231. i++;
  1232. }
  1233. i++;
  1234. }
  1235. // ok we've got a string, if we've got an array on the top of the stack then we store it
  1236. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1237. {
  1238. ((ArrayList)objectStack.Peek()).Add(tokenValue);
  1239. }
  1240. else if (currentKey == null) // no key stored and its not an array this must be a key so store it
  1241. {
  1242. currentKey = tokenValue;
  1243. }
  1244. else
  1245. {
  1246. // we have a key so lets store this value
  1247. ((Hashtable)objectStack.Peek()).Add(currentKey,tokenValue);
  1248. // now lets clear the key, we're done with it and moving on
  1249. currentKey = null;
  1250. }
  1251. break;
  1252. case ':':// key : value separator
  1253. // just ignore
  1254. break;
  1255. case ' ':// spaces
  1256. // just ignore
  1257. break;
  1258. case '[': // array start
  1259. ArrayList currentArray = new ArrayList();
  1260. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1261. {
  1262. ((ArrayList)objectStack.Peek()).Add(currentArray);
  1263. }
  1264. else
  1265. {
  1266. ((Hashtable)objectStack.Peek()).Add(currentKey,currentArray);
  1267. // clear the key
  1268. currentKey = null;
  1269. }
  1270. objectStack.Push(currentArray);
  1271. break;
  1272. case ',':// seperator
  1273. // just ignore
  1274. break;
  1275. case ']'://Array end
  1276. // pop the array off the stack
  1277. objectStack.Pop();
  1278. break;
  1279. case 't': // we've found a character start not in quotes, it must be a boolean true
  1280. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1281. {
  1282. ((ArrayList)objectStack.Peek()).Add(true);
  1283. }
  1284. else
  1285. {
  1286. ((Hashtable)objectStack.Peek()).Add(currentKey,true);
  1287. currentKey = null;
  1288. }
  1289. //advance the counter to the letter 'e'
  1290. i = i + 3;
  1291. break;
  1292. case 'f': // we've found a character start not in quotes, it must be a boolean false
  1293. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1294. {
  1295. ((ArrayList)objectStack.Peek()).Add(false);
  1296. }
  1297. else
  1298. {
  1299. ((Hashtable)objectStack.Peek()).Add(currentKey,false);
  1300. currentKey = null;
  1301. }
  1302. //advance the counter to the letter 'e'
  1303. i = i + 4;
  1304. break;
  1305. case '\n':// carriage return
  1306. // just ignore
  1307. break;
  1308. case '\r':// carriage return
  1309. // just ignore
  1310. break;
  1311. default:
  1312. // ok here we're catching all numeric types int,double,long we might want to spit these up mr accurately
  1313. // but for now we'll just do them as strings
  1314. string numberValue = "";
  1315. // just loop through until the next known marker quote mark storing the string
  1316. while (JSON[i] != '"' && JSON[i] != ',' && JSON[i] != ']' && JSON[i] != '}' && JSON[i] != ' ')
  1317. {
  1318. numberValue += "" + JSON[i++];
  1319. }
  1320. i--; // we want to process this caracter that marked the end of this string in the main loop
  1321. // ok we've got a string, if we've got an array on the top of the stack then we store it
  1322. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1323. {
  1324. ((ArrayList)objectStack.Peek()).Add(numberValue);
  1325. }
  1326. else
  1327. {
  1328. // we have a key so lets store this value
  1329. ((Hashtable)objectStack.Peek()).Add(currentKey,numberValue);
  1330. // now lets clear the key, we're done with it and moving on
  1331. currentKey = null;
  1332. }
  1333. break;
  1334. }
  1335. }
  1336. }
  1337. catch(Exception)
  1338. {
  1339. OSSLError("osParseJSON: The JSON string is not valid " + JSON) ;
  1340. }
  1341. return jsondata;
  1342. }
  1343. // send a message to to object identified by the given UUID, a script in the object must implement the dataserver function
  1344. // the dataserver function is passed the ID of the calling function and a string message
  1345. public void osMessageObject(LSL_Key objectUUID, string message)
  1346. {
  1347. CheckThreatLevel(ThreatLevel.Low, "osMessageObject");
  1348. m_host.AddScriptLPS(1);
  1349. object[] resobj = new object[] { new LSL_Types.LSLString(m_host.UUID.ToString()), new LSL_Types.LSLString(message) };
  1350. SceneObjectPart sceneOP = World.GetSceneObjectPart(new UUID(objectUUID));
  1351. m_ScriptEngine.PostObjectEvent(
  1352. sceneOP.LocalId, new EventParams(
  1353. "dataserver", resobj, new DetectParams[0]));
  1354. }
  1355. // This needs ThreatLevel high. It is an excellent griefer tool,
  1356. // In a loop, it can cause asset bloat and DOS levels of asset
  1357. // writes.
  1358. //
  1359. public void osMakeNotecard(string notecardName, LSL_Types.list contents)
  1360. {
  1361. CheckThreatLevel(ThreatLevel.High, "osMakeNotecard");
  1362. m_host.AddScriptLPS(1);
  1363. // Create new asset
  1364. AssetBase asset = new AssetBase(UUID.Random(), notecardName, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString());
  1365. asset.Description = "Script Generated Notecard";
  1366. string notecardData = String.Empty;
  1367. for (int i = 0; i < contents.Length; i++) {
  1368. notecardData += contents.GetLSLStringItem(i) + "\n";
  1369. }
  1370. int textLength = notecardData.Length;
  1371. notecardData = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length "
  1372. + textLength.ToString() + "\n" + notecardData + "}\n";
  1373. asset.Data = Util.UTF8.GetBytes(notecardData);
  1374. World.AssetService.Store(asset);
  1375. // Create Task Entry
  1376. TaskInventoryItem taskItem=new TaskInventoryItem();
  1377. taskItem.ResetIDs(m_host.UUID);
  1378. taskItem.ParentID = m_host.UUID;
  1379. taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch();
  1380. taskItem.Name = asset.Name;
  1381. taskItem.Description = asset.Description;
  1382. taskItem.Type = (int)AssetType.Notecard;
  1383. taskItem.InvType = (int)InventoryType.Notecard;
  1384. taskItem.OwnerID = m_host.OwnerID;
  1385. taskItem.CreatorID = m_host.OwnerID;
  1386. taskItem.BasePermissions = (uint)PermissionMask.All;
  1387. taskItem.CurrentPermissions = (uint)PermissionMask.All;
  1388. taskItem.EveryonePermissions = 0;
  1389. taskItem.NextPermissions = (uint)PermissionMask.All;
  1390. taskItem.GroupID = m_host.GroupID;
  1391. taskItem.GroupPermissions = 0;
  1392. taskItem.Flags = 0;
  1393. taskItem.PermsGranter = UUID.Zero;
  1394. taskItem.PermsMask = 0;
  1395. taskItem.AssetID = asset.FullID;
  1396. m_host.Inventory.AddInventoryItem(taskItem, false);
  1397. }
  1398. /*Instead of using the LSL Dataserver event to pull notecard data,
  1399. this will simply read the requested line and return its data as a string.
  1400. Warning - due to the synchronous method this function uses to fetch assets, its use
  1401. may be dangerous and unreliable while running in grid mode.
  1402. */
  1403. public string osGetNotecardLine(string name, int line)
  1404. {
  1405. CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine");
  1406. m_host.AddScriptLPS(1);
  1407. UUID assetID = UUID.Zero;
  1408. if (!UUID.TryParse(name, out assetID))
  1409. {
  1410. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  1411. {
  1412. if (item.Type == 7 && item.Name == name)
  1413. {
  1414. assetID = item.AssetID;
  1415. }
  1416. }
  1417. }
  1418. if (assetID == UUID.Zero)
  1419. {
  1420. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1421. return "ERROR!";
  1422. }
  1423. if (!NotecardCache.IsCached(assetID))
  1424. {
  1425. AssetBase a = World.AssetService.Get(assetID.ToString());
  1426. if (a != null)
  1427. {
  1428. System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
  1429. string data = enc.GetString(a.Data);
  1430. NotecardCache.Cache(assetID, data);
  1431. }
  1432. else
  1433. {
  1434. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1435. return "ERROR!";
  1436. }
  1437. };
  1438. return NotecardCache.GetLine(assetID, line, 255);
  1439. }
  1440. /*Instead of using the LSL Dataserver event to pull notecard data line by line,
  1441. this will simply read the entire notecard and return its data as a string.
  1442. Warning - due to the synchronous method this function uses to fetch assets, its use
  1443. may be dangerous and unreliable while running in grid mode.
  1444. */
  1445. public string osGetNotecard(string name)
  1446. {
  1447. CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard");
  1448. m_host.AddScriptLPS(1);
  1449. UUID assetID = UUID.Zero;
  1450. string NotecardData = "";
  1451. if (!UUID.TryParse(name, out assetID))
  1452. {
  1453. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  1454. {
  1455. if (item.Type == 7 && item.Name == name)
  1456. {
  1457. assetID = item.AssetID;
  1458. }
  1459. }
  1460. }
  1461. if (assetID == UUID.Zero)
  1462. {
  1463. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1464. return "ERROR!";
  1465. }
  1466. if (!NotecardCache.IsCached(assetID))
  1467. {
  1468. AssetBase a = World.AssetService.Get(assetID.ToString());
  1469. if (a != null)
  1470. {
  1471. System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
  1472. string data = enc.GetString(a.Data);
  1473. NotecardCache.Cache(assetID, data);
  1474. }
  1475. else
  1476. {
  1477. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1478. return "ERROR!";
  1479. }
  1480. };
  1481. for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
  1482. {
  1483. NotecardData += NotecardCache.GetLine(assetID, count, 255) + "\n";
  1484. }
  1485. return NotecardData;
  1486. }
  1487. /*Instead of using the LSL Dataserver event to pull notecard data,
  1488. this will simply read the number of note card lines and return this data as an integer.
  1489. Warning - due to the synchronous method this function uses to fetch assets, its use
  1490. may be dangerous and unreliable while running in grid mode.
  1491. */
  1492. public int osGetNumberOfNotecardLines(string name)
  1493. {
  1494. CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines");
  1495. m_host.AddScriptLPS(1);
  1496. UUID assetID = UUID.Zero;
  1497. if (!UUID.TryParse(name, out assetID))
  1498. {
  1499. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  1500. {
  1501. if (item.Type == 7 && item.Name == name)
  1502. {
  1503. assetID = item.AssetID;
  1504. }
  1505. }
  1506. }
  1507. if (assetID == UUID.Zero)
  1508. {
  1509. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1510. return -1;
  1511. }
  1512. if (!NotecardCache.IsCached(assetID))
  1513. {
  1514. AssetBase a = World.AssetService.Get(assetID.ToString());
  1515. if (a != null)
  1516. {
  1517. System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
  1518. string data = enc.GetString(a.Data);
  1519. NotecardCache.Cache(assetID, data);
  1520. }
  1521. else
  1522. {
  1523. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1524. return -1;
  1525. }
  1526. };
  1527. return NotecardCache.GetLines(assetID);
  1528. }
  1529. public string osAvatarName2Key(string firstname, string lastname)
  1530. {
  1531. CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key");
  1532. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, firstname, lastname);
  1533. if (null == account)
  1534. {
  1535. return UUID.Zero.ToString();
  1536. }
  1537. else
  1538. {
  1539. return account.PrincipalID.ToString();
  1540. }
  1541. }
  1542. public string osKey2Name(string id)
  1543. {
  1544. CheckThreatLevel(ThreatLevel.Low, "osKey2Name");
  1545. UUID key = new UUID();
  1546. if (UUID.TryParse(id, out key))
  1547. {
  1548. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, key);
  1549. if (null == account)
  1550. {
  1551. return "";
  1552. }
  1553. else
  1554. {
  1555. return account.Name;
  1556. }
  1557. }
  1558. else
  1559. {
  1560. return "";
  1561. }
  1562. }
  1563. /// Threat level is Moderate because intentional abuse, for instance
  1564. /// scripts that are written to be malicious only on one grid,
  1565. /// for instance in a HG scenario, are a distinct possibility.
  1566. ///
  1567. /// Use value from the config file and return it.
  1568. ///
  1569. public string osGetGridNick()
  1570. {
  1571. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridNick");
  1572. m_host.AddScriptLPS(1);
  1573. string nick = "hippogrid";
  1574. IConfigSource config = m_ScriptEngine.ConfigSource;
  1575. if (config.Configs["GridInfo"] != null)
  1576. nick = config.Configs["GridInfo"].GetString("gridnick", nick);
  1577. return nick;
  1578. }
  1579. public string osGetGridName()
  1580. {
  1581. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridName");
  1582. m_host.AddScriptLPS(1);
  1583. string name = "the lost continent of hippo";
  1584. IConfigSource config = m_ScriptEngine.ConfigSource;
  1585. if (config.Configs["GridInfo"] != null)
  1586. name = config.Configs["GridInfo"].GetString("gridname", name);
  1587. return name;
  1588. }
  1589. public string osGetGridLoginURI()
  1590. {
  1591. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridLoginURI");
  1592. m_host.AddScriptLPS(1);
  1593. string loginURI = "http://127.0.0.1:9000/";
  1594. IConfigSource config = m_ScriptEngine.ConfigSource;
  1595. if (config.Configs["GridInfo"] != null)
  1596. loginURI = config.Configs["GridInfo"].GetString("login", loginURI);
  1597. return loginURI;
  1598. }
  1599. public LSL_String osFormatString(string str, LSL_List strings)
  1600. {
  1601. CheckThreatLevel(ThreatLevel.Low, "osFormatString");
  1602. m_host.AddScriptLPS(1);
  1603. return String.Format(str, strings.Data);
  1604. }
  1605. public LSL_List osMatchString(string src, string pattern, int start)
  1606. {
  1607. CheckThreatLevel(ThreatLevel.High, "osMatchString");
  1608. m_host.AddScriptLPS(1);
  1609. LSL_List result = new LSL_List();
  1610. // Normalize indices (if negative).
  1611. // After normlaization they may still be
  1612. // negative, but that is now relative to
  1613. // the start, rather than the end, of the
  1614. // sequence.
  1615. if (start < 0)
  1616. {
  1617. start = src.Length + start;
  1618. }
  1619. if (start < 0 || start >= src.Length)
  1620. {
  1621. return result; // empty list
  1622. }
  1623. // Find matches beginning at start position
  1624. Regex matcher = new Regex(pattern);
  1625. Match match = matcher.Match(src, start);
  1626. if (match.Success)
  1627. {
  1628. foreach (System.Text.RegularExpressions.Group g in match.Groups)
  1629. {
  1630. if (g.Success)
  1631. {
  1632. result.Add(g.Value);
  1633. result.Add(g.Index);
  1634. }
  1635. }
  1636. }
  1637. return result;
  1638. }
  1639. public string osLoadedCreationDate()
  1640. {
  1641. CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationDate");
  1642. m_host.AddScriptLPS(1);
  1643. return World.RegionInfo.RegionSettings.LoadedCreationDate;
  1644. }
  1645. public string osLoadedCreationTime()
  1646. {
  1647. CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationTime");
  1648. m_host.AddScriptLPS(1);
  1649. return World.RegionInfo.RegionSettings.LoadedCreationTime;
  1650. }
  1651. public string osLoadedCreationID()
  1652. {
  1653. CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationID");
  1654. m_host.AddScriptLPS(1);
  1655. return World.RegionInfo.RegionSettings.LoadedCreationID;
  1656. }
  1657. // Threat level is 'Low' because certain users could possibly be tricked into
  1658. // dropping an unverified script into one of their own objects, which could
  1659. // then gather the physical construction details of the object and transmit it
  1660. // to an unscrupulous third party, thus permitting unauthorized duplication of
  1661. // the object's form.
  1662. //
  1663. public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules)
  1664. {
  1665. CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams");
  1666. m_host.AddScriptLPS(1);
  1667. InitLSL();
  1668. LSL_List retVal = new LSL_List();
  1669. List<SceneObjectPart> parts = ((LSL_Api)m_LSL_Api).GetLinkParts(linknumber);
  1670. foreach (SceneObjectPart part in parts)
  1671. {
  1672. retVal += ((LSL_Api)m_LSL_Api).GetLinkPrimitiveParams(part, rules);
  1673. }
  1674. return retVal;
  1675. }
  1676. public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, LSL_Key cloneFrom)
  1677. {
  1678. CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
  1679. //QueueUserWorkItem
  1680. INPCModule module = World.RequestModuleInterface<INPCModule>();
  1681. if (module != null)
  1682. {
  1683. UUID x = module.CreateNPC(firstname,
  1684. lastname,
  1685. new Vector3((float) position.x, (float) position.y, (float) position.z),
  1686. World,
  1687. new UUID(cloneFrom));
  1688. return new LSL_Key(x.ToString());
  1689. }
  1690. return new LSL_Key(UUID.Zero.ToString());
  1691. }
  1692. public void osNpcMoveTo(LSL_Key npc, LSL_Vector position)
  1693. {
  1694. CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo");
  1695. INPCModule module = World.RequestModuleInterface<INPCModule>();
  1696. if (module != null)
  1697. {
  1698. Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z);
  1699. module.Autopilot(new UUID(npc.m_string), World, pos);
  1700. }
  1701. }
  1702. public void osNpcSay(LSL_Key npc, string message)
  1703. {
  1704. CheckThreatLevel(ThreatLevel.High, "osNpcSay");
  1705. INPCModule module = World.RequestModuleInterface<INPCModule>();
  1706. if (module != null)
  1707. {
  1708. module.Say(new UUID(npc.m_string), World, message);
  1709. }
  1710. }
  1711. public void osNpcRemove(LSL_Key npc)
  1712. {
  1713. CheckThreatLevel(ThreatLevel.High, "osNpcRemove");
  1714. INPCModule module = World.RequestModuleInterface<INPCModule>();
  1715. if (module != null)
  1716. {
  1717. module.DeleteNPC(new UUID(npc.m_string), World);
  1718. }
  1719. }
  1720. /// <summary>
  1721. /// Get current region's map texture UUID
  1722. /// </summary>
  1723. /// <returns></returns>
  1724. public LSL_Key osGetMapTexture()
  1725. {
  1726. CheckThreatLevel(ThreatLevel.None, "osGetMapTexture");
  1727. return m_ScriptEngine.World.RegionInfo.RegionSettings.TerrainImageID.ToString();
  1728. }
  1729. /// <summary>
  1730. /// Get a region's map texture UUID by region UUID or name.
  1731. /// </summary>
  1732. /// <param name="regionName"></param>
  1733. /// <returns></returns>
  1734. public LSL_Key osGetRegionMapTexture(string regionName)
  1735. {
  1736. CheckThreatLevel(ThreatLevel.High, "osGetRegionMapTexture");
  1737. Scene scene = m_ScriptEngine.World;
  1738. UUID key = UUID.Zero;
  1739. GridRegion region;
  1740. //If string is a key, use it. Otherwise, try to locate region by name.
  1741. if (UUID.TryParse(regionName, out key))
  1742. region = scene.GridService.GetRegionByUUID(UUID.Zero, key);
  1743. else
  1744. region = scene.GridService.GetRegionByName(UUID.Zero, regionName);
  1745. // If region was found, return the regions map texture key.
  1746. if (region != null)
  1747. key = region.TerrainImage;
  1748. ScriptSleep(1000);
  1749. return key.ToString();
  1750. }
  1751. /// <summary>
  1752. /// Return information regarding various simulator statistics (sim fps, physics fps, time
  1753. /// dilation, total number of prims, total number of active scripts, script lps, various
  1754. /// timing data, packets in/out, etc. Basically much the information that's shown in the
  1755. /// client's Statistics Bar (Ctrl-Shift-1)
  1756. /// </summary>
  1757. /// <returns>List of floats</returns>
  1758. public LSL_List osGetRegionStats()
  1759. {
  1760. CheckThreatLevel(ThreatLevel.Moderate, "osGetRegionStats");
  1761. m_host.AddScriptLPS(1);
  1762. LSL_List ret = new LSL_List();
  1763. float[] stats = World.SimulatorStats;
  1764. for (int i = 0; i < 21; i++)
  1765. {
  1766. ret.Add(new LSL_Float(stats[i]));
  1767. }
  1768. return ret;
  1769. }
  1770. public int osGetSimulatorMemory()
  1771. {
  1772. CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemory");
  1773. m_host.AddScriptLPS(1);
  1774. long pws = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64;
  1775. if (pws > Int32.MaxValue)
  1776. return Int32.MaxValue;
  1777. if (pws < 0)
  1778. return 0;
  1779. return (int)pws;
  1780. }
  1781. public void osSetSpeed(string UUID, float SpeedModifier)
  1782. {
  1783. CheckThreatLevel(ThreatLevel.Moderate, "osSetSpeed");
  1784. m_host.AddScriptLPS(1);
  1785. ScenePresence avatar = World.GetScenePresence(new UUID(UUID));
  1786. avatar.SpeedModifier = SpeedModifier;
  1787. }
  1788. public void osKickAvatar(string FirstName,string SurName,string alert)
  1789. {
  1790. CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
  1791. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  1792. {
  1793. World.ForEachScenePresence(delegate(ScenePresence sp)
  1794. {
  1795. if (!sp.IsChildAgent &&
  1796. sp.Firstname == FirstName &&
  1797. sp.Lastname == SurName)
  1798. {
  1799. // kick client...
  1800. if (alert != null)
  1801. sp.ControllingClient.Kick(alert);
  1802. // ...and close on our side
  1803. sp.Scene.IncomingCloseAgent(sp.UUID);
  1804. }
  1805. });
  1806. }
  1807. }
  1808. public void osCauseDamage(string avatar, double damage)
  1809. {
  1810. CheckThreatLevel(ThreatLevel.High, "osCauseDamage");
  1811. m_host.AddScriptLPS(1);
  1812. UUID avatarId = new UUID(avatar);
  1813. Vector3 pos = m_host.GetWorldPosition();
  1814. ScenePresence presence = World.GetScenePresence(avatarId);
  1815. if (presence != null)
  1816. {
  1817. LandData land = World.GetLandData((float)pos.X, (float)pos.Y);
  1818. if ((land.Flags & (uint)ParcelFlags.AllowDamage) == (uint)ParcelFlags.AllowDamage)
  1819. {
  1820. float health = presence.Health;
  1821. health -= (float)damage;
  1822. presence.setHealthWithUpdate(health);
  1823. if (health <= 0)
  1824. {
  1825. float healthliveagain = 100;
  1826. presence.ControllingClient.SendAgentAlertMessage("You died!", true);
  1827. presence.setHealthWithUpdate(healthliveagain);
  1828. presence.Scene.TeleportClientHome(presence.UUID, presence.ControllingClient);
  1829. }
  1830. }
  1831. }
  1832. }
  1833. public void osCauseHealing(string avatar, double healing)
  1834. {
  1835. CheckThreatLevel(ThreatLevel.High, "osCauseHealing");
  1836. m_host.AddScriptLPS(1);
  1837. UUID avatarId = new UUID(avatar);
  1838. ScenePresence presence = World.GetScenePresence(avatarId);
  1839. Vector3 pos = m_host.GetWorldPosition();
  1840. bool result = World.ScriptDanger(m_host.LocalId, new Vector3((float)pos.X, (float)pos.Y, (float)pos.Z));
  1841. if (result)
  1842. {
  1843. if (presence != null)
  1844. {
  1845. float health = presence.Health;
  1846. health += (float)healing;
  1847. if (health >= 100)
  1848. {
  1849. health = 100;
  1850. }
  1851. presence.setHealthWithUpdate(health);
  1852. }
  1853. }
  1854. }
  1855. public LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules)
  1856. {
  1857. CheckThreatLevel(ThreatLevel.High, "osGetPrimitiveParams");
  1858. m_host.AddScriptLPS(1);
  1859. return m_LSL_Api.GetLinkPrimitiveParamsEx(prim, rules);
  1860. }
  1861. public void osSetPrimitiveParams(LSL_Key prim, LSL_List rules)
  1862. {
  1863. CheckThreatLevel(ThreatLevel.High, "osGetPrimitiveParams");
  1864. m_host.AddScriptLPS(1);
  1865. m_LSL_Api.SetPrimitiveParamsEx(prim, rules);
  1866. }
  1867. /// <summary>
  1868. /// Like osGetAgents but returns enough info for a radar
  1869. /// </summary>
  1870. /// <returns>Strided list of the UUID, position and name of each avatar in the region</returns>
  1871. public LSL_List osGetAvatarList()
  1872. {
  1873. CheckThreatLevel(ThreatLevel.None, "osGetAvatarList");
  1874. LSL_List result = new LSL_List();
  1875. World.ForEachScenePresence(delegate (ScenePresence avatar)
  1876. {
  1877. if (avatar != null && avatar.UUID != m_host.OwnerID)
  1878. {
  1879. if (avatar.IsChildAgent == false)
  1880. {
  1881. result.Add(avatar.UUID);
  1882. result.Add(avatar.AbsolutePosition);
  1883. result.Add(avatar.Name);
  1884. }
  1885. }
  1886. });
  1887. return result;
  1888. }
  1889. }
  1890. }