OSSL_Api.cs 135 KB

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