12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749 |
- /*
- * Copyright (c) Contributors, http://opensimulator.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the OpenSimulator Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Reflection;
- using System.Runtime.Remoting.Lifetime;
- using System.Text;
- using System.Net;
- using System.Threading;
- using System.Xml;
- using log4net;
- using OpenMetaverse;
- using OpenMetaverse.StructuredData;
- using Nini.Config;
- using OpenSim;
- using OpenSim.Framework;
- using OpenSim.Framework.Console;
- using OpenSim.Region.Framework.Interfaces;
- using OpenSim.Region.Framework.Scenes;
- using OpenSim.Region.ScriptEngine.Shared;
- using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
- using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
- using OpenSim.Region.ScriptEngine.Interfaces;
- using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
- using TPFlags = OpenSim.Framework.Constants.TeleportFlags;
- using OpenSim.Services.Interfaces;
- using GridRegion = OpenSim.Services.Interfaces.GridRegion;
- using System.Text.RegularExpressions;
- using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
- using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
- using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
- using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
- using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
- using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
- using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
- using PermissionMask = OpenSim.Framework.PermissionMask;
- namespace OpenSim.Region.ScriptEngine.Shared.Api
- {
- //////////////////////////////////////////////////////////////
- //
- // Level description
- //
- // None - Function is no threat at all. It doesn't constitute
- // an threat to either users or the system and has no
- // known side effects
- //
- // Nuisance - Abuse of this command can cause a nuisance to the
- // region operator, such as log message spew
- //
- // VeryLow - Extreme levels ob abuse of this function can cause
- // impaired functioning of the region, or very gullible
- // users can be tricked into experiencing harmless effects
- //
- // Low - Intentional abuse can cause crashes or malfunction
- // under certain circumstances, which can easily be rectified,
- // or certain users can be tricked into certain situations
- // in an avoidable manner.
- //
- // Moderate - Intentional abuse can cause denial of service and crashes
- // with potential of data or state loss, or trusting users
- // can be tricked into embarrassing or uncomfortable
- // situationsa.
- //
- // High - Casual abuse can cause impaired functionality or temporary
- // denial of service conditions. Intentional abuse can easily
- // cause crashes with potential data loss, or can be used to
- // trick experienced and cautious users into unwanted situations,
- // or changes global data permanently and without undo ability
- // Malicious scripting can allow theft of content
- //
- // VeryHigh - Even normal use may, depending on the number of instances,
- // or frequency of use, result in severe service impairment
- // or crash with loss of data, or can be used to cause
- // unwanted or harmful effects on users without giving the
- // user a means to avoid it.
- //
- // Severe - Even casual use is a danger to region stability, or function
- // allows console or OS command execution, or function allows
- // taking money without consent, or allows deletion or
- // modification of user data, or allows the compromise of
- // sensitive data by design.
- class FunctionPerms
- {
- public List<UUID> AllowedCreators;
- public List<UUID> AllowedOwners;
- public List<string> AllowedOwnerClasses;
- public FunctionPerms()
- {
- AllowedCreators = new List<UUID>();
- AllowedOwners = new List<UUID>();
- AllowedOwnerClasses = new List<string>();
- }
- }
- [Serializable]
- public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi
- {
- private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- public const string GridInfoServiceConfigSectionName = "GridInfoService";
- internal IScriptEngine m_ScriptEngine;
- internal ILSL_Api m_LSL_Api = null; // get a reference to the LSL API so we can call methods housed there
- internal SceneObjectPart m_host;
- internal TaskInventoryItem m_item;
- internal bool m_OSFunctionsEnabled = false;
- internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow;
- internal float m_ScriptDelayFactor = 1.0f;
- internal float m_ScriptDistanceFactor = 1.0f;
- internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
- protected IUrlModule m_UrlModule = null;
- public void Initialize(
- IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, WaitHandle coopSleepHandle)
- {
- m_ScriptEngine = scriptEngine;
- m_host = host;
- m_item = item;
- m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
- if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
- m_OSFunctionsEnabled = true;
- m_ScriptDelayFactor =
- m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
- m_ScriptDistanceFactor =
- m_ScriptEngine.Config.GetFloat("ScriptDistanceLimitFactor", 1.0f);
- string risk = m_ScriptEngine.Config.GetString("OSFunctionThreatLevel", "VeryLow");
- switch (risk)
- {
- case "NoAccess":
- m_MaxThreatLevel = ThreatLevel.NoAccess;
- break;
- case "None":
- m_MaxThreatLevel = ThreatLevel.None;
- break;
- case "VeryLow":
- m_MaxThreatLevel = ThreatLevel.VeryLow;
- break;
- case "Low":
- m_MaxThreatLevel = ThreatLevel.Low;
- break;
- case "Moderate":
- m_MaxThreatLevel = ThreatLevel.Moderate;
- break;
- case "High":
- m_MaxThreatLevel = ThreatLevel.High;
- break;
- case "VeryHigh":
- m_MaxThreatLevel = ThreatLevel.VeryHigh;
- break;
- case "Severe":
- m_MaxThreatLevel = ThreatLevel.Severe;
- break;
- default:
- break;
- }
- }
- public override Object InitializeLifetimeService()
- {
- ILease lease = (ILease)base.InitializeLifetimeService();
- if (lease.CurrentState == LeaseState.Initial)
- {
- lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
- // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
- // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
- }
- return lease;
- }
- public Scene World
- {
- get { return m_ScriptEngine.World; }
- }
- internal void OSSLError(string msg)
- {
- throw new ScriptException("OSSL Runtime Error: " + msg);
- }
- /// <summary>
- /// Initialize the LSL interface.
- /// </summary>
- /// <remarks>
- /// FIXME: This is an abomination. We should be able to set this up earlier but currently we have no
- /// guarantee the interface is present on Initialize(). There needs to be another post initialize call from
- /// ScriptInstance.
- /// </remarks>
- private void InitLSL()
- {
- if (m_LSL_Api != null)
- return;
- m_LSL_Api = (ILSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "LSL");
- }
- //
- //Dumps an error message on the debug console.
- //
- internal void OSSLShoutError(string message)
- {
- if (message.Length > 1023)
- message = message.Substring(0, 1023);
- World.SimChat(Utils.StringToBytes(message),
- ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
- IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
- wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
- }
- // Returns of the function is allowed. Throws a script exception if not allowed.
- public void CheckThreatLevel(ThreatLevel level, string function)
- {
- if (!m_OSFunctionsEnabled)
- OSSLError(String.Format("{0} permission denied. All OS functions are disabled.", function)); // throws
- string reasonWhyNot = CheckThreatLevelTest(level, function);
- if (!String.IsNullOrEmpty(reasonWhyNot))
- {
- OSSLError(reasonWhyNot);
- }
- }
- // Check to see if function is allowed. Returns an empty string if function permitted
- // or a string explaining why this function can't be used.
- private string CheckThreatLevelTest(ThreatLevel level, string function)
- {
- if (!m_FunctionPerms.ContainsKey(function))
- {
- FunctionPerms perms = new FunctionPerms();
- m_FunctionPerms[function] = perms;
- string ownerPerm = m_ScriptEngine.Config.GetString("Allow_" + function, "");
- string creatorPerm = m_ScriptEngine.Config.GetString("Creators_" + function, "");
- if (ownerPerm == "" && creatorPerm == "")
- {
- // Default behavior
- perms.AllowedOwners = null;
- perms.AllowedCreators = null;
- perms.AllowedOwnerClasses = null;
- }
- else
- {
- bool allowed;
- if (bool.TryParse(ownerPerm, out allowed))
- {
- // Boolean given
- if (allowed)
- {
- // Allow globally
- perms.AllowedOwners.Add(UUID.Zero);
- }
- }
- else
- {
- string[] ids = ownerPerm.Split(new char[] {','});
- foreach (string id in ids)
- {
- string current = id.Trim();
- if (current.ToUpper() == "PARCEL_GROUP_MEMBER" || current.ToUpper() == "PARCEL_OWNER" || current.ToUpper() == "ESTATE_MANAGER" || current.ToUpper() == "ESTATE_OWNER")
- {
- if (!perms.AllowedOwnerClasses.Contains(current))
- perms.AllowedOwnerClasses.Add(current.ToUpper());
- }
- else
- {
- UUID uuid;
- if (UUID.TryParse(current, out uuid))
- {
- if (uuid != UUID.Zero)
- perms.AllowedOwners.Add(uuid);
- }
- }
- }
- ids = creatorPerm.Split(new char[] {','});
- foreach (string id in ids)
- {
- string current = id.Trim();
- UUID uuid;
- if (UUID.TryParse(current, out uuid))
- {
- if (uuid != UUID.Zero)
- perms.AllowedCreators.Add(uuid);
- }
- }
- }
- }
- }
- // If the list is null, then the value was true / undefined
- // Threat level governs permissions in this case
- //
- // If the list is non-null, then it is a list of UUIDs allowed
- // to use that particular function. False causes an empty
- // list and therefore means "no one"
- //
- // To allow use by anyone, the list contains UUID.Zero
- //
- if (m_FunctionPerms[function].AllowedOwners == null)
- {
- // Allow / disallow by threat level
- if (level > m_MaxThreatLevel)
- return
- String.Format(
- "{0} permission denied. Allowed threat level is {1} but function threat level is {2}.",
- function, m_MaxThreatLevel, level);
- }
- else
- {
- if (!m_FunctionPerms[function].AllowedOwners.Contains(UUID.Zero))
- {
- // Not anyone. Do detailed checks
- if (m_FunctionPerms[function].AllowedOwners.Contains(m_host.OwnerID))
- {
- // prim owner is in the list of allowed owners
- return String.Empty;
- }
- UUID ownerID = m_item.OwnerID;
- //OSSL only may be used if object is in the same group as the parcel
- if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("PARCEL_GROUP_MEMBER"))
- {
- ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
- if (land.LandData.GroupID == m_item.GroupID && land.LandData.GroupID != UUID.Zero)
- {
- return String.Empty;
- }
- }
- //Only Parcelowners may use the function
- if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("PARCEL_OWNER"))
- {
- ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
- if (land.LandData.OwnerID == ownerID)
- {
- return String.Empty;
- }
- }
- //Only Estate Managers may use the function
- if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("ESTATE_MANAGER"))
- {
- //Only Estate Managers may use the function
- if (World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(ownerID) && World.RegionInfo.EstateSettings.EstateOwner != ownerID)
- {
- return String.Empty;
- }
- }
- //Only regionowners may use the function
- if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("ESTATE_OWNER"))
- {
- if (World.RegionInfo.EstateSettings.EstateOwner == ownerID)
- {
- return String.Empty;
- }
- }
- if (!m_FunctionPerms[function].AllowedCreators.Contains(m_item.CreatorID))
- return(
- 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.",
- function));
- if (m_item.CreatorID != ownerID)
- {
- if ((m_item.CurrentPermissions & (uint)PermissionMask.Modify) != 0)
- return String.Format("{0} permission denied. Script permissions error.", function);
- }
- }
- }
- return String.Empty;
- }
- internal void OSSLDeprecated(string function, string replacement)
- {
- OSSLShoutError(string.Format("Use of function {0} is deprecated. Use {1} instead.", function, replacement));
- }
- protected void ScriptSleep(int delay)
- {
- delay = (int)((float)delay * m_ScriptDelayFactor);
- if (delay == 0)
- return;
- System.Threading.Thread.Sleep(delay);
- }
- public LSL_Integer osSetTerrainHeight(int x, int y, double val)
- {
- CheckThreatLevel(ThreatLevel.High, "osSetTerrainHeight");
- return SetTerrainHeight(x, y, val);
- }
- public LSL_Integer osTerrainSetHeight(int x, int y, double val)
- {
- CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight");
- OSSLDeprecated("osTerrainSetHeight", "osSetTerrainHeight");
- return SetTerrainHeight(x, y, val);
- }
- private LSL_Integer SetTerrainHeight(int x, int y, double val)
- {
- m_host.AddScriptLPS(1);
- if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0)
- OSSLError("osSetTerrainHeight: Coordinate out of bounds");
- if (World.Permissions.CanTerraformLand(m_host.OwnerID, new Vector3(x, y, 0)))
- {
- World.Heightmap[x, y] = val;
- return 1;
- }
- else
- {
- return 0;
- }
- }
- public LSL_Float osGetTerrainHeight(int x, int y)
- {
- CheckThreatLevel(ThreatLevel.None, "osGetTerrainHeight");
- return GetTerrainHeight(x, y);
- }
- public LSL_Float osTerrainGetHeight(int x, int y)
- {
- CheckThreatLevel(ThreatLevel.None, "osTerrainGetHeight");
- OSSLDeprecated("osTerrainGetHeight", "osGetTerrainHeight");
- return GetTerrainHeight(x, y);
- }
- private LSL_Float GetTerrainHeight(int x, int y)
- {
- m_host.AddScriptLPS(1);
- if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0)
- OSSLError("osGetTerrainHeight: Coordinate out of bounds");
- return World.Heightmap[x, y];
- }
- public void osTerrainFlush()
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osTerrainFlush");
- m_host.AddScriptLPS(1);
- ITerrainModule terrainModule = World.RequestModuleInterface<ITerrainModule>();
- if (terrainModule != null) terrainModule.TaintTerrain();
- }
- public int osRegionRestart(double seconds)
- {
- // This is High here because region restart is not reliable
- // it may result in the region staying down or becoming
- // unstable. This should be changed to Low or VeryLow once
- // The underlying functionality is fixed, since the security
- // as such is sound
- //
- CheckThreatLevel(ThreatLevel.High, "osRegionRestart");
- IRestartModule restartModule = World.RequestModuleInterface<IRestartModule>();
- m_host.AddScriptLPS(1);
- if (World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false) && (restartModule != null))
- {
- if (seconds < 15)
- {
- restartModule.AbortRestart("Restart aborted");
- return 1;
- }
- List<int> times = new List<int>();
- while (seconds > 0)
- {
- times.Add((int)seconds);
- if (seconds > 300)
- seconds -= 120;
- else if (seconds > 30)
- seconds -= 30;
- else
- seconds -= 15;
- }
- restartModule.ScheduleRestart(UUID.Zero, "Region will restart in {0}", times.ToArray(), true);
- return 1;
- }
- else
- {
- return 0;
- }
- }
- public void osRegionNotice(string msg)
- {
- // This implementation provides absolutely no security
- // It's high griefing potential makes this classification
- // necessary
- //
- CheckThreatLevel(ThreatLevel.VeryHigh, "osRegionNotice");
- m_host.AddScriptLPS(1);
- IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
- if (dm != null)
- dm.SendGeneralAlert(msg);
- }
- public void osSetRot(UUID target, Quaternion rotation)
- {
- // This function has no security. It can be used to destroy
- // arbitrary builds the user would normally have no rights to
- //
- CheckThreatLevel(ThreatLevel.VeryHigh, "osSetRot");
- m_host.AddScriptLPS(1);
- if (World.Entities.ContainsKey(target))
- {
- EntityBase entity;
- if (World.Entities.TryGetValue(target, out entity))
- {
- if (entity is SceneObjectGroup)
- ((SceneObjectGroup)entity).UpdateGroupRotationR(rotation);
- else if (entity is ScenePresence)
- ((ScenePresence)entity).Rotation = rotation;
- }
- }
- else
- {
- OSSLError("osSetRot: Invalid target");
- }
- }
- public string osSetDynamicTextureURL(string dynamicID, string contentType, string url, string extraParams,
- int timer)
- {
- // This may be upgraded depending on the griefing or DOS
- // potential, or guarded with a delay
- //
- CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURL");
- m_host.AddScriptLPS(1);
- if (dynamicID == String.Empty)
- {
- IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
- UUID createdTexture =
- textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
- extraParams, timer);
- return createdTexture.ToString();
- }
- else
- {
- //TODO update existing dynamic textures
- }
- return UUID.Zero.ToString();
- }
- public string osSetDynamicTextureURLBlend(string dynamicID, string contentType, string url, string extraParams,
- int timer, int alpha)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURLBlend");
- m_host.AddScriptLPS(1);
- if (dynamicID == String.Empty)
- {
- IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
- UUID createdTexture =
- textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
- extraParams, timer, true, (byte) alpha);
- return createdTexture.ToString();
- }
- else
- {
- //TODO update existing dynamic textures
- }
- return UUID.Zero.ToString();
- }
- public string osSetDynamicTextureURLBlendFace(string dynamicID, string contentType, string url, string extraParams,
- bool blend, int disp, int timer, int alpha, int face)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURLBlendFace");
- m_host.AddScriptLPS(1);
- if (dynamicID == String.Empty)
- {
- IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
- UUID createdTexture =
- textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
- extraParams, timer, blend, disp, (byte) alpha, face);
- return createdTexture.ToString();
- }
- else
- {
- //TODO update existing dynamic textures
- }
- return UUID.Zero.ToString();
- }
- public string osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams,
- int timer)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureData");
- m_host.AddScriptLPS(1);
- if (dynamicID == String.Empty)
- {
- IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
- if (textureManager != null)
- {
- if (extraParams == String.Empty)
- {
- extraParams = "256";
- }
- UUID createdTexture =
- textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
- extraParams, timer);
- return createdTexture.ToString();
- }
- }
- else
- {
- //TODO update existing dynamic textures
- }
- return UUID.Zero.ToString();
- }
- public string osSetDynamicTextureDataBlend(string dynamicID, string contentType, string data, string extraParams,
- int timer, int alpha)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureDataBlend");
- m_host.AddScriptLPS(1);
- if (dynamicID == String.Empty)
- {
- IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
- if (textureManager != null)
- {
- if (extraParams == String.Empty)
- {
- extraParams = "256";
- }
- UUID createdTexture =
- textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
- extraParams, timer, true, (byte) alpha);
- return createdTexture.ToString();
- }
- }
- else
- {
- //TODO update existing dynamic textures
- }
- return UUID.Zero.ToString();
- }
- public string osSetDynamicTextureDataBlendFace(string dynamicID, string contentType, string data, string extraParams,
- bool blend, int disp, int timer, int alpha, int face)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureDataBlendFace");
- m_host.AddScriptLPS(1);
- if (dynamicID == String.Empty)
- {
- IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
- if (textureManager != null)
- {
- if (extraParams == String.Empty)
- {
- extraParams = "256";
- }
- UUID createdTexture =
- textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
- extraParams, timer, blend, disp, (byte) alpha, face);
- return createdTexture.ToString();
- }
- }
- else
- {
- //TODO update existing dynamic textures
- }
- return UUID.Zero.ToString();
- }
- public bool osConsoleCommand(string command)
- {
- CheckThreatLevel(ThreatLevel.Severe, "osConsoleCommand");
- m_host.AddScriptLPS(1);
- // For safety, we add another permission check here, and don't rely only on the standard OSSL permissions
- if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
- {
- MainConsole.Instance.RunCommand(command);
- return true;
- }
- return false;
- }
- public void osSetPrimFloatOnWater(int floatYN)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osSetPrimFloatOnWater");
- m_host.AddScriptLPS(1);
- m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN);
- }
- // Teleport functions
- public void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
- {
- // High because there is no security check. High griefer potential
- //
- CheckThreatLevel(ThreatLevel.Severe, "osTeleportAgent");
- TeleportAgent(agent, regionName, position, lookat, false);
- }
- private void TeleportAgent(string agent, string regionName,
- LSL_Types.Vector3 position, LSL_Types.Vector3 lookat, bool relaxRestrictions)
- {
- m_host.AddScriptLPS(1);
- UUID agentId = new UUID();
- if (UUID.TryParse(agent, out agentId))
- {
- ScenePresence presence = World.GetScenePresence(agentId);
- if (presence != null)
- {
- // For osTeleportAgent, agent must be over owners land to avoid abuse
- // For osTeleportOwner, this restriction isn't necessary
- // commented out because its redundant and uneeded please remove eventually.
- // if (relaxRestrictions ||
- // m_host.OwnerID
- // == World.LandChannel.GetLandObject(
- // presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
- // {
- // We will launch the teleport on a new thread so that when the script threads are terminated
- // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting.
- Util.FireAndForget(o => World.RequestTeleportLocation(
- presence.ControllingClient, regionName, position,
- lookat, (uint)TPFlags.ViaLocation));
- ScriptSleep(5000);
- // }
- }
- }
- }
- public void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
- {
- // High because there is no security check. High griefer potential
- //
- CheckThreatLevel(ThreatLevel.Severe, "osTeleportAgent");
- TeleportAgent(agent, regionX, regionY, position, lookat, false);
- }
- private void TeleportAgent(string agent, int regionX, int regionY,
- LSL_Types.Vector3 position, LSL_Types.Vector3 lookat, bool relaxRestrictions)
- {
- // ulong regionHandle = Util.UIntsToLong(((uint)regionX * (uint)Constants.RegionSize), ((uint)regionY * (uint)Constants.RegionSize));
- ulong regionHandle = Util.RegionLocToHandle((uint)regionX, (uint)regionY);
- m_host.AddScriptLPS(1);
- UUID agentId = new UUID();
- if (UUID.TryParse(agent, out agentId))
- {
- ScenePresence presence = World.GetScenePresence(agentId);
- if (presence != null)
- {
- // For osTeleportAgent, agent must be over owners land to avoid abuse
- // For osTeleportOwner, this restriction isn't necessary
- // commented out because its redundant and uneeded please remove eventually.
- // if (relaxRestrictions ||
- // m_host.OwnerID
- // == World.LandChannel.GetLandObject(
- // presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
- // {
- // We will launch the teleport on a new thread so that when the script threads are terminated
- // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting.
- Util.FireAndForget(o => World.RequestTeleportLocation(
- presence.ControllingClient, regionHandle,
- position, lookat, (uint)TPFlags.ViaLocation));
- ScriptSleep(5000);
- // }
- }
- }
- }
- public void osTeleportAgent(string agent, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
- {
- osTeleportAgent(agent, World.RegionInfo.RegionName, position, lookat);
- }
- public void osTeleportOwner(string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
- {
- // Threat level None because this is what can already be done with the World Map in the viewer
- CheckThreatLevel(ThreatLevel.None, "osTeleportOwner");
- TeleportAgent(m_host.OwnerID.ToString(), regionName, position, lookat, true);
- }
- public void osTeleportOwner(LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
- {
- osTeleportOwner(World.RegionInfo.RegionName, position, lookat);
- }
- public void osTeleportOwner(int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
- {
- CheckThreatLevel(ThreatLevel.None, "osTeleportOwner");
- TeleportAgent(m_host.OwnerID.ToString(), regionX, regionY, position, lookat, true);
- }
- // Functions that get information from the agent itself.
- //
- // osGetAgentIP - this is used to determine the IP address of
- //the client. This is needed to help configure other in world
- //resources based on the IP address of the clients connected.
- //I think High is a good risk level for this, as it is an
- //information leak.
- public string osGetAgentIP(string agent)
- {
- CheckThreatLevel(ThreatLevel.High, "osGetAgentIP");
- UUID avatarID = (UUID)agent;
- m_host.AddScriptLPS(1);
- if (World.Entities.ContainsKey((UUID)agent) && World.Entities[avatarID] is ScenePresence)
- {
- ScenePresence target = (ScenePresence)World.Entities[avatarID];
- return target.ControllingClient.RemoteEndPoint.Address.ToString();
- }
-
- // fall through case, just return nothing
- return "";
- }
- // Get a list of all the avatars/agents in the region
- public LSL_List osGetAgents()
- {
- // threat level is None as we could get this information with an
- // in-world script as well, just not as efficient
- CheckThreatLevel(ThreatLevel.None, "osGetAgents");
- m_host.AddScriptLPS(1);
- LSL_List result = new LSL_List();
- World.ForEachRootScenePresence(delegate(ScenePresence sp)
- {
- result.Add(new LSL_String(sp.Name));
- });
- return result;
- }
- // Adam's super super custom animation functions
- public void osAvatarPlayAnimation(string avatar, string animation)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarPlayAnimation");
- AvatarPlayAnimation(avatar, animation);
- }
- private void AvatarPlayAnimation(string avatar, string animation)
- {
- UUID avatarID = (UUID)avatar;
- m_host.AddScriptLPS(1);
- if (World.Entities.ContainsKey((UUID)avatar) && World.Entities[avatarID] is ScenePresence)
- {
- ScenePresence target = (ScenePresence)World.Entities[avatarID];
- if (target != null)
- {
- UUID animID=UUID.Zero;
- lock (m_host.TaskInventory)
- {
- foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
- {
- if (inv.Value.Name == animation)
- {
- if (inv.Value.Type == (int)AssetType.Animation)
- animID = inv.Value.AssetID;
- continue;
- }
- }
- }
- if (animID == UUID.Zero)
- target.Animator.AddAnimation(animation, m_host.UUID);
- else
- target.Animator.AddAnimation(animID, m_host.UUID);
- }
- }
- }
- public void osAvatarStopAnimation(string avatar, string animation)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarStopAnimation");
- AvatarStopAnimation(avatar, animation);
- }
- private void AvatarStopAnimation(string avatar, string animation)
- {
- UUID avatarID = (UUID)avatar;
- m_host.AddScriptLPS(1);
- // FIXME: What we really want to do here is factor out the similar code in llStopAnimation() to a common
- // method (though see that doesn't do the is animation check, which is probably a bug) and have both
- // these functions call that common code. However, this does mean navigating the brain-dead requirement
- // of calling InitLSL()
- if (World.Entities.ContainsKey(avatarID) && World.Entities[avatarID] is ScenePresence)
- {
- ScenePresence target = (ScenePresence)World.Entities[avatarID];
- if (target != null)
- {
- UUID animID;
- if (!UUID.TryParse(animation, out animID))
- {
- TaskInventoryItem item = m_host.Inventory.GetInventoryItem(animation);
- if (item != null && item.Type == (int)AssetType.Animation)
- animID = item.AssetID;
- else
- animID = UUID.Zero;
- }
-
- if (animID == UUID.Zero)
- target.Animator.RemoveAnimation(animation);
- else
- target.Animator.RemoveAnimation(animID, true);
- }
- }
- }
- //Texture draw functions
- public string osMovePen(string drawList, int x, int y)
- {
- CheckThreatLevel(ThreatLevel.None, "osMovePen");
- m_host.AddScriptLPS(1);
- drawList += "MoveTo " + x + "," + y + ";";
- return drawList;
- }
- public string osDrawLine(string drawList, int startX, int startY, int endX, int endY)
- {
- CheckThreatLevel(ThreatLevel.None, "osDrawLine");
- m_host.AddScriptLPS(1);
- drawList += "MoveTo "+ startX+","+ startY +"; LineTo "+endX +","+endY +"; ";
- return drawList;
- }
- public string osDrawLine(string drawList, int endX, int endY)
- {
- CheckThreatLevel(ThreatLevel.None, "osDrawLine");
- m_host.AddScriptLPS(1);
- drawList += "LineTo " + endX + "," + endY + "; ";
- return drawList;
- }
- public string osDrawText(string drawList, string text)
- {
- CheckThreatLevel(ThreatLevel.None, "osDrawText");
- m_host.AddScriptLPS(1);
- drawList += "Text " + text + "; ";
- return drawList;
- }
- public string osDrawEllipse(string drawList, int width, int height)
- {
- CheckThreatLevel(ThreatLevel.None, "osDrawEllipse");
- m_host.AddScriptLPS(1);
- drawList += "Ellipse " + width + "," + height + "; ";
- return drawList;
- }
- public string osDrawRectangle(string drawList, int width, int height)
- {
- CheckThreatLevel(ThreatLevel.None, "osDrawRectangle");
- m_host.AddScriptLPS(1);
- drawList += "Rectangle " + width + "," + height + "; ";
- return drawList;
- }
- public string osDrawFilledRectangle(string drawList, int width, int height)
- {
- CheckThreatLevel(ThreatLevel.None, "osDrawFilledRectangle");
- m_host.AddScriptLPS(1);
- drawList += "FillRectangle " + width + "," + height + "; ";
- return drawList;
- }
- public string osDrawFilledPolygon(string drawList, LSL_List x, LSL_List y)
- {
- CheckThreatLevel(ThreatLevel.None, "osDrawFilledPolygon");
- m_host.AddScriptLPS(1);
- if (x.Length != y.Length || x.Length < 3)
- {
- return "";
- }
- drawList += "FillPolygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
- for (int i = 1; i < x.Length; i++)
- {
- drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
- }
- drawList += "; ";
- return drawList;
- }
- public string osDrawPolygon(string drawList, LSL_List x, LSL_List y)
- {
- CheckThreatLevel(ThreatLevel.None, "osDrawPolygon");
- m_host.AddScriptLPS(1);
- if (x.Length != y.Length || x.Length < 3)
- {
- return "";
- }
- drawList += "Polygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
- for (int i = 1; i < x.Length; i++)
- {
- drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
- }
- drawList += "; ";
- return drawList;
- }
- public string osSetFontSize(string drawList, int fontSize)
- {
- CheckThreatLevel(ThreatLevel.None, "osSetFontSize");
- m_host.AddScriptLPS(1);
- drawList += "FontSize "+ fontSize +"; ";
- return drawList;
- }
- public string osSetFontName(string drawList, string fontName)
- {
- CheckThreatLevel(ThreatLevel.None, "osSetFontName");
- m_host.AddScriptLPS(1);
- drawList += "FontName "+ fontName +"; ";
- return drawList;
- }
- public string osSetPenSize(string drawList, int penSize)
- {
- CheckThreatLevel(ThreatLevel.None, "osSetPenSize");
- m_host.AddScriptLPS(1);
- drawList += "PenSize " + penSize + "; ";
- return drawList;
- }
- public string osSetPenColor(string drawList, string color)
- {
- CheckThreatLevel(ThreatLevel.None, "osSetPenColor");
-
- m_host.AddScriptLPS(1);
- drawList += "PenColor " + color + "; ";
- return drawList;
- }
- // Deprecated
- public string osSetPenColour(string drawList, string colour)
- {
- CheckThreatLevel(ThreatLevel.None, "osSetPenColour");
- OSSLDeprecated("osSetPenColour", "osSetPenColor");
- m_host.AddScriptLPS(1);
- drawList += "PenColour " + colour + "; ";
- return drawList;
- }
- public string osSetPenCap(string drawList, string direction, string type)
- {
- CheckThreatLevel(ThreatLevel.None, "osSetPenCap");
- m_host.AddScriptLPS(1);
- drawList += "PenCap " + direction + "," + type + "; ";
- return drawList;
- }
- public string osDrawImage(string drawList, int width, int height, string imageUrl)
- {
- CheckThreatLevel(ThreatLevel.None, "osDrawImage");
- m_host.AddScriptLPS(1);
- drawList +="Image " +width + "," + height+ ","+ imageUrl +"; " ;
- return drawList;
- }
- public LSL_Vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osGetDrawStringSize");
- m_host.AddScriptLPS(1);
- LSL_Vector vec = new LSL_Vector(0,0,0);
- IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
- if (textureManager != null)
- {
- double xSize, ySize;
- textureManager.GetDrawStringSize(contentType, text, fontName, fontSize,
- out xSize, out ySize);
- vec.x = xSize;
- vec.y = ySize;
- }
- return vec;
- }
- public void osSetStateEvents(int events)
- {
- // This function is a hack. There is no reason for it's existence
- // anymore, since state events now work properly.
- // It was probably added as a crutch or debugging aid, and
- // should be removed
- //
- CheckThreatLevel(ThreatLevel.High, "osSetStateEvents");
- m_host.AddScriptLPS(1);
- m_host.SetScriptEvents(m_item.ItemID, events);
- }
- public void osSetRegionWaterHeight(double height)
- {
- CheckThreatLevel(ThreatLevel.High, "osSetRegionWaterHeight");
- m_host.AddScriptLPS(1);
- World.EventManager.TriggerRequestChangeWaterHeight((float)height);
- }
- /// <summary>
- /// Changes the Region Sun Settings, then Triggers a Sun Update
- /// </summary>
- /// <param name="useEstateSun">True to use Estate Sun instead of Region Sun</param>
- /// <param name="sunFixed">True to keep the sun stationary</param>
- /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
- public void osSetRegionSunSettings(bool useEstateSun, bool sunFixed, double sunHour)
- {
- CheckThreatLevel(ThreatLevel.High, "osSetRegionSunSettings");
- m_host.AddScriptLPS(1);
- while (sunHour > 24.0)
- sunHour -= 24.0;
- while (sunHour < 0)
- sunHour += 24.0;
- World.RegionInfo.RegionSettings.UseEstateSun = useEstateSun;
- World.RegionInfo.RegionSettings.SunPosition = sunHour + 6; // LL Region Sun Hour is 6 to 30
- World.RegionInfo.RegionSettings.FixedSun = sunFixed;
- World.RegionInfo.RegionSettings.Save();
- World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle);
- }
- /// <summary>
- /// Changes the Estate Sun Settings, then Triggers a Sun Update
- /// </summary>
- /// <param name="sunFixed">True to keep the sun stationary, false to use global time</param>
- /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
- public void osSetEstateSunSettings(bool sunFixed, double sunHour)
- {
- CheckThreatLevel(ThreatLevel.High, "osSetEstateSunSettings");
- m_host.AddScriptLPS(1);
- while (sunHour > 24.0)
- sunHour -= 24.0;
- while (sunHour < 0)
- sunHour += 24.0;
- World.RegionInfo.EstateSettings.UseGlobalTime = !sunFixed;
- World.RegionInfo.EstateSettings.SunPosition = sunHour;
- World.RegionInfo.EstateSettings.FixedSun = sunFixed;
- World.RegionInfo.EstateSettings.Save();
- World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle);
- }
- /// <summary>
- /// Return the current Sun Hour 0...24, with 0 being roughly sun-rise
- /// </summary>
- /// <returns></returns>
- public double osGetCurrentSunHour()
- {
- CheckThreatLevel(ThreatLevel.None, "osGetCurrentSunHour");
- m_host.AddScriptLPS(1);
- // Must adjust for the fact that Region Sun Settings are still LL offset
- double sunHour = World.RegionInfo.RegionSettings.SunPosition - 6;
- // See if the sun module has registered itself, if so it's authoritative
- ISunModule module = World.RequestModuleInterface<ISunModule>();
- if (module != null)
- {
- sunHour = module.GetCurrentSunHour();
- }
- return sunHour;
- }
- public double osSunGetParam(string param)
- {
- CheckThreatLevel(ThreatLevel.None, "osSunGetParam");
- OSSLDeprecated("osSunGetParam", "osGetSunParam");
- return GetSunParam(param);
- }
- public double osGetSunParam(string param)
- {
- CheckThreatLevel(ThreatLevel.None, "osGetSunParam");
- return GetSunParam(param);
- }
- private double GetSunParam(string param)
- {
- m_host.AddScriptLPS(1);
- double value = 0.0;
- ISunModule module = World.RequestModuleInterface<ISunModule>();
- if (module != null)
- {
- value = module.GetSunParameter(param);
- }
- return value;
- }
- public void osSunSetParam(string param, double value)
- {
- CheckThreatLevel(ThreatLevel.None, "osSunSetParam");
- OSSLDeprecated("osSunSetParam", "osSetSunParam");
- SetSunParam(param, value);
- }
- public void osSetSunParam(string param, double value)
- {
- CheckThreatLevel(ThreatLevel.None, "osSetSunParam");
- SetSunParam(param, value);
- }
- private void SetSunParam(string param, double value)
- {
- m_host.AddScriptLPS(1);
- ISunModule module = World.RequestModuleInterface<ISunModule>();
- if (module != null)
- {
- module.SetSunParameter(param, value);
- }
- }
- public string osWindActiveModelPluginName()
- {
- CheckThreatLevel(ThreatLevel.None, "osWindActiveModelPluginName");
- m_host.AddScriptLPS(1);
- IWindModule module = World.RequestModuleInterface<IWindModule>();
- if (module != null)
- {
- return module.WindActiveModelPluginName;
- }
- return String.Empty;
- }
- public void osSetWindParam(string plugin, string param, LSL_Float value)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osSetWindParam");
- m_host.AddScriptLPS(1);
- IWindModule module = World.RequestModuleInterface<IWindModule>();
- if (module != null)
- {
- try
- {
- module.WindParamSet(plugin, param, (float)value);
- }
- catch (Exception) { }
- }
- }
- public LSL_Float osGetWindParam(string plugin, string param)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osGetWindParam");
- m_host.AddScriptLPS(1);
- IWindModule module = World.RequestModuleInterface<IWindModule>();
- if (module != null)
- {
- return module.WindParamGet(plugin, param);
- }
- return 0.0f;
- }
- // Routines for creating and managing parcels programmatically
- public void osParcelJoin(LSL_Vector pos1, LSL_Vector pos2)
- {
- CheckThreatLevel(ThreatLevel.High, "osParcelJoin");
- m_host.AddScriptLPS(1);
- int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
- int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
- int endx = (int)(pos1.x > pos2.x ? pos1.x : pos2.x);
- int endy = (int)(pos1.y > pos2.y ? pos1.y : pos2.y);
- World.LandChannel.Join(startx,starty,endx,endy,m_host.OwnerID);
- }
- public void osParcelSubdivide(LSL_Vector pos1, LSL_Vector pos2)
- {
- CheckThreatLevel(ThreatLevel.High, "osParcelSubdivide");
- m_host.AddScriptLPS(1);
- int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
- int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
- int endx = (int)(pos1.x > pos2.x ? pos1.x : pos2.x);
- int endy = (int)(pos1.y > pos2.y ? pos1.y : pos2.y);
- World.LandChannel.Subdivide(startx,starty,endx,endy,m_host.OwnerID);
- }
- public void osParcelSetDetails(LSL_Vector pos, LSL_List rules)
- {
- const string functionName = "osParcelSetDetails";
- CheckThreatLevel(ThreatLevel.High, functionName);
- OSSLDeprecated(functionName, "osSetParcelDetails");
- SetParcelDetails(pos, rules, functionName);
- }
- public void osSetParcelDetails(LSL_Vector pos, LSL_List rules)
- {
- const string functionName = "osSetParcelDetails";
- CheckThreatLevel(ThreatLevel.High, functionName);
- SetParcelDetails(pos, rules, functionName);
- }
- private void SetParcelDetails(LSL_Vector pos, LSL_List rules, string functionName)
- {
- m_host.AddScriptLPS(1);
- // Get a reference to the land data and make sure the owner of the script
- // can modify it
- ILandObject startLandObject = World.LandChannel.GetLandObject((int)pos.x, (int)pos.y);
- if (startLandObject == null)
- {
- OSSLShoutError("There is no land at that location");
- return;
- }
- if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, startLandObject, GroupPowers.LandOptions))
- {
- OSSLShoutError("You do not have permission to modify the parcel");
- return;
- }
- // Create a new land data object we can modify
- LandData newLand = startLandObject.LandData.Copy();
- UUID uuid;
- // Process the rules, not sure what the impact would be of changing owner or group
- for (int idx = 0; idx < rules.Length;)
- {
- int code = rules.GetLSLIntegerItem(idx++);
- string arg = rules.GetLSLStringItem(idx++);
- switch (code)
- {
- case ScriptBaseClass.PARCEL_DETAILS_NAME:
- newLand.Name = arg;
- break;
- case ScriptBaseClass.PARCEL_DETAILS_DESC:
- newLand.Description = arg;
- break;
- case ScriptBaseClass.PARCEL_DETAILS_OWNER:
- CheckThreatLevel(ThreatLevel.VeryHigh, functionName);
- if (UUID.TryParse(arg, out uuid))
- newLand.OwnerID = uuid;
- break;
- case ScriptBaseClass.PARCEL_DETAILS_GROUP:
- CheckThreatLevel(ThreatLevel.VeryHigh, functionName);
- if (UUID.TryParse(arg, out uuid))
- newLand.GroupID = uuid;
- break;
- case ScriptBaseClass.PARCEL_DETAILS_CLAIMDATE:
- CheckThreatLevel(ThreatLevel.VeryHigh, functionName);
- newLand.ClaimDate = Convert.ToInt32(arg);
- if (newLand.ClaimDate == 0)
- newLand.ClaimDate = Util.UnixTimeSinceEpoch();
- break;
- }
- }
- World.LandChannel.UpdateLandObject(newLand.LocalID,newLand);
- }
- public double osList2Double(LSL_Types.list src, int index)
- {
- // There is really no double type in OSSL. C# and other
- // have one, but the current implementation of LSL_Types.list
- // is not allowed to contain any.
- // This really should be removed.
- //
- CheckThreatLevel(ThreatLevel.None, "osList2Double");
- m_host.AddScriptLPS(1);
- if (index < 0)
- {
- index = src.Length + index;
- }
- if (index >= src.Length)
- {
- return 0.0;
- }
- return Convert.ToDouble(src.Data[index]);
- }
- public void osSetParcelMediaURL(string url)
- {
- // What actually is the difference to the LL function?
- //
- CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL");
- m_host.AddScriptLPS(1);
- ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
- if (land.LandData.OwnerID != m_host.OwnerID)
- return;
- land.SetMediaUrl(url);
- }
- public void osSetParcelSIPAddress(string SIPAddress)
- {
- // What actually is the difference to the LL function?
- //
- CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelSIPAddress");
- m_host.AddScriptLPS(1);
- ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
- if (land.LandData.OwnerID != m_host.OwnerID)
- {
- OSSLError("osSetParcelSIPAddress: Sorry, you need to own the land to use this function");
- return;
- }
- // get the voice module
- IVoiceModule voiceModule = World.RequestModuleInterface<IVoiceModule>();
- if (voiceModule != null)
- voiceModule.setLandSIPAddress(SIPAddress,land.LandData.GlobalID);
- else
- OSSLError("osSetParcelSIPAddress: No voice module enabled for this land");
- }
- public string osGetScriptEngineName()
- {
- // This gets a "high" because knowing the engine may be used
- // to exploit engine-specific bugs or induce usage patterns
- // that trigger engine-specific failures.
- // Besides, public grid users aren't supposed to know.
- //
- CheckThreatLevel(ThreatLevel.High, "osGetScriptEngineName");
- m_host.AddScriptLPS(1);
- int scriptEngineNameIndex = 0;
- if (!String.IsNullOrEmpty(m_ScriptEngine.ScriptEngineName))
- {
- // parse off the "ScriptEngine."
- scriptEngineNameIndex = m_ScriptEngine.ScriptEngineName.IndexOf(".", scriptEngineNameIndex);
- scriptEngineNameIndex++; // get past delimiter
- int scriptEngineNameLength = m_ScriptEngine.ScriptEngineName.Length - scriptEngineNameIndex;
- // create char array then a string that is only the script engine name
- Char[] scriptEngineNameCharArray = m_ScriptEngine.ScriptEngineName.ToCharArray(scriptEngineNameIndex, scriptEngineNameLength);
- String scriptEngineName = new String(scriptEngineNameCharArray);
- return scriptEngineName;
- }
- else
- {
- return String.Empty;
- }
- }
- public string osGetPhysicsEngineType()
- {
- // High because it can be used to target attacks to known weaknesses
- // This would allow a new class of griefer scripts that don't even
- // require their user to know what they are doing (see script
- // kiddie)
- // Because it would be nice if scripts didn't blow up if the information
- // about the physics engine, this function returns an empty string if
- // the user does not have permission to see it. This as opposed to
- // throwing an exception.
- m_host.AddScriptLPS(1);
- string ret = String.Empty;
- if (String.IsNullOrEmpty(CheckThreatLevelTest(ThreatLevel.High, "osGetPhysicsEngineType")))
- {
- if (m_ScriptEngine.World.PhysicsScene != null)
- {
- ret = m_ScriptEngine.World.PhysicsScene.EngineType;
- // An old physics engine might have an uninitialized engine type
- if (ret == null)
- ret = "unknown";
- }
- }
- return ret;
- }
- public string osGetSimulatorVersion()
- {
- // High because it can be used to target attacks to known weaknesses
- // This would allow a new class of griefer scripts that don't even
- // require their user to know what they are doing (see script
- // kiddie)
- //
- CheckThreatLevel(ThreatLevel.High,"osGetSimulatorVersion");
- m_host.AddScriptLPS(1);
- return m_ScriptEngine.World.GetSimulatorVersion();
- }
- private Hashtable osdToHashtable(OSDMap map)
- {
- Hashtable result = new Hashtable();
- foreach (KeyValuePair<string, OSD> item in map) {
- result.Add(item.Key, osdToObject(item.Value));
- }
- return result;
- }
-
- private ArrayList osdToArray(OSDArray list)
- {
- ArrayList result = new ArrayList();
- foreach ( OSD item in list ) {
- result.Add(osdToObject(item));
- }
- return result;
- }
- private Object osdToObject(OSD decoded)
- {
- if ( decoded is OSDString ) {
- return (string) decoded.AsString();
- } else if ( decoded is OSDInteger ) {
- return (int) decoded.AsInteger();
- } else if ( decoded is OSDReal ) {
- return (float) decoded.AsReal();
- } else if ( decoded is OSDBoolean ) {
- return (bool) decoded.AsBoolean();
- } else if ( decoded is OSDMap ) {
- return osdToHashtable((OSDMap) decoded);
- } else if ( decoded is OSDArray ) {
- return osdToArray((OSDArray) decoded);
- } else {
- return null;
- }
- }
- public Object osParseJSONNew(string JSON)
- {
- CheckThreatLevel(ThreatLevel.None, "osParseJSONNew");
- m_host.AddScriptLPS(1);
- try
- {
- OSD decoded = OSDParser.DeserializeJson(JSON);
- return osdToObject(decoded);
- }
- catch(Exception e)
- {
- OSSLError("osParseJSONNew: Problems decoding JSON string " + JSON + " : " + e.Message) ;
- return null;
- }
- }
- public Hashtable osParseJSON(string JSON)
- {
- CheckThreatLevel(ThreatLevel.None, "osParseJSON");
- m_host.AddScriptLPS(1);
- Object decoded = osParseJSONNew(JSON);
-
- if ( decoded is Hashtable ) {
- return (Hashtable) decoded;
- } else if ( decoded is ArrayList ) {
- ArrayList decoded_list = (ArrayList) decoded;
- Hashtable fakearray = new Hashtable();
- int i = 0;
- for ( i = 0; i < decoded_list.Count ; i++ ) {
- fakearray.Add(i, decoded_list[i]);
- }
- return fakearray;
- } else {
- OSSLError("osParseJSON: unable to parse JSON string " + JSON);
- return null;
- }
- }
- /// <summary>
- /// Send a message to to object identified by the given UUID
- /// </summary>
- /// <remarks>
- /// A script in the object must implement the dataserver function
- /// the dataserver function is passed the ID of the calling function and a string message
- /// </remarks>
- /// <param name="objectUUID"></param>
- /// <param name="message"></param>
- public void osMessageObject(LSL_Key objectUUID, string message)
- {
- CheckThreatLevel(ThreatLevel.Low, "osMessageObject");
- m_host.AddScriptLPS(1);
- UUID objUUID;
- if (!UUID.TryParse(objectUUID, out objUUID)) // prior to patching, a thrown exception regarding invalid GUID format would be shouted instead.
- {
- OSSLShoutError("osMessageObject() cannot send messages to objects with invalid UUIDs");
- return;
- }
- MessageObject(objUUID, message);
- }
- private void MessageObject(UUID objUUID, string message)
- {
- object[] resobj = new object[] { new LSL_Types.LSLString(m_host.UUID.ToString()), new LSL_Types.LSLString(message) };
- SceneObjectPart sceneOP = World.GetSceneObjectPart(objUUID);
- if (sceneOP == null) // prior to patching, PostObjectEvent() would cause a throw exception to be shouted instead.
- {
- OSSLShoutError("osMessageObject() cannot send message to " + objUUID.ToString() + ", object was not found in scene.");
- return;
- }
- m_ScriptEngine.PostObjectEvent(
- sceneOP.LocalId, new EventParams(
- "dataserver", resobj, new DetectParams[0]));
- }
- /// <summary>
- /// Write a notecard directly to the prim's inventory.
- /// </summary>
- /// <remarks>
- /// This needs ThreatLevel high. It is an excellent griefer tool,
- /// In a loop, it can cause asset bloat and DOS levels of asset
- /// writes.
- /// </remarks>
- /// <param name="notecardName">The name of the notecard to write.</param>
- /// <param name="contents">The contents of the notecard.</param>
- public void osMakeNotecard(string notecardName, LSL_Types.list contents)
- {
- CheckThreatLevel(ThreatLevel.High, "osMakeNotecard");
- m_host.AddScriptLPS(1);
- StringBuilder notecardData = new StringBuilder();
- for (int i = 0; i < contents.Length; i++)
- notecardData.Append((string)(contents.GetLSLStringItem(i) + "\n"));
- SaveNotecard(notecardName, "Script generated notecard", notecardData.ToString(), false);
- }
- /// <summary>
- /// Save a notecard to prim inventory.
- /// </summary>
- /// <param name="name"></param>
- /// <param name="description">Description of notecard</param>
- /// <param name="notecardData"></param>
- /// <param name="forceSameName">
- /// If true, then if an item exists with the same name, it is replaced.
- /// If false, then a new item is created witha slightly different name (e.g. name 1)
- /// </param>
- /// <returns>Prim inventory item created.</returns>
- protected TaskInventoryItem SaveNotecard(string name, string description, string data, bool forceSameName)
- {
- // Create new asset
- AssetBase asset = new AssetBase(UUID.Random(), name, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString());
- asset.Description = description;
- int textLength = data.Length;
- data
- = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length "
- + textLength.ToString() + "\n" + data + "}\n";
- asset.Data = Util.UTF8.GetBytes(data);
- World.AssetService.Store(asset);
- // Create Task Entry
- TaskInventoryItem taskItem = new TaskInventoryItem();
- taskItem.ResetIDs(m_host.UUID);
- taskItem.ParentID = m_host.UUID;
- taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch();
- taskItem.Name = asset.Name;
- taskItem.Description = asset.Description;
- taskItem.Type = (int)AssetType.Notecard;
- taskItem.InvType = (int)InventoryType.Notecard;
- taskItem.OwnerID = m_host.OwnerID;
- taskItem.CreatorID = m_host.OwnerID;
- taskItem.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
- taskItem.CurrentPermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
- taskItem.EveryonePermissions = 0;
- taskItem.NextPermissions = (uint)PermissionMask.All;
- taskItem.GroupID = m_host.GroupID;
- taskItem.GroupPermissions = 0;
- taskItem.Flags = 0;
- taskItem.PermsGranter = UUID.Zero;
- taskItem.PermsMask = 0;
- taskItem.AssetID = asset.FullID;
- if (forceSameName)
- m_host.Inventory.AddInventoryItemExclusive(taskItem, false);
- else
- m_host.Inventory.AddInventoryItem(taskItem, false);
- return taskItem;
- }
- /// <summary>
- /// Load the notecard data found at the given prim inventory item name or asset uuid.
- /// </summary>
- /// <param name="notecardNameOrUuid"></param>
- /// <returns>The text loaded. Null if no notecard was found.</returns>
- protected string LoadNotecard(string notecardNameOrUuid)
- {
- UUID assetID = CacheNotecard(notecardNameOrUuid);
- if (assetID != UUID.Zero)
- {
- StringBuilder notecardData = new StringBuilder();
-
- for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
- {
- string line = NotecardCache.GetLine(assetID, count) + "\n";
-
- // m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line);
-
- notecardData.Append(line);
- }
-
- return notecardData.ToString();
- }
- return null;
- }
- /// <summary>
- /// Cache a notecard's contents.
- /// </summary>
- /// <param name="notecardNameOrUuid"></param>
- /// <returns>
- /// The asset id of the notecard, which is used for retrieving the cached data.
- /// UUID.Zero if no asset could be found.
- /// </returns>
- protected UUID CacheNotecard(string notecardNameOrUuid)
- {
- UUID assetID = UUID.Zero;
- if (!UUID.TryParse(notecardNameOrUuid, out assetID))
- {
- foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
- {
- if (item.Type == 7 && item.Name == notecardNameOrUuid)
- {
- assetID = item.AssetID;
- }
- }
- }
- if (assetID == UUID.Zero)
- return UUID.Zero;
- if (!NotecardCache.IsCached(assetID))
- {
- AssetBase a = World.AssetService.Get(assetID.ToString());
- if (a == null)
- return UUID.Zero;
- string data = Encoding.UTF8.GetString(a.Data);
- NotecardCache.Cache(assetID, data);
- };
- return assetID;
- }
- /// <summary>
- /// Directly get an entire notecard at once.
- /// </summary>
- /// <remarks>
- /// Instead of using the LSL Dataserver event to pull notecard data
- /// this will simply read the entire notecard and return its data as a string.
- ///
- /// Warning - due to the synchronous method this function uses to fetch assets, its use
- /// may be dangerous and unreliable while running in grid mode.
- /// </remarks>
- /// <param name="name">Name of the notecard or its asset id</param>
- /// <param name="line">The line number to read. The first line is line 0</param>
- /// <returns>Notecard line</returns>
- public string osGetNotecardLine(string name, int line)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine");
- m_host.AddScriptLPS(1);
- UUID assetID = CacheNotecard(name);
- if (assetID == UUID.Zero)
- {
- OSSLShoutError("Notecard '" + name + "' could not be found.");
- return "ERROR!";
- }
- return NotecardCache.GetLine(assetID, line);
- }
- /// <summary>
- /// Get an entire notecard at once.
- /// </summary>
- /// <remarks>
- /// Instead of using the LSL Dataserver event to pull notecard data line by line,
- /// this will simply read the entire notecard and return its data as a string.
- ///
- /// Warning - due to the synchronous method this function uses to fetch assets, its use
- /// may be dangerous and unreliable while running in grid mode.
- /// </remarks>
- /// <param name="name">Name of the notecard or its asset id</param>
- /// <returns>Notecard text</returns>
- public string osGetNotecard(string name)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard");
- m_host.AddScriptLPS(1);
- string text = LoadNotecard(name);
- if (text == null)
- {
- OSSLShoutError("Notecard '" + name + "' could not be found.");
- return "ERROR!";
- }
- else
- {
- return text;
- }
- }
- /// <summary>
- /// Get the number of lines in the given notecard.
- /// </summary>
- /// <remarks>
- /// Instead of using the LSL Dataserver event to pull notecard data,
- /// this will simply read the number of note card lines and return this data as an integer.
- ///
- /// Warning - due to the synchronous method this function uses to fetch assets, its use
- /// may be dangerous and unreliable while running in grid mode.
- /// </remarks>
- /// <param name="name">Name of the notecard or its asset id</param>
- /// <returns></returns>
- public int osGetNumberOfNotecardLines(string name)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines");
- m_host.AddScriptLPS(1);
- UUID assetID = CacheNotecard(name);
- if (assetID == UUID.Zero)
- {
- OSSLShoutError("Notecard '" + name + "' could not be found.");
- return -1;
- }
- return NotecardCache.GetLines(assetID);
- }
- public string osAvatarName2Key(string firstname, string lastname)
- {
- CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key");
- m_host.AddScriptLPS(1);
- UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, firstname, lastname);
- if (null == account)
- {
- return UUID.Zero.ToString();
- }
- else
- {
- return account.PrincipalID.ToString();
- }
- }
- public string osKey2Name(string id)
- {
- CheckThreatLevel(ThreatLevel.Low, "osKey2Name");
- m_host.AddScriptLPS(1);
- UUID key = new UUID();
- if (UUID.TryParse(id, out key))
- {
- UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, key);
- if (null == account)
- {
- return "";
- }
- else
- {
- return account.Name;
- }
- }
- else
- {
- return "";
- }
- }
- private enum InfoType
- {
- Nick,
- Name,
- Login,
- Home,
- Custom
- };
- private string GridUserInfo(InfoType type)
- {
- return GridUserInfo(type, "");
- }
- private string GridUserInfo(InfoType type, string key)
- {
- string retval = String.Empty;
- IConfigSource config = m_ScriptEngine.ConfigSource;
- string url = null;
- IConfig gridInfoConfig = config.Configs["GridInfo"];
- if (gridInfoConfig != null)
- url = gridInfoConfig.GetString("GridInfoURI", String.Empty);
- if (String.IsNullOrEmpty(url))
- return "Configuration Error!";
- string verb ="/json_grid_info";
- OSDMap json = new OSDMap();
- OSDMap info = WebUtil.GetFromService(String.Format("{0}{1}",url,verb), 3000);
- if (info["Success"] != true)
- return "Get GridInfo Failed!";
- json = (OSDMap)OSDParser.DeserializeJson(info["_RawResult"].AsString());
- switch (type)
- {
- case InfoType.Nick:
- retval = json["gridnick"];
- break;
- case InfoType.Name:
- retval = json["gridname"];
- break;
- case InfoType.Login:
- retval = json["login"];
- break;
- case InfoType.Home:
- retval = json["home"];
- break;
- case InfoType.Custom:
- retval = json[key];
- break;
- default:
- retval = "error";
- break;
- }
- return retval;
- }
- /// <summary>
- /// Get the nickname of this grid, as set in the [GridInfo] config section.
- /// </summary>
- /// <remarks>
- /// Threat level is Moderate because intentional abuse, for instance
- /// scripts that are written to be malicious only on one grid,
- /// for instance in a HG scenario, are a distinct possibility.
- /// </remarks>
- /// <returns></returns>
- public string osGetGridNick()
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetGridNick");
- m_host.AddScriptLPS(1);
- string nick = String.Empty;
- IConfigSource config = m_ScriptEngine.ConfigSource;
- if (config.Configs[GridInfoServiceConfigSectionName] != null)
- nick = config.Configs[GridInfoServiceConfigSectionName].GetString("gridnick", nick);
- if (String.IsNullOrEmpty(nick))
- nick = GridUserInfo(InfoType.Nick);
- return nick;
- }
- public string osGetGridName()
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetGridName");
- m_host.AddScriptLPS(1);
- string name = String.Empty;
- IConfigSource config = m_ScriptEngine.ConfigSource;
- if (config.Configs[GridInfoServiceConfigSectionName] != null)
- name = config.Configs[GridInfoServiceConfigSectionName].GetString("gridname", name);
- if (String.IsNullOrEmpty(name))
- name = GridUserInfo(InfoType.Name);
- return name;
- }
- public string osGetGridLoginURI()
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetGridLoginURI");
- m_host.AddScriptLPS(1);
- string loginURI = String.Empty;
- IConfigSource config = m_ScriptEngine.ConfigSource;
- if (config.Configs[GridInfoServiceConfigSectionName] != null)
- loginURI = config.Configs[GridInfoServiceConfigSectionName].GetString("login", loginURI);
- if (String.IsNullOrEmpty(loginURI))
- loginURI = GridUserInfo(InfoType.Login);
- return loginURI;
- }
- public string osGetGridHomeURI()
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetGridHomeURI");
- m_host.AddScriptLPS(1);
- IConfigSource config = m_ScriptEngine.ConfigSource;
- string HomeURI = Util.GetConfigVarFromSections<string>(config, "HomeURI",
- new string[] { "Startup", "Hypergrid" }, String.Empty);
- if (!string.IsNullOrEmpty(HomeURI))
- return HomeURI;
- // Legacy. Remove soon!
- if (config.Configs["LoginService"] != null)
- HomeURI = config.Configs["LoginService"].GetString("SRV_HomeURI", HomeURI);
- if (String.IsNullOrEmpty(HomeURI))
- HomeURI = GridUserInfo(InfoType.Home);
- return HomeURI;
- }
- public string osGetGridGatekeeperURI()
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetGridGatekeeperURI");
- m_host.AddScriptLPS(1);
- IConfigSource config = m_ScriptEngine.ConfigSource;
- string gatekeeperURI = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI",
- new string[] { "Startup", "Hypergrid" }, String.Empty);
- if (!string.IsNullOrEmpty(gatekeeperURI))
- return gatekeeperURI;
- // Legacy. Remove soon!
- if (config.Configs["GridService"] != null)
- gatekeeperURI = config.Configs["GridService"].GetString("Gatekeeper", gatekeeperURI);
- return gatekeeperURI;
- }
- public string osGetGridCustom(string key)
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetGridCustom");
- m_host.AddScriptLPS(1);
- string retval = String.Empty;
- IConfigSource config = m_ScriptEngine.ConfigSource;
- if (config.Configs[GridInfoServiceConfigSectionName] != null)
- retval = config.Configs[GridInfoServiceConfigSectionName].GetString(key, retval);
- if (String.IsNullOrEmpty(retval))
- retval = GridUserInfo(InfoType.Custom, key);
- return retval;
- }
- public LSL_String osFormatString(string str, LSL_List strings)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osFormatString");
- m_host.AddScriptLPS(1);
- return String.Format(str, strings.Data);
- }
- public LSL_List osMatchString(string src, string pattern, int start)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osMatchString");
- m_host.AddScriptLPS(1);
- LSL_List result = new LSL_List();
- // Normalize indices (if negative).
- // After normlaization they may still be
- // negative, but that is now relative to
- // the start, rather than the end, of the
- // sequence.
- if (start < 0)
- {
- start = src.Length + start;
- }
- if (start < 0 || start >= src.Length)
- {
- return result; // empty list
- }
- // Find matches beginning at start position
- Regex matcher = new Regex(pattern);
- Match match = matcher.Match(src, start);
- while (match.Success)
- {
- foreach (System.Text.RegularExpressions.Group g in match.Groups)
- {
- if (g.Success)
- {
- result.Add(new LSL_String(g.Value));
- result.Add(new LSL_Integer(g.Index));
- }
- }
- match = match.NextMatch();
- }
- return result;
- }
- public LSL_String osReplaceString(string src, string pattern, string replace, int count, int start)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osReplaceString");
- m_host.AddScriptLPS(1);
- // Normalize indices (if negative).
- // After normlaization they may still be
- // negative, but that is now relative to
- // the start, rather than the end, of the
- // sequence.
- if (start < 0)
- {
- start = src.Length + start;
- }
- if (start < 0 || start >= src.Length)
- {
- return src;
- }
- // Find matches beginning at start position
- Regex matcher = new Regex(pattern);
- return matcher.Replace(src,replace,count,start);
- }
- public string osLoadedCreationDate()
- {
- CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationDate");
- m_host.AddScriptLPS(1);
- return World.RegionInfo.RegionSettings.LoadedCreationDate;
- }
- public string osLoadedCreationTime()
- {
- CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationTime");
- m_host.AddScriptLPS(1);
- return World.RegionInfo.RegionSettings.LoadedCreationTime;
- }
- public string osLoadedCreationID()
- {
- CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationID");
- m_host.AddScriptLPS(1);
- return World.RegionInfo.RegionSettings.LoadedCreationID;
- }
- /// <summary>
- /// Get the primitive parameters of a linked prim.
- /// </summary>
- /// <remarks>
- /// Threat level is 'Low' because certain users could possibly be tricked into
- /// dropping an unverified script into one of their own objects, which could
- /// then gather the physical construction details of the object and transmit it
- /// to an unscrupulous third party, thus permitting unauthorized duplication of
- /// the object's form.
- /// </remarks>
- /// <param name="linknumber"></param>
- /// <param name="rules"></param>
- /// <returns></returns>
- public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules)
- {
- CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams");
- m_host.AddScriptLPS(1);
- InitLSL();
- // One needs to cast m_LSL_Api because we're using functions not
- // on the ILSL_Api interface.
- LSL_Api LSL_Api = (LSL_Api)m_LSL_Api;
- LSL_List retVal = new LSL_List();
- LSL_List remaining = null;
- List<SceneObjectPart> parts = LSL_Api.GetLinkParts(linknumber);
- foreach (SceneObjectPart part in parts)
- {
- remaining = LSL_Api.GetPrimParams(part, rules, ref retVal);
- }
- while (remaining != null && remaining.Length > 2)
- {
- linknumber = remaining.GetLSLIntegerItem(0);
- rules = remaining.GetSublist(1, -1);
- parts = LSL_Api.GetLinkParts(linknumber);
- foreach (SceneObjectPart part in parts)
- remaining = LSL_Api.GetPrimParams(part, rules, ref retVal);
- }
- return retVal;
- }
- public LSL_Integer osIsNpc(LSL_Key npc)
- {
- CheckThreatLevel(ThreatLevel.None, "osIsNpc");
- m_host.AddScriptLPS(1);
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId;
- if (UUID.TryParse(npc.m_string, out npcId))
- if (module.IsNPC(npcId, World))
- return ScriptBaseClass.TRUE;
- }
- return ScriptBaseClass.FALSE;
- }
- public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
- m_host.AddScriptLPS(1);
- return NpcCreate(firstname, lastname, position, notecard, false, false);
- }
- public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
- m_host.AddScriptLPS(1);
- return NpcCreate(
- firstname, lastname, position, notecard,
- (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0,
- (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0);
- }
- private LSL_Key NpcCreate(
- string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent)
- {
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- AvatarAppearance appearance = null;
- UUID id;
- if (UUID.TryParse(notecard, out id))
- {
- ScenePresence clonePresence = World.GetScenePresence(id);
- if (clonePresence != null)
- appearance = clonePresence.Appearance;
- }
- if (appearance == null)
- {
- string appearanceSerialized = LoadNotecard(notecard);
- if (appearanceSerialized != null)
- {
- OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
- appearance = new AvatarAppearance();
- appearance.Unpack(appearanceOsd);
- }
- else
- {
- OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard));
- }
- }
- UUID ownerID = UUID.Zero;
- if (owned)
- ownerID = m_host.OwnerID;
- UUID x = module.CreateNPC(firstname,
- lastname,
- position,
- ownerID,
- senseAsAgent,
- World,
- appearance);
- return new LSL_Key(x.ToString());
- }
- return new LSL_Key(UUID.Zero.ToString());
- }
- /// <summary>
- /// Save the current appearance of the NPC permanently to the named notecard.
- /// </summary>
- /// <param name="avatar"></param>
- /// <param name="notecard">The name of the notecard to which to save the appearance.</param>
- /// <returns>The asset ID of the notecard saved.</returns>
- public LSL_Key osNpcSaveAppearance(LSL_Key npc, string notecard)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcSaveAppearance");
- m_host.AddScriptLPS(1);
- INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
- if (npcModule != null)
- {
- UUID npcId;
- if (!UUID.TryParse(npc.m_string, out npcId))
- return new LSL_Key(UUID.Zero.ToString());
- if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
- return new LSL_Key(UUID.Zero.ToString());
- return SaveAppearanceToNotecard(npcId, notecard);
- }
- return new LSL_Key(UUID.Zero.ToString());
- }
- public void osNpcLoadAppearance(LSL_Key npc, string notecard)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcLoadAppearance");
- m_host.AddScriptLPS(1);
- INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
- if (npcModule != null)
- {
- UUID npcId;
- if (!UUID.TryParse(npc.m_string, out npcId))
- return;
- if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
- return;
- string appearanceSerialized = LoadNotecard(notecard);
- if (appearanceSerialized == null)
- OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard));
- OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
- // OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized);
- // Console.WriteLine("appearanceSerialized {0}", appearanceSerialized);
- // Console.WriteLine("a.Type {0}, a.ToString() {1}", a.Type, a);
- AvatarAppearance appearance = new AvatarAppearance();
- appearance.Unpack(appearanceOsd);
- npcModule.SetNPCAppearance(npcId, appearance, m_host.ParentGroup.Scene);
- }
- }
- public LSL_Key osNpcGetOwner(LSL_Key npc)
- {
- CheckThreatLevel(ThreatLevel.None, "osNpcGetOwner");
- m_host.AddScriptLPS(1);
- INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
- if (npcModule != null)
- {
- UUID npcId;
- if (UUID.TryParse(npc.m_string, out npcId))
- {
- UUID owner = npcModule.GetOwner(npcId);
- if (owner != UUID.Zero)
- return new LSL_Key(owner.ToString());
- else
- return npc;
- }
- }
- return new LSL_Key(UUID.Zero.ToString());
- }
- public LSL_Vector osNpcGetPos(LSL_Key npc)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcGetPos");
- m_host.AddScriptLPS(1);
- INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
- if (npcModule != null)
- {
- UUID npcId;
- if (!UUID.TryParse(npc.m_string, out npcId))
- return new LSL_Vector(0, 0, 0);
- if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
- return new LSL_Vector(0, 0, 0);
- ScenePresence sp = World.GetScenePresence(npcId);
- if (sp != null)
- return new LSL_Vector(sp.AbsolutePosition);
- }
- return Vector3.Zero;
- }
- public void osNpcMoveTo(LSL_Key npc, LSL_Vector pos)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo");
- m_host.AddScriptLPS(1);
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId;
- if (!UUID.TryParse(npc.m_string, out npcId))
- return;
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
-
- module.MoveToTarget(npcId, World, pos, false, true, false);
- }
- }
- public void osNpcMoveToTarget(LSL_Key npc, LSL_Vector target, int options)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcMoveToTarget");
- m_host.AddScriptLPS(1);
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId;
- if (!UUID.TryParse(npc.m_string, out npcId))
- return;
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- module.MoveToTarget(
- new UUID(npc.m_string),
- World,
- target,
- (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0,
- (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0,
- (options & ScriptBaseClass.OS_NPC_RUNNING) != 0);
- }
- }
- public LSL_Rotation osNpcGetRot(LSL_Key npc)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcGetRot");
- m_host.AddScriptLPS(1);
- INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
- if (npcModule != null)
- {
- UUID npcId;
- if (!UUID.TryParse(npc.m_string, out npcId))
- return new LSL_Rotation(Quaternion.Identity);
- if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
- return new LSL_Rotation(Quaternion.Identity);
- ScenePresence sp = World.GetScenePresence(npcId);
- if (sp != null)
- return new LSL_Rotation(sp.GetWorldRotation());
- }
- return Quaternion.Identity;
- }
- public void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcSetRot");
- m_host.AddScriptLPS(1);
- INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
- if (npcModule != null)
- {
- UUID npcId;
- if (!UUID.TryParse(npc.m_string, out npcId))
- return;
- if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
- return;
- ScenePresence sp = World.GetScenePresence(npcId);
- if (sp != null)
- sp.Rotation = rotation;
- }
- }
- public void osNpcStopMoveToTarget(LSL_Key npc)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcStopMoveToTarget");
- m_host.AddScriptLPS(1);
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId = new UUID(npc.m_string);
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- module.StopMoveToTarget(npcId, World);
- }
- }
- public void osNpcSay(LSL_Key npc, string message)
- {
- osNpcSay(npc, 0, message);
- }
- public void osNpcSay(LSL_Key npc, int channel, string message)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcSay");
- m_host.AddScriptLPS(1);
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId = new UUID(npc.m_string);
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- module.Say(npcId, World, message, channel);
- }
- }
- public void osNpcShout(LSL_Key npc, int channel, string message)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcShout");
- m_host.AddScriptLPS(1);
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId = new UUID(npc.m_string);
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- module.Shout(npcId, World, message, channel);
- }
- }
- public void osNpcSit(LSL_Key npc, LSL_Key target, int options)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcSit");
- m_host.AddScriptLPS(1);
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId = new UUID(npc.m_string);
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- module.Sit(npcId, new UUID(target.m_string), World);
- }
- }
- public void osNpcStand(LSL_Key npc)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcStand");
- m_host.AddScriptLPS(1);
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId = new UUID(npc.m_string);
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- module.Stand(npcId, World);
- }
- }
- public void osNpcRemove(LSL_Key npc)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcRemove");
- m_host.AddScriptLPS(1);
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId = new UUID(npc.m_string);
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- module.DeleteNPC(npcId, World);
- }
- }
- public void osNpcPlayAnimation(LSL_Key npc, string animation)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcPlayAnimation");
- m_host.AddScriptLPS(1);
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcID = new UUID(npc.m_string);
- if (module.CheckPermissions(npcID, m_host.OwnerID))
- AvatarPlayAnimation(npcID.ToString(), animation);
- }
- }
- public void osNpcStopAnimation(LSL_Key npc, string animation)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcStopAnimation");
- m_host.AddScriptLPS(1);
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcID = new UUID(npc.m_string);
- if (module.CheckPermissions(npcID, m_host.OwnerID))
- AvatarStopAnimation(npcID.ToString(), animation);
- }
- }
- public void osNpcWhisper(LSL_Key npc, int channel, string message)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcWhisper");
- m_host.AddScriptLPS(1);
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- if (module != null)
- {
- UUID npcId = new UUID(npc.m_string);
- if (!module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- module.Whisper(npcId, World, message, channel);
- }
- }
- public void osNpcTouch(LSL_Key npcLSL_Key, LSL_Key object_key, LSL_Integer link_num)
- {
- CheckThreatLevel(ThreatLevel.High, "osNpcTouch");
- m_host.AddScriptLPS(1);
-
- INPCModule module = World.RequestModuleInterface<INPCModule>();
- int linkNum = link_num.value;
- if (module != null || (linkNum < 0 && linkNum != ScriptBaseClass.LINK_THIS))
- {
- UUID npcId;
- if (!UUID.TryParse(npcLSL_Key, out npcId) || !module.CheckPermissions(npcId, m_host.OwnerID))
- return;
- SceneObjectPart part = null;
- UUID objectId;
- if (UUID.TryParse(LSL_String.ToString(object_key), out objectId))
- part = World.GetSceneObjectPart(objectId);
- if (part == null)
- return;
- if (linkNum != ScriptBaseClass.LINK_THIS)
- {
- if (linkNum == 0 || linkNum == ScriptBaseClass.LINK_ROOT)
- { // 0 and 1 are treated as root, find the root if the current part isnt it
- if (!part.IsRoot)
- part = part.ParentGroup.RootPart;
- }
- else
- { // Find the prim with the given link number if not found then fail silently
- part = part.ParentGroup.GetLinkNumPart(linkNum);
- if (part == null)
- return;
- }
- }
- module.Touch(npcId, part.UUID);
- }
- }
- /// <summary>
- /// Save the current appearance of the script owner permanently to the named notecard.
- /// </summary>
- /// <param name="notecard">The name of the notecard to which to save the appearance.</param>
- /// <returns>The asset ID of the notecard saved.</returns>
- public LSL_Key osOwnerSaveAppearance(string notecard)
- {
- CheckThreatLevel(ThreatLevel.High, "osOwnerSaveAppearance");
- m_host.AddScriptLPS(1);
- return SaveAppearanceToNotecard(m_host.OwnerID, notecard);
- }
- public LSL_Key osAgentSaveAppearance(LSL_Key avatarId, string notecard)
- {
- CheckThreatLevel(ThreatLevel.VeryHigh, "osAgentSaveAppearance");
- m_host.AddScriptLPS(1);
- return SaveAppearanceToNotecard(avatarId, notecard);
- }
- protected LSL_Key SaveAppearanceToNotecard(ScenePresence sp, string notecard)
- {
- IAvatarFactoryModule appearanceModule = World.RequestModuleInterface<IAvatarFactoryModule>();
- if (appearanceModule != null)
- {
- appearanceModule.SaveBakedTextures(sp.UUID);
- OSDMap appearancePacked = sp.Appearance.Pack();
- TaskInventoryItem item
- = SaveNotecard(notecard, "Avatar Appearance", Util.GetFormattedXml(appearancePacked as OSD), true);
- return new LSL_Key(item.AssetID.ToString());
- }
- else
- {
- return new LSL_Key(UUID.Zero.ToString());
- }
- }
- protected LSL_Key SaveAppearanceToNotecard(UUID avatarId, string notecard)
- {
- ScenePresence sp = World.GetScenePresence(avatarId);
- if (sp == null || sp.IsChildAgent)
- return new LSL_Key(UUID.Zero.ToString());
- return SaveAppearanceToNotecard(sp, notecard);
- }
- protected LSL_Key SaveAppearanceToNotecard(LSL_Key rawAvatarId, string notecard)
- {
- UUID avatarId;
- if (!UUID.TryParse(rawAvatarId, out avatarId))
- return new LSL_Key(UUID.Zero.ToString());
- return SaveAppearanceToNotecard(avatarId, notecard);
- }
-
- /// <summary>
- /// Get current region's map texture UUID
- /// </summary>
- /// <returns></returns>
- public LSL_Key osGetMapTexture()
- {
- CheckThreatLevel(ThreatLevel.None, "osGetMapTexture");
- m_host.AddScriptLPS(1);
- return m_ScriptEngine.World.RegionInfo.RegionSettings.TerrainImageID.ToString();
- }
- /// <summary>
- /// Get a region's map texture UUID by region UUID or name.
- /// </summary>
- /// <param name="regionName"></param>
- /// <returns></returns>
- public LSL_Key osGetRegionMapTexture(string regionName)
- {
- CheckThreatLevel(ThreatLevel.High, "osGetRegionMapTexture");
- m_host.AddScriptLPS(1);
- Scene scene = m_ScriptEngine.World;
- UUID key = UUID.Zero;
- GridRegion region;
- //If string is a key, use it. Otherwise, try to locate region by name.
- if (UUID.TryParse(regionName, out key))
- region = scene.GridService.GetRegionByUUID(UUID.Zero, key);
- else
- region = scene.GridService.GetRegionByName(UUID.Zero, regionName);
- // If region was found, return the regions map texture key.
- if (region != null)
- key = region.TerrainImage;
- ScriptSleep(1000);
- return key.ToString();
- }
-
- /// <summary>
- /// Return information regarding various simulator statistics (sim fps, physics fps, time
- /// dilation, total number of prims, total number of active scripts, script lps, various
- /// timing data, packets in/out, etc. Basically much the information that's shown in the
- /// client's Statistics Bar (Ctrl-Shift-1)
- /// </summary>
- /// <returns>List of floats</returns>
- public LSL_List osGetRegionStats()
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetRegionStats");
- m_host.AddScriptLPS(1);
- LSL_List ret = new LSL_List();
- float[] stats = World.StatsReporter.LastReportedSimStats;
-
- for (int i = 0; i < 21; i++)
- {
- ret.Add(new LSL_Float(stats[i]));
- }
- return ret;
- }
- public int osGetSimulatorMemory()
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemory");
- m_host.AddScriptLPS(1);
- long pws = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64;
- if (pws > Int32.MaxValue)
- return Int32.MaxValue;
- if (pws < 0)
- return 0;
- return (int)pws;
- }
-
- public void osSetSpeed(string UUID, LSL_Float SpeedModifier)
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osSetSpeed");
- m_host.AddScriptLPS(1);
- ScenePresence avatar = World.GetScenePresence(new UUID(UUID));
- if (avatar != null)
- avatar.SpeedModifier = (float)SpeedModifier;
- }
-
- public void osKickAvatar(string FirstName, string SurName, string alert)
- {
- CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
- m_host.AddScriptLPS(1);
- World.ForEachRootScenePresence(delegate(ScenePresence sp)
- {
- if (sp.Firstname == FirstName && sp.Lastname == SurName)
- {
- // kick client...
- if (alert != null)
- sp.ControllingClient.Kick(alert);
- // ...and close on our side
- sp.Scene.CloseAgent(sp.UUID, false);
- }
- });
- }
- public LSL_Float osGetHealth(string avatar)
- {
- CheckThreatLevel(ThreatLevel.None, "osGetHealth");
- m_host.AddScriptLPS(1);
- LSL_Float health = new LSL_Float(-1);
- ScenePresence presence = World.GetScenePresence(new UUID(avatar));
- if (presence != null) health = presence.Health;
- return health;
- }
-
- public void osCauseDamage(string avatar, double damage)
- {
- CheckThreatLevel(ThreatLevel.High, "osCauseDamage");
- m_host.AddScriptLPS(1);
- UUID avatarId = new UUID(avatar);
- Vector3 pos = m_host.GetWorldPosition();
- ScenePresence presence = World.GetScenePresence(avatarId);
- if (presence != null)
- {
- LandData land = World.GetLandData(pos);
- if ((land.Flags & (uint)ParcelFlags.AllowDamage) == (uint)ParcelFlags.AllowDamage)
- {
- float health = presence.Health;
- health -= (float)damage;
- presence.setHealthWithUpdate(health);
- if (health <= 0)
- {
- float healthliveagain = 100;
- presence.ControllingClient.SendAgentAlertMessage("You died!", true);
- presence.setHealthWithUpdate(healthliveagain);
- presence.Scene.TeleportClientHome(presence.UUID, presence.ControllingClient);
- }
- }
- }
- }
-
- public void osCauseHealing(string avatar, double healing)
- {
- CheckThreatLevel(ThreatLevel.High, "osCauseHealing");
- m_host.AddScriptLPS(1);
- UUID avatarId = new UUID(avatar);
- ScenePresence presence = World.GetScenePresence(avatarId);
- if (presence != null && World.ScriptDanger(m_host.LocalId, m_host.GetWorldPosition()))
- {
- float health = presence.Health;
- health += (float)healing;
- if (health >= 100)
- health = 100;
- presence.setHealthWithUpdate(health);
- }
- }
- public LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules)
- {
- CheckThreatLevel(ThreatLevel.High, "osGetPrimitiveParams");
- m_host.AddScriptLPS(1);
- InitLSL();
-
- return m_LSL_Api.GetPrimitiveParamsEx(prim, rules);
- }
- public void osSetPrimitiveParams(LSL_Key prim, LSL_List rules)
- {
- CheckThreatLevel(ThreatLevel.High, "osSetPrimitiveParams");
- m_host.AddScriptLPS(1);
- InitLSL();
-
- m_LSL_Api.SetPrimitiveParamsEx(prim, rules, "osSetPrimitiveParams");
- }
-
- /// <summary>
- /// Set parameters for light projection in host prim
- /// </summary>
- public void osSetProjectionParams(bool projection, LSL_Key texture, double fov, double focus, double amb)
- {
- CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams");
- osSetProjectionParams(UUID.Zero.ToString(), projection, texture, fov, focus, amb);
- }
- /// <summary>
- /// Set parameters for light projection with uuid of target prim
- /// </summary>
- public void osSetProjectionParams(LSL_Key prim, bool projection, LSL_Key texture, double fov, double focus, double amb)
- {
- CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams");
- m_host.AddScriptLPS(1);
- SceneObjectPart obj = null;
- if (prim == UUID.Zero.ToString())
- {
- obj = m_host;
- }
- else
- {
- obj = World.GetSceneObjectPart(new UUID(prim));
- if (obj == null)
- return;
- }
- obj.Shape.ProjectionEntry = projection;
- obj.Shape.ProjectionTextureUUID = new UUID(texture);
- obj.Shape.ProjectionFOV = (float)fov;
- obj.Shape.ProjectionFocus = (float)focus;
- obj.Shape.ProjectionAmbiance = (float)amb;
- obj.ParentGroup.HasGroupChanged = true;
- obj.ScheduleFullUpdate();
- }
- /// <summary>
- /// Like osGetAgents but returns enough info for a radar
- /// </summary>
- /// <returns>Strided list of the UUID, position and name of each avatar in the region</returns>
- public LSL_List osGetAvatarList()
- {
- CheckThreatLevel(ThreatLevel.None, "osGetAvatarList");
- m_host.AddScriptLPS(1);
- LSL_List result = new LSL_List();
- World.ForEachRootScenePresence(delegate (ScenePresence avatar)
- {
- if (avatar != null && avatar.UUID != m_host.OwnerID)
- {
- result.Add(new LSL_String(avatar.UUID.ToString()));
- result.Add(new LSL_Vector(avatar.AbsolutePosition));
- result.Add(new LSL_String(avatar.Name));
- }
- });
- return result;
- }
- /// <summary>
- /// Convert a unix time to a llGetTimestamp() like string
- /// </summary>
- /// <param name="unixTime"></param>
- /// <returns></returns>
- public LSL_String osUnixTimeToTimestamp(long time)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osUnixTimeToTimestamp");
- m_host.AddScriptLPS(1);
- long baseTicks = 621355968000000000;
- long tickResolution = 10000000;
- long epochTicks = (time * tickResolution) + baseTicks;
- DateTime date = new DateTime(epochTicks);
- return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
- }
- /// <summary>
- /// Get the description from an inventory item
- /// </summary>
- /// <param name="inventoryName"></param>
- /// <returns>Item description</returns>
- public LSL_String osGetInventoryDesc(string item)
- {
- m_host.AddScriptLPS(1);
- lock (m_host.TaskInventory)
- {
- foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
- {
- if (inv.Value.Name == item)
- {
- return inv.Value.Description.ToString();
- }
- }
- }
- return String.Empty;
- }
- /// <summary>
- /// Invite user to the group this object is set to
- /// </summary>
- /// <param name="agentId"></param>
- /// <returns></returns>
- public LSL_Integer osInviteToGroup(LSL_Key agentId)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osInviteToGroup");
- m_host.AddScriptLPS(1);
- UUID agent = new UUID(agentId);
- // groups module is required
- IGroupsModule groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
- if (groupsModule == null) return ScriptBaseClass.FALSE;
- // object has to be set to a group, but not group owned
- if (m_host.GroupID == UUID.Zero || m_host.GroupID == m_host.OwnerID) return ScriptBaseClass.FALSE;
- // object owner has to be in that group and required permissions
- GroupMembershipData member = groupsModule.GetMembershipData(m_host.GroupID, m_host.OwnerID);
- if (member == null || (member.GroupPowers & (ulong)GroupPowers.Invite) == 0) return ScriptBaseClass.FALSE;
- // check if agent is in that group already
- //member = groupsModule.GetMembershipData(agent, m_host.GroupID, agent);
- //if (member != null) return ScriptBaseClass.FALSE;
- // invited agent has to be present in this scene
- if (World.GetScenePresence(agent) == null) return ScriptBaseClass.FALSE;
- groupsModule.InviteGroup(null, m_host.OwnerID, m_host.GroupID, agent, UUID.Zero);
- return ScriptBaseClass.TRUE;
- }
- /// <summary>
- /// Eject user from the group this object is set to
- /// </summary>
- /// <param name="agentId"></param>
- /// <returns></returns>
- public LSL_Integer osEjectFromGroup(LSL_Key agentId)
- {
- CheckThreatLevel(ThreatLevel.VeryLow, "osEjectFromGroup");
- m_host.AddScriptLPS(1);
- UUID agent = new UUID(agentId);
- // groups module is required
- IGroupsModule groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
- if (groupsModule == null) return ScriptBaseClass.FALSE;
- // object has to be set to a group, but not group owned
- if (m_host.GroupID == UUID.Zero || m_host.GroupID == m_host.OwnerID) return ScriptBaseClass.FALSE;
- // object owner has to be in that group and required permissions
- GroupMembershipData member = groupsModule.GetMembershipData(m_host.GroupID, m_host.OwnerID);
- if (member == null || (member.GroupPowers & (ulong)GroupPowers.Eject) == 0) return ScriptBaseClass.FALSE;
- // agent has to be in that group
- //member = groupsModule.GetMembershipData(agent, m_host.GroupID, agent);
- //if (member == null) return ScriptBaseClass.FALSE;
- // ejectee can be offline
- groupsModule.EjectGroupMember(null, m_host.OwnerID, m_host.GroupID, agent);
- return ScriptBaseClass.TRUE;
- }
- /// <summary>
- /// Sets terrain estate texture
- /// </summary>
- /// <param name="level"></param>
- /// <param name="texture"></param>
- /// <returns></returns>
- public void osSetTerrainTexture(int level, LSL_Key texture)
- {
- CheckThreatLevel(ThreatLevel.High, "osSetTerrainTexture");
- m_host.AddScriptLPS(1);
- //Check to make sure that the script's owner is the estate manager/master
- //World.Permissions.GenericEstatePermission(
- if (World.Permissions.IsGod(m_host.OwnerID))
- {
- if (level < 0 || level > 3)
- return;
- UUID textureID = new UUID();
- if (!UUID.TryParse(texture, out textureID))
- return;
- // estate module is required
- IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
- if (estate != null)
- estate.setEstateTerrainBaseTexture(level, textureID);
- }
- }
- /// <summary>
- /// Sets terrain heights of estate
- /// </summary>
- /// <param name="corner"></param>
- /// <param name="low"></param>
- /// <param name="high"></param>
- /// <returns></returns>
- public void osSetTerrainTextureHeight(int corner, double low, double high)
- {
- CheckThreatLevel(ThreatLevel.High, "osSetTerrainTextureHeight");
- m_host.AddScriptLPS(1);
- //Check to make sure that the script's owner is the estate manager/master
- //World.Permissions.GenericEstatePermission(
- if (World.Permissions.IsGod(m_host.OwnerID))
- {
- if (corner < 0 || corner > 3)
- return;
- // estate module is required
- IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
- if (estate != null)
- estate.setEstateTerrainTextureHeights(corner, (float)low, (float)high);
- }
- }
- #region Attachment commands
- public void osForceAttachToAvatar(int attachmentPoint)
- {
- CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar");
- m_host.AddScriptLPS(1);
- InitLSL();
- ((LSL_Api)m_LSL_Api).AttachToAvatar(attachmentPoint);
- }
- public void osForceAttachToAvatarFromInventory(string itemName, int attachmentPoint)
- {
- CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatarFromInventory");
- m_host.AddScriptLPS(1);
- ForceAttachToAvatarFromInventory(m_host.OwnerID, itemName, attachmentPoint);
- }
- public void osForceAttachToOtherAvatarFromInventory(string rawAvatarId, string itemName, int attachmentPoint)
- {
- CheckThreatLevel(ThreatLevel.Severe, "osForceAttachToOtherAvatarFromInventory");
- m_host.AddScriptLPS(1);
- UUID avatarId;
- if (!UUID.TryParse(rawAvatarId, out avatarId))
- return;
- ForceAttachToAvatarFromInventory(avatarId, itemName, attachmentPoint);
- }
- public void ForceAttachToAvatarFromInventory(UUID avatarId, string itemName, int attachmentPoint)
- {
- IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
- if (attachmentsModule == null)
- return;
- InitLSL();
- TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
- if (item == null)
- {
- ((LSL_Api)m_LSL_Api).llSay(0, string.Format("Could not find object '{0}'", itemName));
- throw new Exception(String.Format("The inventory item '{0}' could not be found", itemName));
- }
- if (item.InvType != (int)InventoryType.Object)
- {
- // FIXME: Temporary null check for regression tests since they dont' have the infrastructure to set
- // up the api reference.
- if (m_LSL_Api != null)
- ((LSL_Api)m_LSL_Api).llSay(0, string.Format("Unable to attach, item '{0}' is not an object.", itemName));
- throw new Exception(String.Format("The inventory item '{0}' is not an object", itemName));
- }
- ScenePresence sp = World.GetScenePresence(avatarId);
- if (sp == null)
- return;
- InventoryItemBase newItem = World.MoveTaskInventoryItem(sp.UUID, UUID.Zero, m_host, item.ItemID);
- if (newItem == null)
- {
- m_log.ErrorFormat(
- "[OSSL API]: Could not create user inventory item {0} for {1}, attach point {2} in {3}",
- itemName, m_host.Name, attachmentPoint, World.Name);
- return;
- }
- attachmentsModule.RezSingleAttachmentFromInventory(sp, newItem.ID, (uint)attachmentPoint);
- }
- public void osForceDetachFromAvatar()
- {
- CheckThreatLevel(ThreatLevel.High, "osForceDetachFromAvatar");
- m_host.AddScriptLPS(1);
- InitLSL();
- ((LSL_Api)m_LSL_Api).DetachFromAvatar();
- }
- public LSL_List osGetNumberOfAttachments(LSL_Key avatar, LSL_List attachmentPoints)
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osGetNumberOfAttachments");
- m_host.AddScriptLPS(1);
- UUID targetUUID;
- ScenePresence target;
- LSL_List resp = new LSL_List();
- if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out targetUUID) && World.TryGetScenePresence(targetUUID, out target))
- {
- foreach (object point in attachmentPoints.Data)
- {
- LSL_Integer ipoint = new LSL_Integer(
- (point is LSL_Integer || point is int || point is uint) ?
- (int)point :
- 0
- );
- resp.Add(ipoint);
- if (ipoint == 0)
- {
- // indicates zero attachments
- resp.Add(new LSL_Integer(0));
- }
- else
- {
- // gets the number of attachments on the attachment point
- resp.Add(new LSL_Integer(target.GetAttachments((uint)ipoint).Count));
- }
- }
- }
- return resp;
- }
- public void osMessageAttachments(LSL_Key avatar, string message, LSL_List attachmentPoints, int options)
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osMessageAttachments");
- m_host.AddScriptLPS(1);
- UUID targetUUID;
- ScenePresence target;
- if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out targetUUID) && World.TryGetScenePresence(targetUUID, out target))
- {
- List<int> aps = new List<int>();
- foreach (object point in attachmentPoints.Data)
- {
- int ipoint;
- if (int.TryParse(point.ToString(), out ipoint))
- {
- aps.Add(ipoint);
- }
- }
- List<SceneObjectGroup> attachments = new List<SceneObjectGroup>();
- bool msgAll = aps.Contains(ScriptBaseClass.OS_ATTACH_MSG_ALL);
- bool invertPoints = (options & ScriptBaseClass.OS_ATTACH_MSG_INVERT_POINTS) != 0;
- if (msgAll && invertPoints)
- {
- return;
- }
- else if (msgAll || invertPoints)
- {
- attachments = target.GetAttachments();
- }
- else
- {
- foreach (int point in aps)
- {
- if (point > 0)
- {
- attachments.AddRange(target.GetAttachments((uint)point));
- }
- }
- }
- // if we have no attachments at this point, exit now
- if (attachments.Count == 0)
- {
- return;
- }
- List<SceneObjectGroup> ignoreThese = new List<SceneObjectGroup>();
- if (invertPoints)
- {
- foreach (SceneObjectGroup attachment in attachments)
- {
- if (aps.Contains((int)attachment.AttachmentPoint))
- {
- ignoreThese.Add(attachment);
- }
- }
- }
- foreach (SceneObjectGroup attachment in ignoreThese)
- {
- attachments.Remove(attachment);
- }
- ignoreThese.Clear();
- // if inverting removed all attachments to check, exit now
- if (attachments.Count < 1)
- {
- return;
- }
- if ((options & ScriptBaseClass.OS_ATTACH_MSG_OBJECT_CREATOR) != 0)
- {
- foreach (SceneObjectGroup attachment in attachments)
- {
- if (attachment.RootPart.CreatorID != m_host.CreatorID)
- {
- ignoreThese.Add(attachment);
- }
- }
- foreach (SceneObjectGroup attachment in ignoreThese)
- {
- attachments.Remove(attachment);
- }
- ignoreThese.Clear();
- // if filtering by same object creator removed all
- // attachments to check, exit now
- if (attachments.Count == 0)
- {
- return;
- }
- }
- if ((options & ScriptBaseClass.OS_ATTACH_MSG_SCRIPT_CREATOR) != 0)
- {
- foreach (SceneObjectGroup attachment in attachments)
- {
- if (attachment.RootPart.CreatorID != m_item.CreatorID)
- {
- ignoreThese.Add(attachment);
- }
- }
- foreach (SceneObjectGroup attachment in ignoreThese)
- {
- attachments.Remove(attachment);
- }
- ignoreThese.Clear();
- // if filtering by object creator must match originating
- // script creator removed all attachments to check,
- // exit now
- if (attachments.Count == 0)
- {
- return;
- }
- }
- foreach (SceneObjectGroup attachment in attachments)
- {
- MessageObject(attachment.RootPart.UUID, message);
- }
- }
- }
- #endregion
- /// <summary>
- /// Checks if thing is a UUID.
- /// </summary>
- /// <param name="thing"></param>
- /// <returns>1 if thing is a valid UUID, 0 otherwise</returns>
- public LSL_Integer osIsUUID(string thing)
- {
- CheckThreatLevel(ThreatLevel.None, "osIsUUID");
- m_host.AddScriptLPS(1);
- UUID test;
- return UUID.TryParse(thing, out test) ? 1 : 0;
- }
- /// <summary>
- /// Wraps to Math.Min()
- /// </summary>
- /// <param name="a"></param>
- /// <param name="b"></param>
- /// <returns></returns>
- public LSL_Float osMin(double a, double b)
- {
- CheckThreatLevel(ThreatLevel.None, "osMin");
- m_host.AddScriptLPS(1);
- return Math.Min(a, b);
- }
- /// <summary>
- /// Wraps to Math.max()
- /// </summary>
- /// <param name="a"></param>
- /// <param name="b"></param>
- /// <returns></returns>
- public LSL_Float osMax(double a, double b)
- {
- CheckThreatLevel(ThreatLevel.None, "osMax");
- m_host.AddScriptLPS(1);
- return Math.Max(a, b);
- }
- public LSL_Key osGetRezzingObject()
- {
- CheckThreatLevel(ThreatLevel.None, "osGetRezzingObject");
- m_host.AddScriptLPS(1);
- return new LSL_Key(m_host.ParentGroup.FromPartID.ToString());
- }
- /// <summary>
- /// Sets the response type for an HTTP request/response
- /// </summary>
- /// <returns></returns>
- public void osSetContentType(LSL_Key id, string type)
- {
- CheckThreatLevel(ThreatLevel.High, "osSetContentType");
- if (m_UrlModule != null)
- m_UrlModule.HttpContentType(new UUID(id),type);
- }
- /// Shout an error if the object owner did not grant the script the specified permissions.
- /// </summary>
- /// <param name="perms"></param>
- /// <returns>boolean indicating whether an error was shouted.</returns>
- protected bool ShoutErrorOnLackingOwnerPerms(int perms, string errorPrefix)
- {
- m_host.AddScriptLPS(1);
- bool fail = false;
- if (m_item.PermsGranter != m_host.OwnerID)
- {
- fail = true;
- OSSLShoutError(string.Format("{0}. Permissions not granted to owner.", errorPrefix));
- }
- else if ((m_item.PermsMask & perms) == 0)
- {
- fail = true;
- OSSLShoutError(string.Format("{0}. Permissions not granted.", errorPrefix));
- }
- return fail;
- }
- protected void DropAttachment(bool checkPerms)
- {
- if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment"))
- {
- return;
- }
- IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
- ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID);
- if (attachmentsModule != null && sp != null)
- {
- attachmentsModule.DetachSingleAttachmentToGround(sp, m_host.ParentGroup.LocalId);
- }
- }
- protected void DropAttachmentAt(bool checkPerms, LSL_Vector pos, LSL_Rotation rot)
- {
- if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment"))
- {
- return;
- }
- IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
- ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID);
- if (attachmentsModule != null && sp != null)
- {
- attachmentsModule.DetachSingleAttachmentToGround(sp, m_host.ParentGroup.LocalId, pos, rot);
- }
- }
- public void osDropAttachment()
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachment");
- m_host.AddScriptLPS(1);
- DropAttachment(true);
- }
- public void osForceDropAttachment()
- {
- CheckThreatLevel(ThreatLevel.High, "osForceDropAttachment");
- m_host.AddScriptLPS(1);
- DropAttachment(false);
- }
- public void osDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot)
- {
- CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachmentAt");
- m_host.AddScriptLPS(1);
- DropAttachmentAt(true, pos, rot);
- }
- public void osForceDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot)
- {
- CheckThreatLevel(ThreatLevel.High, "osForceDropAttachmentAt");
- m_host.AddScriptLPS(1);
- DropAttachmentAt(false, pos, rot);
- }
- public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
- {
- CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
- m_host.AddScriptLPS(1);
- UUID keyID;
- UUID.TryParse(ID, out keyID);
- // if we want the name to be used as a regular expression, ensure it is valid first.
- if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_NAME) == ScriptBaseClass.OS_LISTEN_REGEX_NAME)
- {
- try
- {
- Regex.IsMatch("", name);
- }
- catch (Exception)
- {
- OSSLShoutError("Name regex is invalid.");
- return -1;
- }
- }
- // if we want the msg to be used as a regular expression, ensure it is valid first.
- if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) == ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE)
- {
- try
- {
- Regex.IsMatch("", msg);
- }
- catch (Exception)
- {
- OSSLShoutError("Message regex is invalid.");
- return -1;
- }
- }
- IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
- return (wComm == null) ? -1 : wComm.Listen(
- m_host.LocalId,
- m_item.ItemID,
- m_host.UUID,
- channelID,
- name,
- keyID,
- msg,
- regexBitfield
- );
- }
- public LSL_Integer osRegexIsMatch(string input, string pattern)
- {
- CheckThreatLevel(ThreatLevel.Low, "osRegexIsMatch");
- m_host.AddScriptLPS(1);
- try
- {
- return Regex.IsMatch(input, pattern) ? 1 : 0;
- }
- catch (Exception)
- {
- OSSLShoutError("Possible invalid regular expression detected.");
- return 0;
- }
- }
- }
- }
|