OSSL_Api.cs 137 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748
  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 > ((int)Constants.RegionSize - 1) || x < 0 || y > ((int)Constants.RegionSize - 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 > ((int)Constants.RegionSize - 1) || x < 0 || y > ((int)Constants.RegionSize - 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(o => World.RequestTeleportLocation(
  695. presence.ControllingClient, regionName, position,
  696. lookat, (uint)TPFlags.ViaLocation));
  697. ScriptSleep(5000);
  698. // }
  699. }
  700. }
  701. }
  702. public void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  703. {
  704. // High because there is no security check. High griefer potential
  705. //
  706. CheckThreatLevel(ThreatLevel.Severe, "osTeleportAgent");
  707. TeleportAgent(agent, regionX, regionY, position, lookat, false);
  708. }
  709. private void TeleportAgent(string agent, int regionX, int regionY,
  710. LSL_Types.Vector3 position, LSL_Types.Vector3 lookat, bool relaxRestrictions)
  711. {
  712. ulong regionHandle = Util.UIntsToLong(((uint)regionX * (uint)Constants.RegionSize), ((uint)regionY * (uint)Constants.RegionSize));
  713. m_host.AddScriptLPS(1);
  714. UUID agentId = new UUID();
  715. if (UUID.TryParse(agent, out agentId))
  716. {
  717. ScenePresence presence = World.GetScenePresence(agentId);
  718. if (presence != null)
  719. {
  720. // For osTeleportAgent, agent must be over owners land to avoid abuse
  721. // For osTeleportOwner, this restriction isn't necessary
  722. // commented out because its redundant and uneeded please remove eventually.
  723. // if (relaxRestrictions ||
  724. // m_host.OwnerID
  725. // == World.LandChannel.GetLandObject(
  726. // presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
  727. // {
  728. // We will launch the teleport on a new thread so that when the script threads are terminated
  729. // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting.
  730. Util.FireAndForget(o => World.RequestTeleportLocation(
  731. presence.ControllingClient, regionHandle,
  732. position, lookat, (uint)TPFlags.ViaLocation));
  733. ScriptSleep(5000);
  734. // }
  735. }
  736. }
  737. }
  738. public void osTeleportAgent(string agent, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  739. {
  740. osTeleportAgent(agent, World.RegionInfo.RegionName, position, lookat);
  741. }
  742. public void osTeleportOwner(string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  743. {
  744. // Threat level None because this is what can already be done with the World Map in the viewer
  745. CheckThreatLevel(ThreatLevel.None, "osTeleportOwner");
  746. TeleportAgent(m_host.OwnerID.ToString(), regionName, position, lookat, true);
  747. }
  748. public void osTeleportOwner(LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  749. {
  750. osTeleportOwner(World.RegionInfo.RegionName, position, lookat);
  751. }
  752. public void osTeleportOwner(int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  753. {
  754. CheckThreatLevel(ThreatLevel.None, "osTeleportOwner");
  755. TeleportAgent(m_host.OwnerID.ToString(), regionX, regionY, position, lookat, true);
  756. }
  757. // Functions that get information from the agent itself.
  758. //
  759. // osGetAgentIP - this is used to determine the IP address of
  760. //the client. This is needed to help configure other in world
  761. //resources based on the IP address of the clients connected.
  762. //I think High is a good risk level for this, as it is an
  763. //information leak.
  764. public string osGetAgentIP(string agent)
  765. {
  766. CheckThreatLevel(ThreatLevel.High, "osGetAgentIP");
  767. UUID avatarID = (UUID)agent;
  768. m_host.AddScriptLPS(1);
  769. if (World.Entities.ContainsKey((UUID)agent) && World.Entities[avatarID] is ScenePresence)
  770. {
  771. ScenePresence target = (ScenePresence)World.Entities[avatarID];
  772. return target.ControllingClient.RemoteEndPoint.Address.ToString();
  773. }
  774. // fall through case, just return nothing
  775. return "";
  776. }
  777. // Get a list of all the avatars/agents in the region
  778. public LSL_List osGetAgents()
  779. {
  780. // threat level is None as we could get this information with an
  781. // in-world script as well, just not as efficient
  782. CheckThreatLevel(ThreatLevel.None, "osGetAgents");
  783. m_host.AddScriptLPS(1);
  784. LSL_List result = new LSL_List();
  785. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  786. {
  787. result.Add(new LSL_String(sp.Name));
  788. });
  789. return result;
  790. }
  791. // Adam's super super custom animation functions
  792. public void osAvatarPlayAnimation(string avatar, string animation)
  793. {
  794. CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarPlayAnimation");
  795. AvatarPlayAnimation(avatar, animation);
  796. }
  797. private void AvatarPlayAnimation(string avatar, string animation)
  798. {
  799. UUID avatarID = (UUID)avatar;
  800. m_host.AddScriptLPS(1);
  801. if (World.Entities.ContainsKey((UUID)avatar) && World.Entities[avatarID] is ScenePresence)
  802. {
  803. ScenePresence target = (ScenePresence)World.Entities[avatarID];
  804. if (target != null)
  805. {
  806. UUID animID=UUID.Zero;
  807. lock (m_host.TaskInventory)
  808. {
  809. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  810. {
  811. if (inv.Value.Name == animation)
  812. {
  813. if (inv.Value.Type == (int)AssetType.Animation)
  814. animID = inv.Value.AssetID;
  815. continue;
  816. }
  817. }
  818. }
  819. if (animID == UUID.Zero)
  820. target.Animator.AddAnimation(animation, m_host.UUID);
  821. else
  822. target.Animator.AddAnimation(animID, m_host.UUID);
  823. }
  824. }
  825. }
  826. public void osAvatarStopAnimation(string avatar, string animation)
  827. {
  828. CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarStopAnimation");
  829. AvatarStopAnimation(avatar, animation);
  830. }
  831. private void AvatarStopAnimation(string avatar, string animation)
  832. {
  833. UUID avatarID = (UUID)avatar;
  834. m_host.AddScriptLPS(1);
  835. // FIXME: What we really want to do here is factor out the similar code in llStopAnimation() to a common
  836. // method (though see that doesn't do the is animation check, which is probably a bug) and have both
  837. // these functions call that common code. However, this does mean navigating the brain-dead requirement
  838. // of calling InitLSL()
  839. if (World.Entities.ContainsKey(avatarID) && World.Entities[avatarID] is ScenePresence)
  840. {
  841. ScenePresence target = (ScenePresence)World.Entities[avatarID];
  842. if (target != null)
  843. {
  844. UUID animID;
  845. if (!UUID.TryParse(animation, out animID))
  846. {
  847. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(animation);
  848. if (item != null && item.Type == (int)AssetType.Animation)
  849. animID = item.AssetID;
  850. else
  851. animID = UUID.Zero;
  852. }
  853. if (animID == UUID.Zero)
  854. target.Animator.RemoveAnimation(animation);
  855. else
  856. target.Animator.RemoveAnimation(animID, true);
  857. }
  858. }
  859. }
  860. //Texture draw functions
  861. public string osMovePen(string drawList, int x, int y)
  862. {
  863. CheckThreatLevel(ThreatLevel.None, "osMovePen");
  864. m_host.AddScriptLPS(1);
  865. drawList += "MoveTo " + x + "," + y + ";";
  866. return drawList;
  867. }
  868. public string osDrawLine(string drawList, int startX, int startY, int endX, int endY)
  869. {
  870. CheckThreatLevel(ThreatLevel.None, "osDrawLine");
  871. m_host.AddScriptLPS(1);
  872. drawList += "MoveTo "+ startX+","+ startY +"; LineTo "+endX +","+endY +"; ";
  873. return drawList;
  874. }
  875. public string osDrawLine(string drawList, int endX, int endY)
  876. {
  877. CheckThreatLevel(ThreatLevel.None, "osDrawLine");
  878. m_host.AddScriptLPS(1);
  879. drawList += "LineTo " + endX + "," + endY + "; ";
  880. return drawList;
  881. }
  882. public string osDrawText(string drawList, string text)
  883. {
  884. CheckThreatLevel(ThreatLevel.None, "osDrawText");
  885. m_host.AddScriptLPS(1);
  886. drawList += "Text " + text + "; ";
  887. return drawList;
  888. }
  889. public string osDrawEllipse(string drawList, int width, int height)
  890. {
  891. CheckThreatLevel(ThreatLevel.None, "osDrawEllipse");
  892. m_host.AddScriptLPS(1);
  893. drawList += "Ellipse " + width + "," + height + "; ";
  894. return drawList;
  895. }
  896. public string osDrawRectangle(string drawList, int width, int height)
  897. {
  898. CheckThreatLevel(ThreatLevel.None, "osDrawRectangle");
  899. m_host.AddScriptLPS(1);
  900. drawList += "Rectangle " + width + "," + height + "; ";
  901. return drawList;
  902. }
  903. public string osDrawFilledRectangle(string drawList, int width, int height)
  904. {
  905. CheckThreatLevel(ThreatLevel.None, "osDrawFilledRectangle");
  906. m_host.AddScriptLPS(1);
  907. drawList += "FillRectangle " + width + "," + height + "; ";
  908. return drawList;
  909. }
  910. public string osDrawFilledPolygon(string drawList, LSL_List x, LSL_List y)
  911. {
  912. CheckThreatLevel(ThreatLevel.None, "osDrawFilledPolygon");
  913. m_host.AddScriptLPS(1);
  914. if (x.Length != y.Length || x.Length < 3)
  915. {
  916. return "";
  917. }
  918. drawList += "FillPolygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
  919. for (int i = 1; i < x.Length; i++)
  920. {
  921. drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
  922. }
  923. drawList += "; ";
  924. return drawList;
  925. }
  926. public string osDrawPolygon(string drawList, LSL_List x, LSL_List y)
  927. {
  928. CheckThreatLevel(ThreatLevel.None, "osDrawPolygon");
  929. m_host.AddScriptLPS(1);
  930. if (x.Length != y.Length || x.Length < 3)
  931. {
  932. return "";
  933. }
  934. drawList += "Polygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
  935. for (int i = 1; i < x.Length; i++)
  936. {
  937. drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
  938. }
  939. drawList += "; ";
  940. return drawList;
  941. }
  942. public string osSetFontSize(string drawList, int fontSize)
  943. {
  944. CheckThreatLevel(ThreatLevel.None, "osSetFontSize");
  945. m_host.AddScriptLPS(1);
  946. drawList += "FontSize "+ fontSize +"; ";
  947. return drawList;
  948. }
  949. public string osSetFontName(string drawList, string fontName)
  950. {
  951. CheckThreatLevel(ThreatLevel.None, "osSetFontName");
  952. m_host.AddScriptLPS(1);
  953. drawList += "FontName "+ fontName +"; ";
  954. return drawList;
  955. }
  956. public string osSetPenSize(string drawList, int penSize)
  957. {
  958. CheckThreatLevel(ThreatLevel.None, "osSetPenSize");
  959. m_host.AddScriptLPS(1);
  960. drawList += "PenSize " + penSize + "; ";
  961. return drawList;
  962. }
  963. public string osSetPenColor(string drawList, string color)
  964. {
  965. CheckThreatLevel(ThreatLevel.None, "osSetPenColor");
  966. m_host.AddScriptLPS(1);
  967. drawList += "PenColor " + color + "; ";
  968. return drawList;
  969. }
  970. // Deprecated
  971. public string osSetPenColour(string drawList, string colour)
  972. {
  973. CheckThreatLevel(ThreatLevel.None, "osSetPenColour");
  974. OSSLDeprecated("osSetPenColour", "osSetPenColor");
  975. m_host.AddScriptLPS(1);
  976. drawList += "PenColour " + colour + "; ";
  977. return drawList;
  978. }
  979. public string osSetPenCap(string drawList, string direction, string type)
  980. {
  981. CheckThreatLevel(ThreatLevel.None, "osSetPenCap");
  982. m_host.AddScriptLPS(1);
  983. drawList += "PenCap " + direction + "," + type + "; ";
  984. return drawList;
  985. }
  986. public string osDrawImage(string drawList, int width, int height, string imageUrl)
  987. {
  988. CheckThreatLevel(ThreatLevel.None, "osDrawImage");
  989. m_host.AddScriptLPS(1);
  990. drawList +="Image " +width + "," + height+ ","+ imageUrl +"; " ;
  991. return drawList;
  992. }
  993. public LSL_Vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize)
  994. {
  995. CheckThreatLevel(ThreatLevel.VeryLow, "osGetDrawStringSize");
  996. m_host.AddScriptLPS(1);
  997. LSL_Vector vec = new LSL_Vector(0,0,0);
  998. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  999. if (textureManager != null)
  1000. {
  1001. double xSize, ySize;
  1002. textureManager.GetDrawStringSize(contentType, text, fontName, fontSize,
  1003. out xSize, out ySize);
  1004. vec.x = xSize;
  1005. vec.y = ySize;
  1006. }
  1007. return vec;
  1008. }
  1009. public void osSetStateEvents(int events)
  1010. {
  1011. // This function is a hack. There is no reason for it's existence
  1012. // anymore, since state events now work properly.
  1013. // It was probably added as a crutch or debugging aid, and
  1014. // should be removed
  1015. //
  1016. CheckThreatLevel(ThreatLevel.High, "osSetStateEvents");
  1017. m_host.AddScriptLPS(1);
  1018. m_host.SetScriptEvents(m_item.ItemID, events);
  1019. }
  1020. public void osSetRegionWaterHeight(double height)
  1021. {
  1022. CheckThreatLevel(ThreatLevel.High, "osSetRegionWaterHeight");
  1023. m_host.AddScriptLPS(1);
  1024. World.EventManager.TriggerRequestChangeWaterHeight((float)height);
  1025. }
  1026. /// <summary>
  1027. /// Changes the Region Sun Settings, then Triggers a Sun Update
  1028. /// </summary>
  1029. /// <param name="useEstateSun">True to use Estate Sun instead of Region Sun</param>
  1030. /// <param name="sunFixed">True to keep the sun stationary</param>
  1031. /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
  1032. public void osSetRegionSunSettings(bool useEstateSun, bool sunFixed, double sunHour)
  1033. {
  1034. CheckThreatLevel(ThreatLevel.High, "osSetRegionSunSettings");
  1035. m_host.AddScriptLPS(1);
  1036. while (sunHour > 24.0)
  1037. sunHour -= 24.0;
  1038. while (sunHour < 0)
  1039. sunHour += 24.0;
  1040. World.RegionInfo.RegionSettings.UseEstateSun = useEstateSun;
  1041. World.RegionInfo.RegionSettings.SunPosition = sunHour + 6; // LL Region Sun Hour is 6 to 30
  1042. World.RegionInfo.RegionSettings.FixedSun = sunFixed;
  1043. World.RegionInfo.RegionSettings.Save();
  1044. World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle);
  1045. }
  1046. /// <summary>
  1047. /// Changes the Estate Sun Settings, then Triggers a Sun Update
  1048. /// </summary>
  1049. /// <param name="sunFixed">True to keep the sun stationary, false to use global time</param>
  1050. /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
  1051. public void osSetEstateSunSettings(bool sunFixed, double sunHour)
  1052. {
  1053. CheckThreatLevel(ThreatLevel.High, "osSetEstateSunSettings");
  1054. m_host.AddScriptLPS(1);
  1055. while (sunHour > 24.0)
  1056. sunHour -= 24.0;
  1057. while (sunHour < 0)
  1058. sunHour += 24.0;
  1059. World.RegionInfo.EstateSettings.UseGlobalTime = !sunFixed;
  1060. World.RegionInfo.EstateSettings.SunPosition = sunHour;
  1061. World.RegionInfo.EstateSettings.FixedSun = sunFixed;
  1062. World.RegionInfo.EstateSettings.Save();
  1063. World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle);
  1064. }
  1065. /// <summary>
  1066. /// Return the current Sun Hour 0...24, with 0 being roughly sun-rise
  1067. /// </summary>
  1068. /// <returns></returns>
  1069. public double osGetCurrentSunHour()
  1070. {
  1071. CheckThreatLevel(ThreatLevel.None, "osGetCurrentSunHour");
  1072. m_host.AddScriptLPS(1);
  1073. // Must adjust for the fact that Region Sun Settings are still LL offset
  1074. double sunHour = World.RegionInfo.RegionSettings.SunPosition - 6;
  1075. // See if the sun module has registered itself, if so it's authoritative
  1076. ISunModule module = World.RequestModuleInterface<ISunModule>();
  1077. if (module != null)
  1078. {
  1079. sunHour = module.GetCurrentSunHour();
  1080. }
  1081. return sunHour;
  1082. }
  1083. public double osSunGetParam(string param)
  1084. {
  1085. CheckThreatLevel(ThreatLevel.None, "osSunGetParam");
  1086. OSSLDeprecated("osSunGetParam", "osGetSunParam");
  1087. return GetSunParam(param);
  1088. }
  1089. public double osGetSunParam(string param)
  1090. {
  1091. CheckThreatLevel(ThreatLevel.None, "osGetSunParam");
  1092. return GetSunParam(param);
  1093. }
  1094. private double GetSunParam(string param)
  1095. {
  1096. m_host.AddScriptLPS(1);
  1097. double value = 0.0;
  1098. ISunModule module = World.RequestModuleInterface<ISunModule>();
  1099. if (module != null)
  1100. {
  1101. value = module.GetSunParameter(param);
  1102. }
  1103. return value;
  1104. }
  1105. public void osSunSetParam(string param, double value)
  1106. {
  1107. CheckThreatLevel(ThreatLevel.None, "osSunSetParam");
  1108. OSSLDeprecated("osSunSetParam", "osSetSunParam");
  1109. SetSunParam(param, value);
  1110. }
  1111. public void osSetSunParam(string param, double value)
  1112. {
  1113. CheckThreatLevel(ThreatLevel.None, "osSetSunParam");
  1114. SetSunParam(param, value);
  1115. }
  1116. private void SetSunParam(string param, double value)
  1117. {
  1118. m_host.AddScriptLPS(1);
  1119. ISunModule module = World.RequestModuleInterface<ISunModule>();
  1120. if (module != null)
  1121. {
  1122. module.SetSunParameter(param, value);
  1123. }
  1124. }
  1125. public string osWindActiveModelPluginName()
  1126. {
  1127. CheckThreatLevel(ThreatLevel.None, "osWindActiveModelPluginName");
  1128. m_host.AddScriptLPS(1);
  1129. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1130. if (module != null)
  1131. {
  1132. return module.WindActiveModelPluginName;
  1133. }
  1134. return String.Empty;
  1135. }
  1136. public void osSetWindParam(string plugin, string param, LSL_Float value)
  1137. {
  1138. CheckThreatLevel(ThreatLevel.VeryLow, "osSetWindParam");
  1139. m_host.AddScriptLPS(1);
  1140. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1141. if (module != null)
  1142. {
  1143. try
  1144. {
  1145. module.WindParamSet(plugin, param, (float)value);
  1146. }
  1147. catch (Exception) { }
  1148. }
  1149. }
  1150. public LSL_Float osGetWindParam(string plugin, string param)
  1151. {
  1152. CheckThreatLevel(ThreatLevel.VeryLow, "osGetWindParam");
  1153. m_host.AddScriptLPS(1);
  1154. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1155. if (module != null)
  1156. {
  1157. return module.WindParamGet(plugin, param);
  1158. }
  1159. return 0.0f;
  1160. }
  1161. // Routines for creating and managing parcels programmatically
  1162. public void osParcelJoin(LSL_Vector pos1, LSL_Vector pos2)
  1163. {
  1164. CheckThreatLevel(ThreatLevel.High, "osParcelJoin");
  1165. m_host.AddScriptLPS(1);
  1166. int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
  1167. int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
  1168. int endx = (int)(pos1.x > pos2.x ? pos1.x : pos2.x);
  1169. int endy = (int)(pos1.y > pos2.y ? pos1.y : pos2.y);
  1170. World.LandChannel.Join(startx,starty,endx,endy,m_host.OwnerID);
  1171. }
  1172. public void osParcelSubdivide(LSL_Vector pos1, LSL_Vector pos2)
  1173. {
  1174. CheckThreatLevel(ThreatLevel.High, "osParcelSubdivide");
  1175. m_host.AddScriptLPS(1);
  1176. int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
  1177. int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
  1178. int endx = (int)(pos1.x > pos2.x ? pos1.x : pos2.x);
  1179. int endy = (int)(pos1.y > pos2.y ? pos1.y : pos2.y);
  1180. World.LandChannel.Subdivide(startx,starty,endx,endy,m_host.OwnerID);
  1181. }
  1182. public void osParcelSetDetails(LSL_Vector pos, LSL_List rules)
  1183. {
  1184. const string functionName = "osParcelSetDetails";
  1185. CheckThreatLevel(ThreatLevel.High, functionName);
  1186. OSSLDeprecated(functionName, "osSetParcelDetails");
  1187. SetParcelDetails(pos, rules, functionName);
  1188. }
  1189. public void osSetParcelDetails(LSL_Vector pos, LSL_List rules)
  1190. {
  1191. const string functionName = "osSetParcelDetails";
  1192. CheckThreatLevel(ThreatLevel.High, functionName);
  1193. SetParcelDetails(pos, rules, functionName);
  1194. }
  1195. private void SetParcelDetails(LSL_Vector pos, LSL_List rules, string functionName)
  1196. {
  1197. m_host.AddScriptLPS(1);
  1198. // Get a reference to the land data and make sure the owner of the script
  1199. // can modify it
  1200. ILandObject startLandObject = World.LandChannel.GetLandObject((int)pos.x, (int)pos.y);
  1201. if (startLandObject == null)
  1202. {
  1203. OSSLShoutError("There is no land at that location");
  1204. return;
  1205. }
  1206. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, startLandObject, GroupPowers.LandOptions))
  1207. {
  1208. OSSLShoutError("You do not have permission to modify the parcel");
  1209. return;
  1210. }
  1211. // Create a new land data object we can modify
  1212. LandData newLand = startLandObject.LandData.Copy();
  1213. UUID uuid;
  1214. // Process the rules, not sure what the impact would be of changing owner or group
  1215. for (int idx = 0; idx < rules.Length;)
  1216. {
  1217. int code = rules.GetLSLIntegerItem(idx++);
  1218. string arg = rules.GetLSLStringItem(idx++);
  1219. switch (code)
  1220. {
  1221. case ScriptBaseClass.PARCEL_DETAILS_NAME:
  1222. newLand.Name = arg;
  1223. break;
  1224. case ScriptBaseClass.PARCEL_DETAILS_DESC:
  1225. newLand.Description = arg;
  1226. break;
  1227. case ScriptBaseClass.PARCEL_DETAILS_OWNER:
  1228. CheckThreatLevel(ThreatLevel.VeryHigh, functionName);
  1229. if (UUID.TryParse(arg, out uuid))
  1230. newLand.OwnerID = uuid;
  1231. break;
  1232. case ScriptBaseClass.PARCEL_DETAILS_GROUP:
  1233. CheckThreatLevel(ThreatLevel.VeryHigh, functionName);
  1234. if (UUID.TryParse(arg, out uuid))
  1235. newLand.GroupID = uuid;
  1236. break;
  1237. case ScriptBaseClass.PARCEL_DETAILS_CLAIMDATE:
  1238. CheckThreatLevel(ThreatLevel.VeryHigh, functionName);
  1239. newLand.ClaimDate = Convert.ToInt32(arg);
  1240. if (newLand.ClaimDate == 0)
  1241. newLand.ClaimDate = Util.UnixTimeSinceEpoch();
  1242. break;
  1243. }
  1244. }
  1245. World.LandChannel.UpdateLandObject(newLand.LocalID,newLand);
  1246. }
  1247. public double osList2Double(LSL_Types.list src, int index)
  1248. {
  1249. // There is really no double type in OSSL. C# and other
  1250. // have one, but the current implementation of LSL_Types.list
  1251. // is not allowed to contain any.
  1252. // This really should be removed.
  1253. //
  1254. CheckThreatLevel(ThreatLevel.None, "osList2Double");
  1255. m_host.AddScriptLPS(1);
  1256. if (index < 0)
  1257. {
  1258. index = src.Length + index;
  1259. }
  1260. if (index >= src.Length)
  1261. {
  1262. return 0.0;
  1263. }
  1264. return Convert.ToDouble(src.Data[index]);
  1265. }
  1266. public void osSetParcelMediaURL(string url)
  1267. {
  1268. // What actually is the difference to the LL function?
  1269. //
  1270. CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL");
  1271. m_host.AddScriptLPS(1);
  1272. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  1273. if (land.LandData.OwnerID != m_host.OwnerID)
  1274. return;
  1275. land.SetMediaUrl(url);
  1276. }
  1277. public void osSetParcelSIPAddress(string SIPAddress)
  1278. {
  1279. // What actually is the difference to the LL function?
  1280. //
  1281. CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelSIPAddress");
  1282. m_host.AddScriptLPS(1);
  1283. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  1284. if (land.LandData.OwnerID != m_host.OwnerID)
  1285. {
  1286. OSSLError("osSetParcelSIPAddress: Sorry, you need to own the land to use this function");
  1287. return;
  1288. }
  1289. // get the voice module
  1290. IVoiceModule voiceModule = World.RequestModuleInterface<IVoiceModule>();
  1291. if (voiceModule != null)
  1292. voiceModule.setLandSIPAddress(SIPAddress,land.LandData.GlobalID);
  1293. else
  1294. OSSLError("osSetParcelSIPAddress: No voice module enabled for this land");
  1295. }
  1296. public string osGetScriptEngineName()
  1297. {
  1298. // This gets a "high" because knowing the engine may be used
  1299. // to exploit engine-specific bugs or induce usage patterns
  1300. // that trigger engine-specific failures.
  1301. // Besides, public grid users aren't supposed to know.
  1302. //
  1303. CheckThreatLevel(ThreatLevel.High, "osGetScriptEngineName");
  1304. m_host.AddScriptLPS(1);
  1305. int scriptEngineNameIndex = 0;
  1306. if (!String.IsNullOrEmpty(m_ScriptEngine.ScriptEngineName))
  1307. {
  1308. // parse off the "ScriptEngine."
  1309. scriptEngineNameIndex = m_ScriptEngine.ScriptEngineName.IndexOf(".", scriptEngineNameIndex);
  1310. scriptEngineNameIndex++; // get past delimiter
  1311. int scriptEngineNameLength = m_ScriptEngine.ScriptEngineName.Length - scriptEngineNameIndex;
  1312. // create char array then a string that is only the script engine name
  1313. Char[] scriptEngineNameCharArray = m_ScriptEngine.ScriptEngineName.ToCharArray(scriptEngineNameIndex, scriptEngineNameLength);
  1314. String scriptEngineName = new String(scriptEngineNameCharArray);
  1315. return scriptEngineName;
  1316. }
  1317. else
  1318. {
  1319. return String.Empty;
  1320. }
  1321. }
  1322. public string osGetPhysicsEngineType()
  1323. {
  1324. // High because it can be used to target attacks to known weaknesses
  1325. // This would allow a new class of griefer scripts that don't even
  1326. // require their user to know what they are doing (see script
  1327. // kiddie)
  1328. // Because it would be nice if scripts didn't blow up if the information
  1329. // about the physics engine, this function returns an empty string if
  1330. // the user does not have permission to see it. This as opposed to
  1331. // throwing an exception.
  1332. m_host.AddScriptLPS(1);
  1333. string ret = String.Empty;
  1334. if (String.IsNullOrEmpty(CheckThreatLevelTest(ThreatLevel.High, "osGetPhysicsEngineType")))
  1335. {
  1336. if (m_ScriptEngine.World.PhysicsScene != null)
  1337. {
  1338. ret = m_ScriptEngine.World.PhysicsScene.EngineType;
  1339. // An old physics engine might have an uninitialized engine type
  1340. if (ret == null)
  1341. ret = "unknown";
  1342. }
  1343. }
  1344. return ret;
  1345. }
  1346. public string osGetSimulatorVersion()
  1347. {
  1348. // High because it can be used to target attacks to known weaknesses
  1349. // This would allow a new class of griefer scripts that don't even
  1350. // require their user to know what they are doing (see script
  1351. // kiddie)
  1352. //
  1353. CheckThreatLevel(ThreatLevel.High,"osGetSimulatorVersion");
  1354. m_host.AddScriptLPS(1);
  1355. return m_ScriptEngine.World.GetSimulatorVersion();
  1356. }
  1357. private Hashtable osdToHashtable(OSDMap map)
  1358. {
  1359. Hashtable result = new Hashtable();
  1360. foreach (KeyValuePair<string, OSD> item in map) {
  1361. result.Add(item.Key, osdToObject(item.Value));
  1362. }
  1363. return result;
  1364. }
  1365. private ArrayList osdToArray(OSDArray list)
  1366. {
  1367. ArrayList result = new ArrayList();
  1368. foreach ( OSD item in list ) {
  1369. result.Add(osdToObject(item));
  1370. }
  1371. return result;
  1372. }
  1373. private Object osdToObject(OSD decoded)
  1374. {
  1375. if ( decoded is OSDString ) {
  1376. return (string) decoded.AsString();
  1377. } else if ( decoded is OSDInteger ) {
  1378. return (int) decoded.AsInteger();
  1379. } else if ( decoded is OSDReal ) {
  1380. return (float) decoded.AsReal();
  1381. } else if ( decoded is OSDBoolean ) {
  1382. return (bool) decoded.AsBoolean();
  1383. } else if ( decoded is OSDMap ) {
  1384. return osdToHashtable((OSDMap) decoded);
  1385. } else if ( decoded is OSDArray ) {
  1386. return osdToArray((OSDArray) decoded);
  1387. } else {
  1388. return null;
  1389. }
  1390. }
  1391. public Object osParseJSONNew(string JSON)
  1392. {
  1393. CheckThreatLevel(ThreatLevel.None, "osParseJSONNew");
  1394. m_host.AddScriptLPS(1);
  1395. try
  1396. {
  1397. OSD decoded = OSDParser.DeserializeJson(JSON);
  1398. return osdToObject(decoded);
  1399. }
  1400. catch(Exception e)
  1401. {
  1402. OSSLError("osParseJSONNew: Problems decoding JSON string " + JSON + " : " + e.Message) ;
  1403. return null;
  1404. }
  1405. }
  1406. public Hashtable osParseJSON(string JSON)
  1407. {
  1408. CheckThreatLevel(ThreatLevel.None, "osParseJSON");
  1409. m_host.AddScriptLPS(1);
  1410. Object decoded = osParseJSONNew(JSON);
  1411. if ( decoded is Hashtable ) {
  1412. return (Hashtable) decoded;
  1413. } else if ( decoded is ArrayList ) {
  1414. ArrayList decoded_list = (ArrayList) decoded;
  1415. Hashtable fakearray = new Hashtable();
  1416. int i = 0;
  1417. for ( i = 0; i < decoded_list.Count ; i++ ) {
  1418. fakearray.Add(i, decoded_list[i]);
  1419. }
  1420. return fakearray;
  1421. } else {
  1422. OSSLError("osParseJSON: unable to parse JSON string " + JSON);
  1423. return null;
  1424. }
  1425. }
  1426. /// <summary>
  1427. /// Send a message to to object identified by the given UUID
  1428. /// </summary>
  1429. /// <remarks>
  1430. /// A script in the object must implement the dataserver function
  1431. /// the dataserver function is passed the ID of the calling function and a string message
  1432. /// </remarks>
  1433. /// <param name="objectUUID"></param>
  1434. /// <param name="message"></param>
  1435. public void osMessageObject(LSL_Key objectUUID, string message)
  1436. {
  1437. CheckThreatLevel(ThreatLevel.Low, "osMessageObject");
  1438. m_host.AddScriptLPS(1);
  1439. UUID objUUID;
  1440. if (!UUID.TryParse(objectUUID, out objUUID)) // prior to patching, a thrown exception regarding invalid GUID format would be shouted instead.
  1441. {
  1442. OSSLShoutError("osMessageObject() cannot send messages to objects with invalid UUIDs");
  1443. return;
  1444. }
  1445. MessageObject(objUUID, message);
  1446. }
  1447. private void MessageObject(UUID objUUID, string message)
  1448. {
  1449. object[] resobj = new object[] { new LSL_Types.LSLString(m_host.UUID.ToString()), new LSL_Types.LSLString(message) };
  1450. SceneObjectPart sceneOP = World.GetSceneObjectPart(objUUID);
  1451. if (sceneOP == null) // prior to patching, PostObjectEvent() would cause a throw exception to be shouted instead.
  1452. {
  1453. OSSLShoutError("osMessageObject() cannot send message to " + objUUID.ToString() + ", object was not found in scene.");
  1454. return;
  1455. }
  1456. m_ScriptEngine.PostObjectEvent(
  1457. sceneOP.LocalId, new EventParams(
  1458. "dataserver", resobj, new DetectParams[0]));
  1459. }
  1460. /// <summary>
  1461. /// Write a notecard directly to the prim's inventory.
  1462. /// </summary>
  1463. /// <remarks>
  1464. /// This needs ThreatLevel high. It is an excellent griefer tool,
  1465. /// In a loop, it can cause asset bloat and DOS levels of asset
  1466. /// writes.
  1467. /// </remarks>
  1468. /// <param name="notecardName">The name of the notecard to write.</param>
  1469. /// <param name="contents">The contents of the notecard.</param>
  1470. public void osMakeNotecard(string notecardName, LSL_Types.list contents)
  1471. {
  1472. CheckThreatLevel(ThreatLevel.High, "osMakeNotecard");
  1473. m_host.AddScriptLPS(1);
  1474. StringBuilder notecardData = new StringBuilder();
  1475. for (int i = 0; i < contents.Length; i++)
  1476. notecardData.Append((string)(contents.GetLSLStringItem(i) + "\n"));
  1477. SaveNotecard(notecardName, "Script generated notecard", notecardData.ToString(), false);
  1478. }
  1479. /// <summary>
  1480. /// Save a notecard to prim inventory.
  1481. /// </summary>
  1482. /// <param name="name"></param>
  1483. /// <param name="description">Description of notecard</param>
  1484. /// <param name="notecardData"></param>
  1485. /// <param name="forceSameName">
  1486. /// If true, then if an item exists with the same name, it is replaced.
  1487. /// If false, then a new item is created witha slightly different name (e.g. name 1)
  1488. /// </param>
  1489. /// <returns>Prim inventory item created.</returns>
  1490. protected TaskInventoryItem SaveNotecard(string name, string description, string data, bool forceSameName)
  1491. {
  1492. // Create new asset
  1493. AssetBase asset = new AssetBase(UUID.Random(), name, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString());
  1494. asset.Description = description;
  1495. int textLength = data.Length;
  1496. data
  1497. = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length "
  1498. + textLength.ToString() + "\n" + data + "}\n";
  1499. asset.Data = Util.UTF8.GetBytes(data);
  1500. World.AssetService.Store(asset);
  1501. // Create Task Entry
  1502. TaskInventoryItem taskItem = new TaskInventoryItem();
  1503. taskItem.ResetIDs(m_host.UUID);
  1504. taskItem.ParentID = m_host.UUID;
  1505. taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch();
  1506. taskItem.Name = asset.Name;
  1507. taskItem.Description = asset.Description;
  1508. taskItem.Type = (int)AssetType.Notecard;
  1509. taskItem.InvType = (int)InventoryType.Notecard;
  1510. taskItem.OwnerID = m_host.OwnerID;
  1511. taskItem.CreatorID = m_host.OwnerID;
  1512. taskItem.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
  1513. taskItem.CurrentPermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
  1514. taskItem.EveryonePermissions = 0;
  1515. taskItem.NextPermissions = (uint)PermissionMask.All;
  1516. taskItem.GroupID = m_host.GroupID;
  1517. taskItem.GroupPermissions = 0;
  1518. taskItem.Flags = 0;
  1519. taskItem.PermsGranter = UUID.Zero;
  1520. taskItem.PermsMask = 0;
  1521. taskItem.AssetID = asset.FullID;
  1522. if (forceSameName)
  1523. m_host.Inventory.AddInventoryItemExclusive(taskItem, false);
  1524. else
  1525. m_host.Inventory.AddInventoryItem(taskItem, false);
  1526. return taskItem;
  1527. }
  1528. /// <summary>
  1529. /// Load the notecard data found at the given prim inventory item name or asset uuid.
  1530. /// </summary>
  1531. /// <param name="notecardNameOrUuid"></param>
  1532. /// <returns>The text loaded. Null if no notecard was found.</returns>
  1533. protected string LoadNotecard(string notecardNameOrUuid)
  1534. {
  1535. UUID assetID = CacheNotecard(notecardNameOrUuid);
  1536. if (assetID != UUID.Zero)
  1537. {
  1538. StringBuilder notecardData = new StringBuilder();
  1539. for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
  1540. {
  1541. string line = NotecardCache.GetLine(assetID, count) + "\n";
  1542. // m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line);
  1543. notecardData.Append(line);
  1544. }
  1545. return notecardData.ToString();
  1546. }
  1547. return null;
  1548. }
  1549. /// <summary>
  1550. /// Cache a notecard's contents.
  1551. /// </summary>
  1552. /// <param name="notecardNameOrUuid"></param>
  1553. /// <returns>
  1554. /// The asset id of the notecard, which is used for retrieving the cached data.
  1555. /// UUID.Zero if no asset could be found.
  1556. /// </returns>
  1557. protected UUID CacheNotecard(string notecardNameOrUuid)
  1558. {
  1559. UUID assetID = UUID.Zero;
  1560. if (!UUID.TryParse(notecardNameOrUuid, out assetID))
  1561. {
  1562. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  1563. {
  1564. if (item.Type == 7 && item.Name == notecardNameOrUuid)
  1565. {
  1566. assetID = item.AssetID;
  1567. }
  1568. }
  1569. }
  1570. if (assetID == UUID.Zero)
  1571. return UUID.Zero;
  1572. if (!NotecardCache.IsCached(assetID))
  1573. {
  1574. AssetBase a = World.AssetService.Get(assetID.ToString());
  1575. if (a == null)
  1576. return UUID.Zero;
  1577. string data = Encoding.UTF8.GetString(a.Data);
  1578. NotecardCache.Cache(assetID, data);
  1579. };
  1580. return assetID;
  1581. }
  1582. /// <summary>
  1583. /// Directly get an entire notecard at once.
  1584. /// </summary>
  1585. /// <remarks>
  1586. /// Instead of using the LSL Dataserver event to pull notecard data
  1587. /// this will simply read the entire notecard and return its data as a string.
  1588. ///
  1589. /// Warning - due to the synchronous method this function uses to fetch assets, its use
  1590. /// may be dangerous and unreliable while running in grid mode.
  1591. /// </remarks>
  1592. /// <param name="name">Name of the notecard or its asset id</param>
  1593. /// <param name="line">The line number to read. The first line is line 0</param>
  1594. /// <returns>Notecard line</returns>
  1595. public string osGetNotecardLine(string name, int line)
  1596. {
  1597. CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine");
  1598. m_host.AddScriptLPS(1);
  1599. UUID assetID = CacheNotecard(name);
  1600. if (assetID == UUID.Zero)
  1601. {
  1602. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1603. return "ERROR!";
  1604. }
  1605. return NotecardCache.GetLine(assetID, line);
  1606. }
  1607. /// <summary>
  1608. /// Get an entire notecard at once.
  1609. /// </summary>
  1610. /// <remarks>
  1611. /// Instead of using the LSL Dataserver event to pull notecard data line by line,
  1612. /// this will simply read the entire notecard and return its data as a string.
  1613. ///
  1614. /// Warning - due to the synchronous method this function uses to fetch assets, its use
  1615. /// may be dangerous and unreliable while running in grid mode.
  1616. /// </remarks>
  1617. /// <param name="name">Name of the notecard or its asset id</param>
  1618. /// <returns>Notecard text</returns>
  1619. public string osGetNotecard(string name)
  1620. {
  1621. CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard");
  1622. m_host.AddScriptLPS(1);
  1623. string text = LoadNotecard(name);
  1624. if (text == null)
  1625. {
  1626. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1627. return "ERROR!";
  1628. }
  1629. else
  1630. {
  1631. return text;
  1632. }
  1633. }
  1634. /// <summary>
  1635. /// Get the number of lines in the given notecard.
  1636. /// </summary>
  1637. /// <remarks>
  1638. /// Instead of using the LSL Dataserver event to pull notecard data,
  1639. /// this will simply read the number of note card lines and return this data as an integer.
  1640. ///
  1641. /// Warning - due to the synchronous method this function uses to fetch assets, its use
  1642. /// may be dangerous and unreliable while running in grid mode.
  1643. /// </remarks>
  1644. /// <param name="name">Name of the notecard or its asset id</param>
  1645. /// <returns></returns>
  1646. public int osGetNumberOfNotecardLines(string name)
  1647. {
  1648. CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines");
  1649. m_host.AddScriptLPS(1);
  1650. UUID assetID = CacheNotecard(name);
  1651. if (assetID == UUID.Zero)
  1652. {
  1653. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1654. return -1;
  1655. }
  1656. return NotecardCache.GetLines(assetID);
  1657. }
  1658. public string osAvatarName2Key(string firstname, string lastname)
  1659. {
  1660. CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key");
  1661. m_host.AddScriptLPS(1);
  1662. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, firstname, lastname);
  1663. if (null == account)
  1664. {
  1665. return UUID.Zero.ToString();
  1666. }
  1667. else
  1668. {
  1669. return account.PrincipalID.ToString();
  1670. }
  1671. }
  1672. public string osKey2Name(string id)
  1673. {
  1674. CheckThreatLevel(ThreatLevel.Low, "osKey2Name");
  1675. m_host.AddScriptLPS(1);
  1676. UUID key = new UUID();
  1677. if (UUID.TryParse(id, out key))
  1678. {
  1679. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, key);
  1680. if (null == account)
  1681. {
  1682. return "";
  1683. }
  1684. else
  1685. {
  1686. return account.Name;
  1687. }
  1688. }
  1689. else
  1690. {
  1691. return "";
  1692. }
  1693. }
  1694. private enum InfoType
  1695. {
  1696. Nick,
  1697. Name,
  1698. Login,
  1699. Home,
  1700. Custom
  1701. };
  1702. private string GridUserInfo(InfoType type)
  1703. {
  1704. return GridUserInfo(type, "");
  1705. }
  1706. private string GridUserInfo(InfoType type, string key)
  1707. {
  1708. string retval = String.Empty;
  1709. IConfigSource config = m_ScriptEngine.ConfigSource;
  1710. string url = null;
  1711. IConfig gridInfoConfig = config.Configs["GridInfo"];
  1712. if (gridInfoConfig != null)
  1713. url = gridInfoConfig.GetString("GridInfoURI", String.Empty);
  1714. if (String.IsNullOrEmpty(url))
  1715. return "Configuration Error!";
  1716. string verb ="/json_grid_info";
  1717. OSDMap json = new OSDMap();
  1718. OSDMap info = WebUtil.GetFromService(String.Format("{0}{1}",url,verb), 3000);
  1719. if (info["Success"] != true)
  1720. return "Get GridInfo Failed!";
  1721. json = (OSDMap)OSDParser.DeserializeJson(info["_RawResult"].AsString());
  1722. switch (type)
  1723. {
  1724. case InfoType.Nick:
  1725. retval = json["gridnick"];
  1726. break;
  1727. case InfoType.Name:
  1728. retval = json["gridname"];
  1729. break;
  1730. case InfoType.Login:
  1731. retval = json["login"];
  1732. break;
  1733. case InfoType.Home:
  1734. retval = json["home"];
  1735. break;
  1736. case InfoType.Custom:
  1737. retval = json[key];
  1738. break;
  1739. default:
  1740. retval = "error";
  1741. break;
  1742. }
  1743. return retval;
  1744. }
  1745. /// <summary>
  1746. /// Get the nickname of this grid, as set in the [GridInfo] config section.
  1747. /// </summary>
  1748. /// <remarks>
  1749. /// Threat level is Moderate because intentional abuse, for instance
  1750. /// scripts that are written to be malicious only on one grid,
  1751. /// for instance in a HG scenario, are a distinct possibility.
  1752. /// </remarks>
  1753. /// <returns></returns>
  1754. public string osGetGridNick()
  1755. {
  1756. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridNick");
  1757. m_host.AddScriptLPS(1);
  1758. string nick = String.Empty;
  1759. IConfigSource config = m_ScriptEngine.ConfigSource;
  1760. if (config.Configs[GridInfoServiceConfigSectionName] != null)
  1761. nick = config.Configs[GridInfoServiceConfigSectionName].GetString("gridnick", nick);
  1762. if (String.IsNullOrEmpty(nick))
  1763. nick = GridUserInfo(InfoType.Nick);
  1764. return nick;
  1765. }
  1766. public string osGetGridName()
  1767. {
  1768. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridName");
  1769. m_host.AddScriptLPS(1);
  1770. string name = String.Empty;
  1771. IConfigSource config = m_ScriptEngine.ConfigSource;
  1772. if (config.Configs[GridInfoServiceConfigSectionName] != null)
  1773. name = config.Configs[GridInfoServiceConfigSectionName].GetString("gridname", name);
  1774. if (String.IsNullOrEmpty(name))
  1775. name = GridUserInfo(InfoType.Name);
  1776. return name;
  1777. }
  1778. public string osGetGridLoginURI()
  1779. {
  1780. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridLoginURI");
  1781. m_host.AddScriptLPS(1);
  1782. string loginURI = String.Empty;
  1783. IConfigSource config = m_ScriptEngine.ConfigSource;
  1784. if (config.Configs[GridInfoServiceConfigSectionName] != null)
  1785. loginURI = config.Configs[GridInfoServiceConfigSectionName].GetString("login", loginURI);
  1786. if (String.IsNullOrEmpty(loginURI))
  1787. loginURI = GridUserInfo(InfoType.Login);
  1788. return loginURI;
  1789. }
  1790. public string osGetGridHomeURI()
  1791. {
  1792. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridHomeURI");
  1793. m_host.AddScriptLPS(1);
  1794. IConfigSource config = m_ScriptEngine.ConfigSource;
  1795. string HomeURI = Util.GetConfigVarFromSections<string>(config, "HomeURI",
  1796. new string[] { "Startup", "Hypergrid" }, String.Empty);
  1797. if (!string.IsNullOrEmpty(HomeURI))
  1798. return HomeURI;
  1799. // Legacy. Remove soon!
  1800. if (config.Configs["LoginService"] != null)
  1801. HomeURI = config.Configs["LoginService"].GetString("SRV_HomeURI", HomeURI);
  1802. if (String.IsNullOrEmpty(HomeURI))
  1803. HomeURI = GridUserInfo(InfoType.Home);
  1804. return HomeURI;
  1805. }
  1806. public string osGetGridGatekeeperURI()
  1807. {
  1808. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridGatekeeperURI");
  1809. m_host.AddScriptLPS(1);
  1810. IConfigSource config = m_ScriptEngine.ConfigSource;
  1811. string gatekeeperURI = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI",
  1812. new string[] { "Startup", "Hypergrid" }, String.Empty);
  1813. if (!string.IsNullOrEmpty(gatekeeperURI))
  1814. return gatekeeperURI;
  1815. // Legacy. Remove soon!
  1816. if (config.Configs["GridService"] != null)
  1817. gatekeeperURI = config.Configs["GridService"].GetString("Gatekeeper", gatekeeperURI);
  1818. return gatekeeperURI;
  1819. }
  1820. public string osGetGridCustom(string key)
  1821. {
  1822. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridCustom");
  1823. m_host.AddScriptLPS(1);
  1824. string retval = String.Empty;
  1825. IConfigSource config = m_ScriptEngine.ConfigSource;
  1826. if (config.Configs[GridInfoServiceConfigSectionName] != null)
  1827. retval = config.Configs[GridInfoServiceConfigSectionName].GetString(key, retval);
  1828. if (String.IsNullOrEmpty(retval))
  1829. retval = GridUserInfo(InfoType.Custom, key);
  1830. return retval;
  1831. }
  1832. public LSL_String osFormatString(string str, LSL_List strings)
  1833. {
  1834. CheckThreatLevel(ThreatLevel.VeryLow, "osFormatString");
  1835. m_host.AddScriptLPS(1);
  1836. return String.Format(str, strings.Data);
  1837. }
  1838. public LSL_List osMatchString(string src, string pattern, int start)
  1839. {
  1840. CheckThreatLevel(ThreatLevel.VeryLow, "osMatchString");
  1841. m_host.AddScriptLPS(1);
  1842. LSL_List result = new LSL_List();
  1843. // Normalize indices (if negative).
  1844. // After normlaization they may still be
  1845. // negative, but that is now relative to
  1846. // the start, rather than the end, of the
  1847. // sequence.
  1848. if (start < 0)
  1849. {
  1850. start = src.Length + start;
  1851. }
  1852. if (start < 0 || start >= src.Length)
  1853. {
  1854. return result; // empty list
  1855. }
  1856. // Find matches beginning at start position
  1857. Regex matcher = new Regex(pattern);
  1858. Match match = matcher.Match(src, start);
  1859. while (match.Success)
  1860. {
  1861. foreach (System.Text.RegularExpressions.Group g in match.Groups)
  1862. {
  1863. if (g.Success)
  1864. {
  1865. result.Add(new LSL_String(g.Value));
  1866. result.Add(new LSL_Integer(g.Index));
  1867. }
  1868. }
  1869. match = match.NextMatch();
  1870. }
  1871. return result;
  1872. }
  1873. public LSL_String osReplaceString(string src, string pattern, string replace, int count, int start)
  1874. {
  1875. CheckThreatLevel(ThreatLevel.VeryLow, "osReplaceString");
  1876. m_host.AddScriptLPS(1);
  1877. // Normalize indices (if negative).
  1878. // After normlaization they may still be
  1879. // negative, but that is now relative to
  1880. // the start, rather than the end, of the
  1881. // sequence.
  1882. if (start < 0)
  1883. {
  1884. start = src.Length + start;
  1885. }
  1886. if (start < 0 || start >= src.Length)
  1887. {
  1888. return src;
  1889. }
  1890. // Find matches beginning at start position
  1891. Regex matcher = new Regex(pattern);
  1892. return matcher.Replace(src,replace,count,start);
  1893. }
  1894. public string osLoadedCreationDate()
  1895. {
  1896. CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationDate");
  1897. m_host.AddScriptLPS(1);
  1898. return World.RegionInfo.RegionSettings.LoadedCreationDate;
  1899. }
  1900. public string osLoadedCreationTime()
  1901. {
  1902. CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationTime");
  1903. m_host.AddScriptLPS(1);
  1904. return World.RegionInfo.RegionSettings.LoadedCreationTime;
  1905. }
  1906. public string osLoadedCreationID()
  1907. {
  1908. CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationID");
  1909. m_host.AddScriptLPS(1);
  1910. return World.RegionInfo.RegionSettings.LoadedCreationID;
  1911. }
  1912. /// <summary>
  1913. /// Get the primitive parameters of a linked prim.
  1914. /// </summary>
  1915. /// <remarks>
  1916. /// Threat level is 'Low' because certain users could possibly be tricked into
  1917. /// dropping an unverified script into one of their own objects, which could
  1918. /// then gather the physical construction details of the object and transmit it
  1919. /// to an unscrupulous third party, thus permitting unauthorized duplication of
  1920. /// the object's form.
  1921. /// </remarks>
  1922. /// <param name="linknumber"></param>
  1923. /// <param name="rules"></param>
  1924. /// <returns></returns>
  1925. public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules)
  1926. {
  1927. CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams");
  1928. m_host.AddScriptLPS(1);
  1929. InitLSL();
  1930. // One needs to cast m_LSL_Api because we're using functions not
  1931. // on the ILSL_Api interface.
  1932. LSL_Api LSL_Api = (LSL_Api)m_LSL_Api;
  1933. LSL_List retVal = new LSL_List();
  1934. LSL_List remaining = null;
  1935. List<SceneObjectPart> parts = LSL_Api.GetLinkParts(linknumber);
  1936. foreach (SceneObjectPart part in parts)
  1937. {
  1938. remaining = LSL_Api.GetPrimParams(part, rules, ref retVal);
  1939. }
  1940. while (remaining != null && remaining.Length > 2)
  1941. {
  1942. linknumber = remaining.GetLSLIntegerItem(0);
  1943. rules = remaining.GetSublist(1, -1);
  1944. parts = LSL_Api.GetLinkParts(linknumber);
  1945. foreach (SceneObjectPart part in parts)
  1946. remaining = LSL_Api.GetPrimParams(part, rules, ref retVal);
  1947. }
  1948. return retVal;
  1949. }
  1950. public LSL_Integer osIsNpc(LSL_Key npc)
  1951. {
  1952. CheckThreatLevel(ThreatLevel.None, "osIsNpc");
  1953. m_host.AddScriptLPS(1);
  1954. INPCModule module = World.RequestModuleInterface<INPCModule>();
  1955. if (module != null)
  1956. {
  1957. UUID npcId;
  1958. if (UUID.TryParse(npc.m_string, out npcId))
  1959. if (module.IsNPC(npcId, World))
  1960. return ScriptBaseClass.TRUE;
  1961. }
  1962. return ScriptBaseClass.FALSE;
  1963. }
  1964. public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard)
  1965. {
  1966. CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
  1967. m_host.AddScriptLPS(1);
  1968. return NpcCreate(firstname, lastname, position, notecard, false, false);
  1969. }
  1970. public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options)
  1971. {
  1972. CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
  1973. m_host.AddScriptLPS(1);
  1974. return NpcCreate(
  1975. firstname, lastname, position, notecard,
  1976. (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0,
  1977. (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0);
  1978. }
  1979. private LSL_Key NpcCreate(
  1980. string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent)
  1981. {
  1982. INPCModule module = World.RequestModuleInterface<INPCModule>();
  1983. if (module != null)
  1984. {
  1985. AvatarAppearance appearance = null;
  1986. UUID id;
  1987. if (UUID.TryParse(notecard, out id))
  1988. {
  1989. ScenePresence clonePresence = World.GetScenePresence(id);
  1990. if (clonePresence != null)
  1991. appearance = clonePresence.Appearance;
  1992. }
  1993. if (appearance == null)
  1994. {
  1995. string appearanceSerialized = LoadNotecard(notecard);
  1996. if (appearanceSerialized != null)
  1997. {
  1998. OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
  1999. appearance = new AvatarAppearance();
  2000. appearance.Unpack(appearanceOsd);
  2001. }
  2002. else
  2003. {
  2004. OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard));
  2005. }
  2006. }
  2007. UUID ownerID = UUID.Zero;
  2008. if (owned)
  2009. ownerID = m_host.OwnerID;
  2010. UUID x = module.CreateNPC(firstname,
  2011. lastname,
  2012. position,
  2013. ownerID,
  2014. senseAsAgent,
  2015. World,
  2016. appearance);
  2017. return new LSL_Key(x.ToString());
  2018. }
  2019. return new LSL_Key(UUID.Zero.ToString());
  2020. }
  2021. /// <summary>
  2022. /// Save the current appearance of the NPC permanently to the named notecard.
  2023. /// </summary>
  2024. /// <param name="avatar"></param>
  2025. /// <param name="notecard">The name of the notecard to which to save the appearance.</param>
  2026. /// <returns>The asset ID of the notecard saved.</returns>
  2027. public LSL_Key osNpcSaveAppearance(LSL_Key npc, string notecard)
  2028. {
  2029. CheckThreatLevel(ThreatLevel.High, "osNpcSaveAppearance");
  2030. m_host.AddScriptLPS(1);
  2031. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  2032. if (npcModule != null)
  2033. {
  2034. UUID npcId;
  2035. if (!UUID.TryParse(npc.m_string, out npcId))
  2036. return new LSL_Key(UUID.Zero.ToString());
  2037. if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
  2038. return new LSL_Key(UUID.Zero.ToString());
  2039. return SaveAppearanceToNotecard(npcId, notecard);
  2040. }
  2041. return new LSL_Key(UUID.Zero.ToString());
  2042. }
  2043. public void osNpcLoadAppearance(LSL_Key npc, string notecard)
  2044. {
  2045. CheckThreatLevel(ThreatLevel.High, "osNpcLoadAppearance");
  2046. m_host.AddScriptLPS(1);
  2047. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  2048. if (npcModule != null)
  2049. {
  2050. UUID npcId;
  2051. if (!UUID.TryParse(npc.m_string, out npcId))
  2052. return;
  2053. if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
  2054. return;
  2055. string appearanceSerialized = LoadNotecard(notecard);
  2056. if (appearanceSerialized == null)
  2057. OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard));
  2058. OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
  2059. // OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized);
  2060. // Console.WriteLine("appearanceSerialized {0}", appearanceSerialized);
  2061. // Console.WriteLine("a.Type {0}, a.ToString() {1}", a.Type, a);
  2062. AvatarAppearance appearance = new AvatarAppearance();
  2063. appearance.Unpack(appearanceOsd);
  2064. npcModule.SetNPCAppearance(npcId, appearance, m_host.ParentGroup.Scene);
  2065. }
  2066. }
  2067. public LSL_Key osNpcGetOwner(LSL_Key npc)
  2068. {
  2069. CheckThreatLevel(ThreatLevel.None, "osNpcGetOwner");
  2070. m_host.AddScriptLPS(1);
  2071. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  2072. if (npcModule != null)
  2073. {
  2074. UUID npcId;
  2075. if (UUID.TryParse(npc.m_string, out npcId))
  2076. {
  2077. UUID owner = npcModule.GetOwner(npcId);
  2078. if (owner != UUID.Zero)
  2079. return new LSL_Key(owner.ToString());
  2080. else
  2081. return npc;
  2082. }
  2083. }
  2084. return new LSL_Key(UUID.Zero.ToString());
  2085. }
  2086. public LSL_Vector osNpcGetPos(LSL_Key npc)
  2087. {
  2088. CheckThreatLevel(ThreatLevel.High, "osNpcGetPos");
  2089. m_host.AddScriptLPS(1);
  2090. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  2091. if (npcModule != null)
  2092. {
  2093. UUID npcId;
  2094. if (!UUID.TryParse(npc.m_string, out npcId))
  2095. return new LSL_Vector(0, 0, 0);
  2096. if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
  2097. return new LSL_Vector(0, 0, 0);
  2098. ScenePresence sp = World.GetScenePresence(npcId);
  2099. if (sp != null)
  2100. return new LSL_Vector(sp.AbsolutePosition);
  2101. }
  2102. return Vector3.Zero;
  2103. }
  2104. public void osNpcMoveTo(LSL_Key npc, LSL_Vector pos)
  2105. {
  2106. CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo");
  2107. m_host.AddScriptLPS(1);
  2108. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2109. if (module != null)
  2110. {
  2111. UUID npcId;
  2112. if (!UUID.TryParse(npc.m_string, out npcId))
  2113. return;
  2114. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2115. return;
  2116. module.MoveToTarget(npcId, World, pos, false, true, false);
  2117. }
  2118. }
  2119. public void osNpcMoveToTarget(LSL_Key npc, LSL_Vector target, int options)
  2120. {
  2121. CheckThreatLevel(ThreatLevel.High, "osNpcMoveToTarget");
  2122. m_host.AddScriptLPS(1);
  2123. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2124. if (module != null)
  2125. {
  2126. UUID npcId;
  2127. if (!UUID.TryParse(npc.m_string, out npcId))
  2128. return;
  2129. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2130. return;
  2131. module.MoveToTarget(
  2132. new UUID(npc.m_string),
  2133. World,
  2134. target,
  2135. (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0,
  2136. (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0,
  2137. (options & ScriptBaseClass.OS_NPC_RUNNING) != 0);
  2138. }
  2139. }
  2140. public LSL_Rotation osNpcGetRot(LSL_Key npc)
  2141. {
  2142. CheckThreatLevel(ThreatLevel.High, "osNpcGetRot");
  2143. m_host.AddScriptLPS(1);
  2144. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  2145. if (npcModule != null)
  2146. {
  2147. UUID npcId;
  2148. if (!UUID.TryParse(npc.m_string, out npcId))
  2149. return new LSL_Rotation(Quaternion.Identity);
  2150. if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
  2151. return new LSL_Rotation(Quaternion.Identity);
  2152. ScenePresence sp = World.GetScenePresence(npcId);
  2153. if (sp != null)
  2154. return new LSL_Rotation(sp.GetWorldRotation());
  2155. }
  2156. return Quaternion.Identity;
  2157. }
  2158. public void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation)
  2159. {
  2160. CheckThreatLevel(ThreatLevel.High, "osNpcSetRot");
  2161. m_host.AddScriptLPS(1);
  2162. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  2163. if (npcModule != null)
  2164. {
  2165. UUID npcId;
  2166. if (!UUID.TryParse(npc.m_string, out npcId))
  2167. return;
  2168. if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
  2169. return;
  2170. ScenePresence sp = World.GetScenePresence(npcId);
  2171. if (sp != null)
  2172. sp.Rotation = rotation;
  2173. }
  2174. }
  2175. public void osNpcStopMoveToTarget(LSL_Key npc)
  2176. {
  2177. CheckThreatLevel(ThreatLevel.High, "osNpcStopMoveToTarget");
  2178. m_host.AddScriptLPS(1);
  2179. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2180. if (module != null)
  2181. {
  2182. UUID npcId = new UUID(npc.m_string);
  2183. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2184. return;
  2185. module.StopMoveToTarget(npcId, World);
  2186. }
  2187. }
  2188. public void osNpcSay(LSL_Key npc, string message)
  2189. {
  2190. osNpcSay(npc, 0, message);
  2191. }
  2192. public void osNpcSay(LSL_Key npc, int channel, string message)
  2193. {
  2194. CheckThreatLevel(ThreatLevel.High, "osNpcSay");
  2195. m_host.AddScriptLPS(1);
  2196. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2197. if (module != null)
  2198. {
  2199. UUID npcId = new UUID(npc.m_string);
  2200. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2201. return;
  2202. module.Say(npcId, World, message, channel);
  2203. }
  2204. }
  2205. public void osNpcShout(LSL_Key npc, int channel, string message)
  2206. {
  2207. CheckThreatLevel(ThreatLevel.High, "osNpcShout");
  2208. m_host.AddScriptLPS(1);
  2209. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2210. if (module != null)
  2211. {
  2212. UUID npcId = new UUID(npc.m_string);
  2213. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2214. return;
  2215. module.Shout(npcId, World, message, channel);
  2216. }
  2217. }
  2218. public void osNpcSit(LSL_Key npc, LSL_Key target, int options)
  2219. {
  2220. CheckThreatLevel(ThreatLevel.High, "osNpcSit");
  2221. m_host.AddScriptLPS(1);
  2222. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2223. if (module != null)
  2224. {
  2225. UUID npcId = new UUID(npc.m_string);
  2226. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2227. return;
  2228. module.Sit(npcId, new UUID(target.m_string), World);
  2229. }
  2230. }
  2231. public void osNpcStand(LSL_Key npc)
  2232. {
  2233. CheckThreatLevel(ThreatLevel.High, "osNpcStand");
  2234. m_host.AddScriptLPS(1);
  2235. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2236. if (module != null)
  2237. {
  2238. UUID npcId = new UUID(npc.m_string);
  2239. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2240. return;
  2241. module.Stand(npcId, World);
  2242. }
  2243. }
  2244. public void osNpcRemove(LSL_Key npc)
  2245. {
  2246. CheckThreatLevel(ThreatLevel.High, "osNpcRemove");
  2247. m_host.AddScriptLPS(1);
  2248. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2249. if (module != null)
  2250. {
  2251. UUID npcId = new UUID(npc.m_string);
  2252. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2253. return;
  2254. module.DeleteNPC(npcId, World);
  2255. }
  2256. }
  2257. public void osNpcPlayAnimation(LSL_Key npc, string animation)
  2258. {
  2259. CheckThreatLevel(ThreatLevel.High, "osNpcPlayAnimation");
  2260. m_host.AddScriptLPS(1);
  2261. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2262. if (module != null)
  2263. {
  2264. UUID npcID = new UUID(npc.m_string);
  2265. if (module.CheckPermissions(npcID, m_host.OwnerID))
  2266. AvatarPlayAnimation(npcID.ToString(), animation);
  2267. }
  2268. }
  2269. public void osNpcStopAnimation(LSL_Key npc, string animation)
  2270. {
  2271. CheckThreatLevel(ThreatLevel.High, "osNpcStopAnimation");
  2272. m_host.AddScriptLPS(1);
  2273. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2274. if (module != null)
  2275. {
  2276. UUID npcID = new UUID(npc.m_string);
  2277. if (module.CheckPermissions(npcID, m_host.OwnerID))
  2278. AvatarStopAnimation(npcID.ToString(), animation);
  2279. }
  2280. }
  2281. public void osNpcWhisper(LSL_Key npc, int channel, string message)
  2282. {
  2283. CheckThreatLevel(ThreatLevel.High, "osNpcWhisper");
  2284. m_host.AddScriptLPS(1);
  2285. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2286. if (module != null)
  2287. {
  2288. UUID npcId = new UUID(npc.m_string);
  2289. if (!module.CheckPermissions(npcId, m_host.OwnerID))
  2290. return;
  2291. module.Whisper(npcId, World, message, channel);
  2292. }
  2293. }
  2294. public void osNpcTouch(LSL_Key npcLSL_Key, LSL_Key object_key, LSL_Integer link_num)
  2295. {
  2296. CheckThreatLevel(ThreatLevel.High, "osNpcTouch");
  2297. m_host.AddScriptLPS(1);
  2298. INPCModule module = World.RequestModuleInterface<INPCModule>();
  2299. int linkNum = link_num.value;
  2300. if (module != null || (linkNum < 0 && linkNum != ScriptBaseClass.LINK_THIS))
  2301. {
  2302. UUID npcId;
  2303. if (!UUID.TryParse(npcLSL_Key, out npcId) || !module.CheckPermissions(npcId, m_host.OwnerID))
  2304. return;
  2305. SceneObjectPart part = null;
  2306. UUID objectId;
  2307. if (UUID.TryParse(LSL_String.ToString(object_key), out objectId))
  2308. part = World.GetSceneObjectPart(objectId);
  2309. if (part == null)
  2310. return;
  2311. if (linkNum != ScriptBaseClass.LINK_THIS)
  2312. {
  2313. if (linkNum == 0 || linkNum == ScriptBaseClass.LINK_ROOT)
  2314. { // 0 and 1 are treated as root, find the root if the current part isnt it
  2315. if (!part.IsRoot)
  2316. part = part.ParentGroup.RootPart;
  2317. }
  2318. else
  2319. { // Find the prim with the given link number if not found then fail silently
  2320. part = part.ParentGroup.GetLinkNumPart(linkNum);
  2321. if (part == null)
  2322. return;
  2323. }
  2324. }
  2325. module.Touch(npcId, part.UUID);
  2326. }
  2327. }
  2328. /// <summary>
  2329. /// Save the current appearance of the script owner permanently to the named notecard.
  2330. /// </summary>
  2331. /// <param name="notecard">The name of the notecard to which to save the appearance.</param>
  2332. /// <returns>The asset ID of the notecard saved.</returns>
  2333. public LSL_Key osOwnerSaveAppearance(string notecard)
  2334. {
  2335. CheckThreatLevel(ThreatLevel.High, "osOwnerSaveAppearance");
  2336. m_host.AddScriptLPS(1);
  2337. return SaveAppearanceToNotecard(m_host.OwnerID, notecard);
  2338. }
  2339. public LSL_Key osAgentSaveAppearance(LSL_Key avatarId, string notecard)
  2340. {
  2341. CheckThreatLevel(ThreatLevel.VeryHigh, "osAgentSaveAppearance");
  2342. m_host.AddScriptLPS(1);
  2343. return SaveAppearanceToNotecard(avatarId, notecard);
  2344. }
  2345. protected LSL_Key SaveAppearanceToNotecard(ScenePresence sp, string notecard)
  2346. {
  2347. IAvatarFactoryModule appearanceModule = World.RequestModuleInterface<IAvatarFactoryModule>();
  2348. if (appearanceModule != null)
  2349. {
  2350. appearanceModule.SaveBakedTextures(sp.UUID);
  2351. OSDMap appearancePacked = sp.Appearance.Pack();
  2352. TaskInventoryItem item
  2353. = SaveNotecard(notecard, "Avatar Appearance", Util.GetFormattedXml(appearancePacked as OSD), true);
  2354. return new LSL_Key(item.AssetID.ToString());
  2355. }
  2356. else
  2357. {
  2358. return new LSL_Key(UUID.Zero.ToString());
  2359. }
  2360. }
  2361. protected LSL_Key SaveAppearanceToNotecard(UUID avatarId, string notecard)
  2362. {
  2363. ScenePresence sp = World.GetScenePresence(avatarId);
  2364. if (sp == null || sp.IsChildAgent)
  2365. return new LSL_Key(UUID.Zero.ToString());
  2366. return SaveAppearanceToNotecard(sp, notecard);
  2367. }
  2368. protected LSL_Key SaveAppearanceToNotecard(LSL_Key rawAvatarId, string notecard)
  2369. {
  2370. UUID avatarId;
  2371. if (!UUID.TryParse(rawAvatarId, out avatarId))
  2372. return new LSL_Key(UUID.Zero.ToString());
  2373. return SaveAppearanceToNotecard(avatarId, notecard);
  2374. }
  2375. /// <summary>
  2376. /// Get current region's map texture UUID
  2377. /// </summary>
  2378. /// <returns></returns>
  2379. public LSL_Key osGetMapTexture()
  2380. {
  2381. CheckThreatLevel(ThreatLevel.None, "osGetMapTexture");
  2382. m_host.AddScriptLPS(1);
  2383. return m_ScriptEngine.World.RegionInfo.RegionSettings.TerrainImageID.ToString();
  2384. }
  2385. /// <summary>
  2386. /// Get a region's map texture UUID by region UUID or name.
  2387. /// </summary>
  2388. /// <param name="regionName"></param>
  2389. /// <returns></returns>
  2390. public LSL_Key osGetRegionMapTexture(string regionName)
  2391. {
  2392. CheckThreatLevel(ThreatLevel.High, "osGetRegionMapTexture");
  2393. m_host.AddScriptLPS(1);
  2394. Scene scene = m_ScriptEngine.World;
  2395. UUID key = UUID.Zero;
  2396. GridRegion region;
  2397. //If string is a key, use it. Otherwise, try to locate region by name.
  2398. if (UUID.TryParse(regionName, out key))
  2399. region = scene.GridService.GetRegionByUUID(UUID.Zero, key);
  2400. else
  2401. region = scene.GridService.GetRegionByName(UUID.Zero, regionName);
  2402. // If region was found, return the regions map texture key.
  2403. if (region != null)
  2404. key = region.TerrainImage;
  2405. ScriptSleep(1000);
  2406. return key.ToString();
  2407. }
  2408. /// <summary>
  2409. /// Return information regarding various simulator statistics (sim fps, physics fps, time
  2410. /// dilation, total number of prims, total number of active scripts, script lps, various
  2411. /// timing data, packets in/out, etc. Basically much the information that's shown in the
  2412. /// client's Statistics Bar (Ctrl-Shift-1)
  2413. /// </summary>
  2414. /// <returns>List of floats</returns>
  2415. public LSL_List osGetRegionStats()
  2416. {
  2417. CheckThreatLevel(ThreatLevel.Moderate, "osGetRegionStats");
  2418. m_host.AddScriptLPS(1);
  2419. LSL_List ret = new LSL_List();
  2420. float[] stats = World.StatsReporter.LastReportedSimStats;
  2421. for (int i = 0; i < 21; i++)
  2422. {
  2423. ret.Add(new LSL_Float(stats[i]));
  2424. }
  2425. return ret;
  2426. }
  2427. public int osGetSimulatorMemory()
  2428. {
  2429. CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemory");
  2430. m_host.AddScriptLPS(1);
  2431. long pws = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64;
  2432. if (pws > Int32.MaxValue)
  2433. return Int32.MaxValue;
  2434. if (pws < 0)
  2435. return 0;
  2436. return (int)pws;
  2437. }
  2438. public void osSetSpeed(string UUID, LSL_Float SpeedModifier)
  2439. {
  2440. CheckThreatLevel(ThreatLevel.Moderate, "osSetSpeed");
  2441. m_host.AddScriptLPS(1);
  2442. ScenePresence avatar = World.GetScenePresence(new UUID(UUID));
  2443. if (avatar != null)
  2444. avatar.SpeedModifier = (float)SpeedModifier;
  2445. }
  2446. public void osKickAvatar(string FirstName, string SurName, string alert)
  2447. {
  2448. CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
  2449. m_host.AddScriptLPS(1);
  2450. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  2451. {
  2452. if (sp.Firstname == FirstName && sp.Lastname == SurName)
  2453. {
  2454. // kick client...
  2455. if (alert != null)
  2456. sp.ControllingClient.Kick(alert);
  2457. // ...and close on our side
  2458. sp.Scene.IncomingCloseAgent(sp.UUID, false);
  2459. }
  2460. });
  2461. }
  2462. public LSL_Float osGetHealth(string avatar)
  2463. {
  2464. CheckThreatLevel(ThreatLevel.None, "osGetHealth");
  2465. m_host.AddScriptLPS(1);
  2466. LSL_Float health = new LSL_Float(-1);
  2467. ScenePresence presence = World.GetScenePresence(new UUID(avatar));
  2468. if (presence != null) health = presence.Health;
  2469. return health;
  2470. }
  2471. public void osCauseDamage(string avatar, double damage)
  2472. {
  2473. CheckThreatLevel(ThreatLevel.High, "osCauseDamage");
  2474. m_host.AddScriptLPS(1);
  2475. UUID avatarId = new UUID(avatar);
  2476. Vector3 pos = m_host.GetWorldPosition();
  2477. ScenePresence presence = World.GetScenePresence(avatarId);
  2478. if (presence != null)
  2479. {
  2480. LandData land = World.GetLandData(pos);
  2481. if ((land.Flags & (uint)ParcelFlags.AllowDamage) == (uint)ParcelFlags.AllowDamage)
  2482. {
  2483. float health = presence.Health;
  2484. health -= (float)damage;
  2485. presence.setHealthWithUpdate(health);
  2486. if (health <= 0)
  2487. {
  2488. float healthliveagain = 100;
  2489. presence.ControllingClient.SendAgentAlertMessage("You died!", true);
  2490. presence.setHealthWithUpdate(healthliveagain);
  2491. presence.Scene.TeleportClientHome(presence.UUID, presence.ControllingClient);
  2492. }
  2493. }
  2494. }
  2495. }
  2496. public void osCauseHealing(string avatar, double healing)
  2497. {
  2498. CheckThreatLevel(ThreatLevel.High, "osCauseHealing");
  2499. m_host.AddScriptLPS(1);
  2500. UUID avatarId = new UUID(avatar);
  2501. ScenePresence presence = World.GetScenePresence(avatarId);
  2502. if (presence != null && World.ScriptDanger(m_host.LocalId, m_host.GetWorldPosition()))
  2503. {
  2504. float health = presence.Health;
  2505. health += (float)healing;
  2506. if (health >= 100)
  2507. health = 100;
  2508. presence.setHealthWithUpdate(health);
  2509. }
  2510. }
  2511. public LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules)
  2512. {
  2513. CheckThreatLevel(ThreatLevel.High, "osGetPrimitiveParams");
  2514. m_host.AddScriptLPS(1);
  2515. InitLSL();
  2516. return m_LSL_Api.GetPrimitiveParamsEx(prim, rules);
  2517. }
  2518. public void osSetPrimitiveParams(LSL_Key prim, LSL_List rules)
  2519. {
  2520. CheckThreatLevel(ThreatLevel.High, "osSetPrimitiveParams");
  2521. m_host.AddScriptLPS(1);
  2522. InitLSL();
  2523. m_LSL_Api.SetPrimitiveParamsEx(prim, rules, "osSetPrimitiveParams");
  2524. }
  2525. /// <summary>
  2526. /// Set parameters for light projection in host prim
  2527. /// </summary>
  2528. public void osSetProjectionParams(bool projection, LSL_Key texture, double fov, double focus, double amb)
  2529. {
  2530. CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams");
  2531. osSetProjectionParams(UUID.Zero.ToString(), projection, texture, fov, focus, amb);
  2532. }
  2533. /// <summary>
  2534. /// Set parameters for light projection with uuid of target prim
  2535. /// </summary>
  2536. public void osSetProjectionParams(LSL_Key prim, bool projection, LSL_Key texture, double fov, double focus, double amb)
  2537. {
  2538. CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams");
  2539. m_host.AddScriptLPS(1);
  2540. SceneObjectPart obj = null;
  2541. if (prim == UUID.Zero.ToString())
  2542. {
  2543. obj = m_host;
  2544. }
  2545. else
  2546. {
  2547. obj = World.GetSceneObjectPart(new UUID(prim));
  2548. if (obj == null)
  2549. return;
  2550. }
  2551. obj.Shape.ProjectionEntry = projection;
  2552. obj.Shape.ProjectionTextureUUID = new UUID(texture);
  2553. obj.Shape.ProjectionFOV = (float)fov;
  2554. obj.Shape.ProjectionFocus = (float)focus;
  2555. obj.Shape.ProjectionAmbiance = (float)amb;
  2556. obj.ParentGroup.HasGroupChanged = true;
  2557. obj.ScheduleFullUpdate();
  2558. }
  2559. /// <summary>
  2560. /// Like osGetAgents but returns enough info for a radar
  2561. /// </summary>
  2562. /// <returns>Strided list of the UUID, position and name of each avatar in the region</returns>
  2563. public LSL_List osGetAvatarList()
  2564. {
  2565. CheckThreatLevel(ThreatLevel.None, "osGetAvatarList");
  2566. m_host.AddScriptLPS(1);
  2567. LSL_List result = new LSL_List();
  2568. World.ForEachRootScenePresence(delegate (ScenePresence avatar)
  2569. {
  2570. if (avatar != null && avatar.UUID != m_host.OwnerID)
  2571. {
  2572. result.Add(new LSL_String(avatar.UUID.ToString()));
  2573. result.Add(new LSL_Vector(avatar.AbsolutePosition));
  2574. result.Add(new LSL_String(avatar.Name));
  2575. }
  2576. });
  2577. return result;
  2578. }
  2579. /// <summary>
  2580. /// Convert a unix time to a llGetTimestamp() like string
  2581. /// </summary>
  2582. /// <param name="unixTime"></param>
  2583. /// <returns></returns>
  2584. public LSL_String osUnixTimeToTimestamp(long time)
  2585. {
  2586. CheckThreatLevel(ThreatLevel.VeryLow, "osUnixTimeToTimestamp");
  2587. m_host.AddScriptLPS(1);
  2588. long baseTicks = 621355968000000000;
  2589. long tickResolution = 10000000;
  2590. long epochTicks = (time * tickResolution) + baseTicks;
  2591. DateTime date = new DateTime(epochTicks);
  2592. return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
  2593. }
  2594. /// <summary>
  2595. /// Get the description from an inventory item
  2596. /// </summary>
  2597. /// <param name="inventoryName"></param>
  2598. /// <returns>Item description</returns>
  2599. public LSL_String osGetInventoryDesc(string item)
  2600. {
  2601. m_host.AddScriptLPS(1);
  2602. lock (m_host.TaskInventory)
  2603. {
  2604. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  2605. {
  2606. if (inv.Value.Name == item)
  2607. {
  2608. return inv.Value.Description.ToString();
  2609. }
  2610. }
  2611. }
  2612. return String.Empty;
  2613. }
  2614. /// <summary>
  2615. /// Invite user to the group this object is set to
  2616. /// </summary>
  2617. /// <param name="agentId"></param>
  2618. /// <returns></returns>
  2619. public LSL_Integer osInviteToGroup(LSL_Key agentId)
  2620. {
  2621. CheckThreatLevel(ThreatLevel.VeryLow, "osInviteToGroup");
  2622. m_host.AddScriptLPS(1);
  2623. UUID agent = new UUID(agentId);
  2624. // groups module is required
  2625. IGroupsModule groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
  2626. if (groupsModule == null) return ScriptBaseClass.FALSE;
  2627. // object has to be set to a group, but not group owned
  2628. if (m_host.GroupID == UUID.Zero || m_host.GroupID == m_host.OwnerID) return ScriptBaseClass.FALSE;
  2629. // object owner has to be in that group and required permissions
  2630. GroupMembershipData member = groupsModule.GetMembershipData(m_host.GroupID, m_host.OwnerID);
  2631. if (member == null || (member.GroupPowers & (ulong)GroupPowers.Invite) == 0) return ScriptBaseClass.FALSE;
  2632. // check if agent is in that group already
  2633. //member = groupsModule.GetMembershipData(agent, m_host.GroupID, agent);
  2634. //if (member != null) return ScriptBaseClass.FALSE;
  2635. // invited agent has to be present in this scene
  2636. if (World.GetScenePresence(agent) == null) return ScriptBaseClass.FALSE;
  2637. groupsModule.InviteGroup(null, m_host.OwnerID, m_host.GroupID, agent, UUID.Zero);
  2638. return ScriptBaseClass.TRUE;
  2639. }
  2640. /// <summary>
  2641. /// Eject user from the group this object is set to
  2642. /// </summary>
  2643. /// <param name="agentId"></param>
  2644. /// <returns></returns>
  2645. public LSL_Integer osEjectFromGroup(LSL_Key agentId)
  2646. {
  2647. CheckThreatLevel(ThreatLevel.VeryLow, "osEjectFromGroup");
  2648. m_host.AddScriptLPS(1);
  2649. UUID agent = new UUID(agentId);
  2650. // groups module is required
  2651. IGroupsModule groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
  2652. if (groupsModule == null) return ScriptBaseClass.FALSE;
  2653. // object has to be set to a group, but not group owned
  2654. if (m_host.GroupID == UUID.Zero || m_host.GroupID == m_host.OwnerID) return ScriptBaseClass.FALSE;
  2655. // object owner has to be in that group and required permissions
  2656. GroupMembershipData member = groupsModule.GetMembershipData(m_host.GroupID, m_host.OwnerID);
  2657. if (member == null || (member.GroupPowers & (ulong)GroupPowers.Eject) == 0) return ScriptBaseClass.FALSE;
  2658. // agent has to be in that group
  2659. //member = groupsModule.GetMembershipData(agent, m_host.GroupID, agent);
  2660. //if (member == null) return ScriptBaseClass.FALSE;
  2661. // ejectee can be offline
  2662. groupsModule.EjectGroupMember(null, m_host.OwnerID, m_host.GroupID, agent);
  2663. return ScriptBaseClass.TRUE;
  2664. }
  2665. /// <summary>
  2666. /// Sets terrain estate texture
  2667. /// </summary>
  2668. /// <param name="level"></param>
  2669. /// <param name="texture"></param>
  2670. /// <returns></returns>
  2671. public void osSetTerrainTexture(int level, LSL_Key texture)
  2672. {
  2673. CheckThreatLevel(ThreatLevel.High, "osSetTerrainTexture");
  2674. m_host.AddScriptLPS(1);
  2675. //Check to make sure that the script's owner is the estate manager/master
  2676. //World.Permissions.GenericEstatePermission(
  2677. if (World.Permissions.IsGod(m_host.OwnerID))
  2678. {
  2679. if (level < 0 || level > 3)
  2680. return;
  2681. UUID textureID = new UUID();
  2682. if (!UUID.TryParse(texture, out textureID))
  2683. return;
  2684. // estate module is required
  2685. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  2686. if (estate != null)
  2687. estate.setEstateTerrainBaseTexture(level, textureID);
  2688. }
  2689. }
  2690. /// <summary>
  2691. /// Sets terrain heights of estate
  2692. /// </summary>
  2693. /// <param name="corner"></param>
  2694. /// <param name="low"></param>
  2695. /// <param name="high"></param>
  2696. /// <returns></returns>
  2697. public void osSetTerrainTextureHeight(int corner, double low, double high)
  2698. {
  2699. CheckThreatLevel(ThreatLevel.High, "osSetTerrainTextureHeight");
  2700. m_host.AddScriptLPS(1);
  2701. //Check to make sure that the script's owner is the estate manager/master
  2702. //World.Permissions.GenericEstatePermission(
  2703. if (World.Permissions.IsGod(m_host.OwnerID))
  2704. {
  2705. if (corner < 0 || corner > 3)
  2706. return;
  2707. // estate module is required
  2708. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  2709. if (estate != null)
  2710. estate.setEstateTerrainTextureHeights(corner, (float)low, (float)high);
  2711. }
  2712. }
  2713. #region Attachment commands
  2714. public void osForceAttachToAvatar(int attachmentPoint)
  2715. {
  2716. CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar");
  2717. m_host.AddScriptLPS(1);
  2718. InitLSL();
  2719. ((LSL_Api)m_LSL_Api).AttachToAvatar(attachmentPoint);
  2720. }
  2721. public void osForceAttachToAvatarFromInventory(string itemName, int attachmentPoint)
  2722. {
  2723. CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatarFromInventory");
  2724. m_host.AddScriptLPS(1);
  2725. ForceAttachToAvatarFromInventory(m_host.OwnerID, itemName, attachmentPoint);
  2726. }
  2727. public void osForceAttachToOtherAvatarFromInventory(string rawAvatarId, string itemName, int attachmentPoint)
  2728. {
  2729. CheckThreatLevel(ThreatLevel.Severe, "osForceAttachToOtherAvatarFromInventory");
  2730. m_host.AddScriptLPS(1);
  2731. UUID avatarId;
  2732. if (!UUID.TryParse(rawAvatarId, out avatarId))
  2733. return;
  2734. ForceAttachToAvatarFromInventory(avatarId, itemName, attachmentPoint);
  2735. }
  2736. public void ForceAttachToAvatarFromInventory(UUID avatarId, string itemName, int attachmentPoint)
  2737. {
  2738. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  2739. if (attachmentsModule == null)
  2740. return;
  2741. InitLSL();
  2742. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  2743. if (item == null)
  2744. {
  2745. ((LSL_Api)m_LSL_Api).llSay(0, string.Format("Could not find object '{0}'", itemName));
  2746. throw new Exception(String.Format("The inventory item '{0}' could not be found", itemName));
  2747. }
  2748. if (item.InvType != (int)InventoryType.Object)
  2749. {
  2750. // FIXME: Temporary null check for regression tests since they dont' have the infrastructure to set
  2751. // up the api reference.
  2752. if (m_LSL_Api != null)
  2753. ((LSL_Api)m_LSL_Api).llSay(0, string.Format("Unable to attach, item '{0}' is not an object.", itemName));
  2754. throw new Exception(String.Format("The inventory item '{0}' is not an object", itemName));
  2755. }
  2756. ScenePresence sp = World.GetScenePresence(avatarId);
  2757. if (sp == null)
  2758. return;
  2759. InventoryItemBase newItem = World.MoveTaskInventoryItem(sp.UUID, UUID.Zero, m_host, item.ItemID);
  2760. if (newItem == null)
  2761. {
  2762. m_log.ErrorFormat(
  2763. "[OSSL API]: Could not create user inventory item {0} for {1}, attach point {2} in {3}",
  2764. itemName, m_host.Name, attachmentPoint, World.Name);
  2765. return;
  2766. }
  2767. attachmentsModule.RezSingleAttachmentFromInventory(sp, newItem.ID, (uint)attachmentPoint);
  2768. }
  2769. public void osForceDetachFromAvatar()
  2770. {
  2771. CheckThreatLevel(ThreatLevel.High, "osForceDetachFromAvatar");
  2772. m_host.AddScriptLPS(1);
  2773. InitLSL();
  2774. ((LSL_Api)m_LSL_Api).DetachFromAvatar();
  2775. }
  2776. public LSL_List osGetNumberOfAttachments(LSL_Key avatar, LSL_List attachmentPoints)
  2777. {
  2778. CheckThreatLevel(ThreatLevel.Moderate, "osGetNumberOfAttachments");
  2779. m_host.AddScriptLPS(1);
  2780. UUID targetUUID;
  2781. ScenePresence target;
  2782. LSL_List resp = new LSL_List();
  2783. if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out targetUUID) && World.TryGetScenePresence(targetUUID, out target))
  2784. {
  2785. foreach (object point in attachmentPoints.Data)
  2786. {
  2787. LSL_Integer ipoint = new LSL_Integer(
  2788. (point is LSL_Integer || point is int || point is uint) ?
  2789. (int)point :
  2790. 0
  2791. );
  2792. resp.Add(ipoint);
  2793. if (ipoint == 0)
  2794. {
  2795. // indicates zero attachments
  2796. resp.Add(new LSL_Integer(0));
  2797. }
  2798. else
  2799. {
  2800. // gets the number of attachments on the attachment point
  2801. resp.Add(new LSL_Integer(target.GetAttachments((uint)ipoint).Count));
  2802. }
  2803. }
  2804. }
  2805. return resp;
  2806. }
  2807. public void osMessageAttachments(LSL_Key avatar, string message, LSL_List attachmentPoints, int options)
  2808. {
  2809. CheckThreatLevel(ThreatLevel.Moderate, "osMessageAttachments");
  2810. m_host.AddScriptLPS(1);
  2811. UUID targetUUID;
  2812. ScenePresence target;
  2813. if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out targetUUID) && World.TryGetScenePresence(targetUUID, out target))
  2814. {
  2815. List<int> aps = new List<int>();
  2816. foreach (object point in attachmentPoints.Data)
  2817. {
  2818. int ipoint;
  2819. if (int.TryParse(point.ToString(), out ipoint))
  2820. {
  2821. aps.Add(ipoint);
  2822. }
  2823. }
  2824. List<SceneObjectGroup> attachments = new List<SceneObjectGroup>();
  2825. bool msgAll = aps.Contains(ScriptBaseClass.OS_ATTACH_MSG_ALL);
  2826. bool invertPoints = (options & ScriptBaseClass.OS_ATTACH_MSG_INVERT_POINTS) != 0;
  2827. if (msgAll && invertPoints)
  2828. {
  2829. return;
  2830. }
  2831. else if (msgAll || invertPoints)
  2832. {
  2833. attachments = target.GetAttachments();
  2834. }
  2835. else
  2836. {
  2837. foreach (int point in aps)
  2838. {
  2839. if (point > 0)
  2840. {
  2841. attachments.AddRange(target.GetAttachments((uint)point));
  2842. }
  2843. }
  2844. }
  2845. // if we have no attachments at this point, exit now
  2846. if (attachments.Count == 0)
  2847. {
  2848. return;
  2849. }
  2850. List<SceneObjectGroup> ignoreThese = new List<SceneObjectGroup>();
  2851. if (invertPoints)
  2852. {
  2853. foreach (SceneObjectGroup attachment in attachments)
  2854. {
  2855. if (aps.Contains((int)attachment.AttachmentPoint))
  2856. {
  2857. ignoreThese.Add(attachment);
  2858. }
  2859. }
  2860. }
  2861. foreach (SceneObjectGroup attachment in ignoreThese)
  2862. {
  2863. attachments.Remove(attachment);
  2864. }
  2865. ignoreThese.Clear();
  2866. // if inverting removed all attachments to check, exit now
  2867. if (attachments.Count < 1)
  2868. {
  2869. return;
  2870. }
  2871. if ((options & ScriptBaseClass.OS_ATTACH_MSG_OBJECT_CREATOR) != 0)
  2872. {
  2873. foreach (SceneObjectGroup attachment in attachments)
  2874. {
  2875. if (attachment.RootPart.CreatorID != m_host.CreatorID)
  2876. {
  2877. ignoreThese.Add(attachment);
  2878. }
  2879. }
  2880. foreach (SceneObjectGroup attachment in ignoreThese)
  2881. {
  2882. attachments.Remove(attachment);
  2883. }
  2884. ignoreThese.Clear();
  2885. // if filtering by same object creator removed all
  2886. // attachments to check, exit now
  2887. if (attachments.Count == 0)
  2888. {
  2889. return;
  2890. }
  2891. }
  2892. if ((options & ScriptBaseClass.OS_ATTACH_MSG_SCRIPT_CREATOR) != 0)
  2893. {
  2894. foreach (SceneObjectGroup attachment in attachments)
  2895. {
  2896. if (attachment.RootPart.CreatorID != m_item.CreatorID)
  2897. {
  2898. ignoreThese.Add(attachment);
  2899. }
  2900. }
  2901. foreach (SceneObjectGroup attachment in ignoreThese)
  2902. {
  2903. attachments.Remove(attachment);
  2904. }
  2905. ignoreThese.Clear();
  2906. // if filtering by object creator must match originating
  2907. // script creator removed all attachments to check,
  2908. // exit now
  2909. if (attachments.Count == 0)
  2910. {
  2911. return;
  2912. }
  2913. }
  2914. foreach (SceneObjectGroup attachment in attachments)
  2915. {
  2916. MessageObject(attachment.RootPart.UUID, message);
  2917. }
  2918. }
  2919. }
  2920. #endregion
  2921. /// <summary>
  2922. /// Checks if thing is a UUID.
  2923. /// </summary>
  2924. /// <param name="thing"></param>
  2925. /// <returns>1 if thing is a valid UUID, 0 otherwise</returns>
  2926. public LSL_Integer osIsUUID(string thing)
  2927. {
  2928. CheckThreatLevel(ThreatLevel.None, "osIsUUID");
  2929. m_host.AddScriptLPS(1);
  2930. UUID test;
  2931. return UUID.TryParse(thing, out test) ? 1 : 0;
  2932. }
  2933. /// <summary>
  2934. /// Wraps to Math.Min()
  2935. /// </summary>
  2936. /// <param name="a"></param>
  2937. /// <param name="b"></param>
  2938. /// <returns></returns>
  2939. public LSL_Float osMin(double a, double b)
  2940. {
  2941. CheckThreatLevel(ThreatLevel.None, "osMin");
  2942. m_host.AddScriptLPS(1);
  2943. return Math.Min(a, b);
  2944. }
  2945. /// <summary>
  2946. /// Wraps to Math.max()
  2947. /// </summary>
  2948. /// <param name="a"></param>
  2949. /// <param name="b"></param>
  2950. /// <returns></returns>
  2951. public LSL_Float osMax(double a, double b)
  2952. {
  2953. CheckThreatLevel(ThreatLevel.None, "osMax");
  2954. m_host.AddScriptLPS(1);
  2955. return Math.Max(a, b);
  2956. }
  2957. public LSL_Key osGetRezzingObject()
  2958. {
  2959. CheckThreatLevel(ThreatLevel.None, "osGetRezzingObject");
  2960. m_host.AddScriptLPS(1);
  2961. return new LSL_Key(m_host.ParentGroup.FromPartID.ToString());
  2962. }
  2963. /// <summary>
  2964. /// Sets the response type for an HTTP request/response
  2965. /// </summary>
  2966. /// <returns></returns>
  2967. public void osSetContentType(LSL_Key id, string type)
  2968. {
  2969. CheckThreatLevel(ThreatLevel.High, "osSetContentType");
  2970. if (m_UrlModule != null)
  2971. m_UrlModule.HttpContentType(new UUID(id),type);
  2972. }
  2973. /// Shout an error if the object owner did not grant the script the specified permissions.
  2974. /// </summary>
  2975. /// <param name="perms"></param>
  2976. /// <returns>boolean indicating whether an error was shouted.</returns>
  2977. protected bool ShoutErrorOnLackingOwnerPerms(int perms, string errorPrefix)
  2978. {
  2979. m_host.AddScriptLPS(1);
  2980. bool fail = false;
  2981. if (m_item.PermsGranter != m_host.OwnerID)
  2982. {
  2983. fail = true;
  2984. OSSLShoutError(string.Format("{0}. Permissions not granted to owner.", errorPrefix));
  2985. }
  2986. else if ((m_item.PermsMask & perms) == 0)
  2987. {
  2988. fail = true;
  2989. OSSLShoutError(string.Format("{0}. Permissions not granted.", errorPrefix));
  2990. }
  2991. return fail;
  2992. }
  2993. protected void DropAttachment(bool checkPerms)
  2994. {
  2995. if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment"))
  2996. {
  2997. return;
  2998. }
  2999. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  3000. ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID);
  3001. if (attachmentsModule != null && sp != null)
  3002. {
  3003. attachmentsModule.DetachSingleAttachmentToGround(sp, m_host.ParentGroup.LocalId);
  3004. }
  3005. }
  3006. protected void DropAttachmentAt(bool checkPerms, LSL_Vector pos, LSL_Rotation rot)
  3007. {
  3008. if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment"))
  3009. {
  3010. return;
  3011. }
  3012. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  3013. ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID);
  3014. if (attachmentsModule != null && sp != null)
  3015. {
  3016. attachmentsModule.DetachSingleAttachmentToGround(sp, m_host.ParentGroup.LocalId, pos, rot);
  3017. }
  3018. }
  3019. public void osDropAttachment()
  3020. {
  3021. CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachment");
  3022. m_host.AddScriptLPS(1);
  3023. DropAttachment(true);
  3024. }
  3025. public void osForceDropAttachment()
  3026. {
  3027. CheckThreatLevel(ThreatLevel.High, "osForceDropAttachment");
  3028. m_host.AddScriptLPS(1);
  3029. DropAttachment(false);
  3030. }
  3031. public void osDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot)
  3032. {
  3033. CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachmentAt");
  3034. m_host.AddScriptLPS(1);
  3035. DropAttachmentAt(true, pos, rot);
  3036. }
  3037. public void osForceDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot)
  3038. {
  3039. CheckThreatLevel(ThreatLevel.High, "osForceDropAttachmentAt");
  3040. m_host.AddScriptLPS(1);
  3041. DropAttachmentAt(false, pos, rot);
  3042. }
  3043. public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
  3044. {
  3045. CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
  3046. m_host.AddScriptLPS(1);
  3047. UUID keyID;
  3048. UUID.TryParse(ID, out keyID);
  3049. // if we want the name to be used as a regular expression, ensure it is valid first.
  3050. if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_NAME) == ScriptBaseClass.OS_LISTEN_REGEX_NAME)
  3051. {
  3052. try
  3053. {
  3054. Regex.IsMatch("", name);
  3055. }
  3056. catch (Exception)
  3057. {
  3058. OSSLShoutError("Name regex is invalid.");
  3059. return -1;
  3060. }
  3061. }
  3062. // if we want the msg to be used as a regular expression, ensure it is valid first.
  3063. if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) == ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE)
  3064. {
  3065. try
  3066. {
  3067. Regex.IsMatch("", msg);
  3068. }
  3069. catch (Exception)
  3070. {
  3071. OSSLShoutError("Message regex is invalid.");
  3072. return -1;
  3073. }
  3074. }
  3075. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  3076. return (wComm == null) ? -1 : wComm.Listen(
  3077. m_host.LocalId,
  3078. m_item.ItemID,
  3079. m_host.UUID,
  3080. channelID,
  3081. name,
  3082. keyID,
  3083. msg,
  3084. regexBitfield
  3085. );
  3086. }
  3087. public LSL_Integer osRegexIsMatch(string input, string pattern)
  3088. {
  3089. CheckThreatLevel(ThreatLevel.Low, "osRegexIsMatch");
  3090. m_host.AddScriptLPS(1);
  3091. try
  3092. {
  3093. return Regex.IsMatch(input, pattern) ? 1 : 0;
  3094. }
  3095. catch (Exception)
  3096. {
  3097. OSSLShoutError("Possible invalid regular expression detected.");
  3098. return 0;
  3099. }
  3100. }
  3101. }
  3102. }