OSSL_Api.cs 138 KB

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