LSL_Api.cs 468 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Runtime.Remoting.Lifetime;
  31. using System.Text;
  32. using System.Threading;
  33. using System.Text.RegularExpressions;
  34. using Nini.Config;
  35. using log4net;
  36. using OpenMetaverse;
  37. using OpenMetaverse.Packets;
  38. using OpenSim;
  39. using OpenSim.Framework;
  40. using OpenSim.Region.CoreModules;
  41. using OpenSim.Region.CoreModules.World.Land;
  42. using OpenSim.Region.CoreModules.World.Terrain;
  43. using OpenSim.Region.Framework.Interfaces;
  44. using OpenSim.Region.Framework.Scenes;
  45. using OpenSim.Region.Framework.Scenes.Animation;
  46. using OpenSim.Region.Framework.Scenes.Scripting;
  47. using OpenSim.Region.Physics.Manager;
  48. using OpenSim.Region.ScriptEngine.Shared;
  49. using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
  50. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  51. using OpenSim.Region.ScriptEngine.Interfaces;
  52. using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
  53. using OpenSim.Services.Interfaces;
  54. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  55. using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
  56. using PrimType = OpenSim.Region.Framework.Scenes.PrimType;
  57. using AssetLandmark = OpenSim.Framework.AssetLandmark;
  58. using RegionFlags = OpenSim.Framework.RegionFlags;
  59. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  60. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  61. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  62. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  63. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  64. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  65. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  66. using System.Reflection;
  67. using System.Linq;
  68. using PermissionMask = OpenSim.Framework.PermissionMask;
  69. namespace OpenSim.Region.ScriptEngine.Shared.Api
  70. {
  71. // MUST be a ref type
  72. public class UserInfoCacheEntry
  73. {
  74. public int time;
  75. public UserAccount account;
  76. public PresenceInfo pinfo;
  77. }
  78. /// <summary>
  79. /// Contains all LSL ll-functions. This class will be in Default AppDomain.
  80. /// </summary>
  81. public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi
  82. {
  83. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  84. public int LlRequestAgentDataCacheTimeoutMs { get; set; }
  85. protected IScriptEngine m_ScriptEngine;
  86. protected SceneObjectPart m_host;
  87. /// <summary>
  88. /// Used for script sleeps when we are using co-operative script termination.
  89. /// </summary>
  90. /// <remarks>null if co-operative script termination is not active</remarks>
  91. WaitHandle m_coopSleepHandle;
  92. /// <summary>
  93. /// The item that hosts this script
  94. /// </summary>
  95. protected TaskInventoryItem m_item;
  96. protected bool throwErrorOnNotImplemented = false;
  97. protected AsyncCommandManager AsyncCommands = null;
  98. protected float m_ScriptDelayFactor = 1.0f;
  99. protected float m_ScriptDistanceFactor = 1.0f;
  100. protected float m_MinTimerInterval = 0.5f;
  101. protected float m_recoilScaleFactor = 0.0f;
  102. protected DateTime m_timer = DateTime.Now;
  103. protected bool m_waitingForScriptAnswer = false;
  104. protected bool m_automaticLinkPermission = false;
  105. protected IMessageTransferModule m_TransferModule = null;
  106. protected int m_notecardLineReadCharsMax = 255;
  107. protected int m_scriptConsoleChannel = 0;
  108. protected bool m_scriptConsoleChannelEnabled = false;
  109. protected IUrlModule m_UrlModule = null;
  110. protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache = new Dictionary<UUID, UserInfoCacheEntry>();
  111. protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp.
  112. protected string m_internalObjectHost = "lsl.opensim.local";
  113. protected bool m_restrictEmail = false;
  114. protected ISoundModule m_SoundModule = null;
  115. //An array of HTTP/1.1 headers that are not allowed to be used
  116. //as custom headers by llHTTPRequest.
  117. private string[] HttpStandardHeaders =
  118. {
  119. "Accept", "Accept-Charset", "Accept-Encoding", "Accept-Language",
  120. "Accept-Ranges", "Age", "Allow", "Authorization", "Cache-Control",
  121. "Connection", "Content-Encoding", "Content-Language",
  122. "Content-Length", "Content-Location", "Content-MD5",
  123. "Content-Range", "Content-Type", "Date", "ETag", "Expect",
  124. "Expires", "From", "Host", "If-Match", "If-Modified-Since",
  125. "If-None-Match", "If-Range", "If-Unmodified-Since", "Last-Modified",
  126. "Location", "Max-Forwards", "Pragma", "Proxy-Authenticate",
  127. "Proxy-Authorization", "Range", "Referer", "Retry-After", "Server",
  128. "TE", "Trailer", "Transfer-Encoding", "Upgrade", "User-Agent",
  129. "Vary", "Via", "Warning", "WWW-Authenticate"
  130. };
  131. public void Initialize(
  132. IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, WaitHandle coopSleepHandle)
  133. {
  134. m_ScriptEngine = scriptEngine;
  135. m_host = host;
  136. m_item = item;
  137. m_coopSleepHandle = coopSleepHandle;
  138. LoadConfig();
  139. m_TransferModule =
  140. m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
  141. m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
  142. m_SoundModule = m_ScriptEngine.World.RequestModuleInterface<ISoundModule>();
  143. AsyncCommands = new AsyncCommandManager(m_ScriptEngine);
  144. }
  145. /// <summary>
  146. /// Load configuration items that affect script, object and run-time behavior. */
  147. /// </summary>
  148. private void LoadConfig()
  149. {
  150. LlRequestAgentDataCacheTimeoutMs = 20000;
  151. IConfig seConfig = m_ScriptEngine.Config;
  152. if (seConfig != null)
  153. {
  154. m_ScriptDelayFactor =
  155. seConfig.GetFloat("ScriptDelayFactor", m_ScriptDelayFactor);
  156. m_ScriptDistanceFactor =
  157. seConfig.GetFloat("ScriptDistanceLimitFactor", m_ScriptDistanceFactor);
  158. m_MinTimerInterval =
  159. seConfig.GetFloat("MinTimerInterval", m_MinTimerInterval);
  160. m_automaticLinkPermission =
  161. seConfig.GetBoolean("AutomaticLinkPermission", m_automaticLinkPermission);
  162. m_notecardLineReadCharsMax =
  163. seConfig.GetInt("NotecardLineReadCharsMax", m_notecardLineReadCharsMax);
  164. // Rezzing an object with a velocity can create recoil. This feature seems to have been
  165. // removed from recent versions of SL. The code computes recoil (vel*mass) and scales
  166. // it by this factor. May be zero to turn off recoil all together.
  167. m_recoilScaleFactor = m_ScriptEngine.Config.GetFloat("RecoilScaleFactor", m_recoilScaleFactor);
  168. }
  169. if (m_notecardLineReadCharsMax > 65535)
  170. m_notecardLineReadCharsMax = 65535;
  171. // load limits for particular subsystems.
  172. IConfigSource seConfigSource = m_ScriptEngine.ConfigSource;
  173. if (seConfigSource != null)
  174. {
  175. IConfig lslConfig = seConfigSource.Configs["LL-Functions"];
  176. if (lslConfig != null)
  177. {
  178. m_restrictEmail = lslConfig.GetBoolean("RestrictEmail", m_restrictEmail);
  179. }
  180. IConfig smtpConfig = seConfigSource.Configs["SMTP"];
  181. if (smtpConfig != null)
  182. {
  183. // there's an smtp config, so load in the snooze time.
  184. EMAIL_PAUSE_TIME = smtpConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME);
  185. m_internalObjectHost = smtpConfig.GetString("internal_object_host", m_internalObjectHost);
  186. }
  187. }
  188. }
  189. public override Object InitializeLifetimeService()
  190. {
  191. ILease lease = (ILease)base.InitializeLifetimeService();
  192. if (lease.CurrentState == LeaseState.Initial)
  193. {
  194. lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
  195. // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
  196. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
  197. }
  198. return lease;
  199. }
  200. protected virtual void ScriptSleep(int delay)
  201. {
  202. delay = (int)((float)delay * m_ScriptDelayFactor);
  203. if (delay == 0)
  204. return;
  205. Sleep(delay);
  206. }
  207. protected virtual void Sleep(int delay)
  208. {
  209. if (m_coopSleepHandle == null)
  210. System.Threading.Thread.Sleep(delay);
  211. else
  212. CheckForCoopTermination(delay);
  213. }
  214. /// <summary>
  215. /// Check for co-operative termination.
  216. /// </summary>
  217. /// <param name='delay'>If called with 0, then just the check is performed with no wait.</param>
  218. protected virtual void CheckForCoopTermination(int delay)
  219. {
  220. if (m_coopSleepHandle.WaitOne(delay))
  221. throw new ScriptCoopStopException();
  222. }
  223. public Scene World
  224. {
  225. get { return m_ScriptEngine.World; }
  226. }
  227. public void state(string newState)
  228. {
  229. m_ScriptEngine.SetState(m_item.ItemID, newState);
  230. }
  231. /// <summary>
  232. /// Reset the named script. The script must be present
  233. /// in the same prim.
  234. /// </summary>
  235. public void llResetScript()
  236. {
  237. m_host.AddScriptLPS(1);
  238. // We need to tell the URL module, if we hav one, to release
  239. // the allocated URLs
  240. if (m_UrlModule != null)
  241. m_UrlModule.ScriptRemoved(m_item.ItemID);
  242. m_ScriptEngine.ApiResetScript(m_item.ItemID);
  243. }
  244. public void llResetOtherScript(string name)
  245. {
  246. UUID item;
  247. m_host.AddScriptLPS(1);
  248. if ((item = GetScriptByName(name)) != UUID.Zero)
  249. m_ScriptEngine.ResetScript(item);
  250. else
  251. Error("llResetOtherScript", "Can't find script '" + name + "'");
  252. }
  253. public LSL_Integer llGetScriptState(string name)
  254. {
  255. UUID item;
  256. m_host.AddScriptLPS(1);
  257. if ((item = GetScriptByName(name)) != UUID.Zero)
  258. {
  259. return m_ScriptEngine.GetScriptState(item) ?1:0;
  260. }
  261. Error("llGetScriptState", "Can't find script '" + name + "'");
  262. // If we didn't find it, then it's safe to
  263. // assume it is not running.
  264. return 0;
  265. }
  266. public void llSetScriptState(string name, int run)
  267. {
  268. UUID item;
  269. m_host.AddScriptLPS(1);
  270. // These functions are supposed to be robust,
  271. // so get the state one step at a time.
  272. if ((item = GetScriptByName(name)) != UUID.Zero)
  273. {
  274. m_ScriptEngine.SetScriptState(item, run == 0 ? false : true);
  275. }
  276. else
  277. {
  278. Error("llSetScriptState", "Can't find script '" + name + "'");
  279. }
  280. }
  281. /// <summary>
  282. /// Get a given link entity from a linkset (linked objects and any sitting avatars).
  283. /// </summary>
  284. /// <remarks>
  285. /// If there are any ScenePresence's in the linkset (i.e. because they are sat upon one of the prims), then
  286. /// these are counted as extra entities that correspond to linknums beyond the number of prims in the linkset.
  287. /// The ScenePresences receive linknums in the order in which they sat.
  288. /// </remarks>
  289. /// <returns>
  290. /// The link entity. null if not found.
  291. /// </returns>
  292. /// <param name='part'></param>
  293. /// <param name='linknum'>
  294. /// Can be either a non-negative integer or ScriptBaseClass.LINK_THIS (-4).
  295. /// If ScriptBaseClass.LINK_THIS then the entity containing the script is returned.
  296. /// If the linkset has one entity and a linknum of zero is given, then the single entity is returned. If any
  297. /// positive integer is given in this case then null is returned.
  298. /// If the linkset has more than one entity and a linknum greater than zero but equal to or less than the number
  299. /// of entities, then the entity which corresponds to that linknum is returned.
  300. /// Otherwise, if a positive linknum is given which is greater than the number of entities in the linkset, then
  301. /// null is returned.
  302. /// </param>
  303. public ISceneEntity GetLinkEntity(SceneObjectPart part, int linknum)
  304. {
  305. if (linknum < 0)
  306. {
  307. if (linknum == ScriptBaseClass.LINK_THIS)
  308. return part;
  309. else
  310. return null;
  311. }
  312. int actualPrimCount = part.ParentGroup.PrimCount;
  313. List<ScenePresence> sittingAvatars = part.ParentGroup.GetSittingAvatars();
  314. int adjustedPrimCount = actualPrimCount + sittingAvatars.Count;
  315. // Special case for a single prim. In this case the linknum is zero. However, this will not match a single
  316. // prim that has any avatars sat upon it (in which case the root prim is link 1).
  317. if (linknum == 0)
  318. {
  319. if (actualPrimCount == 1 && sittingAvatars.Count == 0)
  320. return part;
  321. return null;
  322. }
  323. // Special case to handle a single prim with sitting avatars. GetLinkPart() would only match zero but
  324. // here we must match 1 (ScriptBaseClass.LINK_ROOT).
  325. else if (linknum == ScriptBaseClass.LINK_ROOT && actualPrimCount == 1)
  326. {
  327. if (sittingAvatars.Count > 0)
  328. return part.ParentGroup.RootPart;
  329. else
  330. return null;
  331. }
  332. else if (linknum <= adjustedPrimCount)
  333. {
  334. if (linknum <= actualPrimCount)
  335. {
  336. return part.ParentGroup.GetLinkNumPart(linknum);
  337. }
  338. else
  339. {
  340. return sittingAvatars[linknum - actualPrimCount - 1];
  341. }
  342. }
  343. else
  344. {
  345. return null;
  346. }
  347. }
  348. public List<SceneObjectPart> GetLinkParts(int linkType)
  349. {
  350. return GetLinkParts(m_host, linkType);
  351. }
  352. public static List<SceneObjectPart> GetLinkParts(SceneObjectPart part, int linkType)
  353. {
  354. List<SceneObjectPart> ret = new List<SceneObjectPart>();
  355. ret.Add(part);
  356. switch (linkType)
  357. {
  358. case ScriptBaseClass.LINK_SET:
  359. return new List<SceneObjectPart>(part.ParentGroup.Parts);
  360. case ScriptBaseClass.LINK_ROOT:
  361. ret = new List<SceneObjectPart>();
  362. ret.Add(part.ParentGroup.RootPart);
  363. return ret;
  364. case ScriptBaseClass.LINK_ALL_OTHERS:
  365. ret = new List<SceneObjectPart>(part.ParentGroup.Parts);
  366. if (ret.Contains(part))
  367. ret.Remove(part);
  368. return ret;
  369. case ScriptBaseClass.LINK_ALL_CHILDREN:
  370. ret = new List<SceneObjectPart>(part.ParentGroup.Parts);
  371. if (ret.Contains(part.ParentGroup.RootPart))
  372. ret.Remove(part.ParentGroup.RootPart);
  373. return ret;
  374. case ScriptBaseClass.LINK_THIS:
  375. return ret;
  376. default:
  377. if (linkType < 0)
  378. return new List<SceneObjectPart>();
  379. SceneObjectPart target = part.ParentGroup.GetLinkNumPart(linkType);
  380. if (target == null)
  381. return new List<SceneObjectPart>();
  382. ret = new List<SceneObjectPart>();
  383. ret.Add(target);
  384. return ret;
  385. }
  386. }
  387. public List<ISceneEntity> GetLinkEntities(int linkType)
  388. {
  389. return GetLinkEntities(m_host, linkType);
  390. }
  391. public List<ISceneEntity> GetLinkEntities(SceneObjectPart part, int linkType)
  392. {
  393. List<ISceneEntity> ret;
  394. switch (linkType)
  395. {
  396. case ScriptBaseClass.LINK_SET:
  397. return new List<ISceneEntity>(part.ParentGroup.Parts);
  398. case ScriptBaseClass.LINK_ROOT:
  399. return new List<ISceneEntity>() { part.ParentGroup.RootPart };
  400. case ScriptBaseClass.LINK_ALL_OTHERS:
  401. ret = new List<ISceneEntity>(part.ParentGroup.Parts);
  402. if (ret.Contains(part))
  403. ret.Remove(part);
  404. return ret;
  405. case ScriptBaseClass.LINK_ALL_CHILDREN:
  406. ret = new List<ISceneEntity>(part.ParentGroup.Parts);
  407. if (ret.Contains(part.ParentGroup.RootPart))
  408. ret.Remove(part.ParentGroup.RootPart);
  409. return ret;
  410. case ScriptBaseClass.LINK_THIS:
  411. return new List<ISceneEntity>() { part };
  412. default:
  413. if (linkType < 0)
  414. return new List<ISceneEntity>();
  415. ISceneEntity target = GetLinkEntity(part, linkType);
  416. if (target == null)
  417. return new List<ISceneEntity>();
  418. return new List<ISceneEntity>() { target };
  419. }
  420. }
  421. //These are the implementations of the various ll-functions used by the LSL scripts.
  422. public LSL_Float llSin(double f)
  423. {
  424. m_host.AddScriptLPS(1);
  425. return (double)Math.Sin(f);
  426. }
  427. public LSL_Float llCos(double f)
  428. {
  429. m_host.AddScriptLPS(1);
  430. return (double)Math.Cos(f);
  431. }
  432. public LSL_Float llTan(double f)
  433. {
  434. m_host.AddScriptLPS(1);
  435. return (double)Math.Tan(f);
  436. }
  437. public LSL_Float llAtan2(double x, double y)
  438. {
  439. m_host.AddScriptLPS(1);
  440. return (double)Math.Atan2(x, y);
  441. }
  442. public LSL_Float llSqrt(double f)
  443. {
  444. m_host.AddScriptLPS(1);
  445. return (double)Math.Sqrt(f);
  446. }
  447. public LSL_Float llPow(double fbase, double fexponent)
  448. {
  449. m_host.AddScriptLPS(1);
  450. return (double)Math.Pow(fbase, fexponent);
  451. }
  452. public LSL_Integer llAbs(int i)
  453. {
  454. // changed to replicate LSL behaviour whereby minimum int value is returned untouched.
  455. m_host.AddScriptLPS(1);
  456. if (i == Int32.MinValue)
  457. return i;
  458. else
  459. return (int)Math.Abs(i);
  460. }
  461. public LSL_Float llFabs(double f)
  462. {
  463. m_host.AddScriptLPS(1);
  464. return (double)Math.Abs(f);
  465. }
  466. public LSL_Float llFrand(double mag)
  467. {
  468. m_host.AddScriptLPS(1);
  469. return Util.RandomClass.NextDouble() * mag;
  470. }
  471. public LSL_Integer llFloor(double f)
  472. {
  473. m_host.AddScriptLPS(1);
  474. return (int)Math.Floor(f);
  475. }
  476. public LSL_Integer llCeil(double f)
  477. {
  478. m_host.AddScriptLPS(1);
  479. return (int)Math.Ceiling(f);
  480. }
  481. // Xantor 01/May/2008 fixed midpointrounding (2.5 becomes 3.0 instead of 2.0, default = ToEven)
  482. public LSL_Integer llRound(double f)
  483. {
  484. m_host.AddScriptLPS(1);
  485. return (int)Math.Round(f, MidpointRounding.AwayFromZero);
  486. }
  487. //This next group are vector operations involving squaring and square root. ckrinke
  488. public LSL_Float llVecMag(LSL_Vector v)
  489. {
  490. m_host.AddScriptLPS(1);
  491. return LSL_Vector.Mag(v);
  492. }
  493. public LSL_Vector llVecNorm(LSL_Vector v)
  494. {
  495. m_host.AddScriptLPS(1);
  496. return LSL_Vector.Norm(v);
  497. }
  498. private double VecDist(LSL_Vector a, LSL_Vector b)
  499. {
  500. double dx = a.x - b.x;
  501. double dy = a.y - b.y;
  502. double dz = a.z - b.z;
  503. return Math.Sqrt(dx * dx + dy * dy + dz * dz);
  504. }
  505. public LSL_Float llVecDist(LSL_Vector a, LSL_Vector b)
  506. {
  507. m_host.AddScriptLPS(1);
  508. return VecDist(a, b);
  509. }
  510. //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
  511. /// <summary>
  512. /// Convert an LSL rotation to a Euler vector.
  513. /// </summary>
  514. /// <remarks>
  515. /// Using algorithm based off http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/quat_2_euler_paper_ver2-1.pdf
  516. /// to avoid issues with singularity and rounding with Y rotation of +/- PI/2
  517. /// </remarks>
  518. /// <param name="r"></param>
  519. /// <returns></returns>
  520. public LSL_Vector llRot2Euler(LSL_Rotation r)
  521. {
  522. m_host.AddScriptLPS(1);
  523. LSL_Vector v = new LSL_Vector(0.0, 0.0, 1.0) * r; // Z axis unit vector unaffected by Z rotation component of r.
  524. double m = LSL_Vector.Mag(v); // Just in case v isn't normalized, need magnitude for Asin() operation later.
  525. if (m == 0.0) return new LSL_Vector();
  526. double x = Math.Atan2(-v.y, v.z);
  527. double sin = v.x / m;
  528. if (sin < -0.999999 || sin > 0.999999) x = 0.0; // Force X rotation to 0 at the singularities.
  529. double y = Math.Asin(sin);
  530. // Rotate X axis unit vector by r and unwind the X and Y rotations leaving only the Z rotation
  531. v = new LSL_Vector(1.0, 0.0, 0.0) * ((r * new LSL_Rotation(Math.Sin(-x / 2.0), 0.0, 0.0, Math.Cos(-x / 2.0))) * new LSL_Rotation(0.0, Math.Sin(-y / 2.0), 0.0, Math.Cos(-y / 2.0)));
  532. double z = Math.Atan2(v.y, v.x);
  533. return new LSL_Vector(x, y, z);
  534. }
  535. /* From wiki:
  536. The Euler angle vector (in radians) is converted to a rotation by doing the rotations around the 3 axes
  537. in Z, Y, X order. So llEuler2Rot(<1.0, 2.0, 3.0> * DEG_TO_RAD) generates a rotation by taking the zero rotation,
  538. a vector pointing along the X axis, first rotating it 3 degrees around the global Z axis, then rotating the resulting
  539. vector 2 degrees around the global Y axis, and finally rotating that 1 degree around the global X axis.
  540. */
  541. /* How we arrived at this llEuler2Rot
  542. *
  543. * Experiment in SL to determine conventions:
  544. * llEuler2Rot(<PI,0,0>)=<1,0,0,0>
  545. * llEuler2Rot(<0,PI,0>)=<0,1,0,0>
  546. * llEuler2Rot(<0,0,PI>)=<0,0,1,0>
  547. *
  548. * Important facts about Quaternions
  549. * - multiplication is non-commutative (a*b != b*a)
  550. * - http://en.wikipedia.org/wiki/Quaternion#Basis_multiplication
  551. *
  552. * Above SL experiment gives (c1,c2,c3,s1,s2,s3 as defined in our llEuler2Rot):
  553. * Qx = c1+i*s1
  554. * Qy = c2+j*s2;
  555. * Qz = c3+k*s3;
  556. *
  557. * Rotations applied in order (from above) Z, Y, X
  558. * Q = (Qz * Qy) * Qx
  559. * ((c1+i*s1)*(c2+j*s2))*(c3+k*s3)
  560. * (c1*c2+i*s1*c2+j*c1*s2+ij*s1*s2)*(c3+k*s3)
  561. * (c1*c2+i*s1*c2+j*c1*s2+k*s1*s2)*(c3+k*s3)
  562. * c1*c2*c3+i*s1*c2*c3+j*c1*s2*c3+k*s1*s2*c3+k*c1*c2*s3+ik*s1*c2*s3+jk*c1*s2*s3+kk*s1*s2*s3
  563. * c1*c2*c3+i*s1*c2*c3+j*c1*s2*c3+k*s1*s2*c3+k*c1*c2*s3 -j*s1*c2*s3 +i*c1*s2*s3 -s1*s2*s3
  564. * regroup: x=i*(s1*c2*c3+c1*s2*s3)
  565. * y=j*(c1*s2*c3-s1*c2*s3)
  566. * z=k*(s1*s2*c3+c1*c2*s3)
  567. * s= c1*c2*c3-s1*s2*s3
  568. *
  569. * This implementation agrees with the functions found here:
  570. * http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions
  571. * And with the results in SL.
  572. *
  573. * It's also possible to calculate llEuler2Rot by direct multiplication of
  574. * the Qz, Qy, and Qx vectors (as above - and done in the "accurate" function
  575. * from the wiki).
  576. * Apparently in some cases this is better from a numerical precision perspective?
  577. */
  578. public LSL_Rotation llEuler2Rot(LSL_Vector v)
  579. {
  580. m_host.AddScriptLPS(1);
  581. double x,y,z,s;
  582. double c1 = Math.Cos(v.x * 0.5);
  583. double c2 = Math.Cos(v.y * 0.5);
  584. double c3 = Math.Cos(v.z * 0.5);
  585. double s1 = Math.Sin(v.x * 0.5);
  586. double s2 = Math.Sin(v.y * 0.5);
  587. double s3 = Math.Sin(v.z * 0.5);
  588. x = s1 * c2 * c3 + c1 * s2 * s3;
  589. y = c1 * s2 * c3 - s1 * c2 * s3;
  590. z = s1 * s2 * c3 + c1 * c2 * s3;
  591. s = c1 * c2 * c3 - s1 * s2 * s3;
  592. return new LSL_Rotation(x, y, z, s);
  593. }
  594. public LSL_Rotation llAxes2Rot(LSL_Vector fwd, LSL_Vector left, LSL_Vector up)
  595. {
  596. m_host.AddScriptLPS(1);
  597. double s;
  598. double tr = fwd.x + left.y + up.z + 1.0;
  599. if (tr >= 1.0)
  600. {
  601. s = 0.5 / Math.Sqrt(tr);
  602. return new LSL_Rotation(
  603. (left.z - up.y) * s,
  604. (up.x - fwd.z) * s,
  605. (fwd.y - left.x) * s,
  606. 0.25 / s);
  607. }
  608. else
  609. {
  610. double max = (left.y > up.z) ? left.y : up.z;
  611. if (max < fwd.x)
  612. {
  613. s = Math.Sqrt(fwd.x - (left.y + up.z) + 1.0);
  614. double x = s * 0.5;
  615. s = 0.5 / s;
  616. return new LSL_Rotation(
  617. x,
  618. (fwd.y + left.x) * s,
  619. (up.x + fwd.z) * s,
  620. (left.z - up.y) * s);
  621. }
  622. else if (max == left.y)
  623. {
  624. s = Math.Sqrt(left.y - (up.z + fwd.x) + 1.0);
  625. double y = s * 0.5;
  626. s = 0.5 / s;
  627. return new LSL_Rotation(
  628. (fwd.y + left.x) * s,
  629. y,
  630. (left.z + up.y) * s,
  631. (up.x - fwd.z) * s);
  632. }
  633. else
  634. {
  635. s = Math.Sqrt(up.z - (fwd.x + left.y) + 1.0);
  636. double z = s * 0.5;
  637. s = 0.5 / s;
  638. return new LSL_Rotation(
  639. (up.x + fwd.z) * s,
  640. (left.z + up.y) * s,
  641. z,
  642. (fwd.y - left.x) * s);
  643. }
  644. }
  645. }
  646. public LSL_Vector llRot2Fwd(LSL_Rotation r)
  647. {
  648. m_host.AddScriptLPS(1);
  649. double x, y, z, m;
  650. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  651. // m is always greater than zero
  652. // if m is not equal to 1 then Rotation needs to be normalized
  653. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  654. {
  655. m = 1.0 / Math.Sqrt(m);
  656. r.x *= m;
  657. r.y *= m;
  658. r.z *= m;
  659. r.s *= m;
  660. }
  661. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  662. x = r.x * r.x - r.y * r.y - r.z * r.z + r.s * r.s;
  663. y = 2 * (r.x * r.y + r.z * r.s);
  664. z = 2 * (r.x * r.z - r.y * r.s);
  665. return (new LSL_Vector(x, y, z));
  666. }
  667. public LSL_Vector llRot2Left(LSL_Rotation r)
  668. {
  669. m_host.AddScriptLPS(1);
  670. double x, y, z, m;
  671. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  672. // m is always greater than zero
  673. // if m is not equal to 1 then Rotation needs to be normalized
  674. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  675. {
  676. m = 1.0 / Math.Sqrt(m);
  677. r.x *= m;
  678. r.y *= m;
  679. r.z *= m;
  680. r.s *= m;
  681. }
  682. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  683. x = 2 * (r.x * r.y - r.z * r.s);
  684. y = -r.x * r.x + r.y * r.y - r.z * r.z + r.s * r.s;
  685. z = 2 * (r.x * r.s + r.y * r.z);
  686. return (new LSL_Vector(x, y, z));
  687. }
  688. public LSL_Vector llRot2Up(LSL_Rotation r)
  689. {
  690. m_host.AddScriptLPS(1);
  691. double x, y, z, m;
  692. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  693. // m is always greater than zero
  694. // if m is not equal to 1 then Rotation needs to be normalized
  695. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  696. {
  697. m = 1.0 / Math.Sqrt(m);
  698. r.x *= m;
  699. r.y *= m;
  700. r.z *= m;
  701. r.s *= m;
  702. }
  703. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  704. x = 2 * (r.x * r.z + r.y * r.s);
  705. y = 2 * (-r.x * r.s + r.y * r.z);
  706. z = -r.x * r.x - r.y * r.y + r.z * r.z + r.s * r.s;
  707. return (new LSL_Vector(x, y, z));
  708. }
  709. public LSL_Rotation llRotBetween(LSL_Vector a, LSL_Vector b)
  710. {
  711. //A and B should both be normalized
  712. m_host.AddScriptLPS(1);
  713. LSL_Rotation rotBetween;
  714. // Check for zero vectors. If either is zero, return zero rotation. Otherwise,
  715. // continue calculation.
  716. if (a == new LSL_Vector(0.0f, 0.0f, 0.0f) || b == new LSL_Vector(0.0f, 0.0f, 0.0f))
  717. {
  718. rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  719. }
  720. else
  721. {
  722. a = LSL_Vector.Norm(a);
  723. b = LSL_Vector.Norm(b);
  724. double dotProduct = LSL_Vector.Dot(a, b);
  725. // There are two degenerate cases possible. These are for vectors 180 or
  726. // 0 degrees apart. These have to be detected and handled individually.
  727. //
  728. // Check for vectors 180 degrees apart.
  729. // A dot product of -1 would mean the angle between vectors is 180 degrees.
  730. if (dotProduct < -0.9999999f)
  731. {
  732. // First assume X axis is orthogonal to the vectors.
  733. LSL_Vector orthoVector = new LSL_Vector(1.0f, 0.0f, 0.0f);
  734. orthoVector = orthoVector - a * (a.x / LSL_Vector.Dot(a, a));
  735. // Check for near zero vector. A very small non-zero number here will create
  736. // a rotation in an undesired direction.
  737. if (LSL_Vector.Mag(orthoVector) > 0.0001)
  738. {
  739. rotBetween = new LSL_Rotation(orthoVector.x, orthoVector.y, orthoVector.z, 0.0f);
  740. }
  741. // If the magnitude of the vector was near zero, then assume the X axis is not
  742. // orthogonal and use the Z axis instead.
  743. else
  744. {
  745. // Set 180 z rotation.
  746. rotBetween = new LSL_Rotation(0.0f, 0.0f, 1.0f, 0.0f);
  747. }
  748. }
  749. // Check for parallel vectors.
  750. // A dot product of 1 would mean the angle between vectors is 0 degrees.
  751. else if (dotProduct > 0.9999999f)
  752. {
  753. // Set zero rotation.
  754. rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  755. }
  756. else
  757. {
  758. // All special checks have been performed so get the axis of rotation.
  759. LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
  760. // Quarternion s value is the length of the unit vector + dot product.
  761. double qs = 1.0 + dotProduct;
  762. rotBetween = new LSL_Rotation(crossProduct.x, crossProduct.y, crossProduct.z, qs);
  763. // Normalize the rotation.
  764. double mag = LSL_Rotation.Mag(rotBetween);
  765. // We shouldn't have to worry about a divide by zero here. The qs value will be
  766. // non-zero because we already know if we're here, then the dotProduct is not -1 so
  767. // qs will not be zero. Also, we've already handled the input vectors being zero so the
  768. // crossProduct vector should also not be zero.
  769. rotBetween.x = rotBetween.x / mag;
  770. rotBetween.y = rotBetween.y / mag;
  771. rotBetween.z = rotBetween.z / mag;
  772. rotBetween.s = rotBetween.s / mag;
  773. // Check for undefined values and set zero rotation if any found. This code might not actually be required
  774. // any longer since zero vectors are checked for at the top.
  775. if (Double.IsNaN(rotBetween.x) || Double.IsNaN(rotBetween.y) || Double.IsNaN(rotBetween.z) || Double.IsNaN(rotBetween.s))
  776. {
  777. rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  778. }
  779. }
  780. }
  781. return rotBetween;
  782. }
  783. public void llWhisper(int channelID, string text)
  784. {
  785. m_host.AddScriptLPS(1);
  786. if (text.Length > 1023)
  787. text = text.Substring(0, 1023);
  788. World.SimChat(Utils.StringToBytes(text),
  789. ChatTypeEnum.Whisper, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  790. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  791. if (wComm != null)
  792. wComm.DeliverMessage(ChatTypeEnum.Whisper, channelID, m_host.Name, m_host.UUID, text);
  793. }
  794. public void llSay(int channelID, string text)
  795. {
  796. m_host.AddScriptLPS(1);
  797. if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel))
  798. {
  799. Console.WriteLine(text);
  800. }
  801. else
  802. {
  803. if (text.Length > 1023)
  804. text = text.Substring(0, 1023);
  805. World.SimChat(Utils.StringToBytes(text),
  806. ChatTypeEnum.Say, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  807. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  808. if (wComm != null)
  809. wComm.DeliverMessage(ChatTypeEnum.Say, channelID, m_host.Name, m_host.UUID, text);
  810. }
  811. }
  812. public void llShout(int channelID, string text)
  813. {
  814. m_host.AddScriptLPS(1);
  815. if (text.Length > 1023)
  816. text = text.Substring(0, 1023);
  817. World.SimChat(Utils.StringToBytes(text),
  818. ChatTypeEnum.Shout, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  819. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  820. if (wComm != null)
  821. wComm.DeliverMessage(ChatTypeEnum.Shout, channelID, m_host.Name, m_host.UUID, text);
  822. }
  823. public void llRegionSay(int channelID, string text)
  824. {
  825. if (channelID == 0)
  826. {
  827. Error("llRegionSay", "Cannot use on channel 0");
  828. return;
  829. }
  830. if (text.Length > 1023)
  831. text = text.Substring(0, 1023);
  832. m_host.AddScriptLPS(1);
  833. World.SimChat(Utils.StringToBytes(text),
  834. ChatTypeEnum.Region, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  835. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  836. if (wComm != null)
  837. wComm.DeliverMessage(ChatTypeEnum.Region, channelID, m_host.Name, m_host.UUID, text);
  838. }
  839. public void llRegionSayTo(string target, int channel, string msg)
  840. {
  841. if (msg.Length > 1023)
  842. msg = msg.Substring(0, 1023);
  843. m_host.AddScriptLPS(1);
  844. if (channel == ScriptBaseClass.DEBUG_CHANNEL)
  845. {
  846. return;
  847. }
  848. UUID TargetID;
  849. UUID.TryParse(target, out TargetID);
  850. World.SimChatToAgent(TargetID, Utils.StringToBytes(msg),
  851. channel, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  852. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  853. if (wComm != null)
  854. wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg);
  855. }
  856. public LSL_Integer llListen(int channelID, string name, string ID, string msg)
  857. {
  858. m_host.AddScriptLPS(1);
  859. UUID keyID;
  860. UUID.TryParse(ID, out keyID);
  861. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  862. if (wComm != null)
  863. return wComm.Listen(m_host.LocalId, m_item.ItemID, m_host.UUID, channelID, name, keyID, msg);
  864. else
  865. return -1;
  866. }
  867. public void llListenControl(int number, int active)
  868. {
  869. m_host.AddScriptLPS(1);
  870. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  871. if (wComm != null)
  872. wComm.ListenControl(m_item.ItemID, number, active);
  873. }
  874. public void llListenRemove(int number)
  875. {
  876. m_host.AddScriptLPS(1);
  877. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  878. if (wComm != null)
  879. wComm.ListenRemove(m_item.ItemID, number);
  880. }
  881. public void llSensor(string name, string id, int type, double range, double arc)
  882. {
  883. m_host.AddScriptLPS(1);
  884. UUID keyID = UUID.Zero;
  885. UUID.TryParse(id, out keyID);
  886. AsyncCommands.SensorRepeatPlugin.SenseOnce(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, m_host);
  887. }
  888. public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
  889. {
  890. m_host.AddScriptLPS(1);
  891. UUID keyID = UUID.Zero;
  892. UUID.TryParse(id, out keyID);
  893. AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, rate, m_host);
  894. }
  895. public void llSensorRemove()
  896. {
  897. m_host.AddScriptLPS(1);
  898. AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_host.LocalId, m_item.ItemID);
  899. }
  900. public string resolveName(UUID objecUUID)
  901. {
  902. // try avatar username surname
  903. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, objecUUID);
  904. if (account != null)
  905. {
  906. string avatarname = account.Name;
  907. return avatarname;
  908. }
  909. // try an scene object
  910. SceneObjectPart SOP = World.GetSceneObjectPart(objecUUID);
  911. if (SOP != null)
  912. {
  913. string objectname = SOP.Name;
  914. return objectname;
  915. }
  916. EntityBase SensedObject;
  917. World.Entities.TryGetValue(objecUUID, out SensedObject);
  918. if (SensedObject == null)
  919. {
  920. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  921. if (groups != null)
  922. {
  923. GroupRecord gr = groups.GetGroupRecord(objecUUID);
  924. if (gr != null)
  925. return gr.GroupName;
  926. }
  927. return String.Empty;
  928. }
  929. return SensedObject.Name;
  930. }
  931. public LSL_String llDetectedName(int number)
  932. {
  933. m_host.AddScriptLPS(1);
  934. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  935. if (detectedParams == null)
  936. return String.Empty;
  937. return detectedParams.Name;
  938. }
  939. public LSL_String llDetectedKey(int number)
  940. {
  941. m_host.AddScriptLPS(1);
  942. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  943. if (detectedParams == null)
  944. return String.Empty;
  945. return detectedParams.Key.ToString();
  946. }
  947. public LSL_String llDetectedOwner(int number)
  948. {
  949. m_host.AddScriptLPS(1);
  950. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  951. if (detectedParams == null)
  952. return String.Empty;
  953. return detectedParams.Owner.ToString();
  954. }
  955. public LSL_Integer llDetectedType(int number)
  956. {
  957. m_host.AddScriptLPS(1);
  958. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  959. if (detectedParams == null)
  960. return 0;
  961. return new LSL_Integer(detectedParams.Type);
  962. }
  963. public LSL_Vector llDetectedPos(int number)
  964. {
  965. m_host.AddScriptLPS(1);
  966. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  967. if (detectedParams == null)
  968. return new LSL_Vector();
  969. return detectedParams.Position;
  970. }
  971. public LSL_Vector llDetectedVel(int number)
  972. {
  973. m_host.AddScriptLPS(1);
  974. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  975. if (detectedParams == null)
  976. return new LSL_Vector();
  977. return detectedParams.Velocity;
  978. }
  979. public LSL_Vector llDetectedGrab(int number)
  980. {
  981. m_host.AddScriptLPS(1);
  982. DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  983. if (parms == null)
  984. return new LSL_Vector(0, 0, 0);
  985. return parms.OffsetPos;
  986. }
  987. public LSL_Rotation llDetectedRot(int number)
  988. {
  989. m_host.AddScriptLPS(1);
  990. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  991. if (detectedParams == null)
  992. return new LSL_Rotation();
  993. return detectedParams.Rotation;
  994. }
  995. public LSL_Integer llDetectedGroup(int number)
  996. {
  997. m_host.AddScriptLPS(1);
  998. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  999. if (detectedParams == null)
  1000. return new LSL_Integer(0);
  1001. if (m_host.GroupID == detectedParams.Group)
  1002. return new LSL_Integer(1);
  1003. return new LSL_Integer(0);
  1004. }
  1005. public LSL_Integer llDetectedLinkNumber(int number)
  1006. {
  1007. m_host.AddScriptLPS(1);
  1008. DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1009. if (parms == null)
  1010. return new LSL_Integer(0);
  1011. return new LSL_Integer(parms.LinkNum);
  1012. }
  1013. /// <summary>
  1014. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchBinormal for details
  1015. /// </summary>
  1016. public LSL_Vector llDetectedTouchBinormal(int index)
  1017. {
  1018. m_host.AddScriptLPS(1);
  1019. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1020. if (detectedParams == null)
  1021. return new LSL_Vector();
  1022. return detectedParams.TouchBinormal;
  1023. }
  1024. /// <summary>
  1025. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchFace for details
  1026. /// </summary>
  1027. public LSL_Integer llDetectedTouchFace(int index)
  1028. {
  1029. m_host.AddScriptLPS(1);
  1030. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1031. if (detectedParams == null)
  1032. return new LSL_Integer(-1);
  1033. return new LSL_Integer(detectedParams.TouchFace);
  1034. }
  1035. /// <summary>
  1036. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchNormal for details
  1037. /// </summary>
  1038. public LSL_Vector llDetectedTouchNormal(int index)
  1039. {
  1040. m_host.AddScriptLPS(1);
  1041. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1042. if (detectedParams == null)
  1043. return new LSL_Vector();
  1044. return detectedParams.TouchNormal;
  1045. }
  1046. /// <summary>
  1047. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchPos for details
  1048. /// </summary>
  1049. public LSL_Vector llDetectedTouchPos(int index)
  1050. {
  1051. m_host.AddScriptLPS(1);
  1052. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1053. if (detectedParams == null)
  1054. return new LSL_Vector();
  1055. return detectedParams.TouchPos;
  1056. }
  1057. /// <summary>
  1058. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchST for details
  1059. /// </summary>
  1060. public LSL_Vector llDetectedTouchST(int index)
  1061. {
  1062. m_host.AddScriptLPS(1);
  1063. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1064. if (detectedParams == null)
  1065. return new LSL_Vector(-1.0, -1.0, 0.0);
  1066. return detectedParams.TouchST;
  1067. }
  1068. /// <summary>
  1069. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchUV for details
  1070. /// </summary>
  1071. public LSL_Vector llDetectedTouchUV(int index)
  1072. {
  1073. m_host.AddScriptLPS(1);
  1074. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1075. if (detectedParams == null)
  1076. return new LSL_Vector(-1.0, -1.0, 0.0);
  1077. return detectedParams.TouchUV;
  1078. }
  1079. public virtual void llDie()
  1080. {
  1081. m_host.AddScriptLPS(1);
  1082. throw new SelfDeleteException();
  1083. }
  1084. public LSL_Float llGround(LSL_Vector offset)
  1085. {
  1086. m_host.AddScriptLPS(1);
  1087. Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
  1088. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  1089. LSL_Vector vsn = llGroundNormal(offset);
  1090. // Clamp to valid position
  1091. if (pos.X < 0)
  1092. pos.X = 0;
  1093. else if (pos.X >= World.Heightmap.Width)
  1094. pos.X = World.Heightmap.Width - 1;
  1095. if (pos.Y < 0)
  1096. pos.Y = 0;
  1097. else if (pos.Y >= World.Heightmap.Height)
  1098. pos.Y = World.Heightmap.Height - 1;
  1099. //Get the height for the integer coordinates from the Heightmap
  1100. float baseheight = (float)World.Heightmap[(int)pos.X, (int)pos.Y];
  1101. //Calculate the difference between the actual coordinates and the integer coordinates
  1102. float xdiff = pos.X - (float)((int)pos.X);
  1103. float ydiff = pos.Y - (float)((int)pos.Y);
  1104. //Use the equation of the tangent plane to adjust the height to account for slope
  1105. return (((vsn.x * xdiff) + (vsn.y * ydiff)) / (-1 * vsn.z)) + baseheight;
  1106. }
  1107. public LSL_Float llCloud(LSL_Vector offset)
  1108. {
  1109. m_host.AddScriptLPS(1);
  1110. float cloudCover = 0f;
  1111. ICloudModule module = World.RequestModuleInterface<ICloudModule>();
  1112. if (module != null)
  1113. {
  1114. Vector3 pos = m_host.GetWorldPosition();
  1115. int x = (int)(pos.X + offset.x);
  1116. int y = (int)(pos.Y + offset.y);
  1117. cloudCover = module.CloudCover(x, y, 0);
  1118. }
  1119. return cloudCover;
  1120. }
  1121. public LSL_Vector llWind(LSL_Vector offset)
  1122. {
  1123. m_host.AddScriptLPS(1);
  1124. LSL_Vector wind = new LSL_Vector(0, 0, 0);
  1125. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1126. if (module != null)
  1127. {
  1128. Vector3 pos = m_host.GetWorldPosition();
  1129. int x = (int)(pos.X + offset.x);
  1130. int y = (int)(pos.Y + offset.y);
  1131. Vector3 windSpeed = module.WindSpeed(x, y, 0);
  1132. wind.x = windSpeed.X;
  1133. wind.y = windSpeed.Y;
  1134. }
  1135. return wind;
  1136. }
  1137. public void llSetStatus(int status, int value)
  1138. {
  1139. m_host.AddScriptLPS(1);
  1140. int statusrotationaxis = 0;
  1141. if ((status & ScriptBaseClass.STATUS_PHYSICS) == ScriptBaseClass.STATUS_PHYSICS)
  1142. {
  1143. if (value != 0)
  1144. {
  1145. SceneObjectGroup group = m_host.ParentGroup;
  1146. bool allow = true;
  1147. foreach (SceneObjectPart part in group.Parts)
  1148. {
  1149. if (part.Scale.X > World.m_maxPhys || part.Scale.Y > World.m_maxPhys || part.Scale.Z > World.m_maxPhys)
  1150. {
  1151. allow = false;
  1152. break;
  1153. }
  1154. }
  1155. if (!allow)
  1156. return;
  1157. m_host.ScriptSetPhysicsStatus(true);
  1158. }
  1159. else
  1160. {
  1161. m_host.ScriptSetPhysicsStatus(false);
  1162. }
  1163. }
  1164. if ((status & ScriptBaseClass.STATUS_PHANTOM) == ScriptBaseClass.STATUS_PHANTOM)
  1165. {
  1166. m_host.ParentGroup.ScriptSetPhantomStatus(value != 0);
  1167. }
  1168. if ((status & ScriptBaseClass.STATUS_CAST_SHADOWS) == ScriptBaseClass.STATUS_CAST_SHADOWS)
  1169. {
  1170. m_host.AddFlag(PrimFlags.CastShadows);
  1171. }
  1172. if ((status & ScriptBaseClass.STATUS_ROTATE_X) == ScriptBaseClass.STATUS_ROTATE_X)
  1173. {
  1174. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_X;
  1175. }
  1176. if ((status & ScriptBaseClass.STATUS_ROTATE_Y) == ScriptBaseClass.STATUS_ROTATE_Y)
  1177. {
  1178. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Y;
  1179. }
  1180. if ((status & ScriptBaseClass.STATUS_ROTATE_Z) == ScriptBaseClass.STATUS_ROTATE_Z)
  1181. {
  1182. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Z;
  1183. }
  1184. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB) == ScriptBaseClass.STATUS_BLOCK_GRAB)
  1185. m_host.BlockGrab = value != 0;
  1186. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT) == ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT)
  1187. m_host.ParentGroup.BlockGrabOverride = value != 0;
  1188. if ((status & ScriptBaseClass.STATUS_DIE_AT_EDGE) == ScriptBaseClass.STATUS_DIE_AT_EDGE)
  1189. {
  1190. if (value != 0)
  1191. m_host.SetDieAtEdge(true);
  1192. else
  1193. m_host.SetDieAtEdge(false);
  1194. }
  1195. if ((status & ScriptBaseClass.STATUS_RETURN_AT_EDGE) == ScriptBaseClass.STATUS_RETURN_AT_EDGE)
  1196. {
  1197. if (value != 0)
  1198. m_host.SetReturnAtEdge(true);
  1199. else
  1200. m_host.SetReturnAtEdge(false);
  1201. }
  1202. if ((status & ScriptBaseClass.STATUS_SANDBOX) == ScriptBaseClass.STATUS_SANDBOX)
  1203. {
  1204. if (value != 0)
  1205. m_host.SetStatusSandbox(true);
  1206. else
  1207. m_host.SetStatusSandbox(false);
  1208. }
  1209. if (statusrotationaxis != 0)
  1210. {
  1211. m_host.SetAxisRotation(statusrotationaxis, value);
  1212. }
  1213. }
  1214. private bool IsPhysical()
  1215. {
  1216. return ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) == (uint)PrimFlags.Physics);
  1217. }
  1218. public LSL_Integer llGetStatus(int status)
  1219. {
  1220. m_host.AddScriptLPS(1);
  1221. // m_log.Debug(m_host.ToString() + " status is " + m_host.GetEffectiveObjectFlags().ToString());
  1222. switch (status)
  1223. {
  1224. case ScriptBaseClass.STATUS_PHYSICS:
  1225. return IsPhysical() ? 1 : 0;
  1226. case ScriptBaseClass.STATUS_PHANTOM:
  1227. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) == (uint)PrimFlags.Phantom)
  1228. {
  1229. return 1;
  1230. }
  1231. return 0;
  1232. case ScriptBaseClass.STATUS_CAST_SHADOWS:
  1233. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.CastShadows) == (uint)PrimFlags.CastShadows)
  1234. {
  1235. return 1;
  1236. }
  1237. return 0;
  1238. case ScriptBaseClass.STATUS_BLOCK_GRAB:
  1239. return m_host.BlockGrab ? 1 : 0;
  1240. case ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT:
  1241. return m_host.ParentGroup.BlockGrabOverride ? 1 : 0;
  1242. case ScriptBaseClass.STATUS_DIE_AT_EDGE:
  1243. if (m_host.GetDieAtEdge())
  1244. return 1;
  1245. else
  1246. return 0;
  1247. case ScriptBaseClass.STATUS_RETURN_AT_EDGE:
  1248. if (m_host.GetReturnAtEdge())
  1249. return 1;
  1250. else
  1251. return 0;
  1252. case ScriptBaseClass.STATUS_ROTATE_X:
  1253. // if (m_host.GetAxisRotation(2) != 0)
  1254. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) != 0)
  1255. return 1;
  1256. else
  1257. return 0;
  1258. case ScriptBaseClass.STATUS_ROTATE_Y:
  1259. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) != 0)
  1260. return 1;
  1261. else
  1262. return 0;
  1263. case ScriptBaseClass.STATUS_ROTATE_Z:
  1264. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) != 0)
  1265. return 1;
  1266. else
  1267. return 0;
  1268. case ScriptBaseClass.STATUS_SANDBOX:
  1269. if (m_host.GetStatusSandbox())
  1270. return 1;
  1271. else
  1272. return 0;
  1273. }
  1274. return 0;
  1275. }
  1276. public void llSetScale(LSL_Vector scale)
  1277. {
  1278. m_host.AddScriptLPS(1);
  1279. SetScale(m_host, scale);
  1280. }
  1281. protected void SetScale(SceneObjectPart part, LSL_Vector scale)
  1282. {
  1283. // TODO: this needs to trigger a persistance save as well
  1284. if (part == null || part.ParentGroup.IsDeleted)
  1285. return;
  1286. // First we need to check whether or not we need to clamp the size of a physics-enabled prim
  1287. PhysicsActor pa = part.ParentGroup.RootPart.PhysActor;
  1288. if (pa != null && pa.IsPhysical)
  1289. {
  1290. scale.x = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.x));
  1291. scale.y = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.y));
  1292. scale.z = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.z));
  1293. }
  1294. else
  1295. {
  1296. // If not physical, then we clamp the scale to the non-physical min/max
  1297. scale.x = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.x));
  1298. scale.y = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.y));
  1299. scale.z = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.z));
  1300. }
  1301. Vector3 tmp = part.Scale;
  1302. tmp.X = (float)scale.x;
  1303. tmp.Y = (float)scale.y;
  1304. tmp.Z = (float)scale.z;
  1305. part.Scale = tmp;
  1306. part.SendFullUpdateToAllClients();
  1307. }
  1308. public LSL_Vector llGetScale()
  1309. {
  1310. m_host.AddScriptLPS(1);
  1311. return new LSL_Vector(m_host.Scale.X, m_host.Scale.Y, m_host.Scale.Z);
  1312. }
  1313. public void llSetClickAction(int action)
  1314. {
  1315. m_host.AddScriptLPS(1);
  1316. m_host.ClickAction = (byte)action;
  1317. m_host.ParentGroup.HasGroupChanged = true;
  1318. m_host.ScheduleFullUpdate();
  1319. return;
  1320. }
  1321. public void llSetColor(LSL_Vector color, int face)
  1322. {
  1323. m_host.AddScriptLPS(1);
  1324. if (face == ScriptBaseClass.ALL_SIDES)
  1325. face = SceneObjectPart.ALL_SIDES;
  1326. m_host.SetFaceColorAlpha(face, color, null);
  1327. }
  1328. public void llSetContentType(LSL_Key id, LSL_Integer type)
  1329. {
  1330. m_host.AddScriptLPS(1);
  1331. if (m_UrlModule == null)
  1332. return;
  1333. // Make sure the content type is text/plain to start with
  1334. m_UrlModule.HttpContentType(new UUID(id), "text/plain");
  1335. // Is the object owner online and in the region
  1336. ScenePresence agent = World.GetScenePresence(m_host.ParentGroup.OwnerID);
  1337. if (agent == null || agent.IsChildAgent)
  1338. return; // Fail if the owner is not in the same region
  1339. // Is it the embeded browser?
  1340. string userAgent = m_UrlModule.GetHttpHeader(new UUID(id), "user-agent");
  1341. if (userAgent.IndexOf("SecondLife") < 0)
  1342. return; // Not the embedded browser. Is this check good enough?
  1343. // Use the IP address of the client and check against the request
  1344. // seperate logins from the same IP will allow all of them to get non-text/plain as long
  1345. // as the owner is in the region. Same as SL!
  1346. string logonFromIPAddress = agent.ControllingClient.RemoteEndPoint.Address.ToString();
  1347. string requestFromIPAddress = m_UrlModule.GetHttpHeader(new UUID(id), "remote_addr");
  1348. //m_log.Debug("IP from header='" + requestFromIPAddress + "' IP from endpoint='" + logonFromIPAddress + "'");
  1349. if (requestFromIPAddress == null || requestFromIPAddress.Trim() == "")
  1350. return;
  1351. if (logonFromIPAddress == null || logonFromIPAddress.Trim() == "")
  1352. return;
  1353. // If the request isnt from the same IP address then the request cannot be from the owner
  1354. if (!requestFromIPAddress.Trim().Equals(logonFromIPAddress.Trim()))
  1355. return;
  1356. switch (type)
  1357. {
  1358. case ScriptBaseClass.CONTENT_TYPE_HTML:
  1359. m_UrlModule.HttpContentType(new UUID(id), "text/html");
  1360. break;
  1361. case ScriptBaseClass.CONTENT_TYPE_XML:
  1362. m_UrlModule.HttpContentType(new UUID(id), "application/xml");
  1363. break;
  1364. case ScriptBaseClass.CONTENT_TYPE_XHTML:
  1365. m_UrlModule.HttpContentType(new UUID(id), "application/xhtml+xml");
  1366. break;
  1367. case ScriptBaseClass.CONTENT_TYPE_ATOM:
  1368. m_UrlModule.HttpContentType(new UUID(id), "application/atom+xml");
  1369. break;
  1370. case ScriptBaseClass.CONTENT_TYPE_JSON:
  1371. m_UrlModule.HttpContentType(new UUID(id), "application/json");
  1372. break;
  1373. case ScriptBaseClass.CONTENT_TYPE_LLSD:
  1374. m_UrlModule.HttpContentType(new UUID(id), "application/llsd+xml");
  1375. break;
  1376. case ScriptBaseClass.CONTENT_TYPE_FORM:
  1377. m_UrlModule.HttpContentType(new UUID(id), "application/x-www-form-urlencoded");
  1378. break;
  1379. case ScriptBaseClass.CONTENT_TYPE_RSS:
  1380. m_UrlModule.HttpContentType(new UUID(id), "application/rss+xml");
  1381. break;
  1382. default:
  1383. m_UrlModule.HttpContentType(new UUID(id), "text/plain");
  1384. break;
  1385. }
  1386. }
  1387. public void SetTexGen(SceneObjectPart part, int face,int style)
  1388. {
  1389. Primitive.TextureEntry tex = part.Shape.Textures;
  1390. MappingType textype;
  1391. textype = MappingType.Default;
  1392. if (style == (int)ScriptBaseClass.PRIM_TEXGEN_PLANAR)
  1393. textype = MappingType.Planar;
  1394. if (face >= 0 && face < GetNumberOfSides(part))
  1395. {
  1396. tex.CreateFace((uint) face);
  1397. tex.FaceTextures[face].TexMapType = textype;
  1398. part.UpdateTextureEntry(tex.GetBytes());
  1399. return;
  1400. }
  1401. else if (face == ScriptBaseClass.ALL_SIDES)
  1402. {
  1403. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1404. {
  1405. if (tex.FaceTextures[i] != null)
  1406. {
  1407. tex.FaceTextures[i].TexMapType = textype;
  1408. }
  1409. tex.DefaultTexture.TexMapType = textype;
  1410. }
  1411. part.UpdateTextureEntry(tex.GetBytes());
  1412. return;
  1413. }
  1414. }
  1415. public void SetGlow(SceneObjectPart part, int face, float glow)
  1416. {
  1417. Primitive.TextureEntry tex = part.Shape.Textures;
  1418. if (face >= 0 && face < GetNumberOfSides(part))
  1419. {
  1420. tex.CreateFace((uint) face);
  1421. tex.FaceTextures[face].Glow = glow;
  1422. part.UpdateTextureEntry(tex.GetBytes());
  1423. return;
  1424. }
  1425. else if (face == ScriptBaseClass.ALL_SIDES)
  1426. {
  1427. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1428. {
  1429. if (tex.FaceTextures[i] != null)
  1430. {
  1431. tex.FaceTextures[i].Glow = glow;
  1432. }
  1433. tex.DefaultTexture.Glow = glow;
  1434. }
  1435. part.UpdateTextureEntry(tex.GetBytes());
  1436. return;
  1437. }
  1438. }
  1439. public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump)
  1440. {
  1441. Shininess sval = new Shininess();
  1442. switch (shiny)
  1443. {
  1444. case 0:
  1445. sval = Shininess.None;
  1446. break;
  1447. case 1:
  1448. sval = Shininess.Low;
  1449. break;
  1450. case 2:
  1451. sval = Shininess.Medium;
  1452. break;
  1453. case 3:
  1454. sval = Shininess.High;
  1455. break;
  1456. default:
  1457. sval = Shininess.None;
  1458. break;
  1459. }
  1460. Primitive.TextureEntry tex = part.Shape.Textures;
  1461. if (face >= 0 && face < GetNumberOfSides(part))
  1462. {
  1463. tex.CreateFace((uint) face);
  1464. tex.FaceTextures[face].Shiny = sval;
  1465. tex.FaceTextures[face].Bump = bump;
  1466. part.UpdateTextureEntry(tex.GetBytes());
  1467. return;
  1468. }
  1469. else if (face == ScriptBaseClass.ALL_SIDES)
  1470. {
  1471. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1472. {
  1473. if (tex.FaceTextures[i] != null)
  1474. {
  1475. tex.FaceTextures[i].Shiny = sval;
  1476. tex.FaceTextures[i].Bump = bump;
  1477. }
  1478. tex.DefaultTexture.Shiny = sval;
  1479. tex.DefaultTexture.Bump = bump;
  1480. }
  1481. part.UpdateTextureEntry(tex.GetBytes());
  1482. return;
  1483. }
  1484. }
  1485. public void SetFullBright(SceneObjectPart part, int face, bool bright)
  1486. {
  1487. Primitive.TextureEntry tex = part.Shape.Textures;
  1488. if (face >= 0 && face < GetNumberOfSides(part))
  1489. {
  1490. tex.CreateFace((uint) face);
  1491. tex.FaceTextures[face].Fullbright = bright;
  1492. part.UpdateTextureEntry(tex.GetBytes());
  1493. return;
  1494. }
  1495. else if (face == ScriptBaseClass.ALL_SIDES)
  1496. {
  1497. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1498. {
  1499. if (tex.FaceTextures[i] != null)
  1500. {
  1501. tex.FaceTextures[i].Fullbright = bright;
  1502. }
  1503. }
  1504. tex.DefaultTexture.Fullbright = bright;
  1505. part.UpdateTextureEntry(tex.GetBytes());
  1506. return;
  1507. }
  1508. }
  1509. public LSL_Float llGetAlpha(int face)
  1510. {
  1511. m_host.AddScriptLPS(1);
  1512. return GetAlpha(m_host, face);
  1513. }
  1514. protected LSL_Float GetAlpha(SceneObjectPart part, int face)
  1515. {
  1516. Primitive.TextureEntry tex = part.Shape.Textures;
  1517. if (face == ScriptBaseClass.ALL_SIDES)
  1518. {
  1519. int i;
  1520. double sum = 0.0;
  1521. for (i = 0 ; i < GetNumberOfSides(part); i++)
  1522. sum += (double)tex.GetFace((uint)i).RGBA.A;
  1523. return sum;
  1524. }
  1525. if (face >= 0 && face < GetNumberOfSides(part))
  1526. {
  1527. return (double)tex.GetFace((uint)face).RGBA.A;
  1528. }
  1529. return 0.0;
  1530. }
  1531. public void llSetAlpha(double alpha, int face)
  1532. {
  1533. m_host.AddScriptLPS(1);
  1534. SetAlpha(m_host, alpha, face);
  1535. }
  1536. public void llSetLinkAlpha(int linknumber, double alpha, int face)
  1537. {
  1538. m_host.AddScriptLPS(1);
  1539. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  1540. foreach (SceneObjectPart part in parts)
  1541. SetAlpha(part, alpha, face);
  1542. }
  1543. protected void SetAlpha(SceneObjectPart part, double alpha, int face)
  1544. {
  1545. Primitive.TextureEntry tex = part.Shape.Textures;
  1546. Color4 texcolor;
  1547. if (face >= 0 && face < GetNumberOfSides(part))
  1548. {
  1549. texcolor = tex.CreateFace((uint)face).RGBA;
  1550. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1551. tex.FaceTextures[face].RGBA = texcolor;
  1552. part.UpdateTextureEntry(tex.GetBytes());
  1553. return;
  1554. }
  1555. else if (face == ScriptBaseClass.ALL_SIDES)
  1556. {
  1557. for (int i = 0; i < GetNumberOfSides(part); i++)
  1558. {
  1559. if (tex.FaceTextures[i] != null)
  1560. {
  1561. texcolor = tex.FaceTextures[i].RGBA;
  1562. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1563. tex.FaceTextures[i].RGBA = texcolor;
  1564. }
  1565. }
  1566. // In some cases, the default texture can be null, eg when every face
  1567. // has a unique texture
  1568. if (tex.DefaultTexture != null)
  1569. {
  1570. texcolor = tex.DefaultTexture.RGBA;
  1571. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1572. tex.DefaultTexture.RGBA = texcolor;
  1573. }
  1574. part.UpdateTextureEntry(tex.GetBytes());
  1575. return;
  1576. }
  1577. }
  1578. /// <summary>
  1579. /// Set flexi parameters of a part.
  1580. ///
  1581. /// FIXME: Much of this code should probably be within the part itself.
  1582. /// </summary>
  1583. /// <param name="part"></param>
  1584. /// <param name="flexi"></param>
  1585. /// <param name="softness"></param>
  1586. /// <param name="gravity"></param>
  1587. /// <param name="friction"></param>
  1588. /// <param name="wind"></param>
  1589. /// <param name="tension"></param>
  1590. /// <param name="Force"></param>
  1591. protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
  1592. float wind, float tension, LSL_Vector Force)
  1593. {
  1594. if (part == null)
  1595. return;
  1596. if (flexi)
  1597. {
  1598. part.Shape.FlexiEntry = true; // this setting flexi true isn't working, but the below parameters do
  1599. // work once the prim is already flexi
  1600. part.Shape.FlexiSoftness = softness;
  1601. part.Shape.FlexiGravity = gravity;
  1602. part.Shape.FlexiDrag = friction;
  1603. part.Shape.FlexiWind = wind;
  1604. part.Shape.FlexiTension = tension;
  1605. part.Shape.FlexiForceX = (float)Force.x;
  1606. part.Shape.FlexiForceY = (float)Force.y;
  1607. part.Shape.FlexiForceZ = (float)Force.z;
  1608. part.Shape.PathCurve = (byte)Extrusion.Flexible;
  1609. }
  1610. else
  1611. {
  1612. // Other values not set, they do not seem to be sent to the viewer
  1613. // Setting PathCurve appears to be what actually toggles the check box and turns Flexi on and off
  1614. part.Shape.PathCurve = (byte)Extrusion.Straight;
  1615. part.Shape.FlexiEntry = false;
  1616. }
  1617. part.ParentGroup.HasGroupChanged = true;
  1618. part.ScheduleFullUpdate();
  1619. }
  1620. /// <summary>
  1621. /// Set a light point on a part
  1622. /// </summary>
  1623. /// FIXME: Much of this code should probably be in SceneObjectGroup
  1624. ///
  1625. /// <param name="part"></param>
  1626. /// <param name="light"></param>
  1627. /// <param name="color"></param>
  1628. /// <param name="intensity"></param>
  1629. /// <param name="radius"></param>
  1630. /// <param name="falloff"></param>
  1631. protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
  1632. {
  1633. if (part == null)
  1634. return;
  1635. if (light)
  1636. {
  1637. part.Shape.LightEntry = true;
  1638. part.Shape.LightColorR = Util.Clip((float)color.x, 0.0f, 1.0f);
  1639. part.Shape.LightColorG = Util.Clip((float)color.y, 0.0f, 1.0f);
  1640. part.Shape.LightColorB = Util.Clip((float)color.z, 0.0f, 1.0f);
  1641. part.Shape.LightIntensity = Util.Clip((float)intensity, 0.0f, 1.0f);
  1642. part.Shape.LightRadius = Util.Clip((float)radius, 0.1f, 20.0f);
  1643. part.Shape.LightFalloff = Util.Clip((float)falloff, 0.01f, 2.0f);
  1644. }
  1645. else
  1646. {
  1647. part.Shape.LightEntry = false;
  1648. }
  1649. part.ParentGroup.HasGroupChanged = true;
  1650. part.ScheduleFullUpdate();
  1651. }
  1652. public LSL_Vector llGetColor(int face)
  1653. {
  1654. m_host.AddScriptLPS(1);
  1655. return GetColor(m_host, face);
  1656. }
  1657. protected LSL_Vector GetColor(SceneObjectPart part, int face)
  1658. {
  1659. Primitive.TextureEntry tex = part.Shape.Textures;
  1660. Color4 texcolor;
  1661. LSL_Vector rgb = new LSL_Vector();
  1662. if (face == ScriptBaseClass.ALL_SIDES)
  1663. {
  1664. int i;
  1665. for (i = 0 ; i < GetNumberOfSides(part); i++)
  1666. {
  1667. texcolor = tex.GetFace((uint)i).RGBA;
  1668. rgb.x += texcolor.R;
  1669. rgb.y += texcolor.G;
  1670. rgb.z += texcolor.B;
  1671. }
  1672. rgb.x /= (float)GetNumberOfSides(part);
  1673. rgb.y /= (float)GetNumberOfSides(part);
  1674. rgb.z /= (float)GetNumberOfSides(part);
  1675. return rgb;
  1676. }
  1677. if (face >= 0 && face < GetNumberOfSides(part))
  1678. {
  1679. texcolor = tex.GetFace((uint)face).RGBA;
  1680. rgb.x = texcolor.R;
  1681. rgb.y = texcolor.G;
  1682. rgb.z = texcolor.B;
  1683. return rgb;
  1684. }
  1685. else
  1686. {
  1687. return new LSL_Vector();
  1688. }
  1689. }
  1690. public void llSetTexture(string texture, int face)
  1691. {
  1692. m_host.AddScriptLPS(1);
  1693. SetTexture(m_host, texture, face);
  1694. ScriptSleep(200);
  1695. }
  1696. public void llSetLinkTexture(int linknumber, string texture, int face)
  1697. {
  1698. m_host.AddScriptLPS(1);
  1699. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  1700. foreach (SceneObjectPart part in parts)
  1701. SetTexture(part, texture, face);
  1702. ScriptSleep(200);
  1703. }
  1704. protected void SetTexture(SceneObjectPart part, string texture, int face)
  1705. {
  1706. UUID textureID = new UUID();
  1707. textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture);
  1708. if (textureID == UUID.Zero)
  1709. {
  1710. if (!UUID.TryParse(texture, out textureID))
  1711. return;
  1712. }
  1713. Primitive.TextureEntry tex = part.Shape.Textures;
  1714. if (face >= 0 && face < GetNumberOfSides(part))
  1715. {
  1716. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  1717. texface.TextureID = textureID;
  1718. tex.FaceTextures[face] = texface;
  1719. part.UpdateTextureEntry(tex.GetBytes());
  1720. return;
  1721. }
  1722. else if (face == ScriptBaseClass.ALL_SIDES)
  1723. {
  1724. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1725. {
  1726. if (tex.FaceTextures[i] != null)
  1727. {
  1728. tex.FaceTextures[i].TextureID = textureID;
  1729. }
  1730. }
  1731. tex.DefaultTexture.TextureID = textureID;
  1732. part.UpdateTextureEntry(tex.GetBytes());
  1733. return;
  1734. }
  1735. }
  1736. public void llScaleTexture(double u, double v, int face)
  1737. {
  1738. m_host.AddScriptLPS(1);
  1739. ScaleTexture(m_host, u, v, face);
  1740. ScriptSleep(200);
  1741. }
  1742. protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
  1743. {
  1744. Primitive.TextureEntry tex = part.Shape.Textures;
  1745. if (face >= 0 && face < GetNumberOfSides(part))
  1746. {
  1747. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  1748. texface.RepeatU = (float)u;
  1749. texface.RepeatV = (float)v;
  1750. tex.FaceTextures[face] = texface;
  1751. part.UpdateTextureEntry(tex.GetBytes());
  1752. return;
  1753. }
  1754. if (face == ScriptBaseClass.ALL_SIDES)
  1755. {
  1756. for (int i = 0; i < GetNumberOfSides(part); i++)
  1757. {
  1758. if (tex.FaceTextures[i] != null)
  1759. {
  1760. tex.FaceTextures[i].RepeatU = (float)u;
  1761. tex.FaceTextures[i].RepeatV = (float)v;
  1762. }
  1763. }
  1764. tex.DefaultTexture.RepeatU = (float)u;
  1765. tex.DefaultTexture.RepeatV = (float)v;
  1766. part.UpdateTextureEntry(tex.GetBytes());
  1767. return;
  1768. }
  1769. }
  1770. public void llOffsetTexture(double u, double v, int face)
  1771. {
  1772. m_host.AddScriptLPS(1);
  1773. OffsetTexture(m_host, u, v, face);
  1774. ScriptSleep(200);
  1775. }
  1776. protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
  1777. {
  1778. Primitive.TextureEntry tex = part.Shape.Textures;
  1779. if (face >= 0 && face < GetNumberOfSides(part))
  1780. {
  1781. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  1782. texface.OffsetU = (float)u;
  1783. texface.OffsetV = (float)v;
  1784. tex.FaceTextures[face] = texface;
  1785. part.UpdateTextureEntry(tex.GetBytes());
  1786. return;
  1787. }
  1788. if (face == ScriptBaseClass.ALL_SIDES)
  1789. {
  1790. for (int i = 0; i < GetNumberOfSides(part); i++)
  1791. {
  1792. if (tex.FaceTextures[i] != null)
  1793. {
  1794. tex.FaceTextures[i].OffsetU = (float)u;
  1795. tex.FaceTextures[i].OffsetV = (float)v;
  1796. }
  1797. }
  1798. tex.DefaultTexture.OffsetU = (float)u;
  1799. tex.DefaultTexture.OffsetV = (float)v;
  1800. part.UpdateTextureEntry(tex.GetBytes());
  1801. return;
  1802. }
  1803. }
  1804. public void llRotateTexture(double rotation, int face)
  1805. {
  1806. m_host.AddScriptLPS(1);
  1807. RotateTexture(m_host, rotation, face);
  1808. ScriptSleep(200);
  1809. }
  1810. protected void RotateTexture(SceneObjectPart part, double rotation, int face)
  1811. {
  1812. Primitive.TextureEntry tex = part.Shape.Textures;
  1813. if (face >= 0 && face < GetNumberOfSides(part))
  1814. {
  1815. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  1816. texface.Rotation = (float)rotation;
  1817. tex.FaceTextures[face] = texface;
  1818. part.UpdateTextureEntry(tex.GetBytes());
  1819. return;
  1820. }
  1821. if (face == ScriptBaseClass.ALL_SIDES)
  1822. {
  1823. for (int i = 0; i < GetNumberOfSides(part); i++)
  1824. {
  1825. if (tex.FaceTextures[i] != null)
  1826. {
  1827. tex.FaceTextures[i].Rotation = (float)rotation;
  1828. }
  1829. }
  1830. tex.DefaultTexture.Rotation = (float)rotation;
  1831. part.UpdateTextureEntry(tex.GetBytes());
  1832. return;
  1833. }
  1834. }
  1835. public LSL_String llGetTexture(int face)
  1836. {
  1837. m_host.AddScriptLPS(1);
  1838. return GetTexture(m_host, face);
  1839. }
  1840. protected LSL_String GetTexture(SceneObjectPart part, int face)
  1841. {
  1842. Primitive.TextureEntry tex = part.Shape.Textures;
  1843. if (face == ScriptBaseClass.ALL_SIDES)
  1844. {
  1845. face = 0;
  1846. }
  1847. if (face >= 0 && face < GetNumberOfSides(part))
  1848. {
  1849. Primitive.TextureEntryFace texface;
  1850. texface = tex.GetFace((uint)face);
  1851. string texture = texface.TextureID.ToString();
  1852. lock (part.TaskInventory)
  1853. {
  1854. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in part.TaskInventory)
  1855. {
  1856. if (inv.Value.AssetID == texface.TextureID)
  1857. {
  1858. texture = inv.Value.Name.ToString();
  1859. break;
  1860. }
  1861. }
  1862. }
  1863. return texture;
  1864. }
  1865. else
  1866. {
  1867. return UUID.Zero.ToString();
  1868. }
  1869. }
  1870. public void llSetPos(LSL_Vector pos)
  1871. {
  1872. m_host.AddScriptLPS(1);
  1873. SetPos(m_host, pos, true);
  1874. ScriptSleep(200);
  1875. }
  1876. /// <summary>
  1877. /// Tries to move the entire object so that the root prim is within 0.1m of position. http://wiki.secondlife.com/wiki/LlSetRegionPos
  1878. /// Documentation indicates that the use of x/y coordinates up to 10 meters outside the bounds of a region will work but do not specify what happens if there is no adjacent region for the object to move into.
  1879. /// Uses the RegionSize constant here rather than hard-coding 266.0 to alert any developer modifying OpenSim to support variable-sized regions that this method will need tweaking.
  1880. /// </summary>
  1881. /// <param name="pos"></param>
  1882. /// <returns>1 if successful, 0 otherwise.</returns>
  1883. public LSL_Integer llSetRegionPos(LSL_Vector pos)
  1884. {
  1885. m_host.AddScriptLPS(1);
  1886. // BEGIN WORKAROUND
  1887. // IF YOU GET REGION CROSSINGS WORKING WITH THIS FUNCTION, REPLACE THE WORKAROUND.
  1888. //
  1889. // This workaround is to prevent silent failure of this function.
  1890. // According to the specification on the SL Wiki, providing a position outside of the
  1891. if (pos.x < 0 || pos.x > World.RegionInfo.RegionSizeX || pos.y < 0 || pos.y > World.RegionInfo.RegionSizeY)
  1892. {
  1893. return 0;
  1894. }
  1895. // END WORK AROUND
  1896. else if ( // this is not part of the workaround if-block because it's not related to the workaround.
  1897. IsPhysical() ||
  1898. m_host.ParentGroup.IsAttachment || // return FALSE if attachment
  1899. (
  1900. pos.x < -10.0 || // return FALSE if more than 10 meters into a west-adjacent region.
  1901. pos.x > (World.RegionInfo.RegionSizeX + 10) || // return FALSE if more than 10 meters into a east-adjacent region.
  1902. pos.y < -10.0 || // return FALSE if more than 10 meters into a south-adjacent region.
  1903. pos.y > (World.RegionInfo.RegionSizeY + 10) || // return FALSE if more than 10 meters into a north-adjacent region.
  1904. pos.z > Constants.RegionHeight // return FALSE if altitude than 4096m
  1905. )
  1906. )
  1907. {
  1908. return 0;
  1909. }
  1910. // if we reach this point, then the object is not physical, it's not an attachment, and the destination is within the valid range.
  1911. // this could possibly be done in the above else-if block, but we're doing the check here to keep the code easier to read.
  1912. Vector3 objectPos = m_host.ParentGroup.RootPart.AbsolutePosition;
  1913. LandData here = World.GetLandData(objectPos);
  1914. LandData there = World.GetLandData(pos);
  1915. // we're only checking prim limits if it's moving to a different parcel under the assumption that if the object got onto the parcel without exceeding the prim limits.
  1916. bool sameParcel = here.GlobalID == there.GlobalID;
  1917. if (!sameParcel && !World.Permissions.CanRezObject(
  1918. m_host.ParentGroup.PrimCount, m_host.ParentGroup.OwnerID, pos))
  1919. {
  1920. return 0;
  1921. }
  1922. SetPos(m_host.ParentGroup.RootPart, pos, false);
  1923. return VecDist(pos, llGetRootPosition()) <= 0.1 ? 1 : 0;
  1924. }
  1925. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  1926. // note linked setpos is capped "differently"
  1927. private LSL_Vector SetPosAdjust(LSL_Vector start, LSL_Vector end)
  1928. {
  1929. if (llVecDist(start, end) > 10.0f * m_ScriptDistanceFactor)
  1930. return start + m_ScriptDistanceFactor * 10.0f * llVecNorm(end - start);
  1931. else
  1932. return end;
  1933. }
  1934. protected LSL_Vector GetSetPosTarget(SceneObjectPart part, LSL_Vector targetPos, LSL_Vector fromPos)
  1935. {
  1936. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1937. return fromPos;
  1938. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  1939. float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y);
  1940. bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true);
  1941. if (part.ParentGroup.RootPart == part)
  1942. {
  1943. if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0)
  1944. targetPos.z = ground;
  1945. }
  1946. LSL_Vector real_vec = SetPosAdjust(fromPos, targetPos);
  1947. return real_vec;
  1948. }
  1949. /// <summary>
  1950. /// set object position, optionally capping the distance.
  1951. /// </summary>
  1952. /// <param name="part"></param>
  1953. /// <param name="targetPos"></param>
  1954. /// <param name="adjust">if TRUE, will cap the distance to 10m.</param>
  1955. protected void SetPos(SceneObjectPart part, LSL_Vector targetPos, bool adjust)
  1956. {
  1957. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  1958. LSL_Vector currentPos = GetPartLocalPos(part);
  1959. float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y);
  1960. bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true);
  1961. if (part.ParentGroup.RootPart == part)
  1962. {
  1963. if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0)
  1964. targetPos.z = ground;
  1965. SceneObjectGroup parent = part.ParentGroup;
  1966. parent.UpdateGroupPosition(!adjust ? targetPos :
  1967. SetPosAdjust(currentPos, targetPos));
  1968. }
  1969. else
  1970. {
  1971. part.OffsetPosition = !adjust ? targetPos :
  1972. SetPosAdjust(currentPos, targetPos);
  1973. SceneObjectGroup parent = part.ParentGroup;
  1974. parent.HasGroupChanged = true;
  1975. parent.ScheduleGroupForTerseUpdate();
  1976. }
  1977. }
  1978. public LSL_Vector llGetPos()
  1979. {
  1980. m_host.AddScriptLPS(1);
  1981. return m_host.GetWorldPosition();
  1982. }
  1983. public LSL_Vector llGetLocalPos()
  1984. {
  1985. m_host.AddScriptLPS(1);
  1986. return GetPartLocalPos(m_host);
  1987. }
  1988. protected LSL_Vector GetPartLocalPos(SceneObjectPart part)
  1989. {
  1990. m_host.AddScriptLPS(1);
  1991. Vector3 pos;
  1992. if (!part.IsRoot)
  1993. {
  1994. pos = part.OffsetPosition;
  1995. }
  1996. else
  1997. {
  1998. if (part.ParentGroup.IsAttachment)
  1999. {
  2000. pos = part.AttachedPos;
  2001. }
  2002. else
  2003. {
  2004. pos = part.AbsolutePosition;
  2005. }
  2006. }
  2007. // m_log.DebugFormat("[LSL API]: Returning {0} in GetPartLocalPos()", pos);
  2008. return new LSL_Vector(pos);
  2009. }
  2010. public void llSetRot(LSL_Rotation rot)
  2011. {
  2012. m_host.AddScriptLPS(1);
  2013. // try to let this work as in SL...
  2014. if (m_host.ParentID == 0)
  2015. {
  2016. // special case: If we are root, rotate complete SOG to new rotation
  2017. SetRot(m_host, rot);
  2018. }
  2019. else
  2020. {
  2021. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  2022. SceneObjectPart rootPart = m_host.ParentGroup.RootPart;
  2023. if (rootPart != null) // better safe than sorry
  2024. {
  2025. SetRot(m_host, rootPart.RotationOffset * (Quaternion)rot);
  2026. }
  2027. }
  2028. ScriptSleep(200);
  2029. }
  2030. public void llSetLocalRot(LSL_Rotation rot)
  2031. {
  2032. m_host.AddScriptLPS(1);
  2033. SetRot(m_host, rot);
  2034. ScriptSleep(200);
  2035. }
  2036. protected void SetRot(SceneObjectPart part, Quaternion rot)
  2037. {
  2038. part.UpdateRotation(rot);
  2039. // Update rotation does not move the object in the physics scene if it's a linkset.
  2040. //KF: Do NOT use this next line if using ODE physics engine. This need a switch based on .ini Phys Engine type
  2041. // part.ParentGroup.AbsolutePosition = part.ParentGroup.AbsolutePosition;
  2042. // So, after thinking about this for a bit, the issue with the part.ParentGroup.AbsolutePosition = part.ParentGroup.AbsolutePosition line
  2043. // is it isn't compatible with vehicles because it causes the vehicle body to have to be broken down and rebuilt
  2044. // It's perfectly okay when the object is not an active physical body though.
  2045. // So, part.ParentGroup.ResetChildPrimPhysicsPositions(); does the thing that Kitto is warning against
  2046. // but only if the object is not physial and active. This is important for rotating doors.
  2047. // without the absoluteposition = absoluteposition happening, the doors do not move in the physics
  2048. // scene
  2049. PhysicsActor pa = part.PhysActor;
  2050. if (pa != null && !pa.IsPhysical)
  2051. {
  2052. part.ParentGroup.ResetChildPrimPhysicsPositions();
  2053. }
  2054. }
  2055. /// <summary>
  2056. /// See http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  2057. /// </summary>
  2058. public LSL_Rotation llGetRot()
  2059. {
  2060. // unlinked or root prim then use llRootRotation
  2061. // see llRootRotaion for references.
  2062. if (m_host.LinkNum == 0 || m_host.LinkNum == 1)
  2063. {
  2064. return llGetRootRotation();
  2065. }
  2066. m_host.AddScriptLPS(1);
  2067. Quaternion q = m_host.GetWorldRotation();
  2068. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  2069. }
  2070. private LSL_Rotation GetPartRot(SceneObjectPart part)
  2071. {
  2072. Quaternion q;
  2073. if (part.LinkNum == 0 || part.LinkNum == 1) // unlinked or root prim
  2074. {
  2075. if (part.ParentGroup.AttachmentPoint != 0)
  2076. {
  2077. ScenePresence avatar = World.GetScenePresence(part.ParentGroup.AttachedAvatar);
  2078. if (avatar != null)
  2079. {
  2080. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2081. q = avatar.CameraRotation; // Mouselook
  2082. else
  2083. q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate
  2084. }
  2085. else
  2086. q = part.ParentGroup.GroupRotation; // Likely never get here but just in case
  2087. }
  2088. else
  2089. q = part.ParentGroup.GroupRotation; // just the group rotation
  2090. return new LSL_Rotation(q);
  2091. }
  2092. return new LSL_Rotation(part.GetWorldRotation());
  2093. }
  2094. public LSL_Rotation llGetLocalRot()
  2095. {
  2096. m_host.AddScriptLPS(1);
  2097. return new LSL_Rotation(m_host.RotationOffset);
  2098. }
  2099. public void llSetForce(LSL_Vector force, int local)
  2100. {
  2101. m_host.AddScriptLPS(1);
  2102. if (!m_host.ParentGroup.IsDeleted)
  2103. {
  2104. if (local != 0)
  2105. force *= llGetRot();
  2106. m_host.ParentGroup.RootPart.SetForce(force);
  2107. }
  2108. }
  2109. public LSL_Vector llGetForce()
  2110. {
  2111. LSL_Vector force = new LSL_Vector(0.0, 0.0, 0.0);
  2112. m_host.AddScriptLPS(1);
  2113. if (!m_host.ParentGroup.IsDeleted)
  2114. {
  2115. force = m_host.ParentGroup.RootPart.GetForce();
  2116. }
  2117. return force;
  2118. }
  2119. public void llSetVelocity(LSL_Vector velocity, int local)
  2120. {
  2121. m_host.AddScriptLPS(1);
  2122. if (!m_host.ParentGroup.IsDeleted)
  2123. {
  2124. if (local != 0)
  2125. velocity *= llGetRot();
  2126. m_host.ParentGroup.RootPart.Velocity = velocity;
  2127. }
  2128. }
  2129. public void llSetAngularVelocity(LSL_Vector angularVelocity, int local)
  2130. {
  2131. m_host.AddScriptLPS(1);
  2132. if (!m_host.ParentGroup.IsDeleted)
  2133. {
  2134. if (local != 0)
  2135. angularVelocity *= llGetRot();
  2136. m_host.ParentGroup.RootPart.AngularVelocity = angularVelocity;
  2137. }
  2138. }
  2139. public LSL_Integer llTarget(LSL_Vector position, double range)
  2140. {
  2141. m_host.AddScriptLPS(1);
  2142. return m_host.ParentGroup.registerTargetWaypoint(position,
  2143. (float)range);
  2144. }
  2145. public void llTargetRemove(int number)
  2146. {
  2147. m_host.AddScriptLPS(1);
  2148. m_host.ParentGroup.unregisterTargetWaypoint(number);
  2149. }
  2150. public LSL_Integer llRotTarget(LSL_Rotation rot, double error)
  2151. {
  2152. m_host.AddScriptLPS(1);
  2153. return m_host.ParentGroup.registerRotTargetWaypoint(rot, (float)error);
  2154. }
  2155. public void llRotTargetRemove(int number)
  2156. {
  2157. m_host.AddScriptLPS(1);
  2158. m_host.ParentGroup.unregisterRotTargetWaypoint(number);
  2159. }
  2160. public void llMoveToTarget(LSL_Vector target, double tau)
  2161. {
  2162. m_host.AddScriptLPS(1);
  2163. m_host.MoveToTarget(target, (float)tau);
  2164. }
  2165. public void llStopMoveToTarget()
  2166. {
  2167. m_host.AddScriptLPS(1);
  2168. m_host.StopMoveToTarget();
  2169. }
  2170. public void llApplyImpulse(LSL_Vector force, int local)
  2171. {
  2172. m_host.AddScriptLPS(1);
  2173. //No energy force yet
  2174. Vector3 v = force;
  2175. if (v.Length() > 20000.0f)
  2176. {
  2177. v.Normalize();
  2178. v = v * 20000.0f;
  2179. }
  2180. m_host.ApplyImpulse(v, local != 0);
  2181. }
  2182. public void llApplyRotationalImpulse(LSL_Vector force, int local)
  2183. {
  2184. m_host.AddScriptLPS(1);
  2185. m_host.ApplyAngularImpulse(force, local != 0);
  2186. }
  2187. public void llSetTorque(LSL_Vector torque, int local)
  2188. {
  2189. m_host.AddScriptLPS(1);
  2190. m_host.SetAngularImpulse(torque, local != 0);
  2191. }
  2192. public LSL_Vector llGetTorque()
  2193. {
  2194. m_host.AddScriptLPS(1);
  2195. return new LSL_Vector(m_host.ParentGroup.GetTorque());
  2196. }
  2197. public void llSetForceAndTorque(LSL_Vector force, LSL_Vector torque, int local)
  2198. {
  2199. m_host.AddScriptLPS(1);
  2200. llSetForce(force, local);
  2201. llSetTorque(torque, local);
  2202. }
  2203. public LSL_Vector llGetVel()
  2204. {
  2205. m_host.AddScriptLPS(1);
  2206. Vector3 vel;
  2207. if (m_host.ParentGroup.IsAttachment)
  2208. {
  2209. ScenePresence avatar = m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  2210. vel = avatar.GetWorldVelocity();
  2211. }
  2212. else
  2213. {
  2214. vel = m_host.Velocity;
  2215. }
  2216. return new LSL_Vector(vel);
  2217. }
  2218. public LSL_Vector llGetAccel()
  2219. {
  2220. m_host.AddScriptLPS(1);
  2221. return new LSL_Vector(m_host.Acceleration);
  2222. }
  2223. public LSL_Vector llGetOmega()
  2224. {
  2225. m_host.AddScriptLPS(1);
  2226. return new LSL_Vector(m_host.AngularVelocity);
  2227. }
  2228. public LSL_Float llGetTimeOfDay()
  2229. {
  2230. m_host.AddScriptLPS(1);
  2231. return (double)((DateTime.Now.TimeOfDay.TotalMilliseconds / 1000) % (3600 * 4));
  2232. }
  2233. public LSL_Float llGetWallclock()
  2234. {
  2235. m_host.AddScriptLPS(1);
  2236. return DateTime.Now.TimeOfDay.TotalSeconds;
  2237. }
  2238. public LSL_Float llGetTime()
  2239. {
  2240. m_host.AddScriptLPS(1);
  2241. TimeSpan ScriptTime = DateTime.Now - m_timer;
  2242. return (double)(ScriptTime.TotalMilliseconds / 1000);
  2243. }
  2244. public void llResetTime()
  2245. {
  2246. m_host.AddScriptLPS(1);
  2247. m_timer = DateTime.Now;
  2248. }
  2249. public LSL_Float llGetAndResetTime()
  2250. {
  2251. m_host.AddScriptLPS(1);
  2252. TimeSpan ScriptTime = DateTime.Now - m_timer;
  2253. m_timer = DateTime.Now;
  2254. return (double)(ScriptTime.TotalMilliseconds / 1000);
  2255. }
  2256. public void llSound(string sound, double volume, int queue, int loop)
  2257. {
  2258. m_host.AddScriptLPS(1);
  2259. Deprecated("llSound", "Use llPlaySound instead");
  2260. }
  2261. // Xantor 20080528 PlaySound updated so it accepts an objectinventory name -or- a key to a sound
  2262. // 20080530 Updated to remove code duplication
  2263. public void llPlaySound(string sound, double volume)
  2264. {
  2265. m_host.AddScriptLPS(1);
  2266. // send the sound, once, to all clients in range
  2267. if (m_SoundModule != null)
  2268. {
  2269. m_SoundModule.SendSound(
  2270. m_host.UUID,
  2271. ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound),
  2272. volume, false, m_host.SoundQueueing ? (byte)SoundFlags.Queue : (byte)SoundFlags.None,
  2273. 0, false, false);
  2274. }
  2275. }
  2276. public void llLoopSound(string sound, double volume)
  2277. {
  2278. m_host.AddScriptLPS(1);
  2279. if (m_SoundModule != null)
  2280. {
  2281. m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound),
  2282. volume, 20, false);
  2283. }
  2284. }
  2285. public void llLoopSoundMaster(string sound, double volume)
  2286. {
  2287. m_host.AddScriptLPS(1);
  2288. if (m_SoundModule != null)
  2289. {
  2290. m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound),
  2291. volume, 20, true);
  2292. }
  2293. }
  2294. public void llLoopSoundSlave(string sound, double volume)
  2295. {
  2296. m_host.AddScriptLPS(1);
  2297. lock (m_host.ParentGroup.LoopSoundSlavePrims)
  2298. {
  2299. m_host.ParentGroup.LoopSoundSlavePrims.Add(m_host);
  2300. }
  2301. }
  2302. public void llPlaySoundSlave(string sound, double volume)
  2303. {
  2304. m_host.AddScriptLPS(1);
  2305. // send the sound, once, to all clients in range
  2306. if (m_SoundModule != null)
  2307. {
  2308. m_SoundModule.SendSound(m_host.UUID,
  2309. ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, false, 0,
  2310. 0, true, false);
  2311. }
  2312. }
  2313. public void llTriggerSound(string sound, double volume)
  2314. {
  2315. m_host.AddScriptLPS(1);
  2316. // send the sound, once, to all clients in rangeTrigger or play an attached sound in this part's inventory.
  2317. if (m_SoundModule != null)
  2318. {
  2319. m_SoundModule.SendSound(m_host.UUID,
  2320. ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, true, 0, 0,
  2321. false, false);
  2322. }
  2323. }
  2324. public void llStopSound()
  2325. {
  2326. m_host.AddScriptLPS(1);
  2327. if (m_SoundModule != null)
  2328. m_SoundModule.StopSound(m_host.UUID);
  2329. }
  2330. public void llPreloadSound(string sound)
  2331. {
  2332. m_host.AddScriptLPS(1);
  2333. if (m_SoundModule != null)
  2334. m_SoundModule.PreloadSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound), 0);
  2335. ScriptSleep(1000);
  2336. }
  2337. /// <summary>
  2338. /// Return a portion of the designated string bounded by
  2339. /// inclusive indices (start and end). As usual, the negative
  2340. /// indices, and the tolerance for out-of-bound values, makes
  2341. /// this more complicated than it might otherwise seem.
  2342. /// </summary>
  2343. public LSL_String llGetSubString(string src, int start, int end)
  2344. {
  2345. m_host.AddScriptLPS(1);
  2346. // Normalize indices (if negative).
  2347. // After normlaization they may still be
  2348. // negative, but that is now relative to
  2349. // the start, rather than the end, of the
  2350. // sequence.
  2351. if (start < 0)
  2352. {
  2353. start = src.Length+start;
  2354. }
  2355. if (end < 0)
  2356. {
  2357. end = src.Length+end;
  2358. }
  2359. // Conventional substring
  2360. if (start <= end)
  2361. {
  2362. // Implies both bounds are out-of-range.
  2363. if (end < 0 || start >= src.Length)
  2364. {
  2365. return String.Empty;
  2366. }
  2367. // If end is positive, then it directly
  2368. // corresponds to the lengt of the substring
  2369. // needed (plus one of course). BUT, it
  2370. // must be within bounds.
  2371. if (end >= src.Length)
  2372. {
  2373. end = src.Length-1;
  2374. }
  2375. if (start < 0)
  2376. {
  2377. return src.Substring(0,end+1);
  2378. }
  2379. // Both indices are positive
  2380. return src.Substring(start, (end+1) - start);
  2381. }
  2382. // Inverted substring (end < start)
  2383. else
  2384. {
  2385. // Implies both indices are below the
  2386. // lower bound. In the inverted case, that
  2387. // means the entire string will be returned
  2388. // unchanged.
  2389. if (start < 0)
  2390. {
  2391. return src;
  2392. }
  2393. // If both indices are greater than the upper
  2394. // bound the result may seem initially counter
  2395. // intuitive.
  2396. if (end >= src.Length)
  2397. {
  2398. return src;
  2399. }
  2400. if (end < 0)
  2401. {
  2402. if (start < src.Length)
  2403. {
  2404. return src.Substring(start);
  2405. }
  2406. else
  2407. {
  2408. return String.Empty;
  2409. }
  2410. }
  2411. else
  2412. {
  2413. if (start < src.Length)
  2414. {
  2415. return src.Substring(0,end+1) + src.Substring(start);
  2416. }
  2417. else
  2418. {
  2419. return src.Substring(0,end+1);
  2420. }
  2421. }
  2422. }
  2423. }
  2424. /// <summary>
  2425. /// Delete substring removes the specified substring bounded
  2426. /// by the inclusive indices start and end. Indices may be
  2427. /// negative (indicating end-relative) and may be inverted,
  2428. /// i.e. end < start.
  2429. /// </summary>
  2430. public LSL_String llDeleteSubString(string src, int start, int end)
  2431. {
  2432. m_host.AddScriptLPS(1);
  2433. // Normalize indices (if negative).
  2434. // After normlaization they may still be
  2435. // negative, but that is now relative to
  2436. // the start, rather than the end, of the
  2437. // sequence.
  2438. if (start < 0)
  2439. {
  2440. start = src.Length+start;
  2441. }
  2442. if (end < 0)
  2443. {
  2444. end = src.Length+end;
  2445. }
  2446. // Conventionally delimited substring
  2447. if (start <= end)
  2448. {
  2449. // If both bounds are outside of the existing
  2450. // string, then return unchanges.
  2451. if (end < 0 || start >= src.Length)
  2452. {
  2453. return src;
  2454. }
  2455. // At least one bound is in-range, so we
  2456. // need to clip the out-of-bound argument.
  2457. if (start < 0)
  2458. {
  2459. start = 0;
  2460. }
  2461. if (end >= src.Length)
  2462. {
  2463. end = src.Length-1;
  2464. }
  2465. return src.Remove(start,end-start+1);
  2466. }
  2467. // Inverted substring
  2468. else
  2469. {
  2470. // In this case, out of bounds means that
  2471. // the existing string is part of the cut.
  2472. if (start < 0 || end >= src.Length)
  2473. {
  2474. return String.Empty;
  2475. }
  2476. if (end > 0)
  2477. {
  2478. if (start < src.Length)
  2479. {
  2480. return src.Remove(start).Remove(0,end+1);
  2481. }
  2482. else
  2483. {
  2484. return src.Remove(0,end+1);
  2485. }
  2486. }
  2487. else
  2488. {
  2489. if (start < src.Length)
  2490. {
  2491. return src.Remove(start);
  2492. }
  2493. else
  2494. {
  2495. return src;
  2496. }
  2497. }
  2498. }
  2499. }
  2500. /// <summary>
  2501. /// Insert string inserts the specified string identified by src
  2502. /// at the index indicated by index. Index may be negative, in
  2503. /// which case it is end-relative. The index may exceed either
  2504. /// string bound, with the result being a concatenation.
  2505. /// </summary>
  2506. public LSL_String llInsertString(string dest, int index, string src)
  2507. {
  2508. m_host.AddScriptLPS(1);
  2509. // Normalize indices (if negative).
  2510. // After normlaization they may still be
  2511. // negative, but that is now relative to
  2512. // the start, rather than the end, of the
  2513. // sequence.
  2514. if (index < 0)
  2515. {
  2516. index = dest.Length+index;
  2517. // Negative now means it is less than the lower
  2518. // bound of the string.
  2519. if (index < 0)
  2520. {
  2521. return src+dest;
  2522. }
  2523. }
  2524. if (index >= dest.Length)
  2525. {
  2526. return dest+src;
  2527. }
  2528. // The index is in bounds.
  2529. // In this case the index refers to the index that will
  2530. // be assigned to the first character of the inserted string.
  2531. // So unlike the other string operations, we do not add one
  2532. // to get the correct string length.
  2533. return dest.Substring(0,index)+src+dest.Substring(index);
  2534. }
  2535. public LSL_String llToUpper(string src)
  2536. {
  2537. m_host.AddScriptLPS(1);
  2538. return src.ToUpper();
  2539. }
  2540. public LSL_String llToLower(string src)
  2541. {
  2542. m_host.AddScriptLPS(1);
  2543. return src.ToLower();
  2544. }
  2545. public void llGiveMoney(string destination, int amount)
  2546. {
  2547. Util.FireAndForget(x =>
  2548. {
  2549. m_host.AddScriptLPS(1);
  2550. if (m_item.PermsGranter == UUID.Zero)
  2551. return;
  2552. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  2553. {
  2554. Error("llGiveMoney", "No permissions to give money");
  2555. return;
  2556. }
  2557. UUID toID = new UUID();
  2558. if (!UUID.TryParse(destination, out toID))
  2559. {
  2560. Error("llGiveMoney", "Bad key in llGiveMoney");
  2561. return;
  2562. }
  2563. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  2564. if (money == null)
  2565. {
  2566. NotImplemented("llGiveMoney");
  2567. return;
  2568. }
  2569. money.ObjectGiveMoney(
  2570. m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount);
  2571. }, null, "LSL_Api.llGiveMoney");
  2572. }
  2573. public void llMakeExplosion(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  2574. {
  2575. m_host.AddScriptLPS(1);
  2576. Deprecated("llMakeExplosion", "Use llParticleSystem instead");
  2577. ScriptSleep(100);
  2578. }
  2579. public void llMakeFountain(int particles, double scale, double vel, double lifetime, double arc, int bounce, string texture, LSL_Vector offset, double bounce_offset)
  2580. {
  2581. m_host.AddScriptLPS(1);
  2582. Deprecated("llMakeFountain", "Use llParticleSystem instead");
  2583. ScriptSleep(100);
  2584. }
  2585. public void llMakeSmoke(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  2586. {
  2587. m_host.AddScriptLPS(1);
  2588. Deprecated("llMakeSmoke", "Use llParticleSystem instead");
  2589. ScriptSleep(100);
  2590. }
  2591. public void llMakeFire(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  2592. {
  2593. m_host.AddScriptLPS(1);
  2594. Deprecated("llMakeFire", "Use llParticleSystem instead");
  2595. ScriptSleep(100);
  2596. }
  2597. public void llRezAtRoot(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  2598. {
  2599. m_host.AddScriptLPS(1);
  2600. Util.FireAndForget(x =>
  2601. {
  2602. if (Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s))
  2603. return;
  2604. float dist = (float)llVecDist(llGetPos(), pos);
  2605. if (dist > m_ScriptDistanceFactor * 10.0f)
  2606. return;
  2607. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
  2608. if (item == null)
  2609. {
  2610. Error("llRezAtRoot", "Can't find object '" + inventory + "'");
  2611. return;
  2612. }
  2613. if (item.InvType != (int)InventoryType.Object)
  2614. {
  2615. Error("llRezAtRoot", "Can't create requested object; object is missing from database");
  2616. return;
  2617. }
  2618. // need the magnitude later
  2619. // float velmag = (float)Util.GetMagnitude(llvel);
  2620. List<SceneObjectGroup> new_groups = World.RezObject(m_host, item, pos, rot, vel, param);
  2621. // If either of these are null, then there was an unknown error.
  2622. if (new_groups == null)
  2623. return;
  2624. foreach (SceneObjectGroup group in new_groups)
  2625. {
  2626. // objects rezzed with this method are die_at_edge by default.
  2627. group.RootPart.SetDieAtEdge(true);
  2628. group.ResumeScripts();
  2629. m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
  2630. "object_rez", new Object[] {
  2631. new LSL_String(
  2632. group.RootPart.UUID.ToString()) },
  2633. new DetectParams[0]));
  2634. float groupmass = group.GetMass();
  2635. PhysicsActor pa = group.RootPart.PhysActor;
  2636. //Recoil.
  2637. if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero)
  2638. {
  2639. Vector3 recoil = -vel * groupmass * m_recoilScaleFactor;
  2640. if (recoil != Vector3.Zero)
  2641. {
  2642. llApplyImpulse(recoil, 0);
  2643. }
  2644. }
  2645. // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay)
  2646. }
  2647. }, null, "LSL_Api.llRezAtRoot");
  2648. //ScriptSleep((int)((groupmass * velmag) / 10));
  2649. ScriptSleep(100);
  2650. }
  2651. public void llRezObject(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  2652. {
  2653. llRezAtRoot(inventory, pos, vel, rot, param);
  2654. }
  2655. public void llLookAt(LSL_Vector target, double strength, double damping)
  2656. {
  2657. m_host.AddScriptLPS(1);
  2658. // Determine where we are looking from
  2659. LSL_Vector from = llGetPos();
  2660. // Work out the normalised vector from the source to the target
  2661. LSL_Vector delta = llVecNorm(target - from);
  2662. LSL_Vector angle = new LSL_Vector(0,0,0);
  2663. // Calculate the yaw
  2664. // subtracting PI_BY_TWO is required to compensate for the odd SL co-ordinate system
  2665. angle.x = llAtan2(delta.z, delta.y) - ScriptBaseClass.PI_BY_TWO;
  2666. // Calculate pitch
  2667. angle.y = llAtan2(delta.x, llSqrt((delta.y * delta.y) + (delta.z * delta.z)));
  2668. // we need to convert from a vector describing
  2669. // the angles of rotation in radians into rotation value
  2670. LSL_Rotation rot = llEuler2Rot(angle);
  2671. // Per discussion with Melanie, for non-physical objects llLookAt appears to simply
  2672. // set the rotation of the object, copy that behavior
  2673. PhysicsActor pa = m_host.PhysActor;
  2674. if (strength == 0 || pa == null || !pa.IsPhysical)
  2675. {
  2676. llSetRot(rot);
  2677. }
  2678. else
  2679. {
  2680. m_host.StartLookAt(rot, (float)strength, (float)damping);
  2681. }
  2682. }
  2683. public void llStopLookAt()
  2684. {
  2685. m_host.AddScriptLPS(1);
  2686. m_host.StopLookAt();
  2687. }
  2688. public void llSetTimerEvent(double sec)
  2689. {
  2690. if (sec != 0.0 && sec < m_MinTimerInterval)
  2691. sec = m_MinTimerInterval;
  2692. m_host.AddScriptLPS(1);
  2693. // Setting timer repeat
  2694. AsyncCommands.TimerPlugin.SetTimerEvent(m_host.LocalId, m_item.ItemID, sec);
  2695. }
  2696. public virtual void llSleep(double sec)
  2697. {
  2698. // m_log.Info("llSleep snoozing " + sec + "s.");
  2699. m_host.AddScriptLPS(1);
  2700. Sleep((int)(sec * 1000));
  2701. }
  2702. public LSL_Float llGetMass()
  2703. {
  2704. m_host.AddScriptLPS(1);
  2705. if (m_host.ParentGroup.IsAttachment)
  2706. {
  2707. ScenePresence attachedAvatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  2708. if (attachedAvatar != null)
  2709. {
  2710. return attachedAvatar.GetMass();
  2711. }
  2712. else
  2713. {
  2714. return 0;
  2715. }
  2716. }
  2717. else
  2718. {
  2719. if (m_host.IsRoot)
  2720. {
  2721. return m_host.ParentGroup.GetMass();
  2722. }
  2723. else
  2724. {
  2725. return m_host.GetMass();
  2726. }
  2727. }
  2728. }
  2729. public LSL_Float llGetMassMKS()
  2730. {
  2731. // this is what the wiki says it does!
  2732. // http://wiki.secondlife.com/wiki/LlGetMassMKS
  2733. return llGetMass() * 100.0;
  2734. }
  2735. public void llCollisionFilter(string name, string id, int accept)
  2736. {
  2737. m_host.AddScriptLPS(1);
  2738. m_host.CollisionFilter.Clear();
  2739. UUID objectID;
  2740. if (!UUID.TryParse(id, out objectID))
  2741. objectID = UUID.Zero;
  2742. if (objectID == UUID.Zero && name == "")
  2743. return;
  2744. m_host.CollisionFilter.Add(accept,objectID.ToString() + name);
  2745. }
  2746. public void llTakeControls(int controls, int accept, int pass_on)
  2747. {
  2748. if (m_item.PermsGranter != UUID.Zero)
  2749. {
  2750. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  2751. if (presence != null)
  2752. {
  2753. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  2754. {
  2755. presence.RegisterControlEventsToScript(controls, accept, pass_on, m_host.LocalId, m_item.ItemID);
  2756. }
  2757. }
  2758. }
  2759. m_host.AddScriptLPS(1);
  2760. }
  2761. public void llReleaseControls()
  2762. {
  2763. m_host.AddScriptLPS(1);
  2764. if (m_item.PermsGranter != UUID.Zero)
  2765. {
  2766. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  2767. if (presence != null)
  2768. {
  2769. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  2770. {
  2771. // Unregister controls from Presence
  2772. presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID);
  2773. // Remove Take Control permission.
  2774. m_item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  2775. }
  2776. }
  2777. }
  2778. }
  2779. public void llReleaseURL(string url)
  2780. {
  2781. m_host.AddScriptLPS(1);
  2782. if (m_UrlModule != null)
  2783. m_UrlModule.ReleaseURL(url);
  2784. }
  2785. /// <summary>
  2786. /// Attach the object containing this script to the avatar that owns it.
  2787. /// </summary>
  2788. /// <param name='attachmentPoint'>
  2789. /// The attachment point (e.g. <see cref="OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass.ATTACH_CHEST">ATTACH_CHEST</see>)
  2790. /// </param>
  2791. /// <returns>true if the attach suceeded, false if it did not</returns>
  2792. public bool AttachToAvatar(int attachmentPoint)
  2793. {
  2794. SceneObjectGroup grp = m_host.ParentGroup;
  2795. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  2796. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  2797. if (attachmentsModule != null)
  2798. return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true, true);
  2799. else
  2800. return false;
  2801. }
  2802. /// <summary>
  2803. /// Detach the object containing this script from the avatar it is attached to.
  2804. /// </summary>
  2805. /// <remarks>
  2806. /// Nothing happens if the object is not attached.
  2807. /// </remarks>
  2808. public void DetachFromAvatar()
  2809. {
  2810. Util.FireAndForget(DetachWrapper, m_host, "LSL_Api.DetachFromAvatar");
  2811. }
  2812. private void DetachWrapper(object o)
  2813. {
  2814. if (World.AttachmentsModule != null)
  2815. {
  2816. SceneObjectPart host = (SceneObjectPart)o;
  2817. ScenePresence presence = World.GetScenePresence(host.OwnerID);
  2818. World.AttachmentsModule.DetachSingleAttachmentToInv(presence, host.ParentGroup);
  2819. }
  2820. }
  2821. public void llAttachToAvatar(int attachmentPoint)
  2822. {
  2823. m_host.AddScriptLPS(1);
  2824. // if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
  2825. // return;
  2826. if (m_item.PermsGranter != m_host.OwnerID)
  2827. return;
  2828. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  2829. AttachToAvatar(attachmentPoint);
  2830. }
  2831. public void llDetachFromAvatar()
  2832. {
  2833. m_host.AddScriptLPS(1);
  2834. if (m_host.ParentGroup.AttachmentPoint == 0)
  2835. return;
  2836. if (m_item.PermsGranter != m_host.OwnerID)
  2837. return;
  2838. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  2839. DetachFromAvatar();
  2840. }
  2841. public void llTakeCamera(string avatar)
  2842. {
  2843. m_host.AddScriptLPS(1);
  2844. Deprecated("llTakeCamera", "Use llSetCameraParams instead");
  2845. }
  2846. public void llReleaseCamera(string avatar)
  2847. {
  2848. m_host.AddScriptLPS(1);
  2849. Deprecated("llReleaseCamera", "Use llClearCameraParams instead");
  2850. }
  2851. public LSL_String llGetOwner()
  2852. {
  2853. m_host.AddScriptLPS(1);
  2854. return m_host.OwnerID.ToString();
  2855. }
  2856. public void llInstantMessage(string user, string message)
  2857. {
  2858. m_host.AddScriptLPS(1);
  2859. // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
  2860. // InstantMessageModule.OnInstantMessage searches through a list of scenes for a client matching the toAgent,
  2861. // but I don't think we have a list of scenes available from here.
  2862. // (We also don't want to duplicate the code in OnInstantMessage if we can avoid it.)
  2863. // user is a UUID
  2864. // TODO: figure out values for client, fromSession, and imSessionID
  2865. // client.SendInstantMessage(m_host.UUID, fromSession, message, user, imSessionID, m_host.Name, AgentManager.InstantMessageDialog.MessageFromAgent, (uint)Util.UnixTimeSinceEpoch());
  2866. UUID friendTransactionID = UUID.Random();
  2867. //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
  2868. GridInstantMessage msg = new GridInstantMessage();
  2869. msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid;
  2870. msg.toAgentID = new Guid(user); // toAgentID.Guid;
  2871. msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here
  2872. // m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message);
  2873. // m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString());
  2874. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp;
  2875. //if (client != null)
  2876. //{
  2877. msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
  2878. //}
  2879. //else
  2880. //{
  2881. // msg.fromAgentName = "(hippos)";// Added for posterity. This means that we can't figure out who sent it
  2882. //}
  2883. // Cap the message length at 1024.
  2884. if (message != null && message.Length > 1024)
  2885. msg.message = message.Substring(0, 1024);
  2886. else
  2887. msg.message = message;
  2888. msg.dialog = (byte)19; // messgage from script ??? // dialog;
  2889. msg.fromGroup = false;// fromGroup;
  2890. msg.offline = (byte)0; //offline;
  2891. msg.ParentEstateID = 0; //ParentEstateID;
  2892. msg.Position = new Vector3(m_host.AbsolutePosition);
  2893. msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid;
  2894. Vector3 pos = m_host.AbsolutePosition;
  2895. msg.binaryBucket
  2896. = Util.StringToBytes256(
  2897. "{0}/{1}/{2}/{3}",
  2898. World.RegionInfo.RegionName,
  2899. (int)Math.Floor(pos.X),
  2900. (int)Math.Floor(pos.Y),
  2901. (int)Math.Floor(pos.Z));
  2902. if (m_TransferModule != null)
  2903. {
  2904. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  2905. }
  2906. ScriptSleep(2000);
  2907. }
  2908. public void llEmail(string address, string subject, string message)
  2909. {
  2910. m_host.AddScriptLPS(1);
  2911. IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  2912. if (emailModule == null)
  2913. {
  2914. Error("llEmail", "Email module not configured");
  2915. return;
  2916. }
  2917. //Restrict email destination to the avatars registered email address?
  2918. //The restriction only applies if the destination address is not local.
  2919. if (m_restrictEmail == true && address.Contains(m_internalObjectHost) == false)
  2920. {
  2921. UserAccount account =
  2922. World.UserAccountService.GetUserAccount(
  2923. World.RegionInfo.ScopeID,
  2924. m_host.OwnerID);
  2925. if (account == null)
  2926. {
  2927. Error("llEmail", "Can't find user account for '" + m_host.OwnerID.ToString() + "'");
  2928. return;
  2929. }
  2930. if (String.IsNullOrEmpty(account.Email))
  2931. {
  2932. Error("llEmail", "User account has not registered an email address.");
  2933. return;
  2934. }
  2935. address = account.Email;
  2936. }
  2937. emailModule.SendEmail(m_host.UUID, address, subject, message);
  2938. ScriptSleep(EMAIL_PAUSE_TIME * 1000);
  2939. }
  2940. public void llGetNextEmail(string address, string subject)
  2941. {
  2942. m_host.AddScriptLPS(1);
  2943. IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  2944. if (emailModule == null)
  2945. {
  2946. Error("llGetNextEmail", "Email module not configured");
  2947. return;
  2948. }
  2949. Email email;
  2950. email = emailModule.GetNextEmail(m_host.UUID, address, subject);
  2951. if (email == null)
  2952. return;
  2953. m_ScriptEngine.PostObjectEvent(m_host.LocalId,
  2954. new EventParams("email",
  2955. new Object[] {
  2956. new LSL_String(email.time),
  2957. new LSL_String(email.sender),
  2958. new LSL_String(email.subject),
  2959. new LSL_String(email.message),
  2960. new LSL_Integer(email.numLeft)},
  2961. new DetectParams[0]));
  2962. }
  2963. public LSL_String llGetKey()
  2964. {
  2965. m_host.AddScriptLPS(1);
  2966. return m_host.UUID.ToString();
  2967. }
  2968. public LSL_Key llGenerateKey()
  2969. {
  2970. m_host.AddScriptLPS(1);
  2971. return UUID.Random().ToString();
  2972. }
  2973. public void llSetBuoyancy(double buoyancy)
  2974. {
  2975. m_host.AddScriptLPS(1);
  2976. if (!m_host.ParentGroup.IsDeleted)
  2977. {
  2978. m_host.ParentGroup.RootPart.SetBuoyancy((float)buoyancy);
  2979. }
  2980. }
  2981. /// <summary>
  2982. /// Attempt to clamp the object on the Z axis at the given height over tau seconds.
  2983. /// </summary>
  2984. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  2985. /// <param name="water">False if height is calculated just from ground, otherwise uses ground or water depending on whichever is higher</param>
  2986. /// <param name="tau">Number of seconds over which to reach target</param>
  2987. public void llSetHoverHeight(double height, int water, double tau)
  2988. {
  2989. m_host.AddScriptLPS(1);
  2990. if (m_host.PhysActor != null)
  2991. {
  2992. PIDHoverType hoverType = PIDHoverType.Ground;
  2993. if (water != 0)
  2994. {
  2995. hoverType = PIDHoverType.GroundAndWater;
  2996. }
  2997. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  2998. }
  2999. }
  3000. public void llStopHover()
  3001. {
  3002. m_host.AddScriptLPS(1);
  3003. if (m_host.PhysActor != null)
  3004. {
  3005. m_host.SetHoverHeight(0f, PIDHoverType.Ground, 0f);
  3006. }
  3007. }
  3008. public void llMinEventDelay(double delay)
  3009. {
  3010. m_host.AddScriptLPS(1);
  3011. try
  3012. {
  3013. m_ScriptEngine.SetMinEventDelay(m_item.ItemID, delay);
  3014. }
  3015. catch (NotImplementedException)
  3016. {
  3017. // Currently not implemented in DotNetEngine only XEngine
  3018. NotImplemented("llMinEventDelay", "In DotNetEngine");
  3019. }
  3020. }
  3021. public void llSoundPreload(string sound)
  3022. {
  3023. m_host.AddScriptLPS(1);
  3024. Deprecated("llSoundPreload", "Use llPreloadSound instead");
  3025. }
  3026. public void llRotLookAt(LSL_Rotation target, double strength, double damping)
  3027. {
  3028. m_host.AddScriptLPS(1);
  3029. // Per discussion with Melanie, for non-physical objects llLookAt appears to simply
  3030. // set the rotation of the object, copy that behavior
  3031. PhysicsActor pa = m_host.PhysActor;
  3032. if (strength == 0 || pa == null || !pa.IsPhysical)
  3033. {
  3034. llSetLocalRot(target);
  3035. }
  3036. else
  3037. {
  3038. m_host.RotLookAt(target, (float)strength, (float)damping);
  3039. }
  3040. }
  3041. public LSL_Integer llStringLength(string str)
  3042. {
  3043. m_host.AddScriptLPS(1);
  3044. if (str.Length > 0)
  3045. {
  3046. return str.Length;
  3047. }
  3048. else
  3049. {
  3050. return 0;
  3051. }
  3052. }
  3053. public void llStartAnimation(string anim)
  3054. {
  3055. m_host.AddScriptLPS(1);
  3056. if (m_item.PermsGranter == UUID.Zero)
  3057. return;
  3058. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  3059. {
  3060. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3061. if (presence != null)
  3062. {
  3063. // Do NOT try to parse UUID, animations cannot be triggered by ID
  3064. UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  3065. if (animID == UUID.Zero)
  3066. presence.Animator.AddAnimation(anim, m_host.UUID);
  3067. else
  3068. presence.Animator.AddAnimation(animID, m_host.UUID);
  3069. }
  3070. }
  3071. }
  3072. public void llStopAnimation(string anim)
  3073. {
  3074. m_host.AddScriptLPS(1);
  3075. if (m_item.PermsGranter == UUID.Zero)
  3076. return;
  3077. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  3078. {
  3079. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3080. if (presence != null)
  3081. {
  3082. UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim);
  3083. if (animID == UUID.Zero)
  3084. presence.Animator.RemoveAnimation(anim);
  3085. else
  3086. presence.Animator.RemoveAnimation(animID, true);
  3087. }
  3088. }
  3089. }
  3090. public void llPointAt(LSL_Vector pos)
  3091. {
  3092. m_host.AddScriptLPS(1);
  3093. }
  3094. public void llStopPointAt()
  3095. {
  3096. m_host.AddScriptLPS(1);
  3097. }
  3098. public void llTargetOmega(LSL_Vector axis, double spinrate, double gain)
  3099. {
  3100. m_host.AddScriptLPS(1);
  3101. TargetOmega(m_host, axis, spinrate, gain);
  3102. }
  3103. protected void TargetOmega(SceneObjectPart part, LSL_Vector axis, double spinrate, double gain)
  3104. {
  3105. part.UpdateAngularVelocity(axis * spinrate);
  3106. }
  3107. public LSL_Integer llGetStartParameter()
  3108. {
  3109. m_host.AddScriptLPS(1);
  3110. return m_ScriptEngine.GetStartParameter(m_item.ItemID);
  3111. }
  3112. public void llRequestPermissions(string agent, int perm)
  3113. {
  3114. UUID agentID;
  3115. if (!UUID.TryParse(agent, out agentID))
  3116. return;
  3117. if (agentID == UUID.Zero || perm == 0) // Releasing permissions
  3118. {
  3119. llReleaseControls();
  3120. m_item.PermsGranter = UUID.Zero;
  3121. m_item.PermsMask = 0;
  3122. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3123. "run_time_permissions", new Object[] {
  3124. new LSL_Integer(0) },
  3125. new DetectParams[0]));
  3126. return;
  3127. }
  3128. if (m_item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  3129. llReleaseControls();
  3130. m_host.AddScriptLPS(1);
  3131. int implicitPerms = 0;
  3132. if (m_host.ParentGroup.IsAttachment && (UUID)agent == m_host.ParentGroup.AttachedAvatar)
  3133. {
  3134. // When attached, certain permissions are implicit if requested from owner
  3135. implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS |
  3136. ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  3137. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  3138. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  3139. ScriptBaseClass.PERMISSION_ATTACH;
  3140. }
  3141. else
  3142. {
  3143. if (m_host.ParentGroup.GetSittingAvatars().SingleOrDefault(sp => sp.UUID == agentID) != null)
  3144. {
  3145. // When agent is sitting, certain permissions are implicit if requested from sitting agent
  3146. implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  3147. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  3148. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  3149. ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  3150. }
  3151. else
  3152. {
  3153. if (World.GetExtraSetting("auto_grant_attach_perms") == "true")
  3154. implicitPerms = ScriptBaseClass.PERMISSION_ATTACH;
  3155. }
  3156. }
  3157. if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  3158. {
  3159. lock (m_host.TaskInventory)
  3160. {
  3161. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3162. m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
  3163. }
  3164. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3165. "run_time_permissions", new Object[] {
  3166. new LSL_Integer(perm) },
  3167. new DetectParams[0]));
  3168. return;
  3169. }
  3170. ScenePresence presence = World.GetScenePresence(agentID);
  3171. if (presence != null)
  3172. {
  3173. // If permissions are being requested from an NPC and were not implicitly granted above then
  3174. // auto grant all requested permissions if the script is owned by the NPC or the NPCs owner
  3175. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  3176. if (npcModule != null && npcModule.IsNPC(agentID, World))
  3177. {
  3178. if (npcModule.CheckPermissions(agentID, m_host.OwnerID))
  3179. {
  3180. lock (m_host.TaskInventory)
  3181. {
  3182. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3183. m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
  3184. }
  3185. m_ScriptEngine.PostScriptEvent(
  3186. m_item.ItemID,
  3187. new EventParams(
  3188. "run_time_permissions", new Object[] { new LSL_Integer(perm) }, new DetectParams[0]));
  3189. }
  3190. // it is an NPC, exit even if the permissions werent granted above, they are not going to answer
  3191. // the question!
  3192. return;
  3193. }
  3194. string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
  3195. if (ownerName == String.Empty)
  3196. ownerName = "(hippos)";
  3197. if (!m_waitingForScriptAnswer)
  3198. {
  3199. lock (m_host.TaskInventory)
  3200. {
  3201. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3202. m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
  3203. }
  3204. presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
  3205. m_waitingForScriptAnswer=true;
  3206. }
  3207. presence.ControllingClient.SendScriptQuestion(
  3208. m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, m_item.ItemID, perm);
  3209. return;
  3210. }
  3211. // Requested agent is not in range, refuse perms
  3212. m_ScriptEngine.PostScriptEvent(
  3213. m_item.ItemID,
  3214. new EventParams("run_time_permissions", new Object[] { new LSL_Integer(0) }, new DetectParams[0]));
  3215. }
  3216. void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer)
  3217. {
  3218. if (taskID != m_host.UUID)
  3219. return;
  3220. client.OnScriptAnswer -= handleScriptAnswer;
  3221. m_waitingForScriptAnswer = false;
  3222. if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  3223. llReleaseControls();
  3224. lock (m_host.TaskInventory)
  3225. {
  3226. m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
  3227. }
  3228. m_ScriptEngine.PostScriptEvent(
  3229. m_item.ItemID,
  3230. new EventParams("run_time_permissions", new Object[] { new LSL_Integer(answer) }, new DetectParams[0]));
  3231. }
  3232. public LSL_String llGetPermissionsKey()
  3233. {
  3234. m_host.AddScriptLPS(1);
  3235. return m_item.PermsGranter.ToString();
  3236. }
  3237. public LSL_Integer llGetPermissions()
  3238. {
  3239. m_host.AddScriptLPS(1);
  3240. int perms = m_item.PermsMask;
  3241. if (m_automaticLinkPermission)
  3242. perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
  3243. return perms;
  3244. }
  3245. public LSL_Integer llGetLinkNumber()
  3246. {
  3247. m_host.AddScriptLPS(1);
  3248. if (m_host.ParentGroup.PrimCount > 1)
  3249. {
  3250. return m_host.LinkNum;
  3251. }
  3252. else
  3253. {
  3254. return 0;
  3255. }
  3256. }
  3257. public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
  3258. {
  3259. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  3260. foreach (SceneObjectPart part in parts)
  3261. part.SetFaceColorAlpha(face, color, null);
  3262. }
  3263. public void llCreateLink(string target, int parent)
  3264. {
  3265. m_host.AddScriptLPS(1);
  3266. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3267. && !m_automaticLinkPermission)
  3268. {
  3269. Error("llCreateLink", "PERMISSION_CHANGE_LINKS permission not set");
  3270. return;
  3271. }
  3272. CreateLink(target, parent);
  3273. }
  3274. public void CreateLink(string target, int parent)
  3275. {
  3276. UUID targetID;
  3277. if (!UUID.TryParse(target, out targetID))
  3278. return;
  3279. SceneObjectPart targetPart = World.GetSceneObjectPart((UUID)targetID);
  3280. if (targetPart.ParentGroup.AttachmentPoint != 0)
  3281. return; // Fail silently if attached
  3282. if (targetPart.ParentGroup.RootPart.OwnerID != m_host.ParentGroup.RootPart.OwnerID)
  3283. return;
  3284. SceneObjectGroup parentPrim = null, childPrim = null;
  3285. if (targetPart != null)
  3286. {
  3287. if (parent != 0)
  3288. {
  3289. parentPrim = m_host.ParentGroup;
  3290. childPrim = targetPart.ParentGroup;
  3291. }
  3292. else
  3293. {
  3294. parentPrim = targetPart.ParentGroup;
  3295. childPrim = m_host.ParentGroup;
  3296. }
  3297. // Required for linking
  3298. childPrim.RootPart.ClearUpdateSchedule();
  3299. parentPrim.LinkToGroup(childPrim, true);
  3300. }
  3301. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3302. parentPrim.RootPart.CreateSelected = true;
  3303. parentPrim.HasGroupChanged = true;
  3304. parentPrim.ScheduleGroupForFullUpdate();
  3305. IClientAPI client = null;
  3306. ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
  3307. if (sp != null)
  3308. client = sp.ControllingClient;
  3309. if (client != null)
  3310. parentPrim.SendPropertiesToClient(client);
  3311. ScriptSleep(1000);
  3312. }
  3313. public void llBreakLink(int linknum)
  3314. {
  3315. m_host.AddScriptLPS(1);
  3316. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3317. && !m_automaticLinkPermission)
  3318. {
  3319. Error("llBreakLink", "PERMISSION_CHANGE_LINKS permission not set");
  3320. return;
  3321. }
  3322. BreakLink(linknum);
  3323. }
  3324. public void BreakLink(int linknum)
  3325. {
  3326. if (linknum < ScriptBaseClass.LINK_THIS)
  3327. return;
  3328. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3329. if (parentPrim.AttachmentPoint != 0)
  3330. return; // Fail silently if attached
  3331. SceneObjectPart childPrim = null;
  3332. switch (linknum)
  3333. {
  3334. case ScriptBaseClass.LINK_ROOT:
  3335. break;
  3336. case ScriptBaseClass.LINK_SET:
  3337. case ScriptBaseClass.LINK_ALL_OTHERS:
  3338. case ScriptBaseClass.LINK_ALL_CHILDREN:
  3339. case ScriptBaseClass.LINK_THIS:
  3340. foreach (SceneObjectPart part in parentPrim.Parts)
  3341. {
  3342. if (part.UUID != m_host.UUID)
  3343. {
  3344. childPrim = part;
  3345. break;
  3346. }
  3347. }
  3348. break;
  3349. default:
  3350. childPrim = parentPrim.GetLinkNumPart(linknum);
  3351. if (childPrim.UUID == m_host.UUID)
  3352. childPrim = null;
  3353. break;
  3354. }
  3355. if (linknum == ScriptBaseClass.LINK_ROOT)
  3356. {
  3357. // Restructuring Multiple Prims.
  3358. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
  3359. parts.Remove(parentPrim.RootPart);
  3360. foreach (SceneObjectPart part in parts)
  3361. {
  3362. parentPrim.DelinkFromGroup(part.LocalId, true);
  3363. }
  3364. parentPrim.HasGroupChanged = true;
  3365. parentPrim.ScheduleGroupForFullUpdate();
  3366. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3367. if (parts.Count > 0)
  3368. {
  3369. SceneObjectPart newRoot = parts[0];
  3370. parts.Remove(newRoot);
  3371. foreach (SceneObjectPart part in parts)
  3372. {
  3373. // Required for linking
  3374. part.ClearUpdateSchedule();
  3375. newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
  3376. }
  3377. newRoot.ParentGroup.HasGroupChanged = true;
  3378. newRoot.ParentGroup.ScheduleGroupForFullUpdate();
  3379. }
  3380. }
  3381. else
  3382. {
  3383. if (childPrim == null)
  3384. return;
  3385. parentPrim.DelinkFromGroup(childPrim.LocalId, true);
  3386. parentPrim.HasGroupChanged = true;
  3387. parentPrim.ScheduleGroupForFullUpdate();
  3388. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3389. }
  3390. }
  3391. public void llBreakAllLinks()
  3392. {
  3393. m_host.AddScriptLPS(1);
  3394. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3395. && !m_automaticLinkPermission)
  3396. {
  3397. Error("llBreakAllLinks", "PERMISSION_CHANGE_LINKS permission not set");
  3398. return;
  3399. }
  3400. BreakAllLinks();
  3401. }
  3402. public void BreakAllLinks()
  3403. {
  3404. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3405. if (parentPrim.AttachmentPoint != 0)
  3406. return; // Fail silently if attached
  3407. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
  3408. parts.Remove(parentPrim.RootPart);
  3409. foreach (SceneObjectPart part in parts)
  3410. {
  3411. parentPrim.DelinkFromGroup(part.LocalId, true);
  3412. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3413. }
  3414. parentPrim.HasGroupChanged = true;
  3415. parentPrim.ScheduleGroupForFullUpdate();
  3416. }
  3417. public LSL_String llGetLinkKey(int linknum)
  3418. {
  3419. m_host.AddScriptLPS(1);
  3420. ISceneEntity entity = GetLinkEntity(m_host, linknum);
  3421. if (entity != null)
  3422. return entity.UUID.ToString();
  3423. else
  3424. return ScriptBaseClass.NULL_KEY;
  3425. }
  3426. /// <summary>
  3427. /// Returns the name of the child prim or seated avatar matching the
  3428. /// specified link number.
  3429. /// </summary>
  3430. /// <param name="linknum">
  3431. /// The number of a link in the linkset or a link-related constant.
  3432. /// </param>
  3433. /// <returns>
  3434. /// The name determined to match the specified link number.
  3435. /// </returns>
  3436. /// <remarks>
  3437. /// The rules governing the returned name are not simple. The only
  3438. /// time a blank name is returned is if the target prim has a blank
  3439. /// name. If no prim with the given link number can be found then
  3440. /// usually NULL_KEY is returned but there are exceptions.
  3441. ///
  3442. /// In a single unlinked prim, A call with 0 returns the name, all
  3443. /// other values for link number return NULL_KEY
  3444. ///
  3445. /// In link sets it is more complicated.
  3446. ///
  3447. /// If the script is in the root prim:-
  3448. /// A zero link number returns NULL_KEY.
  3449. /// Positive link numbers return the name of the prim, or NULL_KEY
  3450. /// if a prim does not exist at that position.
  3451. /// Negative link numbers return the name of the first child prim.
  3452. ///
  3453. /// If the script is in a child prim:-
  3454. /// Link numbers 0 or 1 return the name of the root prim.
  3455. /// Positive link numbers return the name of the prim or NULL_KEY
  3456. /// if a prim does not exist at that position.
  3457. /// Negative numbers return the name of the root prim.
  3458. ///
  3459. /// References
  3460. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetLinkName
  3461. /// Mentions NULL_KEY being returned
  3462. /// http://wiki.secondlife.com/wiki/LlGetLinkName
  3463. /// Mentions using the LINK_* constants, some of which are negative
  3464. /// </remarks>
  3465. public LSL_String llGetLinkName(int linknum)
  3466. {
  3467. m_host.AddScriptLPS(1);
  3468. ISceneEntity entity = GetLinkEntity(m_host, linknum);
  3469. if (entity != null)
  3470. return entity.Name;
  3471. else
  3472. return ScriptBaseClass.NULL_KEY;
  3473. }
  3474. public LSL_Integer llGetInventoryNumber(int type)
  3475. {
  3476. m_host.AddScriptLPS(1);
  3477. int count = 0;
  3478. lock (m_host.TaskInventory)
  3479. {
  3480. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  3481. {
  3482. if (inv.Value.Type == type || type == -1)
  3483. {
  3484. count = count + 1;
  3485. }
  3486. }
  3487. }
  3488. return count;
  3489. }
  3490. public LSL_String llGetInventoryName(int type, int number)
  3491. {
  3492. m_host.AddScriptLPS(1);
  3493. ArrayList keys = new ArrayList();
  3494. lock (m_host.TaskInventory)
  3495. {
  3496. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  3497. {
  3498. if (inv.Value.Type == type || type == -1)
  3499. {
  3500. keys.Add(inv.Value.Name);
  3501. }
  3502. }
  3503. }
  3504. if (keys.Count == 0)
  3505. {
  3506. return String.Empty;
  3507. }
  3508. keys.Sort();
  3509. if (keys.Count > number)
  3510. {
  3511. return (string)keys[number];
  3512. }
  3513. return String.Empty;
  3514. }
  3515. public LSL_Float llGetEnergy()
  3516. {
  3517. m_host.AddScriptLPS(1);
  3518. // TODO: figure out real energy value
  3519. return 1.0f;
  3520. }
  3521. public void llGiveInventory(string destination, string inventory)
  3522. {
  3523. m_host.AddScriptLPS(1);
  3524. UUID destId = UUID.Zero;
  3525. if (!UUID.TryParse(destination, out destId))
  3526. {
  3527. Error("llGiveInventory", "Can't parse destination key '" + destination + "'");
  3528. return;
  3529. }
  3530. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
  3531. if (item == null)
  3532. {
  3533. Error("llGiveInventory", "Can't find inventory object '" + inventory + "'");
  3534. return;
  3535. }
  3536. UUID objId = item.ItemID;
  3537. // check if destination is an object
  3538. if (World.GetSceneObjectPart(destId) != null)
  3539. {
  3540. // destination is an object
  3541. World.MoveTaskInventoryItem(destId, m_host, objId);
  3542. }
  3543. else
  3544. {
  3545. ScenePresence presence = World.GetScenePresence(destId);
  3546. if (presence == null)
  3547. {
  3548. UserAccount account =
  3549. World.UserAccountService.GetUserAccount(
  3550. World.RegionInfo.ScopeID,
  3551. destId);
  3552. if (account == null)
  3553. {
  3554. Error("llGiveInventory", "Can't find destination '" + destId.ToString() + "'");
  3555. return;
  3556. }
  3557. }
  3558. // destination is an avatar
  3559. string message;
  3560. InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId, out message);
  3561. if (agentItem == null)
  3562. {
  3563. llSay(0, message);
  3564. return;
  3565. }
  3566. if (m_TransferModule != null)
  3567. {
  3568. byte[] bucket = new byte[1];
  3569. bucket[0] = (byte)item.Type;
  3570. GridInstantMessage msg = new GridInstantMessage(World,
  3571. m_host.OwnerID, m_host.Name, destId,
  3572. (byte)InstantMessageDialog.TaskInventoryOffered,
  3573. false, item.Name+". "+m_host.Name+" is located at "+
  3574. World.RegionInfo.RegionName+" "+
  3575. m_host.AbsolutePosition.ToString(),
  3576. agentItem.ID, true, m_host.AbsolutePosition,
  3577. bucket, true);
  3578. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  3579. }
  3580. ScriptSleep(3000);
  3581. }
  3582. }
  3583. public void llRemoveInventory(string name)
  3584. {
  3585. m_host.AddScriptLPS(1);
  3586. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  3587. if (item == null)
  3588. return;
  3589. if (item.ItemID == m_item.ItemID)
  3590. throw new ScriptDeleteException();
  3591. else
  3592. m_host.Inventory.RemoveInventoryItem(item.ItemID);
  3593. }
  3594. public void llSetText(string text, LSL_Vector color, double alpha)
  3595. {
  3596. m_host.AddScriptLPS(1);
  3597. Vector3 av3 = Util.Clip(color, 0.0f, 1.0f);
  3598. if (text.Length > 254)
  3599. text = text.Remove(254);
  3600. byte[] data;
  3601. do
  3602. {
  3603. data = Util.UTF8.GetBytes(text);
  3604. if (data.Length > 254)
  3605. text = text.Substring(0, text.Length - 1);
  3606. } while (data.Length > 254);
  3607. m_host.SetText(text, av3, Util.Clip((float)alpha, 0.0f, 1.0f));
  3608. //m_host.ParentGroup.HasGroupChanged = true;
  3609. //m_host.ParentGroup.ScheduleGroupForFullUpdate();
  3610. }
  3611. public LSL_Float llWater(LSL_Vector offset)
  3612. {
  3613. m_host.AddScriptLPS(1);
  3614. return World.RegionInfo.RegionSettings.WaterHeight;
  3615. }
  3616. public void llPassTouches(int pass)
  3617. {
  3618. m_host.AddScriptLPS(1);
  3619. if (pass != 0)
  3620. m_host.PassTouches = true;
  3621. else
  3622. m_host.PassTouches = false;
  3623. }
  3624. public LSL_String llRequestAgentData(string id, int data)
  3625. {
  3626. m_host.AddScriptLPS(1);
  3627. UUID uuid = (UUID)id;
  3628. PresenceInfo pinfo = null;
  3629. UserAccount account;
  3630. UserInfoCacheEntry ce;
  3631. lock (m_userInfoCache)
  3632. {
  3633. if (!m_userInfoCache.TryGetValue(uuid, out ce))
  3634. {
  3635. account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
  3636. if (account == null)
  3637. {
  3638. m_userInfoCache[uuid] = null; // Cache negative
  3639. return UUID.Zero.ToString();
  3640. }
  3641. PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
  3642. if (pinfos != null && pinfos.Length > 0)
  3643. {
  3644. foreach (PresenceInfo p in pinfos)
  3645. {
  3646. if (p.RegionID != UUID.Zero)
  3647. {
  3648. pinfo = p;
  3649. }
  3650. }
  3651. }
  3652. ce = new UserInfoCacheEntry();
  3653. ce.time = Util.EnvironmentTickCount();
  3654. ce.account = account;
  3655. ce.pinfo = pinfo;
  3656. m_userInfoCache[uuid] = ce;
  3657. }
  3658. else
  3659. {
  3660. if (ce == null)
  3661. return UUID.Zero.ToString();
  3662. account = ce.account;
  3663. if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time)
  3664. >= LlRequestAgentDataCacheTimeoutMs)
  3665. {
  3666. PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
  3667. if (pinfos != null && pinfos.Length > 0)
  3668. {
  3669. foreach (PresenceInfo p in pinfos)
  3670. {
  3671. if (p.RegionID != UUID.Zero)
  3672. {
  3673. pinfo = p;
  3674. }
  3675. }
  3676. }
  3677. else
  3678. {
  3679. pinfo = null;
  3680. }
  3681. ce.time = Util.EnvironmentTickCount();
  3682. ce.pinfo = pinfo;
  3683. }
  3684. else
  3685. {
  3686. pinfo = ce.pinfo;
  3687. }
  3688. }
  3689. }
  3690. string reply = String.Empty;
  3691. switch (data)
  3692. {
  3693. case ScriptBaseClass.DATA_ONLINE:
  3694. if (pinfo != null && pinfo.RegionID != UUID.Zero)
  3695. reply = "1";
  3696. else
  3697. reply = "0";
  3698. break;
  3699. case ScriptBaseClass.DATA_NAME: // (First Last)
  3700. reply = account.FirstName + " " + account.LastName;
  3701. break;
  3702. case ScriptBaseClass.DATA_BORN: // (YYYY-MM-DD)
  3703. DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  3704. born = born.AddSeconds(account.Created);
  3705. reply = born.ToString("yyyy-MM-dd");
  3706. break;
  3707. case ScriptBaseClass.DATA_RATING: // (0,0,0,0,0,0)
  3708. reply = "0,0,0,0,0,0";
  3709. break;
  3710. case 7: // DATA_USERLEVEL (integer). This is not available in LL and so has no constant.
  3711. reply = account.UserLevel.ToString();
  3712. break;
  3713. case ScriptBaseClass.DATA_PAYINFO: // (0|1|2|3)
  3714. reply = "0";
  3715. break;
  3716. default:
  3717. return UUID.Zero.ToString(); // Raise no event
  3718. }
  3719. UUID rq = UUID.Random();
  3720. UUID tid = AsyncCommands.
  3721. DataserverPlugin.RegisterRequest(m_host.LocalId,
  3722. m_item.ItemID, rq.ToString());
  3723. AsyncCommands.
  3724. DataserverPlugin.DataserverReply(rq.ToString(), reply);
  3725. ScriptSleep(100);
  3726. return tid.ToString();
  3727. }
  3728. public LSL_String llRequestInventoryData(string name)
  3729. {
  3730. m_host.AddScriptLPS(1);
  3731. foreach (TaskInventoryItem item in m_host.Inventory.GetInventoryItems())
  3732. {
  3733. if (item.Type == 3 && item.Name == name)
  3734. {
  3735. UUID tid = AsyncCommands.
  3736. DataserverPlugin.RegisterRequest(m_host.LocalId,
  3737. m_item.ItemID, item.AssetID.ToString());
  3738. Vector3 region = new Vector3(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
  3739. World.AssetService.Get(item.AssetID.ToString(), this,
  3740. delegate(string i, object sender, AssetBase a)
  3741. {
  3742. AssetLandmark lm = new AssetLandmark(a);
  3743. float rx = (uint)(lm.RegionHandle >> 32);
  3744. float ry = (uint)lm.RegionHandle;
  3745. region = lm.Position + new Vector3(rx, ry, 0) - region;
  3746. string reply = region.ToString();
  3747. AsyncCommands.
  3748. DataserverPlugin.DataserverReply(i.ToString(),
  3749. reply);
  3750. });
  3751. ScriptSleep(1000);
  3752. return tid.ToString();
  3753. }
  3754. }
  3755. ScriptSleep(1000);
  3756. return String.Empty;
  3757. }
  3758. public void llSetDamage(double damage)
  3759. {
  3760. m_host.AddScriptLPS(1);
  3761. m_host.ParentGroup.Damage = (float)damage;
  3762. }
  3763. public void llTeleportAgentHome(string agent)
  3764. {
  3765. m_host.AddScriptLPS(1);
  3766. UUID agentId = new UUID();
  3767. if (UUID.TryParse(agent, out agentId))
  3768. {
  3769. ScenePresence presence = World.GetScenePresence(agentId);
  3770. if (presence != null)
  3771. {
  3772. // agent must be over the owners land
  3773. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  3774. {
  3775. World.TeleportClientHome(agentId, presence.ControllingClient);
  3776. }
  3777. }
  3778. }
  3779. ScriptSleep(5000);
  3780. }
  3781. public void llTeleportAgent(string agent, string destination, LSL_Vector targetPos, LSL_Vector targetLookAt)
  3782. {
  3783. m_host.AddScriptLPS(1);
  3784. UUID agentId = new UUID();
  3785. if (UUID.TryParse(agent, out agentId))
  3786. {
  3787. ScenePresence presence = World.GetScenePresence(agentId);
  3788. if (presence != null && presence.PresenceType != PresenceType.Npc)
  3789. {
  3790. // agent must not be a god
  3791. if (presence.GodLevel >= 200) return;
  3792. if (destination == String.Empty)
  3793. destination = World.RegionInfo.RegionName;
  3794. // agent must be over the owners land
  3795. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  3796. {
  3797. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  3798. }
  3799. else // or must be wearing the prim
  3800. {
  3801. if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID)
  3802. {
  3803. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  3804. }
  3805. }
  3806. }
  3807. }
  3808. }
  3809. public void llTeleportAgentGlobalCoords(string agent, LSL_Vector global_coords, LSL_Vector targetPos, LSL_Vector targetLookAt)
  3810. {
  3811. m_host.AddScriptLPS(1);
  3812. UUID agentId = new UUID();
  3813. ulong regionHandle = Util.RegionWorldLocToHandle((uint)global_coords.x, (uint)global_coords.y);
  3814. if (UUID.TryParse(agent, out agentId))
  3815. {
  3816. ScenePresence presence = World.GetScenePresence(agentId);
  3817. if (presence != null && presence.PresenceType != PresenceType.Npc)
  3818. {
  3819. // agent must not be a god
  3820. if (presence.GodLevel >= 200) return;
  3821. // agent must be over the owners land
  3822. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  3823. {
  3824. World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  3825. }
  3826. else // or must be wearing the prim
  3827. {
  3828. if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID)
  3829. {
  3830. World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  3831. }
  3832. }
  3833. }
  3834. }
  3835. }
  3836. private void DoLLTeleport(ScenePresence sp, string destination, Vector3 targetPos, Vector3 targetLookAt)
  3837. {
  3838. UUID assetID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, destination);
  3839. // The destinaion is not an asset ID and also doesn't name a landmark.
  3840. // Use it as a sim name
  3841. if (assetID == UUID.Zero)
  3842. {
  3843. World.RequestTeleportLocation(sp.ControllingClient, destination, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  3844. return;
  3845. }
  3846. AssetBase lma = World.AssetService.Get(assetID.ToString());
  3847. if (lma == null)
  3848. return;
  3849. if (lma.Type != (sbyte)AssetType.Landmark)
  3850. return;
  3851. AssetLandmark lm = new AssetLandmark(lma);
  3852. World.RequestTeleportLocation(sp.ControllingClient, lm.RegionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  3853. }
  3854. public void llTextBox(string agent, string message, int chatChannel)
  3855. {
  3856. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  3857. if (dm == null)
  3858. return;
  3859. m_host.AddScriptLPS(1);
  3860. UUID av = new UUID();
  3861. if (!UUID.TryParse(agent,out av))
  3862. {
  3863. Error("llTextBox", "First parameter must be a key");
  3864. return;
  3865. }
  3866. if (message == string.Empty)
  3867. {
  3868. Error("llTextBox", "Empty message");
  3869. }
  3870. else if (message.Length > 512)
  3871. {
  3872. Error("llTextBox", "Message more than 512 characters");
  3873. }
  3874. else
  3875. {
  3876. dm.SendTextBoxToUser(av, message, chatChannel, m_host.Name, m_host.UUID, m_host.OwnerID);
  3877. ScriptSleep(1000);
  3878. }
  3879. }
  3880. public void llModifyLand(int action, int brush)
  3881. {
  3882. m_host.AddScriptLPS(1);
  3883. ITerrainModule tm = m_ScriptEngine.World.RequestModuleInterface<ITerrainModule>();
  3884. if (tm != null)
  3885. {
  3886. tm.ModifyTerrain(m_host.OwnerID, m_host.AbsolutePosition, (byte) brush, (byte) action, m_host.OwnerID);
  3887. }
  3888. }
  3889. public void llCollisionSound(string impact_sound, double impact_volume)
  3890. {
  3891. m_host.AddScriptLPS(1);
  3892. // TODO: Parameter check logic required.
  3893. m_host.CollisionSound = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound);
  3894. m_host.CollisionSoundVolume = (float)impact_volume;
  3895. }
  3896. public LSL_String llGetAnimation(string id)
  3897. {
  3898. // This should only return a value if the avatar is in the same region
  3899. m_host.AddScriptLPS(1);
  3900. UUID avatar = (UUID)id;
  3901. ScenePresence presence = World.GetScenePresence(avatar);
  3902. if (presence == null)
  3903. return "";
  3904. if (m_host.RegionHandle == presence.RegionHandle)
  3905. {
  3906. Dictionary<UUID, string> animationstateNames = DefaultAvatarAnimations.AnimStateNames;
  3907. if (presence != null)
  3908. {
  3909. AnimationSet currentAnims = presence.Animator.Animations;
  3910. string currentAnimationState = String.Empty;
  3911. if (animationstateNames.TryGetValue(currentAnims.ImplicitDefaultAnimation.AnimID, out currentAnimationState))
  3912. return currentAnimationState;
  3913. }
  3914. }
  3915. return String.Empty;
  3916. }
  3917. public void llMessageLinked(int linknumber, int num, string msg, string id)
  3918. {
  3919. m_host.AddScriptLPS(1);
  3920. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  3921. UUID partItemID;
  3922. foreach (SceneObjectPart part in parts)
  3923. {
  3924. foreach (TaskInventoryItem item in part.Inventory.GetInventoryItems())
  3925. {
  3926. if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT)
  3927. {
  3928. partItemID = item.ItemID;
  3929. int linkNumber = m_host.LinkNum;
  3930. if (m_host.ParentGroup.PrimCount == 1)
  3931. linkNumber = 0;
  3932. object[] resobj = new object[]
  3933. {
  3934. new LSL_Integer(linkNumber), new LSL_Integer(num), new LSL_String(msg), new LSL_String(id)
  3935. };
  3936. m_ScriptEngine.PostScriptEvent(partItemID,
  3937. new EventParams("link_message",
  3938. resobj, new DetectParams[0]));
  3939. }
  3940. }
  3941. }
  3942. }
  3943. public void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local)
  3944. {
  3945. m_host.AddScriptLPS(1);
  3946. bool pushrestricted = World.RegionInfo.RegionSettings.RestrictPushing;
  3947. bool pushAllowed = false;
  3948. bool pusheeIsAvatar = false;
  3949. UUID targetID = UUID.Zero;
  3950. if (!UUID.TryParse(target,out targetID))
  3951. return;
  3952. ScenePresence pusheeav = null;
  3953. Vector3 PusheePos = Vector3.Zero;
  3954. SceneObjectPart pusheeob = null;
  3955. ScenePresence avatar = World.GetScenePresence(targetID);
  3956. if (avatar != null)
  3957. {
  3958. pusheeIsAvatar = true;
  3959. // Pushee doesn't have a physics actor
  3960. if (avatar.PhysicsActor == null)
  3961. return;
  3962. // Pushee is in GodMode this pushing object isn't owned by them
  3963. if (avatar.GodLevel > 0 && m_host.OwnerID != targetID)
  3964. return;
  3965. pusheeav = avatar;
  3966. // Find pushee position
  3967. // Pushee Linked?
  3968. SceneObjectPart sitPart = pusheeav.ParentPart;
  3969. if (sitPart != null)
  3970. PusheePos = sitPart.AbsolutePosition;
  3971. else
  3972. PusheePos = pusheeav.AbsolutePosition;
  3973. }
  3974. if (!pusheeIsAvatar)
  3975. {
  3976. // not an avatar so push is not affected by parcel flags
  3977. pusheeob = World.GetSceneObjectPart((UUID)target);
  3978. // We can't find object
  3979. if (pusheeob == null)
  3980. return;
  3981. // Object not pushable. Not an attachment and has no physics component
  3982. if (!pusheeob.ParentGroup.IsAttachment && pusheeob.PhysActor == null)
  3983. return;
  3984. PusheePos = pusheeob.AbsolutePosition;
  3985. pushAllowed = true;
  3986. }
  3987. else
  3988. {
  3989. if (pushrestricted)
  3990. {
  3991. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos);
  3992. // We didn't find the parcel but region is push restricted so assume it is NOT ok
  3993. if (targetlandObj == null)
  3994. return;
  3995. // Need provisions for Group Owned here
  3996. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  3997. targetlandObj.LandData.IsGroupOwned || m_host.OwnerID == targetID)
  3998. {
  3999. pushAllowed = true;
  4000. }
  4001. }
  4002. else
  4003. {
  4004. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos);
  4005. if (targetlandObj == null)
  4006. {
  4007. // We didn't find the parcel but region isn't push restricted so assume it's ok
  4008. pushAllowed = true;
  4009. }
  4010. else
  4011. {
  4012. // Parcel push restriction
  4013. if ((targetlandObj.LandData.Flags & (uint)ParcelFlags.RestrictPushObject) == (uint)ParcelFlags.RestrictPushObject)
  4014. {
  4015. // Need provisions for Group Owned here
  4016. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  4017. targetlandObj.LandData.IsGroupOwned ||
  4018. m_host.OwnerID == targetID)
  4019. {
  4020. pushAllowed = true;
  4021. }
  4022. //ParcelFlags.RestrictPushObject
  4023. //pushAllowed = true;
  4024. }
  4025. else
  4026. {
  4027. // Parcel isn't push restricted
  4028. pushAllowed = true;
  4029. }
  4030. }
  4031. }
  4032. }
  4033. if (pushAllowed)
  4034. {
  4035. float distance = (PusheePos - m_host.AbsolutePosition).Length();
  4036. float distance_term = distance * distance * distance; // Script Energy
  4037. float pusher_mass = m_host.GetMass();
  4038. float PUSH_ATTENUATION_DISTANCE = 17f;
  4039. float PUSH_ATTENUATION_SCALE = 5f;
  4040. float distance_attenuation = 1f;
  4041. if (distance > PUSH_ATTENUATION_DISTANCE)
  4042. {
  4043. float normalized_units = 1f + (distance - PUSH_ATTENUATION_DISTANCE) / PUSH_ATTENUATION_SCALE;
  4044. distance_attenuation = 1f / normalized_units;
  4045. }
  4046. Vector3 applied_linear_impulse = impulse;
  4047. {
  4048. float impulse_length = applied_linear_impulse.Length();
  4049. float desired_energy = impulse_length * pusher_mass;
  4050. if (desired_energy > 0f)
  4051. desired_energy += distance_term;
  4052. float scaling_factor = 1f;
  4053. scaling_factor *= distance_attenuation;
  4054. applied_linear_impulse *= scaling_factor;
  4055. }
  4056. if (pusheeIsAvatar)
  4057. {
  4058. if (pusheeav != null)
  4059. {
  4060. PhysicsActor pa = pusheeav.PhysicsActor;
  4061. if (pa != null)
  4062. {
  4063. if (local != 0)
  4064. {
  4065. applied_linear_impulse *= m_host.GetWorldRotation();
  4066. }
  4067. pa.AddForce(applied_linear_impulse, true);
  4068. }
  4069. }
  4070. }
  4071. else
  4072. {
  4073. if (pusheeob != null)
  4074. {
  4075. if (pusheeob.PhysActor != null)
  4076. {
  4077. pusheeob.ApplyImpulse(applied_linear_impulse, local != 0);
  4078. }
  4079. }
  4080. }
  4081. }
  4082. }
  4083. public void llPassCollisions(int pass)
  4084. {
  4085. m_host.AddScriptLPS(1);
  4086. if (pass == 0)
  4087. {
  4088. m_host.PassCollisions = false;
  4089. }
  4090. else
  4091. {
  4092. m_host.PassCollisions = true;
  4093. }
  4094. }
  4095. public LSL_String llGetScriptName()
  4096. {
  4097. m_host.AddScriptLPS(1);
  4098. return m_item.Name != null ? m_item.Name : String.Empty;
  4099. }
  4100. public LSL_Integer llGetLinkNumberOfSides(int link)
  4101. {
  4102. m_host.AddScriptLPS(1);
  4103. SceneObjectPart linkedPart;
  4104. if (link == ScriptBaseClass.LINK_ROOT)
  4105. linkedPart = m_host.ParentGroup.RootPart;
  4106. else if (link == ScriptBaseClass.LINK_THIS)
  4107. linkedPart = m_host;
  4108. else
  4109. linkedPart = m_host.ParentGroup.GetLinkNumPart(link);
  4110. return GetNumberOfSides(linkedPart);
  4111. }
  4112. public LSL_Integer llGetNumberOfSides()
  4113. {
  4114. m_host.AddScriptLPS(1);
  4115. return GetNumberOfSides(m_host);
  4116. }
  4117. protected int GetNumberOfSides(SceneObjectPart part)
  4118. {
  4119. int sides = part.GetNumberOfSides();
  4120. if (part.GetPrimType() == PrimType.SPHERE && part.Shape.ProfileHollow > 0)
  4121. {
  4122. // Make up for a bug where LSL shows 4 sides rather than 2
  4123. sides += 2;
  4124. }
  4125. return sides;
  4126. }
  4127. /* The new / changed functions were tested with the following LSL script:
  4128. default
  4129. {
  4130. state_entry()
  4131. {
  4132. rotation rot = llEuler2Rot(<0,70,0> * DEG_TO_RAD);
  4133. llOwnerSay("to get here, we rotate over: "+ (string) llRot2Axis(rot));
  4134. llOwnerSay("and we rotate for: "+ (llRot2Angle(rot) * RAD_TO_DEG));
  4135. // convert back and forth between quaternion <-> vector and angle
  4136. rotation newrot = llAxisAngle2Rot(llRot2Axis(rot),llRot2Angle(rot));
  4137. llOwnerSay("Old rotation was: "+(string) rot);
  4138. llOwnerSay("re-converted rotation is: "+(string) newrot);
  4139. llSetRot(rot); // to check the parameters in the prim
  4140. }
  4141. }
  4142. */
  4143. // Xantor 29/apr/2008
  4144. // Returns rotation described by rotating angle radians about axis.
  4145. // q = cos(a/2) + i (x * sin(a/2)) + j (y * sin(a/2)) + k (z * sin(a/2))
  4146. public LSL_Rotation llAxisAngle2Rot(LSL_Vector axis, double angle)
  4147. {
  4148. m_host.AddScriptLPS(1);
  4149. double x, y, z, s, t;
  4150. s = Math.Cos(angle * 0.5);
  4151. t = Math.Sin(angle * 0.5); // temp value to avoid 2 more sin() calcs
  4152. axis = LSL_Vector.Norm(axis);
  4153. x = axis.x * t;
  4154. y = axis.y * t;
  4155. z = axis.z * t;
  4156. return new LSL_Rotation(x,y,z,s);
  4157. }
  4158. /// <summary>
  4159. /// Returns the axis of rotation for a quaternion
  4160. /// </summary>
  4161. /// <returns></returns>
  4162. /// <param name='rot'></param>
  4163. public LSL_Vector llRot2Axis(LSL_Rotation rot)
  4164. {
  4165. m_host.AddScriptLPS(1);
  4166. if (Math.Abs(rot.s) > 1) // normalization needed
  4167. rot.Normalize();
  4168. double s = Math.Sqrt(1 - rot.s * rot.s);
  4169. if (s < 0.001)
  4170. {
  4171. return new LSL_Vector(1, 0, 0);
  4172. }
  4173. else
  4174. {
  4175. double invS = 1.0 / s;
  4176. if (rot.s < 0) invS = -invS;
  4177. return new LSL_Vector(rot.x * invS, rot.y * invS, rot.z * invS);
  4178. }
  4179. }
  4180. // Returns the angle of a quaternion (see llRot2Axis for the axis)
  4181. public LSL_Float llRot2Angle(LSL_Rotation rot)
  4182. {
  4183. m_host.AddScriptLPS(1);
  4184. if (Math.Abs(rot.s) > 1) // normalization needed
  4185. rot.Normalize();
  4186. double angle = 2 * Math.Acos(rot.s);
  4187. if (angle > Math.PI)
  4188. angle = 2 * Math.PI - angle;
  4189. return angle;
  4190. }
  4191. public LSL_Float llAcos(double val)
  4192. {
  4193. m_host.AddScriptLPS(1);
  4194. return (double)Math.Acos(val);
  4195. }
  4196. public LSL_Float llAsin(double val)
  4197. {
  4198. m_host.AddScriptLPS(1);
  4199. return (double)Math.Asin(val);
  4200. }
  4201. // jcochran 5/jan/2012
  4202. public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b)
  4203. {
  4204. m_host.AddScriptLPS(1);
  4205. double aa = (a.x * a.x + a.y * a.y + a.z * a.z + a.s * a.s);
  4206. double bb = (b.x * b.x + b.y * b.y + b.z * b.z + b.s * b.s);
  4207. double aa_bb = aa * bb;
  4208. if (aa_bb == 0) return 0.0;
  4209. double ab = (a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s);
  4210. double quotient = (ab * ab) / aa_bb;
  4211. if (quotient >= 1.0) return 0.0;
  4212. return Math.Acos(2 * quotient - 1);
  4213. }
  4214. public LSL_String llGetInventoryKey(string name)
  4215. {
  4216. m_host.AddScriptLPS(1);
  4217. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  4218. if (item == null)
  4219. return UUID.Zero.ToString();
  4220. if ((item.CurrentPermissions
  4221. & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  4222. == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  4223. {
  4224. return item.AssetID.ToString();
  4225. }
  4226. return UUID.Zero.ToString();
  4227. }
  4228. public void llAllowInventoryDrop(int add)
  4229. {
  4230. m_host.AddScriptLPS(1);
  4231. if (add != 0)
  4232. m_host.ParentGroup.RootPart.AllowedDrop = true;
  4233. else
  4234. m_host.ParentGroup.RootPart.AllowedDrop = false;
  4235. // Update the object flags
  4236. m_host.ParentGroup.RootPart.aggregateScriptEvents();
  4237. }
  4238. public LSL_Vector llGetSunDirection()
  4239. {
  4240. m_host.AddScriptLPS(1);
  4241. LSL_Vector SunDoubleVector3;
  4242. Vector3 SunFloatVector3;
  4243. // sunPosition estate setting is set in OpenSim.Region.CoreModules.SunModule
  4244. // have to convert from Vector3 (float) to LSL_Vector (double)
  4245. SunFloatVector3 = World.RegionInfo.RegionSettings.SunVector;
  4246. SunDoubleVector3.x = (double)SunFloatVector3.X;
  4247. SunDoubleVector3.y = (double)SunFloatVector3.Y;
  4248. SunDoubleVector3.z = (double)SunFloatVector3.Z;
  4249. return SunDoubleVector3;
  4250. }
  4251. public LSL_Vector llGetTextureOffset(int face)
  4252. {
  4253. m_host.AddScriptLPS(1);
  4254. return GetTextureOffset(m_host, face);
  4255. }
  4256. protected LSL_Vector GetTextureOffset(SceneObjectPart part, int face)
  4257. {
  4258. Primitive.TextureEntry tex = part.Shape.Textures;
  4259. LSL_Vector offset = new LSL_Vector();
  4260. if (face == ScriptBaseClass.ALL_SIDES)
  4261. {
  4262. face = 0;
  4263. }
  4264. if (face >= 0 && face < GetNumberOfSides(part))
  4265. {
  4266. offset.x = tex.GetFace((uint)face).OffsetU;
  4267. offset.y = tex.GetFace((uint)face).OffsetV;
  4268. offset.z = 0.0;
  4269. return offset;
  4270. }
  4271. else
  4272. {
  4273. return offset;
  4274. }
  4275. }
  4276. public LSL_Vector llGetTextureScale(int side)
  4277. {
  4278. m_host.AddScriptLPS(1);
  4279. Primitive.TextureEntry tex = m_host.Shape.Textures;
  4280. LSL_Vector scale;
  4281. if (side == -1)
  4282. {
  4283. side = 0;
  4284. }
  4285. scale.x = tex.GetFace((uint)side).RepeatU;
  4286. scale.y = tex.GetFace((uint)side).RepeatV;
  4287. scale.z = 0.0;
  4288. return scale;
  4289. }
  4290. public LSL_Float llGetTextureRot(int face)
  4291. {
  4292. m_host.AddScriptLPS(1);
  4293. return GetTextureRot(m_host, face);
  4294. }
  4295. protected LSL_Float GetTextureRot(SceneObjectPart part, int face)
  4296. {
  4297. Primitive.TextureEntry tex = part.Shape.Textures;
  4298. if (face == -1)
  4299. {
  4300. face = 0;
  4301. }
  4302. if (face >= 0 && face < GetNumberOfSides(part))
  4303. {
  4304. return tex.GetFace((uint)face).Rotation;
  4305. }
  4306. else
  4307. {
  4308. return 0.0;
  4309. }
  4310. }
  4311. public LSL_Integer llSubStringIndex(string source, string pattern)
  4312. {
  4313. m_host.AddScriptLPS(1);
  4314. return source.IndexOf(pattern);
  4315. }
  4316. public LSL_String llGetOwnerKey(string id)
  4317. {
  4318. m_host.AddScriptLPS(1);
  4319. UUID key = new UUID();
  4320. if (UUID.TryParse(id, out key))
  4321. {
  4322. try
  4323. {
  4324. SceneObjectPart obj = World.GetSceneObjectPart(key);
  4325. if (obj == null)
  4326. return id; // the key is for an agent so just return the key
  4327. else
  4328. return obj.OwnerID.ToString();
  4329. }
  4330. catch (KeyNotFoundException)
  4331. {
  4332. return id; // The Object/Agent not in the region so just return the key
  4333. }
  4334. }
  4335. else
  4336. {
  4337. return UUID.Zero.ToString();
  4338. }
  4339. }
  4340. public LSL_Vector llGetCenterOfMass()
  4341. {
  4342. m_host.AddScriptLPS(1);
  4343. return new LSL_Vector(m_host.GetCenterOfMass());
  4344. }
  4345. public LSL_List llListSort(LSL_List src, int stride, int ascending)
  4346. {
  4347. m_host.AddScriptLPS(1);
  4348. if (stride <= 0)
  4349. {
  4350. stride = 1;
  4351. }
  4352. return src.Sort(stride, ascending);
  4353. }
  4354. public LSL_Integer llGetListLength(LSL_List src)
  4355. {
  4356. m_host.AddScriptLPS(1);
  4357. if (src == null)
  4358. {
  4359. return 0;
  4360. }
  4361. else
  4362. {
  4363. return src.Length;
  4364. }
  4365. }
  4366. public LSL_Integer llList2Integer(LSL_List src, int index)
  4367. {
  4368. m_host.AddScriptLPS(1);
  4369. if (index < 0)
  4370. {
  4371. index = src.Length + index;
  4372. }
  4373. if (index >= src.Length || index < 0)
  4374. {
  4375. return 0;
  4376. }
  4377. // Vectors & Rotations always return zero in SL, but
  4378. // keys don't always return zero, it seems to be a bit complex.
  4379. else if (src.Data[index] is LSL_Vector ||
  4380. src.Data[index] is LSL_Rotation)
  4381. {
  4382. return 0;
  4383. }
  4384. try
  4385. {
  4386. if (src.Data[index] is LSL_Integer)
  4387. return (LSL_Integer)src.Data[index];
  4388. else if (src.Data[index] is LSL_Float)
  4389. return Convert.ToInt32(((LSL_Float)src.Data[index]).value);
  4390. return new LSL_Integer(src.Data[index].ToString());
  4391. }
  4392. catch (FormatException)
  4393. {
  4394. return 0;
  4395. }
  4396. }
  4397. public LSL_Float llList2Float(LSL_List src, int index)
  4398. {
  4399. m_host.AddScriptLPS(1);
  4400. if (index < 0)
  4401. {
  4402. index = src.Length + index;
  4403. }
  4404. if (index >= src.Length || index < 0)
  4405. {
  4406. return 0.0;
  4407. }
  4408. // Vectors & Rotations always return zero in SL
  4409. else if (src.Data[index] is LSL_Vector ||
  4410. src.Data[index] is LSL_Rotation)
  4411. {
  4412. return 0;
  4413. }
  4414. // valid keys seem to get parsed as integers then converted to floats
  4415. else
  4416. {
  4417. UUID uuidt;
  4418. if (src.Data[index] is LSL_Key && UUID.TryParse(src.Data[index].ToString(), out uuidt))
  4419. {
  4420. return Convert.ToDouble(new LSL_Integer(src.Data[index].ToString()).value);
  4421. }
  4422. }
  4423. try
  4424. {
  4425. if (src.Data[index] is LSL_Integer)
  4426. return Convert.ToDouble(((LSL_Integer)src.Data[index]).value);
  4427. else if (src.Data[index] is LSL_Float)
  4428. return Convert.ToDouble(((LSL_Float)src.Data[index]).value);
  4429. else if (src.Data[index] is LSL_String)
  4430. return Convert.ToDouble(((LSL_String)src.Data[index]).m_string);
  4431. return Convert.ToDouble(src.Data[index]);
  4432. }
  4433. catch (FormatException)
  4434. {
  4435. return 0.0;
  4436. }
  4437. }
  4438. public LSL_String llList2String(LSL_List src, int index)
  4439. {
  4440. m_host.AddScriptLPS(1);
  4441. if (index < 0)
  4442. {
  4443. index = src.Length + index;
  4444. }
  4445. if (index >= src.Length || index < 0)
  4446. {
  4447. return String.Empty;
  4448. }
  4449. return src.Data[index].ToString();
  4450. }
  4451. public LSL_Key llList2Key(LSL_List src, int index)
  4452. {
  4453. m_host.AddScriptLPS(1);
  4454. if (index < 0)
  4455. {
  4456. index = src.Length + index;
  4457. }
  4458. if (index >= src.Length || index < 0)
  4459. {
  4460. return "";
  4461. }
  4462. // SL spits out an empty string for types other than key & string
  4463. // At the time of patching, LSL_Key is currently LSL_String,
  4464. // so the OR check may be a little redundant, but it's being done
  4465. // for completion and should LSL_Key ever be implemented
  4466. // as it's own struct
  4467. // NOTE: 3rd case is needed because a NULL_KEY comes through as
  4468. // type 'obj' and wrongly returns ""
  4469. else if (!(src.Data[index] is LSL_String ||
  4470. src.Data[index] is LSL_Key ||
  4471. src.Data[index].ToString() == "00000000-0000-0000-0000-000000000000"))
  4472. {
  4473. return "";
  4474. }
  4475. return src.Data[index].ToString();
  4476. }
  4477. public LSL_Vector llList2Vector(LSL_List src, int index)
  4478. {
  4479. m_host.AddScriptLPS(1);
  4480. if (index < 0)
  4481. {
  4482. index = src.Length + index;
  4483. }
  4484. if (index >= src.Length || index < 0)
  4485. {
  4486. return new LSL_Vector(0, 0, 0);
  4487. }
  4488. if (src.Data[index].GetType() == typeof(LSL_Vector))
  4489. {
  4490. return (LSL_Vector)src.Data[index];
  4491. }
  4492. // SL spits always out ZERO_VECTOR for anything other than
  4493. // strings or vectors. Although keys always return ZERO_VECTOR,
  4494. // it is currently difficult to make the distinction between
  4495. // a string, a key as string and a string that by coincidence
  4496. // is a string, so we're going to leave that up to the
  4497. // LSL_Vector constructor.
  4498. else if (!(src.Data[index] is LSL_String ||
  4499. src.Data[index] is LSL_Vector))
  4500. {
  4501. return new LSL_Vector(0, 0, 0);
  4502. }
  4503. else
  4504. {
  4505. return new LSL_Vector(src.Data[index].ToString());
  4506. }
  4507. }
  4508. public LSL_Rotation llList2Rot(LSL_List src, int index)
  4509. {
  4510. m_host.AddScriptLPS(1);
  4511. if (index < 0)
  4512. {
  4513. index = src.Length + index;
  4514. }
  4515. if (index >= src.Length || index < 0)
  4516. {
  4517. return new LSL_Rotation(0, 0, 0, 1);
  4518. }
  4519. // SL spits always out ZERO_ROTATION for anything other than
  4520. // strings or vectors. Although keys always return ZERO_ROTATION,
  4521. // it is currently difficult to make the distinction between
  4522. // a string, a key as string and a string that by coincidence
  4523. // is a string, so we're going to leave that up to the
  4524. // LSL_Rotation constructor.
  4525. else if (!(src.Data[index] is LSL_String ||
  4526. src.Data[index] is LSL_Rotation))
  4527. {
  4528. return new LSL_Rotation(0, 0, 0, 1);
  4529. }
  4530. else if (src.Data[index].GetType() == typeof(LSL_Rotation))
  4531. {
  4532. return (LSL_Rotation)src.Data[index];
  4533. }
  4534. else
  4535. {
  4536. return new LSL_Rotation(src.Data[index].ToString());
  4537. }
  4538. }
  4539. public LSL_List llList2List(LSL_List src, int start, int end)
  4540. {
  4541. m_host.AddScriptLPS(1);
  4542. return src.GetSublist(start, end);
  4543. }
  4544. public LSL_List llDeleteSubList(LSL_List src, int start, int end)
  4545. {
  4546. return src.DeleteSublist(start, end);
  4547. }
  4548. public LSL_Integer llGetListEntryType(LSL_List src, int index)
  4549. {
  4550. m_host.AddScriptLPS(1);
  4551. if (index < 0)
  4552. {
  4553. index = src.Length + index;
  4554. }
  4555. if (index >= src.Length)
  4556. {
  4557. return 0;
  4558. }
  4559. if (src.Data[index] is LSL_Integer || src.Data[index] is Int32)
  4560. return 1;
  4561. if (src.Data[index] is LSL_Float || src.Data[index] is Single || src.Data[index] is Double)
  4562. return 2;
  4563. if (src.Data[index] is LSL_String || src.Data[index] is String)
  4564. {
  4565. UUID tuuid;
  4566. if (UUID.TryParse(src.Data[index].ToString(), out tuuid))
  4567. {
  4568. return 4;
  4569. }
  4570. else
  4571. {
  4572. return 3;
  4573. }
  4574. }
  4575. if (src.Data[index] is LSL_Vector)
  4576. return 5;
  4577. if (src.Data[index] is LSL_Rotation)
  4578. return 6;
  4579. if (src.Data[index] is LSL_List)
  4580. return 7;
  4581. return 0;
  4582. }
  4583. /// <summary>
  4584. /// Process the supplied list and return the
  4585. /// content of the list formatted as a comma
  4586. /// separated list. There is a space after
  4587. /// each comma.
  4588. /// </summary>
  4589. public LSL_String llList2CSV(LSL_List src)
  4590. {
  4591. m_host.AddScriptLPS(1);
  4592. return string.Join(", ",
  4593. (new List<object>(src.Data)).ConvertAll<string>(o =>
  4594. {
  4595. return o.ToString();
  4596. }).ToArray());
  4597. }
  4598. /// <summary>
  4599. /// The supplied string is scanned for commas
  4600. /// and converted into a list. Commas are only
  4601. /// effective if they are encountered outside
  4602. /// of '<' '>' delimiters. Any whitespace
  4603. /// before or after an element is trimmed.
  4604. /// </summary>
  4605. public LSL_List llCSV2List(string src)
  4606. {
  4607. LSL_List result = new LSL_List();
  4608. int parens = 0;
  4609. int start = 0;
  4610. int length = 0;
  4611. m_host.AddScriptLPS(1);
  4612. for (int i = 0; i < src.Length; i++)
  4613. {
  4614. switch (src[i])
  4615. {
  4616. case '<':
  4617. parens++;
  4618. length++;
  4619. break;
  4620. case '>':
  4621. if (parens > 0)
  4622. parens--;
  4623. length++;
  4624. break;
  4625. case ',':
  4626. if (parens == 0)
  4627. {
  4628. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  4629. start += length+1;
  4630. length = 0;
  4631. }
  4632. else
  4633. {
  4634. length++;
  4635. }
  4636. break;
  4637. default:
  4638. length++;
  4639. break;
  4640. }
  4641. }
  4642. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  4643. return result;
  4644. }
  4645. /// <summary>
  4646. /// Randomizes the list, be arbitrarily reordering
  4647. /// sublists of stride elements. As the stride approaches
  4648. /// the size of the list, the options become very
  4649. /// limited.
  4650. /// </summary>
  4651. /// <remarks>
  4652. /// This could take a while for very large list
  4653. /// sizes.
  4654. /// </remarks>
  4655. public LSL_List llListRandomize(LSL_List src, int stride)
  4656. {
  4657. LSL_List result;
  4658. Random rand = new Random();
  4659. int chunkk;
  4660. int[] chunks;
  4661. m_host.AddScriptLPS(1);
  4662. if (stride <= 0)
  4663. {
  4664. stride = 1;
  4665. }
  4666. // Stride MUST be a factor of the list length
  4667. // If not, then return the src list. This also
  4668. // traps those cases where stride > length.
  4669. if (src.Length != stride && src.Length%stride == 0)
  4670. {
  4671. chunkk = src.Length/stride;
  4672. chunks = new int[chunkk];
  4673. for (int i = 0; i < chunkk; i++)
  4674. chunks[i] = i;
  4675. // Knuth shuffle the chunkk index
  4676. for (int i = chunkk - 1; i >= 1; i--)
  4677. {
  4678. // Elect an unrandomized chunk to swap
  4679. int index = rand.Next(i + 1);
  4680. int tmp;
  4681. // and swap position with first unrandomized chunk
  4682. tmp = chunks[i];
  4683. chunks[i] = chunks[index];
  4684. chunks[index] = tmp;
  4685. }
  4686. // Construct the randomized list
  4687. result = new LSL_List();
  4688. for (int i = 0; i < chunkk; i++)
  4689. {
  4690. for (int j = 0; j < stride; j++)
  4691. {
  4692. result.Add(src.Data[chunks[i]*stride+j]);
  4693. }
  4694. }
  4695. }
  4696. else {
  4697. object[] array = new object[src.Length];
  4698. Array.Copy(src.Data, 0, array, 0, src.Length);
  4699. result = new LSL_List(array);
  4700. }
  4701. return result;
  4702. }
  4703. /// <summary>
  4704. /// Elements in the source list starting with 0 and then
  4705. /// every i+stride. If the stride is negative then the scan
  4706. /// is backwards producing an inverted result.
  4707. /// Only those elements that are also in the specified
  4708. /// range are included in the result.
  4709. /// </summary>
  4710. public LSL_List llList2ListStrided(LSL_List src, int start, int end, int stride)
  4711. {
  4712. LSL_List result = new LSL_List();
  4713. int[] si = new int[2];
  4714. int[] ei = new int[2];
  4715. bool twopass = false;
  4716. m_host.AddScriptLPS(1);
  4717. // First step is always to deal with negative indices
  4718. if (start < 0)
  4719. start = src.Length+start;
  4720. if (end < 0)
  4721. end = src.Length+end;
  4722. // Out of bounds indices are OK, just trim them
  4723. // accordingly
  4724. if (start > src.Length)
  4725. start = src.Length;
  4726. if (end > src.Length)
  4727. end = src.Length;
  4728. if (stride == 0)
  4729. stride = 1;
  4730. // There may be one or two ranges to be considered
  4731. if (start != end)
  4732. {
  4733. if (start <= end)
  4734. {
  4735. si[0] = start;
  4736. ei[0] = end;
  4737. }
  4738. else
  4739. {
  4740. si[1] = start;
  4741. ei[1] = src.Length;
  4742. si[0] = 0;
  4743. ei[0] = end;
  4744. twopass = true;
  4745. }
  4746. // The scan always starts from the beginning of the
  4747. // source list, but members are only selected if they
  4748. // fall within the specified sub-range. The specified
  4749. // range values are inclusive.
  4750. // A negative stride reverses the direction of the
  4751. // scan producing an inverted list as a result.
  4752. if (stride > 0)
  4753. {
  4754. for (int i = 0; i < src.Length; i += stride)
  4755. {
  4756. if (i<=ei[0] && i>=si[0])
  4757. result.Add(src.Data[i]);
  4758. if (twopass && i>=si[1] && i<=ei[1])
  4759. result.Add(src.Data[i]);
  4760. }
  4761. }
  4762. else if (stride < 0)
  4763. {
  4764. for (int i = src.Length - 1; i >= 0; i += stride)
  4765. {
  4766. if (i <= ei[0] && i >= si[0])
  4767. result.Add(src.Data[i]);
  4768. if (twopass && i >= si[1] && i <= ei[1])
  4769. result.Add(src.Data[i]);
  4770. }
  4771. }
  4772. }
  4773. else
  4774. {
  4775. if (start%stride == 0)
  4776. {
  4777. result.Add(src.Data[start]);
  4778. }
  4779. }
  4780. return result;
  4781. }
  4782. public LSL_Integer llGetRegionAgentCount()
  4783. {
  4784. m_host.AddScriptLPS(1);
  4785. return new LSL_Integer(World.GetRootAgentCount());
  4786. }
  4787. public LSL_Vector llGetRegionCorner()
  4788. {
  4789. m_host.AddScriptLPS(1);
  4790. return new LSL_Vector(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
  4791. }
  4792. /// <summary>
  4793. /// Insert the list identified by <paramref name="src"/> into the
  4794. /// list designated by <paramref name="dest"/> such that the first
  4795. /// new element has the index specified by <paramref name="index"/>
  4796. /// </summary>
  4797. public LSL_List llListInsertList(LSL_List dest, LSL_List src, int index)
  4798. {
  4799. LSL_List pref = null;
  4800. LSL_List suff = null;
  4801. m_host.AddScriptLPS(1);
  4802. if (index < 0)
  4803. {
  4804. index = index+dest.Length;
  4805. if (index < 0)
  4806. {
  4807. index = 0;
  4808. }
  4809. }
  4810. if (index != 0)
  4811. {
  4812. pref = dest.GetSublist(0,index-1);
  4813. if (index < dest.Length)
  4814. {
  4815. suff = dest.GetSublist(index,-1);
  4816. return pref + src + suff;
  4817. }
  4818. else
  4819. {
  4820. return pref + src;
  4821. }
  4822. }
  4823. else
  4824. {
  4825. if (index < dest.Length)
  4826. {
  4827. suff = dest.GetSublist(index,-1);
  4828. return src + suff;
  4829. }
  4830. else
  4831. {
  4832. return src;
  4833. }
  4834. }
  4835. }
  4836. /// <summary>
  4837. /// Returns the index of the first occurrence of test
  4838. /// in src.
  4839. /// </summary>
  4840. /// <param name="src">Source list</param>
  4841. /// <param name="test">List to search for</param>
  4842. /// <returns>
  4843. /// The index number of the point in src where test was found if it was found.
  4844. /// Otherwise returns -1
  4845. /// </returns>
  4846. public LSL_Integer llListFindList(LSL_List src, LSL_List test)
  4847. {
  4848. int index = -1;
  4849. int length = src.Length - test.Length + 1;
  4850. m_host.AddScriptLPS(1);
  4851. // If either list is empty, do not match
  4852. if (src.Length != 0 && test.Length != 0)
  4853. {
  4854. for (int i = 0; i < length; i++)
  4855. {
  4856. // Why this piece of insanity? This is because most script constants are C# value types (e.g. int)
  4857. // rather than wrapped LSL types. Such a script constant does not have int.Equal(LSL_Integer) code
  4858. // and so the comparison fails even if the LSL_Integer conceptually has the same value.
  4859. // Therefore, here we test Equals on both the source and destination objects.
  4860. // However, a future better approach may be use LSL struct script constants (e.g. LSL_Integer(1)).
  4861. if (src.Data[i].Equals(test.Data[0]) || test.Data[0].Equals(src.Data[i]))
  4862. {
  4863. int j;
  4864. for (j = 1; j < test.Length; j++)
  4865. if (!(src.Data[i+j].Equals(test.Data[j]) || test.Data[j].Equals(src.Data[i+j])))
  4866. break;
  4867. if (j == test.Length)
  4868. {
  4869. index = i;
  4870. break;
  4871. }
  4872. }
  4873. }
  4874. }
  4875. return index;
  4876. }
  4877. public LSL_String llGetObjectName()
  4878. {
  4879. m_host.AddScriptLPS(1);
  4880. return m_host.Name !=null ? m_host.Name : String.Empty;
  4881. }
  4882. public void llSetObjectName(string name)
  4883. {
  4884. m_host.AddScriptLPS(1);
  4885. m_host.Name = name != null ? name : String.Empty;
  4886. }
  4887. public LSL_String llGetDate()
  4888. {
  4889. m_host.AddScriptLPS(1);
  4890. DateTime date = DateTime.Now.ToUniversalTime();
  4891. string result = date.ToString("yyyy-MM-dd");
  4892. return result;
  4893. }
  4894. public LSL_Integer llEdgeOfWorld(LSL_Vector pos, LSL_Vector dir)
  4895. {
  4896. m_host.AddScriptLPS(1);
  4897. // edge will be used to pass the Region Coordinates offset
  4898. // we want to check for a neighboring sim
  4899. LSL_Vector edge = new LSL_Vector(0, 0, 0);
  4900. if (dir.x == 0)
  4901. {
  4902. if (dir.y == 0)
  4903. {
  4904. // Direction vector is 0,0 so return
  4905. // false since we're staying in the sim
  4906. return 0;
  4907. }
  4908. else
  4909. {
  4910. // Y is the only valid direction
  4911. edge.y = dir.y / Math.Abs(dir.y);
  4912. }
  4913. }
  4914. else
  4915. {
  4916. LSL_Float mag;
  4917. if (dir.x > 0)
  4918. {
  4919. mag = (World.RegionInfo.RegionSizeX - pos.x) / dir.x;
  4920. }
  4921. else
  4922. {
  4923. mag = (pos.x/dir.x);
  4924. }
  4925. mag = Math.Abs(mag);
  4926. edge.y = pos.y + (dir.y * mag);
  4927. if (edge.y > World.RegionInfo.RegionSizeY || edge.y < 0)
  4928. {
  4929. // Y goes out of bounds first
  4930. edge.y = dir.y / Math.Abs(dir.y);
  4931. }
  4932. else
  4933. {
  4934. // X goes out of bounds first or its a corner exit
  4935. edge.y = 0;
  4936. edge.x = dir.x / Math.Abs(dir.x);
  4937. }
  4938. }
  4939. List<GridRegion> neighbors = World.GridService.GetNeighbours(World.RegionInfo.ScopeID, World.RegionInfo.RegionID);
  4940. uint neighborX = World.RegionInfo.RegionLocX + (uint)dir.x;
  4941. uint neighborY = World.RegionInfo.RegionLocY + (uint)dir.y;
  4942. foreach (GridRegion sri in neighbors)
  4943. {
  4944. if (sri.RegionCoordX == neighborX && sri.RegionCoordY == neighborY)
  4945. return 0;
  4946. }
  4947. return 1;
  4948. }
  4949. /// <summary>
  4950. /// Not fully implemented yet. Still to do:-
  4951. /// AGENT_BUSY
  4952. /// Remove as they are done
  4953. /// </summary>
  4954. public LSL_Integer llGetAgentInfo(string id)
  4955. {
  4956. m_host.AddScriptLPS(1);
  4957. UUID key = new UUID();
  4958. if (!UUID.TryParse(id, out key))
  4959. {
  4960. return 0;
  4961. }
  4962. int flags = 0;
  4963. ScenePresence agent = World.GetScenePresence(key);
  4964. if (agent == null)
  4965. {
  4966. return 0;
  4967. }
  4968. if (agent.IsChildAgent)
  4969. return 0; // Fail if they are not in the same region
  4970. // note: in OpenSim, sitting seems to cancel AGENT_ALWAYS_RUN, unlike SL
  4971. if (agent.SetAlwaysRun)
  4972. {
  4973. flags |= ScriptBaseClass.AGENT_ALWAYS_RUN;
  4974. }
  4975. if (agent.HasAttachments())
  4976. {
  4977. flags |= ScriptBaseClass.AGENT_ATTACHMENTS;
  4978. if (agent.HasScriptedAttachments())
  4979. flags |= ScriptBaseClass.AGENT_SCRIPTED;
  4980. }
  4981. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0)
  4982. {
  4983. flags |= ScriptBaseClass.AGENT_FLYING;
  4984. flags |= ScriptBaseClass.AGENT_IN_AIR; // flying always implies in-air, even if colliding with e.g. a wall
  4985. }
  4986. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AWAY) != 0)
  4987. {
  4988. flags |= ScriptBaseClass.AGENT_AWAY;
  4989. }
  4990. // seems to get unset, even if in mouselook, when avatar is sitting on a prim???
  4991. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  4992. {
  4993. flags |= ScriptBaseClass.AGENT_MOUSELOOK;
  4994. }
  4995. if ((agent.State & (byte)AgentState.Typing) != (byte)0)
  4996. {
  4997. flags |= ScriptBaseClass.AGENT_TYPING;
  4998. }
  4999. string agentMovementAnimation = agent.Animator.CurrentMovementAnimation;
  5000. if (agentMovementAnimation == "CROUCH")
  5001. {
  5002. flags |= ScriptBaseClass.AGENT_CROUCHING;
  5003. }
  5004. if (agentMovementAnimation == "WALK" || agentMovementAnimation == "CROUCHWALK")
  5005. {
  5006. flags |= ScriptBaseClass.AGENT_WALKING;
  5007. }
  5008. // not colliding implies in air. Note: flying also implies in-air, even if colliding (see above)
  5009. // note: AGENT_IN_AIR and AGENT_WALKING seem to be mutually exclusive states in SL.
  5010. // note: this may need some tweaking when walking downhill. you "fall down" for a brief instant
  5011. // and don't collide when walking downhill, which instantly registers as in-air, briefly. should
  5012. // there be some minimum non-collision threshold time before claiming the avatar is in-air?
  5013. if ((flags & ScriptBaseClass.AGENT_WALKING) == 0 && !agent.IsColliding )
  5014. {
  5015. flags |= ScriptBaseClass.AGENT_IN_AIR;
  5016. }
  5017. if (agent.ParentPart != null)
  5018. {
  5019. flags |= ScriptBaseClass.AGENT_ON_OBJECT;
  5020. flags |= ScriptBaseClass.AGENT_SITTING;
  5021. }
  5022. if (agent.Animator.Animations.ImplicitDefaultAnimation.AnimID
  5023. == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  5024. {
  5025. flags |= ScriptBaseClass.AGENT_SITTING;
  5026. }
  5027. return flags;
  5028. }
  5029. public LSL_String llGetAgentLanguage(string id)
  5030. {
  5031. // This should only return a value if the avatar is in the same region
  5032. //ckrinke 1-30-09 : This needs to parse the XMLRPC language field supplied
  5033. //by the client at login. Currently returning only en-us until our I18N
  5034. //effort gains momentum
  5035. m_host.AddScriptLPS(1);
  5036. return "en-us";
  5037. }
  5038. /// <summary>
  5039. /// http://wiki.secondlife.com/wiki/LlGetAgentList
  5040. /// The list of options is currently not used in SL
  5041. /// scope is one of:-
  5042. /// AGENT_LIST_REGION - all in the region
  5043. /// AGENT_LIST_PARCEL - all in the same parcel as the scripted object
  5044. /// AGENT_LIST_PARCEL_OWNER - all in any parcel owned by the owner of the
  5045. /// current parcel.
  5046. /// </summary>
  5047. public LSL_List llGetAgentList(LSL_Integer scope, LSL_List options)
  5048. {
  5049. m_host.AddScriptLPS(1);
  5050. // the constants are 1, 2 and 4 so bits are being set, but you
  5051. // get an error "INVALID_SCOPE" if it is anything but 1, 2 and 4
  5052. bool regionWide = scope == ScriptBaseClass.AGENT_LIST_REGION;
  5053. bool parcelOwned = scope == ScriptBaseClass.AGENT_LIST_PARCEL_OWNER;
  5054. bool parcel = scope == ScriptBaseClass.AGENT_LIST_PARCEL;
  5055. LSL_List result = new LSL_List();
  5056. if (!regionWide && !parcelOwned && !parcel)
  5057. {
  5058. result.Add("INVALID_SCOPE");
  5059. return result;
  5060. }
  5061. ILandObject land;
  5062. UUID id = UUID.Zero;
  5063. if (parcel || parcelOwned)
  5064. {
  5065. land = World.LandChannel.GetLandObject(m_host.ParentGroup.RootPart.GetWorldPosition());
  5066. if (land == null)
  5067. {
  5068. id = UUID.Zero;
  5069. }
  5070. else
  5071. {
  5072. if (parcelOwned)
  5073. {
  5074. id = land.LandData.OwnerID;
  5075. }
  5076. else
  5077. {
  5078. id = land.LandData.GlobalID;
  5079. }
  5080. }
  5081. }
  5082. World.ForEachRootScenePresence(
  5083. delegate (ScenePresence ssp)
  5084. {
  5085. // Gods are not listed in SL
  5086. if (!ssp.IsDeleted && ssp.GodLevel == 0.0 && !ssp.IsChildAgent)
  5087. {
  5088. if (!regionWide)
  5089. {
  5090. land = World.LandChannel.GetLandObject(ssp.AbsolutePosition);
  5091. if (land != null)
  5092. {
  5093. if (parcelOwned && land.LandData.OwnerID == id ||
  5094. parcel && land.LandData.GlobalID == id)
  5095. {
  5096. result.Add(new LSL_Key(ssp.UUID.ToString()));
  5097. }
  5098. }
  5099. }
  5100. else
  5101. {
  5102. result.Add(new LSL_Key(ssp.UUID.ToString()));
  5103. }
  5104. }
  5105. // Maximum of 100 results
  5106. if (result.Length > 99)
  5107. {
  5108. return;
  5109. }
  5110. }
  5111. );
  5112. return result;
  5113. }
  5114. public void llAdjustSoundVolume(double volume)
  5115. {
  5116. m_host.AddScriptLPS(1);
  5117. m_host.AdjustSoundGain(volume);
  5118. ScriptSleep(100);
  5119. }
  5120. public void llSetSoundRadius(double radius)
  5121. {
  5122. m_host.AddScriptLPS(1);
  5123. m_host.SoundRadius = radius;
  5124. }
  5125. public LSL_String llKey2Name(string id)
  5126. {
  5127. m_host.AddScriptLPS(1);
  5128. UUID key = new UUID();
  5129. if (UUID.TryParse(id,out key))
  5130. {
  5131. ScenePresence presence = World.GetScenePresence(key);
  5132. if (presence != null)
  5133. {
  5134. return presence.ControllingClient.Name;
  5135. //return presence.Name;
  5136. }
  5137. if (World.GetSceneObjectPart(key) != null)
  5138. {
  5139. return World.GetSceneObjectPart(key).Name;
  5140. }
  5141. }
  5142. return String.Empty;
  5143. }
  5144. public void llSetTextureAnim(int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5145. {
  5146. m_host.AddScriptLPS(1);
  5147. SetTextureAnim(m_host, mode, face, sizex, sizey, start, length, rate);
  5148. }
  5149. public void llSetLinkTextureAnim(int linknumber, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5150. {
  5151. m_host.AddScriptLPS(1);
  5152. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  5153. foreach (SceneObjectPart part in parts)
  5154. {
  5155. SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
  5156. }
  5157. }
  5158. private void SetTextureAnim(SceneObjectPart part, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5159. {
  5160. Primitive.TextureAnimation pTexAnim = new Primitive.TextureAnimation();
  5161. pTexAnim.Flags = (Primitive.TextureAnimMode)mode;
  5162. //ALL_SIDES
  5163. if (face == ScriptBaseClass.ALL_SIDES)
  5164. face = 255;
  5165. pTexAnim.Face = (uint)face;
  5166. pTexAnim.Length = (float)length;
  5167. pTexAnim.Rate = (float)rate;
  5168. pTexAnim.SizeX = (uint)sizex;
  5169. pTexAnim.SizeY = (uint)sizey;
  5170. pTexAnim.Start = (float)start;
  5171. part.AddTextureAnimation(pTexAnim);
  5172. part.SendFullUpdateToAllClients();
  5173. part.ParentGroup.HasGroupChanged = true;
  5174. }
  5175. public void llTriggerSoundLimited(string sound, double volume, LSL_Vector top_north_east,
  5176. LSL_Vector bottom_south_west)
  5177. {
  5178. m_host.AddScriptLPS(1);
  5179. if (m_SoundModule != null)
  5180. {
  5181. m_SoundModule.TriggerSoundLimited(m_host.UUID,
  5182. ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume,
  5183. bottom_south_west, top_north_east);
  5184. }
  5185. }
  5186. public void llEjectFromLand(string pest)
  5187. {
  5188. m_host.AddScriptLPS(1);
  5189. UUID agentID = new UUID();
  5190. if (UUID.TryParse(pest, out agentID))
  5191. {
  5192. ScenePresence presence = World.GetScenePresence(agentID);
  5193. if (presence != null)
  5194. {
  5195. // agent must be over the owners land
  5196. ILandObject land = World.LandChannel.GetLandObject(presence.AbsolutePosition);
  5197. if (land == null)
  5198. return;
  5199. if (m_host.OwnerID == land.LandData.OwnerID)
  5200. {
  5201. World.TeleportClientHome(agentID, presence.ControllingClient);
  5202. }
  5203. }
  5204. }
  5205. ScriptSleep(5000);
  5206. }
  5207. public LSL_Integer llOverMyLand(string id)
  5208. {
  5209. m_host.AddScriptLPS(1);
  5210. UUID key = new UUID();
  5211. if (UUID.TryParse(id, out key))
  5212. {
  5213. ScenePresence presence = World.GetScenePresence(key);
  5214. if (presence != null) // object is an avatar
  5215. {
  5216. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  5217. return 1;
  5218. }
  5219. else // object is not an avatar
  5220. {
  5221. SceneObjectPart obj = World.GetSceneObjectPart(key);
  5222. if (obj != null)
  5223. {
  5224. if (m_host.OwnerID == World.LandChannel.GetLandObject(obj.AbsolutePosition).LandData.OwnerID)
  5225. return 1;
  5226. }
  5227. }
  5228. }
  5229. return 0;
  5230. }
  5231. public LSL_String llGetLandOwnerAt(LSL_Vector pos)
  5232. {
  5233. m_host.AddScriptLPS(1);
  5234. ILandObject land = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  5235. if (land == null)
  5236. return UUID.Zero.ToString();
  5237. return land.LandData.OwnerID.ToString();
  5238. }
  5239. /// <summary>
  5240. /// According to http://lslwiki.net/lslwiki/wakka.php?wakka=llGetAgentSize
  5241. /// only the height of avatars vary and that says:
  5242. /// Width (x) and depth (y) are constant. (0.45m and 0.6m respectively).
  5243. /// </summary>
  5244. public LSL_Vector llGetAgentSize(string id)
  5245. {
  5246. m_host.AddScriptLPS(1);
  5247. ScenePresence avatar = World.GetScenePresence((UUID)id);
  5248. LSL_Vector agentSize;
  5249. if (avatar == null || avatar.IsChildAgent) // Fail if not in the same region
  5250. {
  5251. agentSize = ScriptBaseClass.ZERO_VECTOR;
  5252. }
  5253. else
  5254. {
  5255. agentSize = GetAgentSize(avatar);
  5256. }
  5257. return agentSize;
  5258. }
  5259. public LSL_Integer llSameGroup(string agent)
  5260. {
  5261. m_host.AddScriptLPS(1);
  5262. UUID agentId = new UUID();
  5263. if (!UUID.TryParse(agent, out agentId))
  5264. return new LSL_Integer(0);
  5265. ScenePresence presence = World.GetScenePresence(agentId);
  5266. if (presence == null || presence.IsChildAgent) // Return flase for child agents
  5267. return new LSL_Integer(0);
  5268. IClientAPI client = presence.ControllingClient;
  5269. if (m_host.GroupID == client.ActiveGroupId)
  5270. return new LSL_Integer(1);
  5271. else
  5272. return new LSL_Integer(0);
  5273. }
  5274. public void llUnSit(string id)
  5275. {
  5276. m_host.AddScriptLPS(1);
  5277. UUID key = new UUID();
  5278. if (UUID.TryParse(id, out key))
  5279. {
  5280. ScenePresence av = World.GetScenePresence(key);
  5281. List<ScenePresence> sittingAvatars = m_host.ParentGroup.GetSittingAvatars();
  5282. if (av != null)
  5283. {
  5284. if (sittingAvatars.Contains(av))
  5285. {
  5286. // if the avatar is sitting on this object, then
  5287. // we can unsit them. We don't want random scripts unsitting random people
  5288. // Lets avoid the popcorn avatar scenario.
  5289. av.StandUp();
  5290. }
  5291. else
  5292. {
  5293. // If the object owner also owns the parcel
  5294. // or
  5295. // if the land is group owned and the object is group owned by the same group
  5296. // or
  5297. // if the object is owned by a person with estate access.
  5298. ILandObject parcel = World.LandChannel.GetLandObject(av.AbsolutePosition);
  5299. if (parcel != null)
  5300. {
  5301. if (m_host.OwnerID == parcel.LandData.OwnerID ||
  5302. (m_host.OwnerID == m_host.GroupID && m_host.GroupID == parcel.LandData.GroupID
  5303. && parcel.LandData.IsGroupOwned) || World.Permissions.IsGod(m_host.OwnerID))
  5304. {
  5305. av.StandUp();
  5306. }
  5307. }
  5308. }
  5309. }
  5310. }
  5311. }
  5312. public LSL_Vector llGroundSlope(LSL_Vector offset)
  5313. {
  5314. m_host.AddScriptLPS(1);
  5315. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  5316. LSL_Vector vsn = llGroundNormal(offset);
  5317. //Plug the x,y coordinates of the slope normal into the equation of the plane to get
  5318. //the height of that point on the plane. The resulting vector gives the slope.
  5319. Vector3 vsl = vsn;
  5320. vsl.Z = (float)(((vsn.x * vsn.x) + (vsn.y * vsn.y)) / (-1 * vsn.z));
  5321. vsl.Normalize();
  5322. //Normalization might be overkill here
  5323. vsn.x = vsl.X;
  5324. vsn.y = vsl.Y;
  5325. vsn.z = vsl.Z;
  5326. return vsn;
  5327. }
  5328. public LSL_Vector llGroundNormal(LSL_Vector offset)
  5329. {
  5330. m_host.AddScriptLPS(1);
  5331. Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
  5332. // Clamp to valid position
  5333. if (pos.X < 0)
  5334. pos.X = 0;
  5335. else if (pos.X >= World.Heightmap.Width)
  5336. pos.X = World.Heightmap.Width - 1;
  5337. if (pos.Y < 0)
  5338. pos.Y = 0;
  5339. else if (pos.Y >= World.Heightmap.Height)
  5340. pos.Y = World.Heightmap.Height - 1;
  5341. //Find two points in addition to the position to define a plane
  5342. Vector3 p0 = new Vector3(pos.X, pos.Y,
  5343. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  5344. Vector3 p1 = new Vector3();
  5345. Vector3 p2 = new Vector3();
  5346. if ((pos.X + 1.0f) >= World.Heightmap.Width)
  5347. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  5348. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  5349. else
  5350. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  5351. (float)World.Heightmap[(int)(pos.X + 1.0f), (int)pos.Y]);
  5352. if ((pos.Y + 1.0f) >= World.Heightmap.Height)
  5353. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  5354. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  5355. else
  5356. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  5357. (float)World.Heightmap[(int)pos.X, (int)(pos.Y + 1.0f)]);
  5358. //Find normalized vectors from p0 to p1 and p0 to p2
  5359. Vector3 v0 = new Vector3(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
  5360. Vector3 v1 = new Vector3(p2.X - p0.X, p2.Y - p0.Y, p2.Z - p0.Z);
  5361. v0.Normalize();
  5362. v1.Normalize();
  5363. //Find the cross product of the vectors (the slope normal).
  5364. Vector3 vsn = new Vector3();
  5365. vsn.X = (v0.Y * v1.Z) - (v0.Z * v1.Y);
  5366. vsn.Y = (v0.Z * v1.X) - (v0.X * v1.Z);
  5367. vsn.Z = (v0.X * v1.Y) - (v0.Y * v1.X);
  5368. vsn.Normalize();
  5369. //I believe the crossproduct of two normalized vectors is a normalized vector so
  5370. //this normalization may be overkill
  5371. return new LSL_Vector(vsn);
  5372. }
  5373. public LSL_Vector llGroundContour(LSL_Vector offset)
  5374. {
  5375. m_host.AddScriptLPS(1);
  5376. LSL_Vector x = llGroundSlope(offset);
  5377. return new LSL_Vector(-x.y, x.x, 0.0);
  5378. }
  5379. public LSL_Integer llGetAttached()
  5380. {
  5381. m_host.AddScriptLPS(1);
  5382. return m_host.ParentGroup.AttachmentPoint;
  5383. }
  5384. public virtual LSL_Integer llGetFreeMemory()
  5385. {
  5386. m_host.AddScriptLPS(1);
  5387. // Make scripts designed for LSO happy
  5388. return 16384;
  5389. }
  5390. public LSL_Integer llGetFreeURLs()
  5391. {
  5392. m_host.AddScriptLPS(1);
  5393. if (m_UrlModule != null)
  5394. return new LSL_Integer(m_UrlModule.GetFreeUrls());
  5395. return new LSL_Integer(0);
  5396. }
  5397. public LSL_String llGetRegionName()
  5398. {
  5399. m_host.AddScriptLPS(1);
  5400. return World.RegionInfo.RegionName;
  5401. }
  5402. public LSL_Float llGetRegionTimeDilation()
  5403. {
  5404. m_host.AddScriptLPS(1);
  5405. return (double)World.TimeDilation;
  5406. }
  5407. /// <summary>
  5408. /// Returns the value reported in the client Statistics window
  5409. /// </summary>
  5410. public LSL_Float llGetRegionFPS()
  5411. {
  5412. m_host.AddScriptLPS(1);
  5413. return World.StatsReporter.LastReportedSimFPS;
  5414. }
  5415. /* particle system rules should be coming into this routine as doubles, that is
  5416. rule[0] should be an integer from this list and rule[1] should be the arg
  5417. for the same integer. wiki.secondlife.com has most of this mapping, but some
  5418. came from http://www.caligari-designs.com/p4u2
  5419. We iterate through the list for 'Count' elements, incrementing by two for each
  5420. iteration and set the members of Primitive.ParticleSystem, one at a time.
  5421. */
  5422. public enum PrimitiveRule : int
  5423. {
  5424. PSYS_PART_FLAGS = 0,
  5425. PSYS_PART_START_COLOR = 1,
  5426. PSYS_PART_START_ALPHA = 2,
  5427. PSYS_PART_END_COLOR = 3,
  5428. PSYS_PART_END_ALPHA = 4,
  5429. PSYS_PART_START_SCALE = 5,
  5430. PSYS_PART_END_SCALE = 6,
  5431. PSYS_PART_MAX_AGE = 7,
  5432. PSYS_SRC_ACCEL = 8,
  5433. PSYS_SRC_PATTERN = 9,
  5434. PSYS_SRC_INNERANGLE = 10,
  5435. PSYS_SRC_OUTERANGLE = 11,
  5436. PSYS_SRC_TEXTURE = 12,
  5437. PSYS_SRC_BURST_RATE = 13,
  5438. PSYS_SRC_BURST_PART_COUNT = 15,
  5439. PSYS_SRC_BURST_RADIUS = 16,
  5440. PSYS_SRC_BURST_SPEED_MIN = 17,
  5441. PSYS_SRC_BURST_SPEED_MAX = 18,
  5442. PSYS_SRC_MAX_AGE = 19,
  5443. PSYS_SRC_TARGET_KEY = 20,
  5444. PSYS_SRC_OMEGA = 21,
  5445. PSYS_SRC_ANGLE_BEGIN = 22,
  5446. PSYS_SRC_ANGLE_END = 23,
  5447. PSYS_PART_BLEND_FUNC_SOURCE = 24,
  5448. PSYS_PART_BLEND_FUNC_DEST = 25,
  5449. PSYS_PART_START_GLOW = 26,
  5450. PSYS_PART_END_GLOW = 27
  5451. }
  5452. internal Primitive.ParticleSystem.ParticleDataFlags ConvertUINTtoFlags(uint flags)
  5453. {
  5454. Primitive.ParticleSystem.ParticleDataFlags returnval = Primitive.ParticleSystem.ParticleDataFlags.None;
  5455. return returnval;
  5456. }
  5457. protected Primitive.ParticleSystem getNewParticleSystemWithSLDefaultValues()
  5458. {
  5459. Primitive.ParticleSystem ps = new Primitive.ParticleSystem();
  5460. // TODO find out about the other defaults and add them here
  5461. ps.PartStartColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
  5462. ps.PartEndColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
  5463. ps.PartStartScaleX = 1.0f;
  5464. ps.PartStartScaleY = 1.0f;
  5465. ps.PartEndScaleX = 1.0f;
  5466. ps.PartEndScaleY = 1.0f;
  5467. ps.BurstSpeedMin = 1.0f;
  5468. ps.BurstSpeedMax = 1.0f;
  5469. ps.BurstRate = 0.1f;
  5470. ps.PartMaxAge = 10.0f;
  5471. ps.BurstPartCount = 1;
  5472. ps.BlendFuncSource = ScriptBaseClass.PSYS_PART_BF_SOURCE_ALPHA;
  5473. ps.BlendFuncDest = ScriptBaseClass.PSYS_PART_BF_ONE_MINUS_SOURCE_ALPHA;
  5474. ps.PartStartGlow = 0.0f;
  5475. ps.PartEndGlow = 0.0f;
  5476. return ps;
  5477. }
  5478. public void llLinkParticleSystem(int linknumber, LSL_List rules)
  5479. {
  5480. m_host.AddScriptLPS(1);
  5481. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  5482. foreach (SceneObjectPart part in parts)
  5483. {
  5484. SetParticleSystem(part, rules);
  5485. }
  5486. }
  5487. public void llParticleSystem(LSL_List rules)
  5488. {
  5489. m_host.AddScriptLPS(1);
  5490. SetParticleSystem(m_host, rules);
  5491. }
  5492. private void SetParticleSystem(SceneObjectPart part, LSL_List rules)
  5493. {
  5494. if (rules.Length == 0)
  5495. {
  5496. part.RemoveParticleSystem();
  5497. part.ParentGroup.HasGroupChanged = true;
  5498. }
  5499. else
  5500. {
  5501. Primitive.ParticleSystem prules = getNewParticleSystemWithSLDefaultValues();
  5502. LSL_Vector tempv = new LSL_Vector();
  5503. float tempf = 0;
  5504. int tmpi = 0;
  5505. for (int i = 0; i < rules.Length; i += 2)
  5506. {
  5507. switch (rules.GetLSLIntegerItem(i))
  5508. {
  5509. case (int)ScriptBaseClass.PSYS_PART_FLAGS:
  5510. prules.PartDataFlags = (Primitive.ParticleSystem.ParticleDataFlags)(uint)rules.GetLSLIntegerItem(i + 1);
  5511. break;
  5512. case (int)ScriptBaseClass.PSYS_PART_START_COLOR:
  5513. tempv = rules.GetVector3Item(i + 1);
  5514. prules.PartStartColor.R = (float)tempv.x;
  5515. prules.PartStartColor.G = (float)tempv.y;
  5516. prules.PartStartColor.B = (float)tempv.z;
  5517. break;
  5518. case (int)ScriptBaseClass.PSYS_PART_START_ALPHA:
  5519. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5520. prules.PartStartColor.A = tempf;
  5521. break;
  5522. case (int)ScriptBaseClass.PSYS_PART_END_COLOR:
  5523. tempv = rules.GetVector3Item(i + 1);
  5524. prules.PartEndColor.R = (float)tempv.x;
  5525. prules.PartEndColor.G = (float)tempv.y;
  5526. prules.PartEndColor.B = (float)tempv.z;
  5527. break;
  5528. case (int)ScriptBaseClass.PSYS_PART_END_ALPHA:
  5529. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5530. prules.PartEndColor.A = tempf;
  5531. break;
  5532. case (int)ScriptBaseClass.PSYS_PART_START_SCALE:
  5533. tempv = rules.GetVector3Item(i + 1);
  5534. prules.PartStartScaleX = validParticleScale((float)tempv.x);
  5535. prules.PartStartScaleY = validParticleScale((float)tempv.y);
  5536. break;
  5537. case (int)ScriptBaseClass.PSYS_PART_END_SCALE:
  5538. tempv = rules.GetVector3Item(i + 1);
  5539. prules.PartEndScaleX = validParticleScale((float)tempv.x);
  5540. prules.PartEndScaleY = validParticleScale((float)tempv.y);
  5541. break;
  5542. case (int)ScriptBaseClass.PSYS_PART_MAX_AGE:
  5543. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5544. prules.PartMaxAge = tempf;
  5545. break;
  5546. case (int)ScriptBaseClass.PSYS_SRC_ACCEL:
  5547. tempv = rules.GetVector3Item(i + 1);
  5548. prules.PartAcceleration.X = (float)tempv.x;
  5549. prules.PartAcceleration.Y = (float)tempv.y;
  5550. prules.PartAcceleration.Z = (float)tempv.z;
  5551. break;
  5552. case (int)ScriptBaseClass.PSYS_SRC_PATTERN:
  5553. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  5554. prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi;
  5555. break;
  5556. // PSYS_SRC_INNERANGLE and PSYS_SRC_ANGLE_BEGIN use the same variables. The
  5557. // PSYS_SRC_OUTERANGLE and PSYS_SRC_ANGLE_END also use the same variable. The
  5558. // client tells the difference between the two by looking at the 0x02 bit in
  5559. // the PartFlags variable.
  5560. case (int)ScriptBaseClass.PSYS_SRC_INNERANGLE:
  5561. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5562. prules.InnerAngle = (float)tempf;
  5563. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  5564. break;
  5565. case (int)ScriptBaseClass.PSYS_SRC_OUTERANGLE:
  5566. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5567. prules.OuterAngle = (float)tempf;
  5568. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  5569. break;
  5570. case (int)ScriptBaseClass.PSYS_PART_BLEND_FUNC_SOURCE:
  5571. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  5572. prules.BlendFuncSource = (byte)tmpi;
  5573. break;
  5574. case (int)ScriptBaseClass.PSYS_PART_BLEND_FUNC_DEST:
  5575. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  5576. prules.BlendFuncDest = (byte)tmpi;
  5577. break;
  5578. case (int)ScriptBaseClass.PSYS_PART_START_GLOW:
  5579. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5580. prules.PartStartGlow = (float)tempf;
  5581. break;
  5582. case (int)ScriptBaseClass.PSYS_PART_END_GLOW:
  5583. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5584. prules.PartEndGlow = (float)tempf;
  5585. break;
  5586. case (int)ScriptBaseClass.PSYS_SRC_TEXTURE:
  5587. prules.Texture = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, rules.GetLSLStringItem(i + 1));
  5588. break;
  5589. case (int)ScriptBaseClass.PSYS_SRC_BURST_RATE:
  5590. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5591. prules.BurstRate = (float)tempf;
  5592. break;
  5593. case (int)ScriptBaseClass.PSYS_SRC_BURST_PART_COUNT:
  5594. prules.BurstPartCount = (byte)(int)rules.GetLSLIntegerItem(i + 1);
  5595. break;
  5596. case (int)ScriptBaseClass.PSYS_SRC_BURST_RADIUS:
  5597. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5598. prules.BurstRadius = (float)tempf;
  5599. break;
  5600. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MIN:
  5601. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5602. prules.BurstSpeedMin = (float)tempf;
  5603. break;
  5604. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MAX:
  5605. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5606. prules.BurstSpeedMax = (float)tempf;
  5607. break;
  5608. case (int)ScriptBaseClass.PSYS_SRC_MAX_AGE:
  5609. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5610. prules.MaxAge = (float)tempf;
  5611. break;
  5612. case (int)ScriptBaseClass.PSYS_SRC_TARGET_KEY:
  5613. UUID key = UUID.Zero;
  5614. if (UUID.TryParse(rules.Data[i + 1].ToString(), out key))
  5615. {
  5616. prules.Target = key;
  5617. }
  5618. else
  5619. {
  5620. prules.Target = part.UUID;
  5621. }
  5622. break;
  5623. case (int)ScriptBaseClass.PSYS_SRC_OMEGA:
  5624. // AL: This is an assumption, since it is the only thing that would match.
  5625. tempv = rules.GetVector3Item(i + 1);
  5626. prules.AngularVelocity.X = (float)tempv.x;
  5627. prules.AngularVelocity.Y = (float)tempv.y;
  5628. prules.AngularVelocity.Z = (float)tempv.z;
  5629. break;
  5630. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN:
  5631. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5632. prules.InnerAngle = (float)tempf;
  5633. prules.PartFlags |= 0x02; // Set new angle format.
  5634. break;
  5635. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_END:
  5636. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5637. prules.OuterAngle = (float)tempf;
  5638. prules.PartFlags |= 0x02; // Set new angle format.
  5639. break;
  5640. }
  5641. }
  5642. prules.CRC = 1;
  5643. part.AddNewParticleSystem(prules);
  5644. part.ParentGroup.HasGroupChanged = true;
  5645. }
  5646. part.SendFullUpdateToAllClients();
  5647. }
  5648. private float validParticleScale(float value)
  5649. {
  5650. if (value > 4.0f) return 4.0f;
  5651. return value;
  5652. }
  5653. public void llGroundRepel(double height, int water, double tau)
  5654. {
  5655. m_host.AddScriptLPS(1);
  5656. if (m_host.PhysActor != null)
  5657. {
  5658. float ground = (float)llGround(new LSL_Types.Vector3(0, 0, 0));
  5659. float waterLevel = (float)llWater(new LSL_Types.Vector3(0, 0, 0));
  5660. PIDHoverType hoverType = PIDHoverType.Ground;
  5661. if (water != 0)
  5662. {
  5663. hoverType = PIDHoverType.GroundAndWater;
  5664. if (ground < waterLevel)
  5665. height += waterLevel;
  5666. else
  5667. height += ground;
  5668. }
  5669. else
  5670. {
  5671. height += ground;
  5672. }
  5673. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  5674. }
  5675. }
  5676. public void llGiveInventoryList(string destination, string category, LSL_List inventory)
  5677. {
  5678. m_host.AddScriptLPS(1);
  5679. UUID destID;
  5680. if (!UUID.TryParse(destination, out destID))
  5681. return;
  5682. List<UUID> itemList = new List<UUID>();
  5683. foreach (Object item in inventory.Data)
  5684. {
  5685. string rawItemString = item.ToString();
  5686. UUID itemID;
  5687. if (UUID.TryParse(rawItemString, out itemID))
  5688. {
  5689. itemList.Add(itemID);
  5690. }
  5691. else
  5692. {
  5693. TaskInventoryItem taskItem = m_host.Inventory.GetInventoryItem(rawItemString);
  5694. if (taskItem != null)
  5695. itemList.Add(taskItem.ItemID);
  5696. }
  5697. }
  5698. if (itemList.Count == 0)
  5699. return;
  5700. UUID folderID = m_ScriptEngine.World.MoveTaskInventoryItems(destID, category, m_host, itemList);
  5701. if (folderID == UUID.Zero)
  5702. return;
  5703. if (m_TransferModule != null)
  5704. {
  5705. byte[] bucket = new byte[] { (byte)AssetType.Folder };
  5706. Vector3 pos = m_host.AbsolutePosition;
  5707. GridInstantMessage msg = new GridInstantMessage(World,
  5708. m_host.OwnerID, m_host.Name, destID,
  5709. (byte)InstantMessageDialog.TaskInventoryOffered,
  5710. false, string.Format("'{0}'", category),
  5711. // We won't go so far as to add a SLURL, but this is the format used by LL as of 2012-10-06
  5712. // false, string.Format("'{0}' ( http://slurl.com/secondlife/{1}/{2}/{3}/{4} )", category, World.Name, (int)pos.X, (int)pos.Y, (int)pos.Z),
  5713. folderID, false, pos,
  5714. bucket, false);
  5715. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  5716. }
  5717. }
  5718. public void llSetVehicleType(int type)
  5719. {
  5720. m_host.AddScriptLPS(1);
  5721. if (!m_host.ParentGroup.IsDeleted)
  5722. {
  5723. m_host.ParentGroup.RootPart.SetVehicleType(type);
  5724. }
  5725. }
  5726. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  5727. //CFK 9/28: so these are not complete yet.
  5728. public void llSetVehicleFloatParam(int param, LSL_Float value)
  5729. {
  5730. m_host.AddScriptLPS(1);
  5731. if (!m_host.ParentGroup.IsDeleted)
  5732. {
  5733. m_host.ParentGroup.RootPart.SetVehicleFloatParam(param, (float)value);
  5734. }
  5735. }
  5736. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  5737. //CFK 9/28: so these are not complete yet.
  5738. public void llSetVehicleVectorParam(int param, LSL_Vector vec)
  5739. {
  5740. m_host.AddScriptLPS(1);
  5741. if (!m_host.ParentGroup.IsDeleted)
  5742. {
  5743. m_host.ParentGroup.RootPart.SetVehicleVectorParam(param, vec);
  5744. }
  5745. }
  5746. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  5747. //CFK 9/28: so these are not complete yet.
  5748. public void llSetVehicleRotationParam(int param, LSL_Rotation rot)
  5749. {
  5750. m_host.AddScriptLPS(1);
  5751. if (!m_host.ParentGroup.IsDeleted)
  5752. {
  5753. m_host.ParentGroup.RootPart.SetVehicleRotationParam(param, rot);
  5754. }
  5755. }
  5756. public void llSetVehicleFlags(int flags)
  5757. {
  5758. m_host.AddScriptLPS(1);
  5759. if (!m_host.ParentGroup.IsDeleted)
  5760. {
  5761. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, false);
  5762. }
  5763. }
  5764. public void llRemoveVehicleFlags(int flags)
  5765. {
  5766. m_host.AddScriptLPS(1);
  5767. if (!m_host.ParentGroup.IsDeleted)
  5768. {
  5769. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, true);
  5770. }
  5771. }
  5772. protected void SitTarget(SceneObjectPart part, LSL_Vector offset, LSL_Rotation rot)
  5773. {
  5774. part.SitTargetPosition = offset;
  5775. part.SitTargetOrientation = rot;
  5776. part.ParentGroup.HasGroupChanged = true;
  5777. }
  5778. public void llSitTarget(LSL_Vector offset, LSL_Rotation rot)
  5779. {
  5780. m_host.AddScriptLPS(1);
  5781. SitTarget(m_host, offset, rot);
  5782. }
  5783. public void llLinkSitTarget(LSL_Integer link, LSL_Vector offset, LSL_Rotation rot)
  5784. {
  5785. m_host.AddScriptLPS(1);
  5786. if (link == ScriptBaseClass.LINK_ROOT)
  5787. SitTarget(m_host.ParentGroup.RootPart, offset, rot);
  5788. else if (link == ScriptBaseClass.LINK_THIS)
  5789. SitTarget(m_host, offset, rot);
  5790. else
  5791. {
  5792. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  5793. if (null != part)
  5794. {
  5795. SitTarget(part, offset, rot);
  5796. }
  5797. }
  5798. }
  5799. public LSL_String llAvatarOnSitTarget()
  5800. {
  5801. m_host.AddScriptLPS(1);
  5802. return m_host.SitTargetAvatar.ToString();
  5803. }
  5804. // http://wiki.secondlife.com/wiki/LlAvatarOnLinkSitTarget
  5805. public LSL_String llAvatarOnLinkSitTarget(int linknum)
  5806. {
  5807. m_host.AddScriptLPS(1);
  5808. if(linknum == ScriptBaseClass.LINK_SET ||
  5809. linknum == ScriptBaseClass.LINK_ALL_CHILDREN ||
  5810. linknum == ScriptBaseClass.LINK_ALL_OTHERS) return UUID.Zero.ToString();
  5811. List<SceneObjectPart> parts = GetLinkParts(linknum);
  5812. if (parts.Count == 0) return UUID.Zero.ToString();
  5813. return parts[0].SitTargetAvatar.ToString();
  5814. }
  5815. public void llAddToLandPassList(string avatar, double hours)
  5816. {
  5817. m_host.AddScriptLPS(1);
  5818. UUID key;
  5819. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  5820. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned))
  5821. {
  5822. int expires = 0;
  5823. if (hours != 0)
  5824. expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours);
  5825. if (UUID.TryParse(avatar, out key))
  5826. {
  5827. int idx = land.LandData.ParcelAccessList.FindIndex(
  5828. delegate(LandAccessEntry e)
  5829. {
  5830. if (e.AgentID == key && e.Flags == AccessList.Access)
  5831. return true;
  5832. return false;
  5833. });
  5834. if (idx != -1 && (land.LandData.ParcelAccessList[idx].Expires == 0 || (expires != 0 && expires < land.LandData.ParcelAccessList[idx].Expires)))
  5835. return;
  5836. if (idx != -1)
  5837. land.LandData.ParcelAccessList.RemoveAt(idx);
  5838. LandAccessEntry entry = new LandAccessEntry();
  5839. entry.AgentID = key;
  5840. entry.Flags = AccessList.Access;
  5841. entry.Expires = expires;
  5842. land.LandData.ParcelAccessList.Add(entry);
  5843. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  5844. }
  5845. }
  5846. ScriptSleep(100);
  5847. }
  5848. public void llSetTouchText(string text)
  5849. {
  5850. m_host.AddScriptLPS(1);
  5851. m_host.TouchName = text;
  5852. }
  5853. public void llSetSitText(string text)
  5854. {
  5855. m_host.AddScriptLPS(1);
  5856. m_host.SitName = text;
  5857. }
  5858. public void llSetCameraEyeOffset(LSL_Vector offset)
  5859. {
  5860. m_host.AddScriptLPS(1);
  5861. m_host.SetCameraEyeOffset(offset);
  5862. if (m_host.ParentGroup.RootPart.GetCameraEyeOffset() == Vector3.Zero)
  5863. m_host.ParentGroup.RootPart.SetCameraEyeOffset(offset);
  5864. }
  5865. public void llSetCameraAtOffset(LSL_Vector offset)
  5866. {
  5867. m_host.AddScriptLPS(1);
  5868. m_host.SetCameraAtOffset(offset);
  5869. if (m_host.ParentGroup.RootPart.GetCameraAtOffset() == Vector3.Zero)
  5870. m_host.ParentGroup.RootPart.SetCameraAtOffset(offset);
  5871. }
  5872. public void llSetLinkCamera(LSL_Integer link, LSL_Vector eye, LSL_Vector at)
  5873. {
  5874. m_host.AddScriptLPS(1);
  5875. if (link == ScriptBaseClass.LINK_SET ||
  5876. link == ScriptBaseClass.LINK_ALL_CHILDREN ||
  5877. link == ScriptBaseClass.LINK_ALL_OTHERS) return;
  5878. SceneObjectPart part = null;
  5879. switch (link)
  5880. {
  5881. case ScriptBaseClass.LINK_ROOT:
  5882. part = m_host.ParentGroup.RootPart;
  5883. break;
  5884. case ScriptBaseClass.LINK_THIS:
  5885. part = m_host;
  5886. break;
  5887. default:
  5888. part = m_host.ParentGroup.GetLinkNumPart(link);
  5889. break;
  5890. }
  5891. if (null != part)
  5892. {
  5893. part.SetCameraEyeOffset(eye);
  5894. part.SetCameraAtOffset(at);
  5895. }
  5896. }
  5897. public LSL_String llDumpList2String(LSL_List src, string seperator)
  5898. {
  5899. m_host.AddScriptLPS(1);
  5900. if (src.Length == 0)
  5901. {
  5902. return String.Empty;
  5903. }
  5904. string ret = String.Empty;
  5905. foreach (object o in src.Data)
  5906. {
  5907. ret = ret + o.ToString() + seperator;
  5908. }
  5909. ret = ret.Substring(0, ret.Length - seperator.Length);
  5910. return ret;
  5911. }
  5912. public LSL_Integer llScriptDanger(LSL_Vector pos)
  5913. {
  5914. m_host.AddScriptLPS(1);
  5915. bool result = World.ScriptDanger(m_host.LocalId, pos);
  5916. if (result)
  5917. {
  5918. return 1;
  5919. }
  5920. else
  5921. {
  5922. return 0;
  5923. }
  5924. }
  5925. public void llDialog(string avatar, string message, LSL_List buttons, int chat_channel)
  5926. {
  5927. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  5928. if (dm == null)
  5929. return;
  5930. m_host.AddScriptLPS(1);
  5931. UUID av = new UUID();
  5932. if (!UUID.TryParse(avatar,out av))
  5933. {
  5934. Error("llDialog", "First parameter must be a key");
  5935. return;
  5936. }
  5937. if (buttons.Length < 1)
  5938. {
  5939. Error("llDialog", "At least 1 button must be shown");
  5940. return;
  5941. }
  5942. if (buttons.Length > 12)
  5943. {
  5944. Error("llDialog", "No more than 12 buttons can be shown");
  5945. return;
  5946. }
  5947. string[] buts = new string[buttons.Length];
  5948. for (int i = 0; i < buttons.Length; i++)
  5949. {
  5950. if (buttons.Data[i].ToString() == String.Empty)
  5951. {
  5952. Error("llDialog", "Button label cannot be blank");
  5953. return;
  5954. }
  5955. if (buttons.Data[i].ToString().Length > 24)
  5956. {
  5957. Error("llDialog", "Button label cannot be longer than 24 characters");
  5958. return;
  5959. }
  5960. buts[i] = buttons.Data[i].ToString();
  5961. }
  5962. dm.SendDialogToUser(
  5963. av, m_host.Name, m_host.UUID, m_host.OwnerID,
  5964. message, new UUID("00000000-0000-2222-3333-100000001000"), chat_channel, buts);
  5965. ScriptSleep(1000);
  5966. }
  5967. public void llVolumeDetect(int detect)
  5968. {
  5969. m_host.AddScriptLPS(1);
  5970. if (!m_host.ParentGroup.IsDeleted)
  5971. m_host.ParentGroup.ScriptSetVolumeDetect(detect != 0);
  5972. }
  5973. public void llRemoteLoadScript(string target, string name, int running, int start_param)
  5974. {
  5975. m_host.AddScriptLPS(1);
  5976. Deprecated("llRemoteLoadScript", "Use llRemoteLoadScriptPin instead");
  5977. ScriptSleep(3000);
  5978. }
  5979. public void llSetRemoteScriptAccessPin(int pin)
  5980. {
  5981. m_host.AddScriptLPS(1);
  5982. m_host.ScriptAccessPin = pin;
  5983. }
  5984. public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param)
  5985. {
  5986. m_host.AddScriptLPS(1);
  5987. UUID destId = UUID.Zero;
  5988. if (!UUID.TryParse(target, out destId))
  5989. {
  5990. Error("llRemoteLoadScriptPin", "Can't parse key '" + target + "'");
  5991. return;
  5992. }
  5993. // target must be a different prim than the one containing the script
  5994. if (m_host.UUID == destId)
  5995. {
  5996. return;
  5997. }
  5998. // copy the first script found with this inventory name
  5999. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  6000. // make sure the object is a script
  6001. if (item == null || item.Type != 10)
  6002. {
  6003. Error("llRemoteLoadScriptPin", "Can't find script '" + name + "'");
  6004. return;
  6005. }
  6006. // the rest of the permission checks are done in RezScript, so check the pin there as well
  6007. World.RezScriptFromPrim(item.ItemID, m_host, destId, pin, running, start_param);
  6008. // this will cause the delay even if the script pin or permissions were wrong - seems ok
  6009. ScriptSleep(3000);
  6010. }
  6011. public void llOpenRemoteDataChannel()
  6012. {
  6013. m_host.AddScriptLPS(1);
  6014. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  6015. if (xmlrpcMod != null && xmlrpcMod.IsEnabled())
  6016. {
  6017. UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_host.LocalId, m_item.ItemID, UUID.Zero);
  6018. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  6019. if (xmlRpcRouter != null)
  6020. {
  6021. string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName;
  6022. xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID,
  6023. m_item.ItemID, String.Format("http://{0}:{1}/", ExternalHostName,
  6024. xmlrpcMod.Port.ToString()));
  6025. }
  6026. object[] resobj = new object[]
  6027. {
  6028. new LSL_Integer(1),
  6029. new LSL_String(channelID.ToString()),
  6030. new LSL_String(UUID.Zero.ToString()),
  6031. new LSL_String(String.Empty),
  6032. new LSL_Integer(0),
  6033. new LSL_String(String.Empty)
  6034. };
  6035. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams("remote_data", resobj,
  6036. new DetectParams[0]));
  6037. }
  6038. ScriptSleep(1000);
  6039. }
  6040. public LSL_String llSendRemoteData(string channel, string dest, int idata, string sdata)
  6041. {
  6042. m_host.AddScriptLPS(1);
  6043. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  6044. ScriptSleep(3000);
  6045. if (xmlrpcMod == null)
  6046. return "";
  6047. return (xmlrpcMod.SendRemoteData(m_host.LocalId, m_item.ItemID, channel, dest, idata, sdata)).ToString();
  6048. }
  6049. public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
  6050. {
  6051. m_host.AddScriptLPS(1);
  6052. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  6053. if (xmlrpcMod != null)
  6054. xmlrpcMod.RemoteDataReply(channel, message_id, sdata, idata);
  6055. ScriptSleep(3000);
  6056. }
  6057. public void llCloseRemoteDataChannel(string channel)
  6058. {
  6059. m_host.AddScriptLPS(1);
  6060. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  6061. if (xmlRpcRouter != null)
  6062. {
  6063. xmlRpcRouter.UnRegisterReceiver(channel, m_item.ItemID);
  6064. }
  6065. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  6066. if (xmlrpcMod != null)
  6067. xmlrpcMod.CloseXMLRPCChannel((UUID)channel);
  6068. ScriptSleep(1000);
  6069. }
  6070. public LSL_String llMD5String(string src, int nonce)
  6071. {
  6072. m_host.AddScriptLPS(1);
  6073. return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()));
  6074. }
  6075. public LSL_String llSHA1String(string src)
  6076. {
  6077. m_host.AddScriptLPS(1);
  6078. return Util.SHA1Hash(src).ToLower();
  6079. }
  6080. protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve)
  6081. {
  6082. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  6083. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  6084. if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
  6085. holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
  6086. holeshape != (int)ScriptBaseClass.PRIM_HOLE_SQUARE &&
  6087. holeshape != (int)ScriptBaseClass.PRIM_HOLE_TRIANGLE)
  6088. {
  6089. holeshape = (int)ScriptBaseClass.PRIM_HOLE_DEFAULT;
  6090. }
  6091. shapeBlock.PathCurve = pathcurve;
  6092. shapeBlock.ProfileCurve = (byte)holeshape; // Set the hole shape.
  6093. shapeBlock.ProfileCurve += profileshape; // Add in the profile shape.
  6094. if (cut.x < 0f)
  6095. {
  6096. cut.x = 0f;
  6097. }
  6098. if (cut.x > 1f)
  6099. {
  6100. cut.x = 1f;
  6101. }
  6102. if (cut.y < 0f)
  6103. {
  6104. cut.y = 0f;
  6105. }
  6106. if (cut.y > 1f)
  6107. {
  6108. cut.y = 1f;
  6109. }
  6110. if (cut.y - cut.x < 0.05f)
  6111. {
  6112. cut.x = cut.y - 0.05f;
  6113. if (cut.x < 0.0f)
  6114. {
  6115. cut.x = 0.0f;
  6116. cut.y = 0.05f;
  6117. }
  6118. }
  6119. shapeBlock.ProfileBegin = (ushort)(50000 * cut.x);
  6120. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - cut.y));
  6121. if (hollow < 0f)
  6122. {
  6123. hollow = 0f;
  6124. }
  6125. // If the prim is a Cylinder, Prism, Sphere, Torus or Ring (or not a
  6126. // Box or Tube) and the hole shape is a square, hollow is limited to
  6127. // a max of 70%. The viewer performs its own check on this value but
  6128. // we need to do it here also so llGetPrimitiveParams can have access
  6129. // to the correct value.
  6130. if (profileshape != (byte)ProfileCurve.Square &&
  6131. holeshape == (int)ScriptBaseClass.PRIM_HOLE_SQUARE)
  6132. {
  6133. if (hollow > 0.70f)
  6134. {
  6135. hollow = 0.70f;
  6136. }
  6137. }
  6138. // Otherwise, hollow is limited to 95%.
  6139. else
  6140. {
  6141. if (hollow > 0.95f)
  6142. {
  6143. hollow = 0.95f;
  6144. }
  6145. }
  6146. shapeBlock.ProfileHollow = (ushort)(50000 * hollow);
  6147. if (twist.x < -1.0f)
  6148. {
  6149. twist.x = -1.0f;
  6150. }
  6151. if (twist.x > 1.0f)
  6152. {
  6153. twist.x = 1.0f;
  6154. }
  6155. if (twist.y < -1.0f)
  6156. {
  6157. twist.y = -1.0f;
  6158. }
  6159. if (twist.y > 1.0f)
  6160. {
  6161. twist.y = 1.0f;
  6162. }
  6163. // A fairly large precision error occurs for some calculations,
  6164. // if a float or double is directly cast to a byte or sbyte
  6165. // variable, in both .Net and Mono. In .Net, coding
  6166. // "(sbyte)(float)(some expression)" corrects the precision
  6167. // errors. But this does not work for Mono. This longer coding
  6168. // form of creating a tempoary float variable from the
  6169. // expression first, then casting that variable to a byte or
  6170. // sbyte, works for both .Net and Mono. These types of
  6171. // assignments occur in SetPrimtiveBlockShapeParams and
  6172. // SetPrimitiveShapeParams in support of llSetPrimitiveParams.
  6173. tempFloat = (float)(100.0d * twist.x);
  6174. shapeBlock.PathTwistBegin = (sbyte)tempFloat;
  6175. tempFloat = (float)(100.0d * twist.y);
  6176. shapeBlock.PathTwist = (sbyte)tempFloat;
  6177. shapeBlock.ObjectLocalID = part.LocalId;
  6178. part.Shape.SculptEntry = false;
  6179. return shapeBlock;
  6180. }
  6181. // Prim type box, cylinder and prism.
  6182. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte profileshape, byte pathcurve)
  6183. {
  6184. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  6185. ObjectShapePacket.ObjectDataBlock shapeBlock;
  6186. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  6187. if (taper_b.x < 0f)
  6188. {
  6189. taper_b.x = 0f;
  6190. }
  6191. if (taper_b.x > 2f)
  6192. {
  6193. taper_b.x = 2f;
  6194. }
  6195. if (taper_b.y < 0f)
  6196. {
  6197. taper_b.y = 0f;
  6198. }
  6199. if (taper_b.y > 2f)
  6200. {
  6201. taper_b.y = 2f;
  6202. }
  6203. tempFloat = (float)(100.0d * (2.0d - taper_b.x));
  6204. shapeBlock.PathScaleX = (byte)tempFloat;
  6205. tempFloat = (float)(100.0d * (2.0d - taper_b.y));
  6206. shapeBlock.PathScaleY = (byte)tempFloat;
  6207. if (topshear.x < -0.5f)
  6208. {
  6209. topshear.x = -0.5f;
  6210. }
  6211. if (topshear.x > 0.5f)
  6212. {
  6213. topshear.x = 0.5f;
  6214. }
  6215. if (topshear.y < -0.5f)
  6216. {
  6217. topshear.y = -0.5f;
  6218. }
  6219. if (topshear.y > 0.5f)
  6220. {
  6221. topshear.y = 0.5f;
  6222. }
  6223. tempFloat = (float)(100.0d * topshear.x);
  6224. shapeBlock.PathShearX = (byte)tempFloat;
  6225. tempFloat = (float)(100.0d * topshear.y);
  6226. shapeBlock.PathShearY = (byte)tempFloat;
  6227. part.Shape.SculptEntry = false;
  6228. part.UpdateShape(shapeBlock);
  6229. }
  6230. // Prim type sphere.
  6231. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve)
  6232. {
  6233. ObjectShapePacket.ObjectDataBlock shapeBlock;
  6234. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  6235. // profile/path swapped for a sphere
  6236. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  6237. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  6238. shapeBlock.PathScaleX = 100;
  6239. shapeBlock.PathScaleY = 100;
  6240. if (dimple.x < 0f)
  6241. {
  6242. dimple.x = 0f;
  6243. }
  6244. if (dimple.x > 1f)
  6245. {
  6246. dimple.x = 1f;
  6247. }
  6248. if (dimple.y < 0f)
  6249. {
  6250. dimple.y = 0f;
  6251. }
  6252. if (dimple.y > 1f)
  6253. {
  6254. dimple.y = 1f;
  6255. }
  6256. if (dimple.y - cut.x < 0.05f)
  6257. {
  6258. dimple.x = cut.y - 0.05f;
  6259. }
  6260. shapeBlock.ProfileBegin = (ushort)(50000 * dimple.x);
  6261. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - dimple.y));
  6262. part.Shape.SculptEntry = false;
  6263. part.UpdateShape(shapeBlock);
  6264. }
  6265. // Prim type torus, tube and ring.
  6266. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector holesize, LSL_Vector topshear, LSL_Vector profilecut, LSL_Vector taper_a, float revolutions, float radiusoffset, float skew, byte profileshape, byte pathcurve)
  6267. {
  6268. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  6269. ObjectShapePacket.ObjectDataBlock shapeBlock;
  6270. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  6271. // profile/path swapped for a torrus, tube, ring
  6272. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  6273. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  6274. if (holesize.x < 0.05f)
  6275. {
  6276. holesize.x = 0.05f;
  6277. }
  6278. if (holesize.x > 1f)
  6279. {
  6280. holesize.x = 1f;
  6281. }
  6282. if (holesize.y < 0.05f)
  6283. {
  6284. holesize.y = 0.05f;
  6285. }
  6286. if (holesize.y > 0.5f)
  6287. {
  6288. holesize.y = 0.5f;
  6289. }
  6290. tempFloat = (float)(100.0d * (2.0d - holesize.x));
  6291. shapeBlock.PathScaleX = (byte)tempFloat;
  6292. tempFloat = (float)(100.0d * (2.0d - holesize.y));
  6293. shapeBlock.PathScaleY = (byte)tempFloat;
  6294. if (topshear.x < -0.5f)
  6295. {
  6296. topshear.x = -0.5f;
  6297. }
  6298. if (topshear.x > 0.5f)
  6299. {
  6300. topshear.x = 0.5f;
  6301. }
  6302. if (topshear.y < -0.5f)
  6303. {
  6304. topshear.y = -0.5f;
  6305. }
  6306. if (topshear.y > 0.5f)
  6307. {
  6308. topshear.y = 0.5f;
  6309. }
  6310. tempFloat = (float)(100.0d * topshear.x);
  6311. shapeBlock.PathShearX = (byte)tempFloat;
  6312. tempFloat = (float)(100.0d * topshear.y);
  6313. shapeBlock.PathShearY = (byte)tempFloat;
  6314. if (profilecut.x < 0f)
  6315. {
  6316. profilecut.x = 0f;
  6317. }
  6318. if (profilecut.x > 1f)
  6319. {
  6320. profilecut.x = 1f;
  6321. }
  6322. if (profilecut.y < 0f)
  6323. {
  6324. profilecut.y = 0f;
  6325. }
  6326. if (profilecut.y > 1f)
  6327. {
  6328. profilecut.y = 1f;
  6329. }
  6330. if (profilecut.y - profilecut.x < 0.05f)
  6331. {
  6332. profilecut.x = profilecut.y - 0.05f;
  6333. if (profilecut.x < 0.0f)
  6334. {
  6335. profilecut.x = 0.0f;
  6336. profilecut.y = 0.05f;
  6337. }
  6338. }
  6339. shapeBlock.ProfileBegin = (ushort)(50000 * profilecut.x);
  6340. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - profilecut.y));
  6341. if (taper_a.x < -1f)
  6342. {
  6343. taper_a.x = -1f;
  6344. }
  6345. if (taper_a.x > 1f)
  6346. {
  6347. taper_a.x = 1f;
  6348. }
  6349. if (taper_a.y < -1f)
  6350. {
  6351. taper_a.y = -1f;
  6352. }
  6353. if (taper_a.y > 1f)
  6354. {
  6355. taper_a.y = 1f;
  6356. }
  6357. tempFloat = (float)(100.0d * taper_a.x);
  6358. shapeBlock.PathTaperX = (sbyte)tempFloat;
  6359. tempFloat = (float)(100.0d * taper_a.y);
  6360. shapeBlock.PathTaperY = (sbyte)tempFloat;
  6361. if (revolutions < 1f)
  6362. {
  6363. revolutions = 1f;
  6364. }
  6365. if (revolutions > 4f)
  6366. {
  6367. revolutions = 4f;
  6368. }
  6369. tempFloat = 66.66667f * (revolutions - 1.0f);
  6370. shapeBlock.PathRevolutions = (byte)tempFloat;
  6371. // limits on radiusoffset depend on revolutions and hole size (how?) seems like the maximum range is 0 to 1
  6372. if (radiusoffset < 0f)
  6373. {
  6374. radiusoffset = 0f;
  6375. }
  6376. if (radiusoffset > 1f)
  6377. {
  6378. radiusoffset = 1f;
  6379. }
  6380. tempFloat = 100.0f * radiusoffset;
  6381. shapeBlock.PathRadiusOffset = (sbyte)tempFloat;
  6382. if (skew < -0.95f)
  6383. {
  6384. skew = -0.95f;
  6385. }
  6386. if (skew > 0.95f)
  6387. {
  6388. skew = 0.95f;
  6389. }
  6390. tempFloat = 100.0f * skew;
  6391. shapeBlock.PathSkew = (sbyte)tempFloat;
  6392. part.Shape.SculptEntry = false;
  6393. part.UpdateShape(shapeBlock);
  6394. }
  6395. // Prim type sculpt.
  6396. protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve)
  6397. {
  6398. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  6399. UUID sculptId;
  6400. if (!UUID.TryParse(map, out sculptId))
  6401. sculptId = ScriptUtils.GetAssetIdFromItemName(m_host, map, (int)AssetType.Texture);
  6402. if (sculptId == UUID.Zero)
  6403. return;
  6404. shapeBlock.PathCurve = pathcurve;
  6405. shapeBlock.ObjectLocalID = part.LocalId;
  6406. shapeBlock.PathScaleX = 100;
  6407. shapeBlock.PathScaleY = 150;
  6408. int flag = type & (ScriptBaseClass.PRIM_SCULPT_FLAG_INVERT | ScriptBaseClass.PRIM_SCULPT_FLAG_MIRROR);
  6409. if (type != (ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER | flag) &&
  6410. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE | flag) &&
  6411. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE | flag) &&
  6412. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS | flag))
  6413. {
  6414. // default
  6415. type = (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
  6416. }
  6417. part.Shape.SetSculptProperties((byte)type, sculptId);
  6418. part.Shape.SculptEntry = true;
  6419. part.UpdateShape(shapeBlock);
  6420. }
  6421. public void llSetPrimitiveParams(LSL_List rules)
  6422. {
  6423. m_host.AddScriptLPS(1);
  6424. SetLinkPrimParams(ScriptBaseClass.LINK_THIS, rules, "llSetPrimitiveParams");
  6425. ScriptSleep(200);
  6426. }
  6427. public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
  6428. {
  6429. m_host.AddScriptLPS(1);
  6430. SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParams");
  6431. ScriptSleep(200);
  6432. }
  6433. public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
  6434. {
  6435. m_host.AddScriptLPS(1);
  6436. SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParamsFast");
  6437. }
  6438. protected void SetLinkPrimParams(int linknumber, LSL_List rules, string originFunc)
  6439. {
  6440. SetEntityParams(GetLinkEntities(linknumber), rules, originFunc);
  6441. }
  6442. protected void SetEntityParams(List<ISceneEntity> entities, LSL_List rules, string originFunc)
  6443. {
  6444. LSL_List remaining = null;
  6445. uint rulesParsed = 0;
  6446. foreach (ISceneEntity entity in entities)
  6447. {
  6448. if (entity is SceneObjectPart)
  6449. remaining = SetPrimParams((SceneObjectPart)entity, rules, originFunc, ref rulesParsed);
  6450. else
  6451. remaining = SetAgentParams((ScenePresence)entity, rules, originFunc, ref rulesParsed);
  6452. }
  6453. while (remaining != null && remaining.Length > 2)
  6454. {
  6455. int linknumber = remaining.GetLSLIntegerItem(0);
  6456. rules = remaining.GetSublist(1, -1);
  6457. entities = GetLinkEntities(linknumber);
  6458. foreach (ISceneEntity entity in entities)
  6459. {
  6460. if (entity is SceneObjectPart)
  6461. remaining = SetPrimParams((SceneObjectPart)entity, rules, originFunc, ref rulesParsed);
  6462. else
  6463. remaining = SetAgentParams((ScenePresence)entity, rules, originFunc, ref rulesParsed);
  6464. }
  6465. }
  6466. }
  6467. public void llSetKeyframedMotion(LSL_List frames, LSL_List options)
  6468. {
  6469. SceneObjectGroup group = m_host.ParentGroup;
  6470. if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
  6471. return;
  6472. if (group.IsAttachment)
  6473. return;
  6474. if (frames.Data.Length > 0) // We are getting a new motion
  6475. {
  6476. if (group.RootPart.KeyframeMotion != null)
  6477. group.RootPart.KeyframeMotion.Delete();
  6478. group.RootPart.KeyframeMotion = null;
  6479. int idx = 0;
  6480. KeyframeMotion.PlayMode mode = KeyframeMotion.PlayMode.Forward;
  6481. KeyframeMotion.DataFormat data = KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation;
  6482. while (idx < options.Data.Length)
  6483. {
  6484. int option = (int)options.GetLSLIntegerItem(idx++);
  6485. int remain = options.Data.Length - idx;
  6486. switch (option)
  6487. {
  6488. case ScriptBaseClass.KFM_MODE:
  6489. if (remain < 1)
  6490. break;
  6491. int modeval = (int)options.GetLSLIntegerItem(idx++);
  6492. switch(modeval)
  6493. {
  6494. case ScriptBaseClass.KFM_FORWARD:
  6495. mode = KeyframeMotion.PlayMode.Forward;
  6496. break;
  6497. case ScriptBaseClass.KFM_REVERSE:
  6498. mode = KeyframeMotion.PlayMode.Reverse;
  6499. break;
  6500. case ScriptBaseClass.KFM_LOOP:
  6501. mode = KeyframeMotion.PlayMode.Loop;
  6502. break;
  6503. case ScriptBaseClass.KFM_PING_PONG:
  6504. mode = KeyframeMotion.PlayMode.PingPong;
  6505. break;
  6506. }
  6507. break;
  6508. case ScriptBaseClass.KFM_DATA:
  6509. if (remain < 1)
  6510. break;
  6511. int dataval = (int)options.GetLSLIntegerItem(idx++);
  6512. data = (KeyframeMotion.DataFormat)dataval;
  6513. break;
  6514. }
  6515. }
  6516. group.RootPart.KeyframeMotion = new KeyframeMotion(group, mode, data);
  6517. idx = 0;
  6518. int elemLength = 2;
  6519. if (data == (KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation))
  6520. elemLength = 3;
  6521. List<KeyframeMotion.Keyframe> keyframes = new List<KeyframeMotion.Keyframe>();
  6522. while (idx < frames.Data.Length)
  6523. {
  6524. int remain = frames.Data.Length - idx;
  6525. if (remain < elemLength)
  6526. break;
  6527. KeyframeMotion.Keyframe frame = new KeyframeMotion.Keyframe();
  6528. frame.Position = null;
  6529. frame.Rotation = null;
  6530. if ((data & KeyframeMotion.DataFormat.Translation) != 0)
  6531. {
  6532. LSL_Types.Vector3 tempv = frames.GetVector3Item(idx++);
  6533. frame.Position = new Vector3((float)tempv.x, (float)tempv.y, (float)tempv.z);
  6534. }
  6535. if ((data & KeyframeMotion.DataFormat.Rotation) != 0)
  6536. {
  6537. LSL_Types.Quaternion tempq = frames.GetQuaternionItem(idx++);
  6538. Quaternion q = new Quaternion((float)tempq.x, (float)tempq.y, (float)tempq.z, (float)tempq.s);
  6539. q.Normalize();
  6540. frame.Rotation = q;
  6541. }
  6542. float tempf = (float)frames.GetLSLFloatItem(idx++);
  6543. frame.TimeMS = (int)(tempf * 1000.0f);
  6544. keyframes.Add(frame);
  6545. }
  6546. group.RootPart.KeyframeMotion.SetKeyframes(keyframes.ToArray());
  6547. group.RootPart.KeyframeMotion.Start();
  6548. }
  6549. else
  6550. {
  6551. if (group.RootPart.KeyframeMotion == null)
  6552. return;
  6553. if (options.Data.Length == 0)
  6554. {
  6555. group.RootPart.KeyframeMotion.Stop();
  6556. return;
  6557. }
  6558. int idx = 0;
  6559. while (idx < options.Data.Length)
  6560. {
  6561. int option = (int)options.GetLSLIntegerItem(idx++);
  6562. switch (option)
  6563. {
  6564. case ScriptBaseClass.KFM_COMMAND:
  6565. int cmd = (int)options.GetLSLIntegerItem(idx++);
  6566. switch (cmd)
  6567. {
  6568. case ScriptBaseClass.KFM_CMD_PLAY:
  6569. group.RootPart.KeyframeMotion.Start();
  6570. break;
  6571. case ScriptBaseClass.KFM_CMD_STOP:
  6572. group.RootPart.KeyframeMotion.Stop();
  6573. break;
  6574. case ScriptBaseClass.KFM_CMD_PAUSE:
  6575. group.RootPart.KeyframeMotion.Pause();
  6576. break;
  6577. }
  6578. break;
  6579. }
  6580. }
  6581. }
  6582. }
  6583. protected LSL_List SetPrimParams(SceneObjectPart part, LSL_List rules, string originFunc, ref uint rulesParsed)
  6584. {
  6585. int idx = 0;
  6586. int idxStart = 0;
  6587. bool positionChanged = false;
  6588. LSL_Vector currentPosition = GetPartLocalPos(part);
  6589. try
  6590. {
  6591. while (idx < rules.Length)
  6592. {
  6593. ++rulesParsed;
  6594. int code = rules.GetLSLIntegerItem(idx++);
  6595. int remain = rules.Length - idx;
  6596. idxStart = idx;
  6597. int face;
  6598. LSL_Vector v;
  6599. switch (code)
  6600. {
  6601. case (int)ScriptBaseClass.PRIM_POSITION:
  6602. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  6603. if (remain < 1)
  6604. return null;
  6605. v=rules.GetVector3Item(idx++);
  6606. positionChanged = true;
  6607. currentPosition = GetSetPosTarget(part, v, currentPosition);
  6608. break;
  6609. case (int)ScriptBaseClass.PRIM_SIZE:
  6610. if (remain < 1)
  6611. return null;
  6612. v=rules.GetVector3Item(idx++);
  6613. SetScale(part, v);
  6614. break;
  6615. case (int)ScriptBaseClass.PRIM_ROTATION:
  6616. if (remain < 1)
  6617. return null;
  6618. LSL_Rotation q = rules.GetQuaternionItem(idx++);
  6619. // try to let this work as in SL...
  6620. if (part.ParentID == 0)
  6621. {
  6622. // special case: If we are root, rotate complete SOG to new rotation
  6623. SetRot(part, q);
  6624. }
  6625. else
  6626. {
  6627. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  6628. SceneObjectPart rootPart = part.ParentGroup.RootPart;
  6629. SetRot(part, rootPart.RotationOffset * (Quaternion)q);
  6630. }
  6631. break;
  6632. case (int)ScriptBaseClass.PRIM_TYPE:
  6633. if (remain < 3)
  6634. return null;
  6635. code = (int)rules.GetLSLIntegerItem(idx++);
  6636. remain = rules.Length - idx;
  6637. float hollow;
  6638. LSL_Vector twist;
  6639. LSL_Vector taper_b;
  6640. LSL_Vector topshear;
  6641. float revolutions;
  6642. float radiusoffset;
  6643. float skew;
  6644. LSL_Vector holesize;
  6645. LSL_Vector profilecut;
  6646. switch (code)
  6647. {
  6648. case (int)ScriptBaseClass.PRIM_TYPE_BOX:
  6649. if (remain < 6)
  6650. return null;
  6651. face = (int)rules.GetLSLIntegerItem(idx++);
  6652. v = rules.GetVector3Item(idx++); // cut
  6653. hollow = (float)rules.GetLSLFloatItem(idx++);
  6654. twist = rules.GetVector3Item(idx++);
  6655. taper_b = rules.GetVector3Item(idx++);
  6656. topshear = rules.GetVector3Item(idx++);
  6657. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  6658. (byte)ProfileShape.Square, (byte)Extrusion.Straight);
  6659. break;
  6660. case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
  6661. if (remain < 6)
  6662. return null;
  6663. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6664. v = rules.GetVector3Item(idx++); // cut
  6665. hollow = (float)rules.GetLSLFloatItem(idx++);
  6666. twist = rules.GetVector3Item(idx++);
  6667. taper_b = rules.GetVector3Item(idx++);
  6668. topshear = rules.GetVector3Item(idx++);
  6669. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  6670. (byte)ProfileShape.Circle, (byte)Extrusion.Straight);
  6671. break;
  6672. case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
  6673. if (remain < 6)
  6674. return null;
  6675. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6676. v = rules.GetVector3Item(idx++); //cut
  6677. hollow = (float)rules.GetLSLFloatItem(idx++);
  6678. twist = rules.GetVector3Item(idx++);
  6679. taper_b = rules.GetVector3Item(idx++);
  6680. topshear = rules.GetVector3Item(idx++);
  6681. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  6682. (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Straight);
  6683. break;
  6684. case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
  6685. if (remain < 5)
  6686. return null;
  6687. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6688. v = rules.GetVector3Item(idx++); // cut
  6689. hollow = (float)rules.GetLSLFloatItem(idx++);
  6690. twist = rules.GetVector3Item(idx++);
  6691. taper_b = rules.GetVector3Item(idx++); // dimple
  6692. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b,
  6693. (byte)ProfileShape.HalfCircle, (byte)Extrusion.Curve1);
  6694. break;
  6695. case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
  6696. if (remain < 11)
  6697. return null;
  6698. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6699. v = rules.GetVector3Item(idx++); //cut
  6700. hollow = (float)rules.GetLSLFloatItem(idx++);
  6701. twist = rules.GetVector3Item(idx++);
  6702. holesize = rules.GetVector3Item(idx++);
  6703. topshear = rules.GetVector3Item(idx++);
  6704. profilecut = rules.GetVector3Item(idx++);
  6705. taper_b = rules.GetVector3Item(idx++); // taper_a
  6706. revolutions = (float)rules.GetLSLFloatItem(idx++);
  6707. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  6708. skew = (float)rules.GetLSLFloatItem(idx++);
  6709. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  6710. revolutions, radiusoffset, skew, (byte)ProfileShape.Circle, (byte)Extrusion.Curve1);
  6711. break;
  6712. case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
  6713. if (remain < 11)
  6714. return null;
  6715. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6716. v = rules.GetVector3Item(idx++); //cut
  6717. hollow = (float)rules.GetLSLFloatItem(idx++);
  6718. twist = rules.GetVector3Item(idx++);
  6719. holesize = rules.GetVector3Item(idx++);
  6720. topshear = rules.GetVector3Item(idx++);
  6721. profilecut = rules.GetVector3Item(idx++);
  6722. taper_b = rules.GetVector3Item(idx++); // taper_a
  6723. revolutions = (float)rules.GetLSLFloatItem(idx++);
  6724. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  6725. skew = (float)rules.GetLSLFloatItem(idx++);
  6726. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  6727. revolutions, radiusoffset, skew, (byte)ProfileShape.Square, (byte)Extrusion.Curve1);
  6728. break;
  6729. case (int)ScriptBaseClass.PRIM_TYPE_RING:
  6730. if (remain < 11)
  6731. return null;
  6732. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6733. v = rules.GetVector3Item(idx++); //cut
  6734. hollow = (float)rules.GetLSLFloatItem(idx++);
  6735. twist = rules.GetVector3Item(idx++);
  6736. holesize = rules.GetVector3Item(idx++);
  6737. topshear = rules.GetVector3Item(idx++);
  6738. profilecut = rules.GetVector3Item(idx++);
  6739. taper_b = rules.GetVector3Item(idx++); // taper_a
  6740. revolutions = (float)rules.GetLSLFloatItem(idx++);
  6741. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  6742. skew = (float)rules.GetLSLFloatItem(idx++);
  6743. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  6744. revolutions, radiusoffset, skew, (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Curve1);
  6745. break;
  6746. case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
  6747. if (remain < 2)
  6748. return null;
  6749. string map = rules.Data[idx++].ToString();
  6750. face = (int)rules.GetLSLIntegerItem(idx++); // type
  6751. SetPrimitiveShapeParams(part, map, face, (byte)Extrusion.Curve1);
  6752. break;
  6753. }
  6754. break;
  6755. case (int)ScriptBaseClass.PRIM_TEXTURE:
  6756. if (remain < 5)
  6757. return null;
  6758. face=(int)rules.GetLSLIntegerItem(idx++);
  6759. string tex=rules.Data[idx++].ToString();
  6760. LSL_Vector repeats=rules.GetVector3Item(idx++);
  6761. LSL_Vector offsets=rules.GetVector3Item(idx++);
  6762. double rotation=(double)rules.GetLSLFloatItem(idx++);
  6763. SetTexture(part, tex, face);
  6764. ScaleTexture(part, repeats.x, repeats.y, face);
  6765. OffsetTexture(part, offsets.x, offsets.y, face);
  6766. RotateTexture(part, rotation, face);
  6767. break;
  6768. case (int)ScriptBaseClass.PRIM_COLOR:
  6769. if (remain < 3)
  6770. return null;
  6771. face=(int)rules.GetLSLIntegerItem(idx++);
  6772. LSL_Vector color=rules.GetVector3Item(idx++);
  6773. double alpha=(double)rules.GetLSLFloatItem(idx++);
  6774. part.SetFaceColorAlpha(face, color, alpha);
  6775. break;
  6776. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  6777. if (remain < 7)
  6778. return null;
  6779. bool flexi = rules.GetLSLIntegerItem(idx++);
  6780. int softness = rules.GetLSLIntegerItem(idx++);
  6781. float gravity = (float)rules.GetLSLFloatItem(idx++);
  6782. float friction = (float)rules.GetLSLFloatItem(idx++);
  6783. float wind = (float)rules.GetLSLFloatItem(idx++);
  6784. float tension = (float)rules.GetLSLFloatItem(idx++);
  6785. LSL_Vector force = rules.GetVector3Item(idx++);
  6786. SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force);
  6787. break;
  6788. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  6789. if (remain < 5)
  6790. return null;
  6791. bool light = rules.GetLSLIntegerItem(idx++);
  6792. LSL_Vector lightcolor = rules.GetVector3Item(idx++);
  6793. float intensity = (float)rules.GetLSLFloatItem(idx++);
  6794. float radius = (float)rules.GetLSLFloatItem(idx++);
  6795. float falloff = (float)rules.GetLSLFloatItem(idx++);
  6796. SetPointLight(part, light, lightcolor, intensity, radius, falloff);
  6797. break;
  6798. case (int)ScriptBaseClass.PRIM_GLOW:
  6799. if (remain < 2)
  6800. return null;
  6801. face = rules.GetLSLIntegerItem(idx++);
  6802. float glow = (float)rules.GetLSLFloatItem(idx++);
  6803. SetGlow(part, face, glow);
  6804. break;
  6805. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  6806. if (remain < 3)
  6807. return null;
  6808. face = (int)rules.GetLSLIntegerItem(idx++);
  6809. int shiny = (int)rules.GetLSLIntegerItem(idx++);
  6810. Bumpiness bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);
  6811. SetShiny(part, face, shiny, bump);
  6812. break;
  6813. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  6814. if (remain < 2)
  6815. return null;
  6816. face = rules.GetLSLIntegerItem(idx++);
  6817. bool st = rules.GetLSLIntegerItem(idx++);
  6818. SetFullBright(part, face , st);
  6819. break;
  6820. case (int)ScriptBaseClass.PRIM_MATERIAL:
  6821. if (remain < 1)
  6822. return null;
  6823. int mat = rules.GetLSLIntegerItem(idx++);
  6824. if (mat < 0 || mat > 7)
  6825. return null;
  6826. part.Material = Convert.ToByte(mat);
  6827. break;
  6828. case (int)ScriptBaseClass.PRIM_PHANTOM:
  6829. if (remain < 1)
  6830. return null;
  6831. string ph = rules.Data[idx++].ToString();
  6832. part.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1"));
  6833. break;
  6834. case (int)ScriptBaseClass.PRIM_PHYSICS:
  6835. if (remain < 1)
  6836. return null;
  6837. string phy = rules.Data[idx++].ToString();
  6838. bool physics;
  6839. if (phy.Equals("1"))
  6840. physics = true;
  6841. else
  6842. physics = false;
  6843. part.ScriptSetPhysicsStatus(physics);
  6844. break;
  6845. case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  6846. if (remain < 1)
  6847. return null;
  6848. int shape_type = rules.GetLSLIntegerItem(idx++);
  6849. ExtraPhysicsData physdata = new ExtraPhysicsData();
  6850. physdata.Density = part.Density;
  6851. physdata.Bounce = part.Restitution;
  6852. physdata.GravitationModifier = part.GravityModifier;
  6853. physdata.PhysShapeType = (PhysShapeType)shape_type;
  6854. part.UpdateExtraPhysics(physdata);
  6855. break;
  6856. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  6857. if (remain < 1)
  6858. return null;
  6859. string temp = rules.Data[idx++].ToString();
  6860. part.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1"));
  6861. break;
  6862. case (int)ScriptBaseClass.PRIM_TEXGEN:
  6863. if (remain < 2)
  6864. return null;
  6865. //face,type
  6866. face = rules.GetLSLIntegerItem(idx++);
  6867. int style = rules.GetLSLIntegerItem(idx++);
  6868. SetTexGen(part, face, style);
  6869. break;
  6870. case (int)ScriptBaseClass.PRIM_TEXT:
  6871. if (remain < 3)
  6872. return null;
  6873. string primText = rules.GetLSLStringItem(idx++);
  6874. LSL_Vector primTextColor = rules.GetVector3Item(idx++);
  6875. LSL_Float primTextAlpha = rules.GetLSLFloatItem(idx++);
  6876. Vector3 av3 = Util.Clip(primTextColor, 0.0f, 1.0f);
  6877. part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f));
  6878. break;
  6879. case (int)ScriptBaseClass.PRIM_NAME:
  6880. if (remain < 1)
  6881. return null;
  6882. string primName = rules.GetLSLStringItem(idx++);
  6883. part.Name = primName;
  6884. break;
  6885. case (int)ScriptBaseClass.PRIM_DESC:
  6886. if (remain < 1)
  6887. return null;
  6888. string primDesc = rules.GetLSLStringItem(idx++);
  6889. part.Description = primDesc;
  6890. break;
  6891. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  6892. if (remain < 1)
  6893. return null;
  6894. SetRot(part, rules.GetQuaternionItem(idx++));
  6895. break;
  6896. case (int)ScriptBaseClass.PRIM_OMEGA:
  6897. if (remain < 3)
  6898. return null;
  6899. LSL_Vector axis = rules.GetVector3Item(idx++);
  6900. LSL_Float spinrate = rules.GetLSLFloatItem(idx++);
  6901. LSL_Float gain = rules.GetLSLFloatItem(idx++);
  6902. TargetOmega(part, axis, (double)spinrate, (double)gain);
  6903. break;
  6904. case (int)ScriptBaseClass.PRIM_SLICE:
  6905. if (remain < 1)
  6906. return null;
  6907. LSL_Vector slice = rules.GetVector3Item(idx++);
  6908. part.UpdateSlice((float)slice.x, (float)slice.y);
  6909. break;
  6910. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  6911. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  6912. return null;
  6913. return rules.GetSublist(idx, -1);
  6914. }
  6915. }
  6916. }
  6917. catch (InvalidCastException e)
  6918. {
  6919. Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
  6920. }
  6921. finally
  6922. {
  6923. if (positionChanged)
  6924. {
  6925. if (part.ParentGroup.RootPart == part)
  6926. {
  6927. SceneObjectGroup parent = part.ParentGroup;
  6928. parent.UpdateGroupPosition(currentPosition);
  6929. }
  6930. else
  6931. {
  6932. part.OffsetPosition = currentPosition;
  6933. SceneObjectGroup parent = part.ParentGroup;
  6934. parent.HasGroupChanged = true;
  6935. parent.ScheduleGroupForTerseUpdate();
  6936. }
  6937. }
  6938. }
  6939. return null;
  6940. }
  6941. protected LSL_List SetAgentParams(ScenePresence sp, LSL_List rules, string originFunc, ref uint rulesParsed)
  6942. {
  6943. int idx = 0;
  6944. int idxStart = 0;
  6945. try
  6946. {
  6947. while (idx < rules.Length)
  6948. {
  6949. ++rulesParsed;
  6950. int code = rules.GetLSLIntegerItem(idx++);
  6951. int remain = rules.Length - idx;
  6952. idxStart = idx;
  6953. switch (code)
  6954. {
  6955. case (int)ScriptBaseClass.PRIM_POSITION:
  6956. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  6957. if (remain < 1)
  6958. return null;
  6959. sp.OffsetPosition = rules.GetVector3Item(idx++);
  6960. break;
  6961. case (int)ScriptBaseClass.PRIM_ROTATION:
  6962. if (remain < 1)
  6963. return null;
  6964. Quaternion inRot = rules.GetQuaternionItem(idx++);
  6965. SceneObjectPart parentPart = sp.ParentPart;
  6966. if (parentPart != null)
  6967. sp.Rotation = m_host.GetWorldRotation() * inRot;
  6968. break;
  6969. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  6970. if (remain < 1)
  6971. return null;
  6972. sp.Rotation = rules.GetQuaternionItem(idx++);
  6973. break;
  6974. }
  6975. }
  6976. }
  6977. catch (InvalidCastException e)
  6978. {
  6979. Error(
  6980. originFunc,
  6981. string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
  6982. }
  6983. return null;
  6984. }
  6985. public LSL_String llStringToBase64(string str)
  6986. {
  6987. m_host.AddScriptLPS(1);
  6988. try
  6989. {
  6990. byte[] encData_byte = new byte[str.Length];
  6991. encData_byte = Util.UTF8.GetBytes(str);
  6992. string encodedData = Convert.ToBase64String(encData_byte);
  6993. return encodedData;
  6994. }
  6995. catch
  6996. {
  6997. Error("llBase64ToString", "Error encoding string");
  6998. return String.Empty;
  6999. }
  7000. }
  7001. public LSL_String llBase64ToString(string str)
  7002. {
  7003. m_host.AddScriptLPS(1);
  7004. try
  7005. {
  7006. return Util.Base64ToString(str);
  7007. }
  7008. catch
  7009. {
  7010. Error("llBase64ToString", "Error decoding string");
  7011. return String.Empty;
  7012. }
  7013. }
  7014. public LSL_String llXorBase64Strings(string str1, string str2)
  7015. {
  7016. m_host.AddScriptLPS(1);
  7017. Deprecated("llXorBase64Strings", "Use llXorBase64 instead");
  7018. ScriptSleep(300);
  7019. return String.Empty;
  7020. }
  7021. public void llRemoteDataSetRegion()
  7022. {
  7023. m_host.AddScriptLPS(1);
  7024. Deprecated("llRemoteDataSetRegion", "Use llOpenRemoteDataChannel instead");
  7025. }
  7026. public LSL_Float llLog10(double val)
  7027. {
  7028. m_host.AddScriptLPS(1);
  7029. return (double)Math.Log10(val);
  7030. }
  7031. public LSL_Float llLog(double val)
  7032. {
  7033. m_host.AddScriptLPS(1);
  7034. return (double)Math.Log(val);
  7035. }
  7036. public LSL_List llGetAnimationList(string id)
  7037. {
  7038. m_host.AddScriptLPS(1);
  7039. LSL_List l = new LSL_List();
  7040. ScenePresence av = World.GetScenePresence((UUID)id);
  7041. if (av == null || av.IsChildAgent) // only if in the region
  7042. return l;
  7043. UUID[] anims;
  7044. anims = av.Animator.GetAnimationArray();
  7045. foreach (UUID foo in anims)
  7046. l.Add(new LSL_Key(foo.ToString()));
  7047. return l;
  7048. }
  7049. public void llSetParcelMusicURL(string url)
  7050. {
  7051. m_host.AddScriptLPS(1);
  7052. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  7053. if (land.LandData.OwnerID != m_host.OwnerID)
  7054. return;
  7055. land.SetMusicUrl(url);
  7056. ScriptSleep(2000);
  7057. }
  7058. public LSL_String llGetParcelMusicURL()
  7059. {
  7060. m_host.AddScriptLPS(1);
  7061. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  7062. if (land.LandData.OwnerID != m_host.OwnerID)
  7063. return String.Empty;
  7064. return land.GetMusicUrl();
  7065. }
  7066. public LSL_Vector llGetRootPosition()
  7067. {
  7068. m_host.AddScriptLPS(1);
  7069. return new LSL_Vector(m_host.ParentGroup.AbsolutePosition);
  7070. }
  7071. /// <summary>
  7072. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetRot
  7073. /// http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  7074. /// Also tested in sl in regards to the behaviour in attachments/mouselook
  7075. /// In the root prim:-
  7076. /// Returns the object rotation if not attached
  7077. /// Returns the avatars rotation if attached
  7078. /// Returns the camera rotation if attached and the avatar is in mouselook
  7079. /// </summary>
  7080. public LSL_Rotation llGetRootRotation()
  7081. {
  7082. m_host.AddScriptLPS(1);
  7083. Quaternion q;
  7084. if (m_host.ParentGroup.AttachmentPoint != 0)
  7085. {
  7086. ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  7087. if (avatar != null)
  7088. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  7089. q = avatar.CameraRotation; // Mouselook
  7090. else
  7091. q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate
  7092. else
  7093. q = m_host.ParentGroup.GroupRotation; // Likely never get here but just in case
  7094. }
  7095. else
  7096. q = m_host.ParentGroup.GroupRotation; // just the group rotation
  7097. return new LSL_Rotation(q);
  7098. }
  7099. public LSL_String llGetObjectDesc()
  7100. {
  7101. return m_host.Description!=null?m_host.Description:String.Empty;
  7102. }
  7103. public void llSetObjectDesc(string desc)
  7104. {
  7105. m_host.AddScriptLPS(1);
  7106. m_host.Description = desc!=null?desc:String.Empty;
  7107. }
  7108. public LSL_String llGetCreator()
  7109. {
  7110. m_host.AddScriptLPS(1);
  7111. return m_host.CreatorID.ToString();
  7112. }
  7113. public LSL_String llGetTimestamp()
  7114. {
  7115. m_host.AddScriptLPS(1);
  7116. return DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
  7117. }
  7118. public LSL_Integer llGetNumberOfPrims()
  7119. {
  7120. m_host.AddScriptLPS(1);
  7121. return m_host.ParentGroup.PrimCount + m_host.ParentGroup.GetSittingAvatarsCount();
  7122. }
  7123. /// <summary>
  7124. /// A partial implementation.
  7125. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetBoundingBox
  7126. /// So far only valid for standing/flying/ground sitting avatars and single prim objects.
  7127. /// If the object has multiple prims and/or a sitting avatar then the bounding
  7128. /// box is for the root prim only.
  7129. /// </summary>
  7130. public LSL_List llGetBoundingBox(string obj)
  7131. {
  7132. m_host.AddScriptLPS(1);
  7133. UUID objID = UUID.Zero;
  7134. LSL_List result = new LSL_List();
  7135. if (!UUID.TryParse(obj, out objID))
  7136. {
  7137. result.Add(new LSL_Vector());
  7138. result.Add(new LSL_Vector());
  7139. return result;
  7140. }
  7141. ScenePresence presence = World.GetScenePresence(objID);
  7142. if (presence != null)
  7143. {
  7144. if (presence.ParentID == 0) // not sat on an object
  7145. {
  7146. LSL_Vector lower;
  7147. LSL_Vector upper;
  7148. if (presence.Animator.Animations.ImplicitDefaultAnimation.AnimID
  7149. == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  7150. {
  7151. // This is for ground sitting avatars
  7152. float height = presence.Appearance.AvatarHeight / 2.66666667f;
  7153. lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
  7154. upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
  7155. }
  7156. else
  7157. {
  7158. // This is for standing/flying avatars
  7159. float height = presence.Appearance.AvatarHeight / 2.0f;
  7160. lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
  7161. upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
  7162. }
  7163. result.Add(lower);
  7164. result.Add(upper);
  7165. return result;
  7166. }
  7167. else
  7168. {
  7169. // sitting on an object so we need the bounding box of that
  7170. // which should include the avatar so set the UUID to the
  7171. // UUID of the object the avatar is sat on and allow it to fall through
  7172. // to processing an object
  7173. SceneObjectPart p = World.GetSceneObjectPart(presence.ParentID);
  7174. objID = p.UUID;
  7175. }
  7176. }
  7177. SceneObjectPart part = World.GetSceneObjectPart(objID);
  7178. // Currently only works for single prims without a sitting avatar
  7179. if (part != null)
  7180. {
  7181. Vector3 halfSize = part.Scale / 2.0f;
  7182. LSL_Vector lower = (new LSL_Vector(halfSize)) * -1.0f;
  7183. LSL_Vector upper = new LSL_Vector(halfSize);
  7184. result.Add(lower);
  7185. result.Add(upper);
  7186. return result;
  7187. }
  7188. // Not found so return empty values
  7189. result.Add(new LSL_Vector());
  7190. result.Add(new LSL_Vector());
  7191. return result;
  7192. }
  7193. public LSL_Vector llGetGeometricCenter()
  7194. {
  7195. return new LSL_Vector(m_host.GetGeometricCenter());
  7196. }
  7197. public LSL_List GetEntityParams(ISceneEntity entity, LSL_List rules)
  7198. {
  7199. LSL_List result = new LSL_List();
  7200. LSL_List remaining = null;
  7201. while (true)
  7202. {
  7203. // m_log.DebugFormat(
  7204. // "[LSL API]: GetEntityParams has {0} rules with scene entity named {1}",
  7205. // rules.Length, entity != null ? entity.Name : "NULL");
  7206. if (entity == null)
  7207. return result;
  7208. if (entity is SceneObjectPart)
  7209. remaining = GetPrimParams((SceneObjectPart)entity, rules, ref result);
  7210. else
  7211. remaining = GetAgentParams((ScenePresence)entity, rules, ref result);
  7212. if (remaining == null || remaining.Length < 2)
  7213. return result;
  7214. int linknumber = remaining.GetLSLIntegerItem(0);
  7215. rules = remaining.GetSublist(1, -1);
  7216. entity = GetLinkEntity(m_host, linknumber);
  7217. }
  7218. }
  7219. public LSL_List llGetPrimitiveParams(LSL_List rules)
  7220. {
  7221. m_host.AddScriptLPS(1);
  7222. return GetEntityParams(m_host, rules);
  7223. }
  7224. public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules)
  7225. {
  7226. m_host.AddScriptLPS(1);
  7227. return GetEntityParams(GetLinkEntity(m_host, linknumber), rules);
  7228. }
  7229. public LSL_Vector GetAgentSize(ScenePresence sp)
  7230. {
  7231. return new LSL_Vector(0.45, 0.6, sp.Appearance.AvatarHeight);
  7232. }
  7233. /// <summary>
  7234. /// Gets params for a seated avatar in a linkset.
  7235. /// </summary>
  7236. /// <returns></returns>
  7237. /// <param name='sp'></param>
  7238. /// <param name='rules'></param>
  7239. /// <param name='res'></param>
  7240. public LSL_List GetAgentParams(ScenePresence sp, LSL_List rules, ref LSL_List res)
  7241. {
  7242. int idx = 0;
  7243. while (idx < rules.Length)
  7244. {
  7245. int code = (int)rules.GetLSLIntegerItem(idx++);
  7246. int remain = rules.Length-idx;
  7247. switch (code)
  7248. {
  7249. case (int)ScriptBaseClass.PRIM_MATERIAL:
  7250. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MATERIAL_FLESH));
  7251. break;
  7252. case (int)ScriptBaseClass.PRIM_PHYSICS:
  7253. res.Add(ScriptBaseClass.FALSE);
  7254. break;
  7255. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  7256. res.Add(ScriptBaseClass.FALSE);
  7257. break;
  7258. case (int)ScriptBaseClass.PRIM_PHANTOM:
  7259. res.Add(ScriptBaseClass.FALSE);
  7260. break;
  7261. case (int)ScriptBaseClass.PRIM_POSITION:
  7262. res.Add(new LSL_Vector(sp.AbsolutePosition));
  7263. break;
  7264. case (int)ScriptBaseClass.PRIM_SIZE:
  7265. res.Add(GetAgentSize(sp));
  7266. break;
  7267. case (int)ScriptBaseClass.PRIM_ROTATION:
  7268. res.Add(sp.GetWorldRotation());
  7269. break;
  7270. case (int)ScriptBaseClass.PRIM_TYPE:
  7271. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TYPE_BOX));
  7272. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_HOLE_DEFAULT));
  7273. res.Add(new LSL_Vector(0, 1, 0));
  7274. res.Add(new LSL_Float(0));
  7275. res.Add(new LSL_Vector(0, 0, 0));
  7276. res.Add(new LSL_Vector(1, 1, 0));
  7277. res.Add(new LSL_Vector(0, 0, 0));
  7278. break;
  7279. case (int)ScriptBaseClass.PRIM_TEXTURE:
  7280. if (remain < 1)
  7281. return null;
  7282. int face = (int)rules.GetLSLIntegerItem(idx++);
  7283. if (face > 21)
  7284. break;
  7285. res.Add(new LSL_String(""));
  7286. res.Add(ScriptBaseClass.ZERO_VECTOR);
  7287. res.Add(ScriptBaseClass.ZERO_VECTOR);
  7288. res.Add(new LSL_Float(0));
  7289. break;
  7290. case (int)ScriptBaseClass.PRIM_COLOR:
  7291. if (remain < 1)
  7292. return null;
  7293. face = (int)rules.GetLSLIntegerItem(idx++);
  7294. if (face > 21)
  7295. break;
  7296. res.Add(ScriptBaseClass.ZERO_VECTOR);
  7297. res.Add(new LSL_Float(0));
  7298. break;
  7299. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  7300. if (remain < 1)
  7301. return null;
  7302. face = (int)rules.GetLSLIntegerItem(idx++);
  7303. if (face > 21)
  7304. break;
  7305. res.Add(ScriptBaseClass.PRIM_SHINY_NONE);
  7306. res.Add(ScriptBaseClass.PRIM_BUMP_NONE);
  7307. break;
  7308. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  7309. if (remain < 1)
  7310. return null;
  7311. face = (int)rules.GetLSLIntegerItem(idx++);
  7312. if (face > 21)
  7313. break;
  7314. res.Add(ScriptBaseClass.FALSE);
  7315. break;
  7316. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  7317. res.Add(ScriptBaseClass.FALSE);
  7318. res.Add(new LSL_Integer(0));
  7319. res.Add(new LSL_Float(0));
  7320. res.Add(new LSL_Float(0));
  7321. res.Add(new LSL_Float(0));
  7322. res.Add(new LSL_Float(0));
  7323. res.Add(ScriptBaseClass.ZERO_VECTOR);
  7324. break;
  7325. case (int)ScriptBaseClass.PRIM_TEXGEN:
  7326. if (remain < 1)
  7327. return null;
  7328. face = (int)rules.GetLSLIntegerItem(idx++);
  7329. if (face > 21)
  7330. break;
  7331. res.Add(ScriptBaseClass.PRIM_TEXGEN_DEFAULT);
  7332. break;
  7333. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  7334. res.Add(ScriptBaseClass.FALSE);
  7335. res.Add(ScriptBaseClass.ZERO_VECTOR);
  7336. res.Add(ScriptBaseClass.ZERO_VECTOR);
  7337. break;
  7338. case (int)ScriptBaseClass.PRIM_GLOW:
  7339. if (remain < 1)
  7340. return null;
  7341. face = (int)rules.GetLSLIntegerItem(idx++);
  7342. if (face > 21)
  7343. break;
  7344. res.Add(new LSL_Float(0));
  7345. break;
  7346. case (int)ScriptBaseClass.PRIM_TEXT:
  7347. res.Add(new LSL_String(""));
  7348. res.Add(ScriptBaseClass.ZERO_VECTOR);
  7349. res.Add(new LSL_Float(1));
  7350. break;
  7351. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  7352. res.Add(new LSL_Rotation(sp.Rotation));
  7353. break;
  7354. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  7355. res.Add(new LSL_Vector(sp.OffsetPosition));
  7356. break;
  7357. case (int)ScriptBaseClass.PRIM_SLICE:
  7358. res.Add(new LSL_Vector(0, 1, 0));
  7359. break;
  7360. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  7361. if(remain < 3)
  7362. return null;
  7363. return rules.GetSublist(idx, -1);
  7364. }
  7365. }
  7366. return null;
  7367. }
  7368. public LSL_List GetPrimParams(SceneObjectPart part, LSL_List rules, ref LSL_List res)
  7369. {
  7370. int idx = 0;
  7371. while (idx < rules.Length)
  7372. {
  7373. int code = (int)rules.GetLSLIntegerItem(idx++);
  7374. int remain = rules.Length - idx;
  7375. switch (code)
  7376. {
  7377. case (int)ScriptBaseClass.PRIM_MATERIAL:
  7378. res.Add(new LSL_Integer(part.Material));
  7379. break;
  7380. case (int)ScriptBaseClass.PRIM_PHYSICS:
  7381. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) != 0)
  7382. res.Add(new LSL_Integer(1));
  7383. else
  7384. res.Add(new LSL_Integer(0));
  7385. break;
  7386. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  7387. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.TemporaryOnRez) != 0)
  7388. res.Add(new LSL_Integer(1));
  7389. else
  7390. res.Add(new LSL_Integer(0));
  7391. break;
  7392. case (int)ScriptBaseClass.PRIM_PHANTOM:
  7393. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) != 0)
  7394. res.Add(new LSL_Integer(1));
  7395. else
  7396. res.Add(new LSL_Integer(0));
  7397. break;
  7398. case (int)ScriptBaseClass.PRIM_POSITION:
  7399. LSL_Vector v = new LSL_Vector(part.AbsolutePosition);
  7400. // For some reason, the part.AbsolutePosition.* values do not change if the
  7401. // linkset is rotated; they always reflect the child prim's world position
  7402. // as though the linkset is unrotated. This is incompatible behavior with SL's
  7403. // implementation, so will break scripts imported from there (not to mention it
  7404. // makes it more difficult to determine a child prim's actual inworld position).
  7405. if (!part.IsRoot)
  7406. {
  7407. LSL_Vector rootPos = new LSL_Vector(m_host.ParentGroup.AbsolutePosition);
  7408. v = ((v - rootPos) * llGetRootRotation()) + rootPos;
  7409. }
  7410. res.Add(v);
  7411. break;
  7412. case (int)ScriptBaseClass.PRIM_SIZE:
  7413. res.Add(new LSL_Vector(part.Scale));
  7414. break;
  7415. case (int)ScriptBaseClass.PRIM_ROTATION:
  7416. res.Add(GetPartRot(part));
  7417. break;
  7418. case (int)ScriptBaseClass.PRIM_TYPE:
  7419. // implementing box
  7420. PrimitiveBaseShape Shape = part.Shape;
  7421. int primType = (int)part.GetPrimType();
  7422. res.Add(new LSL_Integer(primType));
  7423. double topshearx = (double)(sbyte)Shape.PathShearX / 100.0; // Fix negative values for PathShearX
  7424. double topsheary = (double)(sbyte)Shape.PathShearY / 100.0; // and PathShearY.
  7425. switch (primType)
  7426. {
  7427. case ScriptBaseClass.PRIM_TYPE_BOX:
  7428. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  7429. case ScriptBaseClass.PRIM_TYPE_PRISM:
  7430. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  7431. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  7432. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  7433. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  7434. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  7435. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  7436. break;
  7437. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  7438. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  7439. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  7440. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  7441. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  7442. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  7443. break;
  7444. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  7445. res.Add(new LSL_String(Shape.SculptTexture.ToString()));
  7446. res.Add(new LSL_Integer(Shape.SculptType));
  7447. break;
  7448. case ScriptBaseClass.PRIM_TYPE_RING:
  7449. case ScriptBaseClass.PRIM_TYPE_TUBE:
  7450. case ScriptBaseClass.PRIM_TYPE_TORUS:
  7451. // holeshape
  7452. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  7453. // cut
  7454. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  7455. // hollow
  7456. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  7457. // twist
  7458. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  7459. // vector holesize
  7460. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  7461. // vector topshear
  7462. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  7463. // vector profilecut
  7464. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  7465. // vector tapera
  7466. res.Add(new LSL_Vector(Shape.PathTaperX / 100.0, Shape.PathTaperY / 100.0, 0));
  7467. // float revolutions
  7468. res.Add(new LSL_Float(Math.Round(Shape.PathRevolutions * 0.015d, 2, MidpointRounding.AwayFromZero)) + 1.0d);
  7469. // Slightly inaccurate, because an unsigned byte is being used to represent
  7470. // the entire range of floating-point values from 1.0 through 4.0 (which is how
  7471. // SL does it).
  7472. //
  7473. // Using these formulas to store and retrieve PathRevolutions, it is not
  7474. // possible to use all values between 1.00 and 4.00. For instance, you can't
  7475. // represent 1.10. You can represent 1.09 and 1.11, but not 1.10. So, if you
  7476. // use llSetPrimitiveParams to set revolutions to 1.10 and then retreive them
  7477. // with llGetPrimitiveParams, you'll retrieve 1.09. You can also see a similar
  7478. // behavior in the viewer as you cannot set 1.10. The viewer jumps to 1.11.
  7479. // In SL, llSetPrimitveParams and llGetPrimitiveParams can set and get a value
  7480. // such as 1.10. So, SL must store and retreive the actual user input rather
  7481. // than only storing the encoded value.
  7482. // float radiusoffset
  7483. res.Add(new LSL_Float(Shape.PathRadiusOffset / 100.0));
  7484. // float skew
  7485. res.Add(new LSL_Float(Shape.PathSkew / 100.0));
  7486. break;
  7487. }
  7488. break;
  7489. case (int)ScriptBaseClass.PRIM_TEXTURE:
  7490. if (remain < 1)
  7491. return null;
  7492. int face = (int)rules.GetLSLIntegerItem(idx++);
  7493. Primitive.TextureEntry tex = part.Shape.Textures;
  7494. if (face == ScriptBaseClass.ALL_SIDES)
  7495. {
  7496. for (face = 0 ; face < GetNumberOfSides(part); face++)
  7497. {
  7498. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  7499. res.Add(new LSL_String(texface.TextureID.ToString()));
  7500. res.Add(new LSL_Vector(texface.RepeatU,
  7501. texface.RepeatV,
  7502. 0));
  7503. res.Add(new LSL_Vector(texface.OffsetU,
  7504. texface.OffsetV,
  7505. 0));
  7506. res.Add(new LSL_Float(texface.Rotation));
  7507. }
  7508. }
  7509. else
  7510. {
  7511. if (face >= 0 && face < GetNumberOfSides(part))
  7512. {
  7513. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  7514. res.Add(new LSL_String(texface.TextureID.ToString()));
  7515. res.Add(new LSL_Vector(texface.RepeatU,
  7516. texface.RepeatV,
  7517. 0));
  7518. res.Add(new LSL_Vector(texface.OffsetU,
  7519. texface.OffsetV,
  7520. 0));
  7521. res.Add(new LSL_Float(texface.Rotation));
  7522. }
  7523. }
  7524. break;
  7525. case (int)ScriptBaseClass.PRIM_COLOR:
  7526. if (remain < 1)
  7527. return null;
  7528. face=(int)rules.GetLSLIntegerItem(idx++);
  7529. tex = part.Shape.Textures;
  7530. Color4 texcolor;
  7531. if (face == ScriptBaseClass.ALL_SIDES)
  7532. {
  7533. for (face = 0 ; face < GetNumberOfSides(part); face++)
  7534. {
  7535. texcolor = tex.GetFace((uint)face).RGBA;
  7536. res.Add(new LSL_Vector(texcolor.R,
  7537. texcolor.G,
  7538. texcolor.B));
  7539. res.Add(new LSL_Float(texcolor.A));
  7540. }
  7541. }
  7542. else
  7543. {
  7544. texcolor = tex.GetFace((uint)face).RGBA;
  7545. res.Add(new LSL_Vector(texcolor.R,
  7546. texcolor.G,
  7547. texcolor.B));
  7548. res.Add(new LSL_Float(texcolor.A));
  7549. }
  7550. break;
  7551. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  7552. if (remain < 1)
  7553. return null;
  7554. face=(int)rules.GetLSLIntegerItem(idx++);
  7555. tex = part.Shape.Textures;
  7556. if (face == ScriptBaseClass.ALL_SIDES)
  7557. {
  7558. for (face = 0; face < GetNumberOfSides(part); face++)
  7559. {
  7560. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  7561. // Convert Shininess to PRIM_SHINY_*
  7562. res.Add(new LSL_Integer((uint)texface.Shiny >> 6));
  7563. // PRIM_BUMP_*
  7564. res.Add(new LSL_Integer((int)texface.Bump));
  7565. }
  7566. }
  7567. else
  7568. {
  7569. if (face >= 0 && face < GetNumberOfSides(part))
  7570. {
  7571. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  7572. // Convert Shininess to PRIM_SHINY_*
  7573. res.Add(new LSL_Integer((uint)texface.Shiny >> 6));
  7574. // PRIM_BUMP_*
  7575. res.Add(new LSL_Integer((int)texface.Bump));
  7576. }
  7577. }
  7578. break;
  7579. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  7580. if (remain < 1)
  7581. return null;
  7582. face = (int)rules.GetLSLIntegerItem(idx++);
  7583. tex = part.Shape.Textures;
  7584. if (face == ScriptBaseClass.ALL_SIDES)
  7585. {
  7586. for (face = 0; face < GetNumberOfSides(part); face++)
  7587. {
  7588. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  7589. res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
  7590. }
  7591. }
  7592. else
  7593. {
  7594. if (face >= 0 && face < GetNumberOfSides(part))
  7595. {
  7596. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  7597. res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
  7598. }
  7599. }
  7600. break;
  7601. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  7602. PrimitiveBaseShape shape = part.Shape;
  7603. if (shape.FlexiEntry)
  7604. res.Add(new LSL_Integer(1)); // active
  7605. else
  7606. res.Add(new LSL_Integer(0));
  7607. res.Add(new LSL_Integer(shape.FlexiSoftness));// softness
  7608. res.Add(new LSL_Float(shape.FlexiGravity)); // gravity
  7609. res.Add(new LSL_Float(shape.FlexiDrag)); // friction
  7610. res.Add(new LSL_Float(shape.FlexiWind)); // wind
  7611. res.Add(new LSL_Float(shape.FlexiTension)); // tension
  7612. res.Add(new LSL_Vector(shape.FlexiForceX, // force
  7613. shape.FlexiForceY,
  7614. shape.FlexiForceZ));
  7615. break;
  7616. case (int)ScriptBaseClass.PRIM_TEXGEN:
  7617. if (remain < 1)
  7618. return null;
  7619. face=(int)rules.GetLSLIntegerItem(idx++);
  7620. tex = part.Shape.Textures;
  7621. if (face == ScriptBaseClass.ALL_SIDES)
  7622. {
  7623. for (face = 0; face < GetNumberOfSides(part); face++)
  7624. {
  7625. MappingType texgen = tex.GetFace((uint)face).TexMapType;
  7626. // Convert MappingType to PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR etc.
  7627. res.Add(new LSL_Integer((uint)texgen >> 1));
  7628. }
  7629. }
  7630. else
  7631. {
  7632. if (face >= 0 && face < GetNumberOfSides(part))
  7633. {
  7634. MappingType texgen = tex.GetFace((uint)face).TexMapType;
  7635. res.Add(new LSL_Integer((uint)texgen >> 1));
  7636. }
  7637. }
  7638. break;
  7639. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  7640. shape = part.Shape;
  7641. if (shape.LightEntry)
  7642. res.Add(new LSL_Integer(1)); // active
  7643. else
  7644. res.Add(new LSL_Integer(0));
  7645. res.Add(new LSL_Vector(shape.LightColorR, // color
  7646. shape.LightColorG,
  7647. shape.LightColorB));
  7648. res.Add(new LSL_Float(shape.LightIntensity)); // intensity
  7649. res.Add(new LSL_Float(shape.LightRadius)); // radius
  7650. res.Add(new LSL_Float(shape.LightFalloff)); // falloff
  7651. break;
  7652. case (int)ScriptBaseClass.PRIM_GLOW:
  7653. if (remain < 1)
  7654. return null;
  7655. face=(int)rules.GetLSLIntegerItem(idx++);
  7656. tex = part.Shape.Textures;
  7657. if (face == ScriptBaseClass.ALL_SIDES)
  7658. {
  7659. for (face = 0; face < GetNumberOfSides(part); face++)
  7660. {
  7661. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  7662. res.Add(new LSL_Float(texface.Glow));
  7663. }
  7664. }
  7665. else
  7666. {
  7667. if (face >= 0 && face < GetNumberOfSides(part))
  7668. {
  7669. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  7670. res.Add(new LSL_Float(texface.Glow));
  7671. }
  7672. }
  7673. break;
  7674. case (int)ScriptBaseClass.PRIM_TEXT:
  7675. Color4 textColor = part.GetTextColor();
  7676. res.Add(new LSL_String(part.Text));
  7677. res.Add(new LSL_Vector(textColor.R,
  7678. textColor.G,
  7679. textColor.B));
  7680. res.Add(new LSL_Float(textColor.A));
  7681. break;
  7682. case (int)ScriptBaseClass.PRIM_NAME:
  7683. res.Add(new LSL_String(part.Name));
  7684. break;
  7685. case (int)ScriptBaseClass.PRIM_DESC:
  7686. res.Add(new LSL_String(part.Description));
  7687. break;
  7688. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  7689. res.Add(new LSL_Rotation(part.RotationOffset));
  7690. break;
  7691. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  7692. res.Add(new LSL_Vector(GetPartLocalPos(part)));
  7693. break;
  7694. case (int)ScriptBaseClass.PRIM_SLICE:
  7695. PrimType prim_type = part.GetPrimType();
  7696. bool useProfileBeginEnd = (prim_type == PrimType.SPHERE || prim_type == PrimType.TORUS || prim_type == PrimType.TUBE || prim_type == PrimType.RING);
  7697. res.Add(new LSL_Vector(
  7698. (useProfileBeginEnd ? part.Shape.ProfileBegin : part.Shape.PathBegin) / 50000.0,
  7699. 1 - (useProfileBeginEnd ? part.Shape.ProfileEnd : part.Shape.PathEnd) / 50000.0,
  7700. 0
  7701. ));
  7702. break;
  7703. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  7704. // TODO: Should be issuing a runtime script warning in this case.
  7705. if (remain < 2)
  7706. return null;
  7707. return rules.GetSublist(idx, -1);
  7708. }
  7709. }
  7710. return null;
  7711. }
  7712. public LSL_List llGetPrimMediaParams(int face, LSL_List rules)
  7713. {
  7714. m_host.AddScriptLPS(1);
  7715. ScriptSleep(1000);
  7716. return GetPrimMediaParams(m_host, face, rules);
  7717. }
  7718. public LSL_List llGetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules)
  7719. {
  7720. m_host.AddScriptLPS(1);
  7721. ScriptSleep(1000);
  7722. if (link == ScriptBaseClass.LINK_ROOT)
  7723. return GetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules);
  7724. else if (link == ScriptBaseClass.LINK_THIS)
  7725. return GetPrimMediaParams(m_host, face, rules);
  7726. else
  7727. {
  7728. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  7729. if (null != part)
  7730. return GetPrimMediaParams(part, face, rules);
  7731. }
  7732. return new LSL_List();
  7733. }
  7734. private LSL_List GetPrimMediaParams(SceneObjectPart part, int face, LSL_List rules)
  7735. {
  7736. // LSL Spec http://wiki.secondlife.com/wiki/LlGetPrimMediaParams says to fail silently if face is invalid
  7737. // TODO: Need to correctly handle case where a face has no media (which gives back an empty list).
  7738. // Assuming silently fail means give back an empty list. Ideally, need to check this.
  7739. if (face < 0 || face > part.GetNumberOfSides() - 1)
  7740. return new LSL_List();
  7741. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  7742. if (null == module)
  7743. return new LSL_List();
  7744. MediaEntry me = module.GetMediaEntry(part, face);
  7745. // As per http://wiki.secondlife.com/wiki/LlGetPrimMediaParams
  7746. if (null == me)
  7747. return new LSL_List();
  7748. LSL_List res = new LSL_List();
  7749. for (int i = 0; i < rules.Length; i++)
  7750. {
  7751. int code = (int)rules.GetLSLIntegerItem(i);
  7752. switch (code)
  7753. {
  7754. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  7755. // Not implemented
  7756. res.Add(new LSL_Integer(0));
  7757. break;
  7758. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  7759. if (me.Controls == MediaControls.Standard)
  7760. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD));
  7761. else
  7762. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_MINI));
  7763. break;
  7764. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  7765. res.Add(new LSL_String(me.CurrentURL));
  7766. break;
  7767. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  7768. res.Add(new LSL_String(me.HomeURL));
  7769. break;
  7770. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  7771. res.Add(me.AutoLoop ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  7772. break;
  7773. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  7774. res.Add(me.AutoPlay ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  7775. break;
  7776. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  7777. res.Add(me.AutoScale ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  7778. break;
  7779. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  7780. res.Add(me.AutoZoom ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  7781. break;
  7782. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  7783. res.Add(me.InteractOnFirstClick ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  7784. break;
  7785. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  7786. res.Add(new LSL_Integer(me.Width));
  7787. break;
  7788. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  7789. res.Add(new LSL_Integer(me.Height));
  7790. break;
  7791. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  7792. res.Add(me.EnableWhiteList ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  7793. break;
  7794. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  7795. string[] urls = (string[])me.WhiteList.Clone();
  7796. for (int j = 0; j < urls.Length; j++)
  7797. urls[j] = Uri.EscapeDataString(urls[j]);
  7798. res.Add(new LSL_String(string.Join(", ", urls)));
  7799. break;
  7800. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  7801. res.Add(new LSL_Integer((int)me.InteractPermissions));
  7802. break;
  7803. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  7804. res.Add(new LSL_Integer((int)me.ControlPermissions));
  7805. break;
  7806. default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
  7807. }
  7808. }
  7809. return res;
  7810. }
  7811. public LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules)
  7812. {
  7813. m_host.AddScriptLPS(1);
  7814. ScriptSleep(1000);
  7815. return SetPrimMediaParams(m_host, face, rules);
  7816. }
  7817. public LSL_Integer llSetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules)
  7818. {
  7819. m_host.AddScriptLPS(1);
  7820. ScriptSleep(1000);
  7821. if (link == ScriptBaseClass.LINK_ROOT)
  7822. return SetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules);
  7823. else if (link == ScriptBaseClass.LINK_THIS)
  7824. return SetPrimMediaParams(m_host, face, rules);
  7825. else
  7826. {
  7827. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  7828. if (null != part)
  7829. return SetPrimMediaParams(part, face, rules);
  7830. }
  7831. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  7832. }
  7833. private LSL_Integer SetPrimMediaParams(SceneObjectPart part, LSL_Integer face, LSL_List rules)
  7834. {
  7835. // LSL Spec http://wiki.secondlife.com/wiki/LlSetPrimMediaParams says to fail silently if face is invalid
  7836. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  7837. // Don't perform the media check directly
  7838. if (face < 0 || face > part.GetNumberOfSides() - 1)
  7839. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  7840. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  7841. if (null == module)
  7842. return ScriptBaseClass.LSL_STATUS_NOT_SUPPORTED;
  7843. MediaEntry me = module.GetMediaEntry(part, face);
  7844. if (null == me)
  7845. me = new MediaEntry();
  7846. int i = 0;
  7847. while (i < rules.Length - 1)
  7848. {
  7849. int code = rules.GetLSLIntegerItem(i++);
  7850. switch (code)
  7851. {
  7852. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  7853. me.EnableAlterntiveImage = (rules.GetLSLIntegerItem(i++) != 0 ? true : false);
  7854. break;
  7855. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  7856. int v = rules.GetLSLIntegerItem(i++);
  7857. if (ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD == v)
  7858. me.Controls = MediaControls.Standard;
  7859. else
  7860. me.Controls = MediaControls.Mini;
  7861. break;
  7862. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  7863. me.CurrentURL = rules.GetLSLStringItem(i++);
  7864. break;
  7865. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  7866. me.HomeURL = rules.GetLSLStringItem(i++);
  7867. break;
  7868. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  7869. me.AutoLoop = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  7870. break;
  7871. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  7872. me.AutoPlay = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  7873. break;
  7874. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  7875. me.AutoScale = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  7876. break;
  7877. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  7878. me.AutoZoom = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  7879. break;
  7880. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  7881. me.InteractOnFirstClick = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  7882. break;
  7883. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  7884. me.Width = (int)rules.GetLSLIntegerItem(i++);
  7885. break;
  7886. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  7887. me.Height = (int)rules.GetLSLIntegerItem(i++);
  7888. break;
  7889. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  7890. me.EnableWhiteList = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  7891. break;
  7892. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  7893. string[] rawWhiteListUrls = rules.GetLSLStringItem(i++).ToString().Split(new char[] { ',' });
  7894. List<string> whiteListUrls = new List<string>();
  7895. Array.ForEach(
  7896. rawWhiteListUrls, delegate(string rawUrl) { whiteListUrls.Add(rawUrl.Trim()); });
  7897. me.WhiteList = whiteListUrls.ToArray();
  7898. break;
  7899. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  7900. me.InteractPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  7901. break;
  7902. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  7903. me.ControlPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  7904. break;
  7905. default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
  7906. }
  7907. }
  7908. module.SetMediaEntry(part, face, me);
  7909. return ScriptBaseClass.LSL_STATUS_OK;
  7910. }
  7911. public LSL_Integer llClearPrimMedia(LSL_Integer face)
  7912. {
  7913. m_host.AddScriptLPS(1);
  7914. ScriptSleep(1000);
  7915. return ClearPrimMedia(m_host, face);
  7916. }
  7917. public LSL_Integer llClearLinkMedia(LSL_Integer link, LSL_Integer face)
  7918. {
  7919. m_host.AddScriptLPS(1);
  7920. ScriptSleep(1000);
  7921. if (link == ScriptBaseClass.LINK_ROOT)
  7922. return ClearPrimMedia(m_host.ParentGroup.RootPart, face);
  7923. else if (link == ScriptBaseClass.LINK_THIS)
  7924. return ClearPrimMedia(m_host, face);
  7925. else
  7926. {
  7927. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  7928. if (null != part)
  7929. return ClearPrimMedia(part, face);
  7930. }
  7931. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  7932. }
  7933. private LSL_Integer ClearPrimMedia(SceneObjectPart part, LSL_Integer face)
  7934. {
  7935. // LSL Spec http://wiki.secondlife.com/wiki/LlClearPrimMedia says to fail silently if face is invalid
  7936. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  7937. // FIXME: Don't perform the media check directly
  7938. if (face < 0 || face > part.GetNumberOfSides() - 1)
  7939. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  7940. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  7941. if (null == module)
  7942. return ScriptBaseClass.LSL_STATUS_NOT_SUPPORTED;
  7943. module.ClearMediaEntry(part, face);
  7944. return ScriptBaseClass.LSL_STATUS_OK;
  7945. }
  7946. // <remarks>
  7947. // <para>
  7948. // The .NET definition of base 64 is:
  7949. // <list>
  7950. // <item>
  7951. // Significant: A-Z a-z 0-9 + -
  7952. // </item>
  7953. // <item>
  7954. // Whitespace: \t \n \r ' '
  7955. // </item>
  7956. // <item>
  7957. // Valueless: =
  7958. // </item>
  7959. // <item>
  7960. // End-of-string: \0 or '=='
  7961. // </item>
  7962. // </list>
  7963. // </para>
  7964. // <para>
  7965. // Each point in a base-64 string represents
  7966. // a 6 bit value. A 32-bit integer can be
  7967. // represented using 6 characters (with some
  7968. // redundancy).
  7969. // </para>
  7970. // <para>
  7971. // LSL requires a base64 string to be 8
  7972. // characters in length. LSL also uses '/'
  7973. // rather than '-' (MIME compliant).
  7974. // </para>
  7975. // <para>
  7976. // RFC 1341 used as a reference (as specified
  7977. // by the SecondLife Wiki).
  7978. // </para>
  7979. // <para>
  7980. // SL do not record any kind of exception for
  7981. // these functions, so the string to integer
  7982. // conversion returns '0' if an invalid
  7983. // character is encountered during conversion.
  7984. // </para>
  7985. // <para>
  7986. // References
  7987. // <list>
  7988. // <item>
  7989. // http://lslwiki.net/lslwiki/wakka.php?wakka=Base64
  7990. // </item>
  7991. // <item>
  7992. // </item>
  7993. // </list>
  7994. // </para>
  7995. // </remarks>
  7996. // <summary>
  7997. // Table for converting 6-bit integers into
  7998. // base-64 characters
  7999. // </summary>
  8000. protected static readonly char[] i2ctable =
  8001. {
  8002. 'A','B','C','D','E','F','G','H',
  8003. 'I','J','K','L','M','N','O','P',
  8004. 'Q','R','S','T','U','V','W','X',
  8005. 'Y','Z',
  8006. 'a','b','c','d','e','f','g','h',
  8007. 'i','j','k','l','m','n','o','p',
  8008. 'q','r','s','t','u','v','w','x',
  8009. 'y','z',
  8010. '0','1','2','3','4','5','6','7',
  8011. '8','9',
  8012. '+','/'
  8013. };
  8014. // <summary>
  8015. // Table for converting base-64 characters
  8016. // into 6-bit integers.
  8017. // </summary>
  8018. protected static readonly int[] c2itable =
  8019. {
  8020. -1,-1,-1,-1,-1,-1,-1,-1, // 0x
  8021. -1,-1,-1,-1,-1,-1,-1,-1,
  8022. -1,-1,-1,-1,-1,-1,-1,-1, // 1x
  8023. -1,-1,-1,-1,-1,-1,-1,-1,
  8024. -1,-1,-1,-1,-1,-1,-1,-1, // 2x
  8025. -1,-1,-1,63,-1,-1,-1,64,
  8026. 53,54,55,56,57,58,59,60, // 3x
  8027. 61,62,-1,-1,-1,0,-1,-1,
  8028. -1,1,2,3,4,5,6,7, // 4x
  8029. 8,9,10,11,12,13,14,15,
  8030. 16,17,18,19,20,21,22,23, // 5x
  8031. 24,25,26,-1,-1,-1,-1,-1,
  8032. -1,27,28,29,30,31,32,33, // 6x
  8033. 34,35,36,37,38,39,40,41,
  8034. 42,43,44,45,46,47,48,49, // 7x
  8035. 50,51,52,-1,-1,-1,-1,-1,
  8036. -1,-1,-1,-1,-1,-1,-1,-1, // 8x
  8037. -1,-1,-1,-1,-1,-1,-1,-1,
  8038. -1,-1,-1,-1,-1,-1,-1,-1, // 9x
  8039. -1,-1,-1,-1,-1,-1,-1,-1,
  8040. -1,-1,-1,-1,-1,-1,-1,-1, // Ax
  8041. -1,-1,-1,-1,-1,-1,-1,-1,
  8042. -1,-1,-1,-1,-1,-1,-1,-1, // Bx
  8043. -1,-1,-1,-1,-1,-1,-1,-1,
  8044. -1,-1,-1,-1,-1,-1,-1,-1, // Cx
  8045. -1,-1,-1,-1,-1,-1,-1,-1,
  8046. -1,-1,-1,-1,-1,-1,-1,-1, // Dx
  8047. -1,-1,-1,-1,-1,-1,-1,-1,
  8048. -1,-1,-1,-1,-1,-1,-1,-1, // Ex
  8049. -1,-1,-1,-1,-1,-1,-1,-1,
  8050. -1,-1,-1,-1,-1,-1,-1,-1, // Fx
  8051. -1,-1,-1,-1,-1,-1,-1,-1
  8052. };
  8053. // <summary>
  8054. // Converts a 32-bit integer into a Base64
  8055. // character string. Base64 character strings
  8056. // are always 8 characters long. All iinteger
  8057. // values are acceptable.
  8058. // </summary>
  8059. // <param name="number">
  8060. // 32-bit integer to be converted.
  8061. // </param>
  8062. // <returns>
  8063. // 8 character string. The 1st six characters
  8064. // contain the encoded number, the last two
  8065. // characters are padded with "=".
  8066. // </returns>
  8067. public LSL_String llIntegerToBase64(int number)
  8068. {
  8069. // uninitialized string
  8070. char[] imdt = new char[8];
  8071. m_host.AddScriptLPS(1);
  8072. // Manually unroll the loop
  8073. imdt[7] = '=';
  8074. imdt[6] = '=';
  8075. imdt[5] = i2ctable[number<<4 & 0x3F];
  8076. imdt[4] = i2ctable[number>>2 & 0x3F];
  8077. imdt[3] = i2ctable[number>>8 & 0x3F];
  8078. imdt[2] = i2ctable[number>>14 & 0x3F];
  8079. imdt[1] = i2ctable[number>>20 & 0x3F];
  8080. imdt[0] = i2ctable[number>>26 & 0x3F];
  8081. return new string(imdt);
  8082. }
  8083. // <summary>
  8084. // Converts an eight character base-64 string
  8085. // into a 32-bit integer.
  8086. // </summary>
  8087. // <param name="str">
  8088. // 8 characters string to be converted. Other
  8089. // length strings return zero.
  8090. // </param>
  8091. // <returns>
  8092. // Returns an integer representing the
  8093. // encoded value providedint he 1st 6
  8094. // characters of the string.
  8095. // </returns>
  8096. // <remarks>
  8097. // This is coded to behave like LSL's
  8098. // implementation (I think), based upon the
  8099. // information available at the Wiki.
  8100. // If more than 8 characters are supplied,
  8101. // zero is returned.
  8102. // If a NULL string is supplied, zero will
  8103. // be returned.
  8104. // If fewer than 6 characters are supplied, then
  8105. // the answer will reflect a partial
  8106. // accumulation.
  8107. // <para>
  8108. // The 6-bit segments are
  8109. // extracted left-to-right in big-endian mode,
  8110. // which means that segment 6 only contains the
  8111. // two low-order bits of the 32 bit integer as
  8112. // its high order 2 bits. A short string therefore
  8113. // means loss of low-order information. E.g.
  8114. //
  8115. // |<---------------------- 32-bit integer ----------------------->|<-Pad->|
  8116. // |<--Byte 0----->|<--Byte 1----->|<--Byte 2----->|<--Byte 3----->|<-Pad->|
  8117. // |3|3|2|2|2|2|2|2|2|2|2|2|1|1|1|1|1|1|1|1|1|1| | | | | | | | | | |P|P|P|P|
  8118. // |1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0|P|P|P|P|
  8119. // | str[0] | str[1] | str[2] | str[3] | str[4] | str[6] |
  8120. //
  8121. // </para>
  8122. // </remarks>
  8123. public LSL_Integer llBase64ToInteger(string str)
  8124. {
  8125. int number = 0;
  8126. int digit;
  8127. m_host.AddScriptLPS(1);
  8128. // Require a well-fromed base64 string
  8129. if (str.Length > 8)
  8130. return 0;
  8131. // The loop is unrolled in the interests
  8132. // of performance and simple necessity.
  8133. //
  8134. // MUST find 6 digits to be well formed
  8135. // -1 == invalid
  8136. // 0 == padding
  8137. if ((digit = c2itable[str[0]]) <= 0)
  8138. {
  8139. return digit < 0 ? (int)0 : number;
  8140. }
  8141. number += --digit<<26;
  8142. if ((digit = c2itable[str[1]]) <= 0)
  8143. {
  8144. return digit < 0 ? (int)0 : number;
  8145. }
  8146. number += --digit<<20;
  8147. if ((digit = c2itable[str[2]]) <= 0)
  8148. {
  8149. return digit < 0 ? (int)0 : number;
  8150. }
  8151. number += --digit<<14;
  8152. if ((digit = c2itable[str[3]]) <= 0)
  8153. {
  8154. return digit < 0 ? (int)0 : number;
  8155. }
  8156. number += --digit<<8;
  8157. if ((digit = c2itable[str[4]]) <= 0)
  8158. {
  8159. return digit < 0 ? (int)0 : number;
  8160. }
  8161. number += --digit<<2;
  8162. if ((digit = c2itable[str[5]]) <= 0)
  8163. {
  8164. return digit < 0 ? (int)0 : number;
  8165. }
  8166. number += --digit>>4;
  8167. // ignore trailing padding
  8168. return number;
  8169. }
  8170. public LSL_Float llGetGMTclock()
  8171. {
  8172. m_host.AddScriptLPS(1);
  8173. return DateTime.UtcNow.TimeOfDay.TotalSeconds;
  8174. }
  8175. public LSL_String llGetHTTPHeader(LSL_Key request_id, string header)
  8176. {
  8177. m_host.AddScriptLPS(1);
  8178. if (m_UrlModule != null)
  8179. return m_UrlModule.GetHttpHeader(new UUID(request_id), header);
  8180. return String.Empty;
  8181. }
  8182. public LSL_String llGetSimulatorHostname()
  8183. {
  8184. m_host.AddScriptLPS(1);
  8185. IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
  8186. return UrlModule.ExternalHostNameForLSL;
  8187. }
  8188. // <summary>
  8189. // Scan the string supplied in 'src' and
  8190. // tokenize it based upon two sets of
  8191. // tokenizers provided in two lists,
  8192. // separators and spacers.
  8193. // </summary>
  8194. //
  8195. // <remarks>
  8196. // Separators demarcate tokens and are
  8197. // elided as they are encountered. Spacers
  8198. // also demarcate tokens, but are themselves
  8199. // retained as tokens.
  8200. //
  8201. // Both separators and spacers may be arbitrarily
  8202. // long strings. i.e. ":::".
  8203. //
  8204. // The function returns an ordered list
  8205. // representing the tokens found in the supplied
  8206. // sources string. If two successive tokenizers
  8207. // are encountered, then a NULL entry is added
  8208. // to the list.
  8209. //
  8210. // It is a precondition that the source and
  8211. // toekizer lisst are non-null. If they are null,
  8212. // then a null pointer exception will be thrown
  8213. // while their lengths are being determined.
  8214. //
  8215. // A small amount of working memoryis required
  8216. // of approximately 8*#tokenizers.
  8217. //
  8218. // There are many ways in which this function
  8219. // can be implemented, this implementation is
  8220. // fairly naive and assumes that when the
  8221. // function is invooked with a short source
  8222. // string and/or short lists of tokenizers, then
  8223. // performance will not be an issue.
  8224. //
  8225. // In order to minimize the perofrmance
  8226. // effects of long strings, or large numbers
  8227. // of tokeizers, the function skips as far as
  8228. // possible whenever a toekenizer is found,
  8229. // and eliminates redundant tokenizers as soon
  8230. // as is possible.
  8231. //
  8232. // The implementation tries to avoid any copying
  8233. // of arrays or other objects.
  8234. // </remarks>
  8235. private LSL_List ParseString(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
  8236. {
  8237. int beginning = 0;
  8238. int srclen = src.Length;
  8239. int seplen = separators.Length;
  8240. object[] separray = separators.Data;
  8241. int spclen = spacers.Length;
  8242. object[] spcarray = spacers.Data;
  8243. int mlen = seplen+spclen;
  8244. int[] offset = new int[mlen+1];
  8245. bool[] active = new bool[mlen];
  8246. int best;
  8247. int j;
  8248. // Initial capacity reduces resize cost
  8249. LSL_List tokens = new LSL_List();
  8250. // All entries are initially valid
  8251. for (int i = 0; i < mlen; i++)
  8252. active[i] = true;
  8253. offset[mlen] = srclen;
  8254. while (beginning < srclen)
  8255. {
  8256. best = mlen; // as bad as it gets
  8257. // Scan for separators
  8258. for (j = 0; j < seplen; j++)
  8259. {
  8260. if (separray[j].ToString() == String.Empty)
  8261. active[j] = false;
  8262. if (active[j])
  8263. {
  8264. // scan all of the markers
  8265. if ((offset[j] = src.IndexOf(separray[j].ToString(), beginning)) == -1)
  8266. {
  8267. // not present at all
  8268. active[j] = false;
  8269. }
  8270. else
  8271. {
  8272. // present and correct
  8273. if (offset[j] < offset[best])
  8274. {
  8275. // closest so far
  8276. best = j;
  8277. if (offset[best] == beginning)
  8278. break;
  8279. }
  8280. }
  8281. }
  8282. }
  8283. // Scan for spacers
  8284. if (offset[best] != beginning)
  8285. {
  8286. for (j = seplen; (j < mlen) && (offset[best] > beginning); j++)
  8287. {
  8288. if (spcarray[j-seplen].ToString() == String.Empty)
  8289. active[j] = false;
  8290. if (active[j])
  8291. {
  8292. // scan all of the markers
  8293. if ((offset[j] = src.IndexOf(spcarray[j-seplen].ToString(), beginning)) == -1)
  8294. {
  8295. // not present at all
  8296. active[j] = false;
  8297. }
  8298. else
  8299. {
  8300. // present and correct
  8301. if (offset[j] < offset[best])
  8302. {
  8303. // closest so far
  8304. best = j;
  8305. }
  8306. }
  8307. }
  8308. }
  8309. }
  8310. // This is the normal exit from the scanning loop
  8311. if (best == mlen)
  8312. {
  8313. // no markers were found on this pass
  8314. // so we're pretty much done
  8315. if ((keepNulls) || ((!keepNulls) && (srclen - beginning) > 0))
  8316. tokens.Add(new LSL_String(src.Substring(beginning, srclen - beginning)));
  8317. break;
  8318. }
  8319. // Otherwise we just add the newly delimited token
  8320. // and recalculate where the search should continue.
  8321. if ((keepNulls) || ((!keepNulls) && (offset[best] - beginning) > 0))
  8322. tokens.Add(new LSL_String(src.Substring(beginning,offset[best]-beginning)));
  8323. if (best < seplen)
  8324. {
  8325. beginning = offset[best] + (separray[best].ToString()).Length;
  8326. }
  8327. else
  8328. {
  8329. beginning = offset[best] + (spcarray[best - seplen].ToString()).Length;
  8330. string str = spcarray[best - seplen].ToString();
  8331. if ((keepNulls) || ((!keepNulls) && (str.Length > 0)))
  8332. tokens.Add(new LSL_String(str));
  8333. }
  8334. }
  8335. // This an awkward an not very intuitive boundary case. If the
  8336. // last substring is a tokenizer, then there is an implied trailing
  8337. // null list entry. Hopefully the single comparison will not be too
  8338. // arduous. Alternatively the 'break' could be replced with a return
  8339. // but that's shabby programming.
  8340. if ((beginning == srclen) && (keepNulls))
  8341. {
  8342. if (srclen != 0)
  8343. tokens.Add(new LSL_String(""));
  8344. }
  8345. return tokens;
  8346. }
  8347. public LSL_List llParseString2List(string src, LSL_List separators, LSL_List spacers)
  8348. {
  8349. m_host.AddScriptLPS(1);
  8350. return this.ParseString(src, separators, spacers, false);
  8351. }
  8352. public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
  8353. {
  8354. m_host.AddScriptLPS(1);
  8355. return this.ParseString(src, separators, spacers, true);
  8356. }
  8357. public LSL_Integer llGetObjectPermMask(int mask)
  8358. {
  8359. m_host.AddScriptLPS(1);
  8360. int permmask = 0;
  8361. if (mask == ScriptBaseClass.MASK_BASE)//0
  8362. {
  8363. permmask = (int)m_host.BaseMask;
  8364. }
  8365. else if (mask == ScriptBaseClass.MASK_OWNER)//1
  8366. {
  8367. permmask = (int)m_host.OwnerMask;
  8368. }
  8369. else if (mask == ScriptBaseClass.MASK_GROUP)//2
  8370. {
  8371. permmask = (int)m_host.GroupMask;
  8372. }
  8373. else if (mask == ScriptBaseClass.MASK_EVERYONE)//3
  8374. {
  8375. permmask = (int)m_host.EveryoneMask;
  8376. }
  8377. else if (mask == ScriptBaseClass.MASK_NEXT)//4
  8378. {
  8379. permmask = (int)m_host.NextOwnerMask;
  8380. }
  8381. return permmask;
  8382. }
  8383. public void llSetObjectPermMask(int mask, int value)
  8384. {
  8385. m_host.AddScriptLPS(1);
  8386. if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false))
  8387. {
  8388. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  8389. {
  8390. if (mask == ScriptBaseClass.MASK_BASE)//0
  8391. {
  8392. m_host.BaseMask = (uint)value;
  8393. }
  8394. else if (mask == ScriptBaseClass.MASK_OWNER)//1
  8395. {
  8396. m_host.OwnerMask = (uint)value;
  8397. }
  8398. else if (mask == ScriptBaseClass.MASK_GROUP)//2
  8399. {
  8400. m_host.GroupMask = (uint)value;
  8401. }
  8402. else if (mask == ScriptBaseClass.MASK_EVERYONE)//3
  8403. {
  8404. m_host.EveryoneMask = (uint)value;
  8405. }
  8406. else if (mask == ScriptBaseClass.MASK_NEXT)//4
  8407. {
  8408. m_host.NextOwnerMask = (uint)value;
  8409. }
  8410. }
  8411. }
  8412. }
  8413. public LSL_Integer llGetInventoryPermMask(string itemName, int mask)
  8414. {
  8415. m_host.AddScriptLPS(1);
  8416. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  8417. if (item == null)
  8418. return -1;
  8419. switch (mask)
  8420. {
  8421. case 0:
  8422. return (int)item.BasePermissions;
  8423. case 1:
  8424. return (int)item.CurrentPermissions;
  8425. case 2:
  8426. return (int)item.GroupPermissions;
  8427. case 3:
  8428. return (int)item.EveryonePermissions;
  8429. case 4:
  8430. return (int)item.NextPermissions;
  8431. }
  8432. return -1;
  8433. }
  8434. public void llSetInventoryPermMask(string itemName, int mask, int value)
  8435. {
  8436. m_host.AddScriptLPS(1);
  8437. if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false))
  8438. {
  8439. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  8440. {
  8441. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  8442. if (item != null)
  8443. {
  8444. switch (mask)
  8445. {
  8446. case 0:
  8447. item.BasePermissions = (uint)value;
  8448. break;
  8449. case 1:
  8450. item.CurrentPermissions = (uint)value;
  8451. break;
  8452. case 2:
  8453. item.GroupPermissions = (uint)value;
  8454. break;
  8455. case 3:
  8456. item.EveryonePermissions = (uint)value;
  8457. break;
  8458. case 4:
  8459. item.NextPermissions = (uint)value;
  8460. break;
  8461. }
  8462. }
  8463. }
  8464. }
  8465. }
  8466. public LSL_String llGetInventoryCreator(string itemName)
  8467. {
  8468. m_host.AddScriptLPS(1);
  8469. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  8470. if (item == null)
  8471. {
  8472. Error("llGetInventoryCreator", "Can't find item '" + item + "'");
  8473. return String.Empty;
  8474. }
  8475. return item.CreatorID.ToString();
  8476. }
  8477. public void llOwnerSay(string msg)
  8478. {
  8479. m_host.AddScriptLPS(1);
  8480. World.SimChatBroadcast(Utils.StringToBytes(msg), ChatTypeEnum.Owner, 0,
  8481. m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  8482. // IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  8483. // wComm.DeliverMessage(ChatTypeEnum.Owner, 0, m_host.Name, m_host.UUID, msg);
  8484. }
  8485. public LSL_String llRequestSecureURL()
  8486. {
  8487. m_host.AddScriptLPS(1);
  8488. if (m_UrlModule != null)
  8489. return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
  8490. return UUID.Zero.ToString();
  8491. }
  8492. public LSL_String llRequestSimulatorData(string simulator, int data)
  8493. {
  8494. IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
  8495. try
  8496. {
  8497. m_host.AddScriptLPS(1);
  8498. string reply = String.Empty;
  8499. GridRegion info;
  8500. if (World.RegionInfo.RegionName == simulator)
  8501. info = new GridRegion(World.RegionInfo);
  8502. else
  8503. info = World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator);
  8504. switch (data)
  8505. {
  8506. case ScriptBaseClass.DATA_SIM_POS:
  8507. if (info == null)
  8508. {
  8509. ScriptSleep(1000);
  8510. return UUID.Zero.ToString();
  8511. }
  8512. bool isHypergridRegion = false;
  8513. if (World.RegionInfo.RegionName != simulator && info.RegionSecret != "")
  8514. {
  8515. // Hypergrid is currently placing real destination region co-ords into RegionSecret.
  8516. // But other code can also use this field for a genuine RegionSecret! Therefore, if
  8517. // anything is present we need to disambiguate.
  8518. //
  8519. // FIXME: Hypergrid should be storing this data in a different field.
  8520. RegionFlags regionFlags
  8521. = (RegionFlags)m_ScriptEngine.World.GridService.GetRegionFlags(
  8522. info.ScopeID, info.RegionID);
  8523. isHypergridRegion = (regionFlags & RegionFlags.Hyperlink) != 0;
  8524. }
  8525. if (isHypergridRegion)
  8526. {
  8527. uint rx = 0, ry = 0;
  8528. Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out rx, out ry);
  8529. reply = new LSL_Vector(
  8530. rx,
  8531. ry,
  8532. 0).ToString();
  8533. }
  8534. else
  8535. {
  8536. // Local grid co-oridnates
  8537. reply = new LSL_Vector(
  8538. info.RegionLocX,
  8539. info.RegionLocY,
  8540. 0).ToString();
  8541. }
  8542. break;
  8543. case ScriptBaseClass.DATA_SIM_STATUS:
  8544. if (info != null)
  8545. reply = "up"; // Duh!
  8546. else
  8547. reply = "unknown";
  8548. break;
  8549. case ScriptBaseClass.DATA_SIM_RATING:
  8550. if (info == null)
  8551. {
  8552. ScriptSleep(1000);
  8553. return UUID.Zero.ToString();
  8554. }
  8555. int access = info.Maturity;
  8556. if (access == 0)
  8557. reply = "PG";
  8558. else if (access == 1)
  8559. reply = "MATURE";
  8560. else if (access == 2)
  8561. reply = "ADULT";
  8562. else
  8563. reply = "UNKNOWN";
  8564. break;
  8565. case ScriptBaseClass.DATA_SIM_RELEASE:
  8566. if (ossl != null)
  8567. ossl.CheckThreatLevel(ThreatLevel.High, "llRequestSimulatorData");
  8568. reply = "OpenSim";
  8569. break;
  8570. default:
  8571. ScriptSleep(1000);
  8572. return UUID.Zero.ToString(); // Raise no event
  8573. }
  8574. UUID rq = UUID.Random();
  8575. UUID tid = AsyncCommands.
  8576. DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
  8577. AsyncCommands.
  8578. DataserverPlugin.DataserverReply(rq.ToString(), reply);
  8579. ScriptSleep(1000);
  8580. return tid.ToString();
  8581. }
  8582. catch(Exception)
  8583. {
  8584. //m_log.Error("[LSL_API]: llRequestSimulatorData" + e.ToString());
  8585. return UUID.Zero.ToString();
  8586. }
  8587. }
  8588. public LSL_String llRequestURL()
  8589. {
  8590. m_host.AddScriptLPS(1);
  8591. if (m_UrlModule != null)
  8592. return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
  8593. return UUID.Zero.ToString();
  8594. }
  8595. public void llForceMouselook(int mouselook)
  8596. {
  8597. m_host.AddScriptLPS(1);
  8598. m_host.SetForceMouselook(mouselook != 0);
  8599. }
  8600. public LSL_Float llGetObjectMass(string id)
  8601. {
  8602. m_host.AddScriptLPS(1);
  8603. UUID key = new UUID();
  8604. if (UUID.TryParse(id, out key))
  8605. {
  8606. try
  8607. {
  8608. SceneObjectPart obj = World.GetSceneObjectPart(World.Entities[key].LocalId);
  8609. if (obj != null)
  8610. return (double)obj.GetMass();
  8611. // the object is null so the key is for an avatar
  8612. ScenePresence avatar = World.GetScenePresence(key);
  8613. if (avatar != null)
  8614. if (avatar.IsChildAgent)
  8615. // reference http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetObjectMass
  8616. // child agents have a mass of 1.0
  8617. return 1;
  8618. else
  8619. return (double)avatar.GetMass();
  8620. }
  8621. catch (KeyNotFoundException)
  8622. {
  8623. return 0; // The Object/Agent not in the region so just return zero
  8624. }
  8625. }
  8626. return 0;
  8627. }
  8628. /// <summary>
  8629. /// illListReplaceList removes the sub-list defined by the inclusive indices
  8630. /// start and end and inserts the src list in its place. The inclusive
  8631. /// nature of the indices means that at least one element must be deleted
  8632. /// if the indices are within the bounds of the existing list. I.e. 2,2
  8633. /// will remove the element at index 2 and replace it with the source
  8634. /// list. Both indices may be negative, with the usual interpretation. An
  8635. /// interesting case is where end is lower than start. As these indices
  8636. /// bound the list to be removed, then 0->end, and start->lim are removed
  8637. /// and the source list is added as a suffix.
  8638. /// </summary>
  8639. public LSL_List llListReplaceList(LSL_List dest, LSL_List src, int start, int end)
  8640. {
  8641. LSL_List pref = null;
  8642. m_host.AddScriptLPS(1);
  8643. // Note that although we have normalized, both
  8644. // indices could still be negative.
  8645. if (start < 0)
  8646. {
  8647. start = start+dest.Length;
  8648. }
  8649. if (end < 0)
  8650. {
  8651. end = end+dest.Length;
  8652. }
  8653. // The comventional case, remove a sequence starting with
  8654. // start and ending with end. And then insert the source
  8655. // list.
  8656. if (start <= end)
  8657. {
  8658. // If greater than zero, then there is going to be a
  8659. // surviving prefix. Otherwise the inclusive nature
  8660. // of the indices mean that we're going to add the
  8661. // source list as a prefix.
  8662. if (start > 0)
  8663. {
  8664. pref = dest.GetSublist(0,start-1);
  8665. // Only add a suffix if there is something
  8666. // beyond the end index (it's inclusive too).
  8667. if (end + 1 < dest.Length)
  8668. {
  8669. return pref + src + dest.GetSublist(end + 1, -1);
  8670. }
  8671. else
  8672. {
  8673. return pref + src;
  8674. }
  8675. }
  8676. // If start is less than or equal to zero, then
  8677. // the new list is simply a prefix. We still need to
  8678. // figure out any necessary surgery to the destination
  8679. // based upon end. Note that if end exceeds the upper
  8680. // bound in this case, the entire destination list
  8681. // is removed.
  8682. else
  8683. {
  8684. if (end + 1 < dest.Length)
  8685. {
  8686. return src + dest.GetSublist(end + 1, -1);
  8687. }
  8688. else
  8689. {
  8690. return src;
  8691. }
  8692. }
  8693. }
  8694. // Finally, if start > end, we strip away a prefix and
  8695. // a suffix, to leave the list that sits <between> ens
  8696. // and start, and then tag on the src list. AT least
  8697. // that's my interpretation. We can get sublist to do
  8698. // this for us. Note that one, or both of the indices
  8699. // might have been negative.
  8700. else
  8701. {
  8702. return dest.GetSublist(end + 1, start - 1) + src;
  8703. }
  8704. }
  8705. public void llLoadURL(string avatar_id, string message, string url)
  8706. {
  8707. m_host.AddScriptLPS(1);
  8708. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  8709. if (null != dm)
  8710. dm.SendUrlToUser(
  8711. new UUID(avatar_id), m_host.Name, m_host.UUID, m_host.OwnerID, false, message, url);
  8712. ScriptSleep(10000);
  8713. }
  8714. public void llParcelMediaCommandList(LSL_List commandList)
  8715. {
  8716. // TODO: Not implemented yet (missing in libomv?):
  8717. // PARCEL_MEDIA_COMMAND_LOOP_SET float loop Use this to get or set the parcel's media loop duration. (1.19.1 RC0 or later)
  8718. m_host.AddScriptLPS(1);
  8719. // according to the docs, this command only works if script owner and land owner are the same
  8720. // lets add estate owners and gods, too, and use the generic permission check.
  8721. ILandObject landObject = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  8722. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia)) return;
  8723. bool update = false; // send a ParcelMediaUpdate (and possibly change the land's media URL)?
  8724. byte loop = 0;
  8725. LandData landData = landObject.LandData;
  8726. string url = landData.MediaURL;
  8727. string texture = landData.MediaID.ToString();
  8728. bool autoAlign = landData.MediaAutoScale != 0;
  8729. string mediaType = ""; // TODO these have to be added as soon as LandData supports it
  8730. string description = "";
  8731. int width = 0;
  8732. int height = 0;
  8733. ParcelMediaCommandEnum? commandToSend = null;
  8734. float time = 0.0f; // default is from start
  8735. ScenePresence presence = null;
  8736. for (int i = 0; i < commandList.Data.Length; i++)
  8737. {
  8738. ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)commandList.Data[i];
  8739. switch (command)
  8740. {
  8741. case ParcelMediaCommandEnum.Agent:
  8742. // we send only to one agent
  8743. if ((i + 1) < commandList.Length)
  8744. {
  8745. if (commandList.Data[i + 1] is LSL_String)
  8746. {
  8747. UUID agentID;
  8748. if (UUID.TryParse((LSL_String)commandList.Data[i + 1], out agentID))
  8749. {
  8750. presence = World.GetScenePresence(agentID);
  8751. }
  8752. }
  8753. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AGENT must be a key");
  8754. ++i;
  8755. }
  8756. break;
  8757. case ParcelMediaCommandEnum.Loop:
  8758. loop = 1;
  8759. commandToSend = command;
  8760. update = true; //need to send the media update packet to set looping
  8761. break;
  8762. case ParcelMediaCommandEnum.Play:
  8763. loop = 0;
  8764. commandToSend = command;
  8765. update = true; //need to send the media update packet to make sure it doesn't loop
  8766. break;
  8767. case ParcelMediaCommandEnum.Pause:
  8768. case ParcelMediaCommandEnum.Stop:
  8769. case ParcelMediaCommandEnum.Unload:
  8770. commandToSend = command;
  8771. break;
  8772. case ParcelMediaCommandEnum.Url:
  8773. if ((i + 1) < commandList.Length)
  8774. {
  8775. if (commandList.Data[i + 1] is LSL_String)
  8776. {
  8777. url = (LSL_String)commandList.Data[i + 1];
  8778. update = true;
  8779. }
  8780. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_URL must be a string");
  8781. ++i;
  8782. }
  8783. break;
  8784. case ParcelMediaCommandEnum.Texture:
  8785. if ((i + 1) < commandList.Length)
  8786. {
  8787. if (commandList.Data[i + 1] is LSL_String)
  8788. {
  8789. texture = (LSL_String)commandList.Data[i + 1];
  8790. update = true;
  8791. }
  8792. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TEXTURE must be a string or a key");
  8793. ++i;
  8794. }
  8795. break;
  8796. case ParcelMediaCommandEnum.Time:
  8797. if ((i + 1) < commandList.Length)
  8798. {
  8799. if (commandList.Data[i + 1] is LSL_Float)
  8800. {
  8801. time = (float)(LSL_Float)commandList.Data[i + 1];
  8802. }
  8803. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TIME must be a float");
  8804. ++i;
  8805. }
  8806. break;
  8807. case ParcelMediaCommandEnum.AutoAlign:
  8808. if ((i + 1) < commandList.Length)
  8809. {
  8810. if (commandList.Data[i + 1] is LSL_Integer)
  8811. {
  8812. autoAlign = (LSL_Integer)commandList.Data[i + 1];
  8813. update = true;
  8814. }
  8815. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AUTO_ALIGN must be an integer");
  8816. ++i;
  8817. }
  8818. break;
  8819. case ParcelMediaCommandEnum.Type:
  8820. if ((i + 1) < commandList.Length)
  8821. {
  8822. if (commandList.Data[i + 1] is LSL_String)
  8823. {
  8824. mediaType = (LSL_String)commandList.Data[i + 1];
  8825. update = true;
  8826. }
  8827. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TYPE must be a string");
  8828. ++i;
  8829. }
  8830. break;
  8831. case ParcelMediaCommandEnum.Desc:
  8832. if ((i + 1) < commandList.Length)
  8833. {
  8834. if (commandList.Data[i + 1] is LSL_String)
  8835. {
  8836. description = (LSL_String)commandList.Data[i + 1];
  8837. update = true;
  8838. }
  8839. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_DESC must be a string");
  8840. ++i;
  8841. }
  8842. break;
  8843. case ParcelMediaCommandEnum.Size:
  8844. if ((i + 2) < commandList.Length)
  8845. {
  8846. if (commandList.Data[i + 1] is LSL_Integer)
  8847. {
  8848. if (commandList.Data[i + 2] is LSL_Integer)
  8849. {
  8850. width = (LSL_Integer)commandList.Data[i + 1];
  8851. height = (LSL_Integer)commandList.Data[i + 2];
  8852. update = true;
  8853. }
  8854. else Error("llParcelMediaCommandList", "The second argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer");
  8855. }
  8856. else Error("llParcelMediaCommandList", "The first argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer");
  8857. i += 2;
  8858. }
  8859. break;
  8860. default:
  8861. NotImplemented("llParcelMediaCommandList", "Parameter not supported yet: " + Enum.Parse(typeof(ParcelMediaCommandEnum), commandList.Data[i].ToString()).ToString());
  8862. break;
  8863. }//end switch
  8864. }//end for
  8865. // if we didn't get a presence, we send to all and change the url
  8866. // if we did get a presence, we only send to the agent specified, and *don't change the land settings*!
  8867. // did something important change or do we only start/stop/pause?
  8868. if (update)
  8869. {
  8870. if (presence == null)
  8871. {
  8872. // we send to all
  8873. landData.MediaID = new UUID(texture);
  8874. landData.MediaAutoScale = autoAlign ? (byte)1 : (byte)0;
  8875. landData.MediaWidth = width;
  8876. landData.MediaHeight = height;
  8877. landData.MediaType = mediaType;
  8878. // do that one last, it will cause a ParcelPropertiesUpdate
  8879. landObject.SetMediaUrl(url);
  8880. // now send to all (non-child) agents in the parcel
  8881. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  8882. {
  8883. if (sp.currentParcelUUID == landData.GlobalID)
  8884. {
  8885. sp.ControllingClient.SendParcelMediaUpdate(landData.MediaURL,
  8886. landData.MediaID,
  8887. landData.MediaAutoScale,
  8888. mediaType,
  8889. description,
  8890. width, height,
  8891. loop);
  8892. }
  8893. });
  8894. }
  8895. else if (!presence.IsChildAgent)
  8896. {
  8897. // we only send to one (root) agent
  8898. presence.ControllingClient.SendParcelMediaUpdate(url,
  8899. new UUID(texture),
  8900. autoAlign ? (byte)1 : (byte)0,
  8901. mediaType,
  8902. description,
  8903. width, height,
  8904. loop);
  8905. }
  8906. }
  8907. if (commandToSend != null)
  8908. {
  8909. // the commandList contained a start/stop/... command, too
  8910. if (presence == null)
  8911. {
  8912. // send to all (non-child) agents in the parcel
  8913. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  8914. {
  8915. if (sp.currentParcelUUID == landData.GlobalID)
  8916. {
  8917. sp.ControllingClient.SendParcelMediaCommand(0x4, // TODO what is this?
  8918. (ParcelMediaCommandEnum)commandToSend,
  8919. time);
  8920. }
  8921. });
  8922. }
  8923. else if (!presence.IsChildAgent)
  8924. {
  8925. presence.ControllingClient.SendParcelMediaCommand(0x4, // TODO what is this?
  8926. (ParcelMediaCommandEnum)commandToSend,
  8927. time);
  8928. }
  8929. }
  8930. ScriptSleep(2000);
  8931. }
  8932. public LSL_List llParcelMediaQuery(LSL_List aList)
  8933. {
  8934. m_host.AddScriptLPS(1);
  8935. LSL_List list = new LSL_List();
  8936. //TO DO: make the implementation for the missing commands
  8937. //PARCEL_MEDIA_COMMAND_LOOP_SET float loop Use this to get or set the parcel's media loop duration. (1.19.1 RC0 or later)
  8938. for (int i = 0; i < aList.Data.Length; i++)
  8939. {
  8940. if (aList.Data[i] != null)
  8941. {
  8942. switch ((ParcelMediaCommandEnum) aList.Data[i])
  8943. {
  8944. case ParcelMediaCommandEnum.Url:
  8945. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaURL));
  8946. break;
  8947. case ParcelMediaCommandEnum.Desc:
  8948. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).Description));
  8949. break;
  8950. case ParcelMediaCommandEnum.Texture:
  8951. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaID.ToString()));
  8952. break;
  8953. case ParcelMediaCommandEnum.Type:
  8954. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaType));
  8955. break;
  8956. case ParcelMediaCommandEnum.Size:
  8957. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaWidth));
  8958. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaHeight));
  8959. break;
  8960. default:
  8961. ParcelMediaCommandEnum mediaCommandEnum = ParcelMediaCommandEnum.Url;
  8962. NotImplemented("llParcelMediaQuery", "Parameter not supported yet: " + Enum.Parse(mediaCommandEnum.GetType() , aList.Data[i].ToString()).ToString());
  8963. break;
  8964. }
  8965. }
  8966. }
  8967. ScriptSleep(2000);
  8968. return list;
  8969. }
  8970. public LSL_Integer llModPow(int a, int b, int c)
  8971. {
  8972. m_host.AddScriptLPS(1);
  8973. Int64 tmp = 0;
  8974. Math.DivRem(Convert.ToInt64(Math.Pow(a, b)), c, out tmp);
  8975. ScriptSleep(1000);
  8976. return Convert.ToInt32(tmp);
  8977. }
  8978. public LSL_Integer llGetInventoryType(string name)
  8979. {
  8980. m_host.AddScriptLPS(1);
  8981. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  8982. if (item == null)
  8983. return -1;
  8984. return item.Type;
  8985. }
  8986. public void llSetPayPrice(int price, LSL_List quick_pay_buttons)
  8987. {
  8988. m_host.AddScriptLPS(1);
  8989. if (quick_pay_buttons.Data.Length < 4)
  8990. {
  8991. Error("llSetPayPrice", "List must have at least 4 elements");
  8992. return;
  8993. }
  8994. m_host.ParentGroup.RootPart.PayPrice[0]=price;
  8995. m_host.ParentGroup.RootPart.PayPrice[1]=(LSL_Integer)quick_pay_buttons.Data[0];
  8996. m_host.ParentGroup.RootPart.PayPrice[2]=(LSL_Integer)quick_pay_buttons.Data[1];
  8997. m_host.ParentGroup.RootPart.PayPrice[3]=(LSL_Integer)quick_pay_buttons.Data[2];
  8998. m_host.ParentGroup.RootPart.PayPrice[4]=(LSL_Integer)quick_pay_buttons.Data[3];
  8999. m_host.ParentGroup.HasGroupChanged = true;
  9000. }
  9001. public LSL_Vector llGetCameraPos()
  9002. {
  9003. m_host.AddScriptLPS(1);
  9004. if (m_item.PermsGranter == UUID.Zero)
  9005. return Vector3.Zero;
  9006. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  9007. {
  9008. Error("llGetCameraPos", "No permissions to track the camera");
  9009. return Vector3.Zero;
  9010. }
  9011. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  9012. if (presence != null)
  9013. {
  9014. LSL_Vector pos = new LSL_Vector(presence.CameraPosition);
  9015. return pos;
  9016. }
  9017. return Vector3.Zero;
  9018. }
  9019. public LSL_Rotation llGetCameraRot()
  9020. {
  9021. m_host.AddScriptLPS(1);
  9022. if (m_item.PermsGranter == UUID.Zero)
  9023. return Quaternion.Identity;
  9024. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  9025. {
  9026. Error("llGetCameraRot", "No permissions to track the camera");
  9027. return Quaternion.Identity;
  9028. }
  9029. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  9030. if (presence != null)
  9031. {
  9032. return new LSL_Rotation(presence.CameraRotation);
  9033. }
  9034. return Quaternion.Identity;
  9035. }
  9036. public void llSetPrimURL(string url)
  9037. {
  9038. m_host.AddScriptLPS(1);
  9039. Deprecated("llSetPrimURL", "Use llSetPrimMediaParams instead");
  9040. ScriptSleep(2000);
  9041. }
  9042. public void llRefreshPrimURL()
  9043. {
  9044. m_host.AddScriptLPS(1);
  9045. Deprecated("llRefreshPrimURL");
  9046. ScriptSleep(20000);
  9047. }
  9048. public LSL_String llEscapeURL(string url)
  9049. {
  9050. m_host.AddScriptLPS(1);
  9051. try
  9052. {
  9053. return Uri.EscapeDataString(url);
  9054. }
  9055. catch (Exception ex)
  9056. {
  9057. return "llEscapeURL: " + ex.ToString();
  9058. }
  9059. }
  9060. public LSL_String llUnescapeURL(string url)
  9061. {
  9062. m_host.AddScriptLPS(1);
  9063. try
  9064. {
  9065. return Uri.UnescapeDataString(url);
  9066. }
  9067. catch (Exception ex)
  9068. {
  9069. return "llUnescapeURL: " + ex.ToString();
  9070. }
  9071. }
  9072. public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt)
  9073. {
  9074. m_host.AddScriptLPS(1);
  9075. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
  9076. if (detectedParams == null) return; // only works on the first detected avatar
  9077. ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
  9078. if (avatar != null)
  9079. {
  9080. avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name,
  9081. simname, pos, lookAt);
  9082. }
  9083. ScriptSleep(1000);
  9084. }
  9085. public void llAddToLandBanList(string avatar, double hours)
  9086. {
  9087. m_host.AddScriptLPS(1);
  9088. UUID key;
  9089. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  9090. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned))
  9091. {
  9092. int expires = 0;
  9093. if (hours != 0)
  9094. expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours);
  9095. if (UUID.TryParse(avatar, out key))
  9096. {
  9097. int idx = land.LandData.ParcelAccessList.FindIndex(
  9098. delegate(LandAccessEntry e)
  9099. {
  9100. if (e.AgentID == key && e.Flags == AccessList.Ban)
  9101. return true;
  9102. return false;
  9103. });
  9104. if (idx != -1 && (land.LandData.ParcelAccessList[idx].Expires == 0 || (expires != 0 && expires < land.LandData.ParcelAccessList[idx].Expires)))
  9105. return;
  9106. if (idx != -1)
  9107. land.LandData.ParcelAccessList.RemoveAt(idx);
  9108. LandAccessEntry entry = new LandAccessEntry();
  9109. entry.AgentID = key;
  9110. entry.Flags = AccessList.Ban;
  9111. entry.Expires = expires;
  9112. land.LandData.ParcelAccessList.Add(entry);
  9113. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  9114. }
  9115. }
  9116. ScriptSleep(100);
  9117. }
  9118. public void llRemoveFromLandPassList(string avatar)
  9119. {
  9120. m_host.AddScriptLPS(1);
  9121. UUID key;
  9122. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  9123. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageAllowed))
  9124. {
  9125. if (UUID.TryParse(avatar, out key))
  9126. {
  9127. int idx = land.LandData.ParcelAccessList.FindIndex(
  9128. delegate(LandAccessEntry e)
  9129. {
  9130. if (e.AgentID == key && e.Flags == AccessList.Access)
  9131. return true;
  9132. return false;
  9133. });
  9134. if (idx != -1)
  9135. {
  9136. land.LandData.ParcelAccessList.RemoveAt(idx);
  9137. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  9138. }
  9139. }
  9140. }
  9141. ScriptSleep(100);
  9142. }
  9143. public void llRemoveFromLandBanList(string avatar)
  9144. {
  9145. m_host.AddScriptLPS(1);
  9146. UUID key;
  9147. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  9148. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned))
  9149. {
  9150. if (UUID.TryParse(avatar, out key))
  9151. {
  9152. int idx = land.LandData.ParcelAccessList.FindIndex(
  9153. delegate(LandAccessEntry e)
  9154. {
  9155. if (e.AgentID == key && e.Flags == AccessList.Ban)
  9156. return true;
  9157. return false;
  9158. });
  9159. if (idx != -1)
  9160. {
  9161. land.LandData.ParcelAccessList.RemoveAt(idx);
  9162. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  9163. }
  9164. }
  9165. }
  9166. ScriptSleep(100);
  9167. }
  9168. public void llSetCameraParams(LSL_List rules)
  9169. {
  9170. m_host.AddScriptLPS(1);
  9171. // the object we are in
  9172. UUID objectID = m_host.ParentUUID;
  9173. if (objectID == UUID.Zero)
  9174. return;
  9175. // we need the permission first, to know which avatar we want to set the camera for
  9176. UUID agentID = m_item.PermsGranter;
  9177. if (agentID == UUID.Zero)
  9178. return;
  9179. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  9180. return;
  9181. ScenePresence presence = World.GetScenePresence(agentID);
  9182. // we are not interested in child-agents
  9183. if (presence.IsChildAgent) return;
  9184. SortedDictionary<int, float> parameters = new SortedDictionary<int, float>();
  9185. object[] data = rules.Data;
  9186. for (int i = 0; i < data.Length; ++i) {
  9187. int type = Convert.ToInt32(data[i++].ToString());
  9188. if (i >= data.Length) break; // odd number of entries => ignore the last
  9189. // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
  9190. switch (type) {
  9191. case ScriptBaseClass.CAMERA_FOCUS:
  9192. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  9193. case ScriptBaseClass.CAMERA_POSITION:
  9194. LSL_Vector v = (LSL_Vector)data[i];
  9195. parameters.Add(type + 1, (float)v.x);
  9196. parameters.Add(type + 2, (float)v.y);
  9197. parameters.Add(type + 3, (float)v.z);
  9198. break;
  9199. default:
  9200. // TODO: clean that up as soon as the implicit casts are in
  9201. if (data[i] is LSL_Float)
  9202. parameters.Add(type, (float)((LSL_Float)data[i]).value);
  9203. else if (data[i] is LSL_Integer)
  9204. parameters.Add(type, (float)((LSL_Integer)data[i]).value);
  9205. else parameters.Add(type, Convert.ToSingle(data[i]));
  9206. break;
  9207. }
  9208. }
  9209. if (parameters.Count > 0) presence.ControllingClient.SendSetFollowCamProperties(objectID, parameters);
  9210. }
  9211. public void llClearCameraParams()
  9212. {
  9213. m_host.AddScriptLPS(1);
  9214. // the object we are in
  9215. UUID objectID = m_host.ParentUUID;
  9216. if (objectID == UUID.Zero)
  9217. return;
  9218. // we need the permission first, to know which avatar we want to clear the camera for
  9219. UUID agentID = m_item.PermsGranter;
  9220. if (agentID == UUID.Zero)
  9221. return;
  9222. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  9223. return;
  9224. ScenePresence presence = World.GetScenePresence(agentID);
  9225. // we are not interested in child-agents
  9226. if (presence.IsChildAgent)
  9227. return;
  9228. presence.ControllingClient.SendClearFollowCamProperties(objectID);
  9229. }
  9230. public LSL_Float llListStatistics(int operation, LSL_List src)
  9231. {
  9232. m_host.AddScriptLPS(1);
  9233. switch (operation)
  9234. {
  9235. case ScriptBaseClass.LIST_STAT_RANGE:
  9236. return src.Range();
  9237. case ScriptBaseClass.LIST_STAT_MIN:
  9238. return src.Min();
  9239. case ScriptBaseClass.LIST_STAT_MAX:
  9240. return src.Max();
  9241. case ScriptBaseClass.LIST_STAT_MEAN:
  9242. return src.Mean();
  9243. case ScriptBaseClass.LIST_STAT_MEDIAN:
  9244. return LSL_List.ToDoubleList(src).Median();
  9245. case ScriptBaseClass.LIST_STAT_NUM_COUNT:
  9246. return src.NumericLength();
  9247. case ScriptBaseClass.LIST_STAT_STD_DEV:
  9248. return src.StdDev();
  9249. case ScriptBaseClass.LIST_STAT_SUM:
  9250. return src.Sum();
  9251. case ScriptBaseClass.LIST_STAT_SUM_SQUARES:
  9252. return src.SumSqrs();
  9253. case ScriptBaseClass.LIST_STAT_GEOMETRIC_MEAN:
  9254. return src.GeometricMean();
  9255. case ScriptBaseClass.LIST_STAT_HARMONIC_MEAN:
  9256. return src.HarmonicMean();
  9257. default:
  9258. return 0.0;
  9259. }
  9260. }
  9261. public LSL_Integer llGetUnixTime()
  9262. {
  9263. m_host.AddScriptLPS(1);
  9264. return Util.UnixTimeSinceEpoch();
  9265. }
  9266. public LSL_Integer llGetParcelFlags(LSL_Vector pos)
  9267. {
  9268. m_host.AddScriptLPS(1);
  9269. return (int)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y).LandData.Flags;
  9270. }
  9271. public LSL_Integer llGetRegionFlags()
  9272. {
  9273. m_host.AddScriptLPS(1);
  9274. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  9275. if (estate == null)
  9276. return 67108864;
  9277. return (int)estate.GetRegionFlags();
  9278. }
  9279. public LSL_String llXorBase64StringsCorrect(string str1, string str2)
  9280. {
  9281. m_host.AddScriptLPS(1);
  9282. string ret = String.Empty;
  9283. string src1 = llBase64ToString(str1);
  9284. string src2 = llBase64ToString(str2);
  9285. int c = 0;
  9286. for (int i = 0; i < src1.Length; i++)
  9287. {
  9288. ret += (char) (src1[i] ^ src2[c]);
  9289. c++;
  9290. if (c >= src2.Length)
  9291. c = 0;
  9292. }
  9293. return llStringToBase64(ret);
  9294. }
  9295. public LSL_String llHTTPRequest(string url, LSL_List parameters, string body)
  9296. {
  9297. // Partial implementation: support for parameter flags needed
  9298. // see http://wiki.secondlife.com/wiki/LlHTTPRequest
  9299. // parameter flags support are implemented in ScriptsHttpRequests.cs
  9300. // in StartHttpRequest
  9301. m_host.AddScriptLPS(1);
  9302. IHttpRequestModule httpScriptMod =
  9303. m_ScriptEngine.World.RequestModuleInterface<IHttpRequestModule>();
  9304. List<string> param = new List<string>();
  9305. bool ok;
  9306. Int32 flag;
  9307. for (int i = 0; i < parameters.Data.Length; i += 2)
  9308. {
  9309. ok = Int32.TryParse(parameters.Data[i].ToString(), out flag);
  9310. if (!ok || flag < 0 ||
  9311. flag > (int)HttpRequestConstants.HTTP_PRAGMA_NO_CACHE)
  9312. {
  9313. Error("llHTTPRequest", "Parameter " + i.ToString() + " is an invalid flag");
  9314. }
  9315. param.Add(parameters.Data[i].ToString()); //Add parameter flag
  9316. if (flag != (int)HttpRequestConstants.HTTP_CUSTOM_HEADER)
  9317. {
  9318. param.Add(parameters.Data[i+1].ToString()); //Add parameter value
  9319. }
  9320. else
  9321. {
  9322. //Parameters are in pairs and custom header takes
  9323. //arguments in pairs so adjust for header marker.
  9324. ++i;
  9325. //Maximum of 8 headers are allowed based on the
  9326. //Second Life documentation for llHTTPRequest.
  9327. for (int count = 1; count <= 8; ++count)
  9328. {
  9329. //Enough parameters remaining for (another) header?
  9330. if (parameters.Data.Length - i < 2)
  9331. {
  9332. //There must be at least one name/value pair for custom header
  9333. if (count == 1)
  9334. Error("llHTTPRequest", "Missing name/value for custom header at parameter " + i.ToString());
  9335. break;
  9336. }
  9337. if (HttpStandardHeaders.Contains(parameters.Data[i].ToString(), StringComparer.OrdinalIgnoreCase))
  9338. Error("llHTTPRequest", "Name is invalid as a custom header at parameter " + i.ToString());
  9339. param.Add(parameters.Data[i].ToString());
  9340. param.Add(parameters.Data[i+1].ToString());
  9341. //Have we reached the end of the list of headers?
  9342. //End is marked by a string with a single digit.
  9343. if (i+2 >= parameters.Data.Length ||
  9344. Char.IsDigit(parameters.Data[i].ToString()[0]))
  9345. {
  9346. break;
  9347. }
  9348. i += 2;
  9349. }
  9350. }
  9351. }
  9352. Vector3 position = m_host.AbsolutePosition;
  9353. Vector3 velocity = m_host.Velocity;
  9354. Quaternion rotation = m_host.RotationOffset;
  9355. string ownerName = String.Empty;
  9356. ScenePresence scenePresence = World.GetScenePresence(m_host.OwnerID);
  9357. if (scenePresence == null)
  9358. ownerName = resolveName(m_host.OwnerID);
  9359. else
  9360. ownerName = scenePresence.Name;
  9361. RegionInfo regionInfo = World.RegionInfo;
  9362. Dictionary<string, string> httpHeaders = new Dictionary<string, string>();
  9363. string shard = "OpenSim";
  9364. IConfigSource config = m_ScriptEngine.ConfigSource;
  9365. if (config.Configs["Network"] != null)
  9366. {
  9367. shard = config.Configs["Network"].GetString("shard", shard);
  9368. }
  9369. httpHeaders["X-SecondLife-Shard"] = shard;
  9370. httpHeaders["X-SecondLife-Object-Name"] = m_host.Name;
  9371. httpHeaders["X-SecondLife-Object-Key"] = m_host.UUID.ToString();
  9372. httpHeaders["X-SecondLife-Region"] = string.Format("{0} ({1}, {2})", regionInfo.RegionName, regionInfo.RegionLocX, regionInfo.RegionLocY);
  9373. httpHeaders["X-SecondLife-Local-Position"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", position.X, position.Y, position.Z);
  9374. httpHeaders["X-SecondLife-Local-Velocity"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", velocity.X, velocity.Y, velocity.Z);
  9375. httpHeaders["X-SecondLife-Local-Rotation"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000})", rotation.X, rotation.Y, rotation.Z, rotation.W);
  9376. httpHeaders["X-SecondLife-Owner-Name"] = ownerName;
  9377. httpHeaders["X-SecondLife-Owner-Key"] = m_host.OwnerID.ToString();
  9378. string userAgent = config.Configs["Network"].GetString("user_agent", null);
  9379. if (userAgent != null)
  9380. httpHeaders["User-Agent"] = userAgent;
  9381. string authregex = @"^(https?:\/\/)(\w+):(\w+)@(.*)$";
  9382. Regex r = new Regex(authregex);
  9383. int[] gnums = r.GetGroupNumbers();
  9384. Match m = r.Match(url);
  9385. if (m.Success) {
  9386. for (int i = 1; i < gnums.Length; i++) {
  9387. //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
  9388. //CaptureCollection cc = g.Captures;
  9389. }
  9390. if (m.Groups.Count == 5) {
  9391. httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString())));
  9392. url = m.Groups[1].ToString() + m.Groups[4].ToString();
  9393. }
  9394. }
  9395. UUID reqID
  9396. = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body);
  9397. if (reqID != UUID.Zero)
  9398. return reqID.ToString();
  9399. else
  9400. return null;
  9401. }
  9402. public void llHTTPResponse(LSL_Key id, int status, string body)
  9403. {
  9404. // Partial implementation: support for parameter flags needed
  9405. // see http://wiki.secondlife.com/wiki/llHTTPResponse
  9406. m_host.AddScriptLPS(1);
  9407. if (m_UrlModule != null)
  9408. m_UrlModule.HttpResponse(new UUID(id), status,body);
  9409. }
  9410. public void llResetLandBanList()
  9411. {
  9412. m_host.AddScriptLPS(1);
  9413. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData;
  9414. if (land.OwnerID == m_host.OwnerID)
  9415. {
  9416. foreach (LandAccessEntry entry in land.ParcelAccessList)
  9417. {
  9418. if (entry.Flags == AccessList.Ban)
  9419. {
  9420. land.ParcelAccessList.Remove(entry);
  9421. }
  9422. }
  9423. }
  9424. ScriptSleep(100);
  9425. }
  9426. public void llResetLandPassList()
  9427. {
  9428. m_host.AddScriptLPS(1);
  9429. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData;
  9430. if (land.OwnerID == m_host.OwnerID)
  9431. {
  9432. foreach (LandAccessEntry entry in land.ParcelAccessList)
  9433. {
  9434. if (entry.Flags == AccessList.Access)
  9435. {
  9436. land.ParcelAccessList.Remove(entry);
  9437. }
  9438. }
  9439. }
  9440. ScriptSleep(100);
  9441. }
  9442. public LSL_Integer llGetParcelPrimCount(LSL_Vector pos, int category, int sim_wide)
  9443. {
  9444. m_host.AddScriptLPS(1);
  9445. ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  9446. if (lo == null)
  9447. return 0;
  9448. IPrimCounts pc = lo.PrimCounts;
  9449. if (sim_wide != ScriptBaseClass.FALSE)
  9450. {
  9451. if (category == ScriptBaseClass.PARCEL_COUNT_TOTAL)
  9452. {
  9453. return pc.Simulator;
  9454. }
  9455. else
  9456. {
  9457. // counts not implemented yet
  9458. return 0;
  9459. }
  9460. }
  9461. else
  9462. {
  9463. if (category == ScriptBaseClass.PARCEL_COUNT_TOTAL)
  9464. return pc.Total;
  9465. else if (category == ScriptBaseClass.PARCEL_COUNT_OWNER)
  9466. return pc.Owner;
  9467. else if (category == ScriptBaseClass.PARCEL_COUNT_GROUP)
  9468. return pc.Group;
  9469. else if (category == ScriptBaseClass.PARCEL_COUNT_OTHER)
  9470. return pc.Others;
  9471. else if (category == ScriptBaseClass.PARCEL_COUNT_SELECTED)
  9472. return pc.Selected;
  9473. else if (category == ScriptBaseClass.PARCEL_COUNT_TEMP)
  9474. return 0; // counts not implemented yet
  9475. }
  9476. return 0;
  9477. }
  9478. public LSL_List llGetParcelPrimOwners(LSL_Vector pos)
  9479. {
  9480. m_host.AddScriptLPS(1);
  9481. LandObject land = (LandObject)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  9482. LSL_List ret = new LSL_List();
  9483. if (land != null)
  9484. {
  9485. foreach (KeyValuePair<UUID, int> detectedParams in land.GetLandObjectOwners())
  9486. {
  9487. ret.Add(new LSL_String(detectedParams.Key.ToString()));
  9488. ret.Add(new LSL_Integer(detectedParams.Value));
  9489. }
  9490. }
  9491. ScriptSleep(2000);
  9492. return ret;
  9493. }
  9494. public LSL_Integer llGetObjectPrimCount(string object_id)
  9495. {
  9496. m_host.AddScriptLPS(1);
  9497. SceneObjectPart part = World.GetSceneObjectPart(new UUID(object_id));
  9498. if (part == null)
  9499. {
  9500. return 0;
  9501. }
  9502. else
  9503. {
  9504. return part.ParentGroup.PrimCount;
  9505. }
  9506. }
  9507. public LSL_Integer llGetParcelMaxPrims(LSL_Vector pos, int sim_wide)
  9508. {
  9509. m_host.AddScriptLPS(1);
  9510. ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  9511. if (lo == null)
  9512. return 0;
  9513. if (sim_wide != 0)
  9514. return lo.GetSimulatorMaxPrimCount();
  9515. else
  9516. return lo.GetParcelMaxPrimCount();
  9517. }
  9518. public LSL_List llGetParcelDetails(LSL_Vector pos, LSL_List param)
  9519. {
  9520. m_host.AddScriptLPS(1);
  9521. LandData land = World.GetLandData(pos);
  9522. if (land == null)
  9523. {
  9524. return new LSL_List(0);
  9525. }
  9526. LSL_List ret = new LSL_List();
  9527. foreach (object o in param.Data)
  9528. {
  9529. switch (o.ToString())
  9530. {
  9531. case "0":
  9532. ret.Add(new LSL_String(land.Name));
  9533. break;
  9534. case "1":
  9535. ret.Add(new LSL_String(land.Description));
  9536. break;
  9537. case "2":
  9538. ret.Add(new LSL_Key(land.OwnerID.ToString()));
  9539. break;
  9540. case "3":
  9541. ret.Add(new LSL_Key(land.GroupID.ToString()));
  9542. break;
  9543. case "4":
  9544. ret.Add(new LSL_Integer(land.Area));
  9545. break;
  9546. case "5":
  9547. ret.Add(new LSL_Key(land.GlobalID.ToString()));
  9548. break;
  9549. default:
  9550. ret.Add(new LSL_Integer(0));
  9551. break;
  9552. }
  9553. }
  9554. return ret;
  9555. }
  9556. public LSL_String llStringTrim(string src, int type)
  9557. {
  9558. m_host.AddScriptLPS(1);
  9559. if (type == (int)ScriptBaseClass.STRING_TRIM_HEAD) { return src.TrimStart(); }
  9560. if (type == (int)ScriptBaseClass.STRING_TRIM_TAIL) { return src.TrimEnd(); }
  9561. if (type == (int)ScriptBaseClass.STRING_TRIM) { return src.Trim(); }
  9562. return src;
  9563. }
  9564. public LSL_List llGetObjectDetails(string id, LSL_List args)
  9565. {
  9566. m_host.AddScriptLPS(1);
  9567. LSL_List ret = new LSL_List();
  9568. UUID key = new UUID();
  9569. if (UUID.TryParse(id, out key))
  9570. {
  9571. ScenePresence av = World.GetScenePresence(key);
  9572. if (av != null)
  9573. {
  9574. foreach (object o in args.Data)
  9575. {
  9576. switch (int.Parse(o.ToString()))
  9577. {
  9578. case ScriptBaseClass.OBJECT_NAME:
  9579. ret.Add(new LSL_String(av.Firstname + " " + av.Lastname));
  9580. break;
  9581. case ScriptBaseClass.OBJECT_DESC:
  9582. ret.Add(new LSL_String(""));
  9583. break;
  9584. case ScriptBaseClass.OBJECT_POS:
  9585. ret.Add(new LSL_Vector((double)av.AbsolutePosition.X, (double)av.AbsolutePosition.Y, (double)av.AbsolutePosition.Z));
  9586. break;
  9587. case ScriptBaseClass.OBJECT_ROT:
  9588. ret.Add(new LSL_Rotation(av.GetWorldRotation()));
  9589. break;
  9590. case ScriptBaseClass.OBJECT_VELOCITY:
  9591. ret.Add(new LSL_Vector(av.GetWorldVelocity()));
  9592. break;
  9593. case ScriptBaseClass.OBJECT_OWNER:
  9594. ret.Add(new LSL_String(id));
  9595. break;
  9596. case ScriptBaseClass.OBJECT_GROUP:
  9597. ret.Add(new LSL_String(UUID.Zero.ToString()));
  9598. break;
  9599. case ScriptBaseClass.OBJECT_CREATOR:
  9600. ret.Add(new LSL_String(UUID.Zero.ToString()));
  9601. break;
  9602. // For the following 8 see the Object version below
  9603. case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
  9604. ret.Add(new LSL_Integer(av.RunningScriptCount()));
  9605. break;
  9606. case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
  9607. ret.Add(new LSL_Integer(av.ScriptCount()));
  9608. break;
  9609. case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
  9610. ret.Add(new LSL_Integer(av.RunningScriptCount() * 16384));
  9611. break;
  9612. case ScriptBaseClass.OBJECT_SCRIPT_TIME:
  9613. ret.Add(new LSL_Float(av.ScriptExecutionTime() / 1000.0f));
  9614. break;
  9615. case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
  9616. ret.Add(new LSL_Integer(1));
  9617. break;
  9618. case ScriptBaseClass.OBJECT_SERVER_COST:
  9619. ret.Add(new LSL_Float(0));
  9620. break;
  9621. case ScriptBaseClass.OBJECT_STREAMING_COST:
  9622. ret.Add(new LSL_Float(0));
  9623. break;
  9624. case ScriptBaseClass.OBJECT_PHYSICS_COST:
  9625. ret.Add(new LSL_Float(0));
  9626. break;
  9627. case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
  9628. ret.Add(new LSL_Float(0));
  9629. break;
  9630. case ScriptBaseClass.OBJECT_ROOT:
  9631. SceneObjectPart p = av.ParentPart;
  9632. if (p != null)
  9633. {
  9634. ret.Add(new LSL_String(p.ParentGroup.RootPart.UUID.ToString()));
  9635. }
  9636. else
  9637. {
  9638. ret.Add(new LSL_String(id));
  9639. }
  9640. break;
  9641. case ScriptBaseClass.OBJECT_ATTACHED_POINT:
  9642. ret.Add(new LSL_Integer(0));
  9643. break;
  9644. case ScriptBaseClass.OBJECT_PATHFINDING_TYPE: // Pathfinding
  9645. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_AVATAR));
  9646. break;
  9647. case ScriptBaseClass.OBJECT_PHYSICS:
  9648. ret.Add(new LSL_Integer(0));
  9649. break;
  9650. case ScriptBaseClass.OBJECT_PHANTOM:
  9651. ret.Add(new LSL_Integer(0));
  9652. break;
  9653. case ScriptBaseClass.OBJECT_TEMP_ON_REZ:
  9654. ret.Add(new LSL_Integer(0));
  9655. break;
  9656. default:
  9657. // Invalid or unhandled constant.
  9658. ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
  9659. break;
  9660. }
  9661. }
  9662. return ret;
  9663. }
  9664. SceneObjectPart obj = World.GetSceneObjectPart(key);
  9665. if (obj != null)
  9666. {
  9667. foreach (object o in args.Data)
  9668. {
  9669. switch (int.Parse(o.ToString()))
  9670. {
  9671. case ScriptBaseClass.OBJECT_NAME:
  9672. ret.Add(new LSL_String(obj.Name));
  9673. break;
  9674. case ScriptBaseClass.OBJECT_DESC:
  9675. ret.Add(new LSL_String(obj.Description));
  9676. break;
  9677. case ScriptBaseClass.OBJECT_POS:
  9678. ret.Add(new LSL_Vector(obj.AbsolutePosition.X, obj.AbsolutePosition.Y, obj.AbsolutePosition.Z));
  9679. break;
  9680. case ScriptBaseClass.OBJECT_ROT:
  9681. Quaternion rot = Quaternion.Identity;
  9682. if (obj.ParentGroup.IsAttachment)
  9683. {
  9684. ScenePresence sp = World.GetScenePresence(obj.ParentGroup.AttachedAvatar);
  9685. if (sp != null)
  9686. rot = sp.GetWorldRotation();
  9687. }
  9688. else
  9689. {
  9690. if (obj.ParentGroup.RootPart == obj)
  9691. rot = obj.ParentGroup.GroupRotation;
  9692. else
  9693. rot = obj.GetWorldRotation();
  9694. }
  9695. LSL_Rotation objrot = new LSL_Rotation(rot);
  9696. ret.Add(objrot);
  9697. break;
  9698. case ScriptBaseClass.OBJECT_VELOCITY:
  9699. Vector3 vel = Vector3.Zero;
  9700. if (obj.ParentGroup.IsAttachment)
  9701. {
  9702. ScenePresence sp = World.GetScenePresence(obj.ParentGroup.AttachedAvatar);
  9703. if (sp != null)
  9704. vel = sp.GetWorldVelocity();
  9705. }
  9706. else
  9707. {
  9708. vel = obj.Velocity;
  9709. }
  9710. ret.Add(vel);
  9711. break;
  9712. case ScriptBaseClass.OBJECT_OWNER:
  9713. ret.Add(new LSL_String(obj.OwnerID.ToString()));
  9714. break;
  9715. case ScriptBaseClass.OBJECT_GROUP:
  9716. ret.Add(new LSL_String(obj.GroupID.ToString()));
  9717. break;
  9718. case ScriptBaseClass.OBJECT_CREATOR:
  9719. ret.Add(new LSL_String(obj.CreatorID.ToString()));
  9720. break;
  9721. case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
  9722. ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount()));
  9723. break;
  9724. case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
  9725. ret.Add(new LSL_Integer(obj.ParentGroup.ScriptCount()));
  9726. break;
  9727. case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
  9728. // The value returned in SL for mono scripts is 65536 * number of active scripts
  9729. // and 16384 * number of active scripts for LSO. since llGetFreememory
  9730. // is coded to give the LSO value use it here
  9731. ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount() * 16384));
  9732. break;
  9733. case ScriptBaseClass.OBJECT_SCRIPT_TIME:
  9734. // Average cpu time in seconds per simulator frame expended on all scripts in the object
  9735. ret.Add(new LSL_Float(obj.ParentGroup.ScriptExecutionTime() / 1000.0f));
  9736. break;
  9737. case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
  9738. // according to the SL wiki A prim or linkset will have prim
  9739. // equivalent of the number of prims in a linkset if it does not
  9740. // contain a mesh anywhere in the link set or is not a normal prim
  9741. // The value returned in SL for normal prims is prim count
  9742. ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
  9743. break;
  9744. // The following 3 costs I have intentionaly coded to return zero. They are part of
  9745. // "Land Impact" calculations. These calculations are probably not applicable
  9746. // to OpenSim and are not yet complete in SL
  9747. case ScriptBaseClass.OBJECT_SERVER_COST:
  9748. // The linden calculation is here
  9749. // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
  9750. // The value returned in SL for normal prims looks like the prim count
  9751. ret.Add(new LSL_Float(0));
  9752. break;
  9753. case ScriptBaseClass.OBJECT_STREAMING_COST:
  9754. // The linden calculation is here
  9755. // http://wiki.secondlife.com/wiki/Mesh/Mesh_Streaming_Cost
  9756. // The value returned in SL for normal prims looks like the prim count * 0.06
  9757. ret.Add(new LSL_Float(0));
  9758. break;
  9759. case ScriptBaseClass.OBJECT_PHYSICS_COST:
  9760. // The linden calculation is here
  9761. // http://wiki.secondlife.com/wiki/Mesh/Mesh_physics
  9762. // The value returned in SL for normal prims looks like the prim count
  9763. ret.Add(new LSL_Float(0));
  9764. break;
  9765. case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
  9766. ret.Add(new LSL_Float(0));
  9767. break;
  9768. case ScriptBaseClass.OBJECT_ROOT:
  9769. ret.Add(new LSL_String(obj.ParentGroup.RootPart.UUID.ToString()));
  9770. break;
  9771. case ScriptBaseClass.OBJECT_ATTACHED_POINT:
  9772. ret.Add(new LSL_Integer(obj.ParentGroup.AttachmentPoint));
  9773. break;
  9774. case ScriptBaseClass.OBJECT_PATHFINDING_TYPE:
  9775. byte pcode = obj.Shape.PCode;
  9776. if (obj.ParentGroup.AttachmentPoint != 0
  9777. || pcode == (byte)PCode.Grass
  9778. || pcode == (byte)PCode.Tree
  9779. || pcode == (byte)PCode.NewTree)
  9780. {
  9781. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_OTHER));
  9782. }
  9783. else
  9784. {
  9785. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_LEGACY_LINKSET));
  9786. }
  9787. break;
  9788. case ScriptBaseClass.OBJECT_PHYSICS:
  9789. if (obj.ParentGroup.AttachmentPoint != 0)
  9790. {
  9791. ret.Add(new LSL_Integer(0)); // Always false if attached
  9792. }
  9793. else
  9794. {
  9795. ret.Add(new LSL_Integer(obj.ParentGroup.UsesPhysics ? 1 : 0));
  9796. }
  9797. break;
  9798. case ScriptBaseClass.OBJECT_PHANTOM:
  9799. if (obj.ParentGroup.AttachmentPoint != 0)
  9800. {
  9801. ret.Add(new LSL_Integer(0)); // Always false if attached
  9802. }
  9803. else
  9804. {
  9805. ret.Add(new LSL_Integer(obj.ParentGroup.IsPhantom ? 1 : 0));
  9806. }
  9807. break;
  9808. case ScriptBaseClass.OBJECT_TEMP_ON_REZ:
  9809. ret.Add(new LSL_Integer(obj.ParentGroup.IsTemporary ? 1 : 0));
  9810. break;
  9811. default:
  9812. // Invalid or unhandled constant.
  9813. ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
  9814. break;
  9815. }
  9816. }
  9817. return ret;
  9818. }
  9819. }
  9820. return new LSL_List();
  9821. }
  9822. internal UUID GetScriptByName(string name)
  9823. {
  9824. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  9825. if (item == null || item.Type != 10)
  9826. return UUID.Zero;
  9827. return item.ItemID;
  9828. }
  9829. /// <summary>
  9830. /// Reports the script error in the viewer's Script Warning/Error dialog and shouts it on the debug channel.
  9831. /// </summary>
  9832. /// <param name="command">The name of the command that generated the error.</param>
  9833. /// <param name="message">The error message to report to the user.</param>
  9834. internal void Error(string command, string message)
  9835. {
  9836. string text = command + ": " + message;
  9837. if (text.Length > 1023)
  9838. {
  9839. text = text.Substring(0, 1023);
  9840. }
  9841. World.SimChat(Utils.StringToBytes(text), ChatTypeEnum.DebugChannel, ScriptBaseClass.DEBUG_CHANNEL,
  9842. m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  9843. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  9844. if (wComm != null)
  9845. {
  9846. wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, text);
  9847. }
  9848. }
  9849. /// <summary>
  9850. /// Reports that the command is not implemented as a script error.
  9851. /// </summary>
  9852. /// <param name="command">The name of the command that is not implemented.</param>
  9853. /// <param name="message">Additional information to report to the user. (Optional)</param>
  9854. internal void NotImplemented(string command, string message = "")
  9855. {
  9856. if (throwErrorOnNotImplemented)
  9857. {
  9858. if (message != "")
  9859. {
  9860. message = " - " + message;
  9861. }
  9862. throw new NotImplementedException("Command not implemented: " + command + message);
  9863. }
  9864. else
  9865. {
  9866. string text = "Command not implemented";
  9867. if (message != "")
  9868. {
  9869. text = text + " - " + message;
  9870. }
  9871. Error(command, text);
  9872. }
  9873. }
  9874. /// <summary>
  9875. /// Reports that the command is deprecated as a script error.
  9876. /// </summary>
  9877. /// <param name="command">The name of the command that is deprecated.</param>
  9878. /// <param name="message">Additional information to report to the user. (Optional)</param>
  9879. internal void Deprecated(string command, string message = "")
  9880. {
  9881. string text = "Command deprecated";
  9882. if (message != "")
  9883. {
  9884. text = text + " - " + message;
  9885. }
  9886. Error(command, text);
  9887. }
  9888. public delegate void AssetRequestCallback(UUID assetID, AssetBase asset);
  9889. protected void WithNotecard(UUID assetID, AssetRequestCallback cb)
  9890. {
  9891. World.AssetService.Get(assetID.ToString(), this,
  9892. delegate(string i, object sender, AssetBase a)
  9893. {
  9894. UUID uuid = UUID.Zero;
  9895. UUID.TryParse(i, out uuid);
  9896. cb(uuid, a);
  9897. });
  9898. }
  9899. public LSL_String llGetNumberOfNotecardLines(string name)
  9900. {
  9901. m_host.AddScriptLPS(1);
  9902. UUID assetID = UUID.Zero;
  9903. if (!UUID.TryParse(name, out assetID))
  9904. {
  9905. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  9906. if (item != null && item.Type == 7)
  9907. assetID = item.AssetID;
  9908. }
  9909. if (assetID == UUID.Zero)
  9910. {
  9911. // => complain loudly, as specified by the LSL docs
  9912. Error("llGetNumberOfNotecardLines", "Can't find notecard '" + name + "'");
  9913. return UUID.Zero.ToString();
  9914. }
  9915. string reqIdentifier = UUID.Random().ToString();
  9916. // was: UUID tid = tid = AsyncCommands.
  9917. UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, reqIdentifier);
  9918. if (NotecardCache.IsCached(assetID))
  9919. {
  9920. AsyncCommands.DataserverPlugin.DataserverReply(reqIdentifier, NotecardCache.GetLines(assetID).ToString());
  9921. ScriptSleep(100);
  9922. return tid.ToString();
  9923. }
  9924. WithNotecard(assetID, delegate (UUID id, AssetBase a)
  9925. {
  9926. if (a == null || a.Type != 7)
  9927. {
  9928. Error("llGetNumberOfNotecardLines", "Can't find notecard '" + name + "'");
  9929. return;
  9930. }
  9931. string data = Encoding.UTF8.GetString(a.Data);
  9932. //m_log.Debug(data);
  9933. NotecardCache.Cache(id, data);
  9934. AsyncCommands.DataserverPlugin.DataserverReply(reqIdentifier, NotecardCache.GetLines(id).ToString());
  9935. });
  9936. ScriptSleep(100);
  9937. return tid.ToString();
  9938. }
  9939. public LSL_String llGetNotecardLine(string name, int line)
  9940. {
  9941. m_host.AddScriptLPS(1);
  9942. UUID assetID = UUID.Zero;
  9943. if (!UUID.TryParse(name, out assetID))
  9944. {
  9945. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  9946. if (item != null && item.Type == 7)
  9947. assetID = item.AssetID;
  9948. }
  9949. if (assetID == UUID.Zero)
  9950. {
  9951. // => complain loudly, as specified by the LSL docs
  9952. Error("llGetNotecardLine", "Can't find notecard '" + name + "'");
  9953. return UUID.Zero.ToString();
  9954. }
  9955. string reqIdentifier = UUID.Random().ToString();
  9956. // was: UUID tid = tid = AsyncCommands.
  9957. UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, reqIdentifier);
  9958. if (NotecardCache.IsCached(assetID))
  9959. {
  9960. AsyncCommands.DataserverPlugin.DataserverReply(
  9961. reqIdentifier, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  9962. ScriptSleep(100);
  9963. return tid.ToString();
  9964. }
  9965. WithNotecard(assetID, delegate (UUID id, AssetBase a)
  9966. {
  9967. if (a == null || a.Type != 7)
  9968. {
  9969. Error("llGetNotecardLine", "Can't find notecard '" + name + "'");
  9970. return;
  9971. }
  9972. string data = Encoding.UTF8.GetString(a.Data);
  9973. //m_log.Debug(data);
  9974. NotecardCache.Cache(id, data);
  9975. AsyncCommands.DataserverPlugin.DataserverReply(
  9976. reqIdentifier, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  9977. });
  9978. ScriptSleep(100);
  9979. return tid.ToString();
  9980. }
  9981. public void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules, string originFunc)
  9982. {
  9983. SceneObjectPart obj = World.GetSceneObjectPart(new UUID(prim));
  9984. if (obj == null)
  9985. return;
  9986. if (obj.OwnerID != m_host.OwnerID)
  9987. return;
  9988. SetEntityParams(new List<ISceneEntity>() { obj }, rules, originFunc);
  9989. }
  9990. public LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules)
  9991. {
  9992. SceneObjectPart obj = World.GetSceneObjectPart(new UUID(prim));
  9993. if (obj != null && obj.OwnerID == m_host.OwnerID)
  9994. return GetEntityParams(obj, rules);
  9995. return new LSL_List();
  9996. }
  9997. public void print(string str)
  9998. {
  9999. // yes, this is a real LSL function. See: http://wiki.secondlife.com/wiki/Print
  10000. IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
  10001. if (ossl != null)
  10002. {
  10003. ossl.CheckThreatLevel(ThreatLevel.High, "print");
  10004. m_log.Info("LSL print():" + str);
  10005. }
  10006. }
  10007. private string Name2Username(string name)
  10008. {
  10009. string[] parts = name.Split(new char[] {' '});
  10010. if (parts.Length < 2)
  10011. return name.ToLower();
  10012. if (parts[1] == "Resident")
  10013. return parts[0].ToLower();
  10014. return name.Replace(" ", ".").ToLower();
  10015. }
  10016. public LSL_String llGetUsername(string id)
  10017. {
  10018. return Name2Username(llKey2Name(id));
  10019. }
  10020. public LSL_String llRequestUsername(string id)
  10021. {
  10022. UUID rq = UUID.Random();
  10023. AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
  10024. AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id)));
  10025. return rq.ToString();
  10026. }
  10027. public LSL_String llGetDisplayName(string id)
  10028. {
  10029. return llKey2Name(id);
  10030. }
  10031. public LSL_String llRequestDisplayName(string id)
  10032. {
  10033. UUID rq = UUID.Random();
  10034. AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
  10035. AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id));
  10036. return rq.ToString();
  10037. }
  10038. private struct Tri
  10039. {
  10040. public Vector3 p1;
  10041. public Vector3 p2;
  10042. public Vector3 p3;
  10043. }
  10044. private bool InBoundingBox(ScenePresence avatar, Vector3 point)
  10045. {
  10046. float height = avatar.Appearance.AvatarHeight;
  10047. Vector3 b1 = avatar.AbsolutePosition + new Vector3(-0.22f, -0.22f, -height/2);
  10048. Vector3 b2 = avatar.AbsolutePosition + new Vector3(0.22f, 0.22f, height/2);
  10049. if (point.X > b1.X && point.X < b2.X &&
  10050. point.Y > b1.Y && point.Y < b2.Y &&
  10051. point.Z > b1.Z && point.Z < b2.Z)
  10052. return true;
  10053. return false;
  10054. }
  10055. private ContactResult[] AvatarIntersection(Vector3 rayStart, Vector3 rayEnd)
  10056. {
  10057. List<ContactResult> contacts = new List<ContactResult>();
  10058. Vector3 ab = rayEnd - rayStart;
  10059. World.ForEachScenePresence(delegate(ScenePresence sp)
  10060. {
  10061. Vector3 ac = sp.AbsolutePosition - rayStart;
  10062. // Vector3 bc = sp.AbsolutePosition - rayEnd;
  10063. double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd));
  10064. if (d > 1.5)
  10065. return;
  10066. double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
  10067. if (d2 > 0)
  10068. return;
  10069. double dp = Math.Sqrt(Vector3.Mag(ac) * Vector3.Mag(ac) - d * d);
  10070. Vector3 p = rayStart + Vector3.Divide(Vector3.Multiply(ab, (float)dp), (float)Vector3.Mag(ab));
  10071. if (!InBoundingBox(sp, p))
  10072. return;
  10073. ContactResult result = new ContactResult ();
  10074. result.ConsumerID = sp.LocalId;
  10075. result.Depth = Vector3.Distance(rayStart, p);
  10076. result.Normal = Vector3.Zero;
  10077. result.Pos = p;
  10078. contacts.Add(result);
  10079. });
  10080. return contacts.ToArray();
  10081. }
  10082. private ContactResult[] ObjectIntersection(Vector3 rayStart, Vector3 rayEnd, bool includePhysical, bool includeNonPhysical, bool includePhantom)
  10083. {
  10084. Ray ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
  10085. List<ContactResult> contacts = new List<ContactResult>();
  10086. Vector3 ab = rayEnd - rayStart;
  10087. World.ForEachSOG(delegate(SceneObjectGroup group)
  10088. {
  10089. if (m_host.ParentGroup == group)
  10090. return;
  10091. if (group.IsAttachment)
  10092. return;
  10093. if (group.RootPart.PhysActor == null)
  10094. {
  10095. if (!includePhantom)
  10096. return;
  10097. }
  10098. else
  10099. {
  10100. if (group.RootPart.PhysActor.IsPhysical)
  10101. {
  10102. if (!includePhysical)
  10103. return;
  10104. }
  10105. else
  10106. {
  10107. if (!includeNonPhysical)
  10108. return;
  10109. }
  10110. }
  10111. // Find the radius ouside of which we don't even need to hit test
  10112. float minX;
  10113. float maxX;
  10114. float minY;
  10115. float maxY;
  10116. float minZ;
  10117. float maxZ;
  10118. float radius = 0.0f;
  10119. group.GetAxisAlignedBoundingBoxRaw(out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
  10120. if (Math.Abs(minX) > radius)
  10121. radius = Math.Abs(minX);
  10122. if (Math.Abs(minY) > radius)
  10123. radius = Math.Abs(minY);
  10124. if (Math.Abs(minZ) > radius)
  10125. radius = Math.Abs(minZ);
  10126. if (Math.Abs(maxX) > radius)
  10127. radius = Math.Abs(maxX);
  10128. if (Math.Abs(maxY) > radius)
  10129. radius = Math.Abs(maxY);
  10130. if (Math.Abs(maxZ) > radius)
  10131. radius = Math.Abs(maxZ);
  10132. radius = radius*1.413f;
  10133. Vector3 ac = group.AbsolutePosition - rayStart;
  10134. // Vector3 bc = group.AbsolutePosition - rayEnd;
  10135. double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd));
  10136. // Too far off ray, don't bother
  10137. if (d > radius)
  10138. return;
  10139. // Behind ray, drop
  10140. double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
  10141. if (d2 > 0)
  10142. return;
  10143. ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
  10144. EntityIntersection intersection = group.TestIntersection(ray, true, false);
  10145. // Miss.
  10146. if (!intersection.HitTF)
  10147. return;
  10148. Vector3 b1 = group.AbsolutePosition + new Vector3(minX, minY, minZ);
  10149. Vector3 b2 = group.AbsolutePosition + new Vector3(maxX, maxY, maxZ);
  10150. //m_log.DebugFormat("[LLCASTRAY]: min<{0},{1},{2}>, max<{3},{4},{5}> = hitp<{6},{7},{8}>", b1.X,b1.Y,b1.Z,b2.X,b2.Y,b2.Z,intersection.ipoint.X,intersection.ipoint.Y,intersection.ipoint.Z);
  10151. if (!(intersection.ipoint.X >= b1.X && intersection.ipoint.X <= b2.X &&
  10152. intersection.ipoint.Y >= b1.Y && intersection.ipoint.Y <= b2.Y &&
  10153. intersection.ipoint.Z >= b1.Z && intersection.ipoint.Z <= b2.Z))
  10154. return;
  10155. ContactResult result = new ContactResult ();
  10156. result.ConsumerID = group.LocalId;
  10157. result.Depth = intersection.distance;
  10158. result.Normal = intersection.normal;
  10159. result.Pos = intersection.ipoint;
  10160. contacts.Add(result);
  10161. });
  10162. return contacts.ToArray();
  10163. }
  10164. private ContactResult? GroundIntersection(Vector3 rayStart, Vector3 rayEnd)
  10165. {
  10166. double[,] heightfield = World.Heightmap.GetDoubles();
  10167. List<ContactResult> contacts = new List<ContactResult>();
  10168. double min = 2048.0;
  10169. double max = 0.0;
  10170. // Find the min and max of the heightfield
  10171. for (int x = 0 ; x < World.Heightmap.Width ; x++)
  10172. {
  10173. for (int y = 0 ; y < World.Heightmap.Height ; y++)
  10174. {
  10175. if (heightfield[x, y] > max)
  10176. max = heightfield[x, y];
  10177. if (heightfield[x, y] < min)
  10178. min = heightfield[x, y];
  10179. }
  10180. }
  10181. // A ray extends past rayEnd, but doesn't go back before
  10182. // rayStart. If the start is above the highest point of the ground
  10183. // and the ray goes up, we can't hit the ground. Ever.
  10184. if (rayStart.Z > max && rayEnd.Z >= rayStart.Z)
  10185. return null;
  10186. // Same for going down
  10187. if (rayStart.Z < min && rayEnd.Z <= rayStart.Z)
  10188. return null;
  10189. List<Tri> trilist = new List<Tri>();
  10190. // Create our triangle list
  10191. for (int x = 1 ; x < World.Heightmap.Width ; x++)
  10192. {
  10193. for (int y = 1 ; y < World.Heightmap.Height ; y++)
  10194. {
  10195. Tri t1 = new Tri();
  10196. Tri t2 = new Tri();
  10197. Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]);
  10198. Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]);
  10199. Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]);
  10200. Vector3 p4 = new Vector3(x-1, y, (float)heightfield[x-1, y]);
  10201. t1.p1 = p1;
  10202. t1.p2 = p2;
  10203. t1.p3 = p3;
  10204. t2.p1 = p3;
  10205. t2.p2 = p4;
  10206. t2.p3 = p1;
  10207. trilist.Add(t1);
  10208. trilist.Add(t2);
  10209. }
  10210. }
  10211. // Ray direction
  10212. Vector3 rayDirection = rayEnd - rayStart;
  10213. foreach (Tri t in trilist)
  10214. {
  10215. // Compute triangle plane normal and edges
  10216. Vector3 u = t.p2 - t.p1;
  10217. Vector3 v = t.p3 - t.p1;
  10218. Vector3 n = Vector3.Cross(u, v);
  10219. if (n == Vector3.Zero)
  10220. continue;
  10221. Vector3 w0 = rayStart - t.p1;
  10222. double a = -Vector3.Dot(n, w0);
  10223. double b = Vector3.Dot(n, rayDirection);
  10224. // Not intersecting the plane, or in plane (same thing)
  10225. // Ignoring this MAY cause the ground to not be detected
  10226. // sometimes
  10227. if (Math.Abs(b) < 0.000001)
  10228. continue;
  10229. double r = a / b;
  10230. // ray points away from plane
  10231. if (r < 0.0)
  10232. continue;
  10233. Vector3 ip = rayStart + Vector3.Multiply(rayDirection, (float)r);
  10234. float uu = Vector3.Dot(u, u);
  10235. float uv = Vector3.Dot(u, v);
  10236. float vv = Vector3.Dot(v, v);
  10237. Vector3 w = ip - t.p1;
  10238. float wu = Vector3.Dot(w, u);
  10239. float wv = Vector3.Dot(w, v);
  10240. float d = uv * uv - uu * vv;
  10241. float cs = (uv * wv - vv * wu) / d;
  10242. if (cs < 0 || cs > 1.0)
  10243. continue;
  10244. float ct = (uv * wu - uu * wv) / d;
  10245. if (ct < 0 || (cs + ct) > 1.0)
  10246. continue;
  10247. // Add contact point
  10248. ContactResult result = new ContactResult ();
  10249. result.ConsumerID = 0;
  10250. result.Depth = Vector3.Distance(rayStart, ip);
  10251. result.Normal = n;
  10252. result.Pos = ip;
  10253. contacts.Add(result);
  10254. }
  10255. if (contacts.Count == 0)
  10256. return null;
  10257. contacts.Sort(delegate(ContactResult a, ContactResult b)
  10258. {
  10259. return (int)(a.Depth - b.Depth);
  10260. });
  10261. return contacts[0];
  10262. }
  10263. public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
  10264. {
  10265. LSL_List list = new LSL_List();
  10266. m_host.AddScriptLPS(1);
  10267. Vector3 rayStart = start;
  10268. Vector3 rayEnd = end;
  10269. Vector3 dir = rayEnd - rayStart;
  10270. float dist = Vector3.Mag(dir);
  10271. int count = 1;
  10272. bool detectPhantom = false;
  10273. int dataFlags = 0;
  10274. int rejectTypes = 0;
  10275. for (int i = 0; i < options.Length; i += 2)
  10276. {
  10277. if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
  10278. count = options.GetLSLIntegerItem(i + 1);
  10279. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
  10280. detectPhantom = (options.GetLSLIntegerItem(i + 1) > 0);
  10281. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
  10282. dataFlags = options.GetLSLIntegerItem(i + 1);
  10283. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
  10284. rejectTypes = options.GetLSLIntegerItem(i + 1);
  10285. }
  10286. if (count > 16)
  10287. count = 16;
  10288. List<ContactResult> results = new List<ContactResult>();
  10289. bool checkTerrain = !((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND);
  10290. bool checkAgents = !((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) == ScriptBaseClass.RC_REJECT_AGENTS);
  10291. bool checkNonPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) == ScriptBaseClass.RC_REJECT_NONPHYSICAL);
  10292. bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL);
  10293. if (World.SupportsRayCastFiltered())
  10294. {
  10295. if (dist == 0)
  10296. return list;
  10297. RayFilterFlags rayfilter = RayFilterFlags.ClosestAndBackCull;
  10298. if (checkTerrain)
  10299. rayfilter |= RayFilterFlags.land;
  10300. // if (checkAgents)
  10301. // rayfilter |= RayFilterFlags.agent;
  10302. if (checkPhysical)
  10303. rayfilter |= RayFilterFlags.physical;
  10304. if (checkNonPhysical)
  10305. rayfilter |= RayFilterFlags.nonphysical;
  10306. if (detectPhantom)
  10307. rayfilter |= RayFilterFlags.LSLPhantom;
  10308. Vector3 direction = dir * ( 1/dist);
  10309. if(rayfilter == 0)
  10310. {
  10311. list.Add(new LSL_Integer(0));
  10312. return list;
  10313. }
  10314. // get some more contacts to sort ???
  10315. int physcount = 4 * count;
  10316. if (physcount > 20)
  10317. physcount = 20;
  10318. object physresults;
  10319. physresults = World.RayCastFiltered(rayStart, direction, dist, physcount, rayfilter);
  10320. if (physresults == null)
  10321. {
  10322. list.Add(new LSL_Integer(-3)); // timeout error
  10323. return list;
  10324. }
  10325. results = (List<ContactResult>)physresults;
  10326. // for now physics doesn't detect sitted avatars so do it outside physics
  10327. if (checkAgents)
  10328. {
  10329. ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd);
  10330. foreach (ContactResult r in agentHits)
  10331. results.Add(r);
  10332. }
  10333. // TODO: Replace this with a better solution. ObjectIntersection can only
  10334. // detect nonphysical phantoms. They are detected by virtue of being
  10335. // nonphysical (e.g. no PhysActor) so will not conflict with detecting
  10336. // physicsl phantoms as done by the physics scene
  10337. // We don't want anything else but phantoms here.
  10338. if (detectPhantom)
  10339. {
  10340. ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, false, false, true);
  10341. foreach (ContactResult r in objectHits)
  10342. results.Add(r);
  10343. }
  10344. }
  10345. else
  10346. {
  10347. if (checkAgents)
  10348. {
  10349. ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd);
  10350. foreach (ContactResult r in agentHits)
  10351. results.Add(r);
  10352. }
  10353. if (checkPhysical || checkNonPhysical || detectPhantom)
  10354. {
  10355. ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, checkPhysical, checkNonPhysical, detectPhantom);
  10356. for (int iter = 0; iter < objectHits.Length; iter++)
  10357. {
  10358. // Redistance the Depth because the Scene RayCaster returns distance from center to make the rezzing code simpler.
  10359. objectHits[iter].Depth = Vector3.Distance(objectHits[iter].Pos, rayStart);
  10360. results.Add(objectHits[iter]);
  10361. }
  10362. }
  10363. }
  10364. if (checkTerrain)
  10365. {
  10366. ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
  10367. if (groundContact != null)
  10368. results.Add((ContactResult)groundContact);
  10369. }
  10370. results.Sort(delegate(ContactResult a, ContactResult b)
  10371. {
  10372. return a.Depth.CompareTo(b.Depth);
  10373. });
  10374. int values = 0;
  10375. SceneObjectGroup thisgrp = m_host.ParentGroup;
  10376. foreach (ContactResult result in results)
  10377. {
  10378. if (result.Depth > dist)
  10379. continue;
  10380. // physics ray can return colisions with host prim
  10381. if (m_host.LocalId == result.ConsumerID)
  10382. continue;
  10383. UUID itemID = UUID.Zero;
  10384. int linkNum = 0;
  10385. SceneObjectPart part = World.GetSceneObjectPart(result.ConsumerID);
  10386. // It's a prim!
  10387. if (part != null)
  10388. {
  10389. // dont detect members of same object ???
  10390. if (part.ParentGroup == thisgrp)
  10391. continue;
  10392. if ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) == ScriptBaseClass.RC_GET_ROOT_KEY)
  10393. itemID = part.ParentGroup.UUID;
  10394. else
  10395. itemID = part.UUID;
  10396. linkNum = part.LinkNum;
  10397. }
  10398. else
  10399. {
  10400. ScenePresence sp = World.GetScenePresence(result.ConsumerID);
  10401. /// It it a boy? a girl?
  10402. if (sp != null)
  10403. itemID = sp.UUID;
  10404. }
  10405. list.Add(new LSL_String(itemID.ToString()));
  10406. list.Add(new LSL_String(result.Pos.ToString()));
  10407. if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
  10408. list.Add(new LSL_Integer(linkNum));
  10409. if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
  10410. list.Add(new LSL_Vector(result.Normal));
  10411. values++;
  10412. if (values >= count)
  10413. break;
  10414. }
  10415. list.Add(new LSL_Integer(values));
  10416. return list;
  10417. }
  10418. public LSL_Integer llManageEstateAccess(int action, string avatar)
  10419. {
  10420. m_host.AddScriptLPS(1);
  10421. EstateSettings estate = World.RegionInfo.EstateSettings;
  10422. bool isAccount = false;
  10423. bool isGroup = false;
  10424. if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManagerOrOwner(m_host.OwnerID))
  10425. return 0;
  10426. UUID id = new UUID();
  10427. if (!UUID.TryParse(avatar, out id))
  10428. return 0;
  10429. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, id);
  10430. isAccount = account != null ? true : false;
  10431. if (!isAccount)
  10432. {
  10433. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  10434. if (groups != null)
  10435. {
  10436. GroupRecord group = groups.GetGroupRecord(id);
  10437. isGroup = group != null ? true : false;
  10438. if (!isGroup)
  10439. return 0;
  10440. }
  10441. else
  10442. return 0;
  10443. }
  10444. switch (action)
  10445. {
  10446. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_ADD:
  10447. if (!isAccount) return 0;
  10448. if (estate.HasAccess(id)) return 1;
  10449. if (estate.IsBanned(id))
  10450. estate.RemoveBan(id);
  10451. estate.AddEstateUser(id);
  10452. break;
  10453. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_REMOVE:
  10454. if (!isAccount || !estate.HasAccess(id)) return 0;
  10455. estate.RemoveEstateUser(id);
  10456. break;
  10457. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_GROUP_ADD:
  10458. if (!isGroup) return 0;
  10459. if (estate.GroupAccess(id)) return 1;
  10460. estate.AddEstateGroup(id);
  10461. break;
  10462. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_GROUP_REMOVE:
  10463. if (!isGroup || !estate.GroupAccess(id)) return 0;
  10464. estate.RemoveEstateGroup(id);
  10465. break;
  10466. case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_ADD:
  10467. if (!isAccount) return 0;
  10468. if (estate.IsBanned(id)) return 1;
  10469. EstateBan ban = new EstateBan();
  10470. ban.EstateID = estate.EstateID;
  10471. ban.BannedUserID = id;
  10472. estate.AddBan(ban);
  10473. break;
  10474. case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_REMOVE:
  10475. if (!isAccount || !estate.IsBanned(id)) return 0;
  10476. estate.RemoveBan(id);
  10477. break;
  10478. default: return 0;
  10479. }
  10480. return 1;
  10481. }
  10482. public LSL_Integer llGetMemoryLimit()
  10483. {
  10484. m_host.AddScriptLPS(1);
  10485. // The value returned for LSO scripts in SL
  10486. return 16384;
  10487. }
  10488. public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
  10489. {
  10490. m_host.AddScriptLPS(1);
  10491. // Treat as an LSO script
  10492. return ScriptBaseClass.FALSE;
  10493. }
  10494. public LSL_Integer llGetSPMaxMemory()
  10495. {
  10496. m_host.AddScriptLPS(1);
  10497. // The value returned for LSO scripts in SL
  10498. return 16384;
  10499. }
  10500. public virtual LSL_Integer llGetUsedMemory()
  10501. {
  10502. m_host.AddScriptLPS(1);
  10503. // The value returned for LSO scripts in SL
  10504. return 16384;
  10505. }
  10506. public void llScriptProfiler(LSL_Integer flags)
  10507. {
  10508. m_host.AddScriptLPS(1);
  10509. // This does nothing for LSO scripts in SL
  10510. }
  10511. #region Not Implemented
  10512. //
  10513. // Listing the unimplemented lsl functions here, please move
  10514. // them from this region as they are completed
  10515. //
  10516. public void llGetEnv(LSL_String name)
  10517. {
  10518. m_host.AddScriptLPS(1);
  10519. NotImplemented("llGetEnv");
  10520. }
  10521. public void llSetSoundQueueing(int queue)
  10522. {
  10523. m_host.AddScriptLPS(1);
  10524. if (m_SoundModule != null)
  10525. m_SoundModule.SetSoundQueueing(m_host.UUID, queue == ScriptBaseClass.TRUE.value);
  10526. }
  10527. public void llCollisionSprite(string impact_sprite)
  10528. {
  10529. m_host.AddScriptLPS(1);
  10530. NotImplemented("llCollisionSprite");
  10531. }
  10532. public void llGodLikeRezObject(string inventory, LSL_Vector pos)
  10533. {
  10534. m_host.AddScriptLPS(1);
  10535. NotImplemented("llGodLikeRezObject");
  10536. }
  10537. public LSL_String llTransferLindenDollars(string destination, int amount)
  10538. {
  10539. UUID txn = UUID.Random();
  10540. Util.FireAndForget(delegate(object x)
  10541. {
  10542. int replycode = 0;
  10543. string replydata = destination + "," + amount.ToString();
  10544. try
  10545. {
  10546. TaskInventoryItem item = m_item;
  10547. if (item == null)
  10548. {
  10549. replydata = "SERVICE_ERROR";
  10550. return;
  10551. }
  10552. m_host.AddScriptLPS(1);
  10553. if (item.PermsGranter == UUID.Zero)
  10554. {
  10555. replydata = "MISSING_PERMISSION_DEBIT";
  10556. return;
  10557. }
  10558. if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  10559. {
  10560. replydata = "MISSING_PERMISSION_DEBIT";
  10561. return;
  10562. }
  10563. UUID toID = new UUID();
  10564. if (!UUID.TryParse(destination, out toID))
  10565. {
  10566. replydata = "INVALID_AGENT";
  10567. return;
  10568. }
  10569. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  10570. if (money == null)
  10571. {
  10572. replydata = "TRANSFERS_DISABLED";
  10573. return;
  10574. }
  10575. bool result = money.ObjectGiveMoney(
  10576. m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount);
  10577. if (result)
  10578. {
  10579. replycode = 1;
  10580. return;
  10581. }
  10582. replydata = "LINDENDOLLAR_INSUFFICIENTFUNDS";
  10583. }
  10584. finally
  10585. {
  10586. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  10587. "transaction_result", new Object[] {
  10588. new LSL_String(txn.ToString()),
  10589. new LSL_Integer(replycode),
  10590. new LSL_String(replydata) },
  10591. new DetectParams[0]));
  10592. }
  10593. }, null, "LSL_Api.llTransferLindenDollars");
  10594. return txn.ToString();
  10595. }
  10596. #endregion
  10597. }
  10598. public class NotecardCache
  10599. {
  10600. protected class Notecard
  10601. {
  10602. public string[] text;
  10603. public DateTime lastRef;
  10604. }
  10605. protected static Dictionary<UUID, Notecard> m_Notecards =
  10606. new Dictionary<UUID, Notecard>();
  10607. public static void Cache(UUID assetID, string text)
  10608. {
  10609. CheckCache();
  10610. lock (m_Notecards)
  10611. {
  10612. if (m_Notecards.ContainsKey(assetID))
  10613. return;
  10614. Notecard nc = new Notecard();
  10615. nc.lastRef = DateTime.Now;
  10616. nc.text = SLUtil.ParseNotecardToList(text).ToArray();
  10617. m_Notecards[assetID] = nc;
  10618. }
  10619. }
  10620. public static bool IsCached(UUID assetID)
  10621. {
  10622. lock (m_Notecards)
  10623. {
  10624. return m_Notecards.ContainsKey(assetID);
  10625. }
  10626. }
  10627. public static int GetLines(UUID assetID)
  10628. {
  10629. if (!IsCached(assetID))
  10630. return -1;
  10631. lock (m_Notecards)
  10632. {
  10633. m_Notecards[assetID].lastRef = DateTime.Now;
  10634. return m_Notecards[assetID].text.Length;
  10635. }
  10636. }
  10637. /// <summary>
  10638. /// Get a notecard line.
  10639. /// </summary>
  10640. /// <param name="assetID"></param>
  10641. /// <param name="lineNumber">Lines start at index 0</param>
  10642. /// <returns></returns>
  10643. public static string GetLine(UUID assetID, int lineNumber)
  10644. {
  10645. if (lineNumber < 0)
  10646. return "";
  10647. string data;
  10648. if (!IsCached(assetID))
  10649. return "";
  10650. lock (m_Notecards)
  10651. {
  10652. m_Notecards[assetID].lastRef = DateTime.Now;
  10653. if (lineNumber >= m_Notecards[assetID].text.Length)
  10654. return "\n\n\n";
  10655. data = m_Notecards[assetID].text[lineNumber];
  10656. return data;
  10657. }
  10658. }
  10659. /// <summary>
  10660. /// Get a notecard line.
  10661. /// </summary>
  10662. /// <param name="assetID"></param>
  10663. /// <param name="lineNumber">Lines start at index 0</param>
  10664. /// <param name="maxLength">
  10665. /// Maximum length of the returned line.
  10666. /// </param>
  10667. /// <returns>
  10668. /// If the line length is longer than <paramref name="maxLength"/>,
  10669. /// the return string will be truncated.
  10670. /// </returns>
  10671. public static string GetLine(UUID assetID, int lineNumber, int maxLength)
  10672. {
  10673. string line = GetLine(assetID, lineNumber);
  10674. if (line.Length > maxLength)
  10675. line = line.Substring(0, maxLength);
  10676. return line;
  10677. }
  10678. public static void CheckCache()
  10679. {
  10680. lock (m_Notecards)
  10681. {
  10682. foreach (UUID key in new List<UUID>(m_Notecards.Keys))
  10683. {
  10684. Notecard nc = m_Notecards[key];
  10685. if (nc.lastRef.AddSeconds(30) < DateTime.Now)
  10686. m_Notecards.Remove(key);
  10687. }
  10688. }
  10689. }
  10690. }
  10691. }