OSSL_Api.cs 142 KB

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