OSSL_Api.cs 137 KB

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