OSSL_Api.cs 141 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862
  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.IO;
  31. using System.Reflection;
  32. using System.Runtime.Remoting.Lifetime;
  33. using System.Text;
  34. using System.Net;
  35. using System.Threading;
  36. using System.Xml;
  37. using log4net;
  38. using OpenMetaverse;
  39. using OpenMetaverse.StructuredData;
  40. using Nini.Config;
  41. using OpenSim;
  42. using OpenSim.Framework;
  43. using OpenSim.Framework.Console;
  44. using OpenSim.Region.Framework.Interfaces;
  45. using OpenSim.Region.Framework.Scenes;
  46. using OpenSim.Region.ScriptEngine.Shared;
  47. using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
  48. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  49. using OpenSim.Region.ScriptEngine.Interfaces;
  50. using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
  51. using TPFlags = OpenSim.Framework.Constants.TeleportFlags;
  52. using OpenSim.Services.Interfaces;
  53. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  54. using System.Text.RegularExpressions;
  55. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  56. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  57. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  58. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  59. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  60. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  61. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  62. using PermissionMask = OpenSim.Framework.PermissionMask;
  63. namespace OpenSim.Region.ScriptEngine.Shared.Api
  64. {
  65. //////////////////////////////////////////////////////////////
  66. //
  67. // Level description
  68. //
  69. // None - Function is no threat at all. It doesn't constitute
  70. // an threat to either users or the system and has no
  71. // known side effects
  72. //
  73. // Nuisance - Abuse of this command can cause a nuisance to the
  74. // region operator, such as log message spew
  75. //
  76. // VeryLow - Extreme levels ob abuse of this function can cause
  77. // impaired functioning of the region, or very gullible
  78. // users can be tricked into experiencing harmless effects
  79. //
  80. // Low - Intentional abuse can cause crashes or malfunction
  81. // under certain circumstances, which can easily be rectified,
  82. // or certain users can be tricked into certain situations
  83. // in an avoidable manner.
  84. //
  85. // Moderate - Intentional abuse can cause denial of service and crashes
  86. // with potential of data or state loss, or trusting users
  87. // can be tricked into embarrassing or uncomfortable
  88. // situationsa.
  89. //
  90. // High - Casual abuse can cause impaired functionality or temporary
  91. // denial of service conditions. Intentional abuse can easily
  92. // cause crashes with potential data loss, or can be used to
  93. // trick experienced and cautious users into unwanted situations,
  94. // or changes global data permanently and without undo ability
  95. // Malicious scripting can allow theft of content
  96. //
  97. // VeryHigh - Even normal use may, depending on the number of instances,
  98. // or frequency of use, result in severe service impairment
  99. // or crash with loss of data, or can be used to cause
  100. // unwanted or harmful effects on users without giving the
  101. // user a means to avoid it.
  102. //
  103. // Severe - Even casual use is a danger to region stability, or function
  104. // allows console or OS command execution, or function allows
  105. // taking money without consent, or allows deletion or
  106. // modification of user data, or allows the compromise of
  107. // sensitive data by design.
  108. class FunctionPerms
  109. {
  110. public List<UUID> AllowedCreators;
  111. public List<UUID> AllowedOwners;
  112. public List<string> AllowedOwnerClasses;
  113. public FunctionPerms()
  114. {
  115. AllowedCreators = new List<UUID>();
  116. AllowedOwners = new List<UUID>();
  117. AllowedOwnerClasses = new List<string>();
  118. }
  119. }
  120. [Serializable]
  121. public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi
  122. {
  123. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  124. public const string GridInfoServiceConfigSectionName = "GridInfoService";
  125. internal IScriptEngine m_ScriptEngine;
  126. internal ILSL_Api m_LSL_Api = null; // get a reference to the LSL API so we can call methods housed there
  127. internal SceneObjectPart m_host;
  128. internal TaskInventoryItem m_item;
  129. internal bool m_OSFunctionsEnabled = false;
  130. internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow;
  131. internal float m_ScriptDelayFactor = 1.0f;
  132. internal float m_ScriptDistanceFactor = 1.0f;
  133. internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
  134. protected IUrlModule m_UrlModule = null;
  135. public void Initialize(
  136. IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, WaitHandle coopSleepHandle)
  137. {
  138. m_ScriptEngine = scriptEngine;
  139. m_host = host;
  140. m_item = item;
  141. m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
  142. if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  143. m_OSFunctionsEnabled = true;
  144. m_ScriptDelayFactor =
  145. m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
  146. m_ScriptDistanceFactor =
  147. m_ScriptEngine.Config.GetFloat("ScriptDistanceLimitFactor", 1.0f);
  148. string risk = m_ScriptEngine.Config.GetString("OSFunctionThreatLevel", "VeryLow");
  149. switch (risk)
  150. {
  151. case "NoAccess":
  152. m_MaxThreatLevel = ThreatLevel.NoAccess;
  153. break;
  154. case "None":
  155. m_MaxThreatLevel = ThreatLevel.None;
  156. break;
  157. case "VeryLow":
  158. m_MaxThreatLevel = ThreatLevel.VeryLow;
  159. break;
  160. case "Low":
  161. m_MaxThreatLevel = ThreatLevel.Low;
  162. break;
  163. case "Moderate":
  164. m_MaxThreatLevel = ThreatLevel.Moderate;
  165. break;
  166. case "High":
  167. m_MaxThreatLevel = ThreatLevel.High;
  168. break;
  169. case "VeryHigh":
  170. m_MaxThreatLevel = ThreatLevel.VeryHigh;
  171. break;
  172. case "Severe":
  173. m_MaxThreatLevel = ThreatLevel.Severe;
  174. break;
  175. default:
  176. break;
  177. }
  178. }
  179. public override Object InitializeLifetimeService()
  180. {
  181. ILease lease = (ILease)base.InitializeLifetimeService();
  182. if (lease.CurrentState == LeaseState.Initial)
  183. {
  184. lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
  185. // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
  186. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
  187. }
  188. return lease;
  189. }
  190. public Scene World
  191. {
  192. get { return m_ScriptEngine.World; }
  193. }
  194. internal void OSSLError(string msg)
  195. {
  196. throw new ScriptException("OSSL Runtime Error: " + msg);
  197. }
  198. /// <summary>
  199. /// Initialize the LSL interface.
  200. /// </summary>
  201. /// <remarks>
  202. /// FIXME: This is an abomination. We should be able to set this up earlier but currently we have no
  203. /// guarantee the interface is present on Initialize(). There needs to be another post initialize call from
  204. /// ScriptInstance.
  205. /// </remarks>
  206. private void InitLSL()
  207. {
  208. if (m_LSL_Api != null)
  209. return;
  210. m_LSL_Api = (ILSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "LSL");
  211. }
  212. //
  213. //Dumps an error message on the debug console.
  214. //
  215. internal void OSSLShoutError(string message)
  216. {
  217. if (message.Length > 1023)
  218. message = message.Substring(0, 1023);
  219. World.SimChat(Utils.StringToBytes(message),
  220. ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  221. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  222. wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
  223. }
  224. // Returns of the function is allowed. Throws a script exception if not allowed.
  225. public void CheckThreatLevel(ThreatLevel level, string function)
  226. {
  227. if (!m_OSFunctionsEnabled)
  228. OSSLError(String.Format("{0} permission denied. All OS functions are disabled.", function)); // throws
  229. string reasonWhyNot = CheckThreatLevelTest(level, function);
  230. if (!String.IsNullOrEmpty(reasonWhyNot))
  231. {
  232. OSSLError(reasonWhyNot);
  233. }
  234. }
  235. // Check to see if function is allowed. Returns an empty string if function permitted
  236. // or a string explaining why this function can't be used.
  237. private string CheckThreatLevelTest(ThreatLevel level, string function)
  238. {
  239. if (!m_FunctionPerms.ContainsKey(function))
  240. {
  241. FunctionPerms perms = new FunctionPerms();
  242. m_FunctionPerms[function] = perms;
  243. string ownerPerm = m_ScriptEngine.Config.GetString("Allow_" + function, "");
  244. string creatorPerm = m_ScriptEngine.Config.GetString("Creators_" + function, "");
  245. if (ownerPerm == "" && creatorPerm == "")
  246. {
  247. // Default behavior
  248. perms.AllowedOwners = null;
  249. perms.AllowedCreators = null;
  250. perms.AllowedOwnerClasses = null;
  251. }
  252. else
  253. {
  254. bool allowed;
  255. if (bool.TryParse(ownerPerm, out allowed))
  256. {
  257. // Boolean given
  258. if (allowed)
  259. {
  260. // Allow globally
  261. perms.AllowedOwners.Add(UUID.Zero);
  262. }
  263. }
  264. else
  265. {
  266. string[] ids = ownerPerm.Split(new char[] {','});
  267. foreach (string id in ids)
  268. {
  269. string current = id.Trim();
  270. if (current.ToUpper() == "PARCEL_GROUP_MEMBER" || current.ToUpper() == "PARCEL_OWNER" || current.ToUpper() == "ESTATE_MANAGER" || current.ToUpper() == "ESTATE_OWNER")
  271. {
  272. if (!perms.AllowedOwnerClasses.Contains(current))
  273. perms.AllowedOwnerClasses.Add(current.ToUpper());
  274. }
  275. else
  276. {
  277. UUID uuid;
  278. if (UUID.TryParse(current, out uuid))
  279. {
  280. if (uuid != UUID.Zero)
  281. perms.AllowedOwners.Add(uuid);
  282. }
  283. }
  284. }
  285. ids = creatorPerm.Split(new char[] {','});
  286. foreach (string id in ids)
  287. {
  288. string current = id.Trim();
  289. UUID uuid;
  290. if (UUID.TryParse(current, out uuid))
  291. {
  292. if (uuid != UUID.Zero)
  293. perms.AllowedCreators.Add(uuid);
  294. }
  295. }
  296. }
  297. }
  298. }
  299. // If the list is null, then the value was true / undefined
  300. // Threat level governs permissions in this case
  301. //
  302. // If the list is non-null, then it is a list of UUIDs allowed
  303. // to use that particular function. False causes an empty
  304. // list and therefore means "no one"
  305. //
  306. // To allow use by anyone, the list contains UUID.Zero
  307. //
  308. if (m_FunctionPerms[function].AllowedOwners == null)
  309. {
  310. // Allow / disallow by threat level
  311. if (level > m_MaxThreatLevel)
  312. return
  313. String.Format(
  314. "{0} permission denied. Allowed threat level is {1} but function threat level is {2}.",
  315. function, m_MaxThreatLevel, level);
  316. }
  317. else
  318. {
  319. if (!m_FunctionPerms[function].AllowedOwners.Contains(UUID.Zero))
  320. {
  321. // Not anyone. Do detailed checks
  322. if (m_FunctionPerms[function].AllowedOwners.Contains(m_host.OwnerID))
  323. {
  324. // prim owner is in the list of allowed owners
  325. return String.Empty;
  326. }
  327. UUID ownerID = m_item.OwnerID;
  328. //OSSL only may be used if object is in the same group as the parcel
  329. if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("PARCEL_GROUP_MEMBER"))
  330. {
  331. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  332. if (land.LandData.GroupID == m_item.GroupID && land.LandData.GroupID != UUID.Zero)
  333. {
  334. return String.Empty;
  335. }
  336. }
  337. //Only Parcelowners may use the function
  338. if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("PARCEL_OWNER"))
  339. {
  340. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  341. if (land.LandData.OwnerID == ownerID)
  342. {
  343. return String.Empty;
  344. }
  345. }
  346. //Only Estate Managers may use the function
  347. if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("ESTATE_MANAGER"))
  348. {
  349. //Only Estate Managers may use the function
  350. if (World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(ownerID) && World.RegionInfo.EstateSettings.EstateOwner != ownerID)
  351. {
  352. return String.Empty;
  353. }
  354. }
  355. //Only regionowners may use the function
  356. if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("ESTATE_OWNER"))
  357. {
  358. if (World.RegionInfo.EstateSettings.EstateOwner == ownerID)
  359. {
  360. return String.Empty;
  361. }
  362. }
  363. if (!m_FunctionPerms[function].AllowedCreators.Contains(m_item.CreatorID))
  364. return(
  365. 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.",
  366. function));
  367. if (m_item.CreatorID != ownerID)
  368. {
  369. if ((m_item.CurrentPermissions & (uint)PermissionMask.Modify) != 0)
  370. return String.Format("{0} permission denied. Script permissions error.", function);
  371. }
  372. }
  373. }
  374. return String.Empty;
  375. }
  376. internal void OSSLDeprecated(string function, string replacement)
  377. {
  378. OSSLShoutError(string.Format("Use of function {0} is deprecated. Use {1} instead.", function, replacement));
  379. }
  380. protected void ScriptSleep(int delay)
  381. {
  382. delay = (int)((float)delay * m_ScriptDelayFactor);
  383. if (delay == 0)
  384. return;
  385. System.Threading.Thread.Sleep(delay);
  386. }
  387. public LSL_Integer osSetTerrainHeight(int x, int y, double val)
  388. {
  389. CheckThreatLevel(ThreatLevel.High, "osSetTerrainHeight");
  390. return SetTerrainHeight(x, y, val);
  391. }
  392. public LSL_Integer osTerrainSetHeight(int x, int y, double val)
  393. {
  394. CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight");
  395. OSSLDeprecated("osTerrainSetHeight", "osSetTerrainHeight");
  396. return SetTerrainHeight(x, y, val);
  397. }
  398. private LSL_Integer SetTerrainHeight(int x, int y, double val)
  399. {
  400. m_host.AddScriptLPS(1);
  401. if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0)
  402. OSSLError("osSetTerrainHeight: Coordinate out of bounds");
  403. if (World.Permissions.CanTerraformLand(m_host.OwnerID, new Vector3(x, y, 0)))
  404. {
  405. World.Heightmap[x, y] = val;
  406. return 1;
  407. }
  408. else
  409. {
  410. return 0;
  411. }
  412. }
  413. public LSL_Float osGetTerrainHeight(int x, int y)
  414. {
  415. CheckThreatLevel(ThreatLevel.None, "osGetTerrainHeight");
  416. return GetTerrainHeight(x, y);
  417. }
  418. public LSL_Float osTerrainGetHeight(int x, int y)
  419. {
  420. CheckThreatLevel(ThreatLevel.None, "osTerrainGetHeight");
  421. OSSLDeprecated("osTerrainGetHeight", "osGetTerrainHeight");
  422. return GetTerrainHeight(x, y);
  423. }
  424. private LSL_Float GetTerrainHeight(int x, int y)
  425. {
  426. m_host.AddScriptLPS(1);
  427. if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0)
  428. OSSLError("osGetTerrainHeight: Coordinate out of bounds");
  429. return World.Heightmap[x, y];
  430. }
  431. public void osTerrainFlush()
  432. {
  433. CheckThreatLevel(ThreatLevel.VeryLow, "osTerrainFlush");
  434. m_host.AddScriptLPS(1);
  435. ITerrainModule terrainModule = World.RequestModuleInterface<ITerrainModule>();
  436. if (terrainModule != null) terrainModule.TaintTerrain();
  437. }
  438. public int osRegionRestart(double seconds)
  439. {
  440. // This is High here because region restart is not reliable
  441. // it may result in the region staying down or becoming
  442. // unstable. This should be changed to Low or VeryLow once
  443. // The underlying functionality is fixed, since the security
  444. // as such is sound
  445. //
  446. CheckThreatLevel(ThreatLevel.High, "osRegionRestart");
  447. IRestartModule restartModule = World.RequestModuleInterface<IRestartModule>();
  448. m_host.AddScriptLPS(1);
  449. if (World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false) && (restartModule != null))
  450. {
  451. if (seconds < 15)
  452. {
  453. restartModule.AbortRestart("Restart aborted");
  454. return 1;
  455. }
  456. List<int> times = new List<int>();
  457. while (seconds > 0)
  458. {
  459. times.Add((int)seconds);
  460. if (seconds > 300)
  461. seconds -= 120;
  462. else if (seconds > 30)
  463. seconds -= 30;
  464. else
  465. seconds -= 15;
  466. }
  467. restartModule.ScheduleRestart(UUID.Zero, "Region will restart in {0}", times.ToArray(), true);
  468. return 1;
  469. }
  470. else
  471. {
  472. return 0;
  473. }
  474. }
  475. public void osRegionNotice(string msg)
  476. {
  477. // This implementation provides absolutely no security
  478. // It's high griefing potential makes this classification
  479. // necessary
  480. //
  481. CheckThreatLevel(ThreatLevel.VeryHigh, "osRegionNotice");
  482. m_host.AddScriptLPS(1);
  483. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  484. if (dm != null)
  485. dm.SendGeneralAlert(msg);
  486. }
  487. public void osSetRot(UUID target, Quaternion rotation)
  488. {
  489. // This function has no security. It can be used to destroy
  490. // arbitrary builds the user would normally have no rights to
  491. //
  492. CheckThreatLevel(ThreatLevel.VeryHigh, "osSetRot");
  493. m_host.AddScriptLPS(1);
  494. if (World.Entities.ContainsKey(target))
  495. {
  496. EntityBase entity;
  497. if (World.Entities.TryGetValue(target, out entity))
  498. {
  499. if (entity is SceneObjectGroup)
  500. ((SceneObjectGroup)entity).UpdateGroupRotationR(rotation);
  501. else if (entity is ScenePresence)
  502. ((ScenePresence)entity).Rotation = rotation;
  503. }
  504. }
  505. else
  506. {
  507. OSSLError("osSetRot: Invalid target");
  508. }
  509. }
  510. public string osSetDynamicTextureURL(string dynamicID, string contentType, string url, string extraParams,
  511. int timer)
  512. {
  513. // This may be upgraded depending on the griefing or DOS
  514. // potential, or guarded with a delay
  515. //
  516. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURL");
  517. m_host.AddScriptLPS(1);
  518. if (dynamicID == String.Empty)
  519. {
  520. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  521. UUID createdTexture =
  522. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  523. extraParams, timer);
  524. return createdTexture.ToString();
  525. }
  526. else
  527. {
  528. //TODO update existing dynamic textures
  529. }
  530. return UUID.Zero.ToString();
  531. }
  532. public string osSetDynamicTextureURLBlend(string dynamicID, string contentType, string url, string extraParams,
  533. int timer, int alpha)
  534. {
  535. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURLBlend");
  536. m_host.AddScriptLPS(1);
  537. if (dynamicID == String.Empty)
  538. {
  539. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  540. UUID createdTexture =
  541. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  542. extraParams, timer, true, (byte) alpha);
  543. return createdTexture.ToString();
  544. }
  545. else
  546. {
  547. //TODO update existing dynamic textures
  548. }
  549. return UUID.Zero.ToString();
  550. }
  551. public string osSetDynamicTextureURLBlendFace(string dynamicID, string contentType, string url, string extraParams,
  552. bool blend, int disp, int timer, int alpha, int face)
  553. {
  554. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURLBlendFace");
  555. m_host.AddScriptLPS(1);
  556. if (dynamicID == String.Empty)
  557. {
  558. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  559. UUID createdTexture =
  560. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  561. extraParams, timer, blend, disp, (byte) alpha, face);
  562. return createdTexture.ToString();
  563. }
  564. else
  565. {
  566. //TODO update existing dynamic textures
  567. }
  568. return UUID.Zero.ToString();
  569. }
  570. public string osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams,
  571. int timer)
  572. {
  573. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureData");
  574. m_host.AddScriptLPS(1);
  575. if (dynamicID == String.Empty)
  576. {
  577. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  578. if (textureManager != null)
  579. {
  580. if (extraParams == String.Empty)
  581. {
  582. extraParams = "256";
  583. }
  584. UUID createdTexture =
  585. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  586. extraParams, timer);
  587. return createdTexture.ToString();
  588. }
  589. }
  590. else
  591. {
  592. //TODO update existing dynamic textures
  593. }
  594. return UUID.Zero.ToString();
  595. }
  596. public string osSetDynamicTextureDataBlend(string dynamicID, string contentType, string data, string extraParams,
  597. int timer, int alpha)
  598. {
  599. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureDataBlend");
  600. m_host.AddScriptLPS(1);
  601. if (dynamicID == String.Empty)
  602. {
  603. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  604. if (textureManager != null)
  605. {
  606. if (extraParams == String.Empty)
  607. {
  608. extraParams = "256";
  609. }
  610. UUID createdTexture =
  611. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  612. extraParams, timer, true, (byte) alpha);
  613. return createdTexture.ToString();
  614. }
  615. }
  616. else
  617. {
  618. //TODO update existing dynamic textures
  619. }
  620. return UUID.Zero.ToString();
  621. }
  622. public string osSetDynamicTextureDataBlendFace(string dynamicID, string contentType, string data, string extraParams,
  623. bool blend, int disp, int timer, int alpha, int face)
  624. {
  625. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureDataBlendFace");
  626. m_host.AddScriptLPS(1);
  627. if (dynamicID == String.Empty)
  628. {
  629. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  630. if (textureManager != null)
  631. {
  632. if (extraParams == String.Empty)
  633. {
  634. extraParams = "256";
  635. }
  636. UUID createdTexture =
  637. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  638. extraParams, timer, blend, disp, (byte) alpha, face);
  639. return createdTexture.ToString();
  640. }
  641. }
  642. else
  643. {
  644. //TODO update existing dynamic textures
  645. }
  646. return UUID.Zero.ToString();
  647. }
  648. public bool osConsoleCommand(string command)
  649. {
  650. CheckThreatLevel(ThreatLevel.Severe, "osConsoleCommand");
  651. m_host.AddScriptLPS(1);
  652. // For safety, we add another permission check here, and don't rely only on the standard OSSL permissions
  653. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  654. {
  655. MainConsole.Instance.RunCommand(command);
  656. return true;
  657. }
  658. return false;
  659. }
  660. public void osSetPrimFloatOnWater(int floatYN)
  661. {
  662. CheckThreatLevel(ThreatLevel.VeryLow, "osSetPrimFloatOnWater");
  663. m_host.AddScriptLPS(1);
  664. m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN);
  665. }
  666. // Teleport functions
  667. public void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  668. {
  669. // High because there is no security check. High griefer potential
  670. //
  671. CheckThreatLevel(ThreatLevel.Severe, "osTeleportAgent");
  672. TeleportAgent(agent, regionName, position, lookat, false);
  673. }
  674. private void TeleportAgent(string agent, string regionName,
  675. LSL_Types.Vector3 position, LSL_Types.Vector3 lookat, bool relaxRestrictions)
  676. {
  677. m_host.AddScriptLPS(1);
  678. UUID agentId = new UUID();
  679. if (UUID.TryParse(agent, out agentId))
  680. {
  681. ScenePresence presence = World.GetScenePresence(agentId);
  682. if (presence != null)
  683. {
  684. // For osTeleportAgent, agent must be over owners land to avoid abuse
  685. // For osTeleportOwner, this restriction isn't necessary
  686. // commented out because its redundant and uneeded please remove eventually.
  687. // if (relaxRestrictions ||
  688. // m_host.OwnerID
  689. // == World.LandChannel.GetLandObject(
  690. // presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
  691. // {
  692. // We will launch the teleport on a new thread so that when the script threads are terminated
  693. // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting.
  694. Util.FireAndForget(
  695. o => World.RequestTeleportLocation(
  696. presence.ControllingClient, regionName, position,
  697. lookat, (uint)TPFlags.ViaLocation),
  698. null, "OSSL_Api.TeleportAgentByRegionCoords");
  699. ScriptSleep(5000);
  700. // }
  701. }
  702. }
  703. }
  704. public void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  705. {
  706. // High because there is no security check. High griefer potential
  707. //
  708. CheckThreatLevel(ThreatLevel.Severe, "osTeleportAgent");
  709. TeleportAgent(agent, regionX, regionY, position, lookat, false);
  710. }
  711. private void TeleportAgent(string agent, int regionX, int regionY,
  712. LSL_Types.Vector3 position, LSL_Types.Vector3 lookat, bool relaxRestrictions)
  713. {
  714. // ulong regionHandle = Util.UIntsToLong(((uint)regionX * (uint)Constants.RegionSize), ((uint)regionY * (uint)Constants.RegionSize));
  715. ulong regionHandle = Util.RegionLocToHandle((uint)regionX, (uint)regionY);
  716. m_host.AddScriptLPS(1);
  717. UUID agentId = new UUID();
  718. if (UUID.TryParse(agent, out agentId))
  719. {
  720. ScenePresence presence = World.GetScenePresence(agentId);
  721. if (presence != null)
  722. {
  723. // For osTeleportAgent, agent must be over owners land to avoid abuse
  724. // For osTeleportOwner, this restriction isn't necessary
  725. // commented out because its redundant and uneeded please remove eventually.
  726. // if (relaxRestrictions ||
  727. // m_host.OwnerID
  728. // == World.LandChannel.GetLandObject(
  729. // presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
  730. // {
  731. // We will launch the teleport on a new thread so that when the script threads are terminated
  732. // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting.
  733. Util.FireAndForget(
  734. o => World.RequestTeleportLocation(
  735. presence.ControllingClient, regionHandle,
  736. position, lookat, (uint)TPFlags.ViaLocation),
  737. null, "OSSL_Api.TeleportAgentByRegionName");
  738. ScriptSleep(5000);
  739. // }
  740. }
  741. }
  742. }
  743. public void osTeleportAgent(string agent, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  744. {
  745. osTeleportAgent(agent, World.RegionInfo.RegionName, position, lookat);
  746. }
  747. public void osTeleportOwner(string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  748. {
  749. // Threat level None because this is what can already be done with the World Map in the viewer
  750. CheckThreatLevel(ThreatLevel.None, "osTeleportOwner");
  751. TeleportAgent(m_host.OwnerID.ToString(), regionName, position, lookat, true);
  752. }
  753. public void osTeleportOwner(LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  754. {
  755. osTeleportOwner(World.RegionInfo.RegionName, position, lookat);
  756. }
  757. public void osTeleportOwner(int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  758. {
  759. CheckThreatLevel(ThreatLevel.None, "osTeleportOwner");
  760. TeleportAgent(m_host.OwnerID.ToString(), regionX, regionY, position, lookat, true);
  761. }
  762. ///<summary>
  763. /// Allows a script IN the target prim to force an avatar to sit on it using normal methods
  764. /// as if called by the client.
  765. /// Silent fail if agent (or target if overloaded) not found.
  766. /// Does work if passed key (or keys if overloaded).
  767. /// </summary>
  768. /// <param name="avatar"></param>
  769. public void osForceOtherSit(string avatar)
  770. {
  771. CheckThreatLevel(ThreatLevel.VeryHigh, "osForceOtherSit");
  772. m_host.AddScriptLPS(1);
  773. ForceSit(avatar, m_host.UUID);
  774. }
  775. /// <summary>
  776. /// Overload method of osForceOtherSit(string avatar) to allow a script NOT in the target prim to force
  777. /// an avatar to sit on the target prim using normal methods as if called by the client.
  778. /// </summary>
  779. /// <param name="avatar"></param>
  780. /// <param name="target"></param>
  781. public void osForceOtherSit(string avatar, string target)
  782. {
  783. CheckThreatLevel(ThreatLevel.VeryHigh, "osForceOtherSit");
  784. m_host.AddScriptLPS(1);
  785. UUID targetID = new UUID(target);
  786. ForceSit(avatar, targetID);
  787. }
  788. public void ForceSit(string avatar, UUID targetID)
  789. {
  790. UUID agentID;
  791. if (!UUID.TryParse(avatar, out agentID))
  792. return;
  793. ScenePresence presence = World.GetScenePresence(agentID);
  794. SceneObjectPart part = World.GetSceneObjectPart(targetID);
  795. if (presence != null &&
  796. part != null &&
  797. part.SitTargetAvatar == UUID.Zero)
  798. presence.HandleAgentRequestSit(presence.ControllingClient,
  799. agentID,
  800. targetID,
  801. part.SitTargetPosition);
  802. }
  803. // Functions that get information from the agent itself.
  804. //
  805. // osGetAgentIP - this is used to determine the IP address of
  806. //the client. This is needed to help configure other in world
  807. //resources based on the IP address of the clients connected.
  808. //I think High is a good risk level for this, as it is an
  809. //information leak.
  810. public string osGetAgentIP(string agent)
  811. {
  812. CheckThreatLevel(ThreatLevel.High, "osGetAgentIP");
  813. UUID avatarID = (UUID)agent;
  814. m_host.AddScriptLPS(1);
  815. if (World.Entities.ContainsKey((UUID)agent) && World.Entities[avatarID] is ScenePresence)
  816. {
  817. ScenePresence target = (ScenePresence)World.Entities[avatarID];
  818. return target.ControllingClient.RemoteEndPoint.Address.ToString();
  819. }
  820. // fall through case, just return nothing
  821. return "";
  822. }
  823. // Get a list of all the avatars/agents in the region
  824. public LSL_List osGetAgents()
  825. {
  826. // threat level is None as we could get this information with an
  827. // in-world script as well, just not as efficient
  828. CheckThreatLevel(ThreatLevel.None, "osGetAgents");
  829. m_host.AddScriptLPS(1);
  830. LSL_List result = new LSL_List();
  831. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  832. {
  833. result.Add(new LSL_String(sp.Name));
  834. });
  835. return result;
  836. }
  837. // Adam's super super custom animation functions
  838. public void osAvatarPlayAnimation(string avatar, string animation)
  839. {
  840. CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarPlayAnimation");
  841. AvatarPlayAnimation(avatar, animation);
  842. }
  843. private void AvatarPlayAnimation(string avatar, string animation)
  844. {
  845. UUID avatarID = (UUID)avatar;
  846. m_host.AddScriptLPS(1);
  847. if (World.Entities.ContainsKey((UUID)avatar) && World.Entities[avatarID] is ScenePresence)
  848. {
  849. ScenePresence target = (ScenePresence)World.Entities[avatarID];
  850. if (target != null)
  851. {
  852. UUID animID=UUID.Zero;
  853. lock (m_host.TaskInventory)
  854. {
  855. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  856. {
  857. if (inv.Value.Name == animation)
  858. {
  859. if (inv.Value.Type == (int)AssetType.Animation)
  860. animID = inv.Value.AssetID;
  861. continue;
  862. }
  863. }
  864. }
  865. if (animID == UUID.Zero)
  866. target.Animator.AddAnimation(animation, m_host.UUID);
  867. else
  868. target.Animator.AddAnimation(animID, m_host.UUID);
  869. }
  870. }
  871. }
  872. public void osAvatarStopAnimation(string avatar, string animation)
  873. {
  874. CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarStopAnimation");
  875. AvatarStopAnimation(avatar, animation);
  876. }
  877. private void AvatarStopAnimation(string avatar, string animation)
  878. {
  879. UUID avatarID = (UUID)avatar;
  880. m_host.AddScriptLPS(1);
  881. // FIXME: What we really want to do here is factor out the similar code in llStopAnimation() to a common
  882. // method (though see that doesn't do the is animation check, which is probably a bug) and have both
  883. // these functions call that common code. However, this does mean navigating the brain-dead requirement
  884. // of calling InitLSL()
  885. if (World.Entities.ContainsKey(avatarID) && World.Entities[avatarID] is ScenePresence)
  886. {
  887. ScenePresence target = (ScenePresence)World.Entities[avatarID];
  888. if (target != null)
  889. {
  890. UUID animID;
  891. if (!UUID.TryParse(animation, out animID))
  892. {
  893. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(animation);
  894. if (item != null && item.Type == (int)AssetType.Animation)
  895. animID = item.AssetID;
  896. else
  897. animID = UUID.Zero;
  898. }
  899. if (animID == UUID.Zero)
  900. target.Animator.RemoveAnimation(animation);
  901. else
  902. target.Animator.RemoveAnimation(animID, true);
  903. }
  904. }
  905. }
  906. //Texture draw functions
  907. public string osMovePen(string drawList, int x, int y)
  908. {
  909. CheckThreatLevel(ThreatLevel.None, "osMovePen");
  910. m_host.AddScriptLPS(1);
  911. drawList += "MoveTo " + x + "," + y + ";";
  912. return drawList;
  913. }
  914. public string osDrawLine(string drawList, int startX, int startY, int endX, int endY)
  915. {
  916. CheckThreatLevel(ThreatLevel.None, "osDrawLine");
  917. m_host.AddScriptLPS(1);
  918. drawList += "MoveTo "+ startX+","+ startY +"; LineTo "+endX +","+endY +"; ";
  919. return drawList;
  920. }
  921. public string osDrawLine(string drawList, int endX, int endY)
  922. {
  923. CheckThreatLevel(ThreatLevel.None, "osDrawLine");
  924. m_host.AddScriptLPS(1);
  925. drawList += "LineTo " + endX + "," + endY + "; ";
  926. return drawList;
  927. }
  928. public string osDrawText(string drawList, string text)
  929. {
  930. CheckThreatLevel(ThreatLevel.None, "osDrawText");
  931. m_host.AddScriptLPS(1);
  932. drawList += "Text " + text + "; ";
  933. return drawList;
  934. }
  935. public string osDrawEllipse(string drawList, int width, int height)
  936. {
  937. CheckThreatLevel(ThreatLevel.None, "osDrawEllipse");
  938. m_host.AddScriptLPS(1);
  939. drawList += "Ellipse " + width + "," + height + "; ";
  940. return drawList;
  941. }
  942. public string osDrawRectangle(string drawList, int width, int height)
  943. {
  944. CheckThreatLevel(ThreatLevel.None, "osDrawRectangle");
  945. m_host.AddScriptLPS(1);
  946. drawList += "Rectangle " + width + "," + height + "; ";
  947. return drawList;
  948. }
  949. public string osDrawFilledRectangle(string drawList, int width, int height)
  950. {
  951. CheckThreatLevel(ThreatLevel.None, "osDrawFilledRectangle");
  952. m_host.AddScriptLPS(1);
  953. drawList += "FillRectangle " + width + "," + height + "; ";
  954. return drawList;
  955. }
  956. public string osDrawFilledPolygon(string drawList, LSL_List x, LSL_List y)
  957. {
  958. CheckThreatLevel(ThreatLevel.None, "osDrawFilledPolygon");
  959. m_host.AddScriptLPS(1);
  960. if (x.Length != y.Length || x.Length < 3)
  961. {
  962. return "";
  963. }
  964. drawList += "FillPolygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
  965. for (int i = 1; i < x.Length; i++)
  966. {
  967. drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
  968. }
  969. drawList += "; ";
  970. return drawList;
  971. }
  972. public string osDrawPolygon(string drawList, LSL_List x, LSL_List y)
  973. {
  974. CheckThreatLevel(ThreatLevel.None, "osDrawPolygon");
  975. m_host.AddScriptLPS(1);
  976. if (x.Length != y.Length || x.Length < 3)
  977. {
  978. return "";
  979. }
  980. drawList += "Polygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
  981. for (int i = 1; i < x.Length; i++)
  982. {
  983. drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
  984. }
  985. drawList += "; ";
  986. return drawList;
  987. }
  988. public string osSetFontSize(string drawList, int fontSize)
  989. {
  990. CheckThreatLevel(ThreatLevel.None, "osSetFontSize");
  991. m_host.AddScriptLPS(1);
  992. drawList += "FontSize "+ fontSize +"; ";
  993. return drawList;
  994. }
  995. public string osSetFontName(string drawList, string fontName)
  996. {
  997. CheckThreatLevel(ThreatLevel.None, "osSetFontName");
  998. m_host.AddScriptLPS(1);
  999. drawList += "FontName "+ fontName +"; ";
  1000. return drawList;
  1001. }
  1002. public string osSetPenSize(string drawList, int penSize)
  1003. {
  1004. CheckThreatLevel(ThreatLevel.None, "osSetPenSize");
  1005. m_host.AddScriptLPS(1);
  1006. drawList += "PenSize " + penSize + "; ";
  1007. return drawList;
  1008. }
  1009. public string osSetPenColor(string drawList, string color)
  1010. {
  1011. CheckThreatLevel(ThreatLevel.None, "osSetPenColor");
  1012. m_host.AddScriptLPS(1);
  1013. drawList += "PenColor " + color + "; ";
  1014. return drawList;
  1015. }
  1016. // Deprecated
  1017. public string osSetPenColour(string drawList, string colour)
  1018. {
  1019. CheckThreatLevel(ThreatLevel.None, "osSetPenColour");
  1020. OSSLDeprecated("osSetPenColour", "osSetPenColor");
  1021. m_host.AddScriptLPS(1);
  1022. drawList += "PenColour " + colour + "; ";
  1023. return drawList;
  1024. }
  1025. public string osSetPenCap(string drawList, string direction, string type)
  1026. {
  1027. CheckThreatLevel(ThreatLevel.None, "osSetPenCap");
  1028. m_host.AddScriptLPS(1);
  1029. drawList += "PenCap " + direction + "," + type + "; ";
  1030. return drawList;
  1031. }
  1032. public string osDrawImage(string drawList, int width, int height, string imageUrl)
  1033. {
  1034. CheckThreatLevel(ThreatLevel.None, "osDrawImage");
  1035. m_host.AddScriptLPS(1);
  1036. drawList +="Image " +width + "," + height+ ","+ imageUrl +"; " ;
  1037. return drawList;
  1038. }
  1039. public LSL_Vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize)
  1040. {
  1041. CheckThreatLevel(ThreatLevel.VeryLow, "osGetDrawStringSize");
  1042. m_host.AddScriptLPS(1);
  1043. LSL_Vector vec = new LSL_Vector(0,0,0);
  1044. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  1045. if (textureManager != null)
  1046. {
  1047. double xSize, ySize;
  1048. textureManager.GetDrawStringSize(contentType, text, fontName, fontSize,
  1049. out xSize, out ySize);
  1050. vec.x = xSize;
  1051. vec.y = ySize;
  1052. }
  1053. return vec;
  1054. }
  1055. public void osSetStateEvents(int events)
  1056. {
  1057. // This function is a hack. There is no reason for it's existence
  1058. // anymore, since state events now work properly.
  1059. // It was probably added as a crutch or debugging aid, and
  1060. // should be removed
  1061. //
  1062. CheckThreatLevel(ThreatLevel.High, "osSetStateEvents");
  1063. m_host.AddScriptLPS(1);
  1064. m_host.SetScriptEvents(m_item.ItemID, events);
  1065. }
  1066. public void osSetRegionWaterHeight(double height)
  1067. {
  1068. CheckThreatLevel(ThreatLevel.High, "osSetRegionWaterHeight");
  1069. m_host.AddScriptLPS(1);
  1070. World.EventManager.TriggerRequestChangeWaterHeight((float)height);
  1071. }
  1072. /// <summary>
  1073. /// Changes the Region Sun Settings, then Triggers a Sun Update
  1074. /// </summary>
  1075. /// <param name="useEstateSun">True to use Estate Sun instead of Region Sun</param>
  1076. /// <param name="sunFixed">True to keep the sun stationary</param>
  1077. /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
  1078. public void osSetRegionSunSettings(bool useEstateSun, bool sunFixed, double sunHour)
  1079. {
  1080. CheckThreatLevel(ThreatLevel.High, "osSetRegionSunSettings");
  1081. m_host.AddScriptLPS(1);
  1082. while (sunHour > 24.0)
  1083. sunHour -= 24.0;
  1084. while (sunHour < 0)
  1085. sunHour += 24.0;
  1086. World.RegionInfo.RegionSettings.UseEstateSun = useEstateSun;
  1087. World.RegionInfo.RegionSettings.SunPosition = sunHour + 6; // LL Region Sun Hour is 6 to 30
  1088. World.RegionInfo.RegionSettings.FixedSun = sunFixed;
  1089. World.RegionInfo.RegionSettings.Save();
  1090. World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle);
  1091. }
  1092. /// <summary>
  1093. /// Changes the Estate Sun Settings, then Triggers a Sun Update
  1094. /// </summary>
  1095. /// <param name="sunFixed">True to keep the sun stationary, false to use global time</param>
  1096. /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
  1097. public void osSetEstateSunSettings(bool sunFixed, double sunHour)
  1098. {
  1099. CheckThreatLevel(ThreatLevel.High, "osSetEstateSunSettings");
  1100. m_host.AddScriptLPS(1);
  1101. while (sunHour > 24.0)
  1102. sunHour -= 24.0;
  1103. while (sunHour < 0)
  1104. sunHour += 24.0;
  1105. World.RegionInfo.EstateSettings.UseGlobalTime = !sunFixed;
  1106. World.RegionInfo.EstateSettings.SunPosition = sunHour;
  1107. World.RegionInfo.EstateSettings.FixedSun = sunFixed;
  1108. World.EstateDataService.StoreEstateSettings(World.RegionInfo.EstateSettings);
  1109. World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle);
  1110. }
  1111. /// <summary>
  1112. /// Return the current Sun Hour 0...24, with 0 being roughly sun-rise
  1113. /// </summary>
  1114. /// <returns></returns>
  1115. public double osGetCurrentSunHour()
  1116. {
  1117. CheckThreatLevel(ThreatLevel.None, "osGetCurrentSunHour");
  1118. m_host.AddScriptLPS(1);
  1119. // Must adjust for the fact that Region Sun Settings are still LL offset
  1120. double sunHour = World.RegionInfo.RegionSettings.SunPosition - 6;
  1121. // See if the sun module has registered itself, if so it's authoritative
  1122. ISunModule module = World.RequestModuleInterface<ISunModule>();
  1123. if (module != null)
  1124. {
  1125. sunHour = module.GetCurrentSunHour();
  1126. }
  1127. return sunHour;
  1128. }
  1129. public double osSunGetParam(string param)
  1130. {
  1131. CheckThreatLevel(ThreatLevel.None, "osSunGetParam");
  1132. OSSLDeprecated("osSunGetParam", "osGetSunParam");
  1133. return GetSunParam(param);
  1134. }
  1135. public double osGetSunParam(string param)
  1136. {
  1137. CheckThreatLevel(ThreatLevel.None, "osGetSunParam");
  1138. return GetSunParam(param);
  1139. }
  1140. private double GetSunParam(string param)
  1141. {
  1142. m_host.AddScriptLPS(1);
  1143. double value = 0.0;
  1144. ISunModule module = World.RequestModuleInterface<ISunModule>();
  1145. if (module != null)
  1146. {
  1147. value = module.GetSunParameter(param);
  1148. }
  1149. return value;
  1150. }
  1151. public void osSunSetParam(string param, double value)
  1152. {
  1153. CheckThreatLevel(ThreatLevel.None, "osSunSetParam");
  1154. OSSLDeprecated("osSunSetParam", "osSetSunParam");
  1155. SetSunParam(param, value);
  1156. }
  1157. public void osSetSunParam(string param, double value)
  1158. {
  1159. CheckThreatLevel(ThreatLevel.None, "osSetSunParam");
  1160. SetSunParam(param, value);
  1161. }
  1162. private void SetSunParam(string param, double value)
  1163. {
  1164. m_host.AddScriptLPS(1);
  1165. ISunModule module = World.RequestModuleInterface<ISunModule>();
  1166. if (module != null)
  1167. {
  1168. module.SetSunParameter(param, value);
  1169. }
  1170. }
  1171. public string osWindActiveModelPluginName()
  1172. {
  1173. CheckThreatLevel(ThreatLevel.None, "osWindActiveModelPluginName");
  1174. m_host.AddScriptLPS(1);
  1175. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1176. if (module != null)
  1177. {
  1178. return module.WindActiveModelPluginName;
  1179. }
  1180. return String.Empty;
  1181. }
  1182. public void osSetWindParam(string plugin, string param, LSL_Float value)
  1183. {
  1184. CheckThreatLevel(ThreatLevel.VeryLow, "osSetWindParam");
  1185. m_host.AddScriptLPS(1);
  1186. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1187. if (module != null)
  1188. {
  1189. try
  1190. {
  1191. module.WindParamSet(plugin, param, (float)value);
  1192. }
  1193. catch (Exception) { }
  1194. }
  1195. }
  1196. public LSL_Float osGetWindParam(string plugin, string param)
  1197. {
  1198. CheckThreatLevel(ThreatLevel.VeryLow, "osGetWindParam");
  1199. m_host.AddScriptLPS(1);
  1200. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1201. if (module != null)
  1202. {
  1203. return module.WindParamGet(plugin, param);
  1204. }
  1205. return 0.0f;
  1206. }
  1207. // Routines for creating and managing parcels programmatically
  1208. public void osParcelJoin(LSL_Vector pos1, LSL_Vector pos2)
  1209. {
  1210. CheckThreatLevel(ThreatLevel.High, "osParcelJoin");
  1211. m_host.AddScriptLPS(1);
  1212. int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
  1213. int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
  1214. int endx = (int)(pos1.x > pos2.x ? pos1.x : pos2.x);
  1215. int endy = (int)(pos1.y > pos2.y ? pos1.y : pos2.y);
  1216. World.LandChannel.Join(startx,starty,endx,endy,m_host.OwnerID);
  1217. }
  1218. public void osParcelSubdivide(LSL_Vector pos1, LSL_Vector pos2)
  1219. {
  1220. CheckThreatLevel(ThreatLevel.High, "osParcelSubdivide");
  1221. m_host.AddScriptLPS(1);
  1222. int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
  1223. int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
  1224. int endx = (int)(pos1.x > pos2.x ? pos1.x : pos2.x);
  1225. int endy = (int)(pos1.y > pos2.y ? pos1.y : pos2.y);
  1226. World.LandChannel.Subdivide(startx,starty,endx,endy,m_host.OwnerID);
  1227. }
  1228. public void osParcelSetDetails(LSL_Vector pos, LSL_List rules)
  1229. {
  1230. const string functionName = "osParcelSetDetails";
  1231. CheckThreatLevel(ThreatLevel.High, functionName);
  1232. OSSLDeprecated(functionName, "osSetParcelDetails");
  1233. SetParcelDetails(pos, rules, functionName);
  1234. }
  1235. public void osSetParcelDetails(LSL_Vector pos, LSL_List rules)
  1236. {
  1237. const string functionName = "osSetParcelDetails";
  1238. CheckThreatLevel(ThreatLevel.High, functionName);
  1239. SetParcelDetails(pos, rules, functionName);
  1240. }
  1241. private void SetParcelDetails(LSL_Vector pos, LSL_List rules, string functionName)
  1242. {
  1243. m_host.AddScriptLPS(1);
  1244. // Get a reference to the land data and make sure the owner of the script
  1245. // can modify it
  1246. ILandObject startLandObject = World.LandChannel.GetLandObject((int)pos.x, (int)pos.y);
  1247. if (startLandObject == null)
  1248. {
  1249. OSSLShoutError("There is no land at that location");
  1250. return;
  1251. }
  1252. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, startLandObject, GroupPowers.LandOptions))
  1253. {
  1254. OSSLShoutError("You do not have permission to modify the parcel");
  1255. return;
  1256. }
  1257. // Create a new land data object we can modify
  1258. LandData newLand = startLandObject.LandData.Copy();
  1259. UUID uuid;
  1260. // Process the rules, not sure what the impact would be of changing owner or group
  1261. for (int idx = 0; idx < rules.Length;)
  1262. {
  1263. int code = rules.GetLSLIntegerItem(idx++);
  1264. string arg = rules.GetLSLStringItem(idx++);
  1265. switch (code)
  1266. {
  1267. case ScriptBaseClass.PARCEL_DETAILS_NAME:
  1268. newLand.Name = arg;
  1269. break;
  1270. case ScriptBaseClass.PARCEL_DETAILS_DESC:
  1271. newLand.Description = arg;
  1272. break;
  1273. case ScriptBaseClass.PARCEL_DETAILS_OWNER:
  1274. CheckThreatLevel(ThreatLevel.VeryHigh, functionName);
  1275. if (UUID.TryParse(arg, out uuid))
  1276. newLand.OwnerID = uuid;
  1277. break;
  1278. case ScriptBaseClass.PARCEL_DETAILS_GROUP:
  1279. CheckThreatLevel(ThreatLevel.VeryHigh, functionName);
  1280. if (UUID.TryParse(arg, out uuid))
  1281. newLand.GroupID = uuid;
  1282. break;
  1283. case ScriptBaseClass.PARCEL_DETAILS_CLAIMDATE:
  1284. CheckThreatLevel(ThreatLevel.VeryHigh, functionName);
  1285. newLand.ClaimDate = Convert.ToInt32(arg);
  1286. if (newLand.ClaimDate == 0)
  1287. newLand.ClaimDate = Util.UnixTimeSinceEpoch();
  1288. break;
  1289. }
  1290. }
  1291. World.LandChannel.UpdateLandObject(newLand.LocalID,newLand);
  1292. }
  1293. public double osList2Double(LSL_Types.list src, int index)
  1294. {
  1295. // There is really no double type in OSSL. C# and other
  1296. // have one, but the current implementation of LSL_Types.list
  1297. // is not allowed to contain any.
  1298. // This really should be removed.
  1299. //
  1300. CheckThreatLevel(ThreatLevel.None, "osList2Double");
  1301. m_host.AddScriptLPS(1);
  1302. if (index < 0)
  1303. {
  1304. index = src.Length + index;
  1305. }
  1306. if (index >= src.Length)
  1307. {
  1308. return 0.0;
  1309. }
  1310. return Convert.ToDouble(src.Data[index]);
  1311. }
  1312. public void osSetParcelMediaURL(string url)
  1313. {
  1314. // What actually is the difference to the LL function?
  1315. //
  1316. CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL");
  1317. m_host.AddScriptLPS(1);
  1318. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  1319. if (land.LandData.OwnerID != m_host.OwnerID)
  1320. return;
  1321. land.SetMediaUrl(url);
  1322. }
  1323. public void osSetParcelSIPAddress(string SIPAddress)
  1324. {
  1325. // What actually is the difference to the LL function?
  1326. //
  1327. CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelSIPAddress");
  1328. m_host.AddScriptLPS(1);
  1329. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  1330. if (land.LandData.OwnerID != m_host.OwnerID)
  1331. {
  1332. OSSLError("osSetParcelSIPAddress: Sorry, you need to own the land to use this function");
  1333. return;
  1334. }
  1335. // get the voice module
  1336. IVoiceModule voiceModule = World.RequestModuleInterface<IVoiceModule>();
  1337. if (voiceModule != null)
  1338. voiceModule.setLandSIPAddress(SIPAddress,land.LandData.GlobalID);
  1339. else
  1340. OSSLError("osSetParcelSIPAddress: No voice module enabled for this land");
  1341. }
  1342. public string osGetScriptEngineName()
  1343. {
  1344. // This gets a "high" because knowing the engine may be used
  1345. // to exploit engine-specific bugs or induce usage patterns
  1346. // that trigger engine-specific failures.
  1347. // Besides, public grid users aren't supposed to know.
  1348. //
  1349. CheckThreatLevel(ThreatLevel.High, "osGetScriptEngineName");
  1350. m_host.AddScriptLPS(1);
  1351. int scriptEngineNameIndex = 0;
  1352. if (!String.IsNullOrEmpty(m_ScriptEngine.ScriptEngineName))
  1353. {
  1354. // parse off the "ScriptEngine."
  1355. scriptEngineNameIndex = m_ScriptEngine.ScriptEngineName.IndexOf(".", scriptEngineNameIndex);
  1356. scriptEngineNameIndex++; // get past delimiter
  1357. int scriptEngineNameLength = m_ScriptEngine.ScriptEngineName.Length - scriptEngineNameIndex;
  1358. // create char array then a string that is only the script engine name
  1359. Char[] scriptEngineNameCharArray = m_ScriptEngine.ScriptEngineName.ToCharArray(scriptEngineNameIndex, scriptEngineNameLength);
  1360. String scriptEngineName = new String(scriptEngineNameCharArray);
  1361. return scriptEngineName;
  1362. }
  1363. else
  1364. {
  1365. return String.Empty;
  1366. }
  1367. }
  1368. public string osGetPhysicsEngineType()
  1369. {
  1370. // High because it can be used to target attacks to known weaknesses
  1371. // This would allow a new class of griefer scripts that don't even
  1372. // require their user to know what they are doing (see script
  1373. // kiddie)
  1374. // Because it would be nice if scripts didn't blow up if the information
  1375. // about the physics engine, this function returns an empty string if
  1376. // the user does not have permission to see it. This as opposed to
  1377. // throwing an exception.
  1378. m_host.AddScriptLPS(1);
  1379. string ret = String.Empty;
  1380. if (String.IsNullOrEmpty(CheckThreatLevelTest(ThreatLevel.High, "osGetPhysicsEngineType")))
  1381. {
  1382. if (m_ScriptEngine.World.PhysicsScene != null)
  1383. {
  1384. ret = m_ScriptEngine.World.PhysicsScene.EngineType;
  1385. // An old physics engine might have an uninitialized engine type
  1386. if (ret == null)
  1387. ret = "unknown";
  1388. }
  1389. }
  1390. return ret;
  1391. }
  1392. public string osGetSimulatorVersion()
  1393. {
  1394. // High because it can be used to target attacks to known weaknesses
  1395. // This would allow a new class of griefer scripts that don't even
  1396. // require their user to know what they are doing (see script
  1397. // kiddie)
  1398. //
  1399. CheckThreatLevel(ThreatLevel.High,"osGetSimulatorVersion");
  1400. m_host.AddScriptLPS(1);
  1401. return m_ScriptEngine.World.GetSimulatorVersion();
  1402. }
  1403. private Hashtable osdToHashtable(OSDMap map)
  1404. {
  1405. Hashtable result = new Hashtable();
  1406. foreach (KeyValuePair<string, OSD> item in map) {
  1407. result.Add(item.Key, osdToObject(item.Value));
  1408. }
  1409. return result;
  1410. }
  1411. private ArrayList osdToArray(OSDArray list)
  1412. {
  1413. ArrayList result = new ArrayList();
  1414. foreach ( OSD item in list ) {
  1415. result.Add(osdToObject(item));
  1416. }
  1417. return result;
  1418. }
  1419. private Object osdToObject(OSD decoded)
  1420. {
  1421. if ( decoded is OSDString ) {
  1422. return (string) decoded.AsString();
  1423. } else if ( decoded is OSDInteger ) {
  1424. return (int) decoded.AsInteger();
  1425. } else if ( decoded is OSDReal ) {
  1426. return (float) decoded.AsReal();
  1427. } else if ( decoded is OSDBoolean ) {
  1428. return (bool) decoded.AsBoolean();
  1429. } else if ( decoded is OSDMap ) {
  1430. return osdToHashtable((OSDMap) decoded);
  1431. } else if ( decoded is OSDArray ) {
  1432. return osdToArray((OSDArray) decoded);
  1433. } else {
  1434. return null;
  1435. }
  1436. }
  1437. public Object osParseJSONNew(string JSON)
  1438. {
  1439. CheckThreatLevel(ThreatLevel.None, "osParseJSONNew");
  1440. m_host.AddScriptLPS(1);
  1441. try
  1442. {
  1443. OSD decoded = OSDParser.DeserializeJson(JSON);
  1444. return osdToObject(decoded);
  1445. }
  1446. catch(Exception e)
  1447. {
  1448. OSSLError("osParseJSONNew: Problems decoding JSON string " + JSON + " : " + e.Message) ;
  1449. return null;
  1450. }
  1451. }
  1452. public Hashtable osParseJSON(string JSON)
  1453. {
  1454. CheckThreatLevel(ThreatLevel.None, "osParseJSON");
  1455. m_host.AddScriptLPS(1);
  1456. Object decoded = osParseJSONNew(JSON);
  1457. if ( decoded is Hashtable ) {
  1458. return (Hashtable) decoded;
  1459. } else if ( decoded is ArrayList ) {
  1460. ArrayList decoded_list = (ArrayList) decoded;
  1461. Hashtable fakearray = new Hashtable();
  1462. int i = 0;
  1463. for ( i = 0; i < decoded_list.Count ; i++ ) {
  1464. fakearray.Add(i, decoded_list[i]);
  1465. }
  1466. return fakearray;
  1467. } else {
  1468. OSSLError("osParseJSON: unable to parse JSON string " + JSON);
  1469. return null;
  1470. }
  1471. }
  1472. /// <summary>
  1473. /// Send a message to to object identified by the given UUID
  1474. /// </summary>
  1475. /// <remarks>
  1476. /// A script in the object must implement the dataserver function
  1477. /// the dataserver function is passed the ID of the calling function and a string message
  1478. /// </remarks>
  1479. /// <param name="objectUUID"></param>
  1480. /// <param name="message"></param>
  1481. public void osMessageObject(LSL_Key objectUUID, string message)
  1482. {
  1483. CheckThreatLevel(ThreatLevel.Low, "osMessageObject");
  1484. m_host.AddScriptLPS(1);
  1485. UUID objUUID;
  1486. if (!UUID.TryParse(objectUUID, out objUUID)) // prior to patching, a thrown exception regarding invalid GUID format would be shouted instead.
  1487. {
  1488. OSSLShoutError("osMessageObject() cannot send messages to objects with invalid UUIDs");
  1489. return;
  1490. }
  1491. MessageObject(objUUID, message);
  1492. }
  1493. private void MessageObject(UUID objUUID, string message)
  1494. {
  1495. object[] resobj = new object[] { new LSL_Types.LSLString(m_host.UUID.ToString()), new LSL_Types.LSLString(message) };
  1496. SceneObjectPart sceneOP = World.GetSceneObjectPart(objUUID);
  1497. if (sceneOP == null) // prior to patching, PostObjectEvent() would cause a throw exception to be shouted instead.
  1498. {
  1499. OSSLShoutError("osMessageObject() cannot send message to " + objUUID.ToString() + ", object was not found in scene.");
  1500. return;
  1501. }
  1502. m_ScriptEngine.PostObjectEvent(
  1503. sceneOP.LocalId, new EventParams(
  1504. "dataserver", resobj, new DetectParams[0]));
  1505. }
  1506. /// <summary>
  1507. /// Write a notecard directly to the prim's inventory.
  1508. /// </summary>
  1509. /// <remarks>
  1510. /// This needs ThreatLevel high. It is an excellent griefer tool,
  1511. /// In a loop, it can cause asset bloat and DOS levels of asset
  1512. /// writes.
  1513. /// </remarks>
  1514. /// <param name="notecardName">The name of the notecard to write.</param>
  1515. /// <param name="contents">The contents of the notecard.</param>
  1516. public void osMakeNotecard(string notecardName, LSL_Types.list contents)
  1517. {
  1518. CheckThreatLevel(ThreatLevel.High, "osMakeNotecard");
  1519. m_host.AddScriptLPS(1);
  1520. StringBuilder notecardData = new StringBuilder();
  1521. for (int i = 0; i < contents.Length; i++)
  1522. notecardData.Append((string)(contents.GetLSLStringItem(i) + "\n"));
  1523. SaveNotecard(notecardName, "Script generated notecard", notecardData.ToString(), false);
  1524. }
  1525. /// <summary>
  1526. /// Save a notecard to prim inventory.
  1527. /// </summary>
  1528. /// <param name="name"></param>
  1529. /// <param name="description">Description of notecard</param>
  1530. /// <param name="notecardData"></param>
  1531. /// <param name="forceSameName">
  1532. /// If true, then if an item exists with the same name, it is replaced.
  1533. /// If false, then a new item is created witha slightly different name (e.g. name 1)
  1534. /// </param>
  1535. /// <returns>Prim inventory item created.</returns>
  1536. protected TaskInventoryItem SaveNotecard(string name, string description, string data, bool forceSameName)
  1537. {
  1538. // Create new asset
  1539. AssetBase asset = new AssetBase(UUID.Random(), name, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString());
  1540. asset.Description = description;
  1541. int textLength = data.Length;
  1542. data
  1543. = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length "
  1544. + textLength.ToString() + "\n" + data + "}\n";
  1545. asset.Data = Util.UTF8.GetBytes(data);
  1546. World.AssetService.Store(asset);
  1547. // Create Task Entry
  1548. TaskInventoryItem taskItem = new TaskInventoryItem();
  1549. taskItem.ResetIDs(m_host.UUID);
  1550. taskItem.ParentID = m_host.UUID;
  1551. taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch();
  1552. taskItem.Name = asset.Name;
  1553. taskItem.Description = asset.Description;
  1554. taskItem.Type = (int)AssetType.Notecard;
  1555. taskItem.InvType = (int)InventoryType.Notecard;
  1556. taskItem.OwnerID = m_host.OwnerID;
  1557. taskItem.CreatorID = m_host.OwnerID;
  1558. taskItem.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
  1559. taskItem.CurrentPermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
  1560. taskItem.EveryonePermissions = 0;
  1561. taskItem.NextPermissions = (uint)PermissionMask.All;
  1562. taskItem.GroupID = m_host.GroupID;
  1563. taskItem.GroupPermissions = 0;
  1564. taskItem.Flags = 0;
  1565. taskItem.PermsGranter = UUID.Zero;
  1566. taskItem.PermsMask = 0;
  1567. taskItem.AssetID = asset.FullID;
  1568. if (forceSameName)
  1569. m_host.Inventory.AddInventoryItemExclusive(taskItem, false);
  1570. else
  1571. m_host.Inventory.AddInventoryItem(taskItem, false);
  1572. return taskItem;
  1573. }
  1574. /// <summary>
  1575. /// Load the notecard data found at the given prim inventory item name or asset uuid.
  1576. /// </summary>
  1577. /// <param name="notecardNameOrUuid"></param>
  1578. /// <returns>The text loaded. Null if no notecard was found.</returns>
  1579. protected string LoadNotecard(string notecardNameOrUuid)
  1580. {
  1581. UUID assetID = CacheNotecard(notecardNameOrUuid);
  1582. if (assetID != UUID.Zero)
  1583. {
  1584. StringBuilder notecardData = new StringBuilder();
  1585. for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
  1586. {
  1587. string line = NotecardCache.GetLine(assetID, count) + "\n";
  1588. // m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line);
  1589. notecardData.Append(line);
  1590. }
  1591. return notecardData.ToString();
  1592. }
  1593. return null;
  1594. }
  1595. /// <summary>
  1596. /// Cache a notecard's contents.
  1597. /// </summary>
  1598. /// <param name="notecardNameOrUuid"></param>
  1599. /// <returns>
  1600. /// The asset id of the notecard, which is used for retrieving the cached data.
  1601. /// UUID.Zero if no asset could be found.
  1602. /// </returns>
  1603. protected UUID CacheNotecard(string notecardNameOrUuid)
  1604. {
  1605. UUID assetID = UUID.Zero;
  1606. if (!UUID.TryParse(notecardNameOrUuid, out assetID))
  1607. {
  1608. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  1609. {
  1610. if (item.Type == 7 && item.Name == notecardNameOrUuid)
  1611. {
  1612. assetID = item.AssetID;
  1613. }
  1614. }
  1615. }
  1616. if (assetID == UUID.Zero)
  1617. return UUID.Zero;
  1618. if (!NotecardCache.IsCached(assetID))
  1619. {
  1620. AssetBase a = World.AssetService.Get(assetID.ToString());
  1621. if (a == null)
  1622. return UUID.Zero;
  1623. string data = Encoding.UTF8.GetString(a.Data);
  1624. NotecardCache.Cache(assetID, data);
  1625. };
  1626. return assetID;
  1627. }
  1628. /// <summary>
  1629. /// Directly get an entire notecard at once.
  1630. /// </summary>
  1631. /// <remarks>
  1632. /// Instead of using the LSL Dataserver event to pull notecard data
  1633. /// this will simply read the entire notecard and return its data as a string.
  1634. ///
  1635. /// Warning - due to the synchronous method this function uses to fetch assets, its use
  1636. /// may be dangerous and unreliable while running in grid mode.
  1637. /// </remarks>
  1638. /// <param name="name">Name of the notecard or its asset id</param>
  1639. /// <param name="line">The line number to read. The first line is line 0</param>
  1640. /// <returns>Notecard line</returns>
  1641. public string osGetNotecardLine(string name, int line)
  1642. {
  1643. CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine");
  1644. m_host.AddScriptLPS(1);
  1645. UUID assetID = CacheNotecard(name);
  1646. if (assetID == UUID.Zero)
  1647. {
  1648. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1649. return "ERROR!";
  1650. }
  1651. return NotecardCache.GetLine(assetID, line);
  1652. }
  1653. /// <summary>
  1654. /// Get an entire notecard at once.
  1655. /// </summary>
  1656. /// <remarks>
  1657. /// Instead of using the LSL Dataserver event to pull notecard data line by line,
  1658. /// this will simply read the entire notecard and return its data as a string.
  1659. ///
  1660. /// Warning - due to the synchronous method this function uses to fetch assets, its use
  1661. /// may be dangerous and unreliable while running in grid mode.
  1662. /// </remarks>
  1663. /// <param name="name">Name of the notecard or its asset id</param>
  1664. /// <returns>Notecard text</returns>
  1665. public string osGetNotecard(string name)
  1666. {
  1667. CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard");
  1668. m_host.AddScriptLPS(1);
  1669. string text = LoadNotecard(name);
  1670. if (text == null)
  1671. {
  1672. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1673. return "ERROR!";
  1674. }
  1675. else
  1676. {
  1677. return text;
  1678. }
  1679. }
  1680. /// <summary>
  1681. /// Get the number of lines in the given notecard.
  1682. /// </summary>
  1683. /// <remarks>
  1684. /// Instead of using the LSL Dataserver event to pull notecard data,
  1685. /// this will simply read the number of note card lines and return this data as an integer.
  1686. ///
  1687. /// Warning - due to the synchronous method this function uses to fetch assets, its use
  1688. /// may be dangerous and unreliable while running in grid mode.
  1689. /// </remarks>
  1690. /// <param name="name">Name of the notecard or its asset id</param>
  1691. /// <returns></returns>
  1692. public int osGetNumberOfNotecardLines(string name)
  1693. {
  1694. CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines");
  1695. m_host.AddScriptLPS(1);
  1696. UUID assetID = CacheNotecard(name);
  1697. if (assetID == UUID.Zero)
  1698. {
  1699. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1700. return -1;
  1701. }
  1702. return NotecardCache.GetLines(assetID);
  1703. }
  1704. public string osAvatarName2Key(string firstname, string lastname)
  1705. {
  1706. CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key");
  1707. m_host.AddScriptLPS(1);
  1708. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, firstname, lastname);
  1709. if (null == account)
  1710. {
  1711. return UUID.Zero.ToString();
  1712. }
  1713. else
  1714. {
  1715. return account.PrincipalID.ToString();
  1716. }
  1717. }
  1718. public string osKey2Name(string id)
  1719. {
  1720. CheckThreatLevel(ThreatLevel.Low, "osKey2Name");
  1721. m_host.AddScriptLPS(1);
  1722. UUID key = new UUID();
  1723. if (UUID.TryParse(id, out key))
  1724. {
  1725. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, key);
  1726. if (null == account)
  1727. {
  1728. return "";
  1729. }
  1730. else
  1731. {
  1732. return account.Name;
  1733. }
  1734. }
  1735. else
  1736. {
  1737. return "";
  1738. }
  1739. }
  1740. private enum InfoType
  1741. {
  1742. Nick,
  1743. Name,
  1744. Login,
  1745. Home,
  1746. Custom
  1747. };
  1748. private string GridUserInfo(InfoType type)
  1749. {
  1750. return GridUserInfo(type, "");
  1751. }
  1752. private string GridUserInfo(InfoType type, string key)
  1753. {
  1754. string retval = String.Empty;
  1755. IConfigSource config = m_ScriptEngine.ConfigSource;
  1756. string url = null;
  1757. IConfig gridInfoConfig = config.Configs["GridInfo"];
  1758. if (gridInfoConfig != null)
  1759. url = gridInfoConfig.GetString("GridInfoURI", String.Empty);
  1760. if (String.IsNullOrEmpty(url))
  1761. return "Configuration Error!";
  1762. string verb ="/json_grid_info";
  1763. OSDMap json = new OSDMap();
  1764. OSDMap info = WebUtil.GetFromService(String.Format("{0}{1}",url,verb), 3000);
  1765. if (info["Success"] != true)
  1766. return "Get GridInfo Failed!";
  1767. json = (OSDMap)OSDParser.DeserializeJson(info["_RawResult"].AsString());
  1768. switch (type)
  1769. {
  1770. case InfoType.Nick:
  1771. retval = json["gridnick"];
  1772. break;
  1773. case InfoType.Name:
  1774. retval = json["gridname"];
  1775. break;
  1776. case InfoType.Login:
  1777. retval = json["login"];
  1778. break;
  1779. case InfoType.Home:
  1780. retval = json["home"];
  1781. break;
  1782. case InfoType.Custom:
  1783. retval = json[key];
  1784. break;
  1785. default:
  1786. retval = "error";
  1787. break;
  1788. }
  1789. return retval;
  1790. }
  1791. /// <summary>
  1792. /// Get the nickname of this grid, as set in the [GridInfo] config section.
  1793. /// </summary>
  1794. /// <remarks>
  1795. /// Threat level is Moderate because intentional abuse, for instance
  1796. /// scripts that are written to be malicious only on one grid,
  1797. /// for instance in a HG scenario, are a distinct possibility.
  1798. /// </remarks>
  1799. /// <returns></returns>
  1800. public string osGetGridNick()
  1801. {
  1802. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridNick");
  1803. m_host.AddScriptLPS(1);
  1804. string nick = String.Empty;
  1805. IConfigSource config = m_ScriptEngine.ConfigSource;
  1806. if (config.Configs[GridInfoServiceConfigSectionName] != null)
  1807. nick = config.Configs[GridInfoServiceConfigSectionName].GetString("gridnick", nick);
  1808. if (String.IsNullOrEmpty(nick))
  1809. nick = GridUserInfo(InfoType.Nick);
  1810. return nick;
  1811. }
  1812. public string osGetGridName()
  1813. {
  1814. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridName");
  1815. m_host.AddScriptLPS(1);
  1816. string name = String.Empty;
  1817. IConfigSource config = m_ScriptEngine.ConfigSource;
  1818. if (config.Configs[GridInfoServiceConfigSectionName] != null)
  1819. name = config.Configs[GridInfoServiceConfigSectionName].GetString("gridname", name);
  1820. if (String.IsNullOrEmpty(name))
  1821. name = GridUserInfo(InfoType.Name);
  1822. return name;
  1823. }
  1824. public string osGetGridLoginURI()
  1825. {
  1826. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridLoginURI");
  1827. m_host.AddScriptLPS(1);
  1828. string loginURI = String.Empty;
  1829. IConfigSource config = m_ScriptEngine.ConfigSource;
  1830. if (config.Configs[GridInfoServiceConfigSectionName] != null)
  1831. loginURI = config.Configs[GridInfoServiceConfigSectionName].GetString("login", loginURI);
  1832. if (String.IsNullOrEmpty(loginURI))
  1833. loginURI = GridUserInfo(InfoType.Login);
  1834. return loginURI;
  1835. }
  1836. public string osGetGridHomeURI()
  1837. {
  1838. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridHomeURI");
  1839. m_host.AddScriptLPS(1);
  1840. IConfigSource config = m_ScriptEngine.ConfigSource;
  1841. string HomeURI = Util.GetConfigVarFromSections<string>(config, "HomeURI",
  1842. new string[] { "Startup", "Hypergrid" }, String.Empty);
  1843. if (!string.IsNullOrEmpty(HomeURI))
  1844. return HomeURI;
  1845. // Legacy. Remove soon!
  1846. if (config.Configs["LoginService"] != null)
  1847. HomeURI = config.Configs["LoginService"].GetString("SRV_HomeURI", HomeURI);
  1848. if (String.IsNullOrEmpty(HomeURI))
  1849. HomeURI = GridUserInfo(InfoType.Home);
  1850. return HomeURI;
  1851. }
  1852. public string osGetGridGatekeeperURI()
  1853. {
  1854. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridGatekeeperURI");
  1855. m_host.AddScriptLPS(1);
  1856. IConfigSource config = m_ScriptEngine.ConfigSource;
  1857. string gatekeeperURI = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI",
  1858. new string[] { "Startup", "Hypergrid" }, String.Empty);
  1859. if (!string.IsNullOrEmpty(gatekeeperURI))
  1860. return gatekeeperURI;
  1861. // Legacy. Remove soon!
  1862. if (config.Configs["GridService"] != null)
  1863. gatekeeperURI = config.Configs["GridService"].GetString("Gatekeeper", gatekeeperURI);
  1864. return gatekeeperURI;
  1865. }
  1866. public string osGetGridCustom(string key)
  1867. {
  1868. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridCustom");
  1869. m_host.AddScriptLPS(1);
  1870. string retval = String.Empty;
  1871. IConfigSource config = m_ScriptEngine.ConfigSource;
  1872. if (config.Configs[GridInfoServiceConfigSectionName] != null)
  1873. retval = config.Configs[GridInfoServiceConfigSectionName].GetString(key, retval);
  1874. if (String.IsNullOrEmpty(retval))
  1875. retval = GridUserInfo(InfoType.Custom, key);
  1876. return retval;
  1877. }
  1878. public LSL_String osFormatString(string str, LSL_List strings)
  1879. {
  1880. CheckThreatLevel(ThreatLevel.VeryLow, "osFormatString");
  1881. m_host.AddScriptLPS(1);
  1882. return String.Format(str, strings.Data);
  1883. }
  1884. public LSL_List osMatchString(string src, string pattern, int start)
  1885. {
  1886. CheckThreatLevel(ThreatLevel.VeryLow, "osMatchString");
  1887. m_host.AddScriptLPS(1);
  1888. LSL_List result = new LSL_List();
  1889. // Normalize indices (if negative).
  1890. // After normlaization they may still be
  1891. // negative, but that is now relative to
  1892. // the start, rather than the end, of the
  1893. // sequence.
  1894. if (start < 0)
  1895. {
  1896. start = src.Length + start;
  1897. }
  1898. if (start < 0 || start >= src.Length)
  1899. {
  1900. return result; // empty list
  1901. }
  1902. // Find matches beginning at start position
  1903. Regex matcher = new Regex(pattern);
  1904. Match match = matcher.Match(src, start);
  1905. while (match.Success)
  1906. {
  1907. foreach (System.Text.RegularExpressions.Group g in match.Groups)
  1908. {
  1909. if (g.Success)
  1910. {
  1911. result.Add(new LSL_String(g.Value));
  1912. result.Add(new LSL_Integer(g.Index));
  1913. }
  1914. }
  1915. match = match.NextMatch();
  1916. }
  1917. return result;
  1918. }
  1919. public LSL_String osReplaceString(string src, string pattern, string replace, int count, int start)
  1920. {
  1921. CheckThreatLevel(ThreatLevel.VeryLow, "osReplaceString");
  1922. m_host.AddScriptLPS(1);
  1923. // Normalize indices (if negative).
  1924. // After normlaization they may still be
  1925. // negative, but that is now relative to
  1926. // the start, rather than the end, of the
  1927. // sequence.
  1928. if (start < 0)
  1929. {
  1930. start = src.Length + start;
  1931. }
  1932. if (start < 0 || start >= src.Length)
  1933. {
  1934. return src;
  1935. }
  1936. // Find matches beginning at start position
  1937. Regex matcher = new Regex(pattern);
  1938. return matcher.Replace(src,replace,count,start);
  1939. }
  1940. public string osLoadedCreationDate()
  1941. {
  1942. CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationDate");
  1943. m_host.AddScriptLPS(1);
  1944. return World.RegionInfo.RegionSettings.LoadedCreationDate;
  1945. }
  1946. public string osLoadedCreationTime()
  1947. {
  1948. CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationTime");
  1949. m_host.AddScriptLPS(1);
  1950. return World.RegionInfo.RegionSettings.LoadedCreationTime;
  1951. }
  1952. public string osLoadedCreationID()
  1953. {
  1954. CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationID");
  1955. m_host.AddScriptLPS(1);
  1956. return World.RegionInfo.RegionSettings.LoadedCreationID;
  1957. }
  1958. /// <summary>
  1959. /// Get the primitive parameters of a linked prim.
  1960. /// </summary>
  1961. /// <remarks>
  1962. /// Threat level is 'Low' because certain users could possibly be tricked into
  1963. /// dropping an unverified script into one of their own objects, which could
  1964. /// then gather the physical construction details of the object and transmit it
  1965. /// to an unscrupulous third party, thus permitting unauthorized duplication of
  1966. /// the object's form.
  1967. /// </remarks>
  1968. /// <param name="linknumber"></param>
  1969. /// <param name="rules"></param>
  1970. /// <returns></returns>
  1971. public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules)
  1972. {
  1973. CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams");
  1974. m_host.AddScriptLPS(1);
  1975. InitLSL();
  1976. // One needs to cast m_LSL_Api because we're using functions not
  1977. // on the ILSL_Api interface.
  1978. LSL_Api LSL_Api = (LSL_Api)m_LSL_Api;
  1979. LSL_List retVal = new LSL_List();
  1980. LSL_List remaining = null;
  1981. List<SceneObjectPart> parts = LSL_Api.GetLinkParts(linknumber);
  1982. foreach (SceneObjectPart part in parts)
  1983. {
  1984. remaining = LSL_Api.GetPrimParams(part, rules, ref retVal);
  1985. }
  1986. while (remaining != null && remaining.Length > 2)
  1987. {
  1988. linknumber = remaining.GetLSLIntegerItem(0);
  1989. rules = remaining.GetSublist(1, -1);
  1990. parts = LSL_Api.GetLinkParts(linknumber);
  1991. foreach (SceneObjectPart part in parts)
  1992. remaining = LSL_Api.GetPrimParams(part, rules, ref retVal);
  1993. }
  1994. return retVal;
  1995. }
  1996. public void osForceCreateLink(string target, int parent)
  1997. {
  1998. CheckThreatLevel(ThreatLevel.VeryLow, "osForceCreateLink");
  1999. m_host.AddScriptLPS(1);
  2000. InitLSL();
  2001. ((LSL_Api)m_LSL_Api).CreateLink(target, parent);
  2002. }
  2003. public void osForceBreakLink(int linknum)
  2004. {
  2005. CheckThreatLevel(ThreatLevel.VeryLow, "osForceBreakLink");
  2006. m_host.AddScriptLPS(1);
  2007. InitLSL();
  2008. ((LSL_Api)m_LSL_Api).BreakLink(linknum);
  2009. }
  2010. public void osForceBreakAllLinks()
  2011. {
  2012. CheckThreatLevel(ThreatLevel.VeryLow, "osForceBreakAllLinks");
  2013. m_host.AddScriptLPS(1);
  2014. InitLSL();
  2015. ((LSL_Api)m_LSL_Api).BreakAllLinks();
  2016. }
  2017. public LSL_Integer osIsNpc(LSL_Key npc)
  2018. {
  2019. CheckThreatLevel(ThreatLevel.None, "osIsNpc");
  2020. m_host.AddScriptLPS(1);
  2021. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2022. if (module != null)
  2023. {
  2024. UUID npcId;
  2025. if (UUID.TryParse(npc.m_string, out npcId))
  2026. if (module.IsNPC(npcId, World))
  2027. return ScriptBaseClass.TRUE;
  2028. }
  2029. return ScriptBaseClass.FALSE;
  2030. }
  2031. public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard)
  2032. {
  2033. CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
  2034. m_host.AddScriptLPS(1);
  2035. return NpcCreate(firstname, lastname, position, notecard, false, false);
  2036. }
  2037. public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options)
  2038. {
  2039. CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
  2040. m_host.AddScriptLPS(1);
  2041. return NpcCreate(
  2042. firstname, lastname, position, notecard,
  2043. (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0,
  2044. (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0);
  2045. }
  2046. private LSL_Key NpcCreate(
  2047. string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent)
  2048. {
  2049. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2050. if (module != null)
  2051. {
  2052. AvatarAppearance appearance = null;
  2053. UUID id;
  2054. if (UUID.TryParse(notecard, out id))
  2055. {
  2056. ScenePresence clonePresence = World.GetScenePresence(id);
  2057. if (clonePresence != null)
  2058. appearance = clonePresence.Appearance;
  2059. }
  2060. if (appearance == null)
  2061. {
  2062. string appearanceSerialized = LoadNotecard(notecard);
  2063. if (appearanceSerialized != null)
  2064. {
  2065. OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
  2066. appearance = new AvatarAppearance();
  2067. appearance.Unpack(appearanceOsd);
  2068. }
  2069. else
  2070. {
  2071. OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard));
  2072. }
  2073. }
  2074. UUID ownerID = UUID.Zero;
  2075. if (owned)
  2076. ownerID = m_host.OwnerID;
  2077. UUID x = module.CreateNPC(firstname,
  2078. lastname,
  2079. position,
  2080. ownerID,
  2081. senseAsAgent,
  2082. World,
  2083. appearance);
  2084. return new LSL_Key(x.ToString());
  2085. }
  2086. return new LSL_Key(UUID.Zero.ToString());
  2087. }
  2088. /// <summary>
  2089. /// Save the current appearance of the NPC permanently to the named notecard.
  2090. /// </summary>
  2091. /// <param name="avatar"></param>
  2092. /// <param name="notecard">The name of the notecard to which to save the appearance.</param>
  2093. /// <returns>The asset ID of the notecard saved.</returns>
  2094. public LSL_Key osNpcSaveAppearance(LSL_Key npc, string notecard)
  2095. {
  2096. CheckThreatLevel(ThreatLevel.High, "osNpcSaveAppearance");
  2097. m_host.AddScriptLPS(1);
  2098. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  2099. if (npcModule != null)
  2100. {
  2101. UUID npcId;
  2102. if (!UUID.TryParse(npc.m_string, out npcId))
  2103. return new LSL_Key(UUID.Zero.ToString());
  2104. if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
  2105. return new LSL_Key(UUID.Zero.ToString());
  2106. return SaveAppearanceToNotecard(npcId, notecard);
  2107. }
  2108. return new LSL_Key(UUID.Zero.ToString());
  2109. }
  2110. public void osNpcLoadAppearance(LSL_Key npc, string notecard)
  2111. {
  2112. CheckThreatLevel(ThreatLevel.High, "osNpcLoadAppearance");
  2113. m_host.AddScriptLPS(1);
  2114. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  2115. if (npcModule != null)
  2116. {
  2117. UUID npcId;
  2118. if (!UUID.TryParse(npc.m_string, out npcId))
  2119. return;
  2120. if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
  2121. return;
  2122. string appearanceSerialized = LoadNotecard(notecard);
  2123. if (appearanceSerialized == null)
  2124. OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard));
  2125. OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
  2126. // OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized);
  2127. // Console.WriteLine("appearanceSerialized {0}", appearanceSerialized);
  2128. // Console.WriteLine("a.Type {0}, a.ToString() {1}", a.Type, a);
  2129. AvatarAppearance appearance = new AvatarAppearance();
  2130. appearance.Unpack(appearanceOsd);
  2131. npcModule.SetNPCAppearance(npcId, appearance, m_host.ParentGroup.Scene);
  2132. }
  2133. }
  2134. public LSL_Key osNpcGetOwner(LSL_Key npc)
  2135. {
  2136. CheckThreatLevel(ThreatLevel.None, "osNpcGetOwner");
  2137. m_host.AddScriptLPS(1);
  2138. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  2139. if (npcModule != null)
  2140. {
  2141. UUID npcId;
  2142. if (UUID.TryParse(npc.m_string, out npcId))
  2143. {
  2144. UUID owner = npcModule.GetOwner(npcId);
  2145. if (owner != UUID.Zero)
  2146. return new LSL_Key(owner.ToString());
  2147. else
  2148. return npc;
  2149. }
  2150. }
  2151. return new LSL_Key(UUID.Zero.ToString());
  2152. }
  2153. public LSL_Vector osNpcGetPos(LSL_Key npc)
  2154. {
  2155. CheckThreatLevel(ThreatLevel.High, "osNpcGetPos");
  2156. m_host.AddScriptLPS(1);
  2157. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  2158. if (npcModule != null)
  2159. {
  2160. UUID npcId;
  2161. if (!UUID.TryParse(npc.m_string, out npcId))
  2162. return new LSL_Vector(0, 0, 0);
  2163. if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
  2164. return new LSL_Vector(0, 0, 0);
  2165. ScenePresence sp = World.GetScenePresence(npcId);
  2166. if (sp != null)
  2167. return new LSL_Vector(sp.AbsolutePosition);
  2168. }
  2169. return Vector3.Zero;
  2170. }
  2171. public void osNpcMoveTo(LSL_Key npc, LSL_Vector pos)
  2172. {
  2173. CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo");
  2174. m_host.AddScriptLPS(1);
  2175. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2176. if (module != null)
  2177. {
  2178. UUID npcId;
  2179. if (!UUID.TryParse(npc.m_string, out npcId))
  2180. return;
  2181. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2182. return;
  2183. module.MoveToTarget(npcId, World, pos, false, true, false);
  2184. }
  2185. }
  2186. public void osNpcMoveToTarget(LSL_Key npc, LSL_Vector target, int options)
  2187. {
  2188. CheckThreatLevel(ThreatLevel.High, "osNpcMoveToTarget");
  2189. m_host.AddScriptLPS(1);
  2190. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2191. if (module != null)
  2192. {
  2193. UUID npcId;
  2194. if (!UUID.TryParse(npc.m_string, out npcId))
  2195. return;
  2196. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2197. return;
  2198. module.MoveToTarget(
  2199. new UUID(npc.m_string),
  2200. World,
  2201. target,
  2202. (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0,
  2203. (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0,
  2204. (options & ScriptBaseClass.OS_NPC_RUNNING) != 0);
  2205. }
  2206. }
  2207. public LSL_Rotation osNpcGetRot(LSL_Key npc)
  2208. {
  2209. CheckThreatLevel(ThreatLevel.High, "osNpcGetRot");
  2210. m_host.AddScriptLPS(1);
  2211. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  2212. if (npcModule != null)
  2213. {
  2214. UUID npcId;
  2215. if (!UUID.TryParse(npc.m_string, out npcId))
  2216. return new LSL_Rotation(Quaternion.Identity);
  2217. if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
  2218. return new LSL_Rotation(Quaternion.Identity);
  2219. ScenePresence sp = World.GetScenePresence(npcId);
  2220. if (sp != null)
  2221. return new LSL_Rotation(sp.GetWorldRotation());
  2222. }
  2223. return Quaternion.Identity;
  2224. }
  2225. public void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation)
  2226. {
  2227. CheckThreatLevel(ThreatLevel.High, "osNpcSetRot");
  2228. m_host.AddScriptLPS(1);
  2229. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  2230. if (npcModule != null)
  2231. {
  2232. UUID npcId;
  2233. if (!UUID.TryParse(npc.m_string, out npcId))
  2234. return;
  2235. if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
  2236. return;
  2237. ScenePresence sp = World.GetScenePresence(npcId);
  2238. if (sp != null)
  2239. sp.Rotation = rotation;
  2240. }
  2241. }
  2242. public void osNpcStopMoveToTarget(LSL_Key npc)
  2243. {
  2244. CheckThreatLevel(ThreatLevel.High, "osNpcStopMoveToTarget");
  2245. m_host.AddScriptLPS(1);
  2246. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2247. if (module != null)
  2248. {
  2249. UUID npcId = new UUID(npc.m_string);
  2250. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2251. return;
  2252. module.StopMoveToTarget(npcId, World);
  2253. }
  2254. }
  2255. public void osNpcSay(LSL_Key npc, string message)
  2256. {
  2257. osNpcSay(npc, 0, message);
  2258. }
  2259. public void osNpcSay(LSL_Key npc, int channel, string message)
  2260. {
  2261. CheckThreatLevel(ThreatLevel.High, "osNpcSay");
  2262. m_host.AddScriptLPS(1);
  2263. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2264. if (module != null)
  2265. {
  2266. UUID npcId = new UUID(npc.m_string);
  2267. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2268. return;
  2269. module.Say(npcId, World, message, channel);
  2270. }
  2271. }
  2272. public void osNpcShout(LSL_Key npc, int channel, string message)
  2273. {
  2274. CheckThreatLevel(ThreatLevel.High, "osNpcShout");
  2275. m_host.AddScriptLPS(1);
  2276. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2277. if (module != null)
  2278. {
  2279. UUID npcId = new UUID(npc.m_string);
  2280. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2281. return;
  2282. module.Shout(npcId, World, message, channel);
  2283. }
  2284. }
  2285. public void osNpcSit(LSL_Key npc, LSL_Key target, int options)
  2286. {
  2287. CheckThreatLevel(ThreatLevel.High, "osNpcSit");
  2288. m_host.AddScriptLPS(1);
  2289. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2290. if (module != null)
  2291. {
  2292. UUID npcId = new UUID(npc.m_string);
  2293. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2294. return;
  2295. module.Sit(npcId, new UUID(target.m_string), World);
  2296. }
  2297. }
  2298. public void osNpcStand(LSL_Key npc)
  2299. {
  2300. CheckThreatLevel(ThreatLevel.High, "osNpcStand");
  2301. m_host.AddScriptLPS(1);
  2302. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2303. if (module != null)
  2304. {
  2305. UUID npcId = new UUID(npc.m_string);
  2306. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2307. return;
  2308. module.Stand(npcId, World);
  2309. }
  2310. }
  2311. public void osNpcRemove(LSL_Key npc)
  2312. {
  2313. CheckThreatLevel(ThreatLevel.High, "osNpcRemove");
  2314. m_host.AddScriptLPS(1);
  2315. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2316. if (module != null)
  2317. {
  2318. UUID npcId = new UUID(npc.m_string);
  2319. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2320. return;
  2321. module.DeleteNPC(npcId, World);
  2322. }
  2323. }
  2324. public void osNpcPlayAnimation(LSL_Key npc, string animation)
  2325. {
  2326. CheckThreatLevel(ThreatLevel.High, "osNpcPlayAnimation");
  2327. m_host.AddScriptLPS(1);
  2328. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2329. if (module != null)
  2330. {
  2331. UUID npcID = new UUID(npc.m_string);
  2332. if (module.CheckPermissions(npcID, m_host.OwnerID))
  2333. AvatarPlayAnimation(npcID.ToString(), animation);
  2334. }
  2335. }
  2336. public void osNpcStopAnimation(LSL_Key npc, string animation)
  2337. {
  2338. CheckThreatLevel(ThreatLevel.High, "osNpcStopAnimation");
  2339. m_host.AddScriptLPS(1);
  2340. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2341. if (module != null)
  2342. {
  2343. UUID npcID = new UUID(npc.m_string);
  2344. if (module.CheckPermissions(npcID, m_host.OwnerID))
  2345. AvatarStopAnimation(npcID.ToString(), animation);
  2346. }
  2347. }
  2348. public void osNpcWhisper(LSL_Key npc, int channel, string message)
  2349. {
  2350. CheckThreatLevel(ThreatLevel.High, "osNpcWhisper");
  2351. m_host.AddScriptLPS(1);
  2352. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2353. if (module != null)
  2354. {
  2355. UUID npcId = new UUID(npc.m_string);
  2356. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2357. return;
  2358. module.Whisper(npcId, World, message, channel);
  2359. }
  2360. }
  2361. public void osNpcTouch(LSL_Key npcLSL_Key, LSL_Key object_key, LSL_Integer link_num)
  2362. {
  2363. CheckThreatLevel(ThreatLevel.High, "osNpcTouch");
  2364. m_host.AddScriptLPS(1);
  2365. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2366. int linkNum = link_num.value;
  2367. if (module != null || (linkNum < 0 && linkNum != ScriptBaseClass.LINK_THIS))
  2368. {
  2369. UUID npcId;
  2370. if (!UUID.TryParse(npcLSL_Key, out npcId) || !module.CheckPermissions(npcId, m_host.OwnerID))
  2371. return;
  2372. SceneObjectPart part = null;
  2373. UUID objectId;
  2374. if (UUID.TryParse(LSL_String.ToString(object_key), out objectId))
  2375. part = World.GetSceneObjectPart(objectId);
  2376. if (part == null)
  2377. return;
  2378. if (linkNum != ScriptBaseClass.LINK_THIS)
  2379. {
  2380. if (linkNum == 0 || linkNum == ScriptBaseClass.LINK_ROOT)
  2381. { // 0 and 1 are treated as root, find the root if the current part isnt it
  2382. if (!part.IsRoot)
  2383. part = part.ParentGroup.RootPart;
  2384. }
  2385. else
  2386. { // Find the prim with the given link number if not found then fail silently
  2387. part = part.ParentGroup.GetLinkNumPart(linkNum);
  2388. if (part == null)
  2389. return;
  2390. }
  2391. }
  2392. module.Touch(npcId, part.UUID);
  2393. }
  2394. }
  2395. /// <summary>
  2396. /// Save the current appearance of the script owner permanently to the named notecard.
  2397. /// </summary>
  2398. /// <param name="notecard">The name of the notecard to which to save the appearance.</param>
  2399. /// <returns>The asset ID of the notecard saved.</returns>
  2400. public LSL_Key osOwnerSaveAppearance(string notecard)
  2401. {
  2402. CheckThreatLevel(ThreatLevel.High, "osOwnerSaveAppearance");
  2403. m_host.AddScriptLPS(1);
  2404. return SaveAppearanceToNotecard(m_host.OwnerID, notecard);
  2405. }
  2406. public LSL_Key osAgentSaveAppearance(LSL_Key avatarId, string notecard)
  2407. {
  2408. CheckThreatLevel(ThreatLevel.VeryHigh, "osAgentSaveAppearance");
  2409. m_host.AddScriptLPS(1);
  2410. return SaveAppearanceToNotecard(avatarId, notecard);
  2411. }
  2412. protected LSL_Key SaveAppearanceToNotecard(ScenePresence sp, string notecard)
  2413. {
  2414. IAvatarFactoryModule appearanceModule = World.RequestModuleInterface<IAvatarFactoryModule>();
  2415. if (appearanceModule != null)
  2416. {
  2417. appearanceModule.SaveBakedTextures(sp.UUID);
  2418. OSDMap appearancePacked = sp.Appearance.Pack();
  2419. TaskInventoryItem item
  2420. = SaveNotecard(notecard, "Avatar Appearance", Util.GetFormattedXml(appearancePacked as OSD), true);
  2421. return new LSL_Key(item.AssetID.ToString());
  2422. }
  2423. else
  2424. {
  2425. return new LSL_Key(UUID.Zero.ToString());
  2426. }
  2427. }
  2428. protected LSL_Key SaveAppearanceToNotecard(UUID avatarId, string notecard)
  2429. {
  2430. ScenePresence sp = World.GetScenePresence(avatarId);
  2431. if (sp == null || sp.IsChildAgent)
  2432. return new LSL_Key(UUID.Zero.ToString());
  2433. return SaveAppearanceToNotecard(sp, notecard);
  2434. }
  2435. protected LSL_Key SaveAppearanceToNotecard(LSL_Key rawAvatarId, string notecard)
  2436. {
  2437. UUID avatarId;
  2438. if (!UUID.TryParse(rawAvatarId, out avatarId))
  2439. return new LSL_Key(UUID.Zero.ToString());
  2440. return SaveAppearanceToNotecard(avatarId, notecard);
  2441. }
  2442. /// <summary>
  2443. /// Get current region's map texture UUID
  2444. /// </summary>
  2445. /// <returns></returns>
  2446. public LSL_Key osGetMapTexture()
  2447. {
  2448. CheckThreatLevel(ThreatLevel.None, "osGetMapTexture");
  2449. m_host.AddScriptLPS(1);
  2450. return m_ScriptEngine.World.RegionInfo.RegionSettings.TerrainImageID.ToString();
  2451. }
  2452. /// <summary>
  2453. /// Get a region's map texture UUID by region UUID or name.
  2454. /// </summary>
  2455. /// <param name="regionName"></param>
  2456. /// <returns></returns>
  2457. public LSL_Key osGetRegionMapTexture(string regionName)
  2458. {
  2459. CheckThreatLevel(ThreatLevel.High, "osGetRegionMapTexture");
  2460. m_host.AddScriptLPS(1);
  2461. Scene scene = m_ScriptEngine.World;
  2462. UUID key = UUID.Zero;
  2463. GridRegion region;
  2464. //If string is a key, use it. Otherwise, try to locate region by name.
  2465. if (UUID.TryParse(regionName, out key))
  2466. region = scene.GridService.GetRegionByUUID(UUID.Zero, key);
  2467. else
  2468. region = scene.GridService.GetRegionByName(UUID.Zero, regionName);
  2469. // If region was found, return the regions map texture key.
  2470. if (region != null)
  2471. key = region.TerrainImage;
  2472. ScriptSleep(1000);
  2473. return key.ToString();
  2474. }
  2475. /// <summary>
  2476. /// Return information regarding various simulator statistics (sim fps, physics fps, time
  2477. /// dilation, total number of prims, total number of active scripts, script lps, various
  2478. /// timing data, packets in/out, etc. Basically much the information that's shown in the
  2479. /// client's Statistics Bar (Ctrl-Shift-1)
  2480. /// </summary>
  2481. /// <returns>List of floats</returns>
  2482. public LSL_List osGetRegionStats()
  2483. {
  2484. CheckThreatLevel(ThreatLevel.Moderate, "osGetRegionStats");
  2485. m_host.AddScriptLPS(1);
  2486. LSL_List ret = new LSL_List();
  2487. float[] stats = World.StatsReporter.LastReportedSimStats;
  2488. for (int i = 0; i < 21; i++)
  2489. {
  2490. ret.Add(new LSL_Float(stats[i]));
  2491. }
  2492. return ret;
  2493. }
  2494. public LSL_Vector osGetRegionSize()
  2495. {
  2496. CheckThreatLevel(ThreatLevel.None, "osGetRegionSize");
  2497. m_host.AddScriptLPS(1);
  2498. bool isMegaregion;
  2499. IRegionCombinerModule rcMod = World.RequestModuleInterface<IRegionCombinerModule>();
  2500. if (rcMod != null)
  2501. isMegaregion = rcMod.IsRootForMegaregion(World.RegionInfo.RegionID);
  2502. else
  2503. isMegaregion = false;
  2504. if (isMegaregion)
  2505. {
  2506. Vector2 size = rcMod.GetSizeOfMegaregion(World.RegionInfo.RegionID);
  2507. return new LSL_Vector(size.X, size.Y, Constants.RegionHeight);
  2508. }
  2509. else
  2510. {
  2511. Scene scene = m_ScriptEngine.World;
  2512. GridRegion region = scene.GridService.GetRegionByUUID(UUID.Zero, World.RegionInfo.RegionID);
  2513. return new LSL_Vector((float)region.RegionSizeX, (float)region.RegionSizeX, Constants.RegionHeight);
  2514. }
  2515. }
  2516. public int osGetSimulatorMemory()
  2517. {
  2518. CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemory");
  2519. m_host.AddScriptLPS(1);
  2520. long pws = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64;
  2521. if (pws > Int32.MaxValue)
  2522. return Int32.MaxValue;
  2523. if (pws < 0)
  2524. return 0;
  2525. return (int)pws;
  2526. }
  2527. public void osSetSpeed(string UUID, LSL_Float SpeedModifier)
  2528. {
  2529. CheckThreatLevel(ThreatLevel.Moderate, "osSetSpeed");
  2530. m_host.AddScriptLPS(1);
  2531. ScenePresence avatar = World.GetScenePresence(new UUID(UUID));
  2532. if (avatar != null)
  2533. avatar.SpeedModifier = (float)SpeedModifier;
  2534. }
  2535. public void osKickAvatar(string FirstName, string SurName, string alert)
  2536. {
  2537. CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
  2538. m_host.AddScriptLPS(1);
  2539. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  2540. {
  2541. if (sp.Firstname == FirstName && sp.Lastname == SurName)
  2542. {
  2543. // kick client...
  2544. if (alert != null)
  2545. sp.ControllingClient.Kick(alert);
  2546. // ...and close on our side
  2547. sp.Scene.CloseAgent(sp.UUID, false);
  2548. }
  2549. });
  2550. }
  2551. public LSL_Float osGetHealth(string avatar)
  2552. {
  2553. CheckThreatLevel(ThreatLevel.None, "osGetHealth");
  2554. m_host.AddScriptLPS(1);
  2555. LSL_Float health = new LSL_Float(-1);
  2556. ScenePresence presence = World.GetScenePresence(new UUID(avatar));
  2557. if (presence != null) health = presence.Health;
  2558. return health;
  2559. }
  2560. public void osCauseDamage(string avatar, double damage)
  2561. {
  2562. CheckThreatLevel(ThreatLevel.High, "osCauseDamage");
  2563. m_host.AddScriptLPS(1);
  2564. UUID avatarId = new UUID(avatar);
  2565. Vector3 pos = m_host.GetWorldPosition();
  2566. ScenePresence presence = World.GetScenePresence(avatarId);
  2567. if (presence != null)
  2568. {
  2569. LandData land = World.GetLandData(pos);
  2570. if ((land.Flags & (uint)ParcelFlags.AllowDamage) == (uint)ParcelFlags.AllowDamage)
  2571. {
  2572. float health = presence.Health;
  2573. health -= (float)damage;
  2574. presence.setHealthWithUpdate(health);
  2575. if (health <= 0)
  2576. {
  2577. float healthliveagain = 100;
  2578. presence.ControllingClient.SendAgentAlertMessage("You died!", true);
  2579. presence.setHealthWithUpdate(healthliveagain);
  2580. presence.Scene.TeleportClientHome(presence.UUID, presence.ControllingClient);
  2581. }
  2582. }
  2583. }
  2584. }
  2585. public void osCauseHealing(string avatar, double healing)
  2586. {
  2587. CheckThreatLevel(ThreatLevel.High, "osCauseHealing");
  2588. m_host.AddScriptLPS(1);
  2589. UUID avatarId = new UUID(avatar);
  2590. ScenePresence presence = World.GetScenePresence(avatarId);
  2591. if (presence != null && World.ScriptDanger(m_host.LocalId, m_host.GetWorldPosition()))
  2592. {
  2593. float health = presence.Health;
  2594. health += (float)healing;
  2595. if (health >= 100)
  2596. health = 100;
  2597. presence.setHealthWithUpdate(health);
  2598. }
  2599. }
  2600. public LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules)
  2601. {
  2602. CheckThreatLevel(ThreatLevel.High, "osGetPrimitiveParams");
  2603. m_host.AddScriptLPS(1);
  2604. InitLSL();
  2605. return m_LSL_Api.GetPrimitiveParamsEx(prim, rules);
  2606. }
  2607. public void osSetPrimitiveParams(LSL_Key prim, LSL_List rules)
  2608. {
  2609. CheckThreatLevel(ThreatLevel.High, "osSetPrimitiveParams");
  2610. m_host.AddScriptLPS(1);
  2611. InitLSL();
  2612. m_LSL_Api.SetPrimitiveParamsEx(prim, rules, "osSetPrimitiveParams");
  2613. }
  2614. /// <summary>
  2615. /// Set parameters for light projection in host prim
  2616. /// </summary>
  2617. public void osSetProjectionParams(bool projection, LSL_Key texture, double fov, double focus, double amb)
  2618. {
  2619. CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams");
  2620. osSetProjectionParams(UUID.Zero.ToString(), projection, texture, fov, focus, amb);
  2621. }
  2622. /// <summary>
  2623. /// Set parameters for light projection with uuid of target prim
  2624. /// </summary>
  2625. public void osSetProjectionParams(LSL_Key prim, bool projection, LSL_Key texture, double fov, double focus, double amb)
  2626. {
  2627. CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams");
  2628. m_host.AddScriptLPS(1);
  2629. SceneObjectPart obj = null;
  2630. if (prim == UUID.Zero.ToString())
  2631. {
  2632. obj = m_host;
  2633. }
  2634. else
  2635. {
  2636. obj = World.GetSceneObjectPart(new UUID(prim));
  2637. if (obj == null)
  2638. return;
  2639. }
  2640. obj.Shape.ProjectionEntry = projection;
  2641. obj.Shape.ProjectionTextureUUID = new UUID(texture);
  2642. obj.Shape.ProjectionFOV = (float)fov;
  2643. obj.Shape.ProjectionFocus = (float)focus;
  2644. obj.Shape.ProjectionAmbiance = (float)amb;
  2645. obj.ParentGroup.HasGroupChanged = true;
  2646. obj.ScheduleFullUpdate();
  2647. }
  2648. /// <summary>
  2649. /// Like osGetAgents but returns enough info for a radar
  2650. /// </summary>
  2651. /// <returns>Strided list of the UUID, position and name of each avatar in the region</returns>
  2652. public LSL_List osGetAvatarList()
  2653. {
  2654. CheckThreatLevel(ThreatLevel.None, "osGetAvatarList");
  2655. m_host.AddScriptLPS(1);
  2656. LSL_List result = new LSL_List();
  2657. World.ForEachRootScenePresence(delegate (ScenePresence avatar)
  2658. {
  2659. if (avatar != null && avatar.UUID != m_host.OwnerID)
  2660. {
  2661. result.Add(new LSL_String(avatar.UUID.ToString()));
  2662. result.Add(new LSL_Vector(avatar.AbsolutePosition));
  2663. result.Add(new LSL_String(avatar.Name));
  2664. }
  2665. });
  2666. return result;
  2667. }
  2668. /// <summary>
  2669. /// Convert a unix time to a llGetTimestamp() like string
  2670. /// </summary>
  2671. /// <param name="unixTime"></param>
  2672. /// <returns></returns>
  2673. public LSL_String osUnixTimeToTimestamp(long time)
  2674. {
  2675. CheckThreatLevel(ThreatLevel.VeryLow, "osUnixTimeToTimestamp");
  2676. m_host.AddScriptLPS(1);
  2677. long baseTicks = 621355968000000000;
  2678. long tickResolution = 10000000;
  2679. long epochTicks = (time * tickResolution) + baseTicks;
  2680. DateTime date = new DateTime(epochTicks);
  2681. return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
  2682. }
  2683. /// <summary>
  2684. /// Get the description from an inventory item
  2685. /// </summary>
  2686. /// <param name="inventoryName"></param>
  2687. /// <returns>Item description</returns>
  2688. public LSL_String osGetInventoryDesc(string item)
  2689. {
  2690. m_host.AddScriptLPS(1);
  2691. lock (m_host.TaskInventory)
  2692. {
  2693. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  2694. {
  2695. if (inv.Value.Name == item)
  2696. {
  2697. return inv.Value.Description.ToString();
  2698. }
  2699. }
  2700. }
  2701. return String.Empty;
  2702. }
  2703. /// <summary>
  2704. /// Invite user to the group this object is set to
  2705. /// </summary>
  2706. /// <param name="agentId"></param>
  2707. /// <returns></returns>
  2708. public LSL_Integer osInviteToGroup(LSL_Key agentId)
  2709. {
  2710. CheckThreatLevel(ThreatLevel.VeryLow, "osInviteToGroup");
  2711. m_host.AddScriptLPS(1);
  2712. UUID agent = new UUID(agentId);
  2713. // groups module is required
  2714. IGroupsModule groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
  2715. if (groupsModule == null) return ScriptBaseClass.FALSE;
  2716. // object has to be set to a group, but not group owned
  2717. if (m_host.GroupID == UUID.Zero || m_host.GroupID == m_host.OwnerID) return ScriptBaseClass.FALSE;
  2718. // object owner has to be in that group and required permissions
  2719. GroupMembershipData member = groupsModule.GetMembershipData(m_host.GroupID, m_host.OwnerID);
  2720. if (member == null || (member.GroupPowers & (ulong)GroupPowers.Invite) == 0) return ScriptBaseClass.FALSE;
  2721. // check if agent is in that group already
  2722. //member = groupsModule.GetMembershipData(agent, m_host.GroupID, agent);
  2723. //if (member != null) return ScriptBaseClass.FALSE;
  2724. // invited agent has to be present in this scene
  2725. if (World.GetScenePresence(agent) == null) return ScriptBaseClass.FALSE;
  2726. groupsModule.InviteGroup(null, m_host.OwnerID, m_host.GroupID, agent, UUID.Zero);
  2727. return ScriptBaseClass.TRUE;
  2728. }
  2729. /// <summary>
  2730. /// Eject user from the group this object is set to
  2731. /// </summary>
  2732. /// <param name="agentId"></param>
  2733. /// <returns></returns>
  2734. public LSL_Integer osEjectFromGroup(LSL_Key agentId)
  2735. {
  2736. CheckThreatLevel(ThreatLevel.VeryLow, "osEjectFromGroup");
  2737. m_host.AddScriptLPS(1);
  2738. UUID agent = new UUID(agentId);
  2739. // groups module is required
  2740. IGroupsModule groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
  2741. if (groupsModule == null) return ScriptBaseClass.FALSE;
  2742. // object has to be set to a group, but not group owned
  2743. if (m_host.GroupID == UUID.Zero || m_host.GroupID == m_host.OwnerID) return ScriptBaseClass.FALSE;
  2744. // object owner has to be in that group and required permissions
  2745. GroupMembershipData member = groupsModule.GetMembershipData(m_host.GroupID, m_host.OwnerID);
  2746. if (member == null || (member.GroupPowers & (ulong)GroupPowers.Eject) == 0) return ScriptBaseClass.FALSE;
  2747. // agent has to be in that group
  2748. //member = groupsModule.GetMembershipData(agent, m_host.GroupID, agent);
  2749. //if (member == null) return ScriptBaseClass.FALSE;
  2750. // ejectee can be offline
  2751. groupsModule.EjectGroupMember(null, m_host.OwnerID, m_host.GroupID, agent);
  2752. return ScriptBaseClass.TRUE;
  2753. }
  2754. /// <summary>
  2755. /// Sets terrain estate texture
  2756. /// </summary>
  2757. /// <param name="level"></param>
  2758. /// <param name="texture"></param>
  2759. /// <returns></returns>
  2760. public void osSetTerrainTexture(int level, LSL_Key texture)
  2761. {
  2762. CheckThreatLevel(ThreatLevel.High, "osSetTerrainTexture");
  2763. m_host.AddScriptLPS(1);
  2764. //Check to make sure that the script's owner is the estate manager/master
  2765. //World.Permissions.GenericEstatePermission(
  2766. if (World.Permissions.IsGod(m_host.OwnerID))
  2767. {
  2768. if (level < 0 || level > 3)
  2769. return;
  2770. UUID textureID = new UUID();
  2771. if (!UUID.TryParse(texture, out textureID))
  2772. return;
  2773. // estate module is required
  2774. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  2775. if (estate != null)
  2776. estate.setEstateTerrainBaseTexture(level, textureID);
  2777. }
  2778. }
  2779. /// <summary>
  2780. /// Sets terrain heights of estate
  2781. /// </summary>
  2782. /// <param name="corner"></param>
  2783. /// <param name="low"></param>
  2784. /// <param name="high"></param>
  2785. /// <returns></returns>
  2786. public void osSetTerrainTextureHeight(int corner, double low, double high)
  2787. {
  2788. CheckThreatLevel(ThreatLevel.High, "osSetTerrainTextureHeight");
  2789. m_host.AddScriptLPS(1);
  2790. //Check to make sure that the script's owner is the estate manager/master
  2791. //World.Permissions.GenericEstatePermission(
  2792. if (World.Permissions.IsGod(m_host.OwnerID))
  2793. {
  2794. if (corner < 0 || corner > 3)
  2795. return;
  2796. // estate module is required
  2797. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  2798. if (estate != null)
  2799. estate.setEstateTerrainTextureHeights(corner, (float)low, (float)high);
  2800. }
  2801. }
  2802. #region Attachment commands
  2803. public void osForceAttachToAvatar(int attachmentPoint)
  2804. {
  2805. CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar");
  2806. m_host.AddScriptLPS(1);
  2807. InitLSL();
  2808. ((LSL_Api)m_LSL_Api).AttachToAvatar(attachmentPoint);
  2809. }
  2810. public void osForceAttachToAvatarFromInventory(string itemName, int attachmentPoint)
  2811. {
  2812. CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatarFromInventory");
  2813. m_host.AddScriptLPS(1);
  2814. ForceAttachToAvatarFromInventory(m_host.OwnerID, itemName, attachmentPoint);
  2815. }
  2816. public void osForceAttachToOtherAvatarFromInventory(string rawAvatarId, string itemName, int attachmentPoint)
  2817. {
  2818. CheckThreatLevel(ThreatLevel.VeryHigh, "osForceAttachToOtherAvatarFromInventory");
  2819. m_host.AddScriptLPS(1);
  2820. UUID avatarId;
  2821. if (!UUID.TryParse(rawAvatarId, out avatarId))
  2822. return;
  2823. ForceAttachToAvatarFromInventory(avatarId, itemName, attachmentPoint);
  2824. }
  2825. public void ForceAttachToAvatarFromInventory(UUID avatarId, string itemName, int attachmentPoint)
  2826. {
  2827. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  2828. if (attachmentsModule == null)
  2829. return;
  2830. InitLSL();
  2831. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  2832. if (item == null)
  2833. {
  2834. ((LSL_Api)m_LSL_Api).llSay(0, string.Format("Could not find object '{0}'", itemName));
  2835. throw new Exception(String.Format("The inventory item '{0}' could not be found", itemName));
  2836. }
  2837. if (item.InvType != (int)InventoryType.Object)
  2838. {
  2839. // FIXME: Temporary null check for regression tests since they dont' have the infrastructure to set
  2840. // up the api reference.
  2841. if (m_LSL_Api != null)
  2842. ((LSL_Api)m_LSL_Api).llSay(0, string.Format("Unable to attach, item '{0}' is not an object.", itemName));
  2843. throw new Exception(String.Format("The inventory item '{0}' is not an object", itemName));
  2844. }
  2845. ScenePresence sp = World.GetScenePresence(avatarId);
  2846. if (sp == null)
  2847. return;
  2848. string message;
  2849. InventoryItemBase newItem = World.MoveTaskInventoryItem(sp.UUID, UUID.Zero, m_host, item.ItemID, out message);
  2850. if (newItem == null)
  2851. {
  2852. m_log.ErrorFormat(
  2853. "[OSSL API]: Could not create user inventory item {0} for {1}, attach point {2} in {3}: {4}",
  2854. itemName, m_host.Name, attachmentPoint, World.Name, message);
  2855. ((LSL_Api)m_LSL_Api).llSay(0, message);
  2856. return;
  2857. }
  2858. attachmentsModule.RezSingleAttachmentFromInventory(sp, newItem.ID, (uint)attachmentPoint);
  2859. }
  2860. public void osForceDetachFromAvatar()
  2861. {
  2862. CheckThreatLevel(ThreatLevel.High, "osForceDetachFromAvatar");
  2863. m_host.AddScriptLPS(1);
  2864. InitLSL();
  2865. ((LSL_Api)m_LSL_Api).DetachFromAvatar();
  2866. }
  2867. public LSL_List osGetNumberOfAttachments(LSL_Key avatar, LSL_List attachmentPoints)
  2868. {
  2869. CheckThreatLevel(ThreatLevel.Moderate, "osGetNumberOfAttachments");
  2870. m_host.AddScriptLPS(1);
  2871. UUID targetUUID;
  2872. ScenePresence target;
  2873. LSL_List resp = new LSL_List();
  2874. if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out targetUUID) && World.TryGetScenePresence(targetUUID, out target))
  2875. {
  2876. foreach (object point in attachmentPoints.Data)
  2877. {
  2878. LSL_Integer ipoint = new LSL_Integer(
  2879. (point is LSL_Integer || point is int || point is uint) ?
  2880. (int)point :
  2881. 0
  2882. );
  2883. resp.Add(ipoint);
  2884. if (ipoint == 0)
  2885. {
  2886. // indicates zero attachments
  2887. resp.Add(new LSL_Integer(0));
  2888. }
  2889. else
  2890. {
  2891. // gets the number of attachments on the attachment point
  2892. resp.Add(new LSL_Integer(target.GetAttachments((uint)ipoint).Count));
  2893. }
  2894. }
  2895. }
  2896. return resp;
  2897. }
  2898. public void osMessageAttachments(LSL_Key avatar, string message, LSL_List attachmentPoints, int options)
  2899. {
  2900. CheckThreatLevel(ThreatLevel.Moderate, "osMessageAttachments");
  2901. m_host.AddScriptLPS(1);
  2902. UUID targetUUID;
  2903. ScenePresence target;
  2904. if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out targetUUID) && World.TryGetScenePresence(targetUUID, out target))
  2905. {
  2906. List<int> aps = new List<int>();
  2907. foreach (object point in attachmentPoints.Data)
  2908. {
  2909. int ipoint;
  2910. if (int.TryParse(point.ToString(), out ipoint))
  2911. {
  2912. aps.Add(ipoint);
  2913. }
  2914. }
  2915. List<SceneObjectGroup> attachments = new List<SceneObjectGroup>();
  2916. bool msgAll = aps.Contains(ScriptBaseClass.OS_ATTACH_MSG_ALL);
  2917. bool invertPoints = (options & ScriptBaseClass.OS_ATTACH_MSG_INVERT_POINTS) != 0;
  2918. if (msgAll && invertPoints)
  2919. {
  2920. return;
  2921. }
  2922. else if (msgAll || invertPoints)
  2923. {
  2924. attachments = target.GetAttachments();
  2925. }
  2926. else
  2927. {
  2928. foreach (int point in aps)
  2929. {
  2930. if (point > 0)
  2931. {
  2932. attachments.AddRange(target.GetAttachments((uint)point));
  2933. }
  2934. }
  2935. }
  2936. // if we have no attachments at this point, exit now
  2937. if (attachments.Count == 0)
  2938. {
  2939. return;
  2940. }
  2941. List<SceneObjectGroup> ignoreThese = new List<SceneObjectGroup>();
  2942. if (invertPoints)
  2943. {
  2944. foreach (SceneObjectGroup attachment in attachments)
  2945. {
  2946. if (aps.Contains((int)attachment.AttachmentPoint))
  2947. {
  2948. ignoreThese.Add(attachment);
  2949. }
  2950. }
  2951. }
  2952. foreach (SceneObjectGroup attachment in ignoreThese)
  2953. {
  2954. attachments.Remove(attachment);
  2955. }
  2956. ignoreThese.Clear();
  2957. // if inverting removed all attachments to check, exit now
  2958. if (attachments.Count < 1)
  2959. {
  2960. return;
  2961. }
  2962. if ((options & ScriptBaseClass.OS_ATTACH_MSG_OBJECT_CREATOR) != 0)
  2963. {
  2964. foreach (SceneObjectGroup attachment in attachments)
  2965. {
  2966. if (attachment.RootPart.CreatorID != m_host.CreatorID)
  2967. {
  2968. ignoreThese.Add(attachment);
  2969. }
  2970. }
  2971. foreach (SceneObjectGroup attachment in ignoreThese)
  2972. {
  2973. attachments.Remove(attachment);
  2974. }
  2975. ignoreThese.Clear();
  2976. // if filtering by same object creator removed all
  2977. // attachments to check, exit now
  2978. if (attachments.Count == 0)
  2979. {
  2980. return;
  2981. }
  2982. }
  2983. if ((options & ScriptBaseClass.OS_ATTACH_MSG_SCRIPT_CREATOR) != 0)
  2984. {
  2985. foreach (SceneObjectGroup attachment in attachments)
  2986. {
  2987. if (attachment.RootPart.CreatorID != m_item.CreatorID)
  2988. {
  2989. ignoreThese.Add(attachment);
  2990. }
  2991. }
  2992. foreach (SceneObjectGroup attachment in ignoreThese)
  2993. {
  2994. attachments.Remove(attachment);
  2995. }
  2996. ignoreThese.Clear();
  2997. // if filtering by object creator must match originating
  2998. // script creator removed all attachments to check,
  2999. // exit now
  3000. if (attachments.Count == 0)
  3001. {
  3002. return;
  3003. }
  3004. }
  3005. foreach (SceneObjectGroup attachment in attachments)
  3006. {
  3007. MessageObject(attachment.RootPart.UUID, message);
  3008. }
  3009. }
  3010. }
  3011. #endregion
  3012. /// <summary>
  3013. /// Checks if thing is a UUID.
  3014. /// </summary>
  3015. /// <param name="thing"></param>
  3016. /// <returns>1 if thing is a valid UUID, 0 otherwise</returns>
  3017. public LSL_Integer osIsUUID(string thing)
  3018. {
  3019. CheckThreatLevel(ThreatLevel.None, "osIsUUID");
  3020. m_host.AddScriptLPS(1);
  3021. UUID test;
  3022. return UUID.TryParse(thing, out test) ? 1 : 0;
  3023. }
  3024. /// <summary>
  3025. /// Wraps to Math.Min()
  3026. /// </summary>
  3027. /// <param name="a"></param>
  3028. /// <param name="b"></param>
  3029. /// <returns></returns>
  3030. public LSL_Float osMin(double a, double b)
  3031. {
  3032. CheckThreatLevel(ThreatLevel.None, "osMin");
  3033. m_host.AddScriptLPS(1);
  3034. return Math.Min(a, b);
  3035. }
  3036. /// <summary>
  3037. /// Wraps to Math.max()
  3038. /// </summary>
  3039. /// <param name="a"></param>
  3040. /// <param name="b"></param>
  3041. /// <returns></returns>
  3042. public LSL_Float osMax(double a, double b)
  3043. {
  3044. CheckThreatLevel(ThreatLevel.None, "osMax");
  3045. m_host.AddScriptLPS(1);
  3046. return Math.Max(a, b);
  3047. }
  3048. public LSL_Key osGetRezzingObject()
  3049. {
  3050. CheckThreatLevel(ThreatLevel.None, "osGetRezzingObject");
  3051. m_host.AddScriptLPS(1);
  3052. return new LSL_Key(m_host.ParentGroup.FromPartID.ToString());
  3053. }
  3054. /// <summary>
  3055. /// Sets the response type for an HTTP request/response
  3056. /// </summary>
  3057. /// <returns></returns>
  3058. public void osSetContentType(LSL_Key id, string type)
  3059. {
  3060. CheckThreatLevel(ThreatLevel.High, "osSetContentType");
  3061. if (m_UrlModule != null)
  3062. m_UrlModule.HttpContentType(new UUID(id),type);
  3063. }
  3064. /// Shout an error if the object owner did not grant the script the specified permissions.
  3065. /// </summary>
  3066. /// <param name="perms"></param>
  3067. /// <returns>boolean indicating whether an error was shouted.</returns>
  3068. protected bool ShoutErrorOnLackingOwnerPerms(int perms, string errorPrefix)
  3069. {
  3070. m_host.AddScriptLPS(1);
  3071. bool fail = false;
  3072. if (m_item.PermsGranter != m_host.OwnerID)
  3073. {
  3074. fail = true;
  3075. OSSLShoutError(string.Format("{0}. Permissions not granted to owner.", errorPrefix));
  3076. }
  3077. else if ((m_item.PermsMask & perms) == 0)
  3078. {
  3079. fail = true;
  3080. OSSLShoutError(string.Format("{0}. Permissions not granted.", errorPrefix));
  3081. }
  3082. return fail;
  3083. }
  3084. protected void DropAttachment(bool checkPerms)
  3085. {
  3086. if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment"))
  3087. {
  3088. return;
  3089. }
  3090. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  3091. ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID);
  3092. if (attachmentsModule != null && sp != null)
  3093. {
  3094. attachmentsModule.DetachSingleAttachmentToGround(sp, m_host.ParentGroup.LocalId);
  3095. }
  3096. }
  3097. protected void DropAttachmentAt(bool checkPerms, LSL_Vector pos, LSL_Rotation rot)
  3098. {
  3099. if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment"))
  3100. {
  3101. return;
  3102. }
  3103. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  3104. ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID);
  3105. if (attachmentsModule != null && sp != null)
  3106. {
  3107. attachmentsModule.DetachSingleAttachmentToGround(sp, m_host.ParentGroup.LocalId, pos, rot);
  3108. }
  3109. }
  3110. public void osDropAttachment()
  3111. {
  3112. CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachment");
  3113. m_host.AddScriptLPS(1);
  3114. DropAttachment(true);
  3115. }
  3116. public void osForceDropAttachment()
  3117. {
  3118. CheckThreatLevel(ThreatLevel.High, "osForceDropAttachment");
  3119. m_host.AddScriptLPS(1);
  3120. DropAttachment(false);
  3121. }
  3122. public void osDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot)
  3123. {
  3124. CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachmentAt");
  3125. m_host.AddScriptLPS(1);
  3126. DropAttachmentAt(true, pos, rot);
  3127. }
  3128. public void osForceDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot)
  3129. {
  3130. CheckThreatLevel(ThreatLevel.High, "osForceDropAttachmentAt");
  3131. m_host.AddScriptLPS(1);
  3132. DropAttachmentAt(false, pos, rot);
  3133. }
  3134. public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
  3135. {
  3136. CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
  3137. m_host.AddScriptLPS(1);
  3138. UUID keyID;
  3139. UUID.TryParse(ID, out keyID);
  3140. // if we want the name to be used as a regular expression, ensure it is valid first.
  3141. if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_NAME) == ScriptBaseClass.OS_LISTEN_REGEX_NAME)
  3142. {
  3143. try
  3144. {
  3145. Regex.IsMatch("", name);
  3146. }
  3147. catch (Exception)
  3148. {
  3149. OSSLShoutError("Name regex is invalid.");
  3150. return -1;
  3151. }
  3152. }
  3153. // if we want the msg to be used as a regular expression, ensure it is valid first.
  3154. if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) == ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE)
  3155. {
  3156. try
  3157. {
  3158. Regex.IsMatch("", msg);
  3159. }
  3160. catch (Exception)
  3161. {
  3162. OSSLShoutError("Message regex is invalid.");
  3163. return -1;
  3164. }
  3165. }
  3166. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  3167. return (wComm == null) ? -1 : wComm.Listen(
  3168. m_host.LocalId,
  3169. m_item.ItemID,
  3170. m_host.UUID,
  3171. channelID,
  3172. name,
  3173. keyID,
  3174. msg,
  3175. regexBitfield
  3176. );
  3177. }
  3178. public LSL_Integer osRegexIsMatch(string input, string pattern)
  3179. {
  3180. CheckThreatLevel(ThreatLevel.Low, "osRegexIsMatch");
  3181. m_host.AddScriptLPS(1);
  3182. try
  3183. {
  3184. return Regex.IsMatch(input, pattern) ? 1 : 0;
  3185. }
  3186. catch (Exception)
  3187. {
  3188. OSSLShoutError("Possible invalid regular expression detected.");
  3189. return 0;
  3190. }
  3191. }
  3192. }
  3193. }