LSL_Api.cs 738 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769
  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 log4net;
  28. using Nini.Config;
  29. using OpenMetaverse;
  30. using OpenMetaverse.Assets;
  31. using OpenMetaverse.Packets;
  32. using OpenMetaverse.Rendering;
  33. using OpenSim.Framework;
  34. using OpenSim.Region.CoreModules.World.Land;
  35. using OpenSim.Region.Framework.Interfaces;
  36. using OpenSim.Region.Framework.Scenes;
  37. using OpenSim.Region.Framework.Scenes.Animation;
  38. using OpenSim.Region.Framework.Scenes.Scripting;
  39. using OpenSim.Region.Framework.Scenes.Serialization;
  40. using OpenSim.Region.PhysicsModules.SharedBase;
  41. using OpenSim.Region.ScriptEngine.Interfaces;
  42. using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
  43. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  44. using OpenSim.Services.Interfaces;
  45. using OpenSim.Services.Connectors.Hypergrid;
  46. using System;
  47. using System.Collections;
  48. using System.Collections.Generic;
  49. using System.Collections.Specialized;
  50. using System.Diagnostics;
  51. using System.Drawing;
  52. using System.Globalization;
  53. using System.Reflection;
  54. using System.Runtime.Remoting.Lifetime;
  55. using System.Text;
  56. using System.Text.RegularExpressions;
  57. using System.Threading;
  58. using AssetLandmark = OpenSim.Framework.AssetLandmark;
  59. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  60. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  61. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  62. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  63. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  64. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  65. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  66. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  67. using PermissionMask = OpenSim.Framework.PermissionMask;
  68. using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
  69. using PrimType = OpenSim.Region.Framework.Scenes.PrimType;
  70. using RegionFlags = OpenSim.Framework.RegionFlags;
  71. using RegionInfo = OpenSim.Framework.RegionInfo;
  72. namespace OpenSim.Region.ScriptEngine.Shared.Api
  73. {
  74. /// <summary>
  75. /// Contains all LSL ll-functions. This class will be in Default AppDomain.
  76. /// </summary>
  77. public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi
  78. {
  79. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  80. private int m_llRequestAgentDataCacheTimeout;
  81. public int LlRequestAgentDataCacheTimeoutMs
  82. {
  83. get
  84. {
  85. return 1000 * m_llRequestAgentDataCacheTimeout;
  86. }
  87. set
  88. {
  89. m_llRequestAgentDataCacheTimeout = value / 1000;
  90. }
  91. }
  92. protected IScriptEngine m_ScriptEngine;
  93. protected SceneObjectPart m_host;
  94. protected UUID RegionScopeID = UUID.Zero;
  95. /// <summary>
  96. /// The item that hosts this script
  97. /// </summary>
  98. protected TaskInventoryItem m_item;
  99. protected bool throwErrorOnNotImplemented = false;
  100. protected float m_ScriptDelayFactor = 1.0f;
  101. protected float m_ScriptDistanceFactor = 1.0f;
  102. protected float m_MinTimerInterval = 0.5f;
  103. protected float m_recoilScaleFactor = 0.0f;
  104. protected bool m_AllowGodFunctions;
  105. protected double m_timer = Util.GetTimeStampMS();
  106. protected bool m_waitingForScriptAnswer = false;
  107. protected bool m_automaticLinkPermission = false;
  108. protected int m_notecardLineReadCharsMax = 255;
  109. protected int m_scriptConsoleChannel = 0;
  110. protected bool m_scriptConsoleChannelEnabled = false;
  111. protected bool m_debuggerSafe = false;
  112. protected AsyncCommandManager m_AsyncCommands = null;
  113. protected IUrlModule m_UrlModule = null;
  114. protected IMaterialsModule m_materialsModule = null;
  115. protected IEnvironmentModule m_envModule = null;
  116. protected IEmailModule m_emailModule = null;
  117. protected IUserAccountService m_userAccountService = null;
  118. protected IMessageTransferModule m_TransferModule = null;
  119. protected ExpiringCacheOS<UUID, PresenceInfo> m_PresenceInfoCache = new ExpiringCacheOS<UUID, PresenceInfo>(10000);
  120. protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp.
  121. protected int m_sleepMsOnSetTexture = 200;
  122. protected int m_sleepMsOnSetLinkTexture = 200;
  123. protected int m_sleepMsOnScaleTexture = 200;
  124. protected int m_sleepMsOnOffsetTexture = 200;
  125. protected int m_sleepMsOnRotateTexture = 200;
  126. protected int m_sleepMsOnSetPos = 200;
  127. protected int m_sleepMsOnSetRot = 200;
  128. protected int m_sleepMsOnSetLocalRot = 200;
  129. protected int m_sleepMsOnPreloadSound = 1000;
  130. protected int m_sleepMsOnMakeExplosion = 100;
  131. protected int m_sleepMsOnMakeFountain = 100;
  132. protected int m_sleepMsOnMakeSmoke = 100;
  133. protected int m_sleepMsOnMakeFire = 100;
  134. protected int m_sleepMsOnRezAtRoot = 100;
  135. protected int m_sleepMsOnInstantMessage = 2000;
  136. protected int m_sleepMsOnEmail = 30000;
  137. protected int m_sleepMsOnCreateLink = 1000;
  138. protected int m_sleepMsOnGiveInventory = 3000;
  139. protected int m_sleepMsOnRequestAgentData = 100;
  140. protected int m_sleepMsOnRequestInventoryData = 1000;
  141. protected int m_sleepMsOnSetDamage = 5000;
  142. protected int m_sleepMsOnTextBox = 1000;
  143. protected int m_sleepMsOnAdjustSoundVolume = 100;
  144. protected int m_sleepMsOnEjectFromLand = 1000;
  145. protected int m_sleepMsOnAddToLandPassList = 100;
  146. protected int m_sleepMsOnDialog = 1000;
  147. protected int m_sleepMsOnRemoteLoadScript = 3000;
  148. protected int m_sleepMsOnRemoteLoadScriptPin = 3000;
  149. protected int m_sleepMsOnOpenRemoteDataChannel = 1000;
  150. protected int m_sleepMsOnSendRemoteData = 3000;
  151. protected int m_sleepMsOnRemoteDataReply = 3000;
  152. protected int m_sleepMsOnCloseRemoteDataChannel = 1000;
  153. protected int m_sleepMsOnSetPrimitiveParams = 200;
  154. protected int m_sleepMsOnSetLinkPrimitiveParams = 200;
  155. protected int m_sleepMsOnXorBase64Strings = 300;
  156. protected int m_sleepMsOnSetParcelMusicURL = 2000;
  157. protected int m_sleepMsOnGetPrimMediaParams = 1000;
  158. protected int m_sleepMsOnGetLinkMedia = 1000;
  159. protected int m_sleepMsOnSetPrimMediaParams = 1000;
  160. protected int m_sleepMsOnSetLinkMedia = 1000;
  161. protected int m_sleepMsOnClearPrimMedia = 1000;
  162. protected int m_sleepMsOnClearLinkMedia = 1000;
  163. protected int m_sleepMsOnRequestSimulatorData = 1000;
  164. protected int m_sleepMsOnLoadURL = 10000;
  165. protected int m_sleepMsOnParcelMediaCommandList = 2000;
  166. protected int m_sleepMsOnParcelMediaQuery = 2000;
  167. protected int m_sleepMsOnModPow = 1000;
  168. protected int m_sleepMsOnSetPrimURL = 2000;
  169. protected int m_sleepMsOnRefreshPrimURL = 20000;
  170. protected int m_sleepMsOnMapDestination = 1000;
  171. protected int m_sleepMsOnAddToLandBanList = 100;
  172. protected int m_sleepMsOnRemoveFromLandPassList = 100;
  173. protected int m_sleepMsOnRemoveFromLandBanList = 100;
  174. protected int m_sleepMsOnResetLandBanList = 100;
  175. protected int m_sleepMsOnResetLandPassList = 100;
  176. protected int m_sleepMsOnGetParcelPrimOwners = 2000;
  177. protected int m_sleepMsOnGetNumberOfNotecardLines = 100;
  178. protected int m_sleepMsOnGetNotecardLine = 100;
  179. protected string m_internalObjectHost = "lsl.opensim.local";
  180. protected bool m_restrictEmail = false;
  181. protected ISoundModule m_SoundModule = null;
  182. protected float m_avatarHeightCorrection = 0.2f;
  183. protected bool m_useSimpleBoxesInGetBoundingBox = false;
  184. protected bool m_addStatsInGetBoundingBox = false;
  185. //LSL Avatar Bounding Box (lABB), lower (1) and upper (2),
  186. //standing (Std), Groundsitting (Grs), Sitting (Sit),
  187. //along X, Y and Z axes, constants (0) and coefficients (1)
  188. protected float m_lABB1StdX0 = -0.275f;
  189. protected float m_lABB2StdX0 = 0.275f;
  190. protected float m_lABB1StdY0 = -0.35f;
  191. protected float m_lABB2StdY0 = 0.35f;
  192. protected float m_lABB1StdZ0 = -0.1f;
  193. protected float m_lABB1StdZ1 = -0.5f;
  194. protected float m_lABB2StdZ0 = 0.1f;
  195. protected float m_lABB2StdZ1 = 0.5f;
  196. protected float m_lABB1GrsX0 = -0.3875f;
  197. protected float m_lABB2GrsX0 = 0.3875f;
  198. protected float m_lABB1GrsY0 = -0.5f;
  199. protected float m_lABB2GrsY0 = 0.5f;
  200. protected float m_lABB1GrsZ0 = -0.05f;
  201. protected float m_lABB1GrsZ1 = -0.375f;
  202. protected float m_lABB2GrsZ0 = 0.5f;
  203. protected float m_lABB2GrsZ1 = 0.0f;
  204. protected float m_lABB1SitX0 = -0.5875f;
  205. protected float m_lABB2SitX0 = 0.1875f;
  206. protected float m_lABB1SitY0 = -0.35f;
  207. protected float m_lABB2SitY0 = 0.35f;
  208. protected float m_lABB1SitZ0 = -0.35f;
  209. protected float m_lABB1SitZ1 = -0.375f;
  210. protected float m_lABB2SitZ0 = -0.25f;
  211. protected float m_lABB2SitZ1 = 0.25f;
  212. protected float m_primSafetyCoeffX = 2.414214f;
  213. protected float m_primSafetyCoeffY = 2.414214f;
  214. protected float m_primSafetyCoeffZ = 1.618034f;
  215. protected float m_floatToleranceInCastRay = 0.00001f;
  216. protected float m_floatTolerance2InCastRay = 0.001f;
  217. protected DetailLevel m_primLodInCastRay = DetailLevel.Medium;
  218. protected DetailLevel m_sculptLodInCastRay = DetailLevel.Medium;
  219. protected DetailLevel m_meshLodInCastRay = DetailLevel.Highest;
  220. protected DetailLevel m_avatarLodInCastRay = DetailLevel.Medium;
  221. protected int m_maxHitsInCastRay = 16;
  222. protected int m_maxHitsPerPrimInCastRay = 16;
  223. protected int m_maxHitsPerObjectInCastRay = 16;
  224. protected bool m_detectExitsInCastRay = false;
  225. protected bool m_doAttachmentsInCastRay = false;
  226. protected int m_msThrottleInCastRay = 200;
  227. protected int m_msPerRegionInCastRay = 40;
  228. protected int m_msPerAvatarInCastRay = 10;
  229. protected int m_msMinInCastRay = 2;
  230. protected int m_msMaxInCastRay = 40;
  231. protected static List<CastRayCall> m_castRayCalls = new List<CastRayCall>();
  232. protected bool m_useMeshCacheInCastRay = true;
  233. protected static Dictionary<ulong, FacetedMesh> m_cachedMeshes = new Dictionary<ulong, FacetedMesh>();
  234. // protected Timer m_ShoutSayTimer;
  235. protected int m_SayShoutCount = 0;
  236. DateTime m_lastSayShoutCheck;
  237. private int m_whisperdistance = 10;
  238. private int m_saydistance = 20;
  239. private int m_shoutdistance = 100;
  240. private string m_lsl_shard = "OpenSim";
  241. private string m_lsl_user_agent = string.Empty;
  242. private static readonly Dictionary<string, string> MovementAnimationsForLSL =
  243. new Dictionary<string, string> {
  244. {"CROUCH", "Crouching"},
  245. {"CROUCHWALK", "CrouchWalking"},
  246. {"FALLDOWN", "Falling Down"},
  247. {"FLY", "Flying"},
  248. {"FLYSLOW", "FlyingSlow"},
  249. {"HOVER", "Hovering"},
  250. {"HOVER_UP", "Hovering Up"},
  251. {"HOVER_DOWN", "Hovering Down"},
  252. {"JUMP", "Jumping"},
  253. {"LAND", "Landing"},
  254. {"PREJUMP", "PreJumping"},
  255. {"RUN", "Running"},
  256. {"SIT","Sitting"},
  257. {"SITGROUND","Sitting on Ground"},
  258. {"STAND", "Standing"},
  259. {"STANDUP", "Standing Up"},
  260. {"STRIDE","Striding"},
  261. {"SOFT_LAND", "Soft Landing"},
  262. {"TURNLEFT", "Turning Left"},
  263. {"TURNRIGHT", "Turning Right"},
  264. {"WALK", "Walking"}
  265. };
  266. //An array of HTTP/1.1 headers that are not allowed to be used
  267. //as custom headers by llHTTPRequest.
  268. private static readonly HashSet<string> HttpStandardHeaders = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase)
  269. {
  270. "Accept", "Accept-Charset", "Accept-Encoding", "Accept-Language",
  271. "Accept-Ranges", "Age", "Allow", "Authorization", "Cache-Control",
  272. "Connection", "Content-Encoding", "Content-Language",
  273. "Content-Length", "Content-Location", "Content-MD5",
  274. "Content-Range", "Content-Type", "Date", "ETag", "Expect",
  275. "Expires", "From", "Host", "If-Match", "If-Modified-Since",
  276. "If-None-Match", "If-Range", "If-Unmodified-Since", "Last-Modified",
  277. "Location", "Max-Forwards", "Pragma", "Proxy-Authenticate",
  278. "Proxy-Authorization", "Range", "Referer", "Retry-After", "Server",
  279. "TE", "Trailer", "Transfer-Encoding", "Upgrade", "User-Agent",
  280. "Vary", "Via", "Warning", "WWW-Authenticate"
  281. };
  282. private static readonly HashSet<string> HttpForbiddenInHeaders = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase)
  283. {
  284. "x-secondlife-shard", "x-secondlife-object-name", "x-secondlife-object-key",
  285. "x-secondlife-region", "x-secondlife-local-position", "x-secondlife-local-velocity",
  286. "x-secondlife-local-rotation", "x-secondlife-owner-name", "x-secondlife-owner-key",
  287. "connection", "content-length", "from", "host", "proxy-authorization",
  288. "referer", "trailer", "transfer-encoding", "via", "authorization"
  289. };
  290. public void Initialize(
  291. IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item)
  292. {
  293. m_lastSayShoutCheck = DateTime.UtcNow;
  294. m_ScriptEngine = scriptEngine;
  295. m_host = host;
  296. m_item = item;
  297. m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
  298. LoadConfig();
  299. m_TransferModule =
  300. m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
  301. m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
  302. m_SoundModule = m_ScriptEngine.World.RequestModuleInterface<ISoundModule>();
  303. m_materialsModule = m_ScriptEngine.World.RequestModuleInterface<IMaterialsModule>();
  304. m_emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  305. m_envModule = m_ScriptEngine.World.RequestModuleInterface< IEnvironmentModule>();
  306. m_AsyncCommands = new AsyncCommandManager(m_ScriptEngine);
  307. m_userAccountService = World.UserAccountService;
  308. if(World.RegionInfo != null)
  309. RegionScopeID = World.RegionInfo.ScopeID;
  310. }
  311. /// <summary>
  312. /// Load configuration items that affect script, object and run-time behavior. */
  313. /// </summary>
  314. private void LoadConfig()
  315. {
  316. LlRequestAgentDataCacheTimeoutMs = 20000;
  317. IConfig seConfig = m_ScriptEngine.Config;
  318. if (seConfig != null)
  319. {
  320. m_ScriptDelayFactor =
  321. seConfig.GetFloat("ScriptDelayFactor", m_ScriptDelayFactor);
  322. m_ScriptDistanceFactor =
  323. seConfig.GetFloat("ScriptDistanceLimitFactor", m_ScriptDistanceFactor);
  324. m_MinTimerInterval =
  325. seConfig.GetFloat("MinTimerInterval", m_MinTimerInterval);
  326. m_automaticLinkPermission =
  327. seConfig.GetBoolean("AutomaticLinkPermission", m_automaticLinkPermission);
  328. m_notecardLineReadCharsMax =
  329. seConfig.GetInt("NotecardLineReadCharsMax", m_notecardLineReadCharsMax);
  330. // Rezzing an object with a velocity can create recoil. This feature seems to have been
  331. // removed from recent versions of SL. The code computes recoil (vel*mass) and scales
  332. // it by this factor. May be zero to turn off recoil all together.
  333. m_recoilScaleFactor = seConfig.GetFloat("RecoilScaleFactor", m_recoilScaleFactor);
  334. m_AllowGodFunctions = seConfig.GetBoolean("AllowGodFunctions", false);
  335. }
  336. if (m_notecardLineReadCharsMax > 65535)
  337. m_notecardLineReadCharsMax = 65535;
  338. // load limits for particular subsystems.
  339. IConfigSource seConfigSource = m_ScriptEngine.ConfigSource;
  340. if (seConfigSource != null)
  341. {
  342. IConfig netConfig = seConfigSource.Configs["Network"];
  343. if (netConfig != null)
  344. {
  345. m_lsl_shard = netConfig.GetString("shard", m_lsl_shard);
  346. m_lsl_user_agent = netConfig.GetString("user_agent", m_lsl_user_agent);
  347. }
  348. IConfig lslConfig = seConfigSource.Configs["LL-Functions"];
  349. if (lslConfig != null)
  350. {
  351. m_restrictEmail = lslConfig.GetBoolean("RestrictEmail", m_restrictEmail);
  352. m_avatarHeightCorrection = lslConfig.GetFloat("AvatarHeightCorrection", m_avatarHeightCorrection);
  353. m_useSimpleBoxesInGetBoundingBox = lslConfig.GetBoolean("UseSimpleBoxesInGetBoundingBox", m_useSimpleBoxesInGetBoundingBox);
  354. m_addStatsInGetBoundingBox = lslConfig.GetBoolean("AddStatsInGetBoundingBox", m_addStatsInGetBoundingBox);
  355. m_lABB1StdX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingXconst", m_lABB1StdX0);
  356. m_lABB2StdX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingXconst", m_lABB2StdX0);
  357. m_lABB1StdY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingYconst", m_lABB1StdY0);
  358. m_lABB2StdY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingYconst", m_lABB2StdY0);
  359. m_lABB1StdZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingZconst", m_lABB1StdZ0);
  360. m_lABB1StdZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingZcoeff", m_lABB1StdZ1);
  361. m_lABB2StdZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingZconst", m_lABB2StdZ0);
  362. m_lABB2StdZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingZcoeff", m_lABB2StdZ1);
  363. m_lABB1GrsX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingXconst", m_lABB1GrsX0);
  364. m_lABB2GrsX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingXconst", m_lABB2GrsX0);
  365. m_lABB1GrsY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingYconst", m_lABB1GrsY0);
  366. m_lABB2GrsY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingYconst", m_lABB2GrsY0);
  367. m_lABB1GrsZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingZconst", m_lABB1GrsZ0);
  368. m_lABB1GrsZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingZcoeff", m_lABB1GrsZ1);
  369. m_lABB2GrsZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingZconst", m_lABB2GrsZ0);
  370. m_lABB2GrsZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingZcoeff", m_lABB2GrsZ1);
  371. m_lABB1SitX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingXconst", m_lABB1SitX0);
  372. m_lABB2SitX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingXconst", m_lABB2SitX0);
  373. m_lABB1SitY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingYconst", m_lABB1SitY0);
  374. m_lABB2SitY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingYconst", m_lABB2SitY0);
  375. m_lABB1SitZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingZconst", m_lABB1SitZ0);
  376. m_lABB1SitZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingZcoeff", m_lABB1SitZ1);
  377. m_lABB2SitZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingZconst", m_lABB2SitZ0);
  378. m_lABB2SitZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingZcoeff", m_lABB2SitZ1);
  379. m_primSafetyCoeffX = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientX", m_primSafetyCoeffX);
  380. m_primSafetyCoeffY = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientY", m_primSafetyCoeffY);
  381. m_primSafetyCoeffZ = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientZ", m_primSafetyCoeffZ);
  382. m_floatToleranceInCastRay = lslConfig.GetFloat("FloatToleranceInLlCastRay", m_floatToleranceInCastRay);
  383. m_floatTolerance2InCastRay = lslConfig.GetFloat("FloatTolerance2InLlCastRay", m_floatTolerance2InCastRay);
  384. m_primLodInCastRay = (DetailLevel)lslConfig.GetInt("PrimDetailLevelInLlCastRay", (int)m_primLodInCastRay);
  385. m_sculptLodInCastRay = (DetailLevel)lslConfig.GetInt("SculptDetailLevelInLlCastRay", (int)m_sculptLodInCastRay);
  386. m_meshLodInCastRay = (DetailLevel)lslConfig.GetInt("MeshDetailLevelInLlCastRay", (int)m_meshLodInCastRay);
  387. m_avatarLodInCastRay = (DetailLevel)lslConfig.GetInt("AvatarDetailLevelInLlCastRay", (int)m_avatarLodInCastRay);
  388. m_maxHitsInCastRay = lslConfig.GetInt("MaxHitsInLlCastRay", m_maxHitsInCastRay);
  389. m_maxHitsPerPrimInCastRay = lslConfig.GetInt("MaxHitsPerPrimInLlCastRay", m_maxHitsPerPrimInCastRay);
  390. m_maxHitsPerObjectInCastRay = lslConfig.GetInt("MaxHitsPerObjectInLlCastRay", m_maxHitsPerObjectInCastRay);
  391. m_detectExitsInCastRay = lslConfig.GetBoolean("DetectExitHitsInLlCastRay", m_detectExitsInCastRay);
  392. m_doAttachmentsInCastRay = lslConfig.GetBoolean("DoAttachmentsInLlCastRay", m_doAttachmentsInCastRay);
  393. m_msThrottleInCastRay = lslConfig.GetInt("ThrottleTimeInMsInLlCastRay", m_msThrottleInCastRay);
  394. m_msPerRegionInCastRay = lslConfig.GetInt("AvailableTimeInMsPerRegionInLlCastRay", m_msPerRegionInCastRay);
  395. m_msPerAvatarInCastRay = lslConfig.GetInt("AvailableTimeInMsPerAvatarInLlCastRay", m_msPerAvatarInCastRay);
  396. m_msMinInCastRay = lslConfig.GetInt("RequiredAvailableTimeInMsInLlCastRay", m_msMinInCastRay);
  397. m_msMaxInCastRay = lslConfig.GetInt("MaximumAvailableTimeInMsInLlCastRay", m_msMaxInCastRay);
  398. m_useMeshCacheInCastRay = lslConfig.GetBoolean("UseMeshCacheInLlCastRay", m_useMeshCacheInCastRay);
  399. }
  400. IConfig smtpConfig = seConfigSource.Configs["SMTP"];
  401. if (smtpConfig != null)
  402. {
  403. // there's an smtp config, so load in the snooze time.
  404. EMAIL_PAUSE_TIME = smtpConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME);
  405. m_internalObjectHost = smtpConfig.GetString("internal_object_host", m_internalObjectHost);
  406. }
  407. IConfig chatConfig = seConfigSource.Configs["SMTP"];
  408. if(chatConfig != null)
  409. {
  410. m_whisperdistance = chatConfig.GetInt("whisper_distance", m_whisperdistance);
  411. m_saydistance = chatConfig.GetInt("say_distance", m_saydistance);
  412. m_shoutdistance = chatConfig.GetInt("shout_distance", m_shoutdistance);
  413. }
  414. }
  415. m_sleepMsOnEmail = EMAIL_PAUSE_TIME * 1000;
  416. }
  417. public override Object InitializeLifetimeService()
  418. {
  419. ILease lease = (ILease)base.InitializeLifetimeService();
  420. if (lease.CurrentState == LeaseState.Initial)
  421. {
  422. lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
  423. // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
  424. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
  425. }
  426. return lease;
  427. }
  428. protected SceneObjectPart MonitoringObject()
  429. {
  430. UUID m = m_host.ParentGroup.MonitoringObject;
  431. if (m == UUID.Zero)
  432. return null;
  433. SceneObjectPart p = m_ScriptEngine.World.GetSceneObjectPart(m);
  434. if (p == null)
  435. m_host.ParentGroup.MonitoringObject = UUID.Zero;
  436. return p;
  437. }
  438. protected virtual void ScriptSleep(int delay)
  439. {
  440. delay = (int)(delay * m_ScriptDelayFactor);
  441. if (delay < 10)
  442. return;
  443. Sleep(delay);
  444. }
  445. protected virtual void Sleep(int delay)
  446. {
  447. if (m_item == null) // Some unit tests don't set this
  448. Thread.Sleep(delay);
  449. else
  450. m_ScriptEngine.SleepScript(m_item.ItemID, delay);
  451. }
  452. /// <summary>
  453. /// Check for co-operative termination.
  454. /// </summary>
  455. /// <param name='delay'>If called with 0, then just the check is performed with no wait.</param>
  456. public Scene World
  457. {
  458. get { return m_ScriptEngine.World; }
  459. }
  460. [DebuggerNonUserCode]
  461. public void state(string newState)
  462. {
  463. m_ScriptEngine.SetState(m_item.ItemID, newState);
  464. }
  465. /// <summary>
  466. /// Reset the named script. The script must be present
  467. /// in the same prim.
  468. /// </summary>
  469. [DebuggerNonUserCode]
  470. public void llResetScript()
  471. {
  472. m_host.AddScriptLPS(1);
  473. // We need to tell the URL module, if we hav one, to release
  474. // the allocated URLs
  475. if (m_UrlModule != null)
  476. m_UrlModule.ScriptRemoved(m_item.ItemID);
  477. m_ScriptEngine.ApiResetScript(m_item.ItemID);
  478. }
  479. public void llResetOtherScript(string name)
  480. {
  481. UUID item;
  482. if ((item = GetScriptByName(name)) == UUID.Zero)
  483. {
  484. m_host.AddScriptLPS(1);
  485. Error("llResetOtherScript", "Can't find script '" + name + "'");
  486. return;
  487. }
  488. if(item == m_item.ItemID)
  489. llResetScript();
  490. else
  491. {
  492. m_host.AddScriptLPS(1);
  493. m_ScriptEngine.ResetScript(item);
  494. }
  495. }
  496. public LSL_Integer llGetScriptState(string name)
  497. {
  498. UUID item;
  499. m_host.AddScriptLPS(1);
  500. if ((item = GetScriptByName(name)) != UUID.Zero)
  501. {
  502. return m_ScriptEngine.GetScriptState(item) ?1:0;
  503. }
  504. Error("llGetScriptState", "Can't find script '" + name + "'");
  505. // If we didn't find it, then it's safe to
  506. // assume it is not running.
  507. return 0;
  508. }
  509. public void llSetScriptState(string name, int run)
  510. {
  511. UUID item;
  512. m_host.AddScriptLPS(1);
  513. // These functions are supposed to be robust,
  514. // so get the state one step at a time.
  515. if ((item = GetScriptByName(name)) != UUID.Zero)
  516. {
  517. m_ScriptEngine.SetScriptState(item, run == 0 ? false : true, item == m_item.ItemID);
  518. }
  519. else
  520. {
  521. Error("llSetScriptState", "Can't find script '" + name + "'");
  522. }
  523. }
  524. public List<ScenePresence> GetLinkAvatars(int linkType)
  525. {
  526. List<ScenePresence> ret = new List<ScenePresence>();
  527. if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
  528. return ret;
  529. // List<ScenePresence> avs = m_host.ParentGroup.GetLinkedAvatars();
  530. // this needs check
  531. List<ScenePresence> avs = m_host.ParentGroup.GetSittingAvatars();
  532. switch (linkType)
  533. {
  534. case ScriptBaseClass.LINK_SET:
  535. return avs;
  536. case ScriptBaseClass.LINK_ROOT:
  537. return ret;
  538. case ScriptBaseClass.LINK_ALL_OTHERS:
  539. return avs;
  540. case ScriptBaseClass.LINK_ALL_CHILDREN:
  541. return avs;
  542. case ScriptBaseClass.LINK_THIS:
  543. return ret;
  544. default:
  545. if (linkType < 0)
  546. return ret;
  547. int partCount = m_host.ParentGroup.GetPartCount();
  548. if (linkType <= partCount)
  549. {
  550. return ret;
  551. }
  552. else
  553. {
  554. linkType = linkType - partCount;
  555. if (linkType > avs.Count)
  556. {
  557. return ret;
  558. }
  559. else
  560. {
  561. ret.Add(avs[linkType-1]);
  562. return ret;
  563. }
  564. }
  565. }
  566. }
  567. /// <summary>
  568. /// Get a given link entity from a linkset (linked objects and any sitting avatars).
  569. /// </summary>
  570. /// <remarks>
  571. /// If there are any ScenePresence's in the linkset (i.e. because they are sat upon one of the prims), then
  572. /// these are counted as extra entities that correspond to linknums beyond the number of prims in the linkset.
  573. /// The ScenePresences receive linknums in the order in which they sat.
  574. /// </remarks>
  575. /// <returns>
  576. /// The link entity. null if not found.
  577. /// </returns>
  578. /// <param name='part'></param>
  579. /// <param name='linknum'>
  580. /// Can be either a non-negative integer or ScriptBaseClass.LINK_THIS (-4).
  581. /// If ScriptBaseClass.LINK_THIS then the entity containing the script is returned.
  582. /// If the linkset has one entity and a linknum of zero is given, then the single entity is returned. If any
  583. /// positive integer is given in this case then null is returned.
  584. /// If the linkset has more than one entity and a linknum greater than zero but equal to or less than the number
  585. /// of entities, then the entity which corresponds to that linknum is returned.
  586. /// Otherwise, if a positive linknum is given which is greater than the number of entities in the linkset, then
  587. /// null is returned.
  588. /// </param>
  589. public ISceneEntity GetLinkEntity(SceneObjectPart part, int linknum)
  590. {
  591. if (linknum < 0)
  592. {
  593. if (linknum == ScriptBaseClass.LINK_THIS)
  594. return part;
  595. else
  596. return null;
  597. }
  598. int actualPrimCount = part.ParentGroup.PrimCount;
  599. List<ScenePresence> sittingAvatars = part.ParentGroup.GetSittingAvatars();
  600. int adjustedPrimCount = actualPrimCount + sittingAvatars.Count;
  601. // Special case for a single prim. In this case the linknum is zero. However, this will not match a single
  602. // prim that has any avatars sat upon it (in which case the root prim is link 1).
  603. if (linknum == 0)
  604. {
  605. if (actualPrimCount == 1 && sittingAvatars.Count == 0)
  606. return part;
  607. return null;
  608. }
  609. // Special case to handle a single prim with sitting avatars. GetLinkPart() would only match zero but
  610. // here we must match 1 (ScriptBaseClass.LINK_ROOT).
  611. else if (linknum == ScriptBaseClass.LINK_ROOT && actualPrimCount == 1)
  612. {
  613. if (sittingAvatars.Count > 0)
  614. return part.ParentGroup.RootPart;
  615. else
  616. return null;
  617. }
  618. else if (linknum <= adjustedPrimCount)
  619. {
  620. if (linknum <= actualPrimCount)
  621. {
  622. return part.ParentGroup.GetLinkNumPart(linknum);
  623. }
  624. else
  625. {
  626. return sittingAvatars[linknum - actualPrimCount - 1];
  627. }
  628. }
  629. else
  630. {
  631. return null;
  632. }
  633. }
  634. public List<SceneObjectPart> GetLinkParts(int linkType)
  635. {
  636. return GetLinkParts(m_host, linkType);
  637. }
  638. public static List<SceneObjectPart> GetLinkParts(SceneObjectPart part, int linkType)
  639. {
  640. List<SceneObjectPart> ret = new List<SceneObjectPart>();
  641. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  642. return ret;
  643. switch (linkType)
  644. {
  645. case ScriptBaseClass.LINK_SET:
  646. return new List<SceneObjectPart>(part.ParentGroup.Parts);
  647. case ScriptBaseClass.LINK_ROOT:
  648. ret.Add(part.ParentGroup.RootPart);
  649. return ret;
  650. case ScriptBaseClass.LINK_ALL_OTHERS:
  651. ret = new List<SceneObjectPart>(part.ParentGroup.Parts);
  652. if (ret.Contains(part))
  653. ret.Remove(part);
  654. return ret;
  655. case ScriptBaseClass.LINK_ALL_CHILDREN:
  656. ret = new List<SceneObjectPart>(part.ParentGroup.Parts);
  657. if (ret.Contains(part.ParentGroup.RootPart))
  658. ret.Remove(part.ParentGroup.RootPart);
  659. return ret;
  660. case ScriptBaseClass.LINK_THIS:
  661. ret.Add(part);
  662. return ret;
  663. default:
  664. if (linkType < 0)
  665. return ret;
  666. SceneObjectPart target = part.ParentGroup.GetLinkNumPart(linkType);
  667. if (target == null)
  668. return ret;
  669. ret.Add(target);
  670. return ret;
  671. }
  672. }
  673. public List<ISceneEntity> GetLinkEntities(int linkType)
  674. {
  675. return GetLinkEntities(m_host, linkType);
  676. }
  677. public List<ISceneEntity> GetLinkEntities(SceneObjectPart part, int linkType)
  678. {
  679. List<ISceneEntity> ret;
  680. switch (linkType)
  681. {
  682. case ScriptBaseClass.LINK_SET:
  683. return new List<ISceneEntity>(part.ParentGroup.Parts);
  684. case ScriptBaseClass.LINK_ROOT:
  685. return new List<ISceneEntity>() { part.ParentGroup.RootPart };
  686. case ScriptBaseClass.LINK_ALL_OTHERS:
  687. ret = new List<ISceneEntity>(part.ParentGroup.Parts);
  688. if (ret.Contains(part))
  689. ret.Remove(part);
  690. return ret;
  691. case ScriptBaseClass.LINK_ALL_CHILDREN:
  692. ret = new List<ISceneEntity>(part.ParentGroup.Parts);
  693. if (ret.Contains(part.ParentGroup.RootPart))
  694. ret.Remove(part.ParentGroup.RootPart);
  695. List<ScenePresence> avs = part.ParentGroup.GetSittingAvatars();
  696. if(avs!= null && avs.Count > 0)
  697. ret.AddRange(avs);
  698. return ret;
  699. case ScriptBaseClass.LINK_THIS:
  700. return new List<ISceneEntity>() { part };
  701. default:
  702. if (linkType < 0)
  703. return new List<ISceneEntity>();
  704. ISceneEntity target = GetLinkEntity(part, linkType);
  705. if (target == null)
  706. return new List<ISceneEntity>();
  707. return new List<ISceneEntity>() { target };
  708. }
  709. }
  710. //These are the implementations of the various ll-functions used by the LSL scripts.
  711. public LSL_Float llSin(double f)
  712. {
  713. m_host.AddScriptLPS(1);
  714. return Math.Sin(f);
  715. }
  716. public LSL_Float llCos(double f)
  717. {
  718. m_host.AddScriptLPS(1);
  719. return Math.Cos(f);
  720. }
  721. public LSL_Float llTan(double f)
  722. {
  723. m_host.AddScriptLPS(1);
  724. return Math.Tan(f);
  725. }
  726. public LSL_Float llAtan2(LSL_Float x, LSL_Float y)
  727. {
  728. m_host.AddScriptLPS(1);
  729. return Math.Atan2(x, y);
  730. }
  731. public LSL_Float llSqrt(double f)
  732. {
  733. m_host.AddScriptLPS(1);
  734. return Math.Sqrt(f);
  735. }
  736. public LSL_Float llPow(double fbase, double fexponent)
  737. {
  738. m_host.AddScriptLPS(1);
  739. return (double)Math.Pow(fbase, fexponent);
  740. }
  741. public LSL_Integer llAbs(LSL_Integer i)
  742. {
  743. // changed to replicate LSL behaviour whereby minimum int value is returned untouched.
  744. m_host.AddScriptLPS(1);
  745. if (i == Int32.MinValue)
  746. return i;
  747. else
  748. return (int)Math.Abs(i);
  749. }
  750. public LSL_Float llFabs(double f)
  751. {
  752. m_host.AddScriptLPS(1);
  753. return (double)Math.Abs(f);
  754. }
  755. public LSL_Float llFrand(double mag)
  756. {
  757. m_host.AddScriptLPS(1);
  758. lock (Util.RandomClass)
  759. {
  760. return Util.RandomClass.NextDouble() * mag;
  761. }
  762. }
  763. public LSL_Integer llFloor(double f)
  764. {
  765. m_host.AddScriptLPS(1);
  766. return (int)Math.Floor(f);
  767. }
  768. public LSL_Integer llCeil(double f)
  769. {
  770. m_host.AddScriptLPS(1);
  771. return (int)Math.Ceiling(f);
  772. }
  773. // Xantor 01/May/2008 fixed midpointrounding (2.5 becomes 3.0 instead of 2.0, default = ToEven)
  774. public LSL_Integer llRound(double f)
  775. {
  776. m_host.AddScriptLPS(1);
  777. return (int)Math.Round(f, MidpointRounding.AwayFromZero);
  778. }
  779. //This next group are vector operations involving squaring and square root. ckrinke
  780. public LSL_Float llVecMag(LSL_Vector v)
  781. {
  782. m_host.AddScriptLPS(1);
  783. return LSL_Vector.Mag(v);
  784. }
  785. public LSL_Vector llVecNorm(LSL_Vector v)
  786. {
  787. m_host.AddScriptLPS(1);
  788. return LSL_Vector.Norm(v);
  789. }
  790. private double VecDist(LSL_Vector a, LSL_Vector b)
  791. {
  792. double dx = a.x - b.x;
  793. double dy = a.y - b.y;
  794. double dz = a.z - b.z;
  795. return Math.Sqrt(dx * dx + dy * dy + dz * dz);
  796. }
  797. public LSL_Float llVecDist(LSL_Vector a, LSL_Vector b)
  798. {
  799. m_host.AddScriptLPS(1);
  800. return VecDist(a, b);
  801. }
  802. //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
  803. // Utility function for llRot2Euler
  804. public LSL_Vector llRot2Euler(LSL_Rotation q1)
  805. {
  806. m_host.AddScriptLPS(1);
  807. LSL_Vector eul = new LSL_Vector();
  808. double sqw = q1.s*q1.s;
  809. double sqx = q1.x*q1.x;
  810. double sqy = q1.z*q1.z;
  811. double sqz = q1.y*q1.y;
  812. double unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
  813. double test = q1.x*q1.z + q1.y*q1.s;
  814. if (test > 0.4999*unit) { // singularity at north pole
  815. eul.z = 2 * Math.Atan2(q1.x,q1.s);
  816. eul.y = Math.PI/2;
  817. eul.x = 0;
  818. return eul;
  819. }
  820. if (test < -0.4999*unit) { // singularity at south pole
  821. eul.z = -2 * Math.Atan2(q1.x,q1.s);
  822. eul.y = -Math.PI/2;
  823. eul.x = 0;
  824. return eul;
  825. }
  826. eul.z = Math.Atan2(2*q1.z*q1.s-2*q1.x*q1.y , sqx - sqy - sqz + sqw);
  827. eul.y = Math.Asin(2*test/unit);
  828. eul.x = Math.Atan2(2*q1.x*q1.s-2*q1.z*q1.y , -sqx + sqy - sqz + sqw);
  829. return eul;
  830. }
  831. public LSL_Rotation llEuler2Rot(LSL_Vector v)
  832. {
  833. m_host.AddScriptLPS(1);
  834. double x,y,z,s;
  835. v.x *= 0.5;
  836. v.y *= 0.5;
  837. v.z *= 0.5;
  838. double c1 = Math.Cos(v.x);
  839. double c2 = Math.Cos(v.y);
  840. double c1c2 = c1 * c2;
  841. double s1 = Math.Sin(v.x);
  842. double s2 = Math.Sin(v.y);
  843. double s1s2 = s1 * s2;
  844. double c1s2 = c1 * s2;
  845. double s1c2 = s1 * c2;
  846. double c3 = Math.Cos(v.z);
  847. double s3 = Math.Sin(v.z);
  848. x = s1c2 * c3 + c1s2 * s3;
  849. y = c1s2 * c3 - s1c2 * s3;
  850. z = s1s2 * c3 + c1c2 * s3;
  851. s = c1c2 * c3 - s1s2 * s3;
  852. return new LSL_Rotation(x, y, z, s);
  853. }
  854. public LSL_Rotation llAxes2Rot(LSL_Vector fwd, LSL_Vector left, LSL_Vector up)
  855. {
  856. m_host.AddScriptLPS(1);
  857. double s;
  858. double tr = fwd.x + left.y + up.z + 1.0;
  859. if (tr >= 1.0)
  860. {
  861. s = 0.5 / Math.Sqrt(tr);
  862. return new LSL_Rotation(
  863. (left.z - up.y) * s,
  864. (up.x - fwd.z) * s,
  865. (fwd.y - left.x) * s,
  866. 0.25 / s);
  867. }
  868. else
  869. {
  870. double max = (left.y > up.z) ? left.y : up.z;
  871. if (max < fwd.x)
  872. {
  873. s = Math.Sqrt(fwd.x - (left.y + up.z) + 1.0);
  874. double x = s * 0.5;
  875. s = 0.5 / s;
  876. return new LSL_Rotation(
  877. x,
  878. (fwd.y + left.x) * s,
  879. (up.x + fwd.z) * s,
  880. (left.z - up.y) * s);
  881. }
  882. else if (max == left.y)
  883. {
  884. s = Math.Sqrt(left.y - (up.z + fwd.x) + 1.0);
  885. double y = s * 0.5;
  886. s = 0.5 / s;
  887. return new LSL_Rotation(
  888. (fwd.y + left.x) * s,
  889. y,
  890. (left.z + up.y) * s,
  891. (up.x - fwd.z) * s);
  892. }
  893. else
  894. {
  895. s = Math.Sqrt(up.z - (fwd.x + left.y) + 1.0);
  896. double z = s * 0.5;
  897. s = 0.5 / s;
  898. return new LSL_Rotation(
  899. (up.x + fwd.z) * s,
  900. (left.z + up.y) * s,
  901. z,
  902. (fwd.y - left.x) * s);
  903. }
  904. }
  905. }
  906. public LSL_Vector llRot2Fwd(LSL_Rotation r)
  907. {
  908. m_host.AddScriptLPS(1);
  909. double x, y, z, m;
  910. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  911. // m is always greater than zero
  912. // if m is not equal to 1 then Rotation needs to be normalized
  913. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  914. {
  915. m = 1.0 / Math.Sqrt(m);
  916. r.x *= m;
  917. r.y *= m;
  918. r.z *= m;
  919. r.s *= m;
  920. }
  921. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  922. x = r.x * r.x - r.y * r.y - r.z * r.z + r.s * r.s;
  923. y = 2 * (r.x * r.y + r.z * r.s);
  924. z = 2 * (r.x * r.z - r.y * r.s);
  925. return (new LSL_Vector(x, y, z));
  926. }
  927. public LSL_Vector llRot2Left(LSL_Rotation r)
  928. {
  929. m_host.AddScriptLPS(1);
  930. double x, y, z, m;
  931. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  932. // m is always greater than zero
  933. // if m is not equal to 1 then Rotation needs to be normalized
  934. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  935. {
  936. m = 1.0 / Math.Sqrt(m);
  937. r.x *= m;
  938. r.y *= m;
  939. r.z *= m;
  940. r.s *= m;
  941. }
  942. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  943. x = 2 * (r.x * r.y - r.z * r.s);
  944. y = -r.x * r.x + r.y * r.y - r.z * r.z + r.s * r.s;
  945. z = 2 * (r.x * r.s + r.y * r.z);
  946. return (new LSL_Vector(x, y, z));
  947. }
  948. public LSL_Vector llRot2Up(LSL_Rotation r)
  949. {
  950. m_host.AddScriptLPS(1);
  951. double x, y, z, m;
  952. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  953. // m is always greater than zero
  954. // if m is not equal to 1 then Rotation needs to be normalized
  955. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  956. {
  957. m = 1.0 / Math.Sqrt(m);
  958. r.x *= m;
  959. r.y *= m;
  960. r.z *= m;
  961. r.s *= m;
  962. }
  963. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  964. x = 2 * (r.x * r.z + r.y * r.s);
  965. y = 2 * (-r.x * r.s + r.y * r.z);
  966. z = -r.x * r.x - r.y * r.y + r.z * r.z + r.s * r.s;
  967. return (new LSL_Vector(x, y, z));
  968. }
  969. public LSL_Rotation llRotBetween(LSL_Vector a, LSL_Vector b)
  970. {
  971. //A and B should both be normalized
  972. m_host.AddScriptLPS(1);
  973. // This method mimics the 180 errors found in SL
  974. // See www.euclideanspace.com... angleBetween
  975. // Eliminate zero length
  976. LSL_Float vec_a_mag = LSL_Vector.MagSquare(a);
  977. LSL_Float vec_b_mag = LSL_Vector.MagSquare(b);
  978. if (vec_a_mag < 1e-12 ||
  979. vec_b_mag < 1e-12)
  980. {
  981. return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  982. }
  983. // Normalize
  984. a = llVecNorm(a);
  985. b = llVecNorm(b);
  986. // Calculate axis and rotation angle
  987. LSL_Vector axis = a % b;
  988. LSL_Float cos_theta = a * b;
  989. // Check if parallel
  990. if (cos_theta > 0.99999)
  991. {
  992. return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  993. }
  994. // Check if anti-parallel
  995. else if (cos_theta < -0.99999)
  996. {
  997. LSL_Vector orthog_axis = new LSL_Vector(1.0, 0.0, 0.0) - (a.x / (a * a) * a);
  998. if (LSL_Vector.MagSquare(orthog_axis) < 1e-12)
  999. orthog_axis = new LSL_Vector(0.0, 0.0, 1.0);
  1000. return new LSL_Rotation((float)orthog_axis.x, (float)orthog_axis.y, (float)orthog_axis.z, 0.0);
  1001. }
  1002. else // other rotation
  1003. {
  1004. LSL_Float theta = (LSL_Float)Math.Acos(cos_theta) * 0.5f;
  1005. axis = llVecNorm(axis);
  1006. double x, y, z, s, t;
  1007. s = Math.Cos(theta);
  1008. t = Math.Sin(theta);
  1009. x = axis.x * t;
  1010. y = axis.y * t;
  1011. z = axis.z * t;
  1012. return new LSL_Rotation(x,y,z,s);
  1013. }
  1014. }
  1015. public void llWhisper(int channelID, string text)
  1016. {
  1017. m_host.AddScriptLPS(1);
  1018. if (text.Length > 1023)
  1019. text = text.Substring(0, 1023);
  1020. byte[] binText = Util.StringToBytesNoTerm(text, 1023);
  1021. World.SimChat(binText,
  1022. ChatTypeEnum.Whisper, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  1023. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1024. if (wComm != null)
  1025. wComm.DeliverMessage(ChatTypeEnum.Whisper, channelID, m_host.Name, m_host.UUID, Util.UTF8.GetString(binText));
  1026. }
  1027. private void CheckSayShoutTime()
  1028. {
  1029. DateTime now = DateTime.UtcNow;
  1030. if ((now - m_lastSayShoutCheck).Ticks > 10000000) // 1sec
  1031. {
  1032. m_lastSayShoutCheck = now;
  1033. m_SayShoutCount = 0;
  1034. }
  1035. else
  1036. m_SayShoutCount++;
  1037. }
  1038. public void llSay(int channelID, string text)
  1039. {
  1040. m_host.AddScriptLPS(1);
  1041. if (channelID == 0)
  1042. // m_SayShoutCount++;
  1043. CheckSayShoutTime();
  1044. if (m_SayShoutCount >= 11)
  1045. ScriptSleep(2000);
  1046. if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel))
  1047. {
  1048. Console.WriteLine(text);
  1049. }
  1050. else
  1051. {
  1052. byte[] binText = Util.StringToBytesNoTerm(text, 1023);
  1053. World.SimChat(binText,
  1054. ChatTypeEnum.Say, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  1055. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1056. if (wComm != null)
  1057. wComm.DeliverMessage(ChatTypeEnum.Say, channelID, m_host.Name, m_host.UUID, Util.UTF8.GetString(binText));
  1058. }
  1059. }
  1060. public void llShout(int channelID, string text)
  1061. {
  1062. m_host.AddScriptLPS(1);
  1063. if (channelID == 0)
  1064. // m_SayShoutCount++;
  1065. CheckSayShoutTime();
  1066. if (m_SayShoutCount >= 11)
  1067. ScriptSleep(2000);
  1068. byte[] binText = Util.StringToBytesNoTerm(text, 1023);
  1069. World.SimChat(binText,
  1070. ChatTypeEnum.Shout, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, true);
  1071. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1072. if (wComm != null)
  1073. wComm.DeliverMessage(ChatTypeEnum.Shout, channelID, m_host.Name, m_host.UUID, Util.UTF8.GetString(binText));
  1074. }
  1075. public void llRegionSay(int channelID, string text)
  1076. {
  1077. if (channelID == 0)
  1078. {
  1079. Error("llRegionSay", "Cannot use on channel 0");
  1080. return;
  1081. }
  1082. byte[] binText = Util.StringToBytesNoTerm(text, 1023);
  1083. m_host.AddScriptLPS(1);
  1084. // debug channel is also sent to avatars
  1085. if (channelID == ScriptBaseClass.DEBUG_CHANNEL)
  1086. {
  1087. World.SimChat(binText,
  1088. ChatTypeEnum.Shout, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  1089. }
  1090. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1091. if (wComm != null)
  1092. wComm.DeliverMessage(ChatTypeEnum.Region, channelID, m_host.Name, m_host.UUID, Util.UTF8.GetString(binText));
  1093. }
  1094. public void llRegionSayTo(string target, int channel, string msg)
  1095. {
  1096. if (msg.Length > 1023)
  1097. msg = msg.Substring(0, 1023);
  1098. m_host.AddScriptLPS(1);
  1099. if (channel == ScriptBaseClass.DEBUG_CHANNEL)
  1100. return;
  1101. UUID.TryParse(target, out UUID TargetID);
  1102. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1103. if (wComm != null)
  1104. wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg);
  1105. }
  1106. public LSL_Integer llListen(int channelID, string name, string ID, string msg)
  1107. {
  1108. m_host.AddScriptLPS(1);
  1109. UUID.TryParse(ID, out UUID keyID);
  1110. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1111. if (wComm != null)
  1112. return wComm.Listen(m_host.LocalId, m_item.ItemID, m_host.UUID, channelID, name, keyID, msg);
  1113. else
  1114. return -1;
  1115. }
  1116. public void llListenControl(int number, int active)
  1117. {
  1118. m_host.AddScriptLPS(1);
  1119. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1120. if (wComm != null)
  1121. wComm.ListenControl(m_item.ItemID, number, active);
  1122. }
  1123. public void llListenRemove(int number)
  1124. {
  1125. m_host.AddScriptLPS(1);
  1126. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1127. if (wComm != null)
  1128. wComm.ListenRemove(m_item.ItemID, number);
  1129. }
  1130. public void llSensor(string name, string id, int type, double range, double arc)
  1131. {
  1132. m_host.AddScriptLPS(1);
  1133. UUID keyID = UUID.Zero;
  1134. UUID.TryParse(id, out keyID);
  1135. m_AsyncCommands.SensorRepeatPlugin.SenseOnce(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, m_host);
  1136. }
  1137. public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
  1138. {
  1139. m_host.AddScriptLPS(1);
  1140. UUID keyID = UUID.Zero;
  1141. UUID.TryParse(id, out keyID);
  1142. m_AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, rate, m_host);
  1143. }
  1144. public void llSensorRemove()
  1145. {
  1146. m_host.AddScriptLPS(1);
  1147. m_AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_host.LocalId, m_item.ItemID);
  1148. }
  1149. public string resolveName(UUID objecUUID)
  1150. {
  1151. // try avatar username surname
  1152. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, objecUUID);
  1153. if (account != null)
  1154. {
  1155. string avatarname = account.Name;
  1156. return avatarname;
  1157. }
  1158. // try an scene object
  1159. SceneObjectPart SOP = World.GetSceneObjectPart(objecUUID);
  1160. if (SOP != null)
  1161. {
  1162. string objectname = SOP.Name;
  1163. return objectname;
  1164. }
  1165. World.Entities.TryGetValue(objecUUID, out EntityBase SensedObject);
  1166. if (SensedObject == null)
  1167. {
  1168. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  1169. if (groups != null)
  1170. {
  1171. GroupRecord gr = groups.GetGroupRecord(objecUUID);
  1172. if (gr != null)
  1173. return gr.GroupName;
  1174. }
  1175. return String.Empty;
  1176. }
  1177. return SensedObject.Name;
  1178. }
  1179. public LSL_String llDetectedName(int number)
  1180. {
  1181. m_host.AddScriptLPS(1);
  1182. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1183. if (detectedParams == null)
  1184. return String.Empty;
  1185. return detectedParams.Name;
  1186. }
  1187. public LSL_Key llDetectedKey(int number)
  1188. {
  1189. m_host.AddScriptLPS(1);
  1190. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1191. if (detectedParams == null)
  1192. return String.Empty;
  1193. return detectedParams.Key.ToString();
  1194. }
  1195. public LSL_Key llDetectedOwner(int number)
  1196. {
  1197. m_host.AddScriptLPS(1);
  1198. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1199. if (detectedParams == null)
  1200. return String.Empty;
  1201. return detectedParams.Owner.ToString();
  1202. }
  1203. public LSL_Integer llDetectedType(int number)
  1204. {
  1205. m_host.AddScriptLPS(1);
  1206. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1207. if (detectedParams == null)
  1208. return 0;
  1209. return new LSL_Integer(detectedParams.Type);
  1210. }
  1211. public LSL_Vector llDetectedPos(int number)
  1212. {
  1213. m_host.AddScriptLPS(1);
  1214. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1215. if (detectedParams == null)
  1216. return new LSL_Vector();
  1217. return detectedParams.Position;
  1218. }
  1219. public LSL_Vector llDetectedVel(int number)
  1220. {
  1221. m_host.AddScriptLPS(1);
  1222. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1223. if (detectedParams == null)
  1224. return new LSL_Vector();
  1225. return detectedParams.Velocity;
  1226. }
  1227. public LSL_Vector llDetectedGrab(int number)
  1228. {
  1229. m_host.AddScriptLPS(1);
  1230. DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1231. if (parms == null)
  1232. return new LSL_Vector(0, 0, 0);
  1233. return parms.OffsetPos;
  1234. }
  1235. public LSL_Rotation llDetectedRot(int number)
  1236. {
  1237. m_host.AddScriptLPS(1);
  1238. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1239. if (detectedParams == null)
  1240. return new LSL_Rotation();
  1241. return detectedParams.Rotation;
  1242. }
  1243. public LSL_Integer llDetectedGroup(int number)
  1244. {
  1245. m_host.AddScriptLPS(1);
  1246. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1247. if (detectedParams == null)
  1248. return new LSL_Integer(0);
  1249. if (m_host.GroupID == detectedParams.Group)
  1250. return new LSL_Integer(1);
  1251. return new LSL_Integer(0);
  1252. }
  1253. public LSL_Integer llDetectedLinkNumber(int number)
  1254. {
  1255. m_host.AddScriptLPS(1);
  1256. DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1257. if (parms == null)
  1258. return new LSL_Integer(0);
  1259. return new LSL_Integer(parms.LinkNum);
  1260. }
  1261. /// <summary>
  1262. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchBinormal for details
  1263. /// </summary>
  1264. public LSL_Vector llDetectedTouchBinormal(int index)
  1265. {
  1266. m_host.AddScriptLPS(1);
  1267. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1268. if (detectedParams == null)
  1269. return new LSL_Vector();
  1270. return detectedParams.TouchBinormal;
  1271. }
  1272. /// <summary>
  1273. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchFace for details
  1274. /// </summary>
  1275. public LSL_Integer llDetectedTouchFace(int index)
  1276. {
  1277. m_host.AddScriptLPS(1);
  1278. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1279. if (detectedParams == null)
  1280. return new LSL_Integer(-1);
  1281. return new LSL_Integer(detectedParams.TouchFace);
  1282. }
  1283. /// <summary>
  1284. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchNormal for details
  1285. /// </summary>
  1286. public LSL_Vector llDetectedTouchNormal(int index)
  1287. {
  1288. m_host.AddScriptLPS(1);
  1289. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1290. if (detectedParams == null)
  1291. return new LSL_Vector();
  1292. return detectedParams.TouchNormal;
  1293. }
  1294. /// <summary>
  1295. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchPos for details
  1296. /// </summary>
  1297. public LSL_Vector llDetectedTouchPos(int index)
  1298. {
  1299. m_host.AddScriptLPS(1);
  1300. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1301. if (detectedParams == null)
  1302. return new LSL_Vector();
  1303. return detectedParams.TouchPos;
  1304. }
  1305. /// <summary>
  1306. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchST for details
  1307. /// </summary>
  1308. public LSL_Vector llDetectedTouchST(int index)
  1309. {
  1310. m_host.AddScriptLPS(1);
  1311. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1312. if (detectedParams == null)
  1313. return new LSL_Vector(-1.0, -1.0, 0.0);
  1314. return detectedParams.TouchST;
  1315. }
  1316. /// <summary>
  1317. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchUV for details
  1318. /// </summary>
  1319. public LSL_Vector llDetectedTouchUV(int index)
  1320. {
  1321. m_host.AddScriptLPS(1);
  1322. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1323. if (detectedParams == null)
  1324. return new LSL_Vector(-1.0, -1.0, 0.0);
  1325. return detectedParams.TouchUV;
  1326. }
  1327. [DebuggerNonUserCode]
  1328. public virtual void llDie()
  1329. {
  1330. m_host.AddScriptLPS(1);
  1331. if (!m_host.ParentGroup.IsAttachment) throw new SelfDeleteException();
  1332. }
  1333. public LSL_Float llGround(LSL_Vector offset)
  1334. {
  1335. m_host.AddScriptLPS(1);
  1336. Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
  1337. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  1338. LSL_Vector vsn = llGroundNormal(offset);
  1339. // Clamp to valid position
  1340. if (pos.X < 0)
  1341. pos.X = 0;
  1342. else if (pos.X >= World.Heightmap.Width)
  1343. pos.X = World.Heightmap.Width - 1;
  1344. if (pos.Y < 0)
  1345. pos.Y = 0;
  1346. else if (pos.Y >= World.Heightmap.Height)
  1347. pos.Y = World.Heightmap.Height - 1;
  1348. //Get the height for the integer coordinates from the Heightmap
  1349. float baseheight = (float)World.Heightmap[(int)pos.X, (int)pos.Y];
  1350. //Calculate the difference between the actual coordinates and the integer coordinates
  1351. float xdiff = pos.X - (float)((int)pos.X);
  1352. float ydiff = pos.Y - (float)((int)pos.Y);
  1353. //Use the equation of the tangent plane to adjust the height to account for slope
  1354. return (((vsn.x * xdiff) + (vsn.y * ydiff)) / (-1 * vsn.z)) + baseheight;
  1355. }
  1356. public LSL_Float llCloud(LSL_Vector offset)
  1357. {
  1358. m_host.AddScriptLPS(1);
  1359. float cloudCover = 0f;
  1360. ICloudModule module = World.RequestModuleInterface<ICloudModule>();
  1361. if (module != null)
  1362. {
  1363. Vector3 pos = m_host.GetWorldPosition();
  1364. int x = (int)(pos.X + offset.x);
  1365. int y = (int)(pos.Y + offset.y);
  1366. cloudCover = module.CloudCover(x, y, 0);
  1367. }
  1368. return cloudCover;
  1369. }
  1370. public LSL_Vector llWind(LSL_Vector offset)
  1371. {
  1372. m_host.AddScriptLPS(1);
  1373. LSL_Vector wind = new LSL_Vector(0, 0, 0);
  1374. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1375. if (module != null)
  1376. {
  1377. Vector3 pos = m_host.GetWorldPosition();
  1378. int x = (int)(pos.X + offset.x);
  1379. int y = (int)(pos.Y + offset.y);
  1380. Vector3 windSpeed = module.WindSpeed(x, y, 0);
  1381. wind.x = windSpeed.X;
  1382. wind.y = windSpeed.Y;
  1383. }
  1384. return wind;
  1385. }
  1386. public void llSetStatus(int status, int value)
  1387. {
  1388. if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
  1389. return;
  1390. m_host.AddScriptLPS(1);
  1391. int statusrotationaxis = 0;
  1392. if ((status & ScriptBaseClass.STATUS_PHYSICS) == ScriptBaseClass.STATUS_PHYSICS)
  1393. {
  1394. if (value != 0)
  1395. {
  1396. SceneObjectGroup group = m_host.ParentGroup;
  1397. bool allow = true;
  1398. int maxprims = World.m_linksetPhysCapacity;
  1399. bool checkShape = (maxprims > 0 && group.PrimCount > maxprims);
  1400. foreach (SceneObjectPart part in group.Parts)
  1401. {
  1402. if (part.PhysicsShapeType == (byte)PhysicsShapeType.None)
  1403. continue;
  1404. if (part.Scale.X > World.m_maxPhys || part.Scale.Y > World.m_maxPhys || part.Scale.Z > World.m_maxPhys)
  1405. {
  1406. allow = false;
  1407. break;
  1408. }
  1409. if (checkShape)
  1410. {
  1411. if (--maxprims < 0)
  1412. {
  1413. allow = false;
  1414. break;
  1415. }
  1416. }
  1417. }
  1418. if (!allow)
  1419. return;
  1420. if (m_host.ParentGroup.RootPart.PhysActor != null &&
  1421. m_host.ParentGroup.RootPart.PhysActor.IsPhysical)
  1422. return;
  1423. m_host.ScriptSetPhysicsStatus(true);
  1424. }
  1425. else
  1426. {
  1427. m_host.ScriptSetPhysicsStatus(false);
  1428. }
  1429. }
  1430. if ((status & ScriptBaseClass.STATUS_PHANTOM) == ScriptBaseClass.STATUS_PHANTOM)
  1431. {
  1432. m_host.ParentGroup.ScriptSetPhantomStatus(value != 0);
  1433. }
  1434. if ((status & ScriptBaseClass.STATUS_CAST_SHADOWS) == ScriptBaseClass.STATUS_CAST_SHADOWS)
  1435. {
  1436. m_host.AddFlag(PrimFlags.CastShadows);
  1437. }
  1438. if ((status & ScriptBaseClass.STATUS_ROTATE_X) == ScriptBaseClass.STATUS_ROTATE_X)
  1439. {
  1440. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_X;
  1441. }
  1442. if ((status & ScriptBaseClass.STATUS_ROTATE_Y) == ScriptBaseClass.STATUS_ROTATE_Y)
  1443. {
  1444. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Y;
  1445. }
  1446. if ((status & ScriptBaseClass.STATUS_ROTATE_Z) == ScriptBaseClass.STATUS_ROTATE_Z)
  1447. {
  1448. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Z;
  1449. }
  1450. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB) == ScriptBaseClass.STATUS_BLOCK_GRAB)
  1451. m_host.BlockGrab = value != 0;
  1452. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT) == ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT)
  1453. m_host.ParentGroup.BlockGrabOverride = value != 0;
  1454. if ((status & ScriptBaseClass.STATUS_DIE_AT_EDGE) == ScriptBaseClass.STATUS_DIE_AT_EDGE)
  1455. {
  1456. if (value != 0)
  1457. m_host.SetDieAtEdge(true);
  1458. else
  1459. m_host.SetDieAtEdge(false);
  1460. }
  1461. if ((status & ScriptBaseClass.STATUS_RETURN_AT_EDGE) == ScriptBaseClass.STATUS_RETURN_AT_EDGE)
  1462. {
  1463. if (value != 0)
  1464. m_host.SetReturnAtEdge(true);
  1465. else
  1466. m_host.SetReturnAtEdge(false);
  1467. }
  1468. if ((status & ScriptBaseClass.STATUS_SANDBOX) == ScriptBaseClass.STATUS_SANDBOX)
  1469. {
  1470. if (value != 0)
  1471. m_host.SetStatusSandbox(true);
  1472. else
  1473. m_host.SetStatusSandbox(false);
  1474. }
  1475. if (statusrotationaxis != 0)
  1476. {
  1477. m_host.SetAxisRotation(statusrotationaxis, value);
  1478. }
  1479. }
  1480. private bool IsPhysical()
  1481. {
  1482. return ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) == (uint)PrimFlags.Physics);
  1483. }
  1484. public LSL_Integer llGetStatus(int status)
  1485. {
  1486. m_host.AddScriptLPS(1);
  1487. // m_log.Debug(m_host.ToString() + " status is " + m_host.GetEffectiveObjectFlags().ToString());
  1488. switch (status)
  1489. {
  1490. case ScriptBaseClass.STATUS_PHYSICS:
  1491. return IsPhysical() ? 1 : 0;
  1492. case ScriptBaseClass.STATUS_PHANTOM:
  1493. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) == (uint)PrimFlags.Phantom)
  1494. {
  1495. return 1;
  1496. }
  1497. return 0;
  1498. case ScriptBaseClass.STATUS_CAST_SHADOWS:
  1499. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.CastShadows) == (uint)PrimFlags.CastShadows)
  1500. {
  1501. return 1;
  1502. }
  1503. return 0;
  1504. case ScriptBaseClass.STATUS_BLOCK_GRAB:
  1505. return m_host.BlockGrab ? 1 : 0;
  1506. case ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT:
  1507. return m_host.ParentGroup.BlockGrabOverride ? 1 : 0;
  1508. case ScriptBaseClass.STATUS_DIE_AT_EDGE:
  1509. if (m_host.GetDieAtEdge())
  1510. return 1;
  1511. else
  1512. return 0;
  1513. case ScriptBaseClass.STATUS_RETURN_AT_EDGE:
  1514. if (m_host.GetReturnAtEdge())
  1515. return 1;
  1516. else
  1517. return 0;
  1518. case ScriptBaseClass.STATUS_ROTATE_X:
  1519. // if (m_host.GetAxisRotation(2) != 0)
  1520. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) != 0)
  1521. return 1;
  1522. else
  1523. return 0;
  1524. case ScriptBaseClass.STATUS_ROTATE_Y:
  1525. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) != 0)
  1526. return 1;
  1527. else
  1528. return 0;
  1529. case ScriptBaseClass.STATUS_ROTATE_Z:
  1530. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) != 0)
  1531. return 1;
  1532. else
  1533. return 0;
  1534. case ScriptBaseClass.STATUS_SANDBOX:
  1535. if (m_host.GetStatusSandbox())
  1536. return 1;
  1537. else
  1538. return 0;
  1539. }
  1540. return 0;
  1541. }
  1542. public LSL_Integer llScaleByFactor(double scaling_factor)
  1543. {
  1544. m_host.AddScriptLPS(1);
  1545. SceneObjectGroup group = m_host.ParentGroup;
  1546. if(scaling_factor < 1e-6)
  1547. return ScriptBaseClass.FALSE;
  1548. if(scaling_factor > 1e6)
  1549. return ScriptBaseClass.FALSE;
  1550. if (group == null || group.IsDeleted || group.inTransit)
  1551. return ScriptBaseClass.FALSE;
  1552. if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
  1553. return ScriptBaseClass.FALSE;
  1554. if (group.RootPart.KeyframeMotion != null)
  1555. return ScriptBaseClass.FALSE;
  1556. if(group.GroupResize(scaling_factor))
  1557. return ScriptBaseClass.TRUE;
  1558. else
  1559. return ScriptBaseClass.FALSE;
  1560. }
  1561. public LSL_Float llGetMaxScaleFactor()
  1562. {
  1563. m_host.AddScriptLPS(1);
  1564. SceneObjectGroup group = m_host.ParentGroup;
  1565. if (group == null || group.IsDeleted || group.inTransit)
  1566. return 1.0f;
  1567. return (LSL_Float)group.GetMaxGroupResizeScale();
  1568. }
  1569. public LSL_Float llGetMinScaleFactor()
  1570. {
  1571. m_host.AddScriptLPS(1);
  1572. SceneObjectGroup group = m_host.ParentGroup;
  1573. if (group == null || group.IsDeleted || group.inTransit)
  1574. return 1.0f;
  1575. return (LSL_Float)group.GetMinGroupResizeScale();
  1576. }
  1577. public void llSetScale(LSL_Vector scale)
  1578. {
  1579. m_host.AddScriptLPS(1);
  1580. SetScale(m_host, scale);
  1581. }
  1582. protected void SetScale(SceneObjectPart part, LSL_Vector scale)
  1583. {
  1584. // TODO: this needs to trigger a persistance save as well
  1585. if (part == null || part.ParentGroup.IsDeleted)
  1586. return;
  1587. // First we need to check whether or not we need to clamp the size of a physics-enabled prim
  1588. PhysicsActor pa = part.ParentGroup.RootPart.PhysActor;
  1589. if (pa != null && pa.IsPhysical)
  1590. {
  1591. scale.x = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.x));
  1592. scale.y = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.y));
  1593. scale.z = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.z));
  1594. }
  1595. else
  1596. {
  1597. // If not physical, then we clamp the scale to the non-physical min/max
  1598. scale.x = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.x));
  1599. scale.y = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.y));
  1600. scale.z = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.z));
  1601. }
  1602. Vector3 tmp = part.Scale;
  1603. tmp.X = (float)scale.x;
  1604. tmp.Y = (float)scale.y;
  1605. tmp.Z = (float)scale.z;
  1606. part.Scale = tmp;
  1607. part.ParentGroup.HasGroupChanged = true;
  1608. part.SendFullUpdateToAllClients();
  1609. }
  1610. public LSL_Vector llGetScale()
  1611. {
  1612. m_host.AddScriptLPS(1);
  1613. return new LSL_Vector(m_host.Scale.X, m_host.Scale.Y, m_host.Scale.Z);
  1614. }
  1615. public void llSetClickAction(int action)
  1616. {
  1617. m_host.AddScriptLPS(1);
  1618. m_host.ClickAction = (byte)action;
  1619. m_host.ParentGroup.HasGroupChanged = true;
  1620. m_host.ScheduleFullUpdate();
  1621. return;
  1622. }
  1623. public void llSetColor(LSL_Vector color, int face)
  1624. {
  1625. m_host.AddScriptLPS(1);
  1626. SetColor(m_host, color, face);
  1627. }
  1628. protected void SetColor(SceneObjectPart part, LSL_Vector color, int face)
  1629. {
  1630. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1631. return;
  1632. m_host.SetFaceColorAlpha(face, color, null);
  1633. }
  1634. public void llSetContentType(LSL_Key reqid, LSL_Integer type)
  1635. {
  1636. m_host.AddScriptLPS(1);
  1637. if (m_UrlModule == null)
  1638. return;
  1639. if(!UUID.TryParse(reqid, out UUID id))
  1640. return;
  1641. // Make sure the content type is text/plain to start with
  1642. m_UrlModule.HttpContentType(id, "text/plain");
  1643. // Is the object owner online and in the region
  1644. ScenePresence agent = World.GetScenePresence(m_host.ParentGroup.OwnerID);
  1645. if (agent == null || agent.IsChildAgent || agent.IsDeleted)
  1646. return; // Fail if the owner is not in the same region
  1647. // Is it the embeded browser?
  1648. string userAgent = m_UrlModule.GetHttpHeader(id, "user-agent");
  1649. if(string.IsNullOrEmpty(userAgent))
  1650. return;
  1651. if (userAgent.IndexOf("SecondLife") < 0)
  1652. return; // Not the embedded browser
  1653. // Use the IP address of the client and check against the request
  1654. // seperate logins from the same IP will allow all of them to get non-text/plain as long
  1655. // as the owner is in the region. Same as SL!
  1656. string logonFromIPAddress = agent.ControllingClient.RemoteEndPoint.Address.ToString();
  1657. if (string.IsNullOrEmpty(logonFromIPAddress))
  1658. return;
  1659. string requestFromIPAddress = m_UrlModule.GetHttpHeader(id, "x-remote-ip");
  1660. //m_log.Debug("IP from header='" + requestFromIPAddress + "' IP from endpoint='" + logonFromIPAddress + "'");
  1661. if (requestFromIPAddress == null)
  1662. return;
  1663. requestFromIPAddress = requestFromIPAddress.Trim();
  1664. // If the request isnt from the same IP address then the request cannot be from the owner
  1665. if (!requestFromIPAddress.Equals(logonFromIPAddress))
  1666. return;
  1667. switch (type)
  1668. {
  1669. case ScriptBaseClass.CONTENT_TYPE_HTML:
  1670. m_UrlModule.HttpContentType(new UUID(id), "text/html");
  1671. break;
  1672. case ScriptBaseClass.CONTENT_TYPE_XML:
  1673. m_UrlModule.HttpContentType(new UUID(id), "application/xml");
  1674. break;
  1675. case ScriptBaseClass.CONTENT_TYPE_XHTML:
  1676. m_UrlModule.HttpContentType(new UUID(id), "application/xhtml+xml");
  1677. break;
  1678. case ScriptBaseClass.CONTENT_TYPE_ATOM:
  1679. m_UrlModule.HttpContentType(new UUID(id), "application/atom+xml");
  1680. break;
  1681. case ScriptBaseClass.CONTENT_TYPE_JSON:
  1682. m_UrlModule.HttpContentType(new UUID(id), "application/json");
  1683. break;
  1684. case ScriptBaseClass.CONTENT_TYPE_LLSD:
  1685. m_UrlModule.HttpContentType(new UUID(id), "application/llsd+xml");
  1686. break;
  1687. case ScriptBaseClass.CONTENT_TYPE_FORM:
  1688. m_UrlModule.HttpContentType(new UUID(id), "application/x-www-form-urlencoded");
  1689. break;
  1690. case ScriptBaseClass.CONTENT_TYPE_RSS:
  1691. m_UrlModule.HttpContentType(new UUID(id), "application/rss+xml");
  1692. break;
  1693. default:
  1694. m_UrlModule.HttpContentType(new UUID(id), "text/plain");
  1695. break;
  1696. }
  1697. }
  1698. public void SetTexGen(SceneObjectPart part, int face,int style)
  1699. {
  1700. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1701. return;
  1702. Primitive.TextureEntry tex = part.Shape.Textures;
  1703. MappingType textype;
  1704. textype = MappingType.Default;
  1705. if (style == (int)ScriptBaseClass.PRIM_TEXGEN_PLANAR)
  1706. textype = MappingType.Planar;
  1707. int nsides = GetNumberOfSides(part);
  1708. if (face >= 0 && face < nsides)
  1709. {
  1710. tex.CreateFace((uint) face);
  1711. tex.FaceTextures[face].TexMapType = textype;
  1712. part.UpdateTextureEntry(tex);
  1713. return;
  1714. }
  1715. else if (face == ScriptBaseClass.ALL_SIDES)
  1716. {
  1717. for (uint i = 0; i < nsides; i++)
  1718. {
  1719. if (tex.FaceTextures[i] != null)
  1720. {
  1721. tex.FaceTextures[i].TexMapType = textype;
  1722. }
  1723. }
  1724. tex.DefaultTexture.TexMapType = textype;
  1725. part.UpdateTextureEntry(tex);
  1726. return;
  1727. }
  1728. }
  1729. public void SetGlow(SceneObjectPart part, int face, float glow)
  1730. {
  1731. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1732. return;
  1733. Primitive.TextureEntry tex = part.Shape.Textures;
  1734. int nsides = GetNumberOfSides(part);
  1735. if (face >= 0 && face < nsides)
  1736. {
  1737. tex.CreateFace((uint) face);
  1738. tex.FaceTextures[face].Glow = glow;
  1739. part.UpdateTextureEntry(tex);
  1740. return;
  1741. }
  1742. else if (face == ScriptBaseClass.ALL_SIDES)
  1743. {
  1744. for (uint i = 0; i < nsides; i++)
  1745. {
  1746. if (tex.FaceTextures[i] != null)
  1747. {
  1748. tex.FaceTextures[i].Glow = glow;
  1749. }
  1750. }
  1751. tex.DefaultTexture.Glow = glow;
  1752. part.UpdateTextureEntry(tex);
  1753. return;
  1754. }
  1755. }
  1756. public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump)
  1757. {
  1758. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1759. return;
  1760. Shininess sval = new Shininess();
  1761. switch (shiny)
  1762. {
  1763. case 0:
  1764. sval = Shininess.None;
  1765. break;
  1766. case 1:
  1767. sval = Shininess.Low;
  1768. break;
  1769. case 2:
  1770. sval = Shininess.Medium;
  1771. break;
  1772. case 3:
  1773. sval = Shininess.High;
  1774. break;
  1775. default:
  1776. sval = Shininess.None;
  1777. break;
  1778. }
  1779. int nsides = GetNumberOfSides(part);
  1780. Primitive.TextureEntry tex = part.Shape.Textures;
  1781. if (face >= 0 && face < nsides)
  1782. {
  1783. tex.CreateFace((uint) face);
  1784. tex.FaceTextures[face].Shiny = sval;
  1785. tex.FaceTextures[face].Bump = bump;
  1786. part.UpdateTextureEntry(tex);
  1787. return;
  1788. }
  1789. else if (face == ScriptBaseClass.ALL_SIDES)
  1790. {
  1791. for (uint i = 0; i < nsides; i++)
  1792. {
  1793. if (tex.FaceTextures[i] != null)
  1794. {
  1795. tex.FaceTextures[i].Shiny = sval;
  1796. tex.FaceTextures[i].Bump = bump;
  1797. }
  1798. }
  1799. tex.DefaultTexture.Shiny = sval;
  1800. tex.DefaultTexture.Bump = bump;
  1801. part.UpdateTextureEntry(tex);
  1802. return;
  1803. }
  1804. }
  1805. public void SetFullBright(SceneObjectPart part, int face, bool bright)
  1806. {
  1807. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1808. return;
  1809. int nsides = GetNumberOfSides(part);
  1810. Primitive.TextureEntry tex = part.Shape.Textures;
  1811. if (face >= 0 && face < nsides)
  1812. {
  1813. tex.CreateFace((uint) face);
  1814. tex.FaceTextures[face].Fullbright = bright;
  1815. part.UpdateTextureEntry(tex);
  1816. return;
  1817. }
  1818. else if (face == ScriptBaseClass.ALL_SIDES)
  1819. {
  1820. for (uint i = 0; i < nsides; i++)
  1821. {
  1822. if (tex.FaceTextures[i] != null)
  1823. {
  1824. tex.FaceTextures[i].Fullbright = bright;
  1825. }
  1826. }
  1827. tex.DefaultTexture.Fullbright = bright;
  1828. part.UpdateTextureEntry(tex);
  1829. return;
  1830. }
  1831. }
  1832. public LSL_Float llGetAlpha(int face)
  1833. {
  1834. m_host.AddScriptLPS(1);
  1835. return GetAlpha(m_host, face);
  1836. }
  1837. protected LSL_Float GetAlpha(SceneObjectPart part, int face)
  1838. {
  1839. Primitive.TextureEntry tex = part.Shape.Textures;
  1840. int nsides = GetNumberOfSides(part);
  1841. if (face == ScriptBaseClass.ALL_SIDES)
  1842. {
  1843. int i;
  1844. double sum = 0.0;
  1845. for (i = 0 ; i < nsides; i++)
  1846. sum += (double)tex.GetFace((uint)i).RGBA.A;
  1847. return sum;
  1848. }
  1849. if (face >= 0 && face < nsides)
  1850. {
  1851. return (double)tex.GetFace((uint)face).RGBA.A;
  1852. }
  1853. return 0.0;
  1854. }
  1855. public void llSetAlpha(double alpha, int face)
  1856. {
  1857. m_host.AddScriptLPS(1);
  1858. SetAlpha(m_host, alpha, face);
  1859. }
  1860. public void llSetLinkAlpha(int linknumber, double alpha, int face)
  1861. {
  1862. m_host.AddScriptLPS(1);
  1863. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  1864. if (parts.Count > 0)
  1865. {
  1866. try
  1867. {
  1868. foreach (SceneObjectPart part in parts)
  1869. SetAlpha(part, alpha, face);
  1870. }
  1871. finally { }
  1872. }
  1873. }
  1874. protected void SetAlpha(SceneObjectPart part, double alpha, int face)
  1875. {
  1876. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1877. return;
  1878. Primitive.TextureEntry tex = part.Shape.Textures;
  1879. int nsides = GetNumberOfSides(part);
  1880. Color4 texcolor;
  1881. if (face >= 0 && face < nsides)
  1882. {
  1883. texcolor = tex.CreateFace((uint)face).RGBA;
  1884. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1885. tex.FaceTextures[face].RGBA = texcolor;
  1886. part.UpdateTextureEntry(tex);
  1887. return;
  1888. }
  1889. else if (face == ScriptBaseClass.ALL_SIDES)
  1890. {
  1891. for (int i = 0; i < nsides; i++)
  1892. {
  1893. if (tex.FaceTextures[i] != null)
  1894. {
  1895. texcolor = tex.FaceTextures[i].RGBA;
  1896. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1897. tex.FaceTextures[i].RGBA = texcolor;
  1898. }
  1899. }
  1900. // In some cases, the default texture can be null, eg when every face
  1901. // has a unique texture
  1902. if (tex.DefaultTexture != null)
  1903. {
  1904. texcolor = tex.DefaultTexture.RGBA;
  1905. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1906. tex.DefaultTexture.RGBA = texcolor;
  1907. }
  1908. part.UpdateTextureEntry(tex);
  1909. return;
  1910. }
  1911. }
  1912. /// <summary>
  1913. /// Set flexi parameters of a part.
  1914. ///
  1915. /// FIXME: Much of this code should probably be within the part itself.
  1916. /// </summary>
  1917. /// <param name="part"></param>
  1918. /// <param name="flexi"></param>
  1919. /// <param name="softness"></param>
  1920. /// <param name="gravity"></param>
  1921. /// <param name="friction"></param>
  1922. /// <param name="wind"></param>
  1923. /// <param name="tension"></param>
  1924. /// <param name="Force"></param>
  1925. protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
  1926. float wind, float tension, LSL_Vector Force)
  1927. {
  1928. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1929. return;
  1930. if (flexi)
  1931. {
  1932. part.Shape.FlexiEntry = true; // this setting flexi true isn't working, but the below parameters do
  1933. // work once the prim is already flexi
  1934. part.Shape.FlexiSoftness = softness;
  1935. part.Shape.FlexiGravity = gravity;
  1936. part.Shape.FlexiDrag = friction;
  1937. part.Shape.FlexiWind = wind;
  1938. part.Shape.FlexiTension = tension;
  1939. part.Shape.FlexiForceX = (float)Force.x;
  1940. part.Shape.FlexiForceY = (float)Force.y;
  1941. part.Shape.FlexiForceZ = (float)Force.z;
  1942. part.Shape.PathCurve = (byte)Extrusion.Flexible;
  1943. }
  1944. else
  1945. {
  1946. // Other values not set, they do not seem to be sent to the viewer
  1947. // Setting PathCurve appears to be what actually toggles the check box and turns Flexi on and off
  1948. part.Shape.PathCurve = (byte)Extrusion.Straight;
  1949. part.Shape.FlexiEntry = false;
  1950. }
  1951. part.ParentGroup.HasGroupChanged = true;
  1952. part.ScheduleFullUpdate();
  1953. }
  1954. /// <summary>
  1955. /// Set a light point on a part
  1956. /// </summary>
  1957. /// FIXME: Much of this code should probably be in SceneObjectGroup
  1958. ///
  1959. /// <param name="part"></param>
  1960. /// <param name="light"></param>
  1961. /// <param name="color"></param>
  1962. /// <param name="intensity"></param>
  1963. /// <param name="radius"></param>
  1964. /// <param name="falloff"></param>
  1965. protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
  1966. {
  1967. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1968. return;
  1969. if (light)
  1970. {
  1971. part.Shape.LightEntry = true;
  1972. part.Shape.LightColorR = Util.Clip((float)color.x, 0.0f, 1.0f);
  1973. part.Shape.LightColorG = Util.Clip((float)color.y, 0.0f, 1.0f);
  1974. part.Shape.LightColorB = Util.Clip((float)color.z, 0.0f, 1.0f);
  1975. part.Shape.LightIntensity = Util.Clip((float)intensity, 0.0f, 1.0f);
  1976. part.Shape.LightRadius = Util.Clip((float)radius, 0.1f, 20.0f);
  1977. part.Shape.LightFalloff = Util.Clip((float)falloff, 0.01f, 2.0f);
  1978. }
  1979. else
  1980. {
  1981. part.Shape.LightEntry = false;
  1982. }
  1983. part.ParentGroup.HasGroupChanged = true;
  1984. part.ScheduleFullUpdate();
  1985. }
  1986. public LSL_Vector llGetColor(int face)
  1987. {
  1988. m_host.AddScriptLPS(1);
  1989. return GetColor(m_host, face);
  1990. }
  1991. protected LSL_Vector GetColor(SceneObjectPart part, int face)
  1992. {
  1993. Primitive.TextureEntry tex = part.Shape.Textures;
  1994. Color4 texcolor;
  1995. LSL_Vector rgb = new LSL_Vector();
  1996. int nsides = GetNumberOfSides(part);
  1997. if (face == ScriptBaseClass.ALL_SIDES)
  1998. {
  1999. int i;
  2000. for (i = 0; i < nsides; i++)
  2001. {
  2002. texcolor = tex.GetFace((uint)i).RGBA;
  2003. rgb.x += texcolor.R;
  2004. rgb.y += texcolor.G;
  2005. rgb.z += texcolor.B;
  2006. }
  2007. float invnsides = 1.0f / (float)nsides;
  2008. rgb.x *= invnsides;
  2009. rgb.y *= invnsides;
  2010. rgb.z *= invnsides;
  2011. return rgb;
  2012. }
  2013. if (face >= 0 && face < nsides)
  2014. {
  2015. texcolor = tex.GetFace((uint)face).RGBA;
  2016. rgb.x = texcolor.R;
  2017. rgb.y = texcolor.G;
  2018. rgb.z = texcolor.B;
  2019. return rgb;
  2020. }
  2021. else
  2022. {
  2023. return new LSL_Vector();
  2024. }
  2025. }
  2026. public void llSetTexture(string texture, int face)
  2027. {
  2028. m_host.AddScriptLPS(1);
  2029. SetTexture(m_host, texture, face);
  2030. ScriptSleep(m_sleepMsOnSetTexture);
  2031. }
  2032. public void llSetLinkTexture(int linknumber, string texture, int face)
  2033. {
  2034. m_host.AddScriptLPS(1);
  2035. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  2036. if (parts.Count > 0)
  2037. {
  2038. try
  2039. {
  2040. foreach (SceneObjectPart part in parts)
  2041. SetTexture(part, texture, face);
  2042. }
  2043. finally { }
  2044. }
  2045. ScriptSleep(m_sleepMsOnSetLinkTexture);
  2046. }
  2047. protected void SetTextureParams(SceneObjectPart part, string texture, double scaleU, double ScaleV,
  2048. double offsetU, double offsetV, double rotation, int face)
  2049. {
  2050. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2051. return;
  2052. UUID textureID = new UUID();
  2053. bool dotexture = true;
  2054. if(String.IsNullOrEmpty(texture) || texture == ScriptBaseClass.NULL_KEY)
  2055. dotexture = false;
  2056. else
  2057. {
  2058. textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture);
  2059. if (textureID == UUID.Zero)
  2060. {
  2061. if (!UUID.TryParse(texture, out textureID))
  2062. dotexture = false;
  2063. }
  2064. }
  2065. Primitive.TextureEntry tex = part.Shape.Textures;
  2066. int nsides = GetNumberOfSides(part);
  2067. if (face >= 0 && face < nsides)
  2068. {
  2069. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2070. if (dotexture)
  2071. texface.TextureID = textureID;
  2072. texface.RepeatU = (float)scaleU;
  2073. texface.RepeatV = (float)ScaleV;
  2074. texface.OffsetU = (float)offsetU;
  2075. texface.OffsetV = (float)offsetV;
  2076. texface.Rotation = (float)rotation;
  2077. tex.FaceTextures[face] = texface;
  2078. part.UpdateTextureEntry(tex);
  2079. return;
  2080. }
  2081. else if (face == ScriptBaseClass.ALL_SIDES)
  2082. {
  2083. for (uint i = 0; i < nsides; i++)
  2084. {
  2085. if (tex.FaceTextures[i] != null)
  2086. {
  2087. if (dotexture)
  2088. tex.FaceTextures[i].TextureID = textureID;
  2089. tex.FaceTextures[i].RepeatU = (float)scaleU;
  2090. tex.FaceTextures[i].RepeatV = (float)ScaleV;
  2091. tex.FaceTextures[i].OffsetU = (float)offsetU;
  2092. tex.FaceTextures[i].OffsetV = (float)offsetV;
  2093. tex.FaceTextures[i].Rotation = (float)rotation;
  2094. }
  2095. }
  2096. if (dotexture)
  2097. tex.DefaultTexture.TextureID = textureID;
  2098. tex.DefaultTexture.RepeatU = (float)scaleU;
  2099. tex.DefaultTexture.RepeatV = (float)ScaleV;
  2100. tex.DefaultTexture.OffsetU = (float)offsetU;
  2101. tex.DefaultTexture.OffsetV = (float)offsetV;
  2102. tex.DefaultTexture.Rotation = (float)rotation;
  2103. part.UpdateTextureEntry(tex);
  2104. return;
  2105. }
  2106. }
  2107. protected void SetTexture(SceneObjectPart part, string texture, int face)
  2108. {
  2109. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2110. return;
  2111. UUID textureID = new UUID();
  2112. textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture);
  2113. if (textureID == UUID.Zero)
  2114. {
  2115. if (!UUID.TryParse(texture, out textureID))
  2116. return;
  2117. }
  2118. Primitive.TextureEntry tex = part.Shape.Textures;
  2119. int nsides = GetNumberOfSides(part);
  2120. if (face >= 0 && face < nsides)
  2121. {
  2122. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2123. texface.TextureID = textureID;
  2124. tex.FaceTextures[face] = texface;
  2125. part.UpdateTextureEntry(tex);
  2126. return;
  2127. }
  2128. else if (face == ScriptBaseClass.ALL_SIDES)
  2129. {
  2130. for (uint i = 0; i < nsides; i++)
  2131. {
  2132. if (tex.FaceTextures[i] != null)
  2133. {
  2134. tex.FaceTextures[i].TextureID = textureID;
  2135. }
  2136. }
  2137. tex.DefaultTexture.TextureID = textureID;
  2138. part.UpdateTextureEntry(tex);
  2139. return;
  2140. }
  2141. }
  2142. public void llScaleTexture(double u, double v, int face)
  2143. {
  2144. m_host.AddScriptLPS(1);
  2145. ScaleTexture(m_host, u, v, face);
  2146. ScriptSleep(m_sleepMsOnScaleTexture);
  2147. }
  2148. protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
  2149. {
  2150. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2151. return;
  2152. Primitive.TextureEntry tex = part.Shape.Textures;
  2153. int nsides = GetNumberOfSides(part);
  2154. if (face >= 0 && face < nsides)
  2155. {
  2156. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2157. texface.RepeatU = (float)u;
  2158. texface.RepeatV = (float)v;
  2159. tex.FaceTextures[face] = texface;
  2160. part.UpdateTextureEntry(tex);
  2161. return;
  2162. }
  2163. if (face == ScriptBaseClass.ALL_SIDES)
  2164. {
  2165. for (int i = 0; i < nsides; i++)
  2166. {
  2167. if (tex.FaceTextures[i] != null)
  2168. {
  2169. tex.FaceTextures[i].RepeatU = (float)u;
  2170. tex.FaceTextures[i].RepeatV = (float)v;
  2171. }
  2172. }
  2173. tex.DefaultTexture.RepeatU = (float)u;
  2174. tex.DefaultTexture.RepeatV = (float)v;
  2175. part.UpdateTextureEntry(tex);
  2176. return;
  2177. }
  2178. }
  2179. public void llOffsetTexture(double u, double v, int face)
  2180. {
  2181. m_host.AddScriptLPS(1);
  2182. OffsetTexture(m_host, u, v, face);
  2183. ScriptSleep(m_sleepMsOnOffsetTexture);
  2184. }
  2185. protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
  2186. {
  2187. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2188. return;
  2189. Primitive.TextureEntry tex = part.Shape.Textures;
  2190. int nsides = GetNumberOfSides(part);
  2191. if (face >= 0 && face < nsides)
  2192. {
  2193. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2194. texface.OffsetU = (float)u;
  2195. texface.OffsetV = (float)v;
  2196. tex.FaceTextures[face] = texface;
  2197. part.UpdateTextureEntry(tex);
  2198. return;
  2199. }
  2200. if (face == ScriptBaseClass.ALL_SIDES)
  2201. {
  2202. for (int i = 0; i < nsides; i++)
  2203. {
  2204. if (tex.FaceTextures[i] != null)
  2205. {
  2206. tex.FaceTextures[i].OffsetU = (float)u;
  2207. tex.FaceTextures[i].OffsetV = (float)v;
  2208. }
  2209. }
  2210. tex.DefaultTexture.OffsetU = (float)u;
  2211. tex.DefaultTexture.OffsetV = (float)v;
  2212. part.UpdateTextureEntry(tex);
  2213. return;
  2214. }
  2215. }
  2216. public void llRotateTexture(double rotation, int face)
  2217. {
  2218. m_host.AddScriptLPS(1);
  2219. RotateTexture(m_host, rotation, face);
  2220. ScriptSleep(m_sleepMsOnRotateTexture);
  2221. }
  2222. protected void RotateTexture(SceneObjectPart part, double rotation, int face)
  2223. {
  2224. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2225. return;
  2226. Primitive.TextureEntry tex = part.Shape.Textures;
  2227. int nsides = GetNumberOfSides(part);
  2228. if (face >= 0 && face < nsides)
  2229. {
  2230. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2231. texface.Rotation = (float)rotation;
  2232. tex.FaceTextures[face] = texface;
  2233. part.UpdateTextureEntry(tex);
  2234. return;
  2235. }
  2236. if (face == ScriptBaseClass.ALL_SIDES)
  2237. {
  2238. for (int i = 0; i < nsides; i++)
  2239. {
  2240. if (tex.FaceTextures[i] != null)
  2241. {
  2242. tex.FaceTextures[i].Rotation = (float)rotation;
  2243. }
  2244. }
  2245. tex.DefaultTexture.Rotation = (float)rotation;
  2246. part.UpdateTextureEntry(tex);
  2247. return;
  2248. }
  2249. }
  2250. public LSL_String llGetTexture(int face)
  2251. {
  2252. m_host.AddScriptLPS(1);
  2253. return GetTexture(m_host, face);
  2254. }
  2255. protected LSL_String GetTexture(SceneObjectPart part, int face)
  2256. {
  2257. Primitive.TextureEntry tex = part.Shape.Textures;
  2258. int nsides = GetNumberOfSides(part);
  2259. if (face == ScriptBaseClass.ALL_SIDES)
  2260. {
  2261. face = 0;
  2262. }
  2263. if (face >= 0 && face < nsides)
  2264. {
  2265. Primitive.TextureEntryFace texface;
  2266. texface = tex.GetFace((uint)face);
  2267. string texture = texface.TextureID.ToString();
  2268. lock (part.TaskInventory)
  2269. {
  2270. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in part.TaskInventory)
  2271. {
  2272. if (inv.Value.AssetID == texface.TextureID)
  2273. {
  2274. texture = inv.Value.Name.ToString();
  2275. break;
  2276. }
  2277. }
  2278. }
  2279. return texture;
  2280. }
  2281. else
  2282. {
  2283. return ScriptBaseClass.NULL_KEY;
  2284. }
  2285. }
  2286. public void llSetPos(LSL_Vector pos)
  2287. {
  2288. m_host.AddScriptLPS(1);
  2289. SetPos(m_host, pos, true);
  2290. ScriptSleep(m_sleepMsOnSetPos);
  2291. }
  2292. /// <summary>
  2293. /// Tries to move the entire object so that the root prim is within 0.1m of position. http://wiki.secondlife.com/wiki/LlSetRegionPos
  2294. /// 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.
  2295. /// 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.
  2296. /// </summary>
  2297. /// <param name="pos"></param>
  2298. /// <returns>1 if successful, 0 otherwise.</returns>
  2299. public LSL_Integer llSetRegionPos(LSL_Vector pos)
  2300. {
  2301. m_host.AddScriptLPS(1);
  2302. // BEGIN WORKAROUND
  2303. // IF YOU GET REGION CROSSINGS WORKING WITH THIS FUNCTION, REPLACE THE WORKAROUND.
  2304. //
  2305. // This workaround is to prevent silent failure of this function.
  2306. // According to the specification on the SL Wiki, providing a position outside of the
  2307. if (pos.x < 0 || pos.x > World.RegionInfo.RegionSizeX || pos.y < 0 || pos.y > World.RegionInfo.RegionSizeY)
  2308. {
  2309. return 0;
  2310. }
  2311. // END WORK AROUND
  2312. else if ( // this is not part of the workaround if-block because it's not related to the workaround.
  2313. IsPhysical() ||
  2314. m_host.ParentGroup.IsAttachment || // return FALSE if attachment
  2315. (
  2316. pos.x < -10.0 || // return FALSE if more than 10 meters into a west-adjacent region.
  2317. pos.x > (World.RegionInfo.RegionSizeX + 10) || // return FALSE if more than 10 meters into a east-adjacent region.
  2318. pos.y < -10.0 || // return FALSE if more than 10 meters into a south-adjacent region.
  2319. pos.y > (World.RegionInfo.RegionSizeY + 10) || // return FALSE if more than 10 meters into a north-adjacent region.
  2320. pos.z > Constants.RegionHeight // return FALSE if altitude than 4096m
  2321. )
  2322. )
  2323. {
  2324. return 0;
  2325. }
  2326. // if we reach this point, then the object is not physical, it's not an attachment, and the destination is within the valid range.
  2327. // 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.
  2328. Vector3 objectPos = m_host.ParentGroup.RootPart.AbsolutePosition;
  2329. LandData here = World.GetLandData(objectPos);
  2330. LandData there = World.GetLandData(pos);
  2331. // 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.
  2332. bool sameParcel = here.GlobalID == there.GlobalID;
  2333. if (!sameParcel && !World.Permissions.CanRezObject(
  2334. m_host.ParentGroup.PrimCount, m_host.ParentGroup.OwnerID, pos))
  2335. {
  2336. return 0;
  2337. }
  2338. SetPos(m_host.ParentGroup.RootPart, pos, false);
  2339. return VecDist(pos, llGetRootPosition()) <= 0.1 ? 1 : 0;
  2340. }
  2341. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  2342. // note linked setpos is capped "differently"
  2343. private LSL_Vector SetPosAdjust(LSL_Vector start, LSL_Vector end)
  2344. {
  2345. if (llVecDist(start, end) > 10.0f * m_ScriptDistanceFactor)
  2346. return start + m_ScriptDistanceFactor * 10.0f * llVecNorm(end - start);
  2347. else
  2348. return end;
  2349. }
  2350. protected LSL_Vector GetSetPosTarget(SceneObjectPart part, LSL_Vector targetPos, LSL_Vector fromPos, bool adjust)
  2351. {
  2352. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2353. return fromPos;
  2354. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  2355. float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y);
  2356. bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true);
  2357. if (part.ParentGroup.RootPart == part)
  2358. {
  2359. if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0)
  2360. targetPos.z = ground;
  2361. }
  2362. if (adjust)
  2363. return SetPosAdjust(fromPos, targetPos);
  2364. return targetPos;
  2365. }
  2366. /// <summary>
  2367. /// set object position, optionally capping the distance.
  2368. /// </summary>
  2369. /// <param name="part"></param>
  2370. /// <param name="targetPos"></param>
  2371. /// <param name="adjust">if TRUE, will cap the distance to 10m.</param>
  2372. protected void SetPos(SceneObjectPart part, LSL_Vector targetPos, bool adjust)
  2373. {
  2374. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted || part.ParentGroup.inTransit)
  2375. return;
  2376. LSL_Vector currentPos = GetPartLocalPos(part);
  2377. LSL_Vector toPos = GetSetPosTarget(part, targetPos, currentPos, adjust);
  2378. if (part.ParentGroup.RootPart == part)
  2379. {
  2380. SceneObjectGroup parent = part.ParentGroup;
  2381. if (!parent.IsAttachment && !World.Permissions.CanObjectEntry(parent, false, (Vector3)toPos))
  2382. return;
  2383. parent.UpdateGroupPosition((Vector3)toPos);
  2384. }
  2385. else
  2386. {
  2387. part.OffsetPosition = (Vector3)toPos;
  2388. // SceneObjectGroup parent = part.ParentGroup;
  2389. // parent.HasGroupChanged = true;
  2390. // parent.ScheduleGroupForTerseUpdate();
  2391. part.ScheduleTerseUpdate();
  2392. }
  2393. }
  2394. public LSL_Vector llGetPos()
  2395. {
  2396. m_host.AddScriptLPS(1);
  2397. return m_host.GetWorldPosition();
  2398. }
  2399. public LSL_Vector llGetLocalPos()
  2400. {
  2401. m_host.AddScriptLPS(1);
  2402. return GetPartLocalPos(m_host);
  2403. }
  2404. protected LSL_Vector GetPartLocalPos(SceneObjectPart part)
  2405. {
  2406. m_host.AddScriptLPS(1);
  2407. Vector3 pos;
  2408. if (!part.IsRoot)
  2409. {
  2410. pos = part.OffsetPosition;
  2411. }
  2412. else
  2413. {
  2414. if (part.ParentGroup.IsAttachment)
  2415. pos = part.AttachedPos;
  2416. else
  2417. pos = part.AbsolutePosition;
  2418. }
  2419. // m_log.DebugFormat("[LSL API]: Returning {0} in GetPartLocalPos()", pos);
  2420. return new LSL_Vector(pos);
  2421. }
  2422. public void llSetRot(LSL_Rotation rot)
  2423. {
  2424. m_host.AddScriptLPS(1);
  2425. // try to let this work as in SL...
  2426. if (m_host.ParentID == 0 || (m_host.ParentGroup != null && m_host == m_host.ParentGroup.RootPart))
  2427. {
  2428. // special case: If we are root, rotate complete SOG to new rotation
  2429. SetRot(m_host, rot);
  2430. }
  2431. else
  2432. {
  2433. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  2434. SceneObjectPart rootPart = m_host.ParentGroup.RootPart;
  2435. if (rootPart != null) // better safe than sorry
  2436. {
  2437. SetRot(m_host, rootPart.RotationOffset * (Quaternion)rot);
  2438. }
  2439. }
  2440. ScriptSleep(m_sleepMsOnSetRot);
  2441. }
  2442. public void llSetLocalRot(LSL_Rotation rot)
  2443. {
  2444. m_host.AddScriptLPS(1);
  2445. SetRot(m_host, rot);
  2446. ScriptSleep(m_sleepMsOnSetLocalRot);
  2447. }
  2448. protected void SetRot(SceneObjectPart part, Quaternion rot)
  2449. {
  2450. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2451. return;
  2452. bool isroot = (part == part.ParentGroup.RootPart);
  2453. bool isphys;
  2454. PhysicsActor pa = part.PhysActor;
  2455. // keep using physactor ideia of isphysical
  2456. // it should be SOP ideia of that
  2457. // not much of a issue with ubOde
  2458. if (pa != null && pa.IsPhysical)
  2459. isphys = true;
  2460. else
  2461. isphys = false;
  2462. // SL doesn't let scripts rotate root of physical linksets
  2463. if (isroot && isphys)
  2464. return;
  2465. part.UpdateRotation(rot);
  2466. // Update rotation does not move the object in the physics engine if it's a non physical linkset
  2467. // so do a nasty update of parts positions if is a root part rotation
  2468. if (isroot && pa != null) // with if above implies non physical root part
  2469. {
  2470. part.ParentGroup.ResetChildPrimPhysicsPositions();
  2471. }
  2472. else // fix sitting avatars. This is only needed bc of how we link avas to child parts, not root part
  2473. {
  2474. // List<ScenePresence> sittingavas = part.ParentGroup.GetLinkedAvatars();
  2475. List<ScenePresence> sittingavas = part.ParentGroup.GetSittingAvatars();
  2476. if (sittingavas.Count > 0)
  2477. {
  2478. foreach (ScenePresence av in sittingavas)
  2479. {
  2480. if (isroot || part.LocalId == av.ParentID)
  2481. av.SendTerseUpdateToAllClients();
  2482. }
  2483. }
  2484. }
  2485. }
  2486. /// <summary>
  2487. /// See http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  2488. /// </summary>
  2489. public LSL_Rotation llGetRot()
  2490. {
  2491. // unlinked or root prim then use llRootRotation
  2492. // see llRootRotaion for references.
  2493. if (m_host.LinkNum == 0 || m_host.LinkNum == 1)
  2494. {
  2495. return llGetRootRotation();
  2496. }
  2497. m_host.AddScriptLPS(1);
  2498. Quaternion q = m_host.GetWorldRotation();
  2499. if (m_host.ParentGroup != null && m_host.ParentGroup.AttachmentPoint != 0)
  2500. {
  2501. ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  2502. if (avatar != null)
  2503. {
  2504. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2505. q = avatar.CameraRotation * q; // Mouselook
  2506. else
  2507. q = avatar.Rotation * q; // Currently infrequently updated so may be inaccurate
  2508. }
  2509. }
  2510. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  2511. }
  2512. private LSL_Rotation GetPartRot(SceneObjectPart part)
  2513. {
  2514. Quaternion q;
  2515. if (part.LinkNum == 0 || part.LinkNum == 1) // unlinked or root prim
  2516. {
  2517. if (part.ParentGroup.AttachmentPoint != 0)
  2518. {
  2519. ScenePresence avatar = World.GetScenePresence(part.ParentGroup.AttachedAvatar);
  2520. if (avatar != null)
  2521. {
  2522. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2523. q = avatar.CameraRotation; // Mouselook
  2524. else
  2525. q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate
  2526. }
  2527. else
  2528. q = part.ParentGroup.GroupRotation; // Likely never get here but just in case
  2529. }
  2530. else
  2531. q = part.ParentGroup.GroupRotation; // just the group rotation
  2532. return new LSL_Rotation(q);
  2533. }
  2534. q = part.GetWorldRotation();
  2535. if (part.ParentGroup.AttachmentPoint != 0)
  2536. {
  2537. ScenePresence avatar = World.GetScenePresence(part.ParentGroup.AttachedAvatar);
  2538. if (avatar != null)
  2539. {
  2540. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2541. q = avatar.CameraRotation * q; // Mouselook
  2542. else
  2543. q = avatar.Rotation * q; // Currently infrequently updated so may be inaccurate
  2544. }
  2545. }
  2546. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  2547. }
  2548. public LSL_Rotation llGetLocalRot()
  2549. {
  2550. return GetPartLocalRot(m_host);
  2551. }
  2552. private LSL_Rotation GetPartLocalRot(SceneObjectPart part)
  2553. {
  2554. m_host.AddScriptLPS(1);
  2555. Quaternion rot = part.RotationOffset;
  2556. return new LSL_Rotation(rot.X, rot.Y, rot.Z, rot.W);
  2557. }
  2558. public void llSetForce(LSL_Vector force, int local)
  2559. {
  2560. m_host.AddScriptLPS(1);
  2561. if (!m_host.ParentGroup.IsDeleted)
  2562. {
  2563. if (local != 0)
  2564. force *= llGetRot();
  2565. m_host.ParentGroup.RootPart.SetForce(force);
  2566. }
  2567. }
  2568. public LSL_Vector llGetForce()
  2569. {
  2570. LSL_Vector force = new LSL_Vector(0.0, 0.0, 0.0);
  2571. m_host.AddScriptLPS(1);
  2572. if (!m_host.ParentGroup.IsDeleted)
  2573. {
  2574. force = m_host.ParentGroup.RootPart.GetForce();
  2575. }
  2576. return force;
  2577. }
  2578. public void llSetVelocity(LSL_Vector vel, int local)
  2579. {
  2580. m_host.AddScriptLPS(1);
  2581. m_host.SetVelocity(new Vector3((float)vel.x, (float)vel.y, (float)vel.z), local != 0);
  2582. }
  2583. public void llSetAngularVelocity(LSL_Vector avel, int local)
  2584. {
  2585. m_host.AddScriptLPS(1);
  2586. m_host.SetAngularVelocity(new Vector3((float)avel.x, (float)avel.y, (float)avel.z), local != 0);
  2587. }
  2588. public LSL_Integer llTarget(LSL_Vector position, double range)
  2589. {
  2590. m_host.AddScriptLPS(1);
  2591. return m_host.ParentGroup.RegisterTargetWaypoint(m_item.ItemID, position, (float)range);
  2592. }
  2593. public void llTargetRemove(int number)
  2594. {
  2595. m_host.AddScriptLPS(1);
  2596. m_host.ParentGroup.UnregisterTargetWaypoint(number);
  2597. }
  2598. public LSL_Integer llRotTarget(LSL_Rotation rot, double error)
  2599. {
  2600. m_host.AddScriptLPS(1);
  2601. return m_host.ParentGroup.RegisterRotTargetWaypoint(m_item.ItemID, rot, (float)error);
  2602. }
  2603. public void llRotTargetRemove(int number)
  2604. {
  2605. m_host.AddScriptLPS(1);
  2606. m_host.ParentGroup.UnRegisterRotTargetWaypoint(number);
  2607. }
  2608. public void llMoveToTarget(LSL_Vector target, double tau)
  2609. {
  2610. m_host.AddScriptLPS(1);
  2611. m_host.ParentGroup.MoveToTarget(target, (float)tau);
  2612. }
  2613. public void llStopMoveToTarget()
  2614. {
  2615. m_host.AddScriptLPS(1);
  2616. m_host.ParentGroup.StopMoveToTarget();
  2617. }
  2618. public void llApplyImpulse(LSL_Vector force, LSL_Integer local)
  2619. {
  2620. m_host.AddScriptLPS(1);
  2621. //No energy force yet
  2622. Vector3 v = force;
  2623. if (v.Length() > 20000.0f)
  2624. {
  2625. v.Normalize();
  2626. v = v * 20000.0f;
  2627. }
  2628. m_host.ApplyImpulse(v, local != 0);
  2629. }
  2630. public void llApplyRotationalImpulse(LSL_Vector force, int local)
  2631. {
  2632. m_host.AddScriptLPS(1);
  2633. m_host.ParentGroup.RootPart.ApplyAngularImpulse(force, local != 0);
  2634. }
  2635. public void llSetTorque(LSL_Vector torque, int local)
  2636. {
  2637. m_host.AddScriptLPS(1);
  2638. m_host.ParentGroup.RootPart.SetAngularImpulse(torque, local != 0);
  2639. }
  2640. public LSL_Vector llGetTorque()
  2641. {
  2642. m_host.AddScriptLPS(1);
  2643. return new LSL_Vector(m_host.ParentGroup.GetTorque());
  2644. }
  2645. public void llSetForceAndTorque(LSL_Vector force, LSL_Vector torque, int local)
  2646. {
  2647. m_host.AddScriptLPS(1);
  2648. llSetForce(force, local);
  2649. llSetTorque(torque, local);
  2650. }
  2651. public LSL_Vector llGetVel()
  2652. {
  2653. m_host.AddScriptLPS(1);
  2654. Vector3 vel = Vector3.Zero;
  2655. if (m_host.ParentGroup.IsAttachment)
  2656. {
  2657. ScenePresence avatar = m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  2658. if (avatar != null)
  2659. vel = avatar.GetWorldVelocity();
  2660. }
  2661. else
  2662. {
  2663. vel = m_host.ParentGroup.RootPart.Velocity;
  2664. }
  2665. return new LSL_Vector(vel);
  2666. }
  2667. public LSL_Vector llGetAccel()
  2668. {
  2669. m_host.AddScriptLPS(1);
  2670. return new LSL_Vector(m_host.Acceleration);
  2671. }
  2672. public LSL_Vector llGetOmega()
  2673. {
  2674. m_host.AddScriptLPS(1);
  2675. Vector3 avel = m_host.AngularVelocity;
  2676. return new LSL_Vector(avel.X, avel.Y, avel.Z);
  2677. }
  2678. public LSL_Float llGetTimeOfDay()
  2679. {
  2680. m_host.AddScriptLPS(1);
  2681. return (double)((DateTime.Now.TimeOfDay.TotalMilliseconds / 1000) % (3600 * 4));
  2682. }
  2683. public LSL_Float llGetWallclock()
  2684. {
  2685. m_host.AddScriptLPS(1);
  2686. return DateTime.Now.TimeOfDay.TotalSeconds;
  2687. }
  2688. public LSL_Float llGetTime()
  2689. {
  2690. m_host.AddScriptLPS(1);
  2691. double ScriptTime = Util.GetTimeStampMS() - m_timer;
  2692. return (float)Math.Round((ScriptTime / 1000.0), 3);
  2693. }
  2694. public void llResetTime()
  2695. {
  2696. m_host.AddScriptLPS(1);
  2697. m_timer = Util.GetTimeStampMS();
  2698. }
  2699. public LSL_Float llGetAndResetTime()
  2700. {
  2701. m_host.AddScriptLPS(1);
  2702. double now = Util.GetTimeStampMS();
  2703. double ScriptTime = now - m_timer;
  2704. m_timer = now;
  2705. return (float)Math.Round((ScriptTime / 1000.0), 3);
  2706. }
  2707. public void llSound(string sound, double volume, int queue, int loop)
  2708. {
  2709. m_host.AddScriptLPS(1);
  2710. Deprecated("llSound", "Use llPlaySound instead");
  2711. }
  2712. // Xantor 20080528 PlaySound updated so it accepts an objectinventory name -or- a key to a sound
  2713. // 20080530 Updated to remove code duplication
  2714. public void llPlaySound(string sound, double volume)
  2715. {
  2716. m_host.AddScriptLPS(1);
  2717. if (m_SoundModule == null)
  2718. return;
  2719. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2720. if(soundID == UUID.Zero)
  2721. return;
  2722. // send the sound, once, to all clients in range
  2723. m_SoundModule.SendSound(m_host.UUID, soundID, volume, false, 0, false, false);
  2724. }
  2725. public void llLoopSound(string sound, double volume)
  2726. {
  2727. m_host.AddScriptLPS(1);
  2728. if (m_SoundModule == null)
  2729. return;
  2730. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2731. if(soundID == UUID.Zero)
  2732. return;
  2733. m_SoundModule.LoopSound(m_host.UUID, soundID, volume, false,false);
  2734. }
  2735. public void llLoopSoundMaster(string sound, double volume)
  2736. {
  2737. m_host.AddScriptLPS(1);
  2738. if (m_SoundModule == null)
  2739. return;
  2740. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2741. if(soundID == UUID.Zero)
  2742. return;
  2743. m_SoundModule.LoopSound(m_host.UUID, soundID, volume, true, false);
  2744. }
  2745. public void llLoopSoundSlave(string sound, double volume)
  2746. {
  2747. m_host.AddScriptLPS(1);
  2748. if (m_SoundModule == null)
  2749. return;
  2750. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2751. if(soundID == UUID.Zero)
  2752. return;
  2753. m_SoundModule.LoopSound(m_host.UUID, soundID, volume, false, true);
  2754. }
  2755. public void llPlaySoundSlave(string sound, double volume)
  2756. {
  2757. m_host.AddScriptLPS(1);
  2758. if (m_SoundModule == null)
  2759. return;
  2760. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2761. if(soundID == UUID.Zero)
  2762. return;
  2763. // send the sound, once, to all clients in range
  2764. m_SoundModule.SendSound(m_host.UUID, soundID, volume, false, 0, true, false);
  2765. }
  2766. public void llTriggerSound(string sound, double volume)
  2767. {
  2768. m_host.AddScriptLPS(1);
  2769. if (m_SoundModule == null)
  2770. return;
  2771. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2772. if(soundID == UUID.Zero)
  2773. return;
  2774. // send the sound, once, to all clients in rangeTrigger or play an attached sound in this part's inventory.
  2775. m_SoundModule.SendSound(m_host.UUID, soundID, volume, true, 0, false, false);
  2776. }
  2777. public void llStopSound()
  2778. {
  2779. m_host.AddScriptLPS(1);
  2780. if (m_SoundModule != null)
  2781. m_SoundModule.StopSound(m_host.UUID);
  2782. }
  2783. public void llPreloadSound(string sound)
  2784. {
  2785. m_host.AddScriptLPS(1);
  2786. if (m_SoundModule == null)
  2787. return;
  2788. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2789. if(soundID == UUID.Zero)
  2790. return;
  2791. m_SoundModule.PreloadSound(m_host.UUID, soundID);
  2792. ScriptSleep(m_sleepMsOnPreloadSound);
  2793. }
  2794. /// <summary>
  2795. /// Return a portion of the designated string bounded by
  2796. /// inclusive indices (start and end). As usual, the negative
  2797. /// indices, and the tolerance for out-of-bound values, makes
  2798. /// this more complicated than it might otherwise seem.
  2799. /// </summary>
  2800. public LSL_String llGetSubString(string src, int start, int end)
  2801. {
  2802. m_host.AddScriptLPS(1);
  2803. // Normalize indices (if negative).
  2804. // After normlaization they may still be
  2805. // negative, but that is now relative to
  2806. // the start, rather than the end, of the
  2807. // sequence.
  2808. if (start < 0)
  2809. {
  2810. start = src.Length+start;
  2811. }
  2812. if (end < 0)
  2813. {
  2814. end = src.Length+end;
  2815. }
  2816. // Conventional substring
  2817. if (start <= end)
  2818. {
  2819. // Implies both bounds are out-of-range.
  2820. if (end < 0 || start >= src.Length)
  2821. {
  2822. return String.Empty;
  2823. }
  2824. // If end is positive, then it directly
  2825. // corresponds to the lengt of the substring
  2826. // needed (plus one of course). BUT, it
  2827. // must be within bounds.
  2828. if (end >= src.Length)
  2829. {
  2830. end = src.Length-1;
  2831. }
  2832. if (start < 0)
  2833. {
  2834. return src.Substring(0,end+1);
  2835. }
  2836. // Both indices are positive
  2837. return src.Substring(start, (end+1) - start);
  2838. }
  2839. // Inverted substring (end < start)
  2840. else
  2841. {
  2842. // Implies both indices are below the
  2843. // lower bound. In the inverted case, that
  2844. // means the entire string will be returned
  2845. // unchanged.
  2846. if (start < 0)
  2847. {
  2848. return src;
  2849. }
  2850. // If both indices are greater than the upper
  2851. // bound the result may seem initially counter
  2852. // intuitive.
  2853. if (end >= src.Length)
  2854. {
  2855. return src;
  2856. }
  2857. if (end < 0)
  2858. {
  2859. if (start < src.Length)
  2860. {
  2861. return src.Substring(start);
  2862. }
  2863. else
  2864. {
  2865. return String.Empty;
  2866. }
  2867. }
  2868. else
  2869. {
  2870. if (start < src.Length)
  2871. {
  2872. return src.Substring(0,end+1) + src.Substring(start);
  2873. }
  2874. else
  2875. {
  2876. return src.Substring(0,end+1);
  2877. }
  2878. }
  2879. }
  2880. }
  2881. /// <summary>
  2882. /// Delete substring removes the specified substring bounded
  2883. /// by the inclusive indices start and end. Indices may be
  2884. /// negative (indicating end-relative) and may be inverted,
  2885. /// i.e. end < start.
  2886. /// </summary>
  2887. public LSL_String llDeleteSubString(string src, int start, int end)
  2888. {
  2889. m_host.AddScriptLPS(1);
  2890. // Normalize indices (if negative).
  2891. // After normlaization they may still be
  2892. // negative, but that is now relative to
  2893. // the start, rather than the end, of the
  2894. // sequence.
  2895. if (start < 0)
  2896. {
  2897. start = src.Length+start;
  2898. }
  2899. if (end < 0)
  2900. {
  2901. end = src.Length+end;
  2902. }
  2903. // Conventionally delimited substring
  2904. if (start <= end)
  2905. {
  2906. // If both bounds are outside of the existing
  2907. // string, then return unchanges.
  2908. if (end < 0 || start >= src.Length)
  2909. {
  2910. return src;
  2911. }
  2912. // At least one bound is in-range, so we
  2913. // need to clip the out-of-bound argument.
  2914. if (start < 0)
  2915. {
  2916. start = 0;
  2917. }
  2918. if (end >= src.Length)
  2919. {
  2920. end = src.Length-1;
  2921. }
  2922. return src.Remove(start,end-start+1);
  2923. }
  2924. // Inverted substring
  2925. else
  2926. {
  2927. // In this case, out of bounds means that
  2928. // the existing string is part of the cut.
  2929. if (start < 0 || end >= src.Length)
  2930. {
  2931. return String.Empty;
  2932. }
  2933. if (end > 0)
  2934. {
  2935. if (start < src.Length)
  2936. {
  2937. return src.Remove(start).Remove(0,end+1);
  2938. }
  2939. else
  2940. {
  2941. return src.Remove(0,end+1);
  2942. }
  2943. }
  2944. else
  2945. {
  2946. if (start < src.Length)
  2947. {
  2948. return src.Remove(start);
  2949. }
  2950. else
  2951. {
  2952. return src;
  2953. }
  2954. }
  2955. }
  2956. }
  2957. /// <summary>
  2958. /// Insert string inserts the specified string identified by src
  2959. /// at the index indicated by index. Index may be negative, in
  2960. /// which case it is end-relative. The index may exceed either
  2961. /// string bound, with the result being a concatenation.
  2962. /// </summary>
  2963. public LSL_String llInsertString(string dest, int index, string src)
  2964. {
  2965. m_host.AddScriptLPS(1);
  2966. // Normalize indices (if negative).
  2967. // After normalization they may still be
  2968. // negative, but that is now relative to
  2969. // the start, rather than the end, of the
  2970. // sequence.
  2971. if (index < 0)
  2972. {
  2973. index = dest.Length+index;
  2974. // Negative now means it is less than the lower
  2975. // bound of the string.
  2976. if (index < 0)
  2977. {
  2978. return src+dest;
  2979. }
  2980. }
  2981. if (index >= dest.Length)
  2982. {
  2983. return dest+src;
  2984. }
  2985. // The index is in bounds.
  2986. // In this case the index refers to the index that will
  2987. // be assigned to the first character of the inserted string.
  2988. // So unlike the other string operations, we do not add one
  2989. // to get the correct string length.
  2990. return dest.Substring(0,index)+src+dest.Substring(index);
  2991. }
  2992. public LSL_String llToUpper(string src)
  2993. {
  2994. m_host.AddScriptLPS(1);
  2995. return src.ToUpper();
  2996. }
  2997. public LSL_String llToLower(string src)
  2998. {
  2999. m_host.AddScriptLPS(1);
  3000. return src.ToLower();
  3001. }
  3002. public LSL_Integer llGiveMoney(LSL_Key destination, LSL_Integer amount)
  3003. {
  3004. m_host.AddScriptLPS(1);
  3005. if (m_item.PermsGranter == UUID.Zero)
  3006. return 0;
  3007. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  3008. {
  3009. Error("llGiveMoney", "No permissions to give money");
  3010. return 0;
  3011. }
  3012. UUID toID = new UUID();
  3013. if (!UUID.TryParse(destination, out toID))
  3014. {
  3015. Error("llGiveMoney", "Bad key in llGiveMoney");
  3016. return 0;
  3017. }
  3018. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  3019. if (money == null)
  3020. {
  3021. NotImplemented("llGiveMoney");
  3022. return 0;
  3023. }
  3024. Action<string> act = dontcare =>
  3025. {
  3026. money.ObjectGiveMoney(m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID,
  3027. toID, amount,UUID.Zero, out string reason);
  3028. };
  3029. m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  3030. return 0;
  3031. }
  3032. public void llMakeExplosion(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  3033. {
  3034. m_host.AddScriptLPS(1);
  3035. Deprecated("llMakeExplosion", "Use llParticleSystem instead");
  3036. ScriptSleep(m_sleepMsOnMakeExplosion);
  3037. }
  3038. public void llMakeFountain(int particles, double scale, double vel, double lifetime, double arc, int bounce, string texture, LSL_Vector offset, double bounce_offset)
  3039. {
  3040. m_host.AddScriptLPS(1);
  3041. Deprecated("llMakeFountain", "Use llParticleSystem instead");
  3042. ScriptSleep(m_sleepMsOnMakeFountain);
  3043. }
  3044. public void llMakeSmoke(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  3045. {
  3046. m_host.AddScriptLPS(1);
  3047. Deprecated("llMakeSmoke", "Use llParticleSystem instead");
  3048. ScriptSleep(m_sleepMsOnMakeSmoke);
  3049. }
  3050. public void llMakeFire(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  3051. {
  3052. m_host.AddScriptLPS(1);
  3053. Deprecated("llMakeFire", "Use llParticleSystem instead");
  3054. ScriptSleep(m_sleepMsOnMakeFire);
  3055. }
  3056. public void llRezAtRoot(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  3057. {
  3058. doObjectRez(inventory, pos, vel, rot, param, true);
  3059. }
  3060. public void doObjectRez(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param, bool atRoot)
  3061. {
  3062. m_host.AddScriptLPS(1);
  3063. if (string.IsNullOrEmpty(inventory) || Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s))
  3064. return;
  3065. float dist = (float)llVecDist(llGetPos(), pos);
  3066. if (dist > m_ScriptDistanceFactor * 10.0f)
  3067. return;
  3068. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
  3069. if (item == null)
  3070. {
  3071. Error("llRez(AtRoot/Object)", "Can't find object '" + inventory + "'");
  3072. return;
  3073. }
  3074. if (item.InvType != (int)InventoryType.Object)
  3075. {
  3076. Error("llRez(AtRoot/Object)", "Can't create requested object; object is missing from database");
  3077. return;
  3078. }
  3079. Util.FireAndForget(x =>
  3080. {
  3081. Quaternion wrot = rot;
  3082. wrot.Normalize();
  3083. List<SceneObjectGroup> new_groups = World.RezObject(m_host, item, pos, wrot, vel, param, atRoot);
  3084. // If either of these are null, then there was an unknown error.
  3085. if (new_groups == null)
  3086. return;
  3087. bool notAttachment = !m_host.ParentGroup.IsAttachment;
  3088. foreach (SceneObjectGroup group in new_groups)
  3089. {
  3090. // objects rezzed with this method are die_at_edge by default.
  3091. group.RootPart.SetDieAtEdge(true);
  3092. group.ResumeScripts();
  3093. m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
  3094. "object_rez", new Object[] {
  3095. new LSL_String(
  3096. group.RootPart.UUID.ToString()) },
  3097. new DetectParams[0]));
  3098. if (notAttachment)
  3099. {
  3100. float groupmass = group.GetMass();
  3101. PhysicsActor pa = group.RootPart.PhysActor;
  3102. //Recoil.
  3103. if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero)
  3104. {
  3105. Vector3 recoil = -vel * groupmass * m_recoilScaleFactor;
  3106. if (recoil != Vector3.Zero)
  3107. {
  3108. llApplyImpulse(recoil, 0);
  3109. }
  3110. }
  3111. }
  3112. }
  3113. }, null, "LSL_Api.doObjectRez");
  3114. //ScriptSleep((int)((groupmass * velmag) / 10));
  3115. ScriptSleep(m_sleepMsOnRezAtRoot);
  3116. }
  3117. public void llRezObject(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  3118. {
  3119. doObjectRez(inventory, pos, vel, rot, param, false);
  3120. }
  3121. public void llLookAt(LSL_Vector target, double strength, double damping)
  3122. {
  3123. m_host.AddScriptLPS(1);
  3124. // Get the normalized vector to the target
  3125. LSL_Vector from = llGetPos();
  3126. // normalized direction to target
  3127. LSL_Vector dir = llVecNorm(target - from);
  3128. // use vertical to help compute left axis
  3129. // LSL_Vector up = new LSL_Vector(0.0, 0.0, 1.0);
  3130. // find normalized left axis parallel to horizon
  3131. // LSL_Vector left = llVecNorm(LSL_Vector.Cross(up, dir));
  3132. LSL_Vector left = new LSL_Vector(-dir.y, dir.x, 0.0f);
  3133. left = llVecNorm(left);
  3134. // make up orthogonal to left and dir
  3135. LSL_Vector up = LSL_Vector.Cross(dir, left);
  3136. // compute rotation based on orthogonal axes
  3137. // and rotate so Z points to target with X below horizont
  3138. LSL_Rotation rot = new LSL_Rotation(0.0, 0.707107, 0.0, 0.707107) * llAxes2Rot(dir, left, up);
  3139. SceneObjectGroup sog = m_host.ParentGroup;
  3140. if(sog == null || sog.IsDeleted)
  3141. return;
  3142. if (!sog.UsesPhysics || sog.IsAttachment)
  3143. {
  3144. // Do nothing if either value is 0 (this has been checked in SL)
  3145. if (strength <= 0.0 || damping <= 0.0)
  3146. return;
  3147. llSetLocalRot(rot);
  3148. }
  3149. else
  3150. {
  3151. if (strength == 0)
  3152. {
  3153. llSetLocalRot(rot);
  3154. return;
  3155. }
  3156. sog.StartLookAt(rot, (float)strength, (float)damping);
  3157. }
  3158. }
  3159. public void llStopLookAt()
  3160. {
  3161. m_host.AddScriptLPS(1);
  3162. m_host.StopLookAt();
  3163. }
  3164. public void llSetTimerEvent(double sec)
  3165. {
  3166. if (sec != 0.0 && sec < m_MinTimerInterval)
  3167. sec = m_MinTimerInterval;
  3168. m_host.AddScriptLPS(1);
  3169. // Setting timer repeat
  3170. m_AsyncCommands.TimerPlugin.SetTimerEvent(m_host.LocalId, m_item.ItemID, sec);
  3171. }
  3172. public virtual void llSleep(double sec)
  3173. {
  3174. // m_log.Info("llSleep snoozing " + sec + "s.");
  3175. m_host.AddScriptLPS(1);
  3176. Sleep((int)(sec * 1000));
  3177. }
  3178. public LSL_Float llGetMass()
  3179. {
  3180. m_host.AddScriptLPS(1);
  3181. if (m_host.ParentGroup.IsAttachment)
  3182. {
  3183. ScenePresence attachedAvatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  3184. if (attachedAvatar != null)
  3185. {
  3186. return attachedAvatar.GetMass();
  3187. }
  3188. else
  3189. {
  3190. return 0;
  3191. }
  3192. }
  3193. else
  3194. {
  3195. // new SL always returns object mass
  3196. // if (m_host.IsRoot)
  3197. // {
  3198. return m_host.ParentGroup.GetMass();
  3199. // }
  3200. // else
  3201. // {
  3202. // return m_host.GetMass();
  3203. // }
  3204. }
  3205. }
  3206. public LSL_Float llGetMassMKS()
  3207. {
  3208. return 100f * llGetMass();
  3209. }
  3210. public void llCollisionFilter(LSL_String name, LSL_Key id, LSL_Integer accept)
  3211. {
  3212. m_host.AddScriptLPS(1);
  3213. m_host.CollisionFilter.Clear();
  3214. if (!UUID.TryParse(id, out UUID objectID))
  3215. return;
  3216. if (objectID == UUID.Zero && name == "")
  3217. return;
  3218. m_host.CollisionFilter.Add(accept, objectID.ToString() + name);
  3219. }
  3220. public void llTakeControls(int controls, int accept, int pass_on)
  3221. {
  3222. if (m_item.PermsGranter != UUID.Zero)
  3223. {
  3224. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3225. if (presence != null)
  3226. {
  3227. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  3228. {
  3229. presence.RegisterControlEventsToScript(controls, accept, pass_on, m_host.LocalId, m_item.ItemID);
  3230. }
  3231. }
  3232. }
  3233. m_host.AddScriptLPS(1);
  3234. }
  3235. public void llReleaseControls()
  3236. {
  3237. m_host.AddScriptLPS(1);
  3238. if (m_item.PermsGranter != UUID.Zero)
  3239. {
  3240. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3241. if (presence != null)
  3242. {
  3243. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  3244. {
  3245. // Unregister controls from Presence
  3246. presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID);
  3247. // Remove Take Control permission.
  3248. m_item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  3249. }
  3250. }
  3251. }
  3252. }
  3253. public void llReleaseURL(string url)
  3254. {
  3255. m_host.AddScriptLPS(1);
  3256. if (m_UrlModule != null)
  3257. m_UrlModule.ReleaseURL(url);
  3258. }
  3259. /// <summary>
  3260. /// Attach the object containing this script to the avatar that owns it.
  3261. /// </summary>
  3262. /// <param name='attachmentPoint'>
  3263. /// The attachment point (e.g. <see cref="OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass.ATTACH_CHEST">ATTACH_CHEST</see>)
  3264. /// </param>
  3265. /// <returns>true if the attach suceeded, false if it did not</returns>
  3266. public bool AttachToAvatar(int attachmentPoint)
  3267. {
  3268. SceneObjectGroup grp = m_host.ParentGroup;
  3269. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  3270. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  3271. if (attachmentsModule != null)
  3272. return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true, true);
  3273. else
  3274. return false;
  3275. }
  3276. /// <summary>
  3277. /// Detach the object containing this script from the avatar it is attached to.
  3278. /// </summary>
  3279. /// <remarks>
  3280. /// Nothing happens if the object is not attached.
  3281. /// </remarks>
  3282. public void DetachFromAvatar()
  3283. {
  3284. Util.FireAndForget(DetachWrapper, m_host, "LSL_Api.DetachFromAvatar");
  3285. }
  3286. private void DetachWrapper(object o)
  3287. {
  3288. if (World.AttachmentsModule != null)
  3289. {
  3290. SceneObjectPart host = (SceneObjectPart)o;
  3291. ScenePresence presence = World.GetScenePresence(host.OwnerID);
  3292. World.AttachmentsModule.DetachSingleAttachmentToInv(presence, host.ParentGroup);
  3293. }
  3294. }
  3295. public void llAttachToAvatar(LSL_Integer attachmentPoint)
  3296. {
  3297. m_host.AddScriptLPS(1);
  3298. if (m_item.PermsGranter != m_host.OwnerID)
  3299. return;
  3300. SceneObjectGroup grp = m_host.ParentGroup;
  3301. if (grp == null || grp.IsDeleted || grp.IsAttachment)
  3302. return;
  3303. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  3304. AttachToAvatar(attachmentPoint);
  3305. }
  3306. public void llAttachToAvatarTemp(LSL_Integer attachmentPoint)
  3307. {
  3308. IAttachmentsModule attachmentsModule = World.RequestModuleInterface<IAttachmentsModule>();
  3309. if (attachmentsModule == null)
  3310. return;
  3311. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) == 0)
  3312. return;
  3313. SceneObjectGroup grp = m_host.ParentGroup;
  3314. if (grp == null || grp.IsDeleted || grp.IsAttachment)
  3315. return;
  3316. if (!World.TryGetScenePresence(m_item.PermsGranter, out ScenePresence target))
  3317. return;
  3318. if (target.UUID != grp.OwnerID)
  3319. {
  3320. uint effectivePerms = grp.EffectiveOwnerPerms;
  3321. if ((effectivePerms & (uint)PermissionMask.Transfer) == 0)
  3322. return;
  3323. grp.SetOwner(target.UUID, target.ControllingClient.ActiveGroupId);
  3324. if (World.Permissions.PropagatePermissions())
  3325. {
  3326. foreach (SceneObjectPart child in grp.Parts)
  3327. {
  3328. child.Inventory.ChangeInventoryOwner(target.UUID);
  3329. child.TriggerScriptChangedEvent(Changed.OWNER);
  3330. child.ApplyNextOwnerPermissions();
  3331. }
  3332. grp.InvalidateEffectivePerms();
  3333. }
  3334. grp.RootPart.ObjectSaleType = 0;
  3335. grp.RootPart.SalePrice = 10;
  3336. grp.HasGroupChanged = true;
  3337. grp.RootPart.SendPropertiesToClient(target.ControllingClient);
  3338. grp.RootPart.ScheduleFullUpdate();
  3339. }
  3340. attachmentsModule.AttachObject(target, grp, (uint)attachmentPoint, false, false, true);
  3341. }
  3342. public void llDetachFromAvatar()
  3343. {
  3344. m_host.AddScriptLPS(1);
  3345. if (m_host.ParentGroup.AttachmentPoint == 0)
  3346. return;
  3347. if (m_item.PermsGranter != m_host.OwnerID)
  3348. return;
  3349. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  3350. DetachFromAvatar();
  3351. }
  3352. public void llTakeCamera(string avatar)
  3353. {
  3354. m_host.AddScriptLPS(1);
  3355. Deprecated("llTakeCamera", "Use llSetCameraParams instead");
  3356. }
  3357. public void llReleaseCamera(string avatar)
  3358. {
  3359. m_host.AddScriptLPS(1);
  3360. Deprecated("llReleaseCamera", "Use llClearCameraParams instead");
  3361. }
  3362. public LSL_Key llGetOwner()
  3363. {
  3364. m_host.AddScriptLPS(1);
  3365. return m_host.OwnerID.ToString();
  3366. }
  3367. public void llInstantMessage(string user, string message)
  3368. {
  3369. m_host.AddScriptLPS(1);
  3370. if (!UUID.TryParse(user, out UUID result) || result == UUID.Zero)
  3371. {
  3372. Error("llInstantMessage","An invalid key was passed to llInstantMessage");
  3373. ScriptSleep(2000);
  3374. return;
  3375. }
  3376. // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
  3377. // InstantMessageModule.OnInstantMessage searches through a list of scenes for a client matching the toAgent,
  3378. // but I don't think we have a list of scenes available from here.
  3379. // (We also don't want to duplicate the code in OnInstantMessage if we can avoid it.)
  3380. // user is a UUID
  3381. // TODO: figure out values for client, fromSession, and imSessionID
  3382. // client.SendInstantMessage(m_host.UUID, fromSession, message, user, imSessionID, m_host.Name, AgentManager.InstantMessageDialog.MessageFromAgent, (uint)Util.UnixTimeSinceEpoch());
  3383. UUID friendTransactionID = UUID.Random();
  3384. //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
  3385. GridInstantMessage msg = new GridInstantMessage
  3386. {
  3387. fromAgentID = new Guid(m_host.OwnerID.ToString()), // fromAgentID.Guid;
  3388. toAgentID = new Guid(user), // toAgentID.Guid;
  3389. imSessionID = new Guid(m_host.UUID.ToString()), // This is the item we're mucking with here
  3390. timestamp = (uint)Util.UnixTimeSinceEpoch(),
  3391. fromAgentName = m_host.Name//client.FirstName + " " + client.LastName;// fromAgentName;
  3392. };
  3393. if (message != null && message.Length > 1024)
  3394. msg.message = message.Substring(0, 1024);
  3395. else
  3396. msg.message = message;
  3397. msg.dialog = (byte)19; // MessageFromObject
  3398. msg.fromGroup = false;// fromGroup;
  3399. msg.offline = (byte)0; //offline;
  3400. msg.ParentEstateID = World.RegionInfo.EstateSettings.EstateID;
  3401. msg.Position = new Vector3(m_host.AbsolutePosition);
  3402. msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid;
  3403. Vector3 pos = m_host.AbsolutePosition;
  3404. msg.binaryBucket
  3405. = Util.StringToBytes256(
  3406. "{0}/{1}/{2}/{3}",
  3407. World.RegionInfo.RegionName,
  3408. (int)Math.Floor(pos.X),
  3409. (int)Math.Floor(pos.Y),
  3410. (int)Math.Floor(pos.Z));
  3411. if (m_TransferModule != null)
  3412. {
  3413. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  3414. }
  3415. ScriptSleep(m_sleepMsOnInstantMessage);
  3416. }
  3417. public void llEmail(string address, string subject, string message)
  3418. {
  3419. m_host.AddScriptLPS(1);
  3420. if (m_emailModule == null)
  3421. {
  3422. Error("llEmail", "Email module not configured");
  3423. return;
  3424. }
  3425. // this is a fire and forget no event is sent to script
  3426. Action<string> act = eventID =>
  3427. {
  3428. //Restrict email destination to the avatars registered email address?
  3429. //The restriction only applies if the destination address is not local.
  3430. if (m_restrictEmail == true && address.Contains(m_internalObjectHost) == false)
  3431. {
  3432. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, m_host.OwnerID);
  3433. if (account == null)
  3434. return;
  3435. if (String.IsNullOrEmpty(account.Email))
  3436. return;
  3437. address = account.Email;
  3438. }
  3439. m_emailModule.SendEmail(m_host.UUID, address, subject, message);
  3440. // no dataserver event
  3441. };
  3442. m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId,
  3443. m_item.ItemID, act);
  3444. ScriptSleep(m_sleepMsOnEmail);
  3445. }
  3446. public void llGetNextEmail(string address, string subject)
  3447. {
  3448. m_host.AddScriptLPS(1);
  3449. if (m_emailModule == null)
  3450. {
  3451. Error("llGetNextEmail", "Email module not configured");
  3452. return;
  3453. }
  3454. Email email;
  3455. email = m_emailModule.GetNextEmail(m_host.UUID, address, subject);
  3456. if (email == null)
  3457. return;
  3458. m_ScriptEngine.PostObjectEvent(m_host.LocalId,
  3459. new EventParams("email",
  3460. new Object[] {
  3461. new LSL_String(email.time),
  3462. new LSL_String(email.sender),
  3463. new LSL_String(email.subject),
  3464. new LSL_String(email.message),
  3465. new LSL_Integer(email.numLeft)},
  3466. new DetectParams[0]));
  3467. }
  3468. public void llTargetedEmail(LSL_Integer target, LSL_String subject, LSL_String message)
  3469. {
  3470. m_host.AddScriptLPS(1);
  3471. SceneObjectGroup parent = m_host.ParentGroup;
  3472. if (parent == null || parent.IsDeleted)
  3473. return;
  3474. if (m_emailModule == null)
  3475. {
  3476. Error("llTargetedEmail", "Email module not configured");
  3477. return;
  3478. }
  3479. if (subject.Length + message.Length > 4096)
  3480. {
  3481. Error("llTargetedEmail", "Message is too large");
  3482. return;
  3483. }
  3484. // this is a fire and forget no event is sent to script
  3485. Action<string> act = eventID =>
  3486. {
  3487. UserAccount account = null;
  3488. if (target == ScriptBaseClass.TARGETED_EMAIL_OBJECT_OWNER)
  3489. {
  3490. if(parent.OwnerID == parent.GroupID)
  3491. return;
  3492. account = m_userAccountService.GetUserAccount(RegionScopeID, parent.OwnerID);
  3493. }
  3494. else if (target == ScriptBaseClass.TARGETED_EMAIL_ROOT_CREATOR)
  3495. {
  3496. // non standard avoid creator spam
  3497. if(m_item.CreatorID == parent.RootPart.CreatorID)
  3498. {
  3499. account = m_userAccountService.GetUserAccount(RegionScopeID, parent.RootPart.CreatorID);
  3500. }
  3501. else
  3502. return;
  3503. }
  3504. else
  3505. return;
  3506. if (account == null)
  3507. {
  3508. return;
  3509. }
  3510. string address = account.Email;
  3511. if (String.IsNullOrEmpty(address))
  3512. {
  3513. return;
  3514. }
  3515. m_emailModule.SendEmail(m_host.UUID, address, subject, message);
  3516. };
  3517. m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId,
  3518. m_item.ItemID, act);
  3519. ScriptSleep(m_sleepMsOnEmail);
  3520. }
  3521. public LSL_Key llGetKey()
  3522. {
  3523. m_host.AddScriptLPS(1);
  3524. return m_host.UUID.ToString();
  3525. }
  3526. public LSL_Key llGenerateKey()
  3527. {
  3528. m_host.AddScriptLPS(1);
  3529. return UUID.Random().ToString();
  3530. }
  3531. public void llSetBuoyancy(double buoyancy)
  3532. {
  3533. m_host.AddScriptLPS(1);
  3534. if (!m_host.ParentGroup.IsDeleted)
  3535. {
  3536. m_host.ParentGroup.RootPart.SetBuoyancy((float)buoyancy);
  3537. }
  3538. }
  3539. /// <summary>
  3540. /// Attempt to clamp the object on the Z axis at the given height over tau seconds.
  3541. /// </summary>
  3542. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  3543. /// <param name="water">False if height is calculated just from ground, otherwise uses ground or water depending on whichever is higher</param>
  3544. /// <param name="tau">Number of seconds over which to reach target</param>
  3545. public void llSetHoverHeight(double height, int water, double tau)
  3546. {
  3547. m_host.AddScriptLPS(1);
  3548. PIDHoverType hoverType = PIDHoverType.Ground;
  3549. if (water != 0)
  3550. {
  3551. hoverType = PIDHoverType.GroundAndWater;
  3552. }
  3553. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  3554. }
  3555. public void llStopHover()
  3556. {
  3557. m_host.AddScriptLPS(1);
  3558. m_host.SetHoverHeight(0f, PIDHoverType.Ground, 0f);
  3559. }
  3560. public void llMinEventDelay(double delay)
  3561. {
  3562. m_host.AddScriptLPS(1);
  3563. try
  3564. {
  3565. m_ScriptEngine.SetMinEventDelay(m_item.ItemID, delay);
  3566. }
  3567. catch (NotImplementedException)
  3568. {
  3569. // Currently not implemented in DotNetEngine only XEngine
  3570. NotImplemented("llMinEventDelay", "In DotNetEngine");
  3571. }
  3572. }
  3573. public void llSoundPreload(string sound)
  3574. {
  3575. m_host.AddScriptLPS(1);
  3576. Deprecated("llSoundPreload", "Use llPreloadSound instead");
  3577. }
  3578. public void llRotLookAt(LSL_Rotation target, double strength, double damping)
  3579. {
  3580. m_host.AddScriptLPS(1);
  3581. // Per discussion with Melanie, for non-physical objects llLookAt appears to simply
  3582. // set the rotation of the object, copy that behavior
  3583. SceneObjectGroup sog = m_host.ParentGroup;
  3584. if(sog == null || sog.IsDeleted)
  3585. return;
  3586. if (strength == 0 || !sog.UsesPhysics || sog.IsAttachment)
  3587. {
  3588. llSetLocalRot(target);
  3589. }
  3590. else
  3591. {
  3592. sog.RotLookAt(target, (float)strength, (float)damping);
  3593. }
  3594. }
  3595. public LSL_Integer llStringLength(string str)
  3596. {
  3597. m_host.AddScriptLPS(1);
  3598. if(str == null || str.Length <= 0)
  3599. return 0;
  3600. return str.Length;
  3601. }
  3602. public void llStartAnimation(string anim)
  3603. {
  3604. m_host.AddScriptLPS(1);
  3605. if (m_item.PermsGranter == UUID.Zero)
  3606. return;
  3607. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  3608. {
  3609. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3610. if (presence != null)
  3611. {
  3612. // Do NOT try to parse UUID, animations cannot be triggered by ID
  3613. UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  3614. if (animID == UUID.Zero)
  3615. presence.Animator.AddAnimation(anim, m_host.UUID);
  3616. else
  3617. presence.Animator.AddAnimation(animID, m_host.UUID);
  3618. }
  3619. }
  3620. }
  3621. public void llStopAnimation(string anim)
  3622. {
  3623. m_host.AddScriptLPS(1);
  3624. if (m_item.PermsGranter == UUID.Zero)
  3625. return;
  3626. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  3627. {
  3628. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3629. if (presence != null)
  3630. {
  3631. UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim);
  3632. if (animID == UUID.Zero)
  3633. presence.Animator.RemoveAnimation(anim);
  3634. else
  3635. presence.Animator.RemoveAnimation(animID, true);
  3636. }
  3637. }
  3638. }
  3639. public void llStartObjectAnimation(string anim)
  3640. {
  3641. m_host.AddScriptLPS(1);
  3642. // Do NOT try to parse UUID, animations cannot be triggered by ID
  3643. UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  3644. if (animID == UUID.Zero)
  3645. animID = DefaultAvatarAnimations.GetDefaultAnimation(anim);
  3646. if (animID != UUID.Zero)
  3647. m_host.AddAnimation(animID, anim);
  3648. }
  3649. public void llStopObjectAnimation(string anim)
  3650. {
  3651. m_host.AddScriptLPS(1);
  3652. UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim, AssetType.Animation);
  3653. if (animID == UUID.Zero)
  3654. animID = DefaultAvatarAnimations.GetDefaultAnimation(anim);
  3655. if (animID != UUID.Zero)
  3656. m_host.RemoveAnimation(animID);
  3657. }
  3658. public LSL_List llGetObjectAnimationNames()
  3659. {
  3660. m_host.AddScriptLPS(1);
  3661. LSL_List ret = new LSL_List();
  3662. if(m_host.AnimationsNames == null || m_host.AnimationsNames.Count == 0)
  3663. return ret;
  3664. foreach (string name in m_host.AnimationsNames.Values)
  3665. ret.Add(new LSL_String(name));
  3666. return ret;
  3667. }
  3668. public void llPointAt(LSL_Vector pos)
  3669. {
  3670. m_host.AddScriptLPS(1);
  3671. }
  3672. public void llStopPointAt()
  3673. {
  3674. m_host.AddScriptLPS(1);
  3675. }
  3676. public void llTargetOmega(LSL_Vector axis, double spinrate, double gain)
  3677. {
  3678. m_host.AddScriptLPS(1);
  3679. TargetOmega(m_host, axis, spinrate, gain);
  3680. }
  3681. protected void TargetOmega(SceneObjectPart part, LSL_Vector axis, double spinrate, double gain)
  3682. {
  3683. PhysicsActor pa = part.PhysActor;
  3684. if ( ( pa == null || !pa.IsPhysical ) && gain == 0.0d )
  3685. spinrate = 0.0d;
  3686. part.UpdateAngularVelocity(axis * spinrate);
  3687. }
  3688. public LSL_Integer llGetStartParameter()
  3689. {
  3690. m_host.AddScriptLPS(1);
  3691. return m_ScriptEngine.GetStartParameter(m_item.ItemID);
  3692. }
  3693. public void llRequestPermissions(string agent, int perm)
  3694. {
  3695. if (!UUID.TryParse(agent, out UUID agentID))
  3696. return;
  3697. if (agentID == UUID.Zero || perm == 0) // Releasing permissions
  3698. {
  3699. llReleaseControls();
  3700. m_item.PermsGranter = UUID.Zero;
  3701. m_item.PermsMask = 0;
  3702. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3703. "run_time_permissions", new Object[] {
  3704. new LSL_Integer(0) },
  3705. new DetectParams[0]));
  3706. return;
  3707. }
  3708. if (m_item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  3709. llReleaseControls();
  3710. m_host.AddScriptLPS(1);
  3711. int implicitPerms = 0;
  3712. if (m_host.ParentGroup.IsAttachment && (UUID)agent == m_host.ParentGroup.AttachedAvatar)
  3713. {
  3714. // When attached, certain permissions are implicit if requested from owner
  3715. implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS |
  3716. ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  3717. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  3718. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  3719. ScriptBaseClass.PERMISSION_ATTACH |
  3720. ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS;
  3721. }
  3722. else
  3723. {
  3724. if (m_host.ParentGroup.HasSittingAvatar(agentID))
  3725. {
  3726. // When agent is sitting, certain permissions are implicit if requested from sitting agent
  3727. implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  3728. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  3729. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  3730. ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  3731. }
  3732. else
  3733. {
  3734. if (World.GetExtraSetting("auto_grant_attach_perms") == "true")
  3735. implicitPerms = ScriptBaseClass.PERMISSION_ATTACH;
  3736. }
  3737. if (World.GetExtraSetting("auto_grant_all_perms") == "true")
  3738. {
  3739. implicitPerms = perm;
  3740. }
  3741. }
  3742. if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  3743. {
  3744. m_host.TaskInventory.LockItemsForWrite(true);
  3745. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3746. m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
  3747. m_host.TaskInventory.LockItemsForWrite(false);
  3748. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3749. "run_time_permissions", new Object[] {
  3750. new LSL_Integer(perm) },
  3751. new DetectParams[0]));
  3752. return;
  3753. }
  3754. ScenePresence presence = World.GetScenePresence(agentID);
  3755. if (presence != null)
  3756. {
  3757. // If permissions are being requested from an NPC and were not implicitly granted above then
  3758. // auto grant all requested permissions if the script is owned by the NPC or the NPCs owner
  3759. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  3760. if (npcModule != null && npcModule.IsNPC(agentID, World))
  3761. {
  3762. if (npcModule.CheckPermissions(agentID, m_host.OwnerID))
  3763. {
  3764. lock (m_host.TaskInventory)
  3765. {
  3766. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3767. m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
  3768. }
  3769. m_ScriptEngine.PostScriptEvent(
  3770. m_item.ItemID,
  3771. new EventParams(
  3772. "run_time_permissions", new Object[] { new LSL_Integer(perm) }, new DetectParams[0]));
  3773. }
  3774. // it is an NPC, exit even if the permissions werent granted above, they are not going to answer
  3775. // the question!
  3776. return;
  3777. }
  3778. string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
  3779. if (ownerName == String.Empty)
  3780. ownerName = "(hippos)";
  3781. if (!m_waitingForScriptAnswer)
  3782. {
  3783. m_host.TaskInventory.LockItemsForWrite(true);
  3784. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3785. m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
  3786. m_host.TaskInventory.LockItemsForWrite(false);
  3787. presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
  3788. m_waitingForScriptAnswer=true;
  3789. }
  3790. presence.ControllingClient.SendScriptQuestion(
  3791. m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, m_item.ItemID, perm);
  3792. return;
  3793. }
  3794. // Requested agent is not in range, refuse perms
  3795. m_ScriptEngine.PostScriptEvent(
  3796. m_item.ItemID,
  3797. new EventParams("run_time_permissions", new Object[] { new LSL_Integer(0) }, new DetectParams[0]));
  3798. }
  3799. void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer)
  3800. {
  3801. if (taskID != m_host.UUID)
  3802. return;
  3803. client.OnScriptAnswer -= handleScriptAnswer;
  3804. m_waitingForScriptAnswer = false;
  3805. if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  3806. llReleaseControls();
  3807. m_host.TaskInventory.LockItemsForWrite(true);
  3808. m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
  3809. m_host.TaskInventory.LockItemsForWrite(false);
  3810. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3811. "run_time_permissions", new Object[] {
  3812. new LSL_Integer(answer) },
  3813. new DetectParams[0]));
  3814. }
  3815. public LSL_Key llGetPermissionsKey()
  3816. {
  3817. m_host.AddScriptLPS(1);
  3818. return m_item.PermsGranter.ToString();
  3819. }
  3820. public LSL_Integer llGetPermissions()
  3821. {
  3822. m_host.AddScriptLPS(1);
  3823. int perms = m_item.PermsMask;
  3824. if (m_automaticLinkPermission)
  3825. perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
  3826. return perms;
  3827. }
  3828. public LSL_Integer llGetLinkNumber()
  3829. {
  3830. m_host.AddScriptLPS(1);
  3831. if (m_host.ParentGroup.PrimCount > 1)
  3832. {
  3833. return m_host.LinkNum;
  3834. }
  3835. else
  3836. {
  3837. return 0;
  3838. }
  3839. }
  3840. public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
  3841. {
  3842. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  3843. if (parts.Count > 0)
  3844. {
  3845. try
  3846. {
  3847. foreach (SceneObjectPart part in parts)
  3848. part.SetFaceColorAlpha(face, color, null);
  3849. }
  3850. finally { }
  3851. }
  3852. }
  3853. public void llCreateLink(LSL_Key target, LSL_Integer parent)
  3854. {
  3855. m_host.AddScriptLPS(1);
  3856. if (!UUID.TryParse(target, out UUID targetID))
  3857. return;
  3858. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3859. && !m_automaticLinkPermission)
  3860. {
  3861. Error("llCreateLink", "PERMISSION_CHANGE_LINKS permission not set");
  3862. return;
  3863. }
  3864. CreateLink(target, parent);
  3865. }
  3866. public void CreateLink(string target, int parent)
  3867. {
  3868. if (!UUID.TryParse(target, out UUID targetID))
  3869. return;
  3870. SceneObjectPart targetPart = World.GetSceneObjectPart(targetID);
  3871. if (targetPart == null)
  3872. return;
  3873. if (targetPart.ParentGroup.AttachmentPoint != 0)
  3874. return; // Fail silently if attached
  3875. if (targetPart.ParentGroup.RootPart.OwnerID != m_host.ParentGroup.RootPart.OwnerID)
  3876. return;
  3877. SceneObjectGroup parentPrim = null, childPrim = null;
  3878. if (parent != 0)
  3879. {
  3880. parentPrim = m_host.ParentGroup;
  3881. childPrim = targetPart.ParentGroup;
  3882. }
  3883. else
  3884. {
  3885. parentPrim = targetPart.ParentGroup;
  3886. childPrim = m_host.ParentGroup;
  3887. }
  3888. // Required for linking
  3889. childPrim.RootPart.ClearUpdateSchedule();
  3890. parentPrim.LinkToGroup(childPrim, true);
  3891. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3892. parentPrim.RootPart.CreateSelected = false;
  3893. parentPrim.HasGroupChanged = true;
  3894. parentPrim.ScheduleGroupForFullUpdate();
  3895. IClientAPI client = null;
  3896. ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
  3897. if (sp != null)
  3898. client = sp.ControllingClient;
  3899. if (client != null)
  3900. parentPrim.SendPropertiesToClient(client);
  3901. ScriptSleep(m_sleepMsOnCreateLink);
  3902. }
  3903. public void llBreakLink(int linknum)
  3904. {
  3905. m_host.AddScriptLPS(1);
  3906. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3907. && !m_automaticLinkPermission)
  3908. {
  3909. Error("llBreakLink", "PERMISSION_CHANGE_LINKS permission not set");
  3910. return;
  3911. }
  3912. BreakLink(linknum);
  3913. }
  3914. public void BreakLink(int linknum)
  3915. {
  3916. if (linknum < ScriptBaseClass.LINK_THIS)
  3917. return;
  3918. SceneObjectGroup parentSOG = m_host.ParentGroup;
  3919. if (parentSOG.AttachmentPoint != 0)
  3920. return; // Fail silently if attached
  3921. SceneObjectPart childPrim = null;
  3922. switch (linknum)
  3923. {
  3924. case ScriptBaseClass.LINK_ROOT:
  3925. case ScriptBaseClass.LINK_SET:
  3926. case ScriptBaseClass.LINK_ALL_OTHERS:
  3927. case ScriptBaseClass.LINK_ALL_CHILDREN:
  3928. break;
  3929. case ScriptBaseClass.LINK_THIS: // not as spec
  3930. childPrim = m_host;
  3931. break;
  3932. default:
  3933. childPrim = parentSOG.GetLinkNumPart(linknum);
  3934. break;
  3935. }
  3936. if (linknum == ScriptBaseClass.LINK_ROOT)
  3937. {
  3938. List<ScenePresence> avs = parentSOG.GetSittingAvatars();
  3939. foreach (ScenePresence av in avs)
  3940. av.StandUp();
  3941. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentSOG.Parts);
  3942. parts.Remove(parentSOG.RootPart);
  3943. if (parts.Count > 0)
  3944. {
  3945. try
  3946. {
  3947. foreach (SceneObjectPart part in parts)
  3948. {
  3949. parentSOG.DelinkFromGroup(part.LocalId, true);
  3950. }
  3951. }
  3952. finally { }
  3953. }
  3954. parentSOG.HasGroupChanged = true;
  3955. parentSOG.ScheduleGroupForFullUpdate();
  3956. parentSOG.TriggerScriptChangedEvent(Changed.LINK);
  3957. if (parts.Count > 0)
  3958. {
  3959. SceneObjectPart newRoot = parts[0];
  3960. parts.Remove(newRoot);
  3961. try
  3962. {
  3963. foreach (SceneObjectPart part in parts)
  3964. {
  3965. part.ClearUpdateSchedule();
  3966. newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
  3967. }
  3968. }
  3969. finally { }
  3970. newRoot.ParentGroup.HasGroupChanged = true;
  3971. newRoot.ParentGroup.ScheduleGroupForFullUpdate();
  3972. }
  3973. }
  3974. else
  3975. {
  3976. if (childPrim == null)
  3977. return;
  3978. List<ScenePresence> avs = parentSOG.GetSittingAvatars();
  3979. foreach (ScenePresence av in avs)
  3980. av.StandUp();
  3981. parentSOG.DelinkFromGroup(childPrim.LocalId, true);
  3982. }
  3983. }
  3984. public void llBreakAllLinks()
  3985. {
  3986. m_host.AddScriptLPS(1);
  3987. TaskInventoryItem item = m_item;
  3988. if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3989. && !m_automaticLinkPermission)
  3990. {
  3991. Error("llBreakAllLinks","Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
  3992. return;
  3993. }
  3994. BreakAllLinks();
  3995. }
  3996. public void BreakAllLinks()
  3997. {
  3998. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3999. if (parentPrim.AttachmentPoint != 0)
  4000. return; // Fail silently if attached
  4001. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
  4002. parts.Remove(parentPrim.RootPart);
  4003. foreach (SceneObjectPart part in parts)
  4004. {
  4005. parentPrim.DelinkFromGroup(part.LocalId, true);
  4006. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  4007. }
  4008. parentPrim.HasGroupChanged = true;
  4009. parentPrim.ScheduleGroupForFullUpdate();
  4010. }
  4011. public LSL_Key llGetLinkKey(int linknum)
  4012. {
  4013. m_host.AddScriptLPS(1);
  4014. if(linknum < 0)
  4015. {
  4016. if (linknum == ScriptBaseClass.LINK_THIS)
  4017. return m_host.UUID.ToString();
  4018. return ScriptBaseClass.NULL_KEY;
  4019. }
  4020. if (linknum < 2)
  4021. return m_host.ParentGroup.RootPart.UUID.ToString();
  4022. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum);
  4023. if (part != null)
  4024. {
  4025. return part.UUID.ToString();
  4026. }
  4027. else
  4028. {
  4029. if (linknum > m_host.ParentGroup.PrimCount)
  4030. {
  4031. linknum -= m_host.ParentGroup.PrimCount + 1;
  4032. List<ScenePresence> avatars = GetLinkAvatars(ScriptBaseClass.LINK_SET);
  4033. if (avatars.Count > linknum)
  4034. {
  4035. return avatars[linknum].UUID.ToString();
  4036. }
  4037. }
  4038. return ScriptBaseClass.NULL_KEY;
  4039. }
  4040. }
  4041. /// <summary>
  4042. /// Returns the name of the child prim or seated avatar matching the
  4043. /// specified link number.
  4044. /// </summary>
  4045. /// <param name="linknum">
  4046. /// The number of a link in the linkset or a link-related constant.
  4047. /// </param>
  4048. /// <returns>
  4049. /// The name determined to match the specified link number.
  4050. /// </returns>
  4051. /// <remarks>
  4052. /// The rules governing the returned name are not simple. The only
  4053. /// time a blank name is returned is if the target prim has a blank
  4054. /// name. If no prim with the given link number can be found then
  4055. /// usually NULL_KEY is returned but there are exceptions.
  4056. ///
  4057. /// In a single unlinked prim, A call with 0 returns the name, all
  4058. /// other values for link number return NULL_KEY
  4059. ///
  4060. /// In link sets it is more complicated.
  4061. ///
  4062. /// If the script is in the root prim:-
  4063. /// A zero link number returns NULL_KEY.
  4064. /// Positive link numbers return the name of the prim, or NULL_KEY
  4065. /// if a prim does not exist at that position.
  4066. /// Negative link numbers return the name of the first child prim.
  4067. ///
  4068. /// If the script is in a child prim:-
  4069. /// Link numbers 0 or 1 return the name of the root prim.
  4070. /// Positive link numbers return the name of the prim or NULL_KEY
  4071. /// if a prim does not exist at that position.
  4072. /// Negative numbers return the name of the root prim.
  4073. ///
  4074. /// References
  4075. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetLinkName
  4076. /// Mentions NULL_KEY being returned
  4077. /// http://wiki.secondlife.com/wiki/LlGetLinkName
  4078. /// Mentions using the LINK_* constants, some of which are negative
  4079. /// </remarks>
  4080. public LSL_String llGetLinkName(int linknum)
  4081. {
  4082. m_host.AddScriptLPS(1);
  4083. ISceneEntity entity = GetLinkEntity(m_host, linknum);
  4084. if (entity != null)
  4085. return entity.Name;
  4086. else
  4087. return ScriptBaseClass.NULL_KEY;
  4088. }
  4089. public LSL_Integer llGetInventoryNumber(int type)
  4090. {
  4091. m_host.AddScriptLPS(1);
  4092. int count = 0;
  4093. m_host.TaskInventory.LockItemsForRead(true);
  4094. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  4095. {
  4096. if (inv.Value.Type == type || type == -1)
  4097. {
  4098. count = count + 1;
  4099. }
  4100. }
  4101. m_host.TaskInventory.LockItemsForRead(false);
  4102. return count;
  4103. }
  4104. public LSL_String llGetInventoryName(int type, int number)
  4105. {
  4106. m_host.AddScriptLPS(1);
  4107. ArrayList keys = new ArrayList();
  4108. m_host.TaskInventory.LockItemsForRead(true);
  4109. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  4110. {
  4111. if (inv.Value.Type == type || type == -1)
  4112. {
  4113. keys.Add(inv.Value.Name);
  4114. }
  4115. }
  4116. m_host.TaskInventory.LockItemsForRead(false);
  4117. if (keys.Count == 0)
  4118. {
  4119. return String.Empty;
  4120. }
  4121. keys.Sort();
  4122. if (keys.Count > number)
  4123. {
  4124. return (string)keys[number];
  4125. }
  4126. return String.Empty;
  4127. }
  4128. public LSL_Float llGetEnergy()
  4129. {
  4130. m_host.AddScriptLPS(1);
  4131. // TODO: figure out real energy value
  4132. return 1.0f;
  4133. }
  4134. public void llGiveInventory(LSL_Key destination, LSL_String inventory)
  4135. {
  4136. m_host.AddScriptLPS(1);
  4137. UUID destId = UUID.Zero;
  4138. if (!UUID.TryParse(destination, out destId))
  4139. {
  4140. Error("llGiveInventory", "Can't parse destination key '" + destination + "'");
  4141. return;
  4142. }
  4143. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
  4144. if (item == null)
  4145. {
  4146. Error("llGiveInventory", "Can't find inventory object '" + inventory + "'");
  4147. return;
  4148. }
  4149. UUID objId = item.ItemID;
  4150. // check if destination is an object
  4151. if (World.GetSceneObjectPart(destId) != null)
  4152. {
  4153. // destination is an object
  4154. World.MoveTaskInventoryItem(destId, m_host, objId);
  4155. }
  4156. else
  4157. {
  4158. ScenePresence presence = World.GetScenePresence(destId);
  4159. if (presence == null)
  4160. {
  4161. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, destId);
  4162. if (account == null)
  4163. {
  4164. GridUserInfo info = World.GridUserService.GetGridUserInfo(destId.ToString());
  4165. if(info == null || info.Online == false)
  4166. {
  4167. Error("llGiveInventory", "Can't find destination '" + destId.ToString() + "'");
  4168. return;
  4169. }
  4170. }
  4171. }
  4172. // destination is an avatar
  4173. InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId, out string message);
  4174. if (agentItem == null)
  4175. {
  4176. llSay(0, message);
  4177. return;
  4178. }
  4179. byte[] bucket = new byte[1];
  4180. bucket[0] = (byte)item.Type;
  4181. GridInstantMessage msg = new GridInstantMessage(World,
  4182. m_host.OwnerID, m_host.Name, destId,
  4183. (byte)InstantMessageDialog.TaskInventoryOffered,
  4184. m_host.OwnerID == m_host.GroupID, "'"+item.Name+"'. ("+m_host.Name+" is located at "+
  4185. World.RegionInfo.RegionName+" "+ m_host.AbsolutePosition.ToString() + ")",
  4186. agentItem.ID, true, m_host.AbsolutePosition,
  4187. bucket, true);
  4188. if (World.TryGetScenePresence(destId, out ScenePresence sp))
  4189. {
  4190. sp.ControllingClient.SendInstantMessage(msg);
  4191. }
  4192. else
  4193. {
  4194. if (m_TransferModule != null)
  4195. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  4196. }
  4197. //This delay should only occur when giving inventory to avatars.
  4198. ScriptSleep(m_sleepMsOnGiveInventory);
  4199. }
  4200. }
  4201. [DebuggerNonUserCode]
  4202. public void llRemoveInventory(string name)
  4203. {
  4204. m_host.AddScriptLPS(1);
  4205. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  4206. if (item == null)
  4207. return;
  4208. if (item.ItemID == m_item.ItemID)
  4209. throw new ScriptDeleteException();
  4210. else
  4211. m_host.Inventory.RemoveInventoryItem(item.ItemID);
  4212. }
  4213. public void llSetText(string text, LSL_Vector color, double alpha)
  4214. {
  4215. m_host.AddScriptLPS(1);
  4216. Vector3 av3 = Util.Clip(color, 0.0f, 1.0f);
  4217. m_host.SetText(text, av3, Util.Clip((float)alpha, 0.0f, 1.0f));
  4218. }
  4219. public LSL_Float llWater(LSL_Vector offset)
  4220. {
  4221. m_host.AddScriptLPS(1);
  4222. return World.RegionInfo.RegionSettings.WaterHeight;
  4223. }
  4224. public void llPassTouches(int pass)
  4225. {
  4226. m_host.AddScriptLPS(1);
  4227. if (pass != 0)
  4228. m_host.PassTouches = true;
  4229. else
  4230. m_host.PassTouches = false;
  4231. }
  4232. public LSL_Key llRequestAgentData(string id, int data)
  4233. {
  4234. m_host.AddScriptLPS(1);
  4235. if (UUID.TryParse(id, out UUID uuid) && uuid != UUID.Zero)
  4236. {
  4237. if (uuid == UUID.Zero)
  4238. return string.Empty;
  4239. //pre process fast local avatars
  4240. switch(data)
  4241. {
  4242. case ScriptBaseClass.DATA_ONLINE:
  4243. World.TryGetScenePresence(uuid, out ScenePresence sp);
  4244. if (sp != null)
  4245. {
  4246. string ftid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId,
  4247. m_item.ItemID, "1");
  4248. ScriptSleep(m_sleepMsOnRequestAgentData);
  4249. return ftid;
  4250. }
  4251. break;
  4252. case ScriptBaseClass.DATA_NAME: // DATA_NAME (First Last)
  4253. case ScriptBaseClass.DATA_BORN: // DATA_BORN (YYYY-MM-DD)
  4254. case ScriptBaseClass.DATA_RATING: // DATA_RATING (0,0,0,0,0,0)
  4255. case 7: // DATA_USERLEVEL (integer). This is not available in LL and so has no constant.
  4256. case ScriptBaseClass.DATA_PAYINFO: // DATA_PAYINFO (0|1|2|3)
  4257. break;
  4258. default:
  4259. return string.Empty; // Raise no event
  4260. }
  4261. Action<string> act = eventID =>
  4262. {
  4263. UserAccount account = null;
  4264. string reply;
  4265. if (data == ScriptBaseClass.DATA_ONLINE)
  4266. {
  4267. World.TryGetScenePresence(uuid, out ScenePresence sp);
  4268. if(sp != null)
  4269. reply = "1";
  4270. else
  4271. {
  4272. account = m_userAccountService.GetUserAccount(RegionScopeID, uuid);
  4273. if (account == null)
  4274. reply = "0";
  4275. else
  4276. {
  4277. PresenceInfo pinfo = null;
  4278. if (!m_PresenceInfoCache.TryGetValue(uuid, out pinfo))
  4279. {
  4280. PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
  4281. if (pinfos != null && pinfos.Length > 0)
  4282. {
  4283. foreach (PresenceInfo p in pinfos)
  4284. {
  4285. if (p.RegionID != UUID.Zero)
  4286. {
  4287. pinfo = p;
  4288. }
  4289. }
  4290. }
  4291. m_PresenceInfoCache.AddOrUpdate(uuid, pinfo, m_llRequestAgentDataCacheTimeout);
  4292. }
  4293. reply = pinfo == null ? "0" : "1";
  4294. }
  4295. }
  4296. }
  4297. else
  4298. {
  4299. if (account == null)
  4300. account = m_userAccountService.GetUserAccount(RegionScopeID, uuid);
  4301. if (account == null)
  4302. reply = "0";
  4303. else
  4304. switch (data)
  4305. {
  4306. case ScriptBaseClass.DATA_NAME: // DATA_NAME (First Last)
  4307. reply = account.FirstName + " " + account.LastName;
  4308. break;
  4309. case ScriptBaseClass.DATA_BORN: // DATA_BORN (YYYY-MM-DD)
  4310. DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  4311. born = born.AddSeconds(account.Created);
  4312. reply = born.ToString("yyyy-MM-dd");
  4313. break;
  4314. case ScriptBaseClass.DATA_RATING: // DATA_RATING (0,0,0,0,0,0)
  4315. reply = "0,0,0,0,0,0";
  4316. break;
  4317. case 7: // DATA_USERLEVEL (integer). This is not available in LL and so has no constant.
  4318. reply = account.UserLevel.ToString();
  4319. break;
  4320. case ScriptBaseClass.DATA_PAYINFO: // DATA_PAYINFO (0|1|2|3)
  4321. reply = "0";
  4322. break;
  4323. default:
  4324. reply = "0"; // Raise no event
  4325. break;
  4326. }
  4327. }
  4328. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, reply);
  4329. };
  4330. UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId,
  4331. m_item.ItemID, act);
  4332. ScriptSleep(m_sleepMsOnRequestAgentData);
  4333. return tid.ToString();
  4334. }
  4335. else
  4336. {
  4337. Error("llRequestAgentData","Invalid UUID passed to llRequestAgentData.");
  4338. }
  4339. return "";
  4340. }
  4341. //bad if lm is HG
  4342. public LSL_Key llRequestInventoryData(LSL_String name)
  4343. {
  4344. m_host.AddScriptLPS(1);
  4345. Action<string> act = eventID =>
  4346. {
  4347. string reply = String.Empty;
  4348. foreach (TaskInventoryItem item in m_host.Inventory.GetInventoryItems())
  4349. {
  4350. if (item.Type == 3 && item.Name == name)
  4351. {
  4352. AssetBase a = World.AssetService.Get(item.AssetID.ToString());
  4353. if(a != null)
  4354. {
  4355. AssetLandmark lm = new AssetLandmark(a);
  4356. if(lm != null)
  4357. {
  4358. float rx = (uint)(lm.RegionHandle >> 32);
  4359. float ry = (uint)lm.RegionHandle;
  4360. Vector3 region = new Vector3(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
  4361. region = lm.Position + new Vector3(rx, ry, 0) - region;
  4362. reply = region.ToString();
  4363. }
  4364. }
  4365. break;
  4366. }
  4367. }
  4368. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, reply);
  4369. };
  4370. UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId,
  4371. m_item.ItemID, act);
  4372. ScriptSleep(m_sleepMsOnRequestInventoryData);
  4373. return tid.ToString();
  4374. }
  4375. public void llSetDamage(double damage)
  4376. {
  4377. m_host.AddScriptLPS(1);
  4378. m_host.ParentGroup.Damage = (float)damage;
  4379. }
  4380. public void llTeleportAgentHome(string agent)
  4381. {
  4382. m_host.AddScriptLPS(1);
  4383. UUID agentId = new UUID();
  4384. if (UUID.TryParse(agent, out agentId))
  4385. {
  4386. ScenePresence presence = World.GetScenePresence(agentId);
  4387. if (presence != null && presence.PresenceType != PresenceType.Npc)
  4388. {
  4389. // agent must not be a god
  4390. if (presence.GodController.UserLevel >= 200) return;
  4391. // agent must be over the owners land
  4392. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  4393. {
  4394. if (!World.TeleportClientHome(agentId, presence.ControllingClient))
  4395. {
  4396. // They can't be teleported home for some reason
  4397. GridRegion regionInfo = World.GridService.GetRegionByUUID(UUID.Zero, new UUID("2b02daac-e298-42fa-9a75-f488d37896e6"));
  4398. if (regionInfo != null)
  4399. {
  4400. World.RequestTeleportLocation(
  4401. presence.ControllingClient, regionInfo.RegionHandle, new Vector3(128, 128, 23), Vector3.Zero,
  4402. (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome));
  4403. }
  4404. }
  4405. }
  4406. }
  4407. }
  4408. ScriptSleep(m_sleepMsOnSetDamage);
  4409. }
  4410. public void llTeleportAgent(string agent, string destination, LSL_Vector targetPos, LSL_Vector targetLookAt)
  4411. {
  4412. m_host.AddScriptLPS(1);
  4413. UUID agentId = new UUID();
  4414. if (UUID.TryParse(agent, out agentId))
  4415. {
  4416. ScenePresence presence = World.GetScenePresence(agentId);
  4417. if (presence != null && presence.PresenceType != PresenceType.Npc)
  4418. {
  4419. if (destination == String.Empty)
  4420. destination = World.RegionInfo.RegionName;
  4421. if (m_item.PermsGranter == agentId)
  4422. {
  4423. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
  4424. {
  4425. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  4426. }
  4427. }
  4428. // agent must be wearing the object
  4429. if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID)
  4430. {
  4431. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  4432. }
  4433. else
  4434. {
  4435. // agent must not be a god
  4436. if (presence.IsViewerUIGod) return;
  4437. // agent must be over the owners land
  4438. ILandObject agentLand = World.LandChannel.GetLandObject(presence.AbsolutePosition);
  4439. ILandObject objectLand = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  4440. if (m_host.OwnerID == objectLand.LandData.OwnerID && m_host.OwnerID == agentLand.LandData.OwnerID)
  4441. {
  4442. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  4443. }
  4444. }
  4445. }
  4446. }
  4447. }
  4448. public void llTeleportAgentGlobalCoords(string agent, LSL_Vector global_coords, LSL_Vector targetPos, LSL_Vector targetLookAt)
  4449. {
  4450. m_host.AddScriptLPS(1);
  4451. UUID agentId = new UUID();
  4452. ulong regionHandle = Util.RegionWorldLocToHandle((uint)global_coords.x, (uint)global_coords.y);
  4453. if (UUID.TryParse(agent, out agentId))
  4454. {
  4455. // This function is owner only!
  4456. if (m_host.OwnerID != agentId)
  4457. return;
  4458. ScenePresence presence = World.GetScenePresence(agentId);
  4459. if (presence == null || presence.PresenceType == PresenceType.Npc)
  4460. return;
  4461. // Can't TP sitting avatars
  4462. if (presence.ParentID != 0) // Sitting
  4463. return;
  4464. if (m_item.PermsGranter == agentId)
  4465. {
  4466. // If attached using llAttachToAvatarTemp, cowardly refuse
  4467. if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.ParentGroup.FromItemID == UUID.Zero)
  4468. return;
  4469. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
  4470. {
  4471. World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4472. }
  4473. }
  4474. }
  4475. }
  4476. private void DoLLTeleport(ScenePresence sp, string destination, Vector3 targetPos, Vector3 targetLookAt)
  4477. {
  4478. UUID assetID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, destination);
  4479. // The destinaion is not an asset ID and also doesn't name a landmark.
  4480. // Use it as a sim name
  4481. if (assetID == UUID.Zero)
  4482. {
  4483. World.RequestTeleportLocation(sp.ControllingClient, destination, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4484. return;
  4485. }
  4486. AssetBase lma = World.AssetService.Get(assetID.ToString());
  4487. if (lma == null)
  4488. return;
  4489. if (lma.Type != (sbyte)AssetType.Landmark)
  4490. return;
  4491. AssetLandmark lm = new AssetLandmark(lma);
  4492. World.RequestTeleportLocation(sp.ControllingClient, lm.RegionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4493. }
  4494. public void llTextBox(string agent, string message, int chatChannel)
  4495. {
  4496. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  4497. if (dm == null)
  4498. return;
  4499. m_host.AddScriptLPS(1);
  4500. UUID av = new UUID();
  4501. if (!UUID.TryParse(agent,out av))
  4502. {
  4503. Error("llTextBox", "First parameter must be a key");
  4504. return;
  4505. }
  4506. if (message == string.Empty)
  4507. {
  4508. Error("llTextBox", "Empty message");
  4509. }
  4510. else if (Encoding.UTF8.GetByteCount(message) > 512)
  4511. {
  4512. Error("llTextBox", "Message longer than 512 bytes");
  4513. }
  4514. else
  4515. {
  4516. dm.SendTextBoxToUser(av, message, chatChannel, m_host.Name, m_host.UUID, m_host.OwnerID);
  4517. ScriptSleep(m_sleepMsOnTextBox);
  4518. }
  4519. }
  4520. public void llModifyLand(int action, int brush)
  4521. {
  4522. m_host.AddScriptLPS(1);
  4523. ITerrainModule tm = m_ScriptEngine.World.RequestModuleInterface<ITerrainModule>();
  4524. if (tm != null)
  4525. {
  4526. tm.ModifyTerrain(m_host.OwnerID, m_host.AbsolutePosition, (byte) brush, (byte) action);
  4527. }
  4528. }
  4529. public void llCollisionSound(LSL_String impact_sound, LSL_Float impact_volume)
  4530. {
  4531. m_host.AddScriptLPS(1);
  4532. if(impact_sound == "")
  4533. {
  4534. m_host.CollisionSoundVolume = (float)impact_volume;
  4535. m_host.CollisionSound = m_host.invalidCollisionSoundUUID;
  4536. m_host.CollisionSoundType = -1; // disable all sounds
  4537. m_host.aggregateScriptEvents();
  4538. return;
  4539. }
  4540. // TODO: Parameter check logic required.
  4541. UUID soundId = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound);
  4542. if(soundId != UUID.Zero)
  4543. {
  4544. m_host.CollisionSound = soundId;
  4545. m_host.CollisionSoundVolume = (float)impact_volume;
  4546. m_host.CollisionSoundType = 1;
  4547. }
  4548. else
  4549. m_host.CollisionSoundType = -1;
  4550. m_host.aggregateScriptEvents();
  4551. }
  4552. public LSL_String llGetAnimation(LSL_Key id)
  4553. {
  4554. // This should only return a value if the avatar is in the same region
  4555. m_host.AddScriptLPS(1);
  4556. if(!UUID.TryParse(id, out UUID avatar))
  4557. return "";
  4558. ScenePresence presence = World.GetScenePresence(avatar);
  4559. if (presence == null)
  4560. return "";
  4561. if (m_host.RegionHandle == presence.RegionHandle)
  4562. {
  4563. if (presence != null)
  4564. {
  4565. // if (presence.SitGround)
  4566. // return "Sitting on Ground";
  4567. // if (presence.ParentID != 0 || presence.ParentUUID != UUID.Zero)
  4568. // return "Sitting";
  4569. string movementAnimation = presence.Animator.CurrentMovementAnimation;
  4570. if (MovementAnimationsForLSL.TryGetValue(movementAnimation, out string lslMovementAnimation))
  4571. return lslMovementAnimation;
  4572. }
  4573. }
  4574. return String.Empty;
  4575. }
  4576. public void llMessageLinked(int linknumber, int num, string msg, string id)
  4577. {
  4578. m_host.AddScriptLPS(1);
  4579. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  4580. UUID partItemID;
  4581. foreach (SceneObjectPart part in parts)
  4582. {
  4583. foreach (TaskInventoryItem item in part.Inventory.GetInventoryItems())
  4584. {
  4585. if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT)
  4586. {
  4587. partItemID = item.ItemID;
  4588. int linkNumber = m_host.LinkNum;
  4589. if (m_host.ParentGroup.PrimCount == 1)
  4590. linkNumber = 0;
  4591. object[] resobj = new object[]
  4592. {
  4593. new LSL_Integer(linkNumber), new LSL_Integer(num), new LSL_String(msg), new LSL_String(id)
  4594. };
  4595. m_ScriptEngine.PostScriptEvent(partItemID,
  4596. new EventParams("link_message",
  4597. resobj, new DetectParams[0]));
  4598. }
  4599. }
  4600. }
  4601. }
  4602. public void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local)
  4603. {
  4604. m_host.AddScriptLPS(1);
  4605. bool pushrestricted = World.RegionInfo.RegionSettings.RestrictPushing;
  4606. bool pushAllowed = false;
  4607. bool pusheeIsAvatar = false;
  4608. UUID targetID = UUID.Zero;
  4609. if (!UUID.TryParse(target,out targetID))
  4610. return;
  4611. ScenePresence pusheeav = null;
  4612. Vector3 PusheePos = Vector3.Zero;
  4613. SceneObjectPart pusheeob = null;
  4614. ScenePresence avatar = World.GetScenePresence(targetID);
  4615. if (avatar != null)
  4616. {
  4617. pusheeIsAvatar = true;
  4618. // Pushee doesn't have a physics actor
  4619. if (avatar.PhysicsActor == null)
  4620. return;
  4621. // Pushee is in GodMode this pushing object isn't owned by them
  4622. if (avatar.IsViewerUIGod && m_host.OwnerID != targetID)
  4623. return;
  4624. pusheeav = avatar;
  4625. // Find pushee position
  4626. // Pushee Linked?
  4627. SceneObjectPart sitPart = pusheeav.ParentPart;
  4628. if (sitPart != null)
  4629. PusheePos = sitPart.AbsolutePosition;
  4630. else
  4631. PusheePos = pusheeav.AbsolutePosition;
  4632. }
  4633. if (!pusheeIsAvatar)
  4634. {
  4635. // not an avatar so push is not affected by parcel flags
  4636. pusheeob = World.GetSceneObjectPart((UUID)target);
  4637. // We can't find object
  4638. if (pusheeob == null)
  4639. return;
  4640. // Object not pushable. Not an attachment and has no physics component
  4641. if (!pusheeob.ParentGroup.IsAttachment && pusheeob.PhysActor == null)
  4642. return;
  4643. PusheePos = pusheeob.AbsolutePosition;
  4644. pushAllowed = true;
  4645. }
  4646. else
  4647. {
  4648. if (pushrestricted)
  4649. {
  4650. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos);
  4651. // We didn't find the parcel but region is push restricted so assume it is NOT ok
  4652. if (targetlandObj == null)
  4653. return;
  4654. // Need provisions for Group Owned here
  4655. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  4656. targetlandObj.LandData.IsGroupOwned || m_host.OwnerID == targetID)
  4657. {
  4658. pushAllowed = true;
  4659. }
  4660. }
  4661. else
  4662. {
  4663. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos);
  4664. if (targetlandObj == null)
  4665. {
  4666. // We didn't find the parcel but region isn't push restricted so assume it's ok
  4667. pushAllowed = true;
  4668. }
  4669. else
  4670. {
  4671. // Parcel push restriction
  4672. if ((targetlandObj.LandData.Flags & (uint)ParcelFlags.RestrictPushObject) == (uint)ParcelFlags.RestrictPushObject)
  4673. {
  4674. // Need provisions for Group Owned here
  4675. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  4676. targetlandObj.LandData.IsGroupOwned ||
  4677. m_host.OwnerID == targetID)
  4678. {
  4679. pushAllowed = true;
  4680. }
  4681. //ParcelFlags.RestrictPushObject
  4682. //pushAllowed = true;
  4683. }
  4684. else
  4685. {
  4686. // Parcel isn't push restricted
  4687. pushAllowed = true;
  4688. }
  4689. }
  4690. }
  4691. }
  4692. if (pushAllowed)
  4693. {
  4694. float distance = (PusheePos - m_host.AbsolutePosition).Length();
  4695. float distance_term = distance * distance * distance; // Script Energy
  4696. // use total object mass and not part
  4697. float pusher_mass = m_host.ParentGroup.GetMass();
  4698. float PUSH_ATTENUATION_DISTANCE = 17f;
  4699. float PUSH_ATTENUATION_SCALE = 5f;
  4700. float distance_attenuation = 1f;
  4701. if (distance > PUSH_ATTENUATION_DISTANCE)
  4702. {
  4703. float normalized_units = 1f + (distance - PUSH_ATTENUATION_DISTANCE) / PUSH_ATTENUATION_SCALE;
  4704. distance_attenuation = 1f / normalized_units;
  4705. }
  4706. Vector3 applied_linear_impulse = impulse;
  4707. {
  4708. float impulse_length = applied_linear_impulse.Length();
  4709. float desired_energy = impulse_length * pusher_mass;
  4710. if (desired_energy > 0f)
  4711. desired_energy += distance_term;
  4712. float scaling_factor = 1f;
  4713. scaling_factor *= distance_attenuation;
  4714. applied_linear_impulse *= scaling_factor;
  4715. }
  4716. if (pusheeIsAvatar)
  4717. {
  4718. if (pusheeav != null)
  4719. {
  4720. PhysicsActor pa = pusheeav.PhysicsActor;
  4721. if (pa != null)
  4722. {
  4723. if (local != 0)
  4724. {
  4725. // applied_linear_impulse *= m_host.GetWorldRotation();
  4726. applied_linear_impulse *= pusheeav.GetWorldRotation();
  4727. }
  4728. pa.AddForce(applied_linear_impulse, true);
  4729. }
  4730. }
  4731. }
  4732. else
  4733. {
  4734. if (pusheeob != null)
  4735. {
  4736. if (pusheeob.PhysActor != null)
  4737. {
  4738. pusheeob.ApplyImpulse(applied_linear_impulse, local != 0);
  4739. }
  4740. }
  4741. }
  4742. }
  4743. }
  4744. public void llPassCollisions(int pass)
  4745. {
  4746. m_host.AddScriptLPS(1);
  4747. if (pass == 1)
  4748. {
  4749. m_host.PassCollisions = true;
  4750. }
  4751. else
  4752. {
  4753. m_host.PassCollisions = false;
  4754. }
  4755. }
  4756. public LSL_String llGetScriptName()
  4757. {
  4758. m_host.AddScriptLPS(1);
  4759. return m_item.Name ?? String.Empty;
  4760. }
  4761. public LSL_Integer llGetLinkNumberOfSides(int link)
  4762. {
  4763. m_host.AddScriptLPS(1);
  4764. SceneObjectPart linkedPart;
  4765. if (link == ScriptBaseClass.LINK_ROOT)
  4766. linkedPart = m_host.ParentGroup.RootPart;
  4767. else if (link == ScriptBaseClass.LINK_THIS)
  4768. linkedPart = m_host;
  4769. else
  4770. linkedPart = m_host.ParentGroup.GetLinkNumPart(link);
  4771. return GetNumberOfSides(linkedPart);
  4772. }
  4773. public LSL_Integer llGetNumberOfSides()
  4774. {
  4775. m_host.AddScriptLPS(1);
  4776. return m_host.GetNumberOfSides();
  4777. }
  4778. protected int GetNumberOfSides(SceneObjectPart part)
  4779. {
  4780. return part.GetNumberOfSides();
  4781. }
  4782. /* The new / changed functions were tested with the following LSL script:
  4783. default
  4784. {
  4785. state_entry()
  4786. {
  4787. rotation rot = llEuler2Rot(<0,70,0> * DEG_TO_RAD);
  4788. llOwnerSay("to get here, we rotate over: "+ (string) llRot2Axis(rot));
  4789. llOwnerSay("and we rotate for: "+ (llRot2Angle(rot) * RAD_TO_DEG));
  4790. // convert back and forth between quaternion <-> vector and angle
  4791. rotation newrot = llAxisAngle2Rot(llRot2Axis(rot),llRot2Angle(rot));
  4792. llOwnerSay("Old rotation was: "+(string) rot);
  4793. llOwnerSay("re-converted rotation is: "+(string) newrot);
  4794. llSetRot(rot); // to check the parameters in the prim
  4795. }
  4796. }
  4797. */
  4798. // Xantor 29/apr/2008
  4799. // Returns rotation described by rotating angle radians about axis.
  4800. // q = cos(a/2) + i (x * sin(a/2)) + j (y * sin(a/2)) + k (z * sin(a/2))
  4801. public LSL_Rotation llAxisAngle2Rot(LSL_Vector axis, double angle)
  4802. {
  4803. m_host.AddScriptLPS(1);
  4804. double x, y, z, s, t;
  4805. s = Math.Cos(angle * 0.5);
  4806. t = Math.Sin(angle * 0.5); // temp value to avoid 2 more sin() calcs
  4807. axis = LSL_Vector.Norm(axis);
  4808. x = axis.x * t;
  4809. y = axis.y * t;
  4810. z = axis.z * t;
  4811. return new LSL_Rotation(x,y,z,s);
  4812. }
  4813. /// <summary>
  4814. /// Returns the axis of rotation for a quaternion
  4815. /// </summary>
  4816. /// <returns></returns>
  4817. /// <param name='rot'></param>
  4818. public LSL_Vector llRot2Axis(LSL_Rotation rot)
  4819. {
  4820. m_host.AddScriptLPS(1);
  4821. rot.Normalize();
  4822. double s = Math.Sqrt(1 - rot.s * rot.s);
  4823. if (s < 1e-8)
  4824. return new LSL_Vector(0, 0, 0);
  4825. double invS = 1.0 / s;
  4826. if (rot.s < 0)
  4827. invS = -invS;
  4828. return new LSL_Vector(rot.x * invS, rot.y * invS, rot.z * invS);
  4829. }
  4830. // Returns the angle of a quaternion (see llRot2Axis for the axis)
  4831. public LSL_Float llRot2Angle(LSL_Rotation rot)
  4832. {
  4833. m_host.AddScriptLPS(1);
  4834. rot.Normalize();
  4835. double angle = 2 * Math.Acos(rot.s);
  4836. if (angle > Math.PI)
  4837. angle = 2 * Math.PI - angle;
  4838. return angle;
  4839. }
  4840. public LSL_Float llAcos(LSL_Float val)
  4841. {
  4842. m_host.AddScriptLPS(1);
  4843. return (double)Math.Acos(val);
  4844. }
  4845. public LSL_Float llAsin(LSL_Float val)
  4846. {
  4847. m_host.AddScriptLPS(1);
  4848. return (double)Math.Asin(val);
  4849. }
  4850. // jcochran 5/jan/2012
  4851. public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b)
  4852. {
  4853. m_host.AddScriptLPS(1);
  4854. double aa = (a.x * a.x + a.y * a.y + a.z * a.z + a.s * a.s);
  4855. double bb = (b.x * b.x + b.y * b.y + b.z * b.z + b.s * b.s);
  4856. double aa_bb = aa * bb;
  4857. if (aa_bb == 0) return 0.0;
  4858. double ab = (a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s);
  4859. double quotient = (ab * ab) / aa_bb;
  4860. if (quotient >= 1.0) return 0.0;
  4861. return Math.Acos(2 * quotient - 1);
  4862. }
  4863. public LSL_Key llGetInventoryKey(string name)
  4864. {
  4865. m_host.AddScriptLPS(1);
  4866. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  4867. if (item == null)
  4868. return ScriptBaseClass.NULL_KEY;
  4869. if ((item.CurrentPermissions
  4870. & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  4871. == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  4872. {
  4873. return item.AssetID.ToString();
  4874. }
  4875. return ScriptBaseClass.NULL_KEY;
  4876. }
  4877. public void llAllowInventoryDrop(LSL_Integer add)
  4878. {
  4879. m_host.AddScriptLPS(1);
  4880. if (add != 0)
  4881. m_host.ParentGroup.RootPart.AllowedDrop = true;
  4882. else
  4883. m_host.ParentGroup.RootPart.AllowedDrop = false;
  4884. // Update the object flags
  4885. m_host.ParentGroup.RootPart.aggregateScriptEvents();
  4886. }
  4887. public LSL_Vector llGetTextureOffset(int face)
  4888. {
  4889. m_host.AddScriptLPS(1);
  4890. return GetTextureOffset(m_host, face);
  4891. }
  4892. protected LSL_Vector GetTextureOffset(SceneObjectPart part, int face)
  4893. {
  4894. Primitive.TextureEntry tex = part.Shape.Textures;
  4895. LSL_Vector offset = new LSL_Vector();
  4896. if (face == ScriptBaseClass.ALL_SIDES)
  4897. {
  4898. face = 0;
  4899. }
  4900. if (face >= 0 && face < GetNumberOfSides(part))
  4901. {
  4902. offset.x = tex.GetFace((uint)face).OffsetU;
  4903. offset.y = tex.GetFace((uint)face).OffsetV;
  4904. offset.z = 0.0;
  4905. return offset;
  4906. }
  4907. else
  4908. {
  4909. return offset;
  4910. }
  4911. }
  4912. public LSL_Vector llGetTextureScale(int side)
  4913. {
  4914. m_host.AddScriptLPS(1);
  4915. Primitive.TextureEntry tex = m_host.Shape.Textures;
  4916. LSL_Vector scale;
  4917. if (side == -1)
  4918. {
  4919. side = 0;
  4920. }
  4921. scale.x = tex.GetFace((uint)side).RepeatU;
  4922. scale.y = tex.GetFace((uint)side).RepeatV;
  4923. scale.z = 0.0;
  4924. return scale;
  4925. }
  4926. public LSL_Float llGetTextureRot(int face)
  4927. {
  4928. m_host.AddScriptLPS(1);
  4929. return GetTextureRot(m_host, face);
  4930. }
  4931. protected LSL_Float GetTextureRot(SceneObjectPart part, int face)
  4932. {
  4933. Primitive.TextureEntry tex = part.Shape.Textures;
  4934. if (face == -1)
  4935. {
  4936. face = 0;
  4937. }
  4938. if (face >= 0 && face < GetNumberOfSides(part))
  4939. {
  4940. return tex.GetFace((uint)face).Rotation;
  4941. }
  4942. else
  4943. {
  4944. return 0.0;
  4945. }
  4946. }
  4947. public LSL_Integer llSubStringIndex(string source, string pattern)
  4948. {
  4949. m_host.AddScriptLPS(1);
  4950. if (string.IsNullOrEmpty(source))
  4951. return -1;
  4952. if (string.IsNullOrEmpty(pattern))
  4953. return 0;
  4954. return source.IndexOf(pattern);
  4955. }
  4956. public LSL_Key llGetOwnerKey(string id)
  4957. {
  4958. m_host.AddScriptLPS(1);
  4959. UUID key = new UUID();
  4960. if (UUID.TryParse(id, out key))
  4961. {
  4962. try
  4963. {
  4964. SceneObjectPart obj = World.GetSceneObjectPart(key);
  4965. if (obj == null)
  4966. return id; // the key is for an agent so just return the key
  4967. else
  4968. return obj.OwnerID.ToString();
  4969. }
  4970. catch (KeyNotFoundException)
  4971. {
  4972. return id; // The Object/Agent not in the region so just return the key
  4973. }
  4974. }
  4975. else
  4976. {
  4977. return ScriptBaseClass.NULL_KEY;
  4978. }
  4979. }
  4980. public LSL_Vector llGetCenterOfMass()
  4981. {
  4982. m_host.AddScriptLPS(1);
  4983. return new LSL_Vector(m_host.GetCenterOfMass());
  4984. }
  4985. public LSL_List llListSort(LSL_List src, int stride, int ascending)
  4986. {
  4987. m_host.AddScriptLPS(1);
  4988. if (stride <= 0)
  4989. {
  4990. stride = 1;
  4991. }
  4992. return src.Sort(stride, ascending);
  4993. }
  4994. public LSL_Integer llGetListLength(LSL_List src)
  4995. {
  4996. m_host.AddScriptLPS(1);
  4997. return src.Length;
  4998. }
  4999. public LSL_Integer llList2Integer(LSL_List src, int index)
  5000. {
  5001. m_host.AddScriptLPS(1);
  5002. if (index < 0)
  5003. index = src.Length + index;
  5004. if (index >= src.Length || index < 0)
  5005. return 0;
  5006. object item = src.Data[index];
  5007. // Vectors & Rotations always return zero in SL, but
  5008. // keys don't always return zero, it seems to be a bit complex.
  5009. if (item is LSL_Vector || item is LSL_Rotation)
  5010. return 0;
  5011. try
  5012. {
  5013. if (item is LSL_Integer)
  5014. return (LSL_Integer)item;
  5015. else if (item is LSL_Float)
  5016. return Convert.ToInt32(((LSL_Float)item).value);;
  5017. return new LSL_Integer(item.ToString());
  5018. }
  5019. catch (FormatException)
  5020. {
  5021. return 0;
  5022. }
  5023. }
  5024. public LSL_Float llList2Float(LSL_List src, int index)
  5025. {
  5026. m_host.AddScriptLPS(1);
  5027. if (index < 0)
  5028. index = src.Length + index;
  5029. if (index >= src.Length || index < 0)
  5030. return 0;
  5031. object item = src.Data[index];
  5032. // Vectors & Rotations always return zero in SL
  5033. if(item is LSL_Vector || item is LSL_Rotation)
  5034. return 0;
  5035. // valid keys seem to get parsed as integers then converted to floats
  5036. if (item is LSL_Key)
  5037. {
  5038. string s = item.ToString();
  5039. if(UUID.TryParse(s, out UUID uuidt))
  5040. return Convert.ToDouble(new LSL_Integer(s).value);
  5041. // we can't do this because a string is also a LSL_Key for now :(
  5042. // else
  5043. // return 0;
  5044. }
  5045. try
  5046. {
  5047. if (item is LSL_Integer)
  5048. return Convert.ToDouble(((LSL_Integer)item).value);
  5049. else if (item is LSL_Float)
  5050. return Convert.ToDouble(((LSL_Float)item).value);
  5051. else if (item is LSL_String)
  5052. {
  5053. string str = ((LSL_String)item).m_string;
  5054. Match m = Regex.Match(str, "^\\s*(-?\\+?[,0-9]+\\.?[0-9]*)");
  5055. if (m != Match.Empty)
  5056. {
  5057. str = m.Value;
  5058. if (!Double.TryParse(str, out double d))
  5059. return 0.0;
  5060. return d;
  5061. }
  5062. return 0.0;
  5063. }
  5064. return Convert.ToDouble(item);
  5065. }
  5066. catch (FormatException)
  5067. {
  5068. return 0.0;
  5069. }
  5070. }
  5071. public LSL_String llList2String(LSL_List src, int index)
  5072. {
  5073. m_host.AddScriptLPS(1);
  5074. if (index < 0)
  5075. index = src.Length + index;
  5076. if (index >= src.Length || index < 0)
  5077. return String.Empty;
  5078. return src.Data[index].ToString();
  5079. }
  5080. public LSL_Key llList2Key(LSL_List src, int index)
  5081. {
  5082. m_host.AddScriptLPS(1);
  5083. if (index < 0)
  5084. index = src.Length + index;
  5085. if (index >= src.Length || index < 0)
  5086. return String.Empty;
  5087. object item = src.Data[index];
  5088. // SL spits out an empty string for types other than key & string
  5089. // At the time of patching, LSL_Key is currently LSL_String,
  5090. // so the OR check may be a little redundant, but it's being done
  5091. // for completion and should LSL_Key ever be implemented
  5092. // as it's own struct
  5093. // NOTE: 3rd case is needed because a NULL_KEY comes through as
  5094. // type 'obj' and wrongly returns ""
  5095. if (!(item is LSL_String ||
  5096. item is LSL_Key ||
  5097. item.ToString() == "00000000-0000-0000-0000-000000000000"))
  5098. {
  5099. return String.Empty;
  5100. }
  5101. return item.ToString();
  5102. }
  5103. public LSL_Vector llList2Vector(LSL_List src, int index)
  5104. {
  5105. m_host.AddScriptLPS(1);
  5106. if (index < 0)
  5107. index = src.Length + index;
  5108. if (index >= src.Length || index < 0)
  5109. return new LSL_Vector(0, 0, 0);
  5110. object item = src.Data[index];
  5111. if (item.GetType() == typeof(LSL_Vector))
  5112. return (LSL_Vector)item;
  5113. // SL spits always out ZERO_VECTOR for anything other than
  5114. // strings or vectors. Although keys always return ZERO_VECTOR,
  5115. // it is currently difficult to make the distinction between
  5116. // a string, a key as string and a string that by coincidence
  5117. // is a string, so we're going to leave that up to the
  5118. // LSL_Vector constructor.
  5119. if(item is LSL_Vector)
  5120. return (LSL_Vector) item;
  5121. if (item is LSL_String || item is string) // xengine sees string
  5122. return new LSL_Vector(item.ToString());
  5123. return new LSL_Vector(0, 0, 0);
  5124. }
  5125. public LSL_Rotation llList2Rot(LSL_List src, int index)
  5126. {
  5127. m_host.AddScriptLPS(1);
  5128. if (index < 0)
  5129. index = src.Length + index;
  5130. if (index >= src.Length || index < 0)
  5131. return new LSL_Rotation(0, 0, 0, 1);
  5132. object item = src.Data[index];
  5133. // SL spits always out ZERO_ROTATION for anything other than
  5134. // strings or vectors. Although keys always return ZERO_ROTATION,
  5135. // it is currently difficult to make the distinction between
  5136. // a string, a key as string and a string that by coincidence
  5137. // is a string, so we're going to leave that up to the
  5138. // LSL_Rotation constructor.
  5139. if (item.GetType() == typeof(LSL_Rotation))
  5140. return (LSL_Rotation)item;
  5141. if (item is LSL_String || item is string) // xengine sees string)
  5142. return new LSL_Rotation(src.Data[index].ToString());
  5143. return new LSL_Rotation(0, 0, 0, 1);
  5144. }
  5145. public LSL_List llList2List(LSL_List src, int start, int end)
  5146. {
  5147. m_host.AddScriptLPS(1);
  5148. return src.GetSublist(start, end);
  5149. }
  5150. public LSL_List llDeleteSubList(LSL_List src, int start, int end)
  5151. {
  5152. return src.DeleteSublist(start, end);
  5153. }
  5154. public LSL_Integer llGetListEntryType(LSL_List src, int index)
  5155. {
  5156. m_host.AddScriptLPS(1);
  5157. if (index < 0)
  5158. {
  5159. index = src.Length + index;
  5160. }
  5161. if (index >= src.Length)
  5162. {
  5163. return 0;
  5164. }
  5165. if (src.Data[index] is LSL_Integer || src.Data[index] is Int32)
  5166. return 1;
  5167. if (src.Data[index] is LSL_Float || src.Data[index] is Single || src.Data[index] is Double)
  5168. return 2;
  5169. if (src.Data[index] is LSL_String || src.Data[index] is String)
  5170. {
  5171. if (UUID.TryParse(src.Data[index].ToString(), out UUID tuuid))
  5172. {
  5173. return 4;
  5174. }
  5175. else
  5176. {
  5177. return 3;
  5178. }
  5179. }
  5180. if (src.Data[index] is LSL_Vector)
  5181. return 5;
  5182. if (src.Data[index] is LSL_Rotation)
  5183. return 6;
  5184. if (src.Data[index] is LSL_List)
  5185. return 7;
  5186. return 0;
  5187. }
  5188. /// <summary>
  5189. /// Process the supplied list and return the
  5190. /// content of the list formatted as a comma
  5191. /// separated list. There is a space after
  5192. /// each comma.
  5193. /// </summary>
  5194. public LSL_String llList2CSV(LSL_List src)
  5195. {
  5196. m_host.AddScriptLPS(1);
  5197. return string.Join(", ",
  5198. (new List<object>(src.Data)).ConvertAll<string>(o =>
  5199. {
  5200. return o.ToString();
  5201. }).ToArray());
  5202. }
  5203. /// <summary>
  5204. /// The supplied string is scanned for commas
  5205. /// and converted into a list. Commas are only
  5206. /// effective if they are encountered outside
  5207. /// of '<' '>' delimiters. Any whitespace
  5208. /// before or after an element is trimmed.
  5209. /// </summary>
  5210. public LSL_List llCSV2List(string src)
  5211. {
  5212. LSL_List result = new LSL_List();
  5213. int parens = 0;
  5214. int start = 0;
  5215. int length = 0;
  5216. m_host.AddScriptLPS(1);
  5217. for (int i = 0; i < src.Length; i++)
  5218. {
  5219. switch (src[i])
  5220. {
  5221. case '<':
  5222. parens++;
  5223. length++;
  5224. break;
  5225. case '>':
  5226. if (parens > 0)
  5227. parens--;
  5228. length++;
  5229. break;
  5230. case ',':
  5231. if (parens == 0)
  5232. {
  5233. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  5234. start += length+1;
  5235. length = 0;
  5236. }
  5237. else
  5238. {
  5239. length++;
  5240. }
  5241. break;
  5242. default:
  5243. length++;
  5244. break;
  5245. }
  5246. }
  5247. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  5248. return result;
  5249. }
  5250. /// <summary>
  5251. /// Randomizes the list, be arbitrarily reordering
  5252. /// sublists of stride elements. As the stride approaches
  5253. /// the size of the list, the options become very
  5254. /// limited.
  5255. /// </summary>
  5256. /// <remarks>
  5257. /// This could take a while for very large list
  5258. /// sizes.
  5259. /// </remarks>
  5260. public LSL_List llListRandomize(LSL_List src, int stride)
  5261. {
  5262. LSL_List result;
  5263. BetterRandom rand = new BetterRandom();
  5264. int chunkk;
  5265. int[] chunks;
  5266. m_host.AddScriptLPS(1);
  5267. if (stride <= 0)
  5268. {
  5269. stride = 1;
  5270. }
  5271. // Stride MUST be a factor of the list length
  5272. // If not, then return the src list. This also
  5273. // traps those cases where stride > length.
  5274. if (src.Length != stride && src.Length % stride == 0)
  5275. {
  5276. chunkk = src.Length/stride;
  5277. chunks = new int[chunkk];
  5278. for (int i = 0; i < chunkk; i++)
  5279. {
  5280. chunks[i] = i;
  5281. }
  5282. // Knuth shuffle the chunkk index
  5283. for (int i = chunkk - 1; i > 0; i--)
  5284. {
  5285. // Elect an unrandomized chunk to swap
  5286. int index = rand.Next(i + 1);
  5287. // and swap position with first unrandomized chunk
  5288. int tmp = chunks[i];
  5289. chunks[i] = chunks[index];
  5290. chunks[index] = tmp;
  5291. }
  5292. // Construct the randomized list
  5293. result = new LSL_List();
  5294. for (int i = 0; i < chunkk; i++)
  5295. {
  5296. for (int j = 0; j < stride; j++)
  5297. {
  5298. result.Add(src.Data[chunks[i] * stride + j]);
  5299. }
  5300. }
  5301. }
  5302. else
  5303. {
  5304. object[] array = new object[src.Length];
  5305. Array.Copy(src.Data, 0, array, 0, src.Length);
  5306. result = new LSL_List(array);
  5307. }
  5308. return result;
  5309. }
  5310. /// <summary>
  5311. /// Elements in the source list starting with 0 and then
  5312. /// every i+stride. If the stride is negative then the scan
  5313. /// is backwards producing an inverted result.
  5314. /// Only those elements that are also in the specified
  5315. /// range are included in the result.
  5316. /// </summary>
  5317. public LSL_List llList2ListStrided(LSL_List src, int start, int end, int stride)
  5318. {
  5319. LSL_List result = new LSL_List();
  5320. int[] si = new int[2];
  5321. int[] ei = new int[2];
  5322. bool twopass = false;
  5323. m_host.AddScriptLPS(1);
  5324. // First step is always to deal with negative indices
  5325. if (start < 0)
  5326. start = src.Length+start;
  5327. if (end < 0)
  5328. end = src.Length+end;
  5329. // Out of bounds indices are OK, just trim them
  5330. // accordingly
  5331. if (start > src.Length)
  5332. start = src.Length;
  5333. if (end > src.Length)
  5334. end = src.Length;
  5335. if (stride == 0)
  5336. stride = 1;
  5337. // There may be one or two ranges to be considered
  5338. if (start != end)
  5339. {
  5340. if (start <= end)
  5341. {
  5342. si[0] = start;
  5343. ei[0] = end;
  5344. }
  5345. else
  5346. {
  5347. si[1] = start;
  5348. ei[1] = src.Length;
  5349. si[0] = 0;
  5350. ei[0] = end;
  5351. twopass = true;
  5352. }
  5353. // The scan always starts from the beginning of the
  5354. // source list, but members are only selected if they
  5355. // fall within the specified sub-range. The specified
  5356. // range values are inclusive.
  5357. // A negative stride reverses the direction of the
  5358. // scan producing an inverted list as a result.
  5359. if (stride > 0)
  5360. {
  5361. for (int i = 0; i < src.Length; i += stride)
  5362. {
  5363. if (i<=ei[0] && i>=si[0])
  5364. result.Add(src.Data[i]);
  5365. if (twopass && i>=si[1] && i<=ei[1])
  5366. result.Add(src.Data[i]);
  5367. }
  5368. }
  5369. else if (stride < 0)
  5370. {
  5371. for (int i = src.Length - 1; i >= 0; i += stride)
  5372. {
  5373. if (i <= ei[0] && i >= si[0])
  5374. result.Add(src.Data[i]);
  5375. if (twopass && i >= si[1] && i <= ei[1])
  5376. result.Add(src.Data[i]);
  5377. }
  5378. }
  5379. }
  5380. else
  5381. {
  5382. if (start%stride == 0)
  5383. {
  5384. result.Add(src.Data[start]);
  5385. }
  5386. }
  5387. return result;
  5388. }
  5389. public LSL_Integer llGetRegionAgentCount()
  5390. {
  5391. m_host.AddScriptLPS(1);
  5392. int count = 0;
  5393. World.ForEachRootScenePresence(delegate(ScenePresence sp) {
  5394. count++;
  5395. });
  5396. return new LSL_Integer(count);
  5397. }
  5398. public LSL_Vector llGetRegionCorner()
  5399. {
  5400. m_host.AddScriptLPS(1);
  5401. return new LSL_Vector(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
  5402. }
  5403. public LSL_String llGetEnv(LSL_String name)
  5404. {
  5405. m_host.AddScriptLPS(1);
  5406. string sname = name;
  5407. sname = sname.ToLower();
  5408. switch(sname)
  5409. {
  5410. case "agent_limit":
  5411. return World.RegionInfo.RegionSettings.AgentLimit.ToString();
  5412. case "dynamic_pathfinding":
  5413. return "0";
  5414. case "estate_id":
  5415. return World.RegionInfo.EstateSettings.EstateID.ToString();
  5416. case "estate_name":
  5417. return World.RegionInfo.EstateSettings.EstateName;
  5418. case "frame_number":
  5419. return World.Frame.ToString();
  5420. case "region_cpu_ratio":
  5421. return "1";
  5422. case "region_idle":
  5423. return "0";
  5424. case "region_product_name":
  5425. if (World.RegionInfo.RegionType != String.Empty)
  5426. return World.RegionInfo.RegionType;
  5427. else
  5428. return "";
  5429. case "region_product_sku":
  5430. return "OpenSim";
  5431. case "region_start_time":
  5432. return World.UnixStartTime.ToString();
  5433. case "region_up_time":
  5434. int time = Util.UnixTimeSinceEpoch() - World.UnixStartTime;
  5435. return time.ToString();
  5436. case "sim_channel":
  5437. return "OpenSim";
  5438. case "sim_version":
  5439. return World.GetSimulatorVersion();
  5440. case "simulator_hostname":
  5441. IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
  5442. return UrlModule.ExternalHostNameForLSL;
  5443. case "region_max_prims":
  5444. return World.RegionInfo.ObjectCapacity.ToString();
  5445. case "region_object_bonus":
  5446. return World.RegionInfo.RegionSettings.ObjectBonus.ToString();
  5447. case "whisper_range":
  5448. return m_whisperdistance.ToString();
  5449. case "chat_range":
  5450. return m_saydistance.ToString();
  5451. case "shout_range":
  5452. return m_shoutdistance.ToString();
  5453. default:
  5454. return "";
  5455. }
  5456. }
  5457. /// <summary>
  5458. /// Insert the list identified by <paramref name="src"/> into the
  5459. /// list designated by <paramref name="dest"/> such that the first
  5460. /// new element has the index specified by <paramref name="index"/>
  5461. /// </summary>
  5462. public LSL_List llListInsertList(LSL_List dest, LSL_List src, int index)
  5463. {
  5464. LSL_List pref;
  5465. LSL_List suff;
  5466. m_host.AddScriptLPS(1);
  5467. if (index < 0)
  5468. {
  5469. index = index+dest.Length;
  5470. if (index < 0)
  5471. {
  5472. index = 0;
  5473. }
  5474. }
  5475. if (index != 0)
  5476. {
  5477. pref = dest.GetSublist(0,index-1);
  5478. if (index < dest.Length)
  5479. {
  5480. suff = dest.GetSublist(index,-1);
  5481. return pref + src + suff;
  5482. }
  5483. else
  5484. {
  5485. return pref + src;
  5486. }
  5487. }
  5488. else
  5489. {
  5490. if (index < dest.Length)
  5491. {
  5492. suff = dest.GetSublist(index,-1);
  5493. return src + suff;
  5494. }
  5495. else
  5496. {
  5497. return src;
  5498. }
  5499. }
  5500. }
  5501. /// <summary>
  5502. /// Returns the index of the first occurrence of test
  5503. /// in src.
  5504. /// </summary>
  5505. /// <param name="src">Source list</param>
  5506. /// <param name="test">List to search for</param>
  5507. /// <returns>
  5508. /// The index number of the point in src where test was found if it was found.
  5509. /// Otherwise returns -1
  5510. /// </returns>
  5511. public LSL_Integer llListFindList(LSL_List src, LSL_List test)
  5512. {
  5513. int index = -1;
  5514. int length = src.Length - test.Length + 1;
  5515. m_host.AddScriptLPS(1);
  5516. // If either list is empty, do not match
  5517. if (src.Length != 0 && test.Length != 0)
  5518. {
  5519. for (int i = 0; i < length; i++)
  5520. {
  5521. int needle = llGetListEntryType(test, 0).value;
  5522. int haystack = llGetListEntryType(src, i).value;
  5523. // Why this piece of insanity? This is because most script constants are C# value types (e.g. int)
  5524. // rather than wrapped LSL types. Such a script constant does not have int.Equal(LSL_Integer) code
  5525. // and so the comparison fails even if the LSL_Integer conceptually has the same value.
  5526. // Therefore, here we test Equals on both the source and destination objects.
  5527. // However, a future better approach may be use LSL struct script constants (e.g. LSL_Integer(1)).
  5528. if ((needle == haystack) && (src.Data[i].Equals(test.Data[0]) || test.Data[0].Equals(src.Data[i])))
  5529. {
  5530. int j;
  5531. for (j = 1; j < test.Length; j++)
  5532. {
  5533. needle = llGetListEntryType(test, j).value;
  5534. haystack = llGetListEntryType(src, i+j).value;
  5535. if ((needle != haystack) || (!(src.Data[i+j].Equals(test.Data[j]) || test.Data[j].Equals(src.Data[i+j]))))
  5536. break;
  5537. }
  5538. if (j == test.Length)
  5539. {
  5540. index = i;
  5541. break;
  5542. }
  5543. }
  5544. }
  5545. }
  5546. return index;
  5547. }
  5548. public LSL_String llGetObjectName()
  5549. {
  5550. m_host.AddScriptLPS(1);
  5551. return m_host.Name ?? string.Empty;
  5552. }
  5553. public void llSetObjectName(string name)
  5554. {
  5555. m_host.AddScriptLPS(1);
  5556. m_host.Name = name ?? String.Empty;
  5557. }
  5558. public LSL_String llGetDate()
  5559. {
  5560. m_host.AddScriptLPS(1);
  5561. DateTime date = DateTime.Now.ToUniversalTime();
  5562. string result = date.ToString("yyyy-MM-dd");
  5563. return result;
  5564. }
  5565. public LSL_Integer llEdgeOfWorld(LSL_Vector pos, LSL_Vector dir)
  5566. {
  5567. m_host.AddScriptLPS(1);
  5568. if(dir.x == 0 && dir.y == 0)
  5569. return 1; // SL wiki
  5570. float rsx = World.RegionInfo.RegionSizeX;
  5571. float rsy = World.RegionInfo.RegionSizeY;
  5572. // can understand what sl does if position is not in region, so do something :)
  5573. float px = (float)Util.Clamp(pos.x, 0.5, rsx - 0.5);
  5574. float py = (float)Util.Clamp(pos.y, 0.5, rsy - 0.5);
  5575. float ex, ey;
  5576. if (dir.x == 0)
  5577. {
  5578. ex = px;
  5579. ey = dir.y > 0 ? rsy + 1.0f : -1.0f;
  5580. }
  5581. else if(dir.y == 0)
  5582. {
  5583. ex = dir.x > 0 ? rsx + 1.0f : -1.0f;
  5584. ey = py;
  5585. }
  5586. else
  5587. {
  5588. float dx = (float) dir.x;
  5589. float dy = (float) dir.y;
  5590. float t1 = dx * dx + dy * dy;
  5591. t1 = (float)Math.Sqrt(t1);
  5592. dx /= t1;
  5593. dy /= t1;
  5594. if(dx > 0)
  5595. t1 = (rsx + 1f - px)/dx;
  5596. else
  5597. t1 = -(px + 1f)/dx;
  5598. float t2;
  5599. if(dy > 0)
  5600. t2 = (rsy + 1f - py)/dy;
  5601. else
  5602. t2 = -(py + 1f)/dy;
  5603. if(t1 > t2)
  5604. t1 = t2;
  5605. ex = px + t1 * dx;
  5606. ey = py + t1 * dy;
  5607. }
  5608. ex += World.RegionInfo.WorldLocX;
  5609. ey += World.RegionInfo.WorldLocY;
  5610. if(World.GridService.GetRegionByPosition(RegionScopeID, (int)ex, (int)ey) != null)
  5611. return 0;
  5612. return 1;
  5613. }
  5614. /// <summary>
  5615. /// Not fully implemented yet. Still to do:-
  5616. /// AGENT_BUSY
  5617. /// Remove as they are done
  5618. /// </summary>
  5619. public LSL_Integer llGetAgentInfo(LSL_Key id)
  5620. {
  5621. m_host.AddScriptLPS(1);
  5622. UUID key = new UUID();
  5623. if (!UUID.TryParse(id, out key))
  5624. {
  5625. return 0;
  5626. }
  5627. int flags = 0;
  5628. ScenePresence agent = World.GetScenePresence(key);
  5629. if (agent == null)
  5630. {
  5631. return 0;
  5632. }
  5633. if (agent.IsChildAgent || agent.IsDeleted)
  5634. return 0; // Fail if they are not in the same region
  5635. try
  5636. {
  5637. // note: in OpenSim, sitting seems to cancel AGENT_ALWAYS_RUN, unlike SL
  5638. if (agent.SetAlwaysRun)
  5639. {
  5640. flags |= ScriptBaseClass.AGENT_ALWAYS_RUN;
  5641. }
  5642. if (agent.HasAttachments())
  5643. {
  5644. flags |= ScriptBaseClass.AGENT_ATTACHMENTS;
  5645. if (agent.HasScriptedAttachments())
  5646. flags |= ScriptBaseClass.AGENT_SCRIPTED;
  5647. }
  5648. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0)
  5649. {
  5650. flags |= ScriptBaseClass.AGENT_FLYING;
  5651. flags |= ScriptBaseClass.AGENT_IN_AIR; // flying always implies in-air, even if colliding with e.g. a wall
  5652. }
  5653. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AWAY) != 0)
  5654. {
  5655. flags |= ScriptBaseClass.AGENT_AWAY;
  5656. }
  5657. UUID busy = new UUID("efcf670c-2d18-8128-973a-034ebc806b67");
  5658. UUID[] anims = agent.Animator.GetAnimationArray();
  5659. if (Array.Exists<UUID>(anims, a => { return a == busy; }))
  5660. {
  5661. flags |= ScriptBaseClass.AGENT_BUSY;
  5662. }
  5663. // seems to get unset, even if in mouselook, when avatar is sitting on a prim???
  5664. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  5665. {
  5666. flags |= ScriptBaseClass.AGENT_MOUSELOOK;
  5667. }
  5668. if ((agent.State & (byte)AgentState.Typing) != (byte)0)
  5669. {
  5670. flags |= ScriptBaseClass.AGENT_TYPING;
  5671. }
  5672. string agentMovementAnimation = agent.Animator.CurrentMovementAnimation;
  5673. if (agentMovementAnimation == "CROUCH")
  5674. {
  5675. flags |= ScriptBaseClass.AGENT_CROUCHING;
  5676. }
  5677. if (agentMovementAnimation == "WALK" || agentMovementAnimation == "CROUCHWALK")
  5678. {
  5679. flags |= ScriptBaseClass.AGENT_WALKING;
  5680. }
  5681. // not colliding implies in air. Note: flying also implies in-air, even if colliding (see above)
  5682. // note: AGENT_IN_AIR and AGENT_WALKING seem to be mutually exclusive states in SL.
  5683. // note: this may need some tweaking when walking downhill. you "fall down" for a brief instant
  5684. // and don't collide when walking downhill, which instantly registers as in-air, briefly. should
  5685. // there be some minimum non-collision threshold time before claiming the avatar is in-air?
  5686. if ((flags & ScriptBaseClass.AGENT_WALKING) == 0 && !agent.IsColliding )
  5687. {
  5688. flags |= ScriptBaseClass.AGENT_IN_AIR;
  5689. }
  5690. if (agent.ParentPart != null)
  5691. {
  5692. flags |= ScriptBaseClass.AGENT_ON_OBJECT;
  5693. flags |= ScriptBaseClass.AGENT_SITTING;
  5694. }
  5695. if (agent.Animator.Animations.ImplicitDefaultAnimation.AnimID
  5696. == DefaultAvatarAnimations.AnimsUUIDbyName["SIT_GROUND_CONSTRAINED"])
  5697. {
  5698. flags |= ScriptBaseClass.AGENT_SITTING;
  5699. }
  5700. if (agent.Appearance.VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MALE] > 0)
  5701. {
  5702. flags |= ScriptBaseClass.AGENT_MALE;
  5703. }
  5704. }
  5705. catch
  5706. {
  5707. return 0;
  5708. }
  5709. return flags;
  5710. }
  5711. public LSL_String llGetAgentLanguage(LSL_Key id)
  5712. {
  5713. // This should only return a value if the avatar is in the same region, but eh. idc.
  5714. m_host.AddScriptLPS(1);
  5715. if (World.AgentPreferencesService == null)
  5716. {
  5717. Error("llGetAgentLanguage", "No AgentPreferencesService present");
  5718. }
  5719. else
  5720. {
  5721. UUID key = new UUID();
  5722. if (UUID.TryParse(id, out key))
  5723. {
  5724. return new LSL_String(World.AgentPreferencesService.GetLang(key));
  5725. }
  5726. }
  5727. return new LSL_String("en-us");
  5728. }
  5729. /// <summary>
  5730. /// http://wiki.secondlife.com/wiki/LlGetAgentList
  5731. /// The list of options is currently not used in SL
  5732. /// scope is one of:-
  5733. /// AGENT_LIST_REGION - all in the region
  5734. /// AGENT_LIST_PARCEL - all in the same parcel as the scripted object
  5735. /// AGENT_LIST_PARCEL_OWNER - all in any parcel owned by the owner of the
  5736. /// current parcel.
  5737. /// AGENT_LIST_EXCLUDENPC ignore NPCs (bit mask)
  5738. /// </summary>
  5739. public LSL_List llGetAgentList(LSL_Integer scope, LSL_List options)
  5740. {
  5741. m_host.AddScriptLPS(1);
  5742. // do our bit masks part
  5743. bool noNPC = (scope & ScriptBaseClass.AGENT_LIST_EXCLUDENPC) !=0;
  5744. // remove bit masks part
  5745. scope &= ~ ScriptBaseClass.AGENT_LIST_EXCLUDENPC;
  5746. // the constants are 1, 2 and 4 so bits are being set, but you
  5747. // get an error "INVALID_SCOPE" if it is anything but 1, 2 and 4
  5748. bool regionWide = scope == ScriptBaseClass.AGENT_LIST_REGION;
  5749. bool parcelOwned = scope == ScriptBaseClass.AGENT_LIST_PARCEL_OWNER;
  5750. bool parcel = scope == ScriptBaseClass.AGENT_LIST_PARCEL;
  5751. LSL_List result = new LSL_List();
  5752. if (!regionWide && !parcelOwned && !parcel)
  5753. {
  5754. result.Add("INVALID_SCOPE");
  5755. return result;
  5756. }
  5757. ILandObject land;
  5758. UUID id = UUID.Zero;
  5759. if (parcel || parcelOwned)
  5760. {
  5761. land = World.LandChannel.GetLandObject(m_host.ParentGroup.RootPart.GetWorldPosition());
  5762. if (land == null)
  5763. {
  5764. id = UUID.Zero;
  5765. }
  5766. else
  5767. {
  5768. if (parcelOwned)
  5769. {
  5770. id = land.LandData.OwnerID;
  5771. }
  5772. else
  5773. {
  5774. id = land.LandData.GlobalID;
  5775. }
  5776. }
  5777. }
  5778. World.ForEachRootScenePresence(
  5779. delegate (ScenePresence ssp)
  5780. {
  5781. if(noNPC && ssp.IsNPC)
  5782. return;
  5783. // Gods are not listed in SL
  5784. if (!ssp.IsDeleted && !ssp.IsViewerUIGod && !ssp.IsChildAgent)
  5785. {
  5786. if (!regionWide)
  5787. {
  5788. land = World.LandChannel.GetLandObject(ssp.AbsolutePosition);
  5789. if (land != null)
  5790. {
  5791. if (parcelOwned && land.LandData.OwnerID == id ||
  5792. parcel && land.LandData.GlobalID == id)
  5793. {
  5794. result.Add(new LSL_Key(ssp.UUID.ToString()));
  5795. }
  5796. }
  5797. }
  5798. else
  5799. {
  5800. result.Add(new LSL_Key(ssp.UUID.ToString()));
  5801. }
  5802. }
  5803. // Maximum of 100 results
  5804. if (result.Length > 99)
  5805. {
  5806. return;
  5807. }
  5808. }
  5809. );
  5810. return result;
  5811. }
  5812. public void llAdjustSoundVolume(LSL_Float volume)
  5813. {
  5814. m_host.AddScriptLPS(1);
  5815. m_host.AdjustSoundGain(volume);
  5816. ScriptSleep(m_sleepMsOnAdjustSoundVolume);
  5817. }
  5818. public void llSetSoundRadius(double radius)
  5819. {
  5820. m_host.AddScriptLPS(1);
  5821. m_host.SoundRadius = radius;
  5822. }
  5823. public LSL_String llKey2Name(LSL_Key id)
  5824. {
  5825. m_host.AddScriptLPS(1);
  5826. UUID key = new UUID();
  5827. if (UUID.TryParse(id,out key))
  5828. {
  5829. ScenePresence presence = World.GetScenePresence(key);
  5830. if (presence != null)
  5831. {
  5832. return presence.Name;
  5833. //return presence.Name;
  5834. }
  5835. if (World.GetSceneObjectPart(key) != null)
  5836. {
  5837. return World.GetSceneObjectPart(key).Name;
  5838. }
  5839. }
  5840. return String.Empty;
  5841. }
  5842. public LSL_Key llName2Key(LSL_String name)
  5843. {
  5844. m_host.AddScriptLPS(1);
  5845. if(string.IsNullOrWhiteSpace(name))
  5846. return ScriptBaseClass.NULL_KEY;
  5847. int nc = Util.ParseAvatarName(name, out string firstName, out string lastName, out string server);
  5848. if (nc < 2)
  5849. return ScriptBaseClass.NULL_KEY;
  5850. string sname;
  5851. if (nc == 2)
  5852. sname = firstName + " " + lastName;
  5853. else
  5854. sname = firstName + "." + lastName + " @" + server;
  5855. foreach (ScenePresence sp in World.GetScenePresences())
  5856. {
  5857. if (sp.IsDeleted || sp.IsChildAgent)
  5858. continue;
  5859. if (String.Compare(sname, sp.Name, true) == 0)
  5860. return sp.UUID.ToString();
  5861. }
  5862. return ScriptBaseClass.NULL_KEY;
  5863. }
  5864. public LSL_Key llRequestUserKey(LSL_String username)
  5865. {
  5866. m_host.AddScriptLPS(1);
  5867. if (string.IsNullOrWhiteSpace(username))
  5868. return ScriptBaseClass.NULL_KEY;
  5869. int nc = Util.ParseAvatarName(username, out string firstName, out string lastName, out string server);
  5870. if (nc < 2)
  5871. return ScriptBaseClass.NULL_KEY;
  5872. string sname;
  5873. if (nc == 2)
  5874. sname = firstName + " " + lastName;
  5875. else
  5876. sname = firstName + "." + lastName + " @" + server;
  5877. foreach (ScenePresence sp in World.GetScenePresences())
  5878. {
  5879. if (sp.IsDeleted || sp.IsChildAgent)
  5880. continue;
  5881. if (String.Compare(sname, sp.Name, true) == 0)
  5882. {
  5883. string ftid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId,
  5884. m_item.ItemID, sp.UUID.ToString());
  5885. return ftid;
  5886. }
  5887. }
  5888. Action<string> act = eventID =>
  5889. {
  5890. string reply = ScriptBaseClass.NULL_KEY;
  5891. UUID userID = UUID.Zero;
  5892. IUserManagement userManager = World.RequestModuleInterface<IUserManagement>();
  5893. if (nc == 2)
  5894. {
  5895. if (userManager != null)
  5896. {
  5897. userID = userManager.GetUserIdByName(firstName, lastName);
  5898. if (userID != UUID.Zero)
  5899. reply = userID.ToString();
  5900. }
  5901. }
  5902. else
  5903. {
  5904. string url = "http://" + server;
  5905. if (Uri.TryCreate(url, UriKind.Absolute, out Uri dummy))
  5906. {
  5907. bool notfound = true;
  5908. if (userManager != null)
  5909. {
  5910. string hgfirst = firstName + "." + lastName;
  5911. string hglast = "@" + server;
  5912. userID = userManager.GetUserIdByName(hgfirst, hglast);
  5913. if (userID != UUID.Zero)
  5914. {
  5915. notfound = false;
  5916. reply = userID.ToString();
  5917. }
  5918. }
  5919. if(notfound)
  5920. {
  5921. try
  5922. {
  5923. UserAgentServiceConnector userConnection = new UserAgentServiceConnector(url);
  5924. if (userConnection != null)
  5925. {
  5926. userID = userConnection.GetUUID(firstName, lastName);
  5927. if (userID != UUID.Zero)
  5928. {
  5929. if (userManager != null)
  5930. userManager.AddUser(userID, firstName, lastName, url);
  5931. reply = userID.ToString();
  5932. }
  5933. }
  5934. }
  5935. catch
  5936. {
  5937. reply = ScriptBaseClass.NULL_KEY;
  5938. }
  5939. }
  5940. }
  5941. }
  5942. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, reply);
  5943. };
  5944. UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  5945. ScriptSleep(m_sleepMsOnRequestAgentData);
  5946. return tid.ToString();
  5947. }
  5948. public void llSetTextureAnim(int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5949. {
  5950. m_host.AddScriptLPS(1);
  5951. SetTextureAnim(m_host, mode, face, sizex, sizey, start, length, rate);
  5952. }
  5953. public void llSetLinkTextureAnim(int linknumber, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5954. {
  5955. m_host.AddScriptLPS(1);
  5956. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  5957. try
  5958. {
  5959. foreach (SceneObjectPart part in parts)
  5960. {
  5961. SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
  5962. }
  5963. }
  5964. finally
  5965. {
  5966. }
  5967. }
  5968. private void SetTextureAnim(SceneObjectPart part, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5969. {
  5970. //ALL_SIDES
  5971. if (face == ScriptBaseClass.ALL_SIDES)
  5972. face = 255;
  5973. Primitive.TextureAnimation pTexAnim = new Primitive.TextureAnimation
  5974. {
  5975. Flags = (Primitive.TextureAnimMode)mode,
  5976. Face = (uint)face,
  5977. Length = (float)length,
  5978. Rate = (float)rate,
  5979. SizeX = (uint)sizex,
  5980. SizeY = (uint)sizey,
  5981. Start = (float)start
  5982. };
  5983. part.AddTextureAnimation(pTexAnim);
  5984. part.SendFullUpdateToAllClients();
  5985. part.ParentGroup.HasGroupChanged = true;
  5986. }
  5987. public void llTriggerSoundLimited(string sound, double volume, LSL_Vector top_north_east,
  5988. LSL_Vector bottom_south_west)
  5989. {
  5990. m_host.AddScriptLPS(1);
  5991. if (m_SoundModule != null)
  5992. {
  5993. m_SoundModule.TriggerSoundLimited(m_host.UUID,
  5994. ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume,
  5995. bottom_south_west, top_north_east);
  5996. }
  5997. }
  5998. public void llEjectFromLand(LSL_Key pest)
  5999. {
  6000. m_host.AddScriptLPS(1);
  6001. UUID agentID = new UUID();
  6002. if (UUID.TryParse(pest, out agentID))
  6003. {
  6004. ScenePresence presence = World.GetScenePresence(agentID);
  6005. if (presence != null)
  6006. {
  6007. // agent must be over the owners land
  6008. ILandObject land = World.LandChannel.GetLandObject(presence.AbsolutePosition);
  6009. if (land == null)
  6010. return;
  6011. if (m_host.OwnerID == land.LandData.OwnerID)
  6012. {
  6013. Vector3 p = World.GetNearestAllowedPosition(presence, land);
  6014. presence.TeleportOnEject(p);
  6015. presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
  6016. }
  6017. }
  6018. }
  6019. ScriptSleep(m_sleepMsOnEjectFromLand);
  6020. }
  6021. public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers)
  6022. {
  6023. return ParseString2List(str, separators, in_spacers, false);
  6024. }
  6025. public LSL_Integer llOverMyLand(string id)
  6026. {
  6027. m_host.AddScriptLPS(1);
  6028. UUID key = new UUID();
  6029. if (UUID.TryParse(id, out key))
  6030. {
  6031. try
  6032. {
  6033. ScenePresence presence = World.GetScenePresence(key);
  6034. if (presence != null) // object is an avatar
  6035. {
  6036. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  6037. return 1;
  6038. }
  6039. else // object is not an avatar
  6040. {
  6041. SceneObjectPart obj = World.GetSceneObjectPart(key);
  6042. if (obj != null &&
  6043. m_host.OwnerID == World.LandChannel.GetLandObject(obj.AbsolutePosition).LandData.OwnerID)
  6044. return 1;
  6045. }
  6046. }
  6047. catch { }
  6048. }
  6049. return 0;
  6050. }
  6051. public LSL_Key llGetLandOwnerAt(LSL_Vector pos)
  6052. {
  6053. m_host.AddScriptLPS(1);
  6054. ILandObject land = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  6055. if (land == null)
  6056. return ScriptBaseClass.NULL_KEY;
  6057. return land.LandData.OwnerID.ToString();
  6058. }
  6059. /// <summary>
  6060. /// According to http://lslwiki.net/lslwiki/wakka.php?wakka=llGetAgentSize
  6061. /// only the height of avatars vary and that says:
  6062. /// Width (x) and depth (y) are constant. (0.45m and 0.6m respectively).
  6063. /// </summary>
  6064. public LSL_Vector llGetAgentSize(LSL_Key id)
  6065. {
  6066. m_host.AddScriptLPS(1);
  6067. if(!UUID.TryParse(id, out UUID avID))
  6068. return ScriptBaseClass.ZERO_VECTOR;
  6069. ScenePresence avatar = World.GetScenePresence(avID);
  6070. if (avatar == null || avatar.IsChildAgent) // Fail if not in the same region
  6071. return ScriptBaseClass.ZERO_VECTOR;
  6072. // agentSize = new LSL_Vector(0.45f, 0.6f, avatar.Appearance.AvatarHeight);
  6073. Vector3 s = avatar.Appearance.AvatarSize;
  6074. return new LSL_Vector(s.X, s.Y, s.Z);
  6075. }
  6076. public LSL_Integer llSameGroup(string id)
  6077. {
  6078. m_host.AddScriptLPS(1);
  6079. UUID uuid;
  6080. if (!UUID.TryParse(id, out uuid))
  6081. return 0;
  6082. // Check if it's a group key
  6083. if (uuid == m_host.ParentGroup.RootPart.GroupID)
  6084. return 1;
  6085. // Handle object case
  6086. SceneObjectPart part = World.GetSceneObjectPart(uuid);
  6087. if (part != null)
  6088. {
  6089. if(part.ParentGroup.IsAttachment)
  6090. {
  6091. uuid = part.ParentGroup.AttachedAvatar;
  6092. }
  6093. else
  6094. {
  6095. // This will handle both deed and non-deed and also the no
  6096. // group case
  6097. if (part.ParentGroup.RootPart.GroupID == m_host.ParentGroup.RootPart.GroupID)
  6098. return 1;
  6099. return 0;
  6100. }
  6101. }
  6102. // Handle the case where id names an avatar
  6103. ScenePresence presence = World.GetScenePresence(uuid);
  6104. if (presence != null)
  6105. {
  6106. if (presence.IsChildAgent)
  6107. return 0;
  6108. IClientAPI client = presence.ControllingClient;
  6109. if (m_host.ParentGroup.RootPart.GroupID == client.ActiveGroupId)
  6110. return 1;
  6111. return 0;
  6112. }
  6113. return 0;
  6114. }
  6115. public void llUnSit(string id)
  6116. {
  6117. m_host.AddScriptLPS(1);
  6118. UUID key = new UUID();
  6119. if (UUID.TryParse(id, out key))
  6120. {
  6121. ScenePresence av = World.GetScenePresence(key);
  6122. List<ScenePresence> sittingAvatars = m_host.ParentGroup.GetSittingAvatars();
  6123. if (av != null)
  6124. {
  6125. if (sittingAvatars.Contains(av))
  6126. {
  6127. // if the avatar is sitting on this object, then
  6128. // we can unsit them. We don't want random scripts unsitting random people
  6129. // Lets avoid the popcorn avatar scenario.
  6130. av.StandUp();
  6131. }
  6132. else
  6133. {
  6134. // If the object owner also owns the parcel
  6135. // or
  6136. // if the land is group owned and the object is group owned by the same group
  6137. // or
  6138. // if the object is owned by a person with estate access.
  6139. ILandObject parcel = World.LandChannel.GetLandObject(av.AbsolutePosition);
  6140. if (parcel != null)
  6141. {
  6142. if (m_host.OwnerID == parcel.LandData.OwnerID ||
  6143. (m_host.OwnerID == m_host.GroupID && m_host.GroupID == parcel.LandData.GroupID
  6144. && parcel.LandData.IsGroupOwned) || World.Permissions.IsGod(m_host.OwnerID))
  6145. {
  6146. av.StandUp();
  6147. }
  6148. }
  6149. }
  6150. }
  6151. }
  6152. }
  6153. public LSL_Vector llGroundSlope(LSL_Vector offset)
  6154. {
  6155. m_host.AddScriptLPS(1);
  6156. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  6157. LSL_Vector vsn = llGroundNormal(offset);
  6158. //Plug the x,y coordinates of the slope normal into the equation of the plane to get
  6159. //the height of that point on the plane. The resulting vector gives the slope.
  6160. Vector3 vsl = vsn;
  6161. vsl.Z = (float)(((vsn.x * vsn.x) + (vsn.y * vsn.y)) / (-1 * vsn.z));
  6162. vsl.Normalize();
  6163. //Normalization might be overkill here
  6164. vsn.x = vsl.X;
  6165. vsn.y = vsl.Y;
  6166. vsn.z = vsl.Z;
  6167. return vsn;
  6168. }
  6169. public LSL_Vector llGroundNormal(LSL_Vector offset)
  6170. {
  6171. m_host.AddScriptLPS(1);
  6172. Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
  6173. // Clamp to valid position
  6174. if (pos.X < 0)
  6175. pos.X = 0;
  6176. else if (pos.X >= World.Heightmap.Width)
  6177. pos.X = World.Heightmap.Width - 1;
  6178. if (pos.Y < 0)
  6179. pos.Y = 0;
  6180. else if (pos.Y >= World.Heightmap.Height)
  6181. pos.Y = World.Heightmap.Height - 1;
  6182. //Find two points in addition to the position to define a plane
  6183. Vector3 p0 = new Vector3(pos.X, pos.Y,
  6184. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  6185. Vector3 p1 = new Vector3();
  6186. Vector3 p2 = new Vector3();
  6187. if ((pos.X + 1.0f) >= World.Heightmap.Width)
  6188. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  6189. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  6190. else
  6191. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  6192. (float)World.Heightmap[(int)(pos.X + 1.0f), (int)pos.Y]);
  6193. if ((pos.Y + 1.0f) >= World.Heightmap.Height)
  6194. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  6195. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  6196. else
  6197. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  6198. (float)World.Heightmap[(int)pos.X, (int)(pos.Y + 1.0f)]);
  6199. //Find normalized vectors from p0 to p1 and p0 to p2
  6200. Vector3 v0 = new Vector3(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
  6201. Vector3 v1 = new Vector3(p2.X - p0.X, p2.Y - p0.Y, p2.Z - p0.Z);
  6202. v0.Normalize();
  6203. v1.Normalize();
  6204. //Find the cross product of the vectors (the slope normal).
  6205. Vector3 vsn = new Vector3
  6206. {
  6207. X = (v0.Y * v1.Z) - (v0.Z * v1.Y),
  6208. Y = (v0.Z * v1.X) - (v0.X * v1.Z),
  6209. Z = (v0.X * v1.Y) - (v0.Y * v1.X)
  6210. };
  6211. vsn.Normalize();
  6212. //I believe the crossproduct of two normalized vectors is a normalized vector so
  6213. //this normalization may be overkill
  6214. return new LSL_Vector(vsn);
  6215. }
  6216. public LSL_Vector llGroundContour(LSL_Vector offset)
  6217. {
  6218. m_host.AddScriptLPS(1);
  6219. LSL_Vector x = llGroundSlope(offset);
  6220. return new LSL_Vector(-x.y, x.x, 0.0);
  6221. }
  6222. public LSL_Integer llGetAttached()
  6223. {
  6224. m_host.AddScriptLPS(1);
  6225. return m_host.ParentGroup.AttachmentPoint;
  6226. }
  6227. public LSL_List llGetAttachedList(LSL_Key id)
  6228. {
  6229. m_host.AddScriptLPS(1);
  6230. if(!UUID.TryParse(id, out UUID avID))
  6231. return new LSL_List("NOT_FOUND");
  6232. ScenePresence av = World.GetScenePresence(avID);
  6233. if (av == null || av.IsDeleted)
  6234. return new LSL_List("NOT_FOUND");
  6235. if (av.IsChildAgent || av.IsInTransit)
  6236. return new LSL_List("NOT_ON_REGION");
  6237. LSL_List AttachmentsList = new LSL_List();
  6238. List<SceneObjectGroup> Attachments;
  6239. Attachments = av.GetAttachments();
  6240. foreach (SceneObjectGroup Attachment in Attachments)
  6241. {
  6242. if(Attachment.HasPrivateAttachmentPoint)
  6243. continue;
  6244. AttachmentsList.Add(new LSL_Key(Attachment.UUID.ToString()));
  6245. }
  6246. return AttachmentsList;
  6247. }
  6248. public virtual LSL_Integer llGetFreeMemory()
  6249. {
  6250. m_host.AddScriptLPS(1);
  6251. // Make scripts designed for Mono happy
  6252. return 65536;
  6253. }
  6254. public LSL_Integer llGetFreeURLs()
  6255. {
  6256. m_host.AddScriptLPS(1);
  6257. if (m_UrlModule != null)
  6258. return new LSL_Integer(m_UrlModule.GetFreeUrls());
  6259. return new LSL_Integer(0);
  6260. }
  6261. public LSL_String llGetRegionName()
  6262. {
  6263. m_host.AddScriptLPS(1);
  6264. return World.RegionInfo.RegionName;
  6265. }
  6266. public LSL_Float llGetRegionTimeDilation()
  6267. {
  6268. m_host.AddScriptLPS(1);
  6269. return (double)World.TimeDilation;
  6270. }
  6271. /// <summary>
  6272. /// Returns the value reported in the client Statistics window
  6273. /// </summary>
  6274. public LSL_Float llGetRegionFPS()
  6275. {
  6276. m_host.AddScriptLPS(1);
  6277. return World.StatsReporter.LastReportedSimFPS;
  6278. }
  6279. /* particle system rules should be coming into this routine as doubles, that is
  6280. rule[0] should be an integer from this list and rule[1] should be the arg
  6281. for the same integer. wiki.secondlife.com has most of this mapping, but some
  6282. came from http://www.caligari-designs.com/p4u2
  6283. We iterate through the list for 'Count' elements, incrementing by two for each
  6284. iteration and set the members of Primitive.ParticleSystem, one at a time.
  6285. */
  6286. public enum PrimitiveRule : int
  6287. {
  6288. PSYS_PART_FLAGS = 0,
  6289. PSYS_PART_START_COLOR = 1,
  6290. PSYS_PART_START_ALPHA = 2,
  6291. PSYS_PART_END_COLOR = 3,
  6292. PSYS_PART_END_ALPHA = 4,
  6293. PSYS_PART_START_SCALE = 5,
  6294. PSYS_PART_END_SCALE = 6,
  6295. PSYS_PART_MAX_AGE = 7,
  6296. PSYS_SRC_ACCEL = 8,
  6297. PSYS_SRC_PATTERN = 9,
  6298. PSYS_SRC_INNERANGLE = 10,
  6299. PSYS_SRC_OUTERANGLE = 11,
  6300. PSYS_SRC_TEXTURE = 12,
  6301. PSYS_SRC_BURST_RATE = 13,
  6302. PSYS_SRC_BURST_PART_COUNT = 15,
  6303. PSYS_SRC_BURST_RADIUS = 16,
  6304. PSYS_SRC_BURST_SPEED_MIN = 17,
  6305. PSYS_SRC_BURST_SPEED_MAX = 18,
  6306. PSYS_SRC_MAX_AGE = 19,
  6307. PSYS_SRC_TARGET_KEY = 20,
  6308. PSYS_SRC_OMEGA = 21,
  6309. PSYS_SRC_ANGLE_BEGIN = 22,
  6310. PSYS_SRC_ANGLE_END = 23,
  6311. PSYS_PART_BLEND_FUNC_SOURCE = 24,
  6312. PSYS_PART_BLEND_FUNC_DEST = 25,
  6313. PSYS_PART_START_GLOW = 26,
  6314. PSYS_PART_END_GLOW = 27
  6315. }
  6316. internal Primitive.ParticleSystem.ParticleDataFlags ConvertUINTtoFlags(uint flags)
  6317. {
  6318. Primitive.ParticleSystem.ParticleDataFlags returnval = Primitive.ParticleSystem.ParticleDataFlags.None;
  6319. return returnval;
  6320. }
  6321. protected Primitive.ParticleSystem getNewParticleSystemWithSLDefaultValues()
  6322. {
  6323. Primitive.ParticleSystem ps = new Primitive.ParticleSystem
  6324. {
  6325. PartStartColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f),
  6326. PartEndColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f),
  6327. PartStartScaleX = 1.0f,
  6328. PartStartScaleY = 1.0f,
  6329. PartEndScaleX = 1.0f,
  6330. PartEndScaleY = 1.0f,
  6331. BurstSpeedMin = 1.0f,
  6332. BurstSpeedMax = 1.0f,
  6333. BurstRate = 0.1f,
  6334. PartMaxAge = 10.0f,
  6335. BurstPartCount = 1,
  6336. BlendFuncSource = ScriptBaseClass.PSYS_PART_BF_SOURCE_ALPHA,
  6337. BlendFuncDest = ScriptBaseClass.PSYS_PART_BF_ONE_MINUS_SOURCE_ALPHA,
  6338. PartStartGlow = 0.0f,
  6339. PartEndGlow = 0.0f
  6340. };
  6341. return ps;
  6342. }
  6343. public void llLinkParticleSystem(int linknumber, LSL_List rules)
  6344. {
  6345. m_host.AddScriptLPS(1);
  6346. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  6347. foreach (SceneObjectPart part in parts)
  6348. {
  6349. SetParticleSystem(part, rules, "llLinkParticleSystem");
  6350. }
  6351. }
  6352. public void llParticleSystem(LSL_List rules)
  6353. {
  6354. m_host.AddScriptLPS(1);
  6355. SetParticleSystem(m_host, rules, "llParticleSystem");
  6356. }
  6357. private void SetParticleSystem(SceneObjectPart part, LSL_List rules, string originFunc)
  6358. {
  6359. if (rules.Length == 0)
  6360. {
  6361. part.RemoveParticleSystem();
  6362. part.ParentGroup.HasGroupChanged = true;
  6363. }
  6364. else
  6365. {
  6366. Primitive.ParticleSystem prules = getNewParticleSystemWithSLDefaultValues();
  6367. LSL_Vector tempv = new LSL_Vector();
  6368. float tempf = 0;
  6369. int tmpi = 0;
  6370. for (int i = 0; i < rules.Length; i += 2)
  6371. {
  6372. int psystype;
  6373. try
  6374. {
  6375. psystype = rules.GetLSLIntegerItem(i);
  6376. }
  6377. catch (InvalidCastException)
  6378. {
  6379. Error(originFunc, string.Format("Error running particle system params index #{0}: particle system parameter type must be integer", i));
  6380. return;
  6381. }
  6382. switch (psystype)
  6383. {
  6384. case (int)ScriptBaseClass.PSYS_PART_FLAGS:
  6385. try
  6386. {
  6387. prules.PartDataFlags = (Primitive.ParticleSystem.ParticleDataFlags)(uint)rules.GetLSLIntegerItem(i + 1);
  6388. }
  6389. catch(InvalidCastException)
  6390. {
  6391. Error(originFunc, string.Format("Error running rule PSYS_PART_FLAGS: arg #{0} - parameter 1 must be integer", i + 1));
  6392. return;
  6393. }
  6394. break;
  6395. case (int)ScriptBaseClass.PSYS_PART_START_COLOR:
  6396. try
  6397. {
  6398. tempv = rules.GetVector3Item(i + 1);
  6399. }
  6400. catch(InvalidCastException)
  6401. {
  6402. Error(originFunc, string.Format("Error running rule PSYS_PART_START_COLOR: arg #{0} - parameter 1 must be vector", i + 1));
  6403. return;
  6404. }
  6405. prules.PartStartColor.R = (float)tempv.x;
  6406. prules.PartStartColor.G = (float)tempv.y;
  6407. prules.PartStartColor.B = (float)tempv.z;
  6408. break;
  6409. case (int)ScriptBaseClass.PSYS_PART_START_ALPHA:
  6410. try
  6411. {
  6412. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6413. }
  6414. catch(InvalidCastException)
  6415. {
  6416. Error(originFunc, string.Format("Error running rule PSYS_PART_START_ALPHA: arg #{0} - parameter 1 must be float", i + 1));
  6417. return;
  6418. }
  6419. prules.PartStartColor.A = tempf;
  6420. break;
  6421. case (int)ScriptBaseClass.PSYS_PART_END_COLOR:
  6422. try
  6423. {
  6424. tempv = rules.GetVector3Item(i + 1);
  6425. }
  6426. catch(InvalidCastException)
  6427. {
  6428. Error(originFunc, string.Format("Error running rule PSYS_PART_END_COLOR: arg #{0} - parameter 1 must be vector", i + 1));
  6429. return;
  6430. }
  6431. prules.PartEndColor.R = (float)tempv.x;
  6432. prules.PartEndColor.G = (float)tempv.y;
  6433. prules.PartEndColor.B = (float)tempv.z;
  6434. break;
  6435. case (int)ScriptBaseClass.PSYS_PART_END_ALPHA:
  6436. try
  6437. {
  6438. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6439. }
  6440. catch(InvalidCastException)
  6441. {
  6442. Error(originFunc, string.Format("Error running rule PSYS_PART_END_ALPHA: arg #{0} - parameter 1 must be float", i + 1));
  6443. return;
  6444. }
  6445. prules.PartEndColor.A = tempf;
  6446. break;
  6447. case (int)ScriptBaseClass.PSYS_PART_START_SCALE:
  6448. try
  6449. {
  6450. tempv = rules.GetVector3Item(i + 1);
  6451. }
  6452. catch(InvalidCastException)
  6453. {
  6454. Error(originFunc, string.Format("Error running rule PSYS_PART_START_SCALE: arg #{0} - parameter 1 must be vector", i + 1));
  6455. return;
  6456. }
  6457. prules.PartStartScaleX = validParticleScale((float)tempv.x);
  6458. prules.PartStartScaleY = validParticleScale((float)tempv.y);
  6459. break;
  6460. case (int)ScriptBaseClass.PSYS_PART_END_SCALE:
  6461. try
  6462. {
  6463. tempv = rules.GetVector3Item(i + 1);
  6464. }
  6465. catch(InvalidCastException)
  6466. {
  6467. Error(originFunc, string.Format("Error running rule PSYS_PART_END_SCALE: arg #{0} - parameter 1 must be vector", i + 1));
  6468. return;
  6469. }
  6470. prules.PartEndScaleX = validParticleScale((float)tempv.x);
  6471. prules.PartEndScaleY = validParticleScale((float)tempv.y);
  6472. break;
  6473. case (int)ScriptBaseClass.PSYS_PART_MAX_AGE:
  6474. try
  6475. {
  6476. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6477. }
  6478. catch(InvalidCastException)
  6479. {
  6480. Error(originFunc, string.Format("Error running rule PSYS_PART_MAX_AGE: arg #{0} - parameter 1 must be float", i + 1));
  6481. return;
  6482. }
  6483. prules.PartMaxAge = tempf;
  6484. break;
  6485. case (int)ScriptBaseClass.PSYS_SRC_ACCEL:
  6486. try
  6487. {
  6488. tempv = rules.GetVector3Item(i + 1);
  6489. }
  6490. catch(InvalidCastException)
  6491. {
  6492. Error(originFunc, string.Format("Error running rule PSYS_SRC_ACCEL: arg #{0} - parameter 1 must be vector", i + 1));
  6493. return;
  6494. }
  6495. prules.PartAcceleration.X = (float)tempv.x;
  6496. prules.PartAcceleration.Y = (float)tempv.y;
  6497. prules.PartAcceleration.Z = (float)tempv.z;
  6498. break;
  6499. case (int)ScriptBaseClass.PSYS_SRC_PATTERN:
  6500. try
  6501. {
  6502. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  6503. }
  6504. catch(InvalidCastException)
  6505. {
  6506. Error(originFunc, string.Format("Error running rule PSYS_SRC_PATTERN: arg #{0} - parameter 1 must be integer", i + 1));
  6507. return;
  6508. }
  6509. prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi;
  6510. break;
  6511. // PSYS_SRC_INNERANGLE and PSYS_SRC_ANGLE_BEGIN use the same variables. The
  6512. // PSYS_SRC_OUTERANGLE and PSYS_SRC_ANGLE_END also use the same variable. The
  6513. // client tells the difference between the two by looking at the 0x02 bit in
  6514. // the PartFlags variable.
  6515. case (int)ScriptBaseClass.PSYS_SRC_INNERANGLE:
  6516. try
  6517. {
  6518. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6519. }
  6520. catch(InvalidCastException)
  6521. {
  6522. Error(originFunc, string.Format("Error running rule PSYS_SRC_INNERANGLE: arg #{0} - parameter 1 must be float", i + 1));
  6523. return;
  6524. }
  6525. prules.InnerAngle = (float)tempf;
  6526. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  6527. break;
  6528. case (int)ScriptBaseClass.PSYS_SRC_OUTERANGLE:
  6529. try
  6530. {
  6531. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6532. }
  6533. catch(InvalidCastException)
  6534. {
  6535. Error(originFunc, string.Format("Error running rule PSYS_SRC_OUTERANGLE: arg #{0} - parameter 1 must be float", i + 1));
  6536. return;
  6537. }
  6538. prules.OuterAngle = (float)tempf;
  6539. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  6540. break;
  6541. case (int)ScriptBaseClass.PSYS_PART_BLEND_FUNC_SOURCE:
  6542. try
  6543. {
  6544. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  6545. }
  6546. catch(InvalidCastException)
  6547. {
  6548. Error(originFunc, string.Format("Error running rule PSYS_PART_BLEND_FUNC_SOURCE: arg #{0} - parameter 1 must be integer", i + 1));
  6549. return;
  6550. }
  6551. prules.BlendFuncSource = (byte)tmpi;
  6552. break;
  6553. case (int)ScriptBaseClass.PSYS_PART_BLEND_FUNC_DEST:
  6554. try
  6555. {
  6556. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  6557. }
  6558. catch(InvalidCastException)
  6559. {
  6560. Error(originFunc, string.Format("Error running rule PSYS_PART_BLEND_FUNC_DEST: arg #{0} - parameter 1 must be integer", i + 1));
  6561. return;
  6562. }
  6563. prules.BlendFuncDest = (byte)tmpi;
  6564. break;
  6565. case (int)ScriptBaseClass.PSYS_PART_START_GLOW:
  6566. try
  6567. {
  6568. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6569. }
  6570. catch(InvalidCastException)
  6571. {
  6572. Error(originFunc, string.Format("Error running rule PSYS_PART_START_GLOW: arg #{0} - parameter 1 must be float", i + 1));
  6573. return;
  6574. }
  6575. prules.PartStartGlow = (float)tempf;
  6576. break;
  6577. case (int)ScriptBaseClass.PSYS_PART_END_GLOW:
  6578. try
  6579. {
  6580. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6581. }
  6582. catch(InvalidCastException)
  6583. {
  6584. Error(originFunc, string.Format("Error running rule PSYS_PART_END_GLOW: arg #{0} - parameter 1 must be float", i + 1));
  6585. return;
  6586. }
  6587. prules.PartEndGlow = (float)tempf;
  6588. break;
  6589. case (int)ScriptBaseClass.PSYS_SRC_TEXTURE:
  6590. try
  6591. {
  6592. prules.Texture = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, rules.GetLSLStringItem(i + 1));
  6593. }
  6594. catch(InvalidCastException)
  6595. {
  6596. Error(originFunc, string.Format("Error running rule PSYS_SRC_TEXTURE: arg #{0} - parameter 1 must be string or key", i + 1));
  6597. return;
  6598. }
  6599. break;
  6600. case (int)ScriptBaseClass.PSYS_SRC_BURST_RATE:
  6601. try
  6602. {
  6603. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6604. }
  6605. catch(InvalidCastException)
  6606. {
  6607. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_RATE: arg #{0} - parameter 1 must be float", i + 1));
  6608. return;
  6609. }
  6610. prules.BurstRate = (float)tempf;
  6611. break;
  6612. case (int)ScriptBaseClass.PSYS_SRC_BURST_PART_COUNT:
  6613. try
  6614. {
  6615. prules.BurstPartCount = (byte)(int)rules.GetLSLIntegerItem(i + 1);
  6616. }
  6617. catch(InvalidCastException)
  6618. {
  6619. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_PART_COUNT: arg #{0} - parameter 1 must be integer", i + 1));
  6620. return;
  6621. }
  6622. break;
  6623. case (int)ScriptBaseClass.PSYS_SRC_BURST_RADIUS:
  6624. try
  6625. {
  6626. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6627. }
  6628. catch(InvalidCastException)
  6629. {
  6630. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_RADIUS: arg #{0} - parameter 1 must be float", i + 1));
  6631. return;
  6632. }
  6633. prules.BurstRadius = (float)tempf;
  6634. break;
  6635. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MIN:
  6636. try
  6637. {
  6638. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6639. }
  6640. catch(InvalidCastException)
  6641. {
  6642. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_SPEED_MIN: arg #{0} - parameter 1 must be float", i + 1));
  6643. return;
  6644. }
  6645. prules.BurstSpeedMin = (float)tempf;
  6646. break;
  6647. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MAX:
  6648. try
  6649. {
  6650. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6651. }
  6652. catch(InvalidCastException)
  6653. {
  6654. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_SPEED_MAX: arg #{0} - parameter 1 must be float", i + 1));
  6655. return;
  6656. }
  6657. prules.BurstSpeedMax = (float)tempf;
  6658. break;
  6659. case (int)ScriptBaseClass.PSYS_SRC_MAX_AGE:
  6660. try
  6661. {
  6662. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6663. }
  6664. catch(InvalidCastException)
  6665. {
  6666. Error(originFunc, string.Format("Error running rule PSYS_SRC_MAX_AGE: arg #{0} - parameter 1 must be float", i + 1));
  6667. return;
  6668. }
  6669. prules.MaxAge = (float)tempf;
  6670. break;
  6671. case (int)ScriptBaseClass.PSYS_SRC_TARGET_KEY:
  6672. UUID key = UUID.Zero;
  6673. if (UUID.TryParse(rules.Data[i + 1].ToString(), out key))
  6674. {
  6675. prules.Target = key;
  6676. }
  6677. else
  6678. {
  6679. prules.Target = part.UUID;
  6680. }
  6681. break;
  6682. case (int)ScriptBaseClass.PSYS_SRC_OMEGA:
  6683. // AL: This is an assumption, since it is the only thing that would match.
  6684. try
  6685. {
  6686. tempv = rules.GetVector3Item(i + 1);
  6687. }
  6688. catch(InvalidCastException)
  6689. {
  6690. Error(originFunc, string.Format("Error running rule PSYS_SRC_OMEGA: arg #{0} - parameter 1 must be vector", i + 1));
  6691. return;
  6692. }
  6693. prules.AngularVelocity.X = (float)tempv.x;
  6694. prules.AngularVelocity.Y = (float)tempv.y;
  6695. prules.AngularVelocity.Z = (float)tempv.z;
  6696. break;
  6697. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN:
  6698. try
  6699. {
  6700. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6701. }
  6702. catch(InvalidCastException)
  6703. {
  6704. Error(originFunc, string.Format("Error running rule PSYS_SRC_ANGLE_BEGIN: arg #{0} - parameter 1 must be float", i + 1));
  6705. return;
  6706. }
  6707. prules.InnerAngle = (float)tempf;
  6708. prules.PartFlags |= 0x02; // Set new angle format.
  6709. break;
  6710. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_END:
  6711. try
  6712. {
  6713. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6714. }
  6715. catch (InvalidCastException)
  6716. {
  6717. Error(originFunc, string.Format("Error running rule PSYS_SRC_ANGLE_END: arg #{0} - parameter 1 must be float", i + 1));
  6718. return;
  6719. }
  6720. prules.OuterAngle = (float)tempf;
  6721. prules.PartFlags |= 0x02; // Set new angle format.
  6722. break;
  6723. }
  6724. }
  6725. prules.CRC = 1;
  6726. part.AddNewParticleSystem(prules);
  6727. part.ParentGroup.HasGroupChanged = true;
  6728. }
  6729. part.SendFullUpdateToAllClients();
  6730. }
  6731. private float validParticleScale(float value)
  6732. {
  6733. if (value > 7.96f) return 7.96f;
  6734. return value;
  6735. }
  6736. public void llGroundRepel(double height, int water, double tau)
  6737. {
  6738. m_host.AddScriptLPS(1);
  6739. if (m_host.PhysActor != null)
  6740. {
  6741. float ground = (float)llGround(new LSL_Types.Vector3(0, 0, 0));
  6742. float waterLevel = (float)llWater(new LSL_Types.Vector3(0, 0, 0));
  6743. PIDHoverType hoverType = PIDHoverType.Ground;
  6744. if (water != 0)
  6745. {
  6746. hoverType = PIDHoverType.GroundAndWater;
  6747. if (ground < waterLevel)
  6748. height += waterLevel;
  6749. else
  6750. height += ground;
  6751. }
  6752. else
  6753. {
  6754. height += ground;
  6755. }
  6756. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  6757. }
  6758. }
  6759. public void llGiveInventoryList(LSL_Key destination, LSL_String category, LSL_List inventory)
  6760. {
  6761. m_host.AddScriptLPS(1);
  6762. if (!UUID.TryParse(destination, out UUID destID))
  6763. return;
  6764. ScenePresence sp = null;
  6765. bool isNotOwner = true;
  6766. if (!World.TryGetSceneObjectPart(destID, out SceneObjectPart destSop))
  6767. {
  6768. if (!World.TryGetScenePresence(destID, out sp))
  6769. {
  6770. // we could check if it is a grid user and allow the transfer as in older code
  6771. // but that increases security risk
  6772. Error("llGiveInventoryList", "Unable to give list, destination not found");
  6773. ScriptSleep(100);
  6774. return;
  6775. }
  6776. isNotOwner = sp.UUID != m_host.OwnerID;
  6777. }
  6778. List<UUID> itemList = new List<UUID>();
  6779. foreach (Object item in inventory.Data)
  6780. {
  6781. string rawItemString = item.ToString();
  6782. TaskInventoryItem taskItem = null;
  6783. if (UUID.TryParse(rawItemString, out UUID itemID))
  6784. taskItem = m_host.Inventory.GetInventoryItem(itemID);
  6785. else
  6786. taskItem = m_host.Inventory.GetInventoryItem(rawItemString);
  6787. if(taskItem == null)
  6788. continue;
  6789. if ((taskItem.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  6790. continue;
  6791. if (destSop != null)
  6792. {
  6793. if(!World.Permissions.CanDoObjectInvToObjectInv(taskItem, m_host, destSop))
  6794. continue;
  6795. }
  6796. else
  6797. {
  6798. if(isNotOwner)
  6799. {
  6800. if ((taskItem.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
  6801. continue;
  6802. }
  6803. }
  6804. itemList.Add(taskItem.ItemID);
  6805. }
  6806. if (itemList.Count == 0)
  6807. {
  6808. Error("llGiveInventoryList", "Unable to give list, no items found");
  6809. ScriptSleep(100);
  6810. return;
  6811. }
  6812. UUID folderID = m_ScriptEngine.World.MoveTaskInventoryItems(destID, category, m_host, itemList, false);
  6813. if (folderID == UUID.Zero)
  6814. {
  6815. Error("llGiveInventoryList", "Unable to give list");
  6816. ScriptSleep(100);
  6817. return;
  6818. }
  6819. if (destSop != null)
  6820. return;
  6821. if (m_TransferModule != null)
  6822. {
  6823. byte[] bucket = new byte[] { (byte)AssetType.Folder };
  6824. Vector3 pos = m_host.AbsolutePosition;
  6825. GridInstantMessage msg = new GridInstantMessage(World,
  6826. m_host.OwnerID, m_host.Name, destID,
  6827. (byte)InstantMessageDialog.TaskInventoryOffered,
  6828. m_host.OwnerID == m_host.GroupID,
  6829. string.Format("'{0}'", category),
  6830. //string.Format("'{0}' ( http://slurl.com/secondlife/{1}/{2}/{3}/{4} )", category, World.Name, (int)pos.X, (int)pos.Y, (int)pos.Z),
  6831. folderID, false, pos,
  6832. bucket, false);
  6833. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  6834. }
  6835. ScriptSleep(destSop == null ? 3000 : 100);
  6836. }
  6837. public void llSetVehicleType(int type)
  6838. {
  6839. m_host.AddScriptLPS(1);
  6840. if (!m_host.ParentGroup.IsDeleted)
  6841. {
  6842. m_host.ParentGroup.RootPart.SetVehicleType(type);
  6843. }
  6844. }
  6845. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6846. //CFK 9/28: so these are not complete yet.
  6847. public void llSetVehicleFloatParam(int param, LSL_Float value)
  6848. {
  6849. m_host.AddScriptLPS(1);
  6850. if (!m_host.ParentGroup.IsDeleted)
  6851. {
  6852. m_host.ParentGroup.RootPart.SetVehicleFloatParam(param, (float)value);
  6853. }
  6854. }
  6855. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6856. //CFK 9/28: so these are not complete yet.
  6857. public void llSetVehicleVectorParam(int param, LSL_Vector vec)
  6858. {
  6859. m_host.AddScriptLPS(1);
  6860. if (!m_host.ParentGroup.IsDeleted)
  6861. {
  6862. m_host.ParentGroup.RootPart.SetVehicleVectorParam(param, vec);
  6863. }
  6864. }
  6865. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6866. //CFK 9/28: so these are not complete yet.
  6867. public void llSetVehicleRotationParam(int param, LSL_Rotation rot)
  6868. {
  6869. m_host.AddScriptLPS(1);
  6870. if (!m_host.ParentGroup.IsDeleted)
  6871. {
  6872. m_host.ParentGroup.RootPart.SetVehicleRotationParam(param, rot);
  6873. }
  6874. }
  6875. public void llSetVehicleFlags(int flags)
  6876. {
  6877. m_host.AddScriptLPS(1);
  6878. if (!m_host.ParentGroup.IsDeleted)
  6879. {
  6880. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, false);
  6881. }
  6882. }
  6883. public void llRemoveVehicleFlags(int flags)
  6884. {
  6885. m_host.AddScriptLPS(1);
  6886. if (!m_host.ParentGroup.IsDeleted)
  6887. {
  6888. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, true);
  6889. }
  6890. }
  6891. protected void SitTarget(SceneObjectPart part, LSL_Vector offset, LSL_Rotation rot)
  6892. {
  6893. // LSL quaternions can normalize to 0, normal Quaternions can't.
  6894. if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0)
  6895. rot.s = 1; // ZERO_ROTATION = 0,0,0,1
  6896. part.SitTargetPosition = offset;
  6897. part.SitTargetOrientation = rot;
  6898. part.ParentGroup.HasGroupChanged = true;
  6899. }
  6900. public void llSitTarget(LSL_Vector offset, LSL_Rotation rot)
  6901. {
  6902. m_host.AddScriptLPS(1);
  6903. SitTarget(m_host, offset, rot);
  6904. }
  6905. public void llLinkSitTarget(LSL_Integer link, LSL_Vector offset, LSL_Rotation rot)
  6906. {
  6907. m_host.AddScriptLPS(1);
  6908. if (link == ScriptBaseClass.LINK_ROOT)
  6909. SitTarget(m_host.ParentGroup.RootPart, offset, rot);
  6910. else if (link == ScriptBaseClass.LINK_THIS)
  6911. SitTarget(m_host, offset, rot);
  6912. else
  6913. {
  6914. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  6915. if (null != part)
  6916. {
  6917. SitTarget(part, offset, rot);
  6918. }
  6919. }
  6920. }
  6921. public LSL_Key llAvatarOnSitTarget()
  6922. {
  6923. m_host.AddScriptLPS(1);
  6924. return m_host.SitTargetAvatar.ToString();
  6925. }
  6926. // http://wiki.secondlife.com/wiki/LlAvatarOnLinkSitTarget
  6927. public LSL_Key llAvatarOnLinkSitTarget(LSL_Integer linknum)
  6928. {
  6929. m_host.AddScriptLPS(1);
  6930. if(linknum == ScriptBaseClass.LINK_SET ||
  6931. linknum == ScriptBaseClass.LINK_ALL_CHILDREN ||
  6932. linknum == ScriptBaseClass.LINK_ALL_OTHERS ||
  6933. linknum == 0)
  6934. return ScriptBaseClass.NULL_KEY;
  6935. List<SceneObjectPart> parts = GetLinkParts(linknum);
  6936. if (parts.Count == 0)
  6937. return ScriptBaseClass.NULL_KEY;
  6938. return parts[0].SitTargetAvatar.ToString();
  6939. }
  6940. public void llAddToLandPassList(LSL_Key avatar, LSL_Float hours)
  6941. {
  6942. m_host.AddScriptLPS(1);
  6943. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  6944. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManagePasses, false))
  6945. {
  6946. int expires = 0;
  6947. if (hours != 0)
  6948. expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours);
  6949. if (UUID.TryParse(avatar, out UUID key))
  6950. {
  6951. int idx = land.LandData.ParcelAccessList.FindIndex(
  6952. delegate(LandAccessEntry e)
  6953. {
  6954. if (e.AgentID == key && e.Flags == AccessList.Access)
  6955. return true;
  6956. return false;
  6957. });
  6958. if (idx != -1 && (land.LandData.ParcelAccessList[idx].Expires == 0 || (expires != 0 && expires < land.LandData.ParcelAccessList[idx].Expires)))
  6959. return;
  6960. if (idx != -1)
  6961. land.LandData.ParcelAccessList.RemoveAt(idx);
  6962. LandAccessEntry entry = new LandAccessEntry
  6963. {
  6964. AgentID = key,
  6965. Flags = AccessList.Access,
  6966. Expires = expires
  6967. };
  6968. land.LandData.ParcelAccessList.Add(entry);
  6969. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  6970. }
  6971. }
  6972. ScriptSleep(m_sleepMsOnAddToLandPassList);
  6973. }
  6974. public void llSetTouchText(string text)
  6975. {
  6976. m_host.AddScriptLPS(1);
  6977. if(text.Length <= 9)
  6978. m_host.TouchName = text;
  6979. else
  6980. m_host.TouchName = text.Substring(0, 9);
  6981. }
  6982. public void llSetSitText(string text)
  6983. {
  6984. m_host.AddScriptLPS(1);
  6985. if (text.Length <= 9)
  6986. m_host.SitName = text;
  6987. else
  6988. m_host.SitName = text.Substring(0, 9);
  6989. }
  6990. public void llSetCameraEyeOffset(LSL_Vector offset)
  6991. {
  6992. m_host.AddScriptLPS(1);
  6993. m_host.SetCameraEyeOffset(offset);
  6994. if (m_host.ParentGroup.RootPart.GetCameraEyeOffset() == Vector3.Zero)
  6995. m_host.ParentGroup.RootPart.SetCameraEyeOffset(offset);
  6996. }
  6997. public void llSetCameraAtOffset(LSL_Vector offset)
  6998. {
  6999. m_host.AddScriptLPS(1);
  7000. m_host.SetCameraAtOffset(offset);
  7001. if (m_host.ParentGroup.RootPart.GetCameraAtOffset() == Vector3.Zero)
  7002. m_host.ParentGroup.RootPart.SetCameraAtOffset(offset);
  7003. }
  7004. public void llSetLinkCamera(LSL_Integer link, LSL_Vector eye, LSL_Vector at)
  7005. {
  7006. m_host.AddScriptLPS(1);
  7007. if (link == ScriptBaseClass.LINK_SET ||
  7008. link == ScriptBaseClass.LINK_ALL_CHILDREN ||
  7009. link == ScriptBaseClass.LINK_ALL_OTHERS) return;
  7010. SceneObjectPart part = null;
  7011. switch (link)
  7012. {
  7013. case ScriptBaseClass.LINK_ROOT:
  7014. part = m_host.ParentGroup.RootPart;
  7015. break;
  7016. case ScriptBaseClass.LINK_THIS:
  7017. part = m_host;
  7018. break;
  7019. default:
  7020. part = m_host.ParentGroup.GetLinkNumPart(link);
  7021. break;
  7022. }
  7023. if (null != part)
  7024. {
  7025. part.SetCameraEyeOffset(eye);
  7026. part.SetCameraAtOffset(at);
  7027. }
  7028. }
  7029. public LSL_String llDumpList2String(LSL_List src, string seperator)
  7030. {
  7031. m_host.AddScriptLPS(1);
  7032. if (src.Length == 0)
  7033. {
  7034. return String.Empty;
  7035. }
  7036. string ret = String.Empty;
  7037. foreach (object o in src.Data)
  7038. {
  7039. ret = ret + o.ToString() + seperator;
  7040. }
  7041. ret = ret.Substring(0, ret.Length - seperator.Length);
  7042. return ret;
  7043. }
  7044. public LSL_Integer llScriptDanger(LSL_Vector pos)
  7045. {
  7046. m_host.AddScriptLPS(1);
  7047. bool result = World.LSLScriptDanger(m_host, pos);
  7048. if (result)
  7049. {
  7050. return 1;
  7051. }
  7052. else
  7053. {
  7054. return 0;
  7055. }
  7056. }
  7057. public void llDialog(LSL_Key avatar, LSL_String message, LSL_List buttons, int chat_channel)
  7058. {
  7059. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  7060. if (dm == null)
  7061. return;
  7062. m_host.AddScriptLPS(1);
  7063. UUID av = new UUID();
  7064. if (!UUID.TryParse(avatar,out av))
  7065. {
  7066. Error("llDialog", "First parameter must be a key");
  7067. return;
  7068. }
  7069. int length = buttons.Length;
  7070. if (length < 1)
  7071. {
  7072. buttons.Add(new LSL_String("Ok"));
  7073. length = 1;
  7074. }
  7075. else if (length > 12)
  7076. {
  7077. Error("llDialog", "No more than 12 buttons can be shown");
  7078. return;
  7079. }
  7080. if (message == string.Empty)
  7081. {
  7082. Error("llDialog", "Empty message");
  7083. }
  7084. else if (Encoding.UTF8.GetByteCount(message) > 512)
  7085. {
  7086. Error("llDialog", "Message longer than 512 bytes");
  7087. }
  7088. string[] buts = new string[length];
  7089. for (int i = 0; i < length; i++)
  7090. {
  7091. if (buttons.Data[i].ToString() == String.Empty)
  7092. {
  7093. Error("llDialog", "Button label cannot be blank");
  7094. return;
  7095. }
  7096. /*
  7097. if (buttons.Data[i].ToString().Length > 24)
  7098. {
  7099. Error("llDialog", "Button label cannot be longer than 24 characters");
  7100. return;
  7101. }
  7102. */
  7103. buts[i] = buttons.Data[i].ToString();
  7104. }
  7105. dm.SendDialogToUser(
  7106. av, m_host.Name, m_host.UUID, m_host.OwnerID,
  7107. message, new UUID("00000000-0000-2222-3333-100000001000"), chat_channel, buts);
  7108. ScriptSleep(m_sleepMsOnDialog);
  7109. }
  7110. public void llVolumeDetect(int detect)
  7111. {
  7112. m_host.AddScriptLPS(1);
  7113. if (!m_host.ParentGroup.IsDeleted)
  7114. m_host.ParentGroup.ScriptSetVolumeDetect(detect != 0);
  7115. }
  7116. public void llRemoteLoadScript(string target, string name, int running, int start_param)
  7117. {
  7118. m_host.AddScriptLPS(1);
  7119. Deprecated("llRemoteLoadScript", "Use llRemoteLoadScriptPin instead");
  7120. ScriptSleep(m_sleepMsOnRemoteLoadScript);
  7121. }
  7122. public void llSetRemoteScriptAccessPin(int pin)
  7123. {
  7124. m_host.AddScriptLPS(1);
  7125. m_host.ScriptAccessPin = pin;
  7126. }
  7127. public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param)
  7128. {
  7129. m_host.AddScriptLPS(1);
  7130. UUID destId = UUID.Zero;
  7131. if (!UUID.TryParse(target, out destId))
  7132. {
  7133. Error("llRemoteLoadScriptPin", "Can't parse key '" + target + "'");
  7134. return;
  7135. }
  7136. // target must be a different prim than the one containing the script
  7137. if (m_host.UUID == destId)
  7138. {
  7139. return;
  7140. }
  7141. // copy the first script found with this inventory name
  7142. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  7143. // make sure the object is a script
  7144. if (item == null || item.Type != 10)
  7145. {
  7146. Error("llRemoteLoadScriptPin", "Can't find script '" + name + "'");
  7147. return;
  7148. }
  7149. SceneObjectPart dest = World.GetSceneObjectPart(destId);
  7150. if (dest != null)
  7151. {
  7152. if ((item.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID)
  7153. {
  7154. // the rest of the permission checks are done in RezScript, so check the pin there as well
  7155. World.RezScriptFromPrim(item.ItemID, m_host, destId, pin, running, start_param);
  7156. if ((item.BasePermissions & (uint)PermissionMask.Copy) == 0)
  7157. m_host.Inventory.RemoveInventoryItem(item.ItemID);
  7158. }
  7159. }
  7160. // this will cause the delay even if the script pin or permissions were wrong - seems ok
  7161. ScriptSleep(m_sleepMsOnRemoteLoadScriptPin);
  7162. }
  7163. public void llOpenRemoteDataChannel()
  7164. {
  7165. m_host.AddScriptLPS(1);
  7166. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7167. if (xmlrpcMod != null && xmlrpcMod.IsEnabled())
  7168. {
  7169. UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_host.LocalId, m_item.ItemID, UUID.Zero);
  7170. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  7171. if (xmlRpcRouter != null)
  7172. {
  7173. string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName;
  7174. xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID,
  7175. m_item.ItemID, String.Format("http://{0}:{1}/", ExternalHostName,
  7176. xmlrpcMod.Port.ToString()));
  7177. }
  7178. object[] resobj = new object[]
  7179. {
  7180. new LSL_Integer(1),
  7181. new LSL_String(channelID.ToString()),
  7182. new LSL_String(ScriptBaseClass.NULL_KEY),
  7183. new LSL_String(String.Empty),
  7184. new LSL_Integer(0),
  7185. new LSL_String(String.Empty)
  7186. };
  7187. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams("remote_data", resobj,
  7188. new DetectParams[0]));
  7189. }
  7190. ScriptSleep(m_sleepMsOnOpenRemoteDataChannel);
  7191. }
  7192. public LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata)
  7193. {
  7194. m_host.AddScriptLPS(1);
  7195. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7196. ScriptSleep(m_sleepMsOnSendRemoteData);
  7197. if (xmlrpcMod == null)
  7198. return "";
  7199. return (xmlrpcMod.SendRemoteData(m_host.LocalId, m_item.ItemID, channel, dest, idata, sdata)).ToString();
  7200. }
  7201. public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
  7202. {
  7203. m_host.AddScriptLPS(1);
  7204. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7205. if (xmlrpcMod != null)
  7206. xmlrpcMod.RemoteDataReply(channel, message_id, sdata, idata);
  7207. ScriptSleep(m_sleepMsOnRemoteDataReply);
  7208. }
  7209. public void llCloseRemoteDataChannel(string channel)
  7210. {
  7211. m_host.AddScriptLPS(1);
  7212. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  7213. if (xmlRpcRouter != null)
  7214. {
  7215. xmlRpcRouter.UnRegisterReceiver(channel, m_item.ItemID);
  7216. }
  7217. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7218. if (xmlrpcMod != null)
  7219. xmlrpcMod.CloseXMLRPCChannel((UUID)channel);
  7220. ScriptSleep(m_sleepMsOnCloseRemoteDataChannel);
  7221. }
  7222. public LSL_String llMD5String(string src, int nonce)
  7223. {
  7224. m_host.AddScriptLPS(1);
  7225. return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()), Encoding.UTF8);
  7226. }
  7227. public LSL_String llSHA1String(string src)
  7228. {
  7229. m_host.AddScriptLPS(1);
  7230. return Util.SHA1Hash(src, Encoding.UTF8).ToLower();
  7231. }
  7232. protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve)
  7233. {
  7234. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  7235. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  7236. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7237. return shapeBlock;
  7238. if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
  7239. holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
  7240. holeshape != (int)ScriptBaseClass.PRIM_HOLE_SQUARE &&
  7241. holeshape != (int)ScriptBaseClass.PRIM_HOLE_TRIANGLE)
  7242. {
  7243. holeshape = (int)ScriptBaseClass.PRIM_HOLE_DEFAULT;
  7244. }
  7245. shapeBlock.PathCurve = pathcurve;
  7246. shapeBlock.ProfileCurve = (byte)holeshape; // Set the hole shape.
  7247. shapeBlock.ProfileCurve += profileshape; // Add in the profile shape.
  7248. if (cut.x < 0f)
  7249. {
  7250. cut.x = 0f;
  7251. }
  7252. else if (cut.x > 1f)
  7253. {
  7254. cut.x = 1f;
  7255. }
  7256. if (cut.y < 0f)
  7257. {
  7258. cut.y = 0f;
  7259. }
  7260. else if (cut.y > 1f)
  7261. {
  7262. cut.y = 1f;
  7263. }
  7264. if (cut.y - cut.x < 0.02f)
  7265. {
  7266. cut.x = cut.y - 0.02f;
  7267. if (cut.x < 0.0f)
  7268. {
  7269. cut.x = 0.0f;
  7270. cut.y = 0.02f;
  7271. }
  7272. }
  7273. shapeBlock.ProfileBegin = (ushort)(50000 * cut.x);
  7274. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - cut.y));
  7275. if (hollow < 0f)
  7276. {
  7277. hollow = 0f;
  7278. }
  7279. // If the prim is a Cylinder, Prism, Sphere, Torus or Ring (or not a
  7280. // Box or Tube) and the hole shape is a square, hollow is limited to
  7281. // a max of 70%. The viewer performs its own check on this value but
  7282. // we need to do it here also so llGetPrimitiveParams can have access
  7283. // to the correct value.
  7284. if (profileshape != (byte)ProfileCurve.Square &&
  7285. holeshape == (int)ScriptBaseClass.PRIM_HOLE_SQUARE)
  7286. {
  7287. if (hollow > 0.70f)
  7288. {
  7289. hollow = 0.70f;
  7290. }
  7291. }
  7292. // Otherwise, hollow is limited to 99%.
  7293. else
  7294. {
  7295. if (hollow > 0.99f)
  7296. {
  7297. hollow = 0.99f;
  7298. }
  7299. }
  7300. shapeBlock.ProfileHollow = (ushort)(50000 * hollow);
  7301. if (twist.x < -1.0f)
  7302. {
  7303. twist.x = -1.0f;
  7304. }
  7305. else if (twist.x > 1.0f)
  7306. {
  7307. twist.x = 1.0f;
  7308. }
  7309. if (twist.y < -1.0f)
  7310. {
  7311. twist.y = -1.0f;
  7312. }
  7313. else if (twist.y > 1.0f)
  7314. {
  7315. twist.y = 1.0f;
  7316. }
  7317. tempFloat = 100.0f * (float)twist.x;
  7318. if (tempFloat >= 0)
  7319. tempFloat += 0.5f;
  7320. else
  7321. tempFloat -= 0.5f;
  7322. shapeBlock.PathTwistBegin = (sbyte)tempFloat;
  7323. tempFloat = 100.0f * (float)twist.y;
  7324. if (tempFloat >= 0)
  7325. tempFloat += 0.5f;
  7326. else
  7327. tempFloat -= 0.5f;
  7328. shapeBlock.PathTwist = (sbyte)tempFloat;
  7329. shapeBlock.ObjectLocalID = part.LocalId;
  7330. part.Shape.SculptEntry = false;
  7331. return shapeBlock;
  7332. }
  7333. // Prim type box, cylinder and prism.
  7334. 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)
  7335. {
  7336. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7337. return;
  7338. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  7339. ObjectShapePacket.ObjectDataBlock shapeBlock;
  7340. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  7341. if (taper_b.x < 0f)
  7342. {
  7343. taper_b.x = 0f;
  7344. }
  7345. else if (taper_b.x > 2f)
  7346. {
  7347. taper_b.x = 2f;
  7348. }
  7349. if (taper_b.y < 0f)
  7350. {
  7351. taper_b.y = 0f;
  7352. }
  7353. else if (taper_b.y > 2f)
  7354. {
  7355. taper_b.y = 2f;
  7356. }
  7357. tempFloat = 100.0f * (2.0f - (float)taper_b.x);
  7358. if (tempFloat >= 0)
  7359. tempFloat += 0.5f;
  7360. else
  7361. tempFloat -= 0.5f;
  7362. shapeBlock.PathScaleX = (byte)tempFloat;
  7363. tempFloat = 100.0f * (2.0f - (float)taper_b.y);
  7364. if (tempFloat >= 0)
  7365. tempFloat += 0.5f;
  7366. else
  7367. tempFloat -= 0.5f;
  7368. shapeBlock.PathScaleY = (byte)tempFloat;
  7369. if (topshear.x < -0.5f)
  7370. {
  7371. topshear.x = -0.5f;
  7372. }
  7373. else if (topshear.x > 0.5f)
  7374. {
  7375. topshear.x = 0.5f;
  7376. }
  7377. if (topshear.y < -0.5f)
  7378. {
  7379. topshear.y = -0.5f;
  7380. }
  7381. else if (topshear.y > 0.5f)
  7382. {
  7383. topshear.y = 0.5f;
  7384. }
  7385. tempFloat = 100.0f * (float)topshear.x;
  7386. if (tempFloat >= 0)
  7387. tempFloat += 0.5f;
  7388. else
  7389. tempFloat -= 0.5f;
  7390. shapeBlock.PathShearX = (byte)tempFloat;
  7391. tempFloat = 100.0f * (float)topshear.y;
  7392. if (tempFloat >= 0)
  7393. tempFloat += 0.5f;
  7394. else
  7395. tempFloat -= 0.5f;
  7396. shapeBlock.PathShearY = (byte)tempFloat;
  7397. part.Shape.SculptEntry = false;
  7398. part.UpdateShape(shapeBlock);
  7399. }
  7400. // Prim type sphere.
  7401. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve)
  7402. {
  7403. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7404. return;
  7405. ObjectShapePacket.ObjectDataBlock shapeBlock;
  7406. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  7407. // profile/path swapped for a sphere
  7408. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  7409. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  7410. shapeBlock.PathScaleX = 100;
  7411. shapeBlock.PathScaleY = 100;
  7412. if (dimple.x < 0f)
  7413. {
  7414. dimple.x = 0f;
  7415. }
  7416. else if (dimple.x > 1f)
  7417. {
  7418. dimple.x = 1f;
  7419. }
  7420. if (dimple.y < 0f)
  7421. {
  7422. dimple.y = 0f;
  7423. }
  7424. else if (dimple.y > 1f)
  7425. {
  7426. dimple.y = 1f;
  7427. }
  7428. if (dimple.y - dimple.x < 0.02f)
  7429. {
  7430. dimple.x = dimple.y - 0.02f;
  7431. if (dimple.x < 0.0f)
  7432. {
  7433. dimple.x = 0.0f;
  7434. dimple.y = 0.02f;
  7435. }
  7436. }
  7437. shapeBlock.ProfileBegin = (ushort)(50000 * dimple.x);
  7438. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - dimple.y));
  7439. part.Shape.SculptEntry = false;
  7440. part.UpdateShape(shapeBlock);
  7441. }
  7442. // Prim type torus, tube and ring.
  7443. 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)
  7444. {
  7445. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7446. return;
  7447. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  7448. ObjectShapePacket.ObjectDataBlock shapeBlock;
  7449. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  7450. // profile/path swapped for a torrus, tube, ring
  7451. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  7452. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  7453. if (holesize.x < 0.01f)
  7454. {
  7455. holesize.x = 0.01f;
  7456. }
  7457. else if (holesize.x > 1f)
  7458. {
  7459. holesize.x = 1f;
  7460. }
  7461. tempFloat = 100.0f * (2.0f - (float)holesize.x) + 0.5f;
  7462. shapeBlock.PathScaleX = (byte)tempFloat;
  7463. if (holesize.y < 0.01f)
  7464. {
  7465. holesize.y = 0.01f;
  7466. }
  7467. else if (holesize.y > 0.5f)
  7468. {
  7469. holesize.y = 0.5f;
  7470. }
  7471. tempFloat = 100.0f * (2.0f - (float)holesize.y) + 0.5f;
  7472. shapeBlock.PathScaleY = (byte)tempFloat;
  7473. if (topshear.x < -0.5f)
  7474. {
  7475. topshear.x = -0.5f;
  7476. }
  7477. else if (topshear.x > 0.5f)
  7478. {
  7479. topshear.x = 0.5f;
  7480. }
  7481. tempFloat = (float)(100.0d * topshear.x);
  7482. if (tempFloat >= 0)
  7483. tempFloat += 0.5f;
  7484. else
  7485. tempFloat -= 0.5f;
  7486. shapeBlock.PathShearX = (byte)tempFloat;
  7487. if (topshear.y < -0.5f)
  7488. {
  7489. topshear.y = -0.5f;
  7490. }
  7491. else if (topshear.y > 0.5f)
  7492. {
  7493. topshear.y = 0.5f;
  7494. }
  7495. tempFloat = (float)(100.0d * topshear.y);
  7496. if (tempFloat >= 0)
  7497. tempFloat += 0.5f;
  7498. else
  7499. tempFloat -= 0.5f;
  7500. shapeBlock.PathShearY = (byte)tempFloat;
  7501. if (profilecut.x < 0f)
  7502. {
  7503. profilecut.x = 0f;
  7504. }
  7505. else if (profilecut.x > 1f)
  7506. {
  7507. profilecut.x = 1f;
  7508. }
  7509. if (profilecut.y < 0f)
  7510. {
  7511. profilecut.y = 0f;
  7512. }
  7513. else if (profilecut.y > 1f)
  7514. {
  7515. profilecut.y = 1f;
  7516. }
  7517. if (profilecut.y - profilecut.x < 0.02f)
  7518. {
  7519. profilecut.x = profilecut.y - 0.02f;
  7520. if (profilecut.x < 0.0f)
  7521. {
  7522. profilecut.x = 0.0f;
  7523. profilecut.y = 0.02f;
  7524. }
  7525. }
  7526. shapeBlock.ProfileBegin = (ushort)(50000 * profilecut.x);
  7527. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - profilecut.y));
  7528. if (taper_a.x < -1f)
  7529. {
  7530. taper_a.x = -1f;
  7531. }
  7532. if (taper_a.x > 1f)
  7533. {
  7534. taper_a.x = 1f;
  7535. }
  7536. tempFloat = 100.0f * (float)taper_a.x;
  7537. if (tempFloat >= 0)
  7538. tempFloat += 0.5f;
  7539. else
  7540. tempFloat -= 0.5f;
  7541. shapeBlock.PathTaperX = (sbyte)tempFloat;
  7542. if (taper_a.y < -1f)
  7543. {
  7544. taper_a.y = -1f;
  7545. }
  7546. else if (taper_a.y > 1f)
  7547. {
  7548. taper_a.y = 1f;
  7549. }
  7550. tempFloat = 100.0f * (float)taper_a.y;
  7551. if (tempFloat >= 0)
  7552. tempFloat += 0.5f;
  7553. else
  7554. tempFloat -= 0.5f;
  7555. shapeBlock.PathTaperY = (sbyte)tempFloat;
  7556. if (revolutions < 1f)
  7557. {
  7558. revolutions = 1f;
  7559. }
  7560. if (revolutions > 4f)
  7561. {
  7562. revolutions = 4f;
  7563. }
  7564. tempFloat = 66.66667f * (revolutions - 1.0f) + 0.5f;
  7565. shapeBlock.PathRevolutions = (byte)tempFloat;
  7566. // limits on radiusoffset depend on revolutions and hole size (how?) seems like the maximum range is 0 to 1
  7567. if (radiusoffset < 0f)
  7568. {
  7569. radiusoffset = 0f;
  7570. }
  7571. if (radiusoffset > 1f)
  7572. {
  7573. radiusoffset = 1f;
  7574. }
  7575. tempFloat = 100.0f * radiusoffset + 0.5f;
  7576. shapeBlock.PathRadiusOffset = (sbyte)tempFloat;
  7577. if (skew < -0.95f)
  7578. {
  7579. skew = -0.95f;
  7580. }
  7581. if (skew > 0.95f)
  7582. {
  7583. skew = 0.95f;
  7584. }
  7585. tempFloat = 100.0f * skew;
  7586. if (tempFloat >= 0)
  7587. tempFloat += 0.5f;
  7588. else
  7589. tempFloat -= 0.5f;
  7590. shapeBlock.PathSkew = (sbyte)tempFloat;
  7591. part.Shape.SculptEntry = false;
  7592. part.UpdateShape(shapeBlock);
  7593. }
  7594. // Prim type sculpt.
  7595. protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve)
  7596. {
  7597. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7598. return;
  7599. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  7600. if (!UUID.TryParse(map, out UUID sculptId))
  7601. sculptId = ScriptUtils.GetAssetIdFromItemName(m_host, map, (int)AssetType.Texture);
  7602. if (sculptId == UUID.Zero)
  7603. return;
  7604. shapeBlock.PathCurve = pathcurve;
  7605. shapeBlock.ObjectLocalID = part.LocalId;
  7606. shapeBlock.PathScaleX = 100;
  7607. shapeBlock.PathScaleY = 150;
  7608. int flag = type & (ScriptBaseClass.PRIM_SCULPT_FLAG_INVERT | ScriptBaseClass.PRIM_SCULPT_FLAG_MIRROR);
  7609. if (type != (ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER | flag) &&
  7610. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE | flag) &&
  7611. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE | flag) &&
  7612. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS | flag))
  7613. {
  7614. // default
  7615. type = type | (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
  7616. }
  7617. part.Shape.SetSculptProperties((byte)type, sculptId);
  7618. part.Shape.SculptEntry = true;
  7619. part.UpdateShape(shapeBlock);
  7620. }
  7621. public void llSetPrimitiveParams(LSL_List rules)
  7622. {
  7623. m_host.AddScriptLPS(1);
  7624. SetLinkPrimParams(ScriptBaseClass.LINK_THIS, rules, "llSetPrimitiveParams");
  7625. ScriptSleep(m_sleepMsOnSetPrimitiveParams);
  7626. }
  7627. public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
  7628. {
  7629. m_host.AddScriptLPS(1);
  7630. SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParams");
  7631. ScriptSleep(m_sleepMsOnSetLinkPrimitiveParams);
  7632. }
  7633. public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
  7634. {
  7635. m_host.AddScriptLPS(1);
  7636. SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParamsFast");
  7637. }
  7638. private void SetLinkPrimParams(int linknumber, LSL_List rules, string originFunc)
  7639. {
  7640. List<object> parts = new List<object>();
  7641. List<SceneObjectPart> prims = GetLinkParts(linknumber);
  7642. List<ScenePresence> avatars = GetLinkAvatars(linknumber);
  7643. foreach (SceneObjectPart p in prims)
  7644. parts.Add(p);
  7645. foreach (ScenePresence p in avatars)
  7646. parts.Add(p);
  7647. LSL_List remaining = new LSL_List();
  7648. uint rulesParsed = 0;
  7649. if (parts.Count > 0)
  7650. {
  7651. foreach (object part in parts)
  7652. {
  7653. if (part is SceneObjectPart)
  7654. remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
  7655. else
  7656. remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
  7657. }
  7658. while (remaining.Length > 2)
  7659. {
  7660. linknumber = remaining.GetLSLIntegerItem(0);
  7661. rules = remaining.GetSublist(1, -1);
  7662. parts.Clear();
  7663. prims = GetLinkParts(linknumber);
  7664. avatars = GetLinkAvatars(linknumber);
  7665. foreach (SceneObjectPart p in prims)
  7666. parts.Add(p);
  7667. foreach (ScenePresence p in avatars)
  7668. parts.Add(p);
  7669. remaining = new LSL_List();
  7670. foreach (object part in parts)
  7671. {
  7672. if (part is SceneObjectPart)
  7673. remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
  7674. else
  7675. remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
  7676. }
  7677. }
  7678. }
  7679. }
  7680. public void llSetKeyframedMotion(LSL_List frames, LSL_List options)
  7681. {
  7682. SceneObjectGroup group = m_host.ParentGroup;
  7683. if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
  7684. return;
  7685. if (group.IsAttachment)
  7686. return;
  7687. if (frames.Data.Length > 0) // We are getting a new motion
  7688. {
  7689. if (group.RootPart.KeyframeMotion != null)
  7690. group.RootPart.KeyframeMotion.Delete();
  7691. group.RootPart.KeyframeMotion = null;
  7692. int idx = 0;
  7693. KeyframeMotion.PlayMode mode = KeyframeMotion.PlayMode.Forward;
  7694. KeyframeMotion.DataFormat data = KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation;
  7695. while (idx < options.Data.Length)
  7696. {
  7697. int option = (int)options.GetLSLIntegerItem(idx++);
  7698. int remain = options.Data.Length - idx;
  7699. switch (option)
  7700. {
  7701. case ScriptBaseClass.KFM_MODE:
  7702. if (remain < 1)
  7703. break;
  7704. int modeval = (int)options.GetLSLIntegerItem(idx++);
  7705. switch(modeval)
  7706. {
  7707. case ScriptBaseClass.KFM_FORWARD:
  7708. mode = KeyframeMotion.PlayMode.Forward;
  7709. break;
  7710. case ScriptBaseClass.KFM_REVERSE:
  7711. mode = KeyframeMotion.PlayMode.Reverse;
  7712. break;
  7713. case ScriptBaseClass.KFM_LOOP:
  7714. mode = KeyframeMotion.PlayMode.Loop;
  7715. break;
  7716. case ScriptBaseClass.KFM_PING_PONG:
  7717. mode = KeyframeMotion.PlayMode.PingPong;
  7718. break;
  7719. }
  7720. break;
  7721. case ScriptBaseClass.KFM_DATA:
  7722. if (remain < 1)
  7723. break;
  7724. int dataval = (int)options.GetLSLIntegerItem(idx++);
  7725. data = (KeyframeMotion.DataFormat)dataval;
  7726. break;
  7727. }
  7728. }
  7729. group.RootPart.KeyframeMotion = new KeyframeMotion(group, mode, data);
  7730. idx = 0;
  7731. int elemLength = 2;
  7732. if (data == (KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation))
  7733. elemLength = 3;
  7734. List<KeyframeMotion.Keyframe> keyframes = new List<KeyframeMotion.Keyframe>();
  7735. bool hasTranslation = (data & KeyframeMotion.DataFormat.Translation) != 0;
  7736. bool hasRotation = (data & KeyframeMotion.DataFormat.Rotation) != 0;
  7737. while (idx < frames.Data.Length)
  7738. {
  7739. int remain = frames.Data.Length - idx;
  7740. if (remain < elemLength)
  7741. break;
  7742. KeyframeMotion.Keyframe frame = new KeyframeMotion.Keyframe
  7743. {
  7744. Position = null,
  7745. Rotation = null
  7746. };
  7747. if (hasTranslation)
  7748. {
  7749. LSL_Types.Vector3 tempv = frames.GetVector3Item(idx++);
  7750. frame.Position = new Vector3((float)tempv.x, (float)tempv.y, (float)tempv.z);
  7751. }
  7752. if (hasRotation)
  7753. {
  7754. LSL_Types.Quaternion tempq = frames.GetQuaternionItem(idx++);
  7755. Quaternion q = new Quaternion((float)tempq.x, (float)tempq.y, (float)tempq.z, (float)tempq.s);
  7756. frame.Rotation = q;
  7757. }
  7758. float tempf = (float)frames.GetLSLFloatItem(idx++);
  7759. frame.TimeMS = (int)(tempf * 1000.0f);
  7760. keyframes.Add(frame);
  7761. }
  7762. group.RootPart.KeyframeMotion.SetKeyframes(keyframes.ToArray());
  7763. group.RootPart.KeyframeMotion.Start();
  7764. }
  7765. else
  7766. {
  7767. if (group.RootPart.KeyframeMotion == null)
  7768. return;
  7769. if (options.Data.Length == 0)
  7770. {
  7771. group.RootPart.KeyframeMotion.Stop();
  7772. return;
  7773. }
  7774. int idx = 0;
  7775. while (idx < options.Data.Length)
  7776. {
  7777. int option = (int)options.GetLSLIntegerItem(idx++);
  7778. switch (option)
  7779. {
  7780. case ScriptBaseClass.KFM_COMMAND:
  7781. int cmd = (int)options.GetLSLIntegerItem(idx++);
  7782. switch (cmd)
  7783. {
  7784. case ScriptBaseClass.KFM_CMD_PLAY:
  7785. group.RootPart.KeyframeMotion.Start();
  7786. break;
  7787. case ScriptBaseClass.KFM_CMD_STOP:
  7788. group.RootPart.KeyframeMotion.Stop();
  7789. break;
  7790. case ScriptBaseClass.KFM_CMD_PAUSE:
  7791. group.RootPart.KeyframeMotion.Pause();
  7792. break;
  7793. }
  7794. break;
  7795. }
  7796. }
  7797. }
  7798. }
  7799. public LSL_List llGetPhysicsMaterial()
  7800. {
  7801. LSL_List result = new LSL_List();
  7802. result.Add(new LSL_Float(m_host.GravityModifier));
  7803. result.Add(new LSL_Float(m_host.Restitution));
  7804. result.Add(new LSL_Float(m_host.Friction));
  7805. result.Add(new LSL_Float(m_host.Density));
  7806. return result;
  7807. }
  7808. private void SetPhysicsMaterial(SceneObjectPart part, int material_bits,
  7809. float material_density, float material_friction,
  7810. float material_restitution, float material_gravity_modifier)
  7811. {
  7812. ExtraPhysicsData physdata = new ExtraPhysicsData
  7813. {
  7814. PhysShapeType = (PhysShapeType)part.PhysicsShapeType,
  7815. Density = part.Density,
  7816. Friction = part.Friction,
  7817. Bounce = part.Restitution,
  7818. GravitationModifier = part.GravityModifier
  7819. };
  7820. if ((material_bits & (int)ScriptBaseClass.DENSITY) != 0)
  7821. physdata.Density = material_density;
  7822. if ((material_bits & (int)ScriptBaseClass.FRICTION) != 0)
  7823. physdata.Friction = material_friction;
  7824. if ((material_bits & (int)ScriptBaseClass.RESTITUTION) != 0)
  7825. physdata.Bounce = material_restitution;
  7826. if ((material_bits & (int)ScriptBaseClass.GRAVITY_MULTIPLIER) != 0)
  7827. physdata.GravitationModifier = material_gravity_modifier;
  7828. part.UpdateExtraPhysics(physdata);
  7829. }
  7830. public void llSetPhysicsMaterial(int material_bits,
  7831. LSL_Float material_gravity_modifier, LSL_Float material_restitution,
  7832. LSL_Float material_friction, LSL_Float material_density)
  7833. {
  7834. SetPhysicsMaterial(m_host, material_bits, (float)material_density, (float)material_friction, (float)material_restitution, (float)material_gravity_modifier);
  7835. }
  7836. // vector up using libomv (c&p from sop )
  7837. // vector up rotated by r
  7838. private Vector3 Zrot(Quaternion r)
  7839. {
  7840. double x, y, z, m;
  7841. m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
  7842. if (Math.Abs(1.0 - m) > 0.000001)
  7843. {
  7844. m = 1.0 / Math.Sqrt(m);
  7845. r.X *= (float)m;
  7846. r.Y *= (float)m;
  7847. r.Z *= (float)m;
  7848. r.W *= (float)m;
  7849. }
  7850. x = 2 * (r.X * r.Z + r.Y * r.W);
  7851. y = 2 * (-r.X * r.W + r.Y * r.Z);
  7852. z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
  7853. return new Vector3((float)x, (float)y, (float)z);
  7854. }
  7855. protected LSL_List SetPrimParams(SceneObjectPart part, LSL_List rules, string originFunc, ref uint rulesParsed)
  7856. {
  7857. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7858. return new LSL_List();
  7859. int idx = 0;
  7860. int idxStart = 0;
  7861. SceneObjectGroup parentgrp = part.ParentGroup;
  7862. bool positionChanged = false;
  7863. bool materialChanged = false;
  7864. LSL_Vector currentPosition = GetPartLocalPos(part);
  7865. try
  7866. {
  7867. while (idx < rules.Length)
  7868. {
  7869. ++rulesParsed;
  7870. int code = rules.GetLSLIntegerItem(idx++);
  7871. int remain = rules.Length - idx;
  7872. idxStart = idx;
  7873. int face;
  7874. LSL_Vector v;
  7875. switch (code)
  7876. {
  7877. case ScriptBaseClass.PRIM_POSITION:
  7878. case ScriptBaseClass.PRIM_POS_LOCAL:
  7879. if (remain < 1)
  7880. return new LSL_List();
  7881. try
  7882. {
  7883. v = rules.GetVector3Item(idx++);
  7884. }
  7885. catch(InvalidCastException)
  7886. {
  7887. if(code == ScriptBaseClass.PRIM_POSITION)
  7888. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1));
  7889. else
  7890. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1));
  7891. return new LSL_List();
  7892. }
  7893. if (part.IsRoot && !part.ParentGroup.IsAttachment)
  7894. currentPosition = GetSetPosTarget(part, v, currentPosition, true);
  7895. else
  7896. currentPosition = GetSetPosTarget(part, v, currentPosition, false);
  7897. positionChanged = true;
  7898. break;
  7899. case ScriptBaseClass.PRIM_SIZE:
  7900. if (remain < 1)
  7901. return new LSL_List();
  7902. v=rules.GetVector3Item(idx++);
  7903. SetScale(part, v);
  7904. break;
  7905. case ScriptBaseClass.PRIM_ROTATION:
  7906. if (remain < 1)
  7907. return new LSL_List();
  7908. LSL_Rotation q;
  7909. try
  7910. {
  7911. q = rules.GetQuaternionItem(idx++);
  7912. }
  7913. catch(InvalidCastException)
  7914. {
  7915. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 1 must be rotation", rulesParsed, idx - idxStart - 1));
  7916. return new LSL_List();
  7917. }
  7918. // try to let this work as in SL...
  7919. if (part.ParentID == 0 || (part.ParentGroup != null && part == part.ParentGroup.RootPart))
  7920. {
  7921. // special case: If we are root, rotate complete SOG to new rotation
  7922. SetRot(part, q);
  7923. }
  7924. else
  7925. {
  7926. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  7927. SceneObjectPart rootPart = part.ParentGroup.RootPart;
  7928. SetRot(part, rootPart.RotationOffset * (Quaternion)q);
  7929. }
  7930. break;
  7931. case ScriptBaseClass.PRIM_TYPE:
  7932. if (remain < 3)
  7933. return new LSL_List();
  7934. try
  7935. {
  7936. code = (int)rules.GetLSLIntegerItem(idx++);
  7937. }
  7938. catch(InvalidCastException)
  7939. {
  7940. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE: arg #{1} - parameter 1 must be integer", rulesParsed, idx - idxStart - 1));
  7941. return new LSL_List();
  7942. }
  7943. remain = rules.Length - idx;
  7944. float hollow;
  7945. LSL_Vector twist;
  7946. LSL_Vector taper_b;
  7947. LSL_Vector topshear;
  7948. float revolutions;
  7949. float radiusoffset;
  7950. float skew;
  7951. LSL_Vector holesize;
  7952. LSL_Vector profilecut;
  7953. switch (code)
  7954. {
  7955. case ScriptBaseClass.PRIM_TYPE_BOX:
  7956. if (remain < 6)
  7957. return new LSL_List();
  7958. try
  7959. {
  7960. face = (int)rules.GetLSLIntegerItem(idx++);
  7961. }
  7962. catch(InvalidCastException)
  7963. {
  7964. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  7965. return new LSL_List();
  7966. }
  7967. try
  7968. {
  7969. v = rules.GetVector3Item(idx++); // cut
  7970. }
  7971. catch(InvalidCastException)
  7972. {
  7973. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  7974. return new LSL_List();
  7975. }
  7976. try
  7977. {
  7978. hollow = (float)rules.GetLSLFloatItem(idx++);
  7979. }
  7980. catch(InvalidCastException)
  7981. {
  7982. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  7983. return new LSL_List();
  7984. }
  7985. try
  7986. {
  7987. twist = rules.GetVector3Item(idx++);
  7988. }
  7989. catch(InvalidCastException)
  7990. {
  7991. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 5 must be vector", rulesParsed, idx - idxStart - 1));
  7992. return new LSL_List();
  7993. }
  7994. try
  7995. {
  7996. taper_b = rules.GetVector3Item(idx++);
  7997. }
  7998. catch(InvalidCastException)
  7999. {
  8000. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8001. return new LSL_List();
  8002. }
  8003. try
  8004. {
  8005. topshear = rules.GetVector3Item(idx++);
  8006. }
  8007. catch(InvalidCastException)
  8008. {
  8009. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8010. return new LSL_List();
  8011. }
  8012. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  8013. (byte)ProfileShape.Square, (byte)Extrusion.Straight);
  8014. break;
  8015. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  8016. if (remain < 6)
  8017. return new LSL_List();
  8018. try
  8019. {
  8020. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8021. }
  8022. catch(InvalidCastException)
  8023. {
  8024. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8025. return new LSL_List();
  8026. }
  8027. try
  8028. {
  8029. v = rules.GetVector3Item(idx++); // cut
  8030. }
  8031. catch(InvalidCastException)
  8032. {
  8033. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8034. return new LSL_List();
  8035. }
  8036. try
  8037. {
  8038. hollow = (float)rules.GetLSLFloatItem(idx++);
  8039. }
  8040. catch(InvalidCastException)
  8041. {
  8042. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8043. return new LSL_List();
  8044. }
  8045. try
  8046. {
  8047. twist = rules.GetVector3Item(idx++);
  8048. }
  8049. catch(InvalidCastException)
  8050. {
  8051. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8052. return new LSL_List();
  8053. }
  8054. try
  8055. {
  8056. taper_b = rules.GetVector3Item(idx++);
  8057. }
  8058. catch(InvalidCastException)
  8059. {
  8060. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8061. return new LSL_List();
  8062. }
  8063. try
  8064. {
  8065. topshear = rules.GetVector3Item(idx++);
  8066. }
  8067. catch(InvalidCastException)
  8068. {
  8069. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8070. return new LSL_List();
  8071. }
  8072. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  8073. (byte)ProfileShape.Circle, (byte)Extrusion.Straight);
  8074. break;
  8075. case ScriptBaseClass.PRIM_TYPE_PRISM:
  8076. if (remain < 6)
  8077. return new LSL_List();
  8078. try
  8079. {
  8080. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8081. }
  8082. catch(InvalidCastException)
  8083. {
  8084. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8085. return new LSL_List();
  8086. }
  8087. try
  8088. {
  8089. v = rules.GetVector3Item(idx++); //cut
  8090. }
  8091. catch(InvalidCastException)
  8092. {
  8093. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8094. return new LSL_List();
  8095. }
  8096. try
  8097. {
  8098. hollow = (float)rules.GetLSLFloatItem(idx++);
  8099. }
  8100. catch(InvalidCastException)
  8101. {
  8102. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8103. return new LSL_List();
  8104. }
  8105. try
  8106. {
  8107. twist = rules.GetVector3Item(idx++);
  8108. }
  8109. catch(InvalidCastException)
  8110. {
  8111. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8112. return new LSL_List();
  8113. }
  8114. try
  8115. {
  8116. taper_b = rules.GetVector3Item(idx++);
  8117. }
  8118. catch(InvalidCastException)
  8119. {
  8120. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8121. return new LSL_List();
  8122. }
  8123. try
  8124. {
  8125. topshear = rules.GetVector3Item(idx++);
  8126. }
  8127. catch(InvalidCastException)
  8128. {
  8129. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8130. return new LSL_List();
  8131. }
  8132. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  8133. (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Straight);
  8134. break;
  8135. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  8136. if (remain < 5)
  8137. return new LSL_List();
  8138. try
  8139. {
  8140. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8141. }
  8142. catch(InvalidCastException)
  8143. {
  8144. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8145. return new LSL_List();
  8146. }
  8147. try
  8148. {
  8149. v = rules.GetVector3Item(idx++); // cut
  8150. }
  8151. catch(InvalidCastException)
  8152. {
  8153. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8154. return new LSL_List();
  8155. }
  8156. try
  8157. {
  8158. hollow = (float)rules.GetLSLFloatItem(idx++);
  8159. }
  8160. catch(InvalidCastException)
  8161. {
  8162. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8163. return new LSL_List();
  8164. }
  8165. try
  8166. {
  8167. twist = rules.GetVector3Item(idx++);
  8168. }
  8169. catch(InvalidCastException)
  8170. {
  8171. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8172. return new LSL_List();
  8173. }
  8174. try
  8175. {
  8176. taper_b = rules.GetVector3Item(idx++); // dimple
  8177. }
  8178. catch(InvalidCastException)
  8179. {
  8180. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8181. return new LSL_List();
  8182. }
  8183. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b,
  8184. (byte)ProfileShape.HalfCircle, (byte)Extrusion.Curve1);
  8185. break;
  8186. case ScriptBaseClass.PRIM_TYPE_TORUS:
  8187. if (remain < 11)
  8188. return new LSL_List();
  8189. try
  8190. {
  8191. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8192. }
  8193. catch(InvalidCastException)
  8194. {
  8195. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8196. return new LSL_List();
  8197. }
  8198. try
  8199. {
  8200. v = rules.GetVector3Item(idx++); //cut
  8201. }
  8202. catch(InvalidCastException)
  8203. {
  8204. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8205. return new LSL_List();
  8206. }
  8207. try
  8208. {
  8209. hollow = (float)rules.GetLSLFloatItem(idx++);
  8210. }
  8211. catch(InvalidCastException)
  8212. {
  8213. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8214. return new LSL_List();
  8215. }
  8216. try
  8217. {
  8218. twist = rules.GetVector3Item(idx++);
  8219. }
  8220. catch(InvalidCastException)
  8221. {
  8222. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8223. return new LSL_List();
  8224. }
  8225. try
  8226. {
  8227. holesize = rules.GetVector3Item(idx++);
  8228. }
  8229. catch(InvalidCastException)
  8230. {
  8231. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8232. return new LSL_List();
  8233. }
  8234. try
  8235. {
  8236. topshear = rules.GetVector3Item(idx++);
  8237. }
  8238. catch(InvalidCastException)
  8239. {
  8240. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8241. return new LSL_List();
  8242. }
  8243. try
  8244. {
  8245. profilecut = rules.GetVector3Item(idx++);
  8246. }
  8247. catch(InvalidCastException)
  8248. {
  8249. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  8250. return new LSL_List();
  8251. }
  8252. try
  8253. {
  8254. taper_b = rules.GetVector3Item(idx++); // taper_a
  8255. }
  8256. catch(InvalidCastException)
  8257. {
  8258. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  8259. return new LSL_List();
  8260. }
  8261. try
  8262. {
  8263. revolutions = (float)rules.GetLSLFloatItem(idx++);
  8264. }
  8265. catch(InvalidCastException)
  8266. {
  8267. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  8268. return new LSL_List();
  8269. }
  8270. try
  8271. {
  8272. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  8273. }
  8274. catch(InvalidCastException)
  8275. {
  8276. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  8277. return new LSL_List();
  8278. }
  8279. try
  8280. {
  8281. skew = (float)rules.GetLSLFloatItem(idx++);
  8282. }
  8283. catch(InvalidCastException)
  8284. {
  8285. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 13 must be vector", rulesParsed, idx - idxStart - 1));
  8286. return new LSL_List();
  8287. }
  8288. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  8289. revolutions, radiusoffset, skew, (byte)ProfileShape.Circle, (byte)Extrusion.Curve1);
  8290. break;
  8291. case ScriptBaseClass.PRIM_TYPE_TUBE:
  8292. if (remain < 11)
  8293. return new LSL_List();
  8294. try
  8295. {
  8296. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8297. }
  8298. catch(InvalidCastException)
  8299. {
  8300. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8301. return new LSL_List();
  8302. }
  8303. try
  8304. {
  8305. v = rules.GetVector3Item(idx++); //cut
  8306. }
  8307. catch(InvalidCastException)
  8308. {
  8309. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8310. return new LSL_List();
  8311. }
  8312. try
  8313. {
  8314. hollow = (float)rules.GetLSLFloatItem(idx++);
  8315. }
  8316. catch(InvalidCastException)
  8317. {
  8318. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8319. return new LSL_List();
  8320. }
  8321. try
  8322. {
  8323. twist = rules.GetVector3Item(idx++);
  8324. }
  8325. catch(InvalidCastException)
  8326. {
  8327. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8328. return new LSL_List();
  8329. }
  8330. try
  8331. {
  8332. holesize = rules.GetVector3Item(idx++);
  8333. }
  8334. catch(InvalidCastException)
  8335. {
  8336. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8337. return new LSL_List();
  8338. }
  8339. try
  8340. {
  8341. topshear = rules.GetVector3Item(idx++);
  8342. }
  8343. catch(InvalidCastException)
  8344. {
  8345. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8346. return new LSL_List();
  8347. }
  8348. try
  8349. {
  8350. profilecut = rules.GetVector3Item(idx++);
  8351. }
  8352. catch(InvalidCastException)
  8353. {
  8354. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  8355. return new LSL_List();
  8356. }
  8357. try
  8358. {
  8359. taper_b = rules.GetVector3Item(idx++); // taper_a
  8360. }
  8361. catch(InvalidCastException)
  8362. {
  8363. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  8364. return new LSL_List();
  8365. }
  8366. try
  8367. {
  8368. revolutions = (float)rules.GetLSLFloatItem(idx++);
  8369. }
  8370. catch(InvalidCastException)
  8371. {
  8372. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  8373. return new LSL_List();
  8374. }
  8375. try
  8376. {
  8377. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  8378. }
  8379. catch(InvalidCastException)
  8380. {
  8381. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  8382. return new LSL_List();
  8383. }
  8384. try
  8385. {
  8386. skew = (float)rules.GetLSLFloatItem(idx++);
  8387. }
  8388. catch(InvalidCastException)
  8389. {
  8390. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 13 must be float", rulesParsed, idx - idxStart - 1));
  8391. return new LSL_List();
  8392. }
  8393. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  8394. revolutions, radiusoffset, skew, (byte)ProfileShape.Square, (byte)Extrusion.Curve1);
  8395. break;
  8396. case ScriptBaseClass.PRIM_TYPE_RING:
  8397. if (remain < 11)
  8398. return new LSL_List();
  8399. try
  8400. {
  8401. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8402. }
  8403. catch(InvalidCastException)
  8404. {
  8405. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8406. return new LSL_List();
  8407. }
  8408. try
  8409. {
  8410. v = rules.GetVector3Item(idx++); //cut
  8411. }
  8412. catch(InvalidCastException)
  8413. {
  8414. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8415. return new LSL_List();
  8416. }
  8417. try
  8418. {
  8419. hollow = (float)rules.GetLSLFloatItem(idx++);
  8420. }
  8421. catch(InvalidCastException)
  8422. {
  8423. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8424. return new LSL_List();
  8425. }
  8426. try
  8427. {
  8428. twist = rules.GetVector3Item(idx++);
  8429. }
  8430. catch(InvalidCastException)
  8431. {
  8432. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8433. return new LSL_List();
  8434. }
  8435. try
  8436. {
  8437. holesize = rules.GetVector3Item(idx++);
  8438. }
  8439. catch(InvalidCastException)
  8440. {
  8441. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8442. return new LSL_List();
  8443. }
  8444. try
  8445. {
  8446. topshear = rules.GetVector3Item(idx++);
  8447. }
  8448. catch(InvalidCastException)
  8449. {
  8450. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8451. return new LSL_List();
  8452. }
  8453. try
  8454. {
  8455. profilecut = rules.GetVector3Item(idx++);
  8456. }
  8457. catch(InvalidCastException)
  8458. {
  8459. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  8460. return new LSL_List();
  8461. }
  8462. try
  8463. {
  8464. taper_b = rules.GetVector3Item(idx++); // taper_a
  8465. }
  8466. catch(InvalidCastException)
  8467. {
  8468. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  8469. return new LSL_List();
  8470. }
  8471. try
  8472. {
  8473. revolutions = (float)rules.GetLSLFloatItem(idx++);
  8474. }
  8475. catch(InvalidCastException)
  8476. {
  8477. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  8478. return new LSL_List();
  8479. }
  8480. try
  8481. {
  8482. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  8483. }
  8484. catch(InvalidCastException)
  8485. {
  8486. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  8487. return new LSL_List();
  8488. }
  8489. try
  8490. {
  8491. skew = (float)rules.GetLSLFloatItem(idx++);
  8492. }
  8493. catch(InvalidCastException)
  8494. {
  8495. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 13 must be float", rulesParsed, idx - idxStart - 1));
  8496. return new LSL_List();
  8497. }
  8498. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  8499. revolutions, radiusoffset, skew, (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Curve1);
  8500. break;
  8501. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  8502. if (remain < 2)
  8503. return new LSL_List();
  8504. string map = rules.Data[idx++].ToString();
  8505. try
  8506. {
  8507. face = (int)rules.GetLSLIntegerItem(idx++); // type
  8508. }
  8509. catch(InvalidCastException)
  8510. {
  8511. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SCULPT: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  8512. return new LSL_List();
  8513. }
  8514. SetPrimitiveShapeParams(part, map, face, (byte)Extrusion.Curve1);
  8515. break;
  8516. }
  8517. break;
  8518. case ScriptBaseClass.PRIM_TEXTURE:
  8519. if (remain < 5)
  8520. return new LSL_List();
  8521. face=(int)rules.GetLSLIntegerItem(idx++);
  8522. string tex;
  8523. LSL_Vector repeats;
  8524. LSL_Vector offsets;
  8525. double rotation;
  8526. tex = rules.Data[idx++].ToString();
  8527. try
  8528. {
  8529. repeats = rules.GetVector3Item(idx++);
  8530. }
  8531. catch(InvalidCastException)
  8532. {
  8533. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8534. return new LSL_List();
  8535. }
  8536. try
  8537. {
  8538. offsets = rules.GetVector3Item(idx++);
  8539. }
  8540. catch(InvalidCastException)
  8541. {
  8542. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8543. return new LSL_List();
  8544. }
  8545. try
  8546. {
  8547. rotation = (double)rules.GetLSLFloatItem(idx++);
  8548. }
  8549. catch(InvalidCastException)
  8550. {
  8551. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8552. return new LSL_List();
  8553. }
  8554. SetTextureParams(part, tex, repeats.x, repeats.y, offsets.x, offsets.y, rotation, face);
  8555. break;
  8556. case ScriptBaseClass.PRIM_COLOR:
  8557. if (remain < 3)
  8558. return new LSL_List();
  8559. LSL_Vector color;
  8560. double alpha;
  8561. try
  8562. {
  8563. face = (int)rules.GetLSLIntegerItem(idx++);
  8564. }
  8565. catch(InvalidCastException)
  8566. {
  8567. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8568. return new LSL_List();
  8569. }
  8570. try
  8571. {
  8572. color = rules.GetVector3Item(idx++);
  8573. }
  8574. catch(InvalidCastException)
  8575. {
  8576. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8577. return new LSL_List();
  8578. }
  8579. try
  8580. {
  8581. alpha = (double)rules.GetLSLFloatItem(idx++);
  8582. }
  8583. catch(InvalidCastException)
  8584. {
  8585. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8586. return new LSL_List();
  8587. }
  8588. part.SetFaceColorAlpha(face, color, alpha);
  8589. break;
  8590. case ScriptBaseClass.PRIM_FLEXIBLE:
  8591. if (remain < 7)
  8592. return new LSL_List();
  8593. bool flexi;
  8594. int softness;
  8595. float gravity;
  8596. float friction;
  8597. float wind;
  8598. float tension;
  8599. LSL_Vector force;
  8600. try
  8601. {
  8602. flexi = rules.GetLSLIntegerItem(idx++);
  8603. }
  8604. catch(InvalidCastException)
  8605. {
  8606. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8607. return new LSL_List();
  8608. }
  8609. try
  8610. {
  8611. softness = rules.GetLSLIntegerItem(idx++);
  8612. }
  8613. catch(InvalidCastException)
  8614. {
  8615. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8616. return new LSL_List();
  8617. }
  8618. try
  8619. {
  8620. gravity = (float)rules.GetLSLFloatItem(idx++);
  8621. }
  8622. catch(InvalidCastException)
  8623. {
  8624. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8625. return new LSL_List();
  8626. }
  8627. try
  8628. {
  8629. friction = (float)rules.GetLSLFloatItem(idx++);
  8630. }
  8631. catch(InvalidCastException)
  8632. {
  8633. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8634. return new LSL_List();
  8635. }
  8636. try
  8637. {
  8638. wind = (float)rules.GetLSLFloatItem(idx++);
  8639. }
  8640. catch(InvalidCastException)
  8641. {
  8642. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 6 must be float", rulesParsed, idx - idxStart - 1));
  8643. return new LSL_List();
  8644. }
  8645. try
  8646. {
  8647. tension = (float)rules.GetLSLFloatItem(idx++);
  8648. }
  8649. catch(InvalidCastException)
  8650. {
  8651. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 7 must be float", rulesParsed, idx - idxStart - 1));
  8652. return new LSL_List();
  8653. }
  8654. try
  8655. {
  8656. force = rules.GetVector3Item(idx++);
  8657. }
  8658. catch(InvalidCastException)
  8659. {
  8660. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8661. return new LSL_List();
  8662. }
  8663. SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force);
  8664. break;
  8665. case ScriptBaseClass.PRIM_POINT_LIGHT:
  8666. if (remain < 5)
  8667. return new LSL_List();
  8668. bool light;
  8669. LSL_Vector lightcolor;
  8670. float intensity;
  8671. float radius;
  8672. float falloff;
  8673. try
  8674. {
  8675. light = rules.GetLSLIntegerItem(idx++);
  8676. }
  8677. catch(InvalidCastException)
  8678. {
  8679. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8680. return new LSL_List();
  8681. }
  8682. try
  8683. {
  8684. lightcolor = rules.GetVector3Item(idx++);
  8685. }
  8686. catch(InvalidCastException)
  8687. {
  8688. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8689. return new LSL_List();
  8690. }
  8691. try
  8692. {
  8693. intensity = (float)rules.GetLSLFloatItem(idx++);
  8694. }
  8695. catch(InvalidCastException)
  8696. {
  8697. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8698. return new LSL_List();
  8699. }
  8700. try
  8701. {
  8702. radius = (float)rules.GetLSLFloatItem(idx++);
  8703. }
  8704. catch(InvalidCastException)
  8705. {
  8706. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8707. return new LSL_List();
  8708. }
  8709. try
  8710. {
  8711. falloff = (float)rules.GetLSLFloatItem(idx++);
  8712. }
  8713. catch(InvalidCastException)
  8714. {
  8715. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 6 must be float", rulesParsed, idx - idxStart - 1));
  8716. return new LSL_List();
  8717. }
  8718. SetPointLight(part, light, lightcolor, intensity, radius, falloff);
  8719. break;
  8720. case ScriptBaseClass.PRIM_GLOW:
  8721. if (remain < 2)
  8722. return new LSL_List();
  8723. float glow;
  8724. try
  8725. {
  8726. face = rules.GetLSLIntegerItem(idx++);
  8727. }
  8728. catch(InvalidCastException)
  8729. {
  8730. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_GLOW: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8731. return new LSL_List();
  8732. }
  8733. try
  8734. {
  8735. glow = (float)rules.GetLSLFloatItem(idx++);
  8736. }
  8737. catch(InvalidCastException)
  8738. {
  8739. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_GLOW: arg #{1} - parameter 3 must be float", rulesParsed, idx - idxStart - 1));
  8740. return new LSL_List();
  8741. }
  8742. SetGlow(part, face, glow);
  8743. break;
  8744. case ScriptBaseClass.PRIM_BUMP_SHINY:
  8745. if (remain < 3)
  8746. return new LSL_List();
  8747. int shiny;
  8748. Bumpiness bump;
  8749. try
  8750. {
  8751. face = (int)rules.GetLSLIntegerItem(idx++);
  8752. }
  8753. catch(InvalidCastException)
  8754. {
  8755. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8756. return new LSL_List();
  8757. }
  8758. try
  8759. {
  8760. shiny = (int)rules.GetLSLIntegerItem(idx++);
  8761. }
  8762. catch(InvalidCastException)
  8763. {
  8764. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8765. return new LSL_List();
  8766. }
  8767. try
  8768. {
  8769. bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);
  8770. }
  8771. catch(InvalidCastException)
  8772. {
  8773. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  8774. return new LSL_List();
  8775. }
  8776. SetShiny(part, face, shiny, bump);
  8777. break;
  8778. case ScriptBaseClass.PRIM_FULLBRIGHT:
  8779. if (remain < 2)
  8780. return new LSL_List();
  8781. bool st;
  8782. try
  8783. {
  8784. face = rules.GetLSLIntegerItem(idx++);
  8785. }
  8786. catch(InvalidCastException)
  8787. {
  8788. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FULLBRIGHT: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8789. return new LSL_List();
  8790. }
  8791. try
  8792. {
  8793. st = rules.GetLSLIntegerItem(idx++);
  8794. }
  8795. catch(InvalidCastException)
  8796. {
  8797. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FULLBRIGHT: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  8798. return new LSL_List();
  8799. }
  8800. SetFullBright(part, face , st);
  8801. break;
  8802. case ScriptBaseClass.PRIM_MATERIAL:
  8803. if (remain < 1)
  8804. return new LSL_List();
  8805. int mat;
  8806. try
  8807. {
  8808. mat = rules.GetLSLIntegerItem(idx++);
  8809. }
  8810. catch(InvalidCastException)
  8811. {
  8812. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_MATERIAL: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8813. return new LSL_List();
  8814. }
  8815. if (mat < 0 || mat > 7)
  8816. return new LSL_List();
  8817. part.Material = Convert.ToByte(mat);
  8818. break;
  8819. case ScriptBaseClass.PRIM_PHANTOM:
  8820. if (remain < 1)
  8821. return new LSL_List();
  8822. string ph = rules.Data[idx++].ToString();
  8823. part.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1"));
  8824. break;
  8825. case ScriptBaseClass.PRIM_PHYSICS:
  8826. if (remain < 1)
  8827. return new LSL_List();
  8828. string phy = rules.Data[idx++].ToString();
  8829. part.ScriptSetPhysicsStatus(phy.Equals("1"));
  8830. break;
  8831. case ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  8832. if (remain < 1)
  8833. return new LSL_List();
  8834. int shape_type;
  8835. try
  8836. {
  8837. shape_type = rules.GetLSLIntegerItem(idx++);
  8838. }
  8839. catch(InvalidCastException)
  8840. {
  8841. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_PHYSICS_SHAPE_TYPE: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8842. return new LSL_List();
  8843. }
  8844. ExtraPhysicsData physdata = new ExtraPhysicsData
  8845. {
  8846. Density = part.Density,
  8847. Bounce = part.Restitution,
  8848. GravitationModifier = part.GravityModifier,
  8849. PhysShapeType = (PhysShapeType)shape_type
  8850. };
  8851. part.UpdateExtraPhysics(physdata);
  8852. break;
  8853. case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
  8854. if (remain < 5)
  8855. return new LSL_List();
  8856. int material_bits = rules.GetLSLIntegerItem(idx++);
  8857. float material_density = (float)rules.GetLSLFloatItem(idx++);
  8858. float material_friction = (float)rules.GetLSLFloatItem(idx++);
  8859. float material_restitution = (float)rules.GetLSLFloatItem(idx++);
  8860. float material_gravity_modifier = (float)rules.GetLSLFloatItem(idx++);
  8861. SetPhysicsMaterial(part, material_bits, material_density, material_friction, material_restitution, material_gravity_modifier);
  8862. break;
  8863. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  8864. if (remain < 1)
  8865. return new LSL_List();
  8866. string temp = rules.Data[idx++].ToString();
  8867. part.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1"));
  8868. break;
  8869. case ScriptBaseClass.PRIM_TEXGEN:
  8870. if (remain < 2)
  8871. return new LSL_List();
  8872. //face,type
  8873. int style;
  8874. try
  8875. {
  8876. face = rules.GetLSLIntegerItem(idx++);
  8877. }
  8878. catch(InvalidCastException)
  8879. {
  8880. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXGEN: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8881. return new LSL_List();
  8882. }
  8883. try
  8884. {
  8885. style = rules.GetLSLIntegerItem(idx++);
  8886. }
  8887. catch(InvalidCastException)
  8888. {
  8889. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXGEN: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8890. return new LSL_List();
  8891. }
  8892. SetTexGen(part, face, style);
  8893. break;
  8894. case ScriptBaseClass.PRIM_TEXT:
  8895. if (remain < 3)
  8896. return new LSL_List();
  8897. string primText;
  8898. LSL_Vector primTextColor;
  8899. LSL_Float primTextAlpha;
  8900. try
  8901. {
  8902. primText = rules.GetLSLStringItem(idx++);
  8903. }
  8904. catch(InvalidCastException)
  8905. {
  8906. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8907. return new LSL_List();
  8908. }
  8909. try
  8910. {
  8911. primTextColor = rules.GetVector3Item(idx++);
  8912. }
  8913. catch(InvalidCastException)
  8914. {
  8915. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8916. return new LSL_List();
  8917. }
  8918. try
  8919. {
  8920. primTextAlpha = rules.GetLSLFloatItem(idx++);
  8921. }
  8922. catch(InvalidCastException)
  8923. {
  8924. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8925. return new LSL_List();
  8926. }
  8927. Vector3 av3 = Util.Clip(primTextColor, 0.0f, 1.0f);
  8928. part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f));
  8929. break;
  8930. case ScriptBaseClass.PRIM_NAME:
  8931. if (remain < 1)
  8932. return new LSL_List();
  8933. try
  8934. {
  8935. string primName = rules.GetLSLStringItem(idx++);
  8936. part.Name = primName;
  8937. }
  8938. catch(InvalidCastException)
  8939. {
  8940. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NAME: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8941. return new LSL_List();
  8942. }
  8943. break;
  8944. case ScriptBaseClass.PRIM_DESC:
  8945. if (remain < 1)
  8946. return new LSL_List();
  8947. try
  8948. {
  8949. string primDesc = rules.GetLSLStringItem(idx++);
  8950. part.Description = primDesc;
  8951. }
  8952. catch(InvalidCastException)
  8953. {
  8954. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_DESC: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8955. return new LSL_List();
  8956. }
  8957. break;
  8958. case ScriptBaseClass.PRIM_ROT_LOCAL:
  8959. if (remain < 1)
  8960. return new LSL_List();
  8961. LSL_Rotation rot;
  8962. try
  8963. {
  8964. rot = rules.GetQuaternionItem(idx++);
  8965. }
  8966. catch(InvalidCastException)
  8967. {
  8968. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  8969. return new LSL_List();
  8970. }
  8971. SetRot(part, rot);
  8972. break;
  8973. case ScriptBaseClass.PRIM_OMEGA:
  8974. if (remain < 3)
  8975. return new LSL_List();
  8976. LSL_Vector axis;
  8977. LSL_Float spinrate;
  8978. LSL_Float gain;
  8979. try
  8980. {
  8981. axis = rules.GetVector3Item(idx++);
  8982. }
  8983. catch(InvalidCastException)
  8984. {
  8985. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  8986. return new LSL_List();
  8987. }
  8988. try
  8989. {
  8990. spinrate = rules.GetLSLFloatItem(idx++);
  8991. }
  8992. catch(InvalidCastException)
  8993. {
  8994. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 3 must be float", rulesParsed, idx - idxStart - 1));
  8995. return new LSL_List();
  8996. }
  8997. try
  8998. {
  8999. gain = rules.GetLSLFloatItem(idx++);
  9000. }
  9001. catch(InvalidCastException)
  9002. {
  9003. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  9004. return new LSL_List();
  9005. }
  9006. TargetOmega(part, axis, (double)spinrate, (double)gain);
  9007. break;
  9008. case ScriptBaseClass.PRIM_SLICE:
  9009. if (remain < 1)
  9010. return new LSL_List();
  9011. LSL_Vector slice;
  9012. try
  9013. {
  9014. slice = rules.GetVector3Item(idx++);
  9015. }
  9016. catch(InvalidCastException)
  9017. {
  9018. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SLICE: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  9019. return new LSL_List();
  9020. }
  9021. part.UpdateSlice((float)slice.x, (float)slice.y);
  9022. break;
  9023. case ScriptBaseClass.PRIM_SIT_TARGET:
  9024. if (remain < 3)
  9025. return new LSL_List();
  9026. int active;
  9027. try
  9028. {
  9029. active = rules.GetLSLIntegerItem(idx++);
  9030. }
  9031. catch(InvalidCastException)
  9032. {
  9033. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SIT_TARGET: arg #{1} - parameter 1 must be integer", rulesParsed, idx - idxStart - 1));
  9034. return new LSL_List();
  9035. }
  9036. LSL_Vector offset;
  9037. try
  9038. {
  9039. offset = rules.GetVector3Item(idx++);
  9040. }
  9041. catch(InvalidCastException)
  9042. {
  9043. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SIT_TARGET: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  9044. return new LSL_List();
  9045. }
  9046. LSL_Rotation sitrot;
  9047. try
  9048. {
  9049. sitrot = rules.GetQuaternionItem(idx++);
  9050. }
  9051. catch(InvalidCastException)
  9052. {
  9053. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SIT_TARGET: arg #{1} - parameter 3 must be rotation", rulesParsed, idx - idxStart - 1));
  9054. return new LSL_List();
  9055. }
  9056. // not SL compatible since we don't have a independent flag to control active target but use the values of offset and rotation
  9057. if(active == 1)
  9058. {
  9059. if(offset.x == 0 && offset.y == 0 && offset.z == 0 && sitrot.s == 1.0)
  9060. offset.z = 1e-5f; // hack
  9061. SitTarget(part,offset,sitrot);
  9062. }
  9063. else if(active == 0)
  9064. SitTarget(part, Vector3.Zero , Quaternion.Identity);
  9065. break;
  9066. case ScriptBaseClass.PRIM_ALPHA_MODE:
  9067. if (remain < 3)
  9068. return new LSL_List();
  9069. try
  9070. {
  9071. face = rules.GetLSLIntegerItem(idx++);
  9072. }
  9073. catch(InvalidCastException)
  9074. {
  9075. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9076. return new LSL_List();
  9077. }
  9078. int materialAlphaMode;
  9079. try
  9080. {
  9081. materialAlphaMode = rules.GetLSLIntegerItem(idx++);
  9082. }
  9083. catch(InvalidCastException)
  9084. {
  9085. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9086. return new LSL_List();
  9087. }
  9088. if(materialAlphaMode < 0 || materialAlphaMode > 3)
  9089. {
  9090. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be 0 to 3", rulesParsed, idx - idxStart - 1));
  9091. return new LSL_List();
  9092. }
  9093. int materialMaskCutoff;
  9094. try
  9095. {
  9096. materialMaskCutoff = rules.GetLSLIntegerItem(idx++);
  9097. }
  9098. catch(InvalidCastException)
  9099. {
  9100. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9101. return new LSL_List();
  9102. }
  9103. if(materialMaskCutoff < 0 || materialMaskCutoff > 255)
  9104. {
  9105. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be 0 to 255", rulesParsed, idx - idxStart - 1));
  9106. return new LSL_List();
  9107. }
  9108. materialChanged |= SetMaterialAlphaMode(part, face, materialAlphaMode, materialMaskCutoff);
  9109. break;
  9110. case ScriptBaseClass.PRIM_NORMAL:
  9111. if (remain < 5)
  9112. return new LSL_List();
  9113. try
  9114. {
  9115. face = rules.GetLSLIntegerItem(idx++);
  9116. }
  9117. catch(InvalidCastException)
  9118. {
  9119. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9120. return new LSL_List();
  9121. }
  9122. string mapname = rules.Data[idx++].ToString();
  9123. UUID mapID = UUID.Zero;
  9124. if (!string.IsNullOrEmpty(mapname))
  9125. {
  9126. mapID = ScriptUtils.GetAssetIdFromItemName(m_host, mapname, (int)AssetType.Texture);
  9127. if (mapID == UUID.Zero)
  9128. {
  9129. if (!UUID.TryParse(mapname, out mapID))
  9130. {
  9131. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be a UUID or a texture name on object inventory", rulesParsed, idx - idxStart - 1));
  9132. return new LSL_List();
  9133. }
  9134. }
  9135. }
  9136. LSL_Vector mnrepeat;
  9137. try
  9138. {
  9139. mnrepeat = rules.GetVector3Item(idx++);
  9140. }
  9141. catch(InvalidCastException)
  9142. {
  9143. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9144. return new LSL_List();
  9145. }
  9146. LSL_Vector mnoffset;
  9147. try
  9148. {
  9149. mnoffset = rules.GetVector3Item(idx++);
  9150. }
  9151. catch(InvalidCastException)
  9152. {
  9153. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9154. return new LSL_List();
  9155. }
  9156. LSL_Float mnrot;
  9157. try
  9158. {
  9159. mnrot = rules.GetLSLFloatItem(idx++);
  9160. }
  9161. catch(InvalidCastException)
  9162. {
  9163. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be float", rulesParsed, idx - idxStart - 1));
  9164. return new LSL_List();
  9165. }
  9166. float repeatX = (float)Util.Clamp(mnrepeat.x,-100.0, 100.0);
  9167. float repeatY = (float)Util.Clamp(mnrepeat.y,-100.0, 100.0);
  9168. float offsetX = (float)Util.Clamp(mnoffset.x, 0, 1.0);
  9169. float offsetY = (float)Util.Clamp(mnoffset.y, 0, 1.0);
  9170. materialChanged |= SetMaterialNormalMap(part, face, mapID, repeatX, repeatY, offsetX, offsetY, (float)mnrot);
  9171. break;
  9172. case ScriptBaseClass.PRIM_SPECULAR:
  9173. if (remain < 8)
  9174. return new LSL_List();
  9175. try
  9176. {
  9177. face = rules.GetLSLIntegerItem(idx++);
  9178. }
  9179. catch(InvalidCastException)
  9180. {
  9181. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9182. return new LSL_List();
  9183. }
  9184. string smapname = rules.Data[idx++].ToString();
  9185. UUID smapID = UUID.Zero;
  9186. if(!string.IsNullOrEmpty(smapname))
  9187. {
  9188. smapID = ScriptUtils.GetAssetIdFromItemName(m_host, smapname, (int)AssetType.Texture);
  9189. if (smapID == UUID.Zero)
  9190. {
  9191. if (!UUID.TryParse(smapname, out smapID))
  9192. {
  9193. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be a UUID or a texture name on object inventory", rulesParsed, idx - idxStart - 1));
  9194. return new LSL_List();
  9195. }
  9196. }
  9197. }
  9198. LSL_Vector msrepeat;
  9199. try
  9200. {
  9201. msrepeat = rules.GetVector3Item(idx++);
  9202. }
  9203. catch(InvalidCastException)
  9204. {
  9205. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9206. return new LSL_List();
  9207. }
  9208. LSL_Vector msoffset;
  9209. try
  9210. {
  9211. msoffset = rules.GetVector3Item(idx++);
  9212. }
  9213. catch(InvalidCastException)
  9214. {
  9215. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9216. return new LSL_List();
  9217. }
  9218. LSL_Float msrot;
  9219. try
  9220. {
  9221. msrot = rules.GetLSLFloatItem(idx++);
  9222. }
  9223. catch(InvalidCastException)
  9224. {
  9225. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be float", rulesParsed, idx - idxStart - 1));
  9226. return new LSL_List();
  9227. }
  9228. LSL_Vector mscolor;
  9229. try
  9230. {
  9231. mscolor = rules.GetVector3Item(idx++);
  9232. }
  9233. catch(InvalidCastException)
  9234. {
  9235. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9236. return new LSL_List();
  9237. }
  9238. LSL_Integer msgloss;
  9239. try
  9240. {
  9241. msgloss = rules.GetLSLIntegerItem(idx++);
  9242. }
  9243. catch(InvalidCastException)
  9244. {
  9245. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9246. return new LSL_List();
  9247. }
  9248. LSL_Integer msenv;
  9249. try
  9250. {
  9251. msenv = rules.GetLSLIntegerItem(idx++);
  9252. }
  9253. catch(InvalidCastException)
  9254. {
  9255. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9256. return new LSL_List();
  9257. }
  9258. float srepeatX = (float)Util.Clamp(msrepeat.x, -100.0, 100.0);
  9259. float srepeatY = (float)Util.Clamp(msrepeat.y, -100.0, 100.0);
  9260. float soffsetX = (float)Util.Clamp(msoffset.x, -1.0, 1.0);
  9261. float soffsetY = (float)Util.Clamp(msoffset.y, -1.0, 1.0);
  9262. byte colorR = (byte)(255.0 * Util.Clamp(mscolor.x, 0, 1.0) + 0.5);
  9263. byte colorG = (byte)(255.0 * Util.Clamp(mscolor.y, 0, 1.0) + 0.5);
  9264. byte colorB = (byte)(255.0 * Util.Clamp(mscolor.z, 0, 1.0) + 0.5);
  9265. byte gloss = (byte)Util.Clamp((int)msgloss, 0, 255);
  9266. byte env = (byte)Util.Clamp((int)msenv, 0, 255);
  9267. materialChanged |= SetMaterialSpecMap(part, face, smapID, srepeatX, srepeatY, soffsetX, soffsetY,
  9268. (float)msrot, colorR, colorG, colorB, gloss, env);
  9269. break;
  9270. case ScriptBaseClass.PRIM_LINK_TARGET:
  9271. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  9272. return new LSL_List();
  9273. return rules.GetSublist(idx, -1);
  9274. default:
  9275. Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - unsupported parameter", rulesParsed, idx - idxStart));
  9276. return new LSL_List();
  9277. }
  9278. }
  9279. }
  9280. catch (InvalidCastException e)
  9281. {
  9282. Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
  9283. }
  9284. finally
  9285. {
  9286. if (positionChanged)
  9287. {
  9288. if (part.ParentGroup.RootPart == part)
  9289. {
  9290. SceneObjectGroup parent = part.ParentGroup;
  9291. // Util.FireAndForget(delegate(object x) {
  9292. parent.UpdateGroupPosition(currentPosition);
  9293. // });
  9294. }
  9295. else
  9296. {
  9297. part.OffsetPosition = currentPosition;
  9298. // SceneObjectGroup parent = part.ParentGroup;
  9299. // parent.HasGroupChanged = true;
  9300. // parent.ScheduleGroupForTerseUpdate();
  9301. part.ScheduleTerseUpdate();
  9302. }
  9303. }
  9304. if(materialChanged)
  9305. {
  9306. if (part.ParentGroup != null && !part.ParentGroup.IsDeleted)
  9307. {
  9308. part.TriggerScriptChangedEvent(Changed.TEXTURE);
  9309. part.ScheduleFullUpdate();
  9310. part.ParentGroup.HasGroupChanged = true;
  9311. }
  9312. }
  9313. }
  9314. return new LSL_List();
  9315. }
  9316. protected bool SetMaterialAlphaMode(SceneObjectPart part, int face, int materialAlphaMode, int materialMaskCutoff)
  9317. {
  9318. if(m_materialsModule == null)
  9319. return false;
  9320. int nsides = part.GetNumberOfSides();
  9321. if(face == ScriptBaseClass.ALL_SIDES)
  9322. {
  9323. bool changed = false;
  9324. for(int i = 0; i < nsides; i++)
  9325. changed |= SetFaceMaterialAlphaMode(part, i, materialAlphaMode, materialMaskCutoff);
  9326. return changed;
  9327. }
  9328. if( face >= 0 && face < nsides)
  9329. return SetFaceMaterialAlphaMode(part, face, materialAlphaMode, materialMaskCutoff);
  9330. return false;
  9331. }
  9332. protected bool SetFaceMaterialAlphaMode(SceneObjectPart part, int face, int materialAlphaMode, int materialMaskCutoff)
  9333. {
  9334. Primitive.TextureEntry tex = part.Shape.Textures;
  9335. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  9336. if(texface == null)
  9337. return false;
  9338. FaceMaterial mat = null;
  9339. UUID oldid = texface.MaterialID;
  9340. if (oldid == UUID.Zero)
  9341. {
  9342. if (materialAlphaMode == 1)
  9343. return false;
  9344. }
  9345. else
  9346. mat = m_materialsModule.GetMaterialCopy(oldid);
  9347. if(mat == null)
  9348. mat = new FaceMaterial();
  9349. mat.DiffuseAlphaMode = (byte)materialAlphaMode;
  9350. mat.AlphaMaskCutoff = (byte)materialMaskCutoff;
  9351. UUID id = m_materialsModule.AddNewMaterial(mat); // id is a hash of entire material hash, so this means no change
  9352. if(oldid == id)
  9353. return false;
  9354. texface.MaterialID = id;
  9355. part.Shape.TextureEntry = tex.GetBytes(9);
  9356. m_materialsModule.RemoveMaterial(oldid);
  9357. return true;
  9358. }
  9359. protected bool SetMaterialNormalMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9360. float offsetX, float offsetY, float rot)
  9361. {
  9362. if(m_materialsModule == null)
  9363. return false;
  9364. int nsides = part.GetNumberOfSides();
  9365. if(face == ScriptBaseClass.ALL_SIDES)
  9366. {
  9367. bool changed = false;
  9368. for(int i = 0; i < nsides; i++)
  9369. changed |= SetFaceMaterialNormalMap(part, i, mapID, repeatX, repeatY, offsetX, offsetY, rot);
  9370. return changed;
  9371. }
  9372. if( face >= 0 && face < nsides)
  9373. return SetFaceMaterialNormalMap(part, face, mapID, repeatX, repeatY, offsetX, offsetY, rot);
  9374. return false;
  9375. }
  9376. protected bool SetFaceMaterialNormalMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9377. float offsetX, float offsetY, float rot)
  9378. {
  9379. Primitive.TextureEntry tex = part.Shape.Textures;
  9380. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  9381. if(texface == null)
  9382. return false;
  9383. FaceMaterial mat = null;
  9384. UUID oldid = texface.MaterialID;
  9385. if (oldid == UUID.Zero)
  9386. {
  9387. if (mapID == UUID.Zero)
  9388. return false;
  9389. }
  9390. else
  9391. mat = m_materialsModule.GetMaterialCopy(oldid);
  9392. if(mat == null)
  9393. mat = new FaceMaterial();
  9394. mat.NormalMapID = mapID;
  9395. mat.NormalOffsetX = offsetX;
  9396. mat.NormalOffsetY = offsetY;
  9397. mat.NormalRepeatX = repeatX;
  9398. mat.NormalRepeatY = repeatY;
  9399. mat.NormalRotation = rot;
  9400. mapID = m_materialsModule.AddNewMaterial(mat);
  9401. if(oldid == mapID)
  9402. return false;
  9403. texface.MaterialID = mapID;
  9404. part.Shape.TextureEntry = tex.GetBytes(9);
  9405. m_materialsModule.RemoveMaterial(oldid);
  9406. return true;
  9407. }
  9408. protected bool SetMaterialSpecMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9409. float offsetX, float offsetY, float rot,
  9410. byte colorR, byte colorG, byte colorB,
  9411. byte gloss, byte env)
  9412. {
  9413. if(m_materialsModule == null)
  9414. return false;
  9415. int nsides = part.GetNumberOfSides();
  9416. if(face == ScriptBaseClass.ALL_SIDES)
  9417. {
  9418. bool changed = false;
  9419. for(int i = 0; i < nsides; i++)
  9420. changed |= SetFaceMaterialSpecMap(part, i, mapID, repeatX, repeatY, offsetX, offsetY, rot,
  9421. colorR, colorG, colorB, gloss, env);
  9422. return changed;
  9423. }
  9424. if( face >= 0 && face < nsides)
  9425. return SetFaceMaterialSpecMap(part, face, mapID, repeatX, repeatY, offsetX, offsetY, rot,
  9426. colorR, colorG, colorB, gloss, env);
  9427. return false;
  9428. }
  9429. protected bool SetFaceMaterialSpecMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9430. float offsetX, float offsetY, float rot,
  9431. byte colorR, byte colorG, byte colorB,
  9432. byte gloss, byte env)
  9433. {
  9434. Primitive.TextureEntry tex = part.Shape.Textures;
  9435. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  9436. if(texface == null)
  9437. return false;
  9438. FaceMaterial mat = null;
  9439. UUID oldid = texface.MaterialID;
  9440. if(oldid == UUID.Zero)
  9441. {
  9442. if(mapID == UUID.Zero)
  9443. return false;
  9444. }
  9445. else
  9446. mat = m_materialsModule.GetMaterialCopy(oldid);
  9447. if (mat == null)
  9448. mat = new FaceMaterial();
  9449. mat.SpecularMapID = mapID;
  9450. mat.SpecularOffsetX = offsetX;
  9451. mat.SpecularOffsetY = offsetY;
  9452. mat.SpecularRepeatX = repeatX;
  9453. mat.SpecularRepeatY = repeatY;
  9454. mat.SpecularRotation = rot;
  9455. mat.SpecularLightColorR = colorR;
  9456. mat.SpecularLightColorG = colorG;
  9457. mat.SpecularLightColorB = colorB;
  9458. mat.SpecularLightExponent = gloss;
  9459. mat.EnvironmentIntensity = env;
  9460. mapID = m_materialsModule.AddNewMaterial(mat);
  9461. if(oldid == mapID)
  9462. return false;
  9463. texface.MaterialID = mapID;
  9464. part.Shape.TextureEntry = tex.GetBytes(9);
  9465. m_materialsModule.RemoveMaterial(oldid);
  9466. return true;
  9467. }
  9468. protected LSL_List SetAgentParams(ScenePresence sp, LSL_List rules, string originFunc, ref uint rulesParsed)
  9469. {
  9470. int idx = 0;
  9471. int idxStart = 0;
  9472. try
  9473. {
  9474. while (idx < rules.Length)
  9475. {
  9476. ++rulesParsed;
  9477. int code = rules.GetLSLIntegerItem(idx++);
  9478. int remain = rules.Length - idx;
  9479. idxStart = idx;
  9480. switch (code)
  9481. {
  9482. case ScriptBaseClass.PRIM_POSITION:
  9483. case ScriptBaseClass.PRIM_POS_LOCAL:
  9484. if (remain < 1)
  9485. return new LSL_List();
  9486. try
  9487. {
  9488. sp.OffsetPosition = rules.GetVector3Item(idx++);
  9489. }
  9490. catch(InvalidCastException)
  9491. {
  9492. if (code == ScriptBaseClass.PRIM_POSITION)
  9493. {
  9494. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  9495. }
  9496. else
  9497. {
  9498. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  9499. }
  9500. return new LSL_List();
  9501. }
  9502. break;
  9503. case ScriptBaseClass.PRIM_ROTATION:
  9504. if (remain < 1)
  9505. return new LSL_List();
  9506. Quaternion inRot;
  9507. try
  9508. {
  9509. inRot = rules.GetQuaternionItem(idx++);
  9510. }
  9511. catch(InvalidCastException)
  9512. {
  9513. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  9514. return new LSL_List();
  9515. }
  9516. SceneObjectPart parentPart = sp.ParentPart;
  9517. if (parentPart != null)
  9518. sp.Rotation = m_host.GetWorldRotation() * inRot;
  9519. break;
  9520. case ScriptBaseClass.PRIM_ROT_LOCAL:
  9521. if (remain < 1)
  9522. return new LSL_List();
  9523. try
  9524. {
  9525. sp.Rotation = rules.GetQuaternionItem(idx++);
  9526. }
  9527. catch(InvalidCastException)
  9528. {
  9529. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  9530. return new LSL_List();
  9531. }
  9532. break;
  9533. case ScriptBaseClass.PRIM_TYPE:
  9534. Error(originFunc, "PRIM_TYPE disallowed on agent");
  9535. return new LSL_List();
  9536. case ScriptBaseClass.PRIM_OMEGA:
  9537. Error(originFunc, "PRIM_OMEGA disallowed on agent");
  9538. return new LSL_List();
  9539. case ScriptBaseClass.PRIM_LINK_TARGET:
  9540. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  9541. return new LSL_List();
  9542. return rules.GetSublist(idx, -1);
  9543. default:
  9544. Error(originFunc,
  9545. string.Format("Error running rule #{0} on agent: arg #{1} - disallowed on agent", rulesParsed, idx - idxStart));
  9546. return new LSL_List();
  9547. }
  9548. }
  9549. }
  9550. catch (InvalidCastException e)
  9551. {
  9552. Error(
  9553. originFunc,
  9554. string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
  9555. }
  9556. return new LSL_List();
  9557. }
  9558. public LSL_String llStringToBase64(string str)
  9559. {
  9560. m_host.AddScriptLPS(1);
  9561. try
  9562. {
  9563. byte[] encData_byte;
  9564. encData_byte = Util.UTF8.GetBytes(str);
  9565. string encodedData = Convert.ToBase64String(encData_byte);
  9566. return encodedData;
  9567. }
  9568. catch
  9569. {
  9570. Error("llBase64ToString", "Error encoding string");
  9571. return string.Empty;
  9572. }
  9573. }
  9574. public LSL_String llBase64ToString(string str)
  9575. {
  9576. m_host.AddScriptLPS(1);
  9577. try
  9578. {
  9579. byte[] b = Convert.FromBase64String(str);
  9580. return Encoding.UTF8.GetString(b);
  9581. }
  9582. catch
  9583. {
  9584. Error("llBase64ToString", "Error decoding string");
  9585. return string.Empty;
  9586. }
  9587. }
  9588. public void llRemoteDataSetRegion()
  9589. {
  9590. m_host.AddScriptLPS(1);
  9591. Deprecated("llRemoteDataSetRegion", "Use llOpenRemoteDataChannel instead");
  9592. }
  9593. public LSL_Float llLog10(double val)
  9594. {
  9595. m_host.AddScriptLPS(1);
  9596. return (double)Math.Log10(val);
  9597. }
  9598. public LSL_Float llLog(double val)
  9599. {
  9600. m_host.AddScriptLPS(1);
  9601. return (double)Math.Log(val);
  9602. }
  9603. public LSL_List llGetAnimationList(LSL_Key id)
  9604. {
  9605. m_host.AddScriptLPS(1);
  9606. if(!UUID.TryParse(id, out UUID avID))
  9607. return new LSL_List();
  9608. ScenePresence av = World.GetScenePresence(avID);
  9609. if (av == null || av.IsChildAgent) // only if in the region
  9610. return new LSL_List();
  9611. UUID[] anims;
  9612. anims = av.Animator.GetAnimationArray();
  9613. LSL_List l = new LSL_List();
  9614. foreach (UUID foo in anims)
  9615. l.Add(new LSL_Key(foo.ToString()));
  9616. return l;
  9617. }
  9618. public void llSetParcelMusicURL(string url)
  9619. {
  9620. m_host.AddScriptLPS(1);
  9621. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  9622. if (land.LandData.OwnerID != m_host.OwnerID)
  9623. return;
  9624. land.SetMusicUrl(url);
  9625. ScriptSleep(m_sleepMsOnSetParcelMusicURL);
  9626. }
  9627. public LSL_String llGetParcelMusicURL()
  9628. {
  9629. m_host.AddScriptLPS(1);
  9630. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  9631. if (land.LandData.OwnerID != m_host.OwnerID)
  9632. return String.Empty;
  9633. return land.GetMusicUrl();
  9634. }
  9635. public LSL_Vector llGetRootPosition()
  9636. {
  9637. m_host.AddScriptLPS(1);
  9638. return new LSL_Vector(m_host.ParentGroup.AbsolutePosition);
  9639. }
  9640. /// <summary>
  9641. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetRot
  9642. /// http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  9643. /// Also tested in sl in regards to the behaviour in attachments/mouselook
  9644. /// In the root prim:-
  9645. /// Returns the object rotation if not attached
  9646. /// Returns the avatars rotation if attached
  9647. /// Returns the camera rotation if attached and the avatar is in mouselook
  9648. /// </summary>
  9649. public LSL_Rotation llGetRootRotation()
  9650. {
  9651. m_host.AddScriptLPS(1);
  9652. Quaternion q;
  9653. if (m_host.ParentGroup.AttachmentPoint != 0)
  9654. {
  9655. ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  9656. if (avatar != null)
  9657. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  9658. q = avatar.CameraRotation; // Mouselook
  9659. else
  9660. q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate
  9661. else
  9662. q = m_host.ParentGroup.GroupRotation; // Likely never get here but just in case
  9663. }
  9664. else
  9665. q = m_host.ParentGroup.GroupRotation; // just the group rotation
  9666. return new LSL_Rotation(q);
  9667. }
  9668. public LSL_String llGetObjectDesc()
  9669. {
  9670. return m_host.Description ?? String.Empty;
  9671. }
  9672. public void llSetObjectDesc(string desc)
  9673. {
  9674. m_host.AddScriptLPS(1);
  9675. m_host.Description = desc ?? String.Empty;
  9676. }
  9677. public LSL_Key llGetCreator()
  9678. {
  9679. m_host.AddScriptLPS(1);
  9680. return m_host.CreatorID.ToString();
  9681. }
  9682. public LSL_String llGetTimestamp()
  9683. {
  9684. m_host.AddScriptLPS(1);
  9685. return DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
  9686. }
  9687. public LSL_Integer llGetNumberOfPrims()
  9688. {
  9689. m_host.AddScriptLPS(1);
  9690. return m_host.ParentGroup.PrimCount + m_host.ParentGroup.GetSittingAvatarsCount();
  9691. }
  9692. /// <summary>
  9693. /// Full implementation of llGetBoundingBox according to SL 2015-04-15.
  9694. /// http://wiki.secondlife.com/wiki/LlGetBoundingBox
  9695. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetBoundingBox
  9696. /// Returns local bounding box of avatar without attachments
  9697. /// if target is non-seated avatar or prim/mesh in avatar attachment.
  9698. /// Returns local bounding box of object
  9699. /// if target is seated avatar or prim/mesh in object.
  9700. /// Uses less accurate box models for speed.
  9701. /// </summary>
  9702. public LSL_List llGetBoundingBox(string obj)
  9703. {
  9704. m_host.AddScriptLPS(1);
  9705. UUID objID = UUID.Zero;
  9706. LSL_List result = new LSL_List();
  9707. // If the ID is not valid, return null result
  9708. if (!UUID.TryParse(obj, out objID))
  9709. {
  9710. result.Add(new LSL_Vector());
  9711. result.Add(new LSL_Vector());
  9712. return result;
  9713. }
  9714. // Check if this is an attached prim. If so, replace
  9715. // the UUID with the avatar UUID and report it's bounding box
  9716. SceneObjectPart part = World.GetSceneObjectPart(objID);
  9717. if (part != null && part.ParentGroup.IsAttachment)
  9718. objID = part.ParentGroup.AttachedAvatar;
  9719. // Find out if this is an avatar ID. If so, return it's box
  9720. ScenePresence presence = World.GetScenePresence(objID);
  9721. if (presence != null)
  9722. {
  9723. LSL_Vector lower;
  9724. LSL_Vector upper;
  9725. Vector3 box = presence.Appearance.AvatarBoxSize * 0.5f;
  9726. if (presence.Animator.Animations.ImplicitDefaultAnimation.AnimID
  9727. == DefaultAvatarAnimations.AnimsUUIDbyName["SIT_GROUND_CONSTRAINED"])
  9728. {
  9729. // This is for ground sitting avatars TODO!
  9730. lower = new LSL_Vector(-box.X - 0.1125, -box.Y, box.Z * -1.0f);
  9731. upper = new LSL_Vector(box.X + 0.1125, box.Y, box.Z * -1.0f);
  9732. }
  9733. else
  9734. {
  9735. // This is for standing/flying avatars
  9736. lower = new LSL_Vector(-box.X, -box.Y, -box.Z);
  9737. upper = new LSL_Vector(box.X, box.Y, box.Z);
  9738. }
  9739. if (lower.x > upper.x)
  9740. lower.x = upper.x;
  9741. if (lower.y > upper.y)
  9742. lower.y = upper.y;
  9743. if (lower.z > upper.z)
  9744. lower.z = upper.z;
  9745. result.Add(lower);
  9746. result.Add(upper);
  9747. return result;
  9748. }
  9749. part = World.GetSceneObjectPart(objID);
  9750. // Currently only works for single prims without a sitting avatar
  9751. if (part == null)
  9752. {
  9753. result.Add(new LSL_Vector());
  9754. result.Add(new LSL_Vector());
  9755. return result;
  9756. }
  9757. SceneObjectGroup sog = part.ParentGroup;
  9758. if(sog.IsDeleted)
  9759. {
  9760. result.Add(new LSL_Vector());
  9761. result.Add(new LSL_Vector());
  9762. return result;
  9763. }
  9764. sog.GetBoundingBox(out float minX, out float maxX, out float minY, out float maxY, out float minZ, out float maxZ);
  9765. result.Add(new LSL_Vector(minX, minY, minZ));
  9766. result.Add(new LSL_Vector(maxX, maxY, maxZ));
  9767. return result;
  9768. }
  9769. /// <summary>
  9770. /// Helper to calculate bounding box of an avatar.
  9771. /// </summary>
  9772. private void BoundingBoxOfScenePresence(ScenePresence sp, out Vector3 lower, out Vector3 upper)
  9773. {
  9774. // Adjust from OS model
  9775. // avatar height = visual height - 0.2, bounding box height = visual height
  9776. // to SL model
  9777. // avatar height = visual height, bounding box height = visual height + 0.2
  9778. float height = sp.Appearance.AvatarHeight + m_avatarHeightCorrection;
  9779. // According to avatar bounding box in SL 2015-04-18:
  9780. // standing = <-0.275,-0.35,-0.1-0.5*h> : <0.275,0.35,0.1+0.5*h>
  9781. // groundsitting = <-0.3875,-0.5,-0.05-0.375*h> : <0.3875,0.5,0.5>
  9782. // sitting = <-0.5875,-0.35,-0.35-0.375*h> : <0.1875,0.35,-0.25+0.25*h>
  9783. // When avatar is sitting
  9784. if (sp.ParentPart != null)
  9785. {
  9786. lower = new Vector3(m_lABB1SitX0, m_lABB1SitY0, m_lABB1SitZ0 + m_lABB1SitZ1 * height);
  9787. upper = new Vector3(m_lABB2SitX0, m_lABB2SitY0, m_lABB2SitZ0 + m_lABB2SitZ1 * height);
  9788. }
  9789. // When avatar is groundsitting
  9790. else if (sp.Animator.Animations.ImplicitDefaultAnimation.AnimID == DefaultAvatarAnimations.AnimsUUIDbyName["SIT_GROUND_CONSTRAINED"])
  9791. {
  9792. lower = new Vector3(m_lABB1GrsX0, m_lABB1GrsY0, m_lABB1GrsZ0 + m_lABB1GrsZ1 * height);
  9793. upper = new Vector3(m_lABB2GrsX0, m_lABB2GrsY0, m_lABB2GrsZ0 + m_lABB2GrsZ1 * height);
  9794. }
  9795. // When avatar is standing or flying
  9796. else
  9797. {
  9798. lower = new Vector3(m_lABB1StdX0, m_lABB1StdY0, m_lABB1StdZ0 + m_lABB1StdZ1 * height);
  9799. upper = new Vector3(m_lABB2StdX0, m_lABB2StdY0, m_lABB2StdZ0 + m_lABB2StdZ1 * height);
  9800. }
  9801. }
  9802. public LSL_Vector llGetGeometricCenter()
  9803. {
  9804. return new LSL_Vector(m_host.GetGeometricCenter());
  9805. }
  9806. public LSL_List llGetPrimitiveParams(LSL_List rules)
  9807. {
  9808. m_host.AddScriptLPS(1);
  9809. LSL_List result = new LSL_List();
  9810. LSL_List remaining = GetPrimParams(m_host, rules, ref result);
  9811. while (!(remaining is null) && remaining.Length > 1)
  9812. {
  9813. int linknumber = remaining.GetLSLIntegerItem(0);
  9814. rules = remaining.GetSublist(1, -1);
  9815. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  9816. if(parts.Count == 0)
  9817. break;
  9818. foreach (SceneObjectPart part in parts)
  9819. remaining = GetPrimParams(part, rules, ref result);
  9820. }
  9821. return result;
  9822. }
  9823. public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules)
  9824. {
  9825. m_host.AddScriptLPS(1);
  9826. // acording to SL wiki this must indicate a single link number or link_root or link_this.
  9827. // keep other options as before
  9828. List<SceneObjectPart> parts;
  9829. List<ScenePresence> avatars;
  9830. LSL_List res = new LSL_List();
  9831. LSL_List remaining = new LSL_List();
  9832. while (rules.Length > 0)
  9833. {
  9834. parts = GetLinkParts(linknumber);
  9835. avatars = GetLinkAvatars(linknumber);
  9836. remaining = new LSL_List();
  9837. foreach (SceneObjectPart part in parts)
  9838. {
  9839. remaining = GetPrimParams(part, rules, ref res);
  9840. }
  9841. foreach (ScenePresence avatar in avatars)
  9842. {
  9843. remaining = GetPrimParams(avatar, rules, ref res);
  9844. }
  9845. if (remaining.Length > 0)
  9846. {
  9847. linknumber = remaining.GetLSLIntegerItem(0);
  9848. rules = remaining.GetSublist(1, -1);
  9849. }
  9850. else
  9851. break;
  9852. }
  9853. return res;
  9854. }
  9855. public LSL_List GetPrimParams(SceneObjectPart part, LSL_List rules, ref LSL_List res)
  9856. {
  9857. int idx = 0;
  9858. int face;
  9859. Primitive.TextureEntry tex;
  9860. int nsides = GetNumberOfSides(part);
  9861. while (idx < rules.Length)
  9862. {
  9863. int code = (int)rules.GetLSLIntegerItem(idx++);
  9864. int remain = rules.Length - idx;
  9865. switch (code)
  9866. {
  9867. case (int)ScriptBaseClass.PRIM_MATERIAL:
  9868. res.Add(new LSL_Integer(part.Material));
  9869. break;
  9870. case (int)ScriptBaseClass.PRIM_PHYSICS:
  9871. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) != 0)
  9872. res.Add(new LSL_Integer(1));
  9873. else
  9874. res.Add(new LSL_Integer(0));
  9875. break;
  9876. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  9877. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.TemporaryOnRez) != 0)
  9878. res.Add(new LSL_Integer(1));
  9879. else
  9880. res.Add(new LSL_Integer(0));
  9881. break;
  9882. case (int)ScriptBaseClass.PRIM_PHANTOM:
  9883. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) != 0)
  9884. res.Add(new LSL_Integer(1));
  9885. else
  9886. res.Add(new LSL_Integer(0));
  9887. break;
  9888. case (int)ScriptBaseClass.PRIM_POSITION:
  9889. LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X,
  9890. part.AbsolutePosition.Y,
  9891. part.AbsolutePosition.Z);
  9892. res.Add(v);
  9893. break;
  9894. case (int)ScriptBaseClass.PRIM_SIZE:
  9895. res.Add(new LSL_Vector(part.Scale));
  9896. break;
  9897. case (int)ScriptBaseClass.PRIM_ROTATION:
  9898. res.Add(GetPartRot(part));
  9899. break;
  9900. case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  9901. res.Add(new LSL_Integer((int)part.PhysicsShapeType));
  9902. break;
  9903. case (int)ScriptBaseClass.PRIM_TYPE:
  9904. // implementing box
  9905. PrimitiveBaseShape Shape = part.Shape;
  9906. int primType = (int)part.GetPrimType();
  9907. res.Add(new LSL_Integer(primType));
  9908. double topshearx = (double)(sbyte)Shape.PathShearX / 100.0; // Fix negative values for PathShearX
  9909. double topsheary = (double)(sbyte)Shape.PathShearY / 100.0; // and PathShearY.
  9910. switch (primType)
  9911. {
  9912. case ScriptBaseClass.PRIM_TYPE_BOX:
  9913. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  9914. case ScriptBaseClass.PRIM_TYPE_PRISM:
  9915. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9916. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9917. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9918. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9919. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  9920. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  9921. break;
  9922. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  9923. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9924. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  9925. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9926. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9927. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9928. break;
  9929. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  9930. res.Add(new LSL_String(Shape.SculptTexture.ToString()));
  9931. res.Add(new LSL_Integer(Shape.SculptType));
  9932. break;
  9933. case ScriptBaseClass.PRIM_TYPE_RING:
  9934. case ScriptBaseClass.PRIM_TYPE_TUBE:
  9935. case ScriptBaseClass.PRIM_TYPE_TORUS:
  9936. // holeshape
  9937. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9938. // cut
  9939. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  9940. // hollow
  9941. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9942. // twist
  9943. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9944. // vector holesize
  9945. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  9946. // vector topshear
  9947. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  9948. // vector profilecut
  9949. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9950. // vector tapera
  9951. res.Add(new LSL_Vector(Shape.PathTaperX / 100.0, Shape.PathTaperY / 100.0, 0));
  9952. // float revolutions
  9953. res.Add(new LSL_Float(Math.Round(Shape.PathRevolutions * 0.015d, 2, MidpointRounding.AwayFromZero)) + 1.0d);
  9954. // Slightly inaccurate, because an unsigned byte is being used to represent
  9955. // the entire range of floating-point values from 1.0 through 4.0 (which is how
  9956. // SL does it).
  9957. //
  9958. // Using these formulas to store and retrieve PathRevolutions, it is not
  9959. // possible to use all values between 1.00 and 4.00. For instance, you can't
  9960. // represent 1.10. You can represent 1.09 and 1.11, but not 1.10. So, if you
  9961. // use llSetPrimitiveParams to set revolutions to 1.10 and then retreive them
  9962. // with llGetPrimitiveParams, you'll retrieve 1.09. You can also see a similar
  9963. // behavior in the viewer as you cannot set 1.10. The viewer jumps to 1.11.
  9964. // In SL, llSetPrimitveParams and llGetPrimitiveParams can set and get a value
  9965. // such as 1.10. So, SL must store and retreive the actual user input rather
  9966. // than only storing the encoded value.
  9967. // float radiusoffset
  9968. res.Add(new LSL_Float(Shape.PathRadiusOffset / 100.0));
  9969. // float skew
  9970. res.Add(new LSL_Float(Shape.PathSkew / 100.0));
  9971. break;
  9972. }
  9973. break;
  9974. case (int)ScriptBaseClass.PRIM_TEXTURE:
  9975. if (remain < 1)
  9976. return new LSL_List();
  9977. face = (int)rules.GetLSLIntegerItem(idx++);
  9978. tex = part.Shape.Textures;
  9979. if (face == ScriptBaseClass.ALL_SIDES)
  9980. {
  9981. for (face = 0; face < nsides; face++)
  9982. {
  9983. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  9984. res.Add(new LSL_String(texface.TextureID.ToString()));
  9985. res.Add(new LSL_Vector(texface.RepeatU,
  9986. texface.RepeatV,
  9987. 0));
  9988. res.Add(new LSL_Vector(texface.OffsetU,
  9989. texface.OffsetV,
  9990. 0));
  9991. res.Add(new LSL_Float(texface.Rotation));
  9992. }
  9993. }
  9994. else
  9995. {
  9996. if (face >= 0 && face < nsides)
  9997. {
  9998. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  9999. res.Add(new LSL_String(texface.TextureID.ToString()));
  10000. res.Add(new LSL_Vector(texface.RepeatU,
  10001. texface.RepeatV,
  10002. 0));
  10003. res.Add(new LSL_Vector(texface.OffsetU,
  10004. texface.OffsetV,
  10005. 0));
  10006. res.Add(new LSL_Float(texface.Rotation));
  10007. }
  10008. }
  10009. break;
  10010. case (int)ScriptBaseClass.PRIM_COLOR:
  10011. if (remain < 1)
  10012. return new LSL_List();
  10013. face = (int)rules.GetLSLIntegerItem(idx++);
  10014. tex = part.Shape.Textures;
  10015. Color4 texcolor;
  10016. if (face == ScriptBaseClass.ALL_SIDES)
  10017. {
  10018. for (face = 0; face < nsides; face++)
  10019. {
  10020. texcolor = tex.GetFace((uint)face).RGBA;
  10021. res.Add(new LSL_Vector(texcolor.R,
  10022. texcolor.G,
  10023. texcolor.B));
  10024. res.Add(new LSL_Float(texcolor.A));
  10025. }
  10026. }
  10027. else
  10028. {
  10029. texcolor = tex.GetFace((uint)face).RGBA;
  10030. res.Add(new LSL_Vector(texcolor.R,
  10031. texcolor.G,
  10032. texcolor.B));
  10033. res.Add(new LSL_Float(texcolor.A));
  10034. }
  10035. break;
  10036. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  10037. {
  10038. if (remain < 1)
  10039. return new LSL_List();
  10040. face = (int)rules.GetLSLIntegerItem(idx++);
  10041. tex = part.Shape.Textures;
  10042. int shiny;
  10043. if (face == ScriptBaseClass.ALL_SIDES)
  10044. {
  10045. for (face = 0; face < nsides; face++)
  10046. {
  10047. Shininess shinyness = tex.GetFace((uint)face).Shiny;
  10048. if (shinyness == Shininess.High)
  10049. {
  10050. shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
  10051. }
  10052. else if (shinyness == Shininess.Medium)
  10053. {
  10054. shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
  10055. }
  10056. else if (shinyness == Shininess.Low)
  10057. {
  10058. shiny = ScriptBaseClass.PRIM_SHINY_LOW;
  10059. }
  10060. else
  10061. {
  10062. shiny = ScriptBaseClass.PRIM_SHINY_NONE;
  10063. }
  10064. res.Add(new LSL_Integer(shiny));
  10065. res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
  10066. }
  10067. }
  10068. else
  10069. {
  10070. Shininess shinyness = tex.GetFace((uint)face).Shiny;
  10071. if (shinyness == Shininess.High)
  10072. {
  10073. shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
  10074. }
  10075. else if (shinyness == Shininess.Medium)
  10076. {
  10077. shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
  10078. }
  10079. else if (shinyness == Shininess.Low)
  10080. {
  10081. shiny = ScriptBaseClass.PRIM_SHINY_LOW;
  10082. }
  10083. else
  10084. {
  10085. shiny = ScriptBaseClass.PRIM_SHINY_NONE;
  10086. }
  10087. res.Add(new LSL_Integer(shiny));
  10088. res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
  10089. }
  10090. break;
  10091. }
  10092. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  10093. {
  10094. if (remain < 1)
  10095. return new LSL_List();
  10096. face = (int)rules.GetLSLIntegerItem(idx++);
  10097. tex = part.Shape.Textures;
  10098. int fullbright;
  10099. if (face == ScriptBaseClass.ALL_SIDES)
  10100. {
  10101. for (face = 0; face < nsides; face++)
  10102. {
  10103. if (tex.GetFace((uint)face).Fullbright == true)
  10104. {
  10105. fullbright = ScriptBaseClass.TRUE;
  10106. }
  10107. else
  10108. {
  10109. fullbright = ScriptBaseClass.FALSE;
  10110. }
  10111. res.Add(new LSL_Integer(fullbright));
  10112. }
  10113. }
  10114. else
  10115. {
  10116. if (tex.GetFace((uint)face).Fullbright == true)
  10117. {
  10118. fullbright = ScriptBaseClass.TRUE;
  10119. }
  10120. else
  10121. {
  10122. fullbright = ScriptBaseClass.FALSE;
  10123. }
  10124. res.Add(new LSL_Integer(fullbright));
  10125. }
  10126. break;
  10127. }
  10128. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  10129. PrimitiveBaseShape shape = part.Shape;
  10130. if (shape.FlexiEntry)
  10131. res.Add(new LSL_Integer(1)); // active
  10132. else
  10133. res.Add(new LSL_Integer(0));
  10134. res.Add(new LSL_Integer(shape.FlexiSoftness));// softness
  10135. res.Add(new LSL_Float(shape.FlexiGravity)); // gravity
  10136. res.Add(new LSL_Float(shape.FlexiDrag)); // friction
  10137. res.Add(new LSL_Float(shape.FlexiWind)); // wind
  10138. res.Add(new LSL_Float(shape.FlexiTension)); // tension
  10139. res.Add(new LSL_Vector(shape.FlexiForceX, // force
  10140. shape.FlexiForceY,
  10141. shape.FlexiForceZ));
  10142. break;
  10143. case (int)ScriptBaseClass.PRIM_TEXGEN:
  10144. // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
  10145. if (remain < 1)
  10146. return new LSL_List();
  10147. face = (int)rules.GetLSLIntegerItem(idx++);
  10148. tex = part.Shape.Textures;
  10149. if (face == ScriptBaseClass.ALL_SIDES)
  10150. {
  10151. for (face = 0; face < nsides; face++)
  10152. {
  10153. if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
  10154. {
  10155. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
  10156. }
  10157. else
  10158. {
  10159. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  10160. }
  10161. }
  10162. }
  10163. else
  10164. {
  10165. if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
  10166. {
  10167. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
  10168. }
  10169. else
  10170. {
  10171. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  10172. }
  10173. }
  10174. break;
  10175. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  10176. shape = part.Shape;
  10177. if (shape.LightEntry)
  10178. res.Add(new LSL_Integer(1)); // active
  10179. else
  10180. res.Add(new LSL_Integer(0));
  10181. res.Add(new LSL_Vector(shape.LightColorR, // color
  10182. shape.LightColorG,
  10183. shape.LightColorB));
  10184. res.Add(new LSL_Float(shape.LightIntensity)); // intensity
  10185. res.Add(new LSL_Float(shape.LightRadius)); // radius
  10186. res.Add(new LSL_Float(shape.LightFalloff)); // falloff
  10187. break;
  10188. case (int)ScriptBaseClass.PRIM_GLOW:
  10189. if (remain < 1)
  10190. return new LSL_List();
  10191. face = (int)rules.GetLSLIntegerItem(idx++);
  10192. tex = part.Shape.Textures;
  10193. float primglow;
  10194. if (face == ScriptBaseClass.ALL_SIDES)
  10195. {
  10196. for (face = 0; face < nsides; face++)
  10197. {
  10198. primglow = tex.GetFace((uint)face).Glow;
  10199. res.Add(new LSL_Float(primglow));
  10200. }
  10201. }
  10202. else
  10203. {
  10204. primglow = tex.GetFace((uint)face).Glow;
  10205. res.Add(new LSL_Float(primglow));
  10206. }
  10207. break;
  10208. case (int)ScriptBaseClass.PRIM_TEXT:
  10209. Color4 textColor = part.GetTextColor();
  10210. res.Add(new LSL_String(part.Text));
  10211. res.Add(new LSL_Vector(textColor.R,
  10212. textColor.G,
  10213. textColor.B));
  10214. res.Add(new LSL_Float(textColor.A));
  10215. break;
  10216. case (int)ScriptBaseClass.PRIM_NAME:
  10217. res.Add(new LSL_String(part.Name));
  10218. break;
  10219. case (int)ScriptBaseClass.PRIM_DESC:
  10220. res.Add(new LSL_String(part.Description));
  10221. break;
  10222. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  10223. res.Add(new LSL_Rotation(part.RotationOffset));
  10224. break;
  10225. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  10226. res.Add(new LSL_Vector(GetPartLocalPos(part)));
  10227. break;
  10228. case (int)ScriptBaseClass.PRIM_SLICE:
  10229. PrimType prim_type = part.GetPrimType();
  10230. bool useProfileBeginEnd = (prim_type == PrimType.SPHERE || prim_type == PrimType.TORUS || prim_type == PrimType.TUBE || prim_type == PrimType.RING);
  10231. res.Add(new LSL_Vector(
  10232. (useProfileBeginEnd ? part.Shape.ProfileBegin : part.Shape.PathBegin) / 50000.0,
  10233. 1 - (useProfileBeginEnd ? part.Shape.ProfileEnd : part.Shape.PathEnd) / 50000.0,
  10234. 0
  10235. ));
  10236. break;
  10237. case (int)ScriptBaseClass.PRIM_OMEGA:
  10238. // this may return values diferent from SL since we don't handle set the same way
  10239. float gain = 1.0f; // we don't use gain and don't store it
  10240. Vector3 axis = part.AngularVelocity;
  10241. float spin = axis.Length();
  10242. if(spin < 1.0e-6)
  10243. {
  10244. axis = Vector3.Zero;
  10245. gain = 0.0f;
  10246. spin = 0.0f;
  10247. }
  10248. else
  10249. {
  10250. axis = axis * (1.0f/spin);
  10251. }
  10252. res.Add(new LSL_Vector(axis.X,
  10253. axis.Y,
  10254. axis.Z));
  10255. res.Add(new LSL_Float(spin));
  10256. res.Add(new LSL_Float(gain));
  10257. break;
  10258. case (int)ScriptBaseClass.PRIM_SIT_TARGET:
  10259. if(part.IsSitTargetSet)
  10260. {
  10261. res.Add(new LSL_Integer(1));
  10262. res.Add(new LSL_Vector(part.SitTargetPosition));
  10263. res.Add(new LSL_Rotation(part.SitTargetOrientation));
  10264. }
  10265. else
  10266. {
  10267. res.Add(new LSL_Integer(0));
  10268. res.Add(new LSL_Vector(Vector3.Zero));
  10269. res.Add(new LSL_Rotation(Quaternion.Identity));
  10270. }
  10271. break;
  10272. case (int)ScriptBaseClass.PRIM_NORMAL:
  10273. case (int)ScriptBaseClass.PRIM_SPECULAR:
  10274. case (int)ScriptBaseClass.PRIM_ALPHA_MODE:
  10275. if (remain < 1)
  10276. return new LSL_List();
  10277. face = (int)rules.GetLSLIntegerItem(idx++);
  10278. tex = part.Shape.Textures;
  10279. if (face == ScriptBaseClass.ALL_SIDES)
  10280. {
  10281. for (face = 0; face < nsides; face++)
  10282. {
  10283. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  10284. getLSLFaceMaterial(ref res, code, part, texface);
  10285. }
  10286. }
  10287. else
  10288. {
  10289. if (face >= 0 && face < nsides)
  10290. {
  10291. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  10292. getLSLFaceMaterial(ref res, code, part, texface);
  10293. }
  10294. }
  10295. break;
  10296. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  10297. // TODO: Should be issuing a runtime script warning in this case.
  10298. if (remain < 2)
  10299. return new LSL_List();
  10300. return rules.GetSublist(idx, -1);
  10301. }
  10302. }
  10303. return new LSL_List();
  10304. }
  10305. private string GetMaterialTextureUUIDbyRights(UUID origID, SceneObjectPart part)
  10306. {
  10307. if(World.Permissions.CanEditObject(m_host.ParentGroup.UUID, m_host.ParentGroup.RootPart.OwnerID))
  10308. return origID.ToString();
  10309. lock(part.TaskInventory)
  10310. {
  10311. foreach(KeyValuePair<UUID, TaskInventoryItem> inv in part.TaskInventory)
  10312. {
  10313. if(inv.Value.InvType == (int)InventoryType.Texture && inv.Value.AssetID == origID)
  10314. return origID.ToString();
  10315. }
  10316. }
  10317. return ScriptBaseClass.NULL_KEY;
  10318. }
  10319. private void getLSLFaceMaterial(ref LSL_List res, int code, SceneObjectPart part, Primitive.TextureEntryFace texface)
  10320. {
  10321. UUID matID = UUID.Zero;
  10322. if(m_materialsModule != null)
  10323. matID = texface.MaterialID;
  10324. if(matID != UUID.Zero)
  10325. {
  10326. FaceMaterial mat = m_materialsModule.GetMaterial(matID);
  10327. if(mat != null)
  10328. {
  10329. if(code == ScriptBaseClass.PRIM_NORMAL)
  10330. {
  10331. res.Add(new LSL_String(GetMaterialTextureUUIDbyRights(mat.NormalMapID, part)));
  10332. res.Add(new LSL_Vector(mat.NormalRepeatX, mat.NormalRepeatY, 0));
  10333. res.Add(new LSL_Vector(mat.NormalOffsetX, mat.NormalOffsetY, 0));
  10334. res.Add(new LSL_Float(mat.NormalRotation));
  10335. }
  10336. else if(code == ScriptBaseClass.PRIM_SPECULAR)
  10337. {
  10338. const float colorScale = 1.0f / 255f;
  10339. res.Add(new LSL_String(GetMaterialTextureUUIDbyRights(mat.SpecularMapID, part)));
  10340. res.Add(new LSL_Vector(mat.SpecularRepeatX, mat.SpecularRepeatY, 0));
  10341. res.Add(new LSL_Vector(mat.SpecularOffsetX, mat.SpecularOffsetY, 0));
  10342. res.Add(new LSL_Float(mat.SpecularRotation));
  10343. res.Add(new LSL_Vector(mat.SpecularLightColorR * colorScale,
  10344. mat.SpecularLightColorG * colorScale,
  10345. mat.SpecularLightColorB * colorScale));
  10346. res.Add(new LSL_Integer(mat.SpecularLightExponent));
  10347. res.Add(new LSL_Integer(mat.EnvironmentIntensity));
  10348. }
  10349. else if(code == ScriptBaseClass.PRIM_ALPHA_MODE)
  10350. {
  10351. res.Add(new LSL_Integer(mat.DiffuseAlphaMode));
  10352. res.Add(new LSL_Integer(mat.AlphaMaskCutoff));
  10353. }
  10354. return;
  10355. }
  10356. }
  10357. // material not found
  10358. if(code == (int)ScriptBaseClass.PRIM_NORMAL || code == (int)ScriptBaseClass.PRIM_SPECULAR)
  10359. {
  10360. res.Add(new LSL_String(ScriptBaseClass.NULL_KEY));
  10361. res.Add(new LSL_Vector(1.0, 1.0, 0));
  10362. res.Add(new LSL_Vector(0, 0, 0));
  10363. res.Add(new LSL_Float(0));
  10364. if(code == (int)ScriptBaseClass.PRIM_SPECULAR)
  10365. {
  10366. res.Add(new LSL_Vector(1.0, 1.0, 1.0));
  10367. res.Add(new LSL_Integer(51));
  10368. res.Add(new LSL_Integer(0));
  10369. }
  10370. }
  10371. else if(code == (int)ScriptBaseClass.PRIM_ALPHA_MODE)
  10372. {
  10373. res.Add(new LSL_Integer(1));
  10374. res.Add(new LSL_Integer(0));
  10375. }
  10376. }
  10377. public LSL_List llGetPrimMediaParams(int face, LSL_List rules)
  10378. {
  10379. m_host.AddScriptLPS(1);
  10380. ScriptSleep(m_sleepMsOnGetPrimMediaParams);
  10381. return GetPrimMediaParams(m_host, face, rules);
  10382. }
  10383. public LSL_List llGetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules)
  10384. {
  10385. m_host.AddScriptLPS(1);
  10386. ScriptSleep(m_sleepMsOnGetLinkMedia);
  10387. if (link == ScriptBaseClass.LINK_ROOT)
  10388. return GetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules);
  10389. else if (link == ScriptBaseClass.LINK_THIS)
  10390. return GetPrimMediaParams(m_host, face, rules);
  10391. else
  10392. {
  10393. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  10394. if (null != part)
  10395. return GetPrimMediaParams(part, face, rules);
  10396. }
  10397. return new LSL_List();
  10398. }
  10399. private LSL_List GetPrimMediaParams(SceneObjectPart part, int face, LSL_List rules)
  10400. {
  10401. // LSL Spec http://wiki.secondlife.com/wiki/LlGetPrimMediaParams says to fail silently if face is invalid
  10402. // TODO: Need to correctly handle case where a face has no media (which gives back an empty list).
  10403. // Assuming silently fail means give back an empty list. Ideally, need to check this.
  10404. if (face < 0 || face > part.GetNumberOfSides() - 1)
  10405. return new LSL_List();
  10406. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  10407. if (null == module)
  10408. return new LSL_List();
  10409. MediaEntry me = module.GetMediaEntry(part, face);
  10410. // As per http://wiki.secondlife.com/wiki/LlGetPrimMediaParams
  10411. if (null == me)
  10412. return new LSL_List();
  10413. LSL_List res = new LSL_List();
  10414. for (int i = 0; i < rules.Length; i++)
  10415. {
  10416. int code = (int)rules.GetLSLIntegerItem(i);
  10417. switch (code)
  10418. {
  10419. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  10420. // Not implemented
  10421. res.Add(new LSL_Integer(0));
  10422. break;
  10423. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  10424. if (me.Controls == MediaControls.Standard)
  10425. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD));
  10426. else
  10427. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_MINI));
  10428. break;
  10429. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  10430. res.Add(new LSL_String(me.CurrentURL));
  10431. break;
  10432. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  10433. res.Add(new LSL_String(me.HomeURL));
  10434. break;
  10435. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  10436. res.Add(me.AutoLoop ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10437. break;
  10438. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  10439. res.Add(me.AutoPlay ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10440. break;
  10441. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  10442. res.Add(me.AutoScale ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10443. break;
  10444. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  10445. res.Add(me.AutoZoom ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10446. break;
  10447. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  10448. res.Add(me.InteractOnFirstClick ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10449. break;
  10450. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  10451. res.Add(new LSL_Integer(me.Width));
  10452. break;
  10453. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  10454. res.Add(new LSL_Integer(me.Height));
  10455. break;
  10456. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  10457. res.Add(me.EnableWhiteList ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10458. break;
  10459. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  10460. string[] urls = (string[])me.WhiteList.Clone();
  10461. for (int j = 0; j < urls.Length; j++)
  10462. urls[j] = Uri.EscapeDataString(urls[j]);
  10463. res.Add(new LSL_String(string.Join(", ", urls)));
  10464. break;
  10465. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  10466. res.Add(new LSL_Integer((int)me.InteractPermissions));
  10467. break;
  10468. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  10469. res.Add(new LSL_Integer((int)me.ControlPermissions));
  10470. break;
  10471. default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
  10472. }
  10473. }
  10474. return res;
  10475. }
  10476. public LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules)
  10477. {
  10478. m_host.AddScriptLPS(1);
  10479. ScriptSleep(m_sleepMsOnSetPrimMediaParams);
  10480. return SetPrimMediaParams(m_host, face, rules);
  10481. }
  10482. public LSL_Integer llSetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules)
  10483. {
  10484. m_host.AddScriptLPS(1);
  10485. ScriptSleep(m_sleepMsOnSetLinkMedia);
  10486. if (link == ScriptBaseClass.LINK_ROOT)
  10487. return SetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules);
  10488. else if (link == ScriptBaseClass.LINK_THIS)
  10489. return SetPrimMediaParams(m_host, face, rules);
  10490. else
  10491. {
  10492. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  10493. if (null != part)
  10494. return SetPrimMediaParams(part, face, rules);
  10495. }
  10496. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10497. }
  10498. private LSL_Integer SetPrimMediaParams(SceneObjectPart part, LSL_Integer face, LSL_List rules)
  10499. {
  10500. // LSL Spec http://wiki.secondlife.com/wiki/LlSetPrimMediaParams says to fail silently if face is invalid
  10501. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  10502. // Don't perform the media check directly
  10503. if (face < 0 || face > part.GetNumberOfSides() - 1)
  10504. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10505. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  10506. if (null == module)
  10507. return ScriptBaseClass.LSL_STATUS_NOT_SUPPORTED;
  10508. MediaEntry me = module.GetMediaEntry(part, face);
  10509. if (null == me)
  10510. me = new MediaEntry();
  10511. int i = 0;
  10512. while (i < rules.Length - 1)
  10513. {
  10514. int code = rules.GetLSLIntegerItem(i++);
  10515. switch (code)
  10516. {
  10517. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  10518. me.EnableAlterntiveImage = (rules.GetLSLIntegerItem(i++) != 0 ? true : false);
  10519. break;
  10520. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  10521. int v = rules.GetLSLIntegerItem(i++);
  10522. if (ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD == v)
  10523. me.Controls = MediaControls.Standard;
  10524. else
  10525. me.Controls = MediaControls.Mini;
  10526. break;
  10527. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  10528. me.CurrentURL = rules.GetLSLStringItem(i++);
  10529. break;
  10530. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  10531. me.HomeURL = rules.GetLSLStringItem(i++);
  10532. break;
  10533. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  10534. me.AutoLoop = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10535. break;
  10536. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  10537. me.AutoPlay = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10538. break;
  10539. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  10540. me.AutoScale = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10541. break;
  10542. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  10543. me.AutoZoom = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10544. break;
  10545. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  10546. me.InteractOnFirstClick = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10547. break;
  10548. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  10549. me.Width = (int)rules.GetLSLIntegerItem(i++);
  10550. break;
  10551. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  10552. me.Height = (int)rules.GetLSLIntegerItem(i++);
  10553. break;
  10554. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  10555. me.EnableWhiteList = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10556. break;
  10557. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  10558. string[] rawWhiteListUrls = rules.GetLSLStringItem(i++).ToString().Split(new char[] { ',' });
  10559. List<string> whiteListUrls = new List<string>();
  10560. Array.ForEach(
  10561. rawWhiteListUrls, delegate(string rawUrl) { whiteListUrls.Add(rawUrl.Trim()); });
  10562. me.WhiteList = whiteListUrls.ToArray();
  10563. break;
  10564. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  10565. me.InteractPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  10566. break;
  10567. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  10568. me.ControlPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  10569. break;
  10570. default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
  10571. }
  10572. }
  10573. module.SetMediaEntry(part, face, me);
  10574. return ScriptBaseClass.LSL_STATUS_OK;
  10575. }
  10576. public LSL_Integer llClearPrimMedia(LSL_Integer face)
  10577. {
  10578. m_host.AddScriptLPS(1);
  10579. ScriptSleep(m_sleepMsOnClearPrimMedia);
  10580. return ClearPrimMedia(m_host, face);
  10581. }
  10582. public LSL_Integer llClearLinkMedia(LSL_Integer link, LSL_Integer face)
  10583. {
  10584. m_host.AddScriptLPS(1);
  10585. ScriptSleep(m_sleepMsOnClearLinkMedia);
  10586. if (link == ScriptBaseClass.LINK_ROOT)
  10587. return ClearPrimMedia(m_host.ParentGroup.RootPart, face);
  10588. else if (link == ScriptBaseClass.LINK_THIS)
  10589. return ClearPrimMedia(m_host, face);
  10590. else
  10591. {
  10592. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  10593. if (null != part)
  10594. return ClearPrimMedia(part, face);
  10595. }
  10596. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10597. }
  10598. private LSL_Integer ClearPrimMedia(SceneObjectPart part, LSL_Integer face)
  10599. {
  10600. // LSL Spec http://wiki.secondlife.com/wiki/LlClearPrimMedia says to fail silently if face is invalid
  10601. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  10602. // FIXME: Don't perform the media check directly
  10603. if (face < 0 || face > part.GetNumberOfSides() - 1)
  10604. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10605. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  10606. if (null == module)
  10607. return ScriptBaseClass.LSL_STATUS_NOT_SUPPORTED;
  10608. module.ClearMediaEntry(part, face);
  10609. return ScriptBaseClass.LSL_STATUS_OK;
  10610. }
  10611. // <remarks>
  10612. // <para>
  10613. // The .NET definition of base 64 is:
  10614. // <list>
  10615. // <item>
  10616. // Significant: A-Z a-z 0-9 + -
  10617. // </item>
  10618. // <item>
  10619. // Whitespace: \t \n \r ' '
  10620. // </item>
  10621. // <item>
  10622. // Valueless: =
  10623. // </item>
  10624. // <item>
  10625. // End-of-string: \0 or '=='
  10626. // </item>
  10627. // </list>
  10628. // </para>
  10629. // <para>
  10630. // Each point in a base-64 string represents
  10631. // a 6 bit value. A 32-bit integer can be
  10632. // represented using 6 characters (with some
  10633. // redundancy).
  10634. // </para>
  10635. // <para>
  10636. // LSL requires a base64 string to be 8
  10637. // characters in length. LSL also uses '/'
  10638. // rather than '-' (MIME compliant).
  10639. // </para>
  10640. // <para>
  10641. // RFC 1341 used as a reference (as specified
  10642. // by the SecondLife Wiki).
  10643. // </para>
  10644. // <para>
  10645. // SL do not record any kind of exception for
  10646. // these functions, so the string to integer
  10647. // conversion returns '0' if an invalid
  10648. // character is encountered during conversion.
  10649. // </para>
  10650. // <para>
  10651. // References
  10652. // <list>
  10653. // <item>
  10654. // http://lslwiki.net/lslwiki/wakka.php?wakka=Base64
  10655. // </item>
  10656. // <item>
  10657. // </item>
  10658. // </list>
  10659. // </para>
  10660. // </remarks>
  10661. // <summary>
  10662. // Table for converting 6-bit integers into
  10663. // base-64 characters
  10664. // </summary>
  10665. protected static readonly char[] i2ctable =
  10666. {
  10667. 'A','B','C','D','E','F','G','H',
  10668. 'I','J','K','L','M','N','O','P',
  10669. 'Q','R','S','T','U','V','W','X',
  10670. 'Y','Z',
  10671. 'a','b','c','d','e','f','g','h',
  10672. 'i','j','k','l','m','n','o','p',
  10673. 'q','r','s','t','u','v','w','x',
  10674. 'y','z',
  10675. '0','1','2','3','4','5','6','7',
  10676. '8','9',
  10677. '+','/'
  10678. };
  10679. // <summary>
  10680. // Table for converting base-64 characters
  10681. // into 6-bit integers.
  10682. // </summary>
  10683. protected static readonly int[] c2itable =
  10684. {
  10685. -1,-1,-1,-1,-1,-1,-1,-1, // 0x
  10686. -1,-1,-1,-1,-1,-1,-1,-1,
  10687. -1,-1,-1,-1,-1,-1,-1,-1, // 1x
  10688. -1,-1,-1,-1,-1,-1,-1,-1,
  10689. -1,-1,-1,-1,-1,-1,-1,-1, // 2x
  10690. -1,-1,-1,63,-1,-1,-1,64,
  10691. 53,54,55,56,57,58,59,60, // 3x
  10692. 61,62,-1,-1,-1,0,-1,-1,
  10693. -1,1,2,3,4,5,6,7, // 4x
  10694. 8,9,10,11,12,13,14,15,
  10695. 16,17,18,19,20,21,22,23, // 5x
  10696. 24,25,26,-1,-1,-1,-1,-1,
  10697. -1,27,28,29,30,31,32,33, // 6x
  10698. 34,35,36,37,38,39,40,41,
  10699. 42,43,44,45,46,47,48,49, // 7x
  10700. 50,51,52,-1,-1,-1,-1,-1,
  10701. -1,-1,-1,-1,-1,-1,-1,-1, // 8x
  10702. -1,-1,-1,-1,-1,-1,-1,-1,
  10703. -1,-1,-1,-1,-1,-1,-1,-1, // 9x
  10704. -1,-1,-1,-1,-1,-1,-1,-1,
  10705. -1,-1,-1,-1,-1,-1,-1,-1, // Ax
  10706. -1,-1,-1,-1,-1,-1,-1,-1,
  10707. -1,-1,-1,-1,-1,-1,-1,-1, // Bx
  10708. -1,-1,-1,-1,-1,-1,-1,-1,
  10709. -1,-1,-1,-1,-1,-1,-1,-1, // Cx
  10710. -1,-1,-1,-1,-1,-1,-1,-1,
  10711. -1,-1,-1,-1,-1,-1,-1,-1, // Dx
  10712. -1,-1,-1,-1,-1,-1,-1,-1,
  10713. -1,-1,-1,-1,-1,-1,-1,-1, // Ex
  10714. -1,-1,-1,-1,-1,-1,-1,-1,
  10715. -1,-1,-1,-1,-1,-1,-1,-1, // Fx
  10716. -1,-1,-1,-1,-1,-1,-1,-1
  10717. };
  10718. // <summary>
  10719. // Converts a 32-bit integer into a Base64
  10720. // character string. Base64 character strings
  10721. // are always 8 characters long. All iinteger
  10722. // values are acceptable.
  10723. // </summary>
  10724. // <param name="number">
  10725. // 32-bit integer to be converted.
  10726. // </param>
  10727. // <returns>
  10728. // 8 character string. The 1st six characters
  10729. // contain the encoded number, the last two
  10730. // characters are padded with "=".
  10731. // </returns>
  10732. public LSL_String llIntegerToBase64(int number)
  10733. {
  10734. // uninitialized string
  10735. char[] imdt = new char[8];
  10736. m_host.AddScriptLPS(1);
  10737. // Manually unroll the loop
  10738. imdt[7] = '=';
  10739. imdt[6] = '=';
  10740. imdt[5] = i2ctable[number<<4 & 0x3F];
  10741. imdt[4] = i2ctable[number>>2 & 0x3F];
  10742. imdt[3] = i2ctable[number>>8 & 0x3F];
  10743. imdt[2] = i2ctable[number>>14 & 0x3F];
  10744. imdt[1] = i2ctable[number>>20 & 0x3F];
  10745. imdt[0] = i2ctable[number>>26 & 0x3F];
  10746. return new string(imdt);
  10747. }
  10748. // <summary>
  10749. // Converts an eight character base-64 string
  10750. // into a 32-bit integer.
  10751. // </summary>
  10752. // <param name="str">
  10753. // 8 characters string to be converted. Other
  10754. // length strings return zero.
  10755. // </param>
  10756. // <returns>
  10757. // Returns an integer representing the
  10758. // encoded value providedint he 1st 6
  10759. // characters of the string.
  10760. // </returns>
  10761. // <remarks>
  10762. // This is coded to behave like LSL's
  10763. // implementation (I think), based upon the
  10764. // information available at the Wiki.
  10765. // If more than 8 characters are supplied,
  10766. // zero is returned.
  10767. // If a NULL string is supplied, zero will
  10768. // be returned.
  10769. // If fewer than 6 characters are supplied, then
  10770. // the answer will reflect a partial
  10771. // accumulation.
  10772. // <para>
  10773. // The 6-bit segments are
  10774. // extracted left-to-right in big-endian mode,
  10775. // which means that segment 6 only contains the
  10776. // two low-order bits of the 32 bit integer as
  10777. // its high order 2 bits. A short string therefore
  10778. // means loss of low-order information. E.g.
  10779. //
  10780. // |<---------------------- 32-bit integer ----------------------->|<-Pad->|
  10781. // |<--Byte 0----->|<--Byte 1----->|<--Byte 2----->|<--Byte 3----->|<-Pad->|
  10782. // |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|
  10783. // |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|
  10784. // | str[0] | str[1] | str[2] | str[3] | str[4] | str[6] |
  10785. //
  10786. // </para>
  10787. // </remarks>
  10788. public LSL_Integer llBase64ToInteger(string str)
  10789. {
  10790. int number = 0;
  10791. int digit;
  10792. m_host.AddScriptLPS(1);
  10793. // Require a well-fromed base64 string
  10794. if (str.Length > 8)
  10795. return 0;
  10796. // The loop is unrolled in the interests
  10797. // of performance and simple necessity.
  10798. //
  10799. // MUST find 6 digits to be well formed
  10800. // -1 == invalid
  10801. // 0 == padding
  10802. if ((digit = c2itable[str[0]]) <= 0)
  10803. {
  10804. return digit < 0 ? (int)0 : number;
  10805. }
  10806. number += --digit<<26;
  10807. if ((digit = c2itable[str[1]]) <= 0)
  10808. {
  10809. return digit < 0 ? (int)0 : number;
  10810. }
  10811. number += --digit<<20;
  10812. if ((digit = c2itable[str[2]]) <= 0)
  10813. {
  10814. return digit < 0 ? (int)0 : number;
  10815. }
  10816. number += --digit<<14;
  10817. if ((digit = c2itable[str[3]]) <= 0)
  10818. {
  10819. return digit < 0 ? (int)0 : number;
  10820. }
  10821. number += --digit<<8;
  10822. if ((digit = c2itable[str[4]]) <= 0)
  10823. {
  10824. return digit < 0 ? (int)0 : number;
  10825. }
  10826. number += --digit<<2;
  10827. if ((digit = c2itable[str[5]]) <= 0)
  10828. {
  10829. return digit < 0 ? (int)0 : number;
  10830. }
  10831. number += --digit>>4;
  10832. // ignore trailing padding
  10833. return number;
  10834. }
  10835. public LSL_Float llGetGMTclock()
  10836. {
  10837. m_host.AddScriptLPS(1);
  10838. return DateTime.UtcNow.TimeOfDay.TotalSeconds;
  10839. }
  10840. public LSL_String llGetHTTPHeader(LSL_Key request_id, string header)
  10841. {
  10842. m_host.AddScriptLPS(1);
  10843. if (m_UrlModule != null)
  10844. return m_UrlModule.GetHttpHeader(new UUID(request_id), header);
  10845. return String.Empty;
  10846. }
  10847. public LSL_String llGetSimulatorHostname()
  10848. {
  10849. m_host.AddScriptLPS(1);
  10850. IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
  10851. return UrlModule.ExternalHostNameForLSL;
  10852. }
  10853. // <summary>
  10854. // Scan the string supplied in 'src' and
  10855. // tokenize it based upon two sets of
  10856. // tokenizers provided in two lists,
  10857. // separators and spacers.
  10858. // </summary>
  10859. //
  10860. // <remarks>
  10861. // Separators demarcate tokens and are
  10862. // elided as they are encountered. Spacers
  10863. // also demarcate tokens, but are themselves
  10864. // retained as tokens.
  10865. //
  10866. // Both separators and spacers may be arbitrarily
  10867. // long strings. i.e. ":::".
  10868. //
  10869. // The function returns an ordered list
  10870. // representing the tokens found in the supplied
  10871. // sources string. If two successive tokenizers
  10872. // are encountered, then a null-string entry is
  10873. // added to the list.
  10874. //
  10875. // It is a precondition that the source and
  10876. // toekizer lisst are non-null. If they are null,
  10877. // then a null pointer exception will be thrown
  10878. // while their lengths are being determined.
  10879. //
  10880. // A small amount of working memoryis required
  10881. // of approximately 8*#tokenizers + 8*srcstrlen.
  10882. //
  10883. // There are many ways in which this function
  10884. // can be implemented, this implementation is
  10885. // fairly naive and assumes that when the
  10886. // function is invooked with a short source
  10887. // string and/or short lists of tokenizers, then
  10888. // performance will not be an issue.
  10889. //
  10890. // In order to minimize the perofrmance
  10891. // effects of long strings, or large numbers
  10892. // of tokeizers, the function skips as far as
  10893. // possible whenever a toekenizer is found,
  10894. // and eliminates redundant tokenizers as soon
  10895. // as is possible.
  10896. //
  10897. // The implementation tries to minimize temporary
  10898. // garbage generation.
  10899. // </remarks>
  10900. public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
  10901. {
  10902. return ParseString2List(src, separators, spacers, true);
  10903. }
  10904. private LSL_List ParseString2List(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
  10905. {
  10906. int srclen = src.Length;
  10907. int seplen = separators.Length;
  10908. object[] separray = separators.Data;
  10909. int spclen = spacers.Length;
  10910. object[] spcarray = spacers.Data;
  10911. int dellen = 0;
  10912. string[] delarray = new string[seplen+spclen];
  10913. int outlen = 0;
  10914. string[] outarray = new string[srclen*2+1];
  10915. int i, j;
  10916. string d;
  10917. m_host.AddScriptLPS(1);
  10918. /*
  10919. * Convert separator and spacer lists to C# strings.
  10920. * Also filter out null strings so we don't hang.
  10921. */
  10922. for (i = 0; i < seplen; i ++)
  10923. {
  10924. d = separray[i].ToString();
  10925. if (d.Length > 0)
  10926. {
  10927. delarray[dellen++] = d;
  10928. }
  10929. }
  10930. seplen = dellen;
  10931. for (i = 0; i < spclen; i ++)
  10932. {
  10933. d = spcarray[i].ToString();
  10934. if (d.Length > 0)
  10935. {
  10936. delarray[dellen++] = d;
  10937. }
  10938. }
  10939. /*
  10940. * Scan through source string from beginning to end.
  10941. */
  10942. for (i = 0;;)
  10943. {
  10944. /*
  10945. * Find earliest delimeter in src starting at i (if any).
  10946. */
  10947. int earliestDel = -1;
  10948. int earliestSrc = srclen;
  10949. string earliestStr = null;
  10950. for (j = 0; j < dellen; j ++)
  10951. {
  10952. d = delarray[j];
  10953. if (d != null)
  10954. {
  10955. int index = src.IndexOf(d, i);
  10956. if (index < 0)
  10957. {
  10958. delarray[j] = null; // delim nowhere in src, don't check it anymore
  10959. }
  10960. else if (index < earliestSrc)
  10961. {
  10962. earliestSrc = index; // where delimeter starts in source string
  10963. earliestDel = j; // where delimeter is in delarray[]
  10964. earliestStr = d; // the delimeter string from delarray[]
  10965. if (index == i) break; // can't do any better than found at beg of string
  10966. }
  10967. }
  10968. }
  10969. /*
  10970. * Output source string starting at i through start of earliest delimeter.
  10971. */
  10972. if (keepNulls || (earliestSrc > i))
  10973. {
  10974. outarray[outlen++] = src.Substring(i, earliestSrc - i);
  10975. }
  10976. /*
  10977. * If no delimeter found at or after i, we're done scanning.
  10978. */
  10979. if (earliestDel < 0) break;
  10980. /*
  10981. * If delimeter was a spacer, output the spacer.
  10982. */
  10983. if (earliestDel >= seplen)
  10984. {
  10985. outarray[outlen++] = earliestStr;
  10986. }
  10987. /*
  10988. * Look at rest of src string following delimeter.
  10989. */
  10990. i = earliestSrc + earliestStr.Length;
  10991. }
  10992. /*
  10993. * Make up an exact-sized output array suitable for an LSL_List object.
  10994. */
  10995. object[] outlist = new object[outlen];
  10996. for (i = 0; i < outlen; i ++)
  10997. {
  10998. outlist[i] = new LSL_String(outarray[i]);
  10999. }
  11000. return new LSL_List(outlist);
  11001. }
  11002. private const uint fullperms = (uint)PermissionMask.All; // no export for now
  11003. private int PermissionMaskToLSLPerm(uint value)
  11004. {
  11005. value &= fullperms;
  11006. if (value == fullperms)
  11007. return ScriptBaseClass.PERM_ALL;
  11008. if( value == 0)
  11009. return 0;
  11010. int ret = 0;
  11011. if ((value & (uint)PermissionMask.Copy) != 0)
  11012. ret |= ScriptBaseClass.PERM_COPY;
  11013. if ((value & (uint)PermissionMask.Modify) != 0)
  11014. ret |= ScriptBaseClass.PERM_MODIFY;
  11015. if ((value & (uint)PermissionMask.Move) != 0)
  11016. ret |= ScriptBaseClass.PERM_MOVE;
  11017. if ((value & (uint)PermissionMask.Transfer) != 0)
  11018. ret |= ScriptBaseClass.PERM_TRANSFER;
  11019. return ret;
  11020. }
  11021. private uint LSLPermToPermissionMask(int lslperm, uint oldvalue)
  11022. {
  11023. lslperm &= ScriptBaseClass.PERM_ALL;
  11024. if (lslperm == ScriptBaseClass.PERM_ALL)
  11025. return oldvalue |= fullperms;
  11026. oldvalue &= ~fullperms;
  11027. if(lslperm != 0)
  11028. {
  11029. if ((lslperm & ScriptBaseClass.PERM_COPY) != 0)
  11030. oldvalue |= (uint)PermissionMask.Copy;
  11031. if ((lslperm & ScriptBaseClass.PERM_MODIFY) != 0)
  11032. oldvalue |= (uint)PermissionMask.Modify;
  11033. if ((lslperm & ScriptBaseClass.PERM_MOVE) != 0)
  11034. oldvalue |= (uint)PermissionMask.Move;
  11035. if ((lslperm & ScriptBaseClass.PERM_TRANSFER) != 0)
  11036. oldvalue |= (uint)PermissionMask.Transfer;
  11037. }
  11038. return oldvalue;
  11039. }
  11040. private int fixedCopyTransfer(int value)
  11041. {
  11042. if ((value & (ScriptBaseClass.PERM_COPY | ScriptBaseClass.PERM_TRANSFER)) == 0)
  11043. value |= ScriptBaseClass.PERM_TRANSFER;
  11044. return value;
  11045. }
  11046. public LSL_Integer llGetObjectPermMask(int mask)
  11047. {
  11048. m_host.AddScriptLPS(1);
  11049. switch(mask)
  11050. {
  11051. case ScriptBaseClass.MASK_BASE:
  11052. return PermissionMaskToLSLPerm(m_host.BaseMask);
  11053. case ScriptBaseClass.MASK_OWNER:
  11054. return PermissionMaskToLSLPerm(m_host.OwnerMask);
  11055. case ScriptBaseClass.MASK_GROUP:
  11056. return PermissionMaskToLSLPerm(m_host.GroupMask);
  11057. case ScriptBaseClass.MASK_EVERYONE:
  11058. return PermissionMaskToLSLPerm(m_host.EveryoneMask);
  11059. case ScriptBaseClass.MASK_NEXT:
  11060. return PermissionMaskToLSLPerm(m_host.NextOwnerMask);
  11061. }
  11062. return -1;
  11063. }
  11064. public void llSetObjectPermMask(int mask, int value)
  11065. {
  11066. m_host.AddScriptLPS(1);
  11067. if (!m_AllowGodFunctions || !World.Permissions.IsAdministrator(m_host.OwnerID))
  11068. return;
  11069. // not even admins have right to violate basic rules
  11070. if (mask != ScriptBaseClass.MASK_BASE)
  11071. {
  11072. mask &= PermissionMaskToLSLPerm(m_host.BaseMask);
  11073. if (mask != ScriptBaseClass.MASK_OWNER)
  11074. mask &= PermissionMaskToLSLPerm(m_host.OwnerMask);
  11075. }
  11076. switch (mask)
  11077. {
  11078. case ScriptBaseClass.MASK_BASE:
  11079. value = fixedCopyTransfer(value);
  11080. m_host.BaseMask = LSLPermToPermissionMask(value, m_host.BaseMask);
  11081. break;
  11082. case ScriptBaseClass.MASK_OWNER:
  11083. value = fixedCopyTransfer(value);
  11084. m_host.OwnerMask = LSLPermToPermissionMask(value, m_host.OwnerMask);
  11085. break;
  11086. case ScriptBaseClass.MASK_GROUP:
  11087. m_host.GroupMask = LSLPermToPermissionMask(value, m_host.GroupMask);
  11088. break;
  11089. case ScriptBaseClass.MASK_EVERYONE:
  11090. m_host.EveryoneMask = LSLPermToPermissionMask(value, m_host.EveryoneMask);
  11091. break;
  11092. case ScriptBaseClass.MASK_NEXT:
  11093. value = fixedCopyTransfer(value);
  11094. m_host.NextOwnerMask = LSLPermToPermissionMask(value, m_host.NextOwnerMask);
  11095. break;
  11096. default:
  11097. return;
  11098. }
  11099. m_host.ParentGroup.AggregatePerms();
  11100. }
  11101. public LSL_Integer llGetInventoryPermMask(string itemName, int mask)
  11102. {
  11103. m_host.AddScriptLPS(1);
  11104. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  11105. if (item == null)
  11106. return -1;
  11107. switch (mask)
  11108. {
  11109. case ScriptBaseClass.MASK_BASE:
  11110. return PermissionMaskToLSLPerm(item.BasePermissions);
  11111. case ScriptBaseClass.MASK_OWNER:
  11112. return PermissionMaskToLSLPerm(item.CurrentPermissions);
  11113. case ScriptBaseClass.MASK_GROUP:
  11114. return PermissionMaskToLSLPerm(item.GroupPermissions);
  11115. case ScriptBaseClass.MASK_EVERYONE:
  11116. return PermissionMaskToLSLPerm(item.EveryonePermissions);
  11117. case ScriptBaseClass.MASK_NEXT:
  11118. return PermissionMaskToLSLPerm(item.NextPermissions);
  11119. }
  11120. return -1;
  11121. }
  11122. public void llSetInventoryPermMask(string itemName, int mask, int value)
  11123. {
  11124. m_host.AddScriptLPS(1);
  11125. if(!m_AllowGodFunctions || !World.Permissions.IsAdministrator(m_host.OwnerID))
  11126. return;
  11127. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  11128. if (item != null)
  11129. {
  11130. if (mask != ScriptBaseClass.MASK_BASE)
  11131. {
  11132. mask &= PermissionMaskToLSLPerm(item.BasePermissions);
  11133. if (mask != ScriptBaseClass.MASK_OWNER)
  11134. mask &= PermissionMaskToLSLPerm(item.CurrentPermissions);
  11135. }
  11136. /*
  11137. if(item.Type == (int)(AssetType.Settings))
  11138. value |= ScriptBaseClass.PERM_COPY;
  11139. */
  11140. switch (mask)
  11141. {
  11142. case ScriptBaseClass.MASK_BASE:
  11143. value = fixedCopyTransfer(value);
  11144. item.BasePermissions = LSLPermToPermissionMask(value, item.BasePermissions);
  11145. break;
  11146. case ScriptBaseClass.MASK_OWNER:
  11147. value = fixedCopyTransfer(value);
  11148. item.CurrentPermissions = LSLPermToPermissionMask(value, item.CurrentPermissions);
  11149. break;
  11150. case ScriptBaseClass.MASK_GROUP:
  11151. item.GroupPermissions = LSLPermToPermissionMask(value, item.GroupPermissions);
  11152. break;
  11153. case ScriptBaseClass.MASK_EVERYONE:
  11154. item.EveryonePermissions = LSLPermToPermissionMask(value, item.EveryonePermissions);
  11155. break;
  11156. case ScriptBaseClass.MASK_NEXT:
  11157. value = fixedCopyTransfer(value);
  11158. item.NextPermissions = LSLPermToPermissionMask(value, item.NextPermissions);
  11159. break;
  11160. default:
  11161. return;
  11162. }
  11163. m_host.ParentGroup.InvalidateDeepEffectivePerms();
  11164. m_host.ParentGroup.AggregatePerms();
  11165. }
  11166. }
  11167. public LSL_Key llGetInventoryCreator(string itemName)
  11168. {
  11169. m_host.AddScriptLPS(1);
  11170. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  11171. if (item == null)
  11172. {
  11173. Error("llGetInventoryCreator", "Can't find item '" + item + "'");
  11174. return String.Empty;
  11175. }
  11176. return item.CreatorID.ToString();
  11177. }
  11178. public void llOwnerSay(string msg)
  11179. {
  11180. m_host.AddScriptLPS(1);
  11181. World.SimChatBroadcast(Utils.StringToBytes(msg), ChatTypeEnum.Owner, 0,
  11182. m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  11183. // IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  11184. // wComm.DeliverMessage(ChatTypeEnum.Owner, 0, m_host.Name, m_host.UUID, msg);
  11185. }
  11186. public LSL_Key llRequestSecureURL()
  11187. {
  11188. m_host.AddScriptLPS(1);
  11189. if (m_UrlModule != null)
  11190. return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, null).ToString();
  11191. return ScriptBaseClass.NULL_KEY;
  11192. }
  11193. public LSL_Key llRequestSimulatorData(string simulator, int data)
  11194. {
  11195. try
  11196. {
  11197. m_host.AddScriptLPS(1);
  11198. if (World.RegionInfo.RegionName == simulator)
  11199. {
  11200. string lreply = String.Empty;
  11201. GridRegion linfo = new GridRegion(World.RegionInfo);
  11202. switch (data)
  11203. {
  11204. case ScriptBaseClass.DATA_SIM_POS:
  11205. {
  11206. lreply = new LSL_Vector(
  11207. linfo.RegionLocX,
  11208. linfo.RegionLocY,
  11209. 0).ToString();
  11210. }
  11211. break;
  11212. case ScriptBaseClass.DATA_SIM_STATUS:
  11213. lreply = "up"; // Duh!
  11214. break;
  11215. case ScriptBaseClass.DATA_SIM_RATING:
  11216. int access = linfo.Maturity;
  11217. if (access == 0)
  11218. lreply = "PG";
  11219. else if (access == 1)
  11220. lreply = "MATURE";
  11221. else if (access == 2)
  11222. lreply = "ADULT";
  11223. else
  11224. lreply = "UNKNOWN";
  11225. break;
  11226. case ScriptBaseClass.DATA_SIM_RELEASE:
  11227. lreply = "OpenSim";
  11228. break;
  11229. default:
  11230. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11231. return ScriptBaseClass.NULL_KEY; // Raise no event
  11232. }
  11233. string ltid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId,
  11234. m_item.ItemID, lreply);
  11235. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11236. return ltid;
  11237. }
  11238. Action<string> act = eventID =>
  11239. {
  11240. GridRegion info = World.GridService.GetRegionByName(RegionScopeID, simulator);
  11241. string reply = "unknown";
  11242. if (info != null)
  11243. {
  11244. switch (data)
  11245. {
  11246. case ScriptBaseClass.DATA_SIM_POS:
  11247. // Hypergrid is currently placing real destination region co-ords into RegionSecret.
  11248. // But other code can also use this field for a genuine RegionSecret! Therefore, if
  11249. // anything is present we need to disambiguate.
  11250. //
  11251. // FIXME: Hypergrid should be storing this data in a different field.
  11252. RegionFlags regionFlags = (RegionFlags)m_ScriptEngine.World.GridService.GetRegionFlags(
  11253. info.ScopeID, info.RegionID);
  11254. if ((regionFlags & RegionFlags.Hyperlink) != 0)
  11255. {
  11256. Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out uint rx, out uint ry);
  11257. reply = new LSL_Vector(rx, ry, 0).ToString();
  11258. }
  11259. else
  11260. {
  11261. // Local grid co-oridnates
  11262. reply = new LSL_Vector(info.RegionLocX, info.RegionLocY, 0).ToString();
  11263. }
  11264. break;
  11265. case ScriptBaseClass.DATA_SIM_STATUS:
  11266. reply = "up"; // Duh!
  11267. break;
  11268. case ScriptBaseClass.DATA_SIM_RATING:
  11269. int access = info.Maturity;
  11270. if (access == 0)
  11271. reply = "PG";
  11272. else if (access == 1)
  11273. reply = "MATURE";
  11274. else if (access == 2)
  11275. reply = "ADULT";
  11276. else
  11277. reply = "UNKNOWN";
  11278. break;
  11279. case ScriptBaseClass.DATA_SIM_RELEASE:
  11280. reply = "OpenSim";
  11281. break;
  11282. default:
  11283. break;
  11284. }
  11285. }
  11286. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, reply);
  11287. };
  11288. UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(
  11289. m_host.LocalId, m_item.ItemID, act);
  11290. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11291. return tid.ToString();
  11292. }
  11293. catch(Exception)
  11294. {
  11295. //m_log.Error("[LSL_API]: llRequestSimulatorData" + e.ToString());
  11296. return ScriptBaseClass.NULL_KEY;
  11297. }
  11298. }
  11299. public LSL_Key llRequestURL()
  11300. {
  11301. m_host.AddScriptLPS(1);
  11302. if (m_UrlModule != null)
  11303. return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, null).ToString();
  11304. return ScriptBaseClass.NULL_KEY;
  11305. }
  11306. public void llForceMouselook(int mouselook)
  11307. {
  11308. m_host.AddScriptLPS(1);
  11309. m_host.SetForceMouselook(mouselook != 0);
  11310. }
  11311. public LSL_Float llGetObjectMass(LSL_Key id)
  11312. {
  11313. m_host.AddScriptLPS(1);
  11314. UUID key = new UUID();
  11315. if (!UUID.TryParse(id, out key))
  11316. return 0;
  11317. // return total object mass
  11318. SceneObjectPart part = World.GetSceneObjectPart(key);
  11319. if (part != null)
  11320. return part.ParentGroup.GetMass();
  11321. // the object is null so the key is for an avatar
  11322. ScenePresence avatar = World.GetScenePresence(key);
  11323. if (avatar != null)
  11324. {
  11325. if (avatar.IsChildAgent)
  11326. {
  11327. // reference http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetObjectMass
  11328. // child agents have a mass of 1.0
  11329. return 1;
  11330. }
  11331. else
  11332. {
  11333. return avatar.GetMass();
  11334. }
  11335. }
  11336. return 0;
  11337. }
  11338. /// <summary>
  11339. /// llListReplaceList removes the sub-list defined by the inclusive indices
  11340. /// start and end and inserts the src list in its place. The inclusive
  11341. /// nature of the indices means that at least one element must be deleted
  11342. /// if the indices are within the bounds of the existing list. I.e. 2,2
  11343. /// will remove the element at index 2 and replace it with the source
  11344. /// list. Both indices may be negative, with the usual interpretation. An
  11345. /// interesting case is where end is lower than start. As these indices
  11346. /// bound the list to be removed, then 0->end, and start->lim are removed
  11347. /// and the source list is added as a suffix.
  11348. /// </summary>
  11349. public LSL_List llListReplaceList(LSL_List dest, LSL_List src, int start, int end)
  11350. {
  11351. LSL_List pref;
  11352. m_host.AddScriptLPS(1);
  11353. // Note that although we have normalized, both
  11354. // indices could still be negative.
  11355. if (start < 0)
  11356. {
  11357. start = start+dest.Length;
  11358. }
  11359. if (end < 0)
  11360. {
  11361. end = end+dest.Length;
  11362. }
  11363. // The comventional case, remove a sequence starting with
  11364. // start and ending with end. And then insert the source
  11365. // list.
  11366. if (start <= end)
  11367. {
  11368. // If greater than zero, then there is going to be a
  11369. // surviving prefix. Otherwise the inclusive nature
  11370. // of the indices mean that we're going to add the
  11371. // source list as a prefix.
  11372. if (start > 0)
  11373. {
  11374. pref = dest.GetSublist(0,start-1);
  11375. // Only add a suffix if there is something
  11376. // beyond the end index (it's inclusive too).
  11377. if (end + 1 < dest.Length)
  11378. {
  11379. return pref + src + dest.GetSublist(end + 1, -1);
  11380. }
  11381. else
  11382. {
  11383. return pref + src;
  11384. }
  11385. }
  11386. // If start is less than or equal to zero, then
  11387. // the new list is simply a prefix. We still need to
  11388. // figure out any necessary surgery to the destination
  11389. // based upon end. Note that if end exceeds the upper
  11390. // bound in this case, the entire destination list
  11391. // is removed.
  11392. else if (start == 0)
  11393. {
  11394. if (end + 1 < dest.Length)
  11395. return src + dest.GetSublist(end + 1, -1);
  11396. else
  11397. return src;
  11398. }
  11399. else // Start < 0
  11400. {
  11401. if (end + 1 < dest.Length)
  11402. return dest.GetSublist(end + 1, -1);
  11403. else
  11404. return new LSL_List();
  11405. }
  11406. }
  11407. // Finally, if start > end, we strip away a prefix and
  11408. // a suffix, to leave the list that sits <between> ens
  11409. // and start, and then tag on the src list. AT least
  11410. // that's my interpretation. We can get sublist to do
  11411. // this for us. Note that one, or both of the indices
  11412. // might have been negative.
  11413. else
  11414. {
  11415. return dest.GetSublist(end + 1, start - 1) + src;
  11416. }
  11417. }
  11418. public void llLoadURL(string avatar_id, string message, string url)
  11419. {
  11420. m_host.AddScriptLPS(1);
  11421. if(m_host.OwnerID == m_host.GroupID)
  11422. return;
  11423. try
  11424. {
  11425. Uri m_checkuri = new Uri(url);
  11426. if (m_checkuri.Scheme != Uri.UriSchemeHttp && m_checkuri.Scheme != Uri.UriSchemeHttps)
  11427. {
  11428. Error("llLoadURL","Invalid url schema");
  11429. ScriptSleep(200);
  11430. return;
  11431. }
  11432. }
  11433. catch
  11434. {
  11435. Error("llLoadURL","Invalid url");
  11436. ScriptSleep(200);
  11437. return;
  11438. }
  11439. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  11440. if (null != dm)
  11441. dm.SendUrlToUser(
  11442. new UUID(avatar_id), m_host.Name, m_host.UUID, m_host.OwnerID, false, message, url);
  11443. ScriptSleep(m_sleepMsOnLoadURL);
  11444. }
  11445. public void llParcelMediaCommandList(LSL_List commandList)
  11446. {
  11447. // TODO: Not implemented yet (missing in libomv?):
  11448. // 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)
  11449. m_host.AddScriptLPS(1);
  11450. // according to the docs, this command only works if script owner and land owner are the same
  11451. // lets add estate owners and gods, too, and use the generic permission check.
  11452. ILandObject landObject = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11453. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia, false)) return;
  11454. bool update = false; // send a ParcelMediaUpdate (and possibly change the land's media URL)?
  11455. byte loop = 0;
  11456. LandData landData = landObject.LandData;
  11457. string url = landData.MediaURL;
  11458. string texture = landData.MediaID.ToString();
  11459. bool autoAlign = landData.MediaAutoScale != 0;
  11460. string mediaType = ""; // TODO these have to be added as soon as LandData supports it
  11461. string description = "";
  11462. int width = 0;
  11463. int height = 0;
  11464. ParcelMediaCommandEnum? commandToSend = null;
  11465. float time = 0.0f; // default is from start
  11466. uint cmndFlags = 0;
  11467. ScenePresence presence = null;
  11468. int cmd;
  11469. for (int i = 0; i < commandList.Data.Length; i++)
  11470. {
  11471. if(commandList.Data[i] is LSL_Integer)
  11472. cmd = (LSL_Integer)commandList.Data[i];
  11473. else
  11474. cmd = (int)commandList.Data[i];
  11475. ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)cmd;
  11476. switch (command)
  11477. {
  11478. case ParcelMediaCommandEnum.Agent:
  11479. // we send only to one agent
  11480. if ((i + 1) < commandList.Length)
  11481. {
  11482. if (commandList.Data[i + 1] is LSL_String)
  11483. {
  11484. if (UUID.TryParse((LSL_String)commandList.Data[i + 1], out UUID agentID))
  11485. {
  11486. presence = World.GetScenePresence(agentID);
  11487. if(presence == null || presence.IsNPC)
  11488. return;
  11489. }
  11490. }
  11491. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AGENT must be a key");
  11492. ++i;
  11493. }
  11494. break;
  11495. case ParcelMediaCommandEnum.Loop:
  11496. loop = 1;
  11497. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_LOOP);
  11498. commandToSend = command;
  11499. update = true; //need to send the media update packet to set looping
  11500. break;
  11501. case ParcelMediaCommandEnum.Play:
  11502. loop = 0;
  11503. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_PLAY);
  11504. commandToSend = command;
  11505. update = true; //need to send the media update packet to make sure it doesn't loop
  11506. break;
  11507. case ParcelMediaCommandEnum.Pause:
  11508. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_PAUSE);
  11509. commandToSend = command;
  11510. break;
  11511. case ParcelMediaCommandEnum.Stop:
  11512. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_STOP);
  11513. commandToSend = command;
  11514. break;
  11515. case ParcelMediaCommandEnum.Unload:
  11516. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_UNLOAD);
  11517. commandToSend = command;
  11518. break;
  11519. case ParcelMediaCommandEnum.Url:
  11520. if ((i + 1) < commandList.Length)
  11521. {
  11522. if (commandList.Data[i + 1] is LSL_String)
  11523. {
  11524. url = (LSL_String)commandList.Data[i + 1];
  11525. if(string.IsNullOrWhiteSpace(url))
  11526. url = string.Empty;
  11527. else
  11528. {
  11529. try
  11530. {
  11531. Uri dummy = new Uri(url, UriKind.Absolute);
  11532. }
  11533. catch
  11534. {
  11535. Error("llParcelMediaCommandList", "invalid PARCEL_MEDIA_COMMAND_URL");
  11536. return;
  11537. }
  11538. }
  11539. update = true;
  11540. }
  11541. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_URL must be a string");
  11542. ++i;
  11543. }
  11544. break;
  11545. case ParcelMediaCommandEnum.Texture:
  11546. if ((i + 1) < commandList.Length)
  11547. {
  11548. if (commandList.Data[i + 1] is LSL_String)
  11549. {
  11550. texture = (LSL_String)commandList.Data[i + 1];
  11551. update = true;
  11552. }
  11553. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TEXTURE must be a string or a key");
  11554. ++i;
  11555. }
  11556. break;
  11557. case ParcelMediaCommandEnum.Time:
  11558. if ((i + 1) < commandList.Length)
  11559. {
  11560. if (commandList.Data[i + 1] is LSL_Float)
  11561. {
  11562. time = (float)(LSL_Float)commandList.Data[i + 1];
  11563. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_TIME);
  11564. }
  11565. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TIME must be a float");
  11566. ++i;
  11567. }
  11568. break;
  11569. case ParcelMediaCommandEnum.AutoAlign:
  11570. if ((i + 1) < commandList.Length)
  11571. {
  11572. if (commandList.Data[i + 1] is LSL_Integer)
  11573. {
  11574. autoAlign = (LSL_Integer)commandList.Data[i + 1];
  11575. update = true;
  11576. }
  11577. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AUTO_ALIGN must be an integer");
  11578. ++i;
  11579. }
  11580. break;
  11581. case ParcelMediaCommandEnum.Type:
  11582. if ((i + 1) < commandList.Length)
  11583. {
  11584. if (commandList.Data[i + 1] is LSL_String)
  11585. {
  11586. mediaType = (LSL_String)commandList.Data[i + 1];
  11587. update = true;
  11588. }
  11589. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TYPE must be a string");
  11590. ++i;
  11591. }
  11592. break;
  11593. case ParcelMediaCommandEnum.Desc:
  11594. if ((i + 1) < commandList.Length)
  11595. {
  11596. if (commandList.Data[i + 1] is LSL_String)
  11597. {
  11598. description = (LSL_String)commandList.Data[i + 1];
  11599. update = true;
  11600. }
  11601. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_DESC must be a string");
  11602. ++i;
  11603. }
  11604. break;
  11605. case ParcelMediaCommandEnum.Size:
  11606. if ((i + 2) < commandList.Length)
  11607. {
  11608. if (commandList.Data[i + 1] is LSL_Integer)
  11609. {
  11610. if (commandList.Data[i + 2] is LSL_Integer)
  11611. {
  11612. width = (LSL_Integer)commandList.Data[i + 1];
  11613. height = (LSL_Integer)commandList.Data[i + 2];
  11614. update = true;
  11615. }
  11616. else Error("llParcelMediaCommandList", "The second argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer");
  11617. }
  11618. else Error("llParcelMediaCommandList", "The first argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer");
  11619. i += 2;
  11620. }
  11621. break;
  11622. default:
  11623. NotImplemented("llParcelMediaCommandList", "Parameter not supported yet: " + Enum.Parse(typeof(ParcelMediaCommandEnum), commandList.Data[i].ToString()).ToString());
  11624. break;
  11625. }//end switch
  11626. }//end for
  11627. // if we didn't get a presence, we send to all and change the url
  11628. // if we did get a presence, we only send to the agent specified, and *don't change the land settings*!
  11629. // did something important change or do we only start/stop/pause?
  11630. if (update)
  11631. {
  11632. if (presence == null)
  11633. {
  11634. // we send to all
  11635. landData.MediaID = new UUID(texture);
  11636. landData.MediaAutoScale = autoAlign ? (byte)1 : (byte)0;
  11637. landData.MediaWidth = width;
  11638. landData.MediaHeight = height;
  11639. landData.MediaType = mediaType;
  11640. // do that one last, it will cause a ParcelPropertiesUpdate
  11641. landObject.SetMediaUrl(url);
  11642. // now send to all (non-child) agents in the parcel
  11643. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  11644. {
  11645. if (sp.currentParcelUUID == landData.GlobalID)
  11646. {
  11647. sp.ControllingClient.SendParcelMediaUpdate(landData.MediaURL,
  11648. landData.MediaID,
  11649. landData.MediaAutoScale,
  11650. mediaType,
  11651. description,
  11652. width, height,
  11653. loop);
  11654. }
  11655. });
  11656. }
  11657. else if (!presence.IsChildAgent)
  11658. {
  11659. // we only send to one (root) agent
  11660. presence.ControllingClient.SendParcelMediaUpdate(url,
  11661. new UUID(texture),
  11662. autoAlign ? (byte)1 : (byte)0,
  11663. mediaType,
  11664. description,
  11665. width, height,
  11666. loop);
  11667. }
  11668. }
  11669. if (commandToSend != null)
  11670. {
  11671. // the commandList contained a start/stop/... command, too
  11672. if (presence == null)
  11673. {
  11674. // send to all (non-child) agents in the parcel
  11675. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  11676. {
  11677. if (sp.currentParcelUUID == landData.GlobalID)
  11678. {
  11679. sp.ControllingClient.SendParcelMediaCommand(cmndFlags,
  11680. commandToSend.Value, time);
  11681. }
  11682. });
  11683. }
  11684. else if (!presence.IsChildAgent)
  11685. {
  11686. presence.ControllingClient.SendParcelMediaCommand(cmndFlags,
  11687. commandToSend.Value, time);
  11688. }
  11689. }
  11690. ScriptSleep(m_sleepMsOnParcelMediaCommandList);
  11691. }
  11692. public LSL_List llParcelMediaQuery(LSL_List aList)
  11693. {
  11694. m_host.AddScriptLPS(1);
  11695. LSL_List list = new LSL_List();
  11696. Vector3 pos = m_host.AbsolutePosition;
  11697. ILandObject landObject = World.LandChannel.GetLandObject(pos);
  11698. if(landObject == null)
  11699. return list;
  11700. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia, false))
  11701. return list;
  11702. LandData land = landObject.LandData;
  11703. if(land == null)
  11704. return list;
  11705. //TO DO: make the implementation for the missing commands
  11706. //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)
  11707. for (int i = 0; i < aList.Data.Length; i++)
  11708. {
  11709. if (aList.Data[i] != null)
  11710. {
  11711. switch ((ParcelMediaCommandEnum) Convert.ToInt32(aList.Data[i].ToString()))
  11712. {
  11713. case ParcelMediaCommandEnum.Url:
  11714. list.Add(new LSL_String(land.MediaURL));
  11715. break;
  11716. case ParcelMediaCommandEnum.Desc:
  11717. list.Add(new LSL_String(land.MediaDescription));
  11718. break;
  11719. case ParcelMediaCommandEnum.Texture:
  11720. list.Add(new LSL_String(land.MediaID.ToString()));
  11721. break;
  11722. case ParcelMediaCommandEnum.Type:
  11723. list.Add(new LSL_String(land.MediaType));
  11724. break;
  11725. case ParcelMediaCommandEnum.Size:
  11726. list.Add(new LSL_String(land.MediaWidth));
  11727. list.Add(new LSL_String(land.MediaHeight));
  11728. break;
  11729. default:
  11730. ParcelMediaCommandEnum mediaCommandEnum = ParcelMediaCommandEnum.Url;
  11731. NotImplemented("llParcelMediaQuery", "Parameter not supported yet: " + Enum.Parse(mediaCommandEnum.GetType() , aList.Data[i].ToString()).ToString());
  11732. break;
  11733. }
  11734. }
  11735. }
  11736. ScriptSleep(m_sleepMsOnParcelMediaQuery);
  11737. return list;
  11738. }
  11739. public LSL_Integer llModPow(int a, int b, int c)
  11740. {
  11741. m_host.AddScriptLPS(1);
  11742. Math.DivRem((long)Math.Pow(a, b), c, out long tmp);
  11743. ScriptSleep(m_sleepMsOnModPow);
  11744. return (int)tmp;
  11745. }
  11746. public LSL_Integer llGetInventoryType(string name)
  11747. {
  11748. m_host.AddScriptLPS(1);
  11749. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  11750. if (item == null)
  11751. return -1;
  11752. return item.Type;
  11753. }
  11754. public void llSetPayPrice(int price, LSL_List quick_pay_buttons)
  11755. {
  11756. m_host.AddScriptLPS(1);
  11757. if(m_host.LocalId != m_host.ParentGroup.RootPart.LocalId)
  11758. return;
  11759. if (quick_pay_buttons.Data.Length < 4)
  11760. {
  11761. int x;
  11762. for (x=quick_pay_buttons.Data.Length; x<= 4; x++)
  11763. {
  11764. quick_pay_buttons.Add(ScriptBaseClass.PAY_HIDE);
  11765. }
  11766. }
  11767. int[] nPrice = new int[5];
  11768. nPrice[0] = price;
  11769. nPrice[1] = quick_pay_buttons.GetLSLIntegerItem(0);
  11770. nPrice[2] = quick_pay_buttons.GetLSLIntegerItem(1);
  11771. nPrice[3] = quick_pay_buttons.GetLSLIntegerItem(2);
  11772. nPrice[4] = quick_pay_buttons.GetLSLIntegerItem(3);
  11773. m_host.ParentGroup.RootPart.PayPrice = nPrice;
  11774. m_host.ParentGroup.HasGroupChanged = true;
  11775. }
  11776. public LSL_Vector llGetCameraPos()
  11777. {
  11778. m_host.AddScriptLPS(1);
  11779. if (m_item.PermsGranter == UUID.Zero)
  11780. return Vector3.Zero;
  11781. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  11782. {
  11783. Error("llGetCameraPos", "No permissions to track the camera");
  11784. return Vector3.Zero;
  11785. }
  11786. // ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  11787. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  11788. if (presence != null)
  11789. {
  11790. LSL_Vector pos = new LSL_Vector(presence.CameraPosition);
  11791. return pos;
  11792. }
  11793. return Vector3.Zero;
  11794. }
  11795. public LSL_Rotation llGetCameraRot()
  11796. {
  11797. m_host.AddScriptLPS(1);
  11798. if (m_item.PermsGranter == UUID.Zero)
  11799. return Quaternion.Identity;
  11800. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  11801. {
  11802. Error("llGetCameraRot", "No permissions to track the camera");
  11803. return Quaternion.Identity;
  11804. }
  11805. // ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  11806. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  11807. if (presence != null)
  11808. {
  11809. return new LSL_Rotation(presence.CameraRotation);
  11810. }
  11811. return Quaternion.Identity;
  11812. }
  11813. public void llSetPrimURL(string url)
  11814. {
  11815. m_host.AddScriptLPS(1);
  11816. Deprecated("llSetPrimURL", "Use llSetPrimMediaParams instead");
  11817. ScriptSleep(m_sleepMsOnSetPrimURL);
  11818. }
  11819. public void llRefreshPrimURL()
  11820. {
  11821. m_host.AddScriptLPS(1);
  11822. Deprecated("llRefreshPrimURL");
  11823. ScriptSleep(m_sleepMsOnRefreshPrimURL);
  11824. }
  11825. public LSL_String llEscapeURL(string url)
  11826. {
  11827. m_host.AddScriptLPS(1);
  11828. try
  11829. {
  11830. return Uri.EscapeDataString(url);
  11831. }
  11832. catch (Exception ex)
  11833. {
  11834. return "llEscapeURL: " + ex.ToString();
  11835. }
  11836. }
  11837. public LSL_String llUnescapeURL(string url)
  11838. {
  11839. m_host.AddScriptLPS(1);
  11840. try
  11841. {
  11842. return Uri.UnescapeDataString(url);
  11843. }
  11844. catch (Exception ex)
  11845. {
  11846. return "llUnescapeURL: " + ex.ToString();
  11847. }
  11848. }
  11849. public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt)
  11850. {
  11851. m_host.AddScriptLPS(1);
  11852. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
  11853. if (detectedParams == null)
  11854. {
  11855. if (m_host.ParentGroup.IsAttachment == true)
  11856. {
  11857. detectedParams = new DetectParams
  11858. {
  11859. Key = m_host.OwnerID
  11860. };
  11861. }
  11862. else
  11863. {
  11864. return;
  11865. }
  11866. }
  11867. ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
  11868. if (avatar != null)
  11869. {
  11870. avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name,
  11871. simname, pos, lookAt);
  11872. }
  11873. ScriptSleep(m_sleepMsOnMapDestination);
  11874. }
  11875. public void llAddToLandBanList(LSL_Key avatar, LSL_Float hours)
  11876. {
  11877. m_host.AddScriptLPS(1);
  11878. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11879. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned, false))
  11880. {
  11881. int expires = 0;
  11882. if (hours != 0)
  11883. expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours);
  11884. if (UUID.TryParse(avatar, out UUID key))
  11885. {
  11886. int idx = land.LandData.ParcelAccessList.FindIndex(
  11887. delegate(LandAccessEntry e)
  11888. {
  11889. if (e.AgentID == key && e.Flags == AccessList.Ban)
  11890. return true;
  11891. return false;
  11892. });
  11893. if (idx != -1 && (land.LandData.ParcelAccessList[idx].Expires == 0 || (expires != 0 && expires < land.LandData.ParcelAccessList[idx].Expires)))
  11894. return;
  11895. if (idx != -1)
  11896. land.LandData.ParcelAccessList.RemoveAt(idx);
  11897. LandAccessEntry entry = new LandAccessEntry
  11898. {
  11899. AgentID = key,
  11900. Flags = AccessList.Ban,
  11901. Expires = expires
  11902. };
  11903. land.LandData.ParcelAccessList.Add(entry);
  11904. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  11905. }
  11906. }
  11907. ScriptSleep(m_sleepMsOnAddToLandBanList);
  11908. }
  11909. public void llRemoveFromLandPassList(string avatar)
  11910. {
  11911. m_host.AddScriptLPS(1);
  11912. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11913. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManagePasses, false))
  11914. {
  11915. if (UUID.TryParse(avatar, out UUID key))
  11916. {
  11917. int idx = land.LandData.ParcelAccessList.FindIndex(
  11918. delegate(LandAccessEntry e)
  11919. {
  11920. if (e.AgentID == key && e.Flags == AccessList.Access)
  11921. return true;
  11922. return false;
  11923. });
  11924. if (idx != -1)
  11925. {
  11926. land.LandData.ParcelAccessList.RemoveAt(idx);
  11927. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  11928. }
  11929. }
  11930. }
  11931. ScriptSleep(m_sleepMsOnRemoveFromLandPassList);
  11932. }
  11933. public void llRemoveFromLandBanList(string avatar)
  11934. {
  11935. m_host.AddScriptLPS(1);
  11936. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11937. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned, false))
  11938. {
  11939. if (UUID.TryParse(avatar, out UUID key))
  11940. {
  11941. int idx = land.LandData.ParcelAccessList.FindIndex(
  11942. delegate(LandAccessEntry e)
  11943. {
  11944. if (e.AgentID == key && e.Flags == AccessList.Ban)
  11945. return true;
  11946. return false;
  11947. });
  11948. if (idx != -1)
  11949. {
  11950. land.LandData.ParcelAccessList.RemoveAt(idx);
  11951. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  11952. }
  11953. }
  11954. }
  11955. ScriptSleep(m_sleepMsOnRemoveFromLandBanList);
  11956. }
  11957. public void llSetCameraParams(LSL_List rules)
  11958. {
  11959. m_host.AddScriptLPS(1);
  11960. // the object we are in
  11961. UUID objectID = m_host.ParentUUID;
  11962. if (objectID == UUID.Zero)
  11963. return;
  11964. // we need the permission first, to know which avatar we want to set the camera for
  11965. UUID agentID = m_item.PermsGranter;
  11966. if (agentID == UUID.Zero)
  11967. return;
  11968. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  11969. return;
  11970. ScenePresence presence = World.GetScenePresence(agentID);
  11971. // we are not interested in child-agents
  11972. if (presence.IsChildAgent) return;
  11973. SortedDictionary<int, float> parameters = new SortedDictionary<int, float>();
  11974. object[] data = rules.Data;
  11975. for (int i = 0; i < data.Length; ++i)
  11976. {
  11977. int type;
  11978. try
  11979. {
  11980. type = Convert.ToInt32(data[i++].ToString());
  11981. }
  11982. catch
  11983. {
  11984. Error("llSetCameraParams", string.Format("Invalid camera param type {0}", data[i - 1]));
  11985. return;
  11986. }
  11987. if (i >= data.Length) break; // odd number of entries => ignore the last
  11988. // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
  11989. switch (type)
  11990. {
  11991. case ScriptBaseClass.CAMERA_FOCUS:
  11992. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  11993. case ScriptBaseClass.CAMERA_POSITION:
  11994. LSL_Vector v = (LSL_Vector)data[i];
  11995. try
  11996. {
  11997. parameters.Add(type + 1, (float)v.x);
  11998. }
  11999. catch
  12000. {
  12001. switch(type)
  12002. {
  12003. case ScriptBaseClass.CAMERA_FOCUS:
  12004. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter x is invalid");
  12005. return;
  12006. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  12007. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter x is invalid");
  12008. return;
  12009. case ScriptBaseClass.CAMERA_POSITION:
  12010. Error("llSetCameraParams", "CAMERA_POSITION: Parameter x is invalid");
  12011. return;
  12012. }
  12013. }
  12014. try
  12015. {
  12016. parameters.Add(type + 2, (float)v.y);
  12017. }
  12018. catch
  12019. {
  12020. switch(type)
  12021. {
  12022. case ScriptBaseClass.CAMERA_FOCUS:
  12023. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter y is invalid");
  12024. return;
  12025. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  12026. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter y is invalid");
  12027. return;
  12028. case ScriptBaseClass.CAMERA_POSITION:
  12029. Error("llSetCameraParams", "CAMERA_POSITION: Parameter y is invalid");
  12030. return;
  12031. }
  12032. }
  12033. try
  12034. {
  12035. parameters.Add(type + 3, (float)v.z);
  12036. }
  12037. catch
  12038. {
  12039. switch(type)
  12040. {
  12041. case ScriptBaseClass.CAMERA_FOCUS:
  12042. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter z is invalid");
  12043. return;
  12044. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  12045. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter z is invalid");
  12046. return;
  12047. case ScriptBaseClass.CAMERA_POSITION:
  12048. Error("llSetCameraParams", "CAMERA_POSITION: Parameter z is invalid");
  12049. return;
  12050. }
  12051. }
  12052. break;
  12053. default:
  12054. // TODO: clean that up as soon as the implicit casts are in
  12055. if (data[i] is LSL_Float)
  12056. parameters.Add(type, (float)((LSL_Float)data[i]).value);
  12057. else if (data[i] is LSL_Integer)
  12058. parameters.Add(type, (float)((LSL_Integer)data[i]).value);
  12059. else
  12060. {
  12061. try
  12062. {
  12063. parameters.Add(type, Convert.ToSingle(data[i]));
  12064. }
  12065. catch
  12066. {
  12067. Error("llSetCameraParams", string.Format("{0}: Parameter is invalid", type));
  12068. }
  12069. }
  12070. break;
  12071. }
  12072. }
  12073. if (parameters.Count > 0) presence.ControllingClient.SendSetFollowCamProperties(objectID, parameters);
  12074. }
  12075. public void llClearCameraParams()
  12076. {
  12077. m_host.AddScriptLPS(1);
  12078. // the object we are in
  12079. UUID objectID = m_host.ParentUUID;
  12080. if (objectID == UUID.Zero)
  12081. return;
  12082. // we need the permission first, to know which avatar we want to clear the camera for
  12083. UUID agentID = m_item.PermsGranter;
  12084. if (agentID == UUID.Zero)
  12085. return;
  12086. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  12087. return;
  12088. ScenePresence presence = World.GetScenePresence(agentID);
  12089. // we are not interested in child-agents
  12090. if (presence.IsChildAgent)
  12091. return;
  12092. presence.ControllingClient.SendClearFollowCamProperties(objectID);
  12093. }
  12094. public LSL_Float llListStatistics(int operation, LSL_List src)
  12095. {
  12096. m_host.AddScriptLPS(1);
  12097. switch (operation)
  12098. {
  12099. case ScriptBaseClass.LIST_STAT_RANGE:
  12100. return src.Range();
  12101. case ScriptBaseClass.LIST_STAT_MIN:
  12102. return src.Min();
  12103. case ScriptBaseClass.LIST_STAT_MAX:
  12104. return src.Max();
  12105. case ScriptBaseClass.LIST_STAT_MEAN:
  12106. return src.Mean();
  12107. case ScriptBaseClass.LIST_STAT_MEDIAN:
  12108. return LSL_List.ToDoubleList(src).Median();
  12109. case ScriptBaseClass.LIST_STAT_NUM_COUNT:
  12110. return src.NumericLength();
  12111. case ScriptBaseClass.LIST_STAT_STD_DEV:
  12112. return src.StdDev();
  12113. case ScriptBaseClass.LIST_STAT_SUM:
  12114. return src.Sum();
  12115. case ScriptBaseClass.LIST_STAT_SUM_SQUARES:
  12116. return src.SumSqrs();
  12117. case ScriptBaseClass.LIST_STAT_GEOMETRIC_MEAN:
  12118. return src.GeometricMean();
  12119. case ScriptBaseClass.LIST_STAT_HARMONIC_MEAN:
  12120. return src.HarmonicMean();
  12121. default:
  12122. return 0.0;
  12123. }
  12124. }
  12125. public LSL_Integer llGetUnixTime()
  12126. {
  12127. m_host.AddScriptLPS(1);
  12128. return Util.UnixTimeSinceEpoch();
  12129. }
  12130. public LSL_Integer llGetParcelFlags(LSL_Vector pos)
  12131. {
  12132. m_host.AddScriptLPS(1);
  12133. return (int)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y).LandData.Flags;
  12134. }
  12135. public LSL_Integer llGetRegionFlags()
  12136. {
  12137. m_host.AddScriptLPS(1);
  12138. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  12139. if (estate == null)
  12140. return 67108864;
  12141. return (int)estate.GetRegionFlags();
  12142. }
  12143. private const string b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  12144. public LSL_String llXorBase64Strings(string str1, string str2)
  12145. {
  12146. int padding = 0;
  12147. ScriptSleep(300);
  12148. m_host.AddScriptLPS(1);
  12149. if (str1 == string.Empty)
  12150. return string.Empty;
  12151. if (str2 == string.Empty)
  12152. return str1;
  12153. int len = str2.Length;
  12154. if ((len % 4) != 0) // LL is EVIL!!!!
  12155. {
  12156. while (str2.EndsWith("="))
  12157. str2 = str2.Substring(0, str2.Length - 1);
  12158. len = str2.Length;
  12159. int mod = len % 4;
  12160. if (mod == 1)
  12161. str2 = str2.Substring(0, str2.Length - 1);
  12162. else if (mod == 2)
  12163. str2 += "==";
  12164. else if (mod == 3)
  12165. str2 += "=";
  12166. }
  12167. byte[] data1;
  12168. byte[] data2;
  12169. try
  12170. {
  12171. data1 = Convert.FromBase64String(str1);
  12172. data2 = Convert.FromBase64String(str2);
  12173. }
  12174. catch
  12175. {
  12176. return string.Empty;
  12177. }
  12178. // Remove padding
  12179. while (str1.EndsWith("="))
  12180. {
  12181. str1 = str1.Substring(0, str1.Length - 1);
  12182. padding++;
  12183. }
  12184. while (str2.EndsWith("="))
  12185. str2 = str2.Substring(0, str2.Length - 1);
  12186. byte[] d1 = new byte[str1.Length];
  12187. byte[] d2 = new byte[str2.Length];
  12188. for (int i = 0; i < str1.Length; i++)
  12189. {
  12190. int idx = b64.IndexOf(str1.Substring(i, 1));
  12191. if (idx == -1)
  12192. idx = 0;
  12193. d1[i] = (byte)idx;
  12194. }
  12195. for (int i = 0; i < str2.Length; i++)
  12196. {
  12197. int idx = b64.IndexOf(str2.Substring(i, 1));
  12198. if (idx == -1)
  12199. idx = 0;
  12200. d2[i] = (byte)idx;
  12201. }
  12202. string output = string.Empty;
  12203. for (int pos = 0; pos < d1.Length; pos++)
  12204. output += b64[d1[pos] ^ d2[pos % d2.Length]];
  12205. // Here's a funny thing: LL blithely violate the base64
  12206. // standard pretty much everywhere. Here, padding is
  12207. // added only if the first input string had it, rather
  12208. // than when the data actually needs it. This can result
  12209. // in invalid base64 being returned. Go figure.
  12210. while (padding-- > 0)
  12211. output += "=";
  12212. return output;
  12213. }
  12214. public LSL_String llXorBase64StringsCorrect(string str1, string str2)
  12215. {
  12216. m_host.AddScriptLPS(1);
  12217. if (str1 == string.Empty)
  12218. return string.Empty;
  12219. if (str2 == string.Empty)
  12220. return str1;
  12221. int len = str2.Length;
  12222. if ((len % 4) != 0) // LL is EVIL!!!!
  12223. {
  12224. str2.TrimEnd(new char[] { '=' });
  12225. len = str2.Length;
  12226. if(len == 0)
  12227. return str1;
  12228. int mod = len % 4;
  12229. if (mod == 1)
  12230. str2 = str2.Substring(0, len - 1);
  12231. else if (mod == 2)
  12232. str2 += "==";
  12233. else if (mod == 3)
  12234. str2 += "=";
  12235. }
  12236. byte[] data1;
  12237. byte[] data2;
  12238. try
  12239. {
  12240. data1 = Convert.FromBase64String(str1);
  12241. data2 = Convert.FromBase64String(str2);
  12242. }
  12243. catch (Exception)
  12244. {
  12245. return string.Empty;
  12246. }
  12247. int len2 = data2.Length;
  12248. if (len2 == 0)
  12249. return str1;
  12250. for (int pos = 0, pos2 = 0; pos < data1.Length; pos++)
  12251. {
  12252. data1[pos] ^= data2[pos2];
  12253. if (++pos2 >= len2)
  12254. pos2 = 0;
  12255. }
  12256. return Convert.ToBase64String(data1);
  12257. }
  12258. private string truncateBase64(string input)
  12259. {
  12260. if (string.IsNullOrEmpty(input))
  12261. return string.Empty;
  12262. int paddingPos = -1;
  12263. for (int i = 0; i < input.Length; i++)
  12264. {
  12265. char c = input[i];
  12266. if (c >= 'A' && c <= 'Z')
  12267. continue;
  12268. if (c >= 'a' && c <= 'z')
  12269. continue;
  12270. if (c >= '0' && c <= '9')
  12271. continue;
  12272. if (c == '+' || c == '/')
  12273. continue;
  12274. paddingPos = i;
  12275. break;
  12276. }
  12277. if (paddingPos == 0)
  12278. return string.Empty;
  12279. if (paddingPos > 0)
  12280. input = input.Substring(0, paddingPos);
  12281. int remainder = input.Length % 4;
  12282. switch(remainder)
  12283. {
  12284. case 0:
  12285. return input;
  12286. case 1:
  12287. return input.Substring(0, input.Length - 1);
  12288. case 2:
  12289. return input + "==";
  12290. }
  12291. return input + "=";
  12292. }
  12293. public LSL_String llXorBase64(string str1, string str2)
  12294. {
  12295. m_host.AddScriptLPS(1);
  12296. if (string.IsNullOrEmpty(str2))
  12297. return str1;
  12298. str1 = truncateBase64(str1);
  12299. if (string.IsNullOrEmpty(str1))
  12300. return string.Empty;
  12301. str2 = truncateBase64(str2);
  12302. if (string.IsNullOrEmpty(str2))
  12303. return str1;
  12304. byte[] data1;
  12305. byte[] data2;
  12306. try
  12307. {
  12308. data1 = Convert.FromBase64String(str1);
  12309. data2 = Convert.FromBase64String(str2);
  12310. }
  12311. catch (Exception)
  12312. {
  12313. return string.Empty;
  12314. }
  12315. int len2 = data2.Length;
  12316. if (len2 == 0)
  12317. return str1;
  12318. for (int pos = 0, pos2 = 0; pos < data1.Length; pos++)
  12319. {
  12320. data1[pos] ^= data2[pos2];
  12321. if (++pos2 >= len2)
  12322. pos2 = 0;
  12323. }
  12324. return Convert.ToBase64String(data1);
  12325. }
  12326. public LSL_Key llHTTPRequest(string url, LSL_List parameters, string body)
  12327. {
  12328. m_host.AddScriptLPS(1);
  12329. IHttpRequestModule httpScriptMod = m_ScriptEngine.World.RequestModuleInterface<IHttpRequestModule>();
  12330. if(httpScriptMod == null)
  12331. return string.Empty;
  12332. if(!httpScriptMod.CheckThrottle(m_host.LocalId, m_host.OwnerID))
  12333. return ScriptBaseClass.NULL_KEY;
  12334. try
  12335. {
  12336. Uri m_checkuri = new Uri(url);
  12337. if (m_checkuri.Scheme != Uri.UriSchemeHttp && m_checkuri.Scheme != Uri.UriSchemeHttps)
  12338. {
  12339. Error("llHTTPRequest", "Invalid url schema");
  12340. ScriptSleep(200);
  12341. return string.Empty;
  12342. }
  12343. }
  12344. catch
  12345. {
  12346. Error("llHTTPRequest", "Invalid url");
  12347. ScriptSleep(200);
  12348. return string.Empty;
  12349. }
  12350. List<string> param = new List<string>();
  12351. bool ok;
  12352. int nCustomHeaders = 0;
  12353. for (int i = 0; i < parameters.Data.Length; i += 2)
  12354. {
  12355. ok = Int32.TryParse(parameters.Data[i].ToString(), out int flag);
  12356. if (!ok || flag < 0 ||
  12357. flag > (int)HttpRequestConstants.HTTP_PRAGMA_NO_CACHE)
  12358. {
  12359. Error("llHTTPRequest", "Parameter " + i.ToString() + " is an invalid flag");
  12360. }
  12361. param.Add(parameters.Data[i].ToString()); //Add parameter flag
  12362. if (flag != (int)HttpRequestConstants.HTTP_CUSTOM_HEADER)
  12363. {
  12364. param.Add(parameters.Data[i+1].ToString()); //Add parameter value
  12365. }
  12366. else
  12367. {
  12368. //Parameters are in pairs and custom header takes
  12369. //arguments in pairs so adjust for header marker.
  12370. ++i;
  12371. //Maximum of 8 headers are allowed based on the
  12372. //Second Life documentation for llHTTPRequest.
  12373. for (int count = 1; count <= 8; ++count)
  12374. {
  12375. if(nCustomHeaders >= 8)
  12376. {
  12377. Error("llHTTPRequest", "Max number of custom headers is 8, excess ignored");
  12378. break;
  12379. }
  12380. //Enough parameters remaining for (another) header?
  12381. if (parameters.Data.Length - i < 2)
  12382. {
  12383. //There must be at least one name/value pair for custom header
  12384. if (count == 1)
  12385. Error("llHTTPRequest", "Missing name/value for custom header at parameter " + i.ToString());
  12386. break;
  12387. }
  12388. if (HttpStandardHeaders.Contains(parameters.Data[i].ToString()))
  12389. Error("llHTTPRequest", "Name is invalid as a custom header at parameter " + i.ToString());
  12390. param.Add(parameters.Data[i].ToString());
  12391. param.Add(parameters.Data[i+1].ToString());
  12392. nCustomHeaders++;
  12393. //Have we reached the end of the list of headers?
  12394. //End is marked by a string with a single digit.
  12395. if (i + 2 >= parameters.Data.Length ||
  12396. Char.IsDigit(parameters.Data[i + 2].ToString()[0]))
  12397. {
  12398. break;
  12399. }
  12400. i += 2;
  12401. }
  12402. }
  12403. }
  12404. Vector3 position = m_host.AbsolutePosition;
  12405. Vector3 velocity = m_host.Velocity;
  12406. Quaternion rotation = m_host.GetWorldRotation();
  12407. string ownerName = string.Empty;
  12408. ScenePresence scenePresence = World.GetScenePresence(m_host.OwnerID);
  12409. if (scenePresence == null)
  12410. ownerName = resolveName(m_host.OwnerID);
  12411. else
  12412. ownerName = scenePresence.Name;
  12413. RegionInfo regionInfo = World.RegionInfo;
  12414. Dictionary<string, string> httpHeaders = new Dictionary<string, string>();
  12415. if (!string.IsNullOrWhiteSpace(m_lsl_shard))
  12416. httpHeaders["X-SecondLife-Shard"] = m_lsl_shard;
  12417. httpHeaders["X-SecondLife-Object-Name"] = m_host.Name;
  12418. httpHeaders["X-SecondLife-Object-Key"] = m_host.UUID.ToString();
  12419. httpHeaders["X-SecondLife-Region"] = string.Format("{0} ({1}, {2})", regionInfo.RegionName, regionInfo.WorldLocX, regionInfo.WorldLocY);
  12420. httpHeaders["X-SecondLife-Local-Position"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", position.X, position.Y, position.Z);
  12421. httpHeaders["X-SecondLife-Local-Velocity"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", velocity.X, velocity.Y, velocity.Z);
  12422. 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);
  12423. httpHeaders["X-SecondLife-Owner-Name"] = ownerName;
  12424. httpHeaders["X-SecondLife-Owner-Key"] = m_host.OwnerID.ToString();
  12425. if (!string.IsNullOrWhiteSpace(m_lsl_user_agent))
  12426. httpHeaders["User-Agent"] = m_lsl_user_agent;
  12427. // See if the URL contains any header hacks
  12428. string[] urlParts = url.Split(new char[] {'\n'});
  12429. if (urlParts.Length > 1)
  12430. {
  12431. // Iterate the passed headers and parse them
  12432. for (int i = 1 ; i < urlParts.Length ; i++ )
  12433. {
  12434. // The rest of those would be added to the body in SL.
  12435. // Let's not do that.
  12436. if (urlParts[i] == string.Empty)
  12437. break;
  12438. // See if this could be a valid header
  12439. string[] headerParts = urlParts[i].Split(new char[] {':'}, 2);
  12440. if (headerParts.Length != 2)
  12441. continue;
  12442. string headerName = headerParts[0].Trim();
  12443. if(!HttpForbiddenInHeaders.Contains(headerName))
  12444. {
  12445. string headerValue = headerParts[1].Trim();
  12446. httpHeaders[headerName] = headerValue;
  12447. }
  12448. }
  12449. // Finally, strip any protocol specifier from the URL
  12450. url = urlParts[0].Trim();
  12451. int idx = url.IndexOf(" HTTP/");
  12452. if (idx != -1)
  12453. url = url.Substring(0, idx);
  12454. }
  12455. string authregex = @"^(https?:\/\/)(\w+):(\w+)@(.*)$";
  12456. Regex r = new Regex(authregex);
  12457. int[] gnums = r.GetGroupNumbers();
  12458. Match m = r.Match(url);
  12459. if (m.Success)
  12460. {
  12461. for (int i = 1; i < gnums.Length; i++)
  12462. {
  12463. //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
  12464. //CaptureCollection cc = g.Captures;
  12465. }
  12466. if (m.Groups.Count == 5)
  12467. {
  12468. httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString())));
  12469. url = m.Groups[1].ToString() + m.Groups[4].ToString();
  12470. }
  12471. }
  12472. UUID reqID = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body,
  12473. out HttpInitialRequestStatus status);
  12474. if (status == HttpInitialRequestStatus.DISALLOWED_BY_FILTER)
  12475. Error("llHttpRequest", string.Format("Request to {0} disallowed by filter", url));
  12476. if (reqID != UUID.Zero)
  12477. return reqID.ToString();
  12478. else
  12479. return "";
  12480. }
  12481. public void llHTTPResponse(LSL_Key id, int status, string body)
  12482. {
  12483. // Partial implementation: support for parameter flags needed
  12484. // see http://wiki.secondlife.com/wiki/llHTTPResponse
  12485. m_host.AddScriptLPS(1);
  12486. if (m_UrlModule != null)
  12487. m_UrlModule.HttpResponse(new UUID(id), status,body);
  12488. }
  12489. public void llResetLandBanList()
  12490. {
  12491. m_host.AddScriptLPS(1);
  12492. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData;
  12493. if (land.OwnerID == m_host.OwnerID && land.ParcelAccessList.Count > 0)
  12494. {
  12495. var todelete = new List<LandAccessEntry>();
  12496. foreach (LandAccessEntry entry in land.ParcelAccessList)
  12497. {
  12498. if (entry.Flags == AccessList.Ban)
  12499. todelete.Add(entry);
  12500. }
  12501. foreach (LandAccessEntry entry in todelete)
  12502. land.ParcelAccessList.Remove(entry);
  12503. }
  12504. ScriptSleep(m_sleepMsOnResetLandBanList);
  12505. }
  12506. public void llResetLandPassList()
  12507. {
  12508. m_host.AddScriptLPS(1);
  12509. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData;
  12510. if (land.OwnerID == m_host.OwnerID && land.ParcelAccessList.Count > 0)
  12511. {
  12512. var todelete = new List<LandAccessEntry>();
  12513. foreach (LandAccessEntry entry in land.ParcelAccessList)
  12514. {
  12515. if (entry.Flags == AccessList.Access)
  12516. todelete.Add(entry);
  12517. }
  12518. foreach (LandAccessEntry entry in todelete)
  12519. land.ParcelAccessList.Remove(entry);
  12520. }
  12521. ScriptSleep(m_sleepMsOnResetLandPassList);
  12522. }
  12523. public LSL_Integer llGetParcelPrimCount(LSL_Vector pos, int category, int sim_wide)
  12524. {
  12525. m_host.AddScriptLPS(1);
  12526. ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  12527. if (lo == null)
  12528. return 0;
  12529. IPrimCounts pc = lo.PrimCounts;
  12530. if (sim_wide != ScriptBaseClass.FALSE)
  12531. {
  12532. if (category == ScriptBaseClass.PARCEL_COUNT_TOTAL)
  12533. {
  12534. return pc.Simulator;
  12535. }
  12536. else
  12537. {
  12538. // counts not implemented yet
  12539. return 0;
  12540. }
  12541. }
  12542. else
  12543. {
  12544. if (category == ScriptBaseClass.PARCEL_COUNT_TOTAL)
  12545. return pc.Total;
  12546. else if (category == ScriptBaseClass.PARCEL_COUNT_OWNER)
  12547. return pc.Owner;
  12548. else if (category == ScriptBaseClass.PARCEL_COUNT_GROUP)
  12549. return pc.Group;
  12550. else if (category == ScriptBaseClass.PARCEL_COUNT_OTHER)
  12551. return pc.Others;
  12552. else if (category == ScriptBaseClass.PARCEL_COUNT_SELECTED)
  12553. return pc.Selected;
  12554. else if (category == ScriptBaseClass.PARCEL_COUNT_TEMP)
  12555. return 0; // counts not implemented yet
  12556. }
  12557. return 0;
  12558. }
  12559. public LSL_List llGetParcelPrimOwners(LSL_Vector pos)
  12560. {
  12561. m_host.AddScriptLPS(1);
  12562. LandObject land = (LandObject)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  12563. LSL_List ret = new LSL_List();
  12564. if (land != null)
  12565. {
  12566. foreach (KeyValuePair<UUID, int> detectedParams in land.GetLandObjectOwners())
  12567. {
  12568. ret.Add(new LSL_String(detectedParams.Key.ToString()));
  12569. ret.Add(new LSL_Integer(detectedParams.Value));
  12570. }
  12571. }
  12572. ScriptSleep(m_sleepMsOnGetParcelPrimOwners);
  12573. return ret;
  12574. }
  12575. public LSL_Integer llGetObjectPrimCount(LSL_Key object_id)
  12576. {
  12577. m_host.AddScriptLPS(1);
  12578. if(!UUID.TryParse(object_id, out UUID id))
  12579. return 0;
  12580. SceneObjectPart part = World.GetSceneObjectPart(id);
  12581. if (part == null)
  12582. return 0;
  12583. return part.ParentGroup.PrimCount;
  12584. }
  12585. public LSL_Integer llGetParcelMaxPrims(LSL_Vector pos, int sim_wide)
  12586. {
  12587. m_host.AddScriptLPS(1);
  12588. ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  12589. if (lo == null)
  12590. return 0;
  12591. if (sim_wide != 0)
  12592. return lo.GetSimulatorMaxPrimCount();
  12593. else
  12594. return lo.GetParcelMaxPrimCount();
  12595. }
  12596. public LSL_List llGetParcelDetails(LSL_Vector pos, LSL_List param)
  12597. {
  12598. m_host.AddScriptLPS(1);
  12599. LandData land = World.GetLandData(pos);
  12600. if (land == null)
  12601. {
  12602. return new LSL_List(0);
  12603. }
  12604. LSL_List ret = new LSL_List();
  12605. foreach (object o in param.Data)
  12606. {
  12607. switch (o.ToString())
  12608. {
  12609. case "0":
  12610. ret.Add(new LSL_String(land.Name));
  12611. break;
  12612. case "1":
  12613. ret.Add(new LSL_String(land.Description));
  12614. break;
  12615. case "2":
  12616. ret.Add(new LSL_Key(land.OwnerID.ToString()));
  12617. break;
  12618. case "3":
  12619. ret.Add(new LSL_Key(land.GroupID.ToString()));
  12620. break;
  12621. case "4":
  12622. ret.Add(new LSL_Integer(land.Area));
  12623. break;
  12624. case "5":
  12625. ret.Add(new LSL_Key(land.GlobalID.ToString()));
  12626. break;
  12627. case "64":
  12628. ret.Add(new LSL_Integer(land.Dwell));
  12629. break;
  12630. default:
  12631. ret.Add(new LSL_Integer(0));
  12632. break;
  12633. }
  12634. }
  12635. return ret;
  12636. }
  12637. public LSL_String llStringTrim(LSL_String src, LSL_Integer type)
  12638. {
  12639. m_host.AddScriptLPS(1);
  12640. if (type == (int)ScriptBaseClass.STRING_TRIM_HEAD) { return ((string)src).TrimStart(); }
  12641. if (type == (int)ScriptBaseClass.STRING_TRIM_TAIL) { return ((string)src).TrimEnd(); }
  12642. if (type == (int)ScriptBaseClass.STRING_TRIM) { return ((string)src).Trim(); }
  12643. return src;
  12644. }
  12645. public LSL_List llGetObjectDetails(LSL_Key id, LSL_List args)
  12646. {
  12647. m_host.AddScriptLPS(1);
  12648. LSL_List ret = new LSL_List();
  12649. UUID key = new UUID();
  12650. if (!UUID.TryParse(id, out key))
  12651. return ret;
  12652. int count = 0;
  12653. ScenePresence av = World.GetScenePresence(key);
  12654. if (av != null)
  12655. {
  12656. List<SceneObjectGroup> Attachments = null;
  12657. int? nAnimated = null;
  12658. foreach (object o in args.Data)
  12659. {
  12660. switch (int.Parse(o.ToString()))
  12661. {
  12662. case ScriptBaseClass.OBJECT_NAME:
  12663. ret.Add(new LSL_String(av.Firstname + " " + av.Lastname));
  12664. break;
  12665. case ScriptBaseClass.OBJECT_DESC:
  12666. ret.Add(new LSL_String(""));
  12667. break;
  12668. case ScriptBaseClass.OBJECT_POS:
  12669. Vector3 avpos;
  12670. if (av.ParentID != 0 && av.ParentPart != null &&
  12671. av.ParentPart.ParentGroup != null && av.ParentPart.ParentGroup.RootPart != null )
  12672. {
  12673. avpos = av.OffsetPosition;
  12674. if(!av.LegacySitOffsets)
  12675. {
  12676. Vector3 sitOffset = (Zrot(av.Rotation)) * (av.Appearance.AvatarHeight * 0.02638f *2.0f);
  12677. avpos -= sitOffset;
  12678. }
  12679. SceneObjectPart sitRoot = av.ParentPart.ParentGroup.RootPart;
  12680. avpos = sitRoot.GetWorldPosition() + avpos * sitRoot.GetWorldRotation();
  12681. }
  12682. else
  12683. avpos = av.AbsolutePosition;
  12684. ret.Add(new LSL_Vector((double)avpos.X, (double)avpos.Y, (double)avpos.Z));
  12685. break;
  12686. case ScriptBaseClass.OBJECT_ROT:
  12687. Quaternion avrot = av.GetWorldRotation();
  12688. ret.Add(new LSL_Rotation(avrot));
  12689. break;
  12690. case ScriptBaseClass.OBJECT_VELOCITY:
  12691. Vector3 avvel = av.GetWorldVelocity();
  12692. ret.Add(new LSL_Vector((double)avvel.X, (double)avvel.Y, (double)avvel.Z));
  12693. break;
  12694. case ScriptBaseClass.OBJECT_OWNER:
  12695. ret.Add(new LSL_Key((string)id));
  12696. break;
  12697. case ScriptBaseClass.OBJECT_GROUP:
  12698. ret.Add(new LSL_String(ScriptBaseClass.NULL_KEY));
  12699. break;
  12700. case ScriptBaseClass.OBJECT_CREATOR:
  12701. ret.Add(new LSL_Key(ScriptBaseClass.NULL_KEY));
  12702. break;
  12703. // For the following 8 see the Object version below
  12704. case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
  12705. ret.Add(new LSL_Integer(av.RunningScriptCount()));
  12706. break;
  12707. case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
  12708. ret.Add(new LSL_Integer(av.ScriptCount()));
  12709. break;
  12710. case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
  12711. ret.Add(new LSL_Integer(av.RunningScriptCount() * 16384));
  12712. break;
  12713. case ScriptBaseClass.OBJECT_SCRIPT_TIME:
  12714. ret.Add(new LSL_Float(av.ScriptExecutionTime() / 1000.0f));
  12715. break;
  12716. case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
  12717. ret.Add(new LSL_Integer(1));
  12718. break;
  12719. case ScriptBaseClass.OBJECT_SERVER_COST:
  12720. ret.Add(new LSL_Float(0));
  12721. break;
  12722. case ScriptBaseClass.OBJECT_STREAMING_COST:
  12723. ret.Add(new LSL_Float(0));
  12724. break;
  12725. case ScriptBaseClass.OBJECT_PHYSICS_COST:
  12726. ret.Add(new LSL_Float(0));
  12727. break;
  12728. case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
  12729. ret.Add(new LSL_Float(0));
  12730. break;
  12731. case ScriptBaseClass.OBJECT_ROOT:
  12732. SceneObjectPart p = av.ParentPart;
  12733. if (p != null)
  12734. {
  12735. ret.Add(new LSL_String(p.ParentGroup.RootPart.UUID.ToString()));
  12736. }
  12737. else
  12738. {
  12739. ret.Add(new LSL_Key((string)id));
  12740. }
  12741. break;
  12742. case ScriptBaseClass.OBJECT_ATTACHED_POINT:
  12743. ret.Add(new LSL_Integer(0));
  12744. break;
  12745. case ScriptBaseClass.OBJECT_PATHFINDING_TYPE: // Pathfinding
  12746. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_AVATAR));
  12747. break;
  12748. case ScriptBaseClass.OBJECT_PHYSICS:
  12749. ret.Add(new LSL_Integer(0));
  12750. break;
  12751. case ScriptBaseClass.OBJECT_PHANTOM:
  12752. ret.Add(new LSL_Integer(0));
  12753. break;
  12754. case ScriptBaseClass.OBJECT_TEMP_ON_REZ:
  12755. ret.Add(new LSL_Integer(0));
  12756. break;
  12757. case ScriptBaseClass.OBJECT_RENDER_WEIGHT:
  12758. ret.Add(new LSL_Integer(-1));
  12759. break;
  12760. case ScriptBaseClass.OBJECT_HOVER_HEIGHT:
  12761. ret.Add(new LSL_Float(0));
  12762. break;
  12763. case ScriptBaseClass.OBJECT_BODY_SHAPE_TYPE:
  12764. LSL_Float shapeType;
  12765. if (av.Appearance.VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MALE] != 0)
  12766. shapeType = new LSL_Float(1);
  12767. else
  12768. shapeType = new LSL_Float(0);
  12769. ret.Add(shapeType);
  12770. break;
  12771. case ScriptBaseClass.OBJECT_LAST_OWNER_ID:
  12772. ret.Add(new LSL_Key(ScriptBaseClass.NULL_KEY));
  12773. break;
  12774. case ScriptBaseClass.OBJECT_CLICK_ACTION:
  12775. ret.Add(new LSL_Integer(0));
  12776. break;
  12777. case ScriptBaseClass.OBJECT_OMEGA:
  12778. ret.Add(new LSL_Vector(Vector3.Zero));
  12779. break;
  12780. case ScriptBaseClass.OBJECT_PRIM_COUNT:
  12781. if (Attachments == null)
  12782. Attachments = av.GetAttachments();
  12783. count = 0;
  12784. try
  12785. {
  12786. foreach (SceneObjectGroup Attachment in Attachments)
  12787. count += Attachment.PrimCount;
  12788. }
  12789. catch { };
  12790. ret.Add(new LSL_Integer(count));
  12791. break;
  12792. case ScriptBaseClass.OBJECT_TOTAL_INVENTORY_COUNT:
  12793. if (Attachments == null)
  12794. Attachments = av.GetAttachments();
  12795. count = 0;
  12796. try
  12797. {
  12798. foreach (SceneObjectGroup Attachment in Attachments)
  12799. {
  12800. SceneObjectPart[] parts = Attachment.Parts;
  12801. for(int i = 0; i < parts.Length; i++)
  12802. count += parts[i].Inventory.Count;
  12803. }
  12804. } catch { };
  12805. ret.Add(new LSL_Integer(count));
  12806. break;
  12807. case ScriptBaseClass.OBJECT_REZZER_KEY:
  12808. ret.Add(new LSL_Key((string)id));
  12809. break;
  12810. case ScriptBaseClass.OBJECT_GROUP_TAG:
  12811. ret.Add(new LSL_String(av.Grouptitle));
  12812. break;
  12813. case ScriptBaseClass.OBJECT_TEMP_ATTACHED:
  12814. ret.Add(new LSL_Integer(0));
  12815. break;
  12816. case ScriptBaseClass.OBJECT_ATTACHED_SLOTS_AVAILABLE:
  12817. ret.Add(new LSL_Integer(Constants.MaxAgentAttachments - av.GetAttachmentsCount()));
  12818. break;
  12819. case ScriptBaseClass.OBJECT_CREATION_TIME:
  12820. ret.Add(new LSL_String(""));
  12821. break;
  12822. case ScriptBaseClass.OBJECT_SELECT_COUNT:
  12823. ret.Add(new LSL_Integer(0));
  12824. break;
  12825. case ScriptBaseClass.OBJECT_SIT_COUNT:
  12826. ret.Add(new LSL_Integer(0));
  12827. break;
  12828. case ScriptBaseClass.OBJECT_ANIMATED_COUNT:
  12829. count = 0;
  12830. if (nAnimated.HasValue)
  12831. count = nAnimated.Value;
  12832. else
  12833. {
  12834. if (Attachments == null)
  12835. Attachments = av.GetAttachments();
  12836. try
  12837. {
  12838. for(int i = 0; i < Attachments.Count;++i)
  12839. {
  12840. if(Attachments[i].RootPart.Shape.MeshFlagEntry)
  12841. ++count;
  12842. }
  12843. }
  12844. catch { };
  12845. nAnimated = count;
  12846. }
  12847. ret.Add(new LSL_Integer(count));
  12848. break;
  12849. case ScriptBaseClass.OBJECT_ANIMATED_SLOTS_AVAILABLE:
  12850. count = 0;
  12851. if (nAnimated.HasValue)
  12852. count = nAnimated.Value;
  12853. else
  12854. {
  12855. if (Attachments == null)
  12856. Attachments = av.GetAttachments();
  12857. count = 0;
  12858. try
  12859. {
  12860. for (int i = 0; i < Attachments.Count; ++i)
  12861. {
  12862. if (Attachments[i].RootPart.Shape.MeshFlagEntry)
  12863. ++count;
  12864. }
  12865. }
  12866. catch { };
  12867. nAnimated = count;
  12868. }
  12869. count = 2 - count; // for now hardcoded max (simulator features, viewers settings, etc)
  12870. if(count < 0)
  12871. count = 0;
  12872. ret.Add(new LSL_Integer(count));
  12873. break;
  12874. default:
  12875. // Invalid or unhandled constant.
  12876. ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
  12877. break;
  12878. }
  12879. }
  12880. return ret;
  12881. }
  12882. SceneObjectPart obj = World.GetSceneObjectPart(key);
  12883. if (obj != null)
  12884. {
  12885. foreach (object o in args.Data)
  12886. {
  12887. switch (int.Parse(o.ToString()))
  12888. {
  12889. case ScriptBaseClass.OBJECT_NAME:
  12890. ret.Add(new LSL_String(obj.Name));
  12891. break;
  12892. case ScriptBaseClass.OBJECT_DESC:
  12893. ret.Add(new LSL_String(obj.Description));
  12894. break;
  12895. case ScriptBaseClass.OBJECT_POS:
  12896. Vector3 opos = obj.AbsolutePosition;
  12897. ret.Add(new LSL_Vector(opos.X, opos.Y, opos.Z));
  12898. break;
  12899. case ScriptBaseClass.OBJECT_ROT:
  12900. Quaternion rot = Quaternion.Identity;
  12901. if (obj.ParentGroup.IsAttachment)
  12902. {
  12903. ScenePresence sp = World.GetScenePresence(obj.ParentGroup.AttachedAvatar);
  12904. if (sp != null)
  12905. rot = sp.GetWorldRotation();
  12906. }
  12907. else
  12908. {
  12909. if (obj.ParentGroup.RootPart == obj)
  12910. rot = obj.ParentGroup.GroupRotation;
  12911. else
  12912. rot = obj.GetWorldRotation();
  12913. }
  12914. LSL_Rotation objrot = new LSL_Rotation(rot);
  12915. ret.Add(objrot);
  12916. break;
  12917. case ScriptBaseClass.OBJECT_VELOCITY:
  12918. Vector3 vel = Vector3.Zero;
  12919. if (obj.ParentGroup.IsAttachment)
  12920. {
  12921. ScenePresence sp = World.GetScenePresence(obj.ParentGroup.AttachedAvatar);
  12922. if (sp != null)
  12923. vel = sp.GetWorldVelocity();
  12924. }
  12925. else
  12926. {
  12927. vel = obj.Velocity;
  12928. }
  12929. ret.Add(vel);
  12930. break;
  12931. case ScriptBaseClass.OBJECT_OWNER:
  12932. ret.Add(new LSL_String(obj.OwnerID.ToString()));
  12933. break;
  12934. case ScriptBaseClass.OBJECT_GROUP:
  12935. ret.Add(new LSL_String(obj.GroupID.ToString()));
  12936. break;
  12937. case ScriptBaseClass.OBJECT_CREATOR:
  12938. ret.Add(new LSL_String(obj.CreatorID.ToString()));
  12939. break;
  12940. case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
  12941. ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount()));
  12942. break;
  12943. case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
  12944. ret.Add(new LSL_Integer(obj.ParentGroup.ScriptCount()));
  12945. break;
  12946. case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
  12947. // The value returned in SL for mono scripts is 65536 * number of active scripts
  12948. // and 16384 * number of active scripts for LSO. since llGetFreememory
  12949. // is coded to give the LSO value use it here
  12950. ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount() * 16384));
  12951. break;
  12952. case ScriptBaseClass.OBJECT_SCRIPT_TIME:
  12953. // Average cpu time in seconds per simulator frame expended on all scripts in the object
  12954. ret.Add(new LSL_Float(obj.ParentGroup.ScriptExecutionTime() / 1000.0f));
  12955. break;
  12956. case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
  12957. // according to the SL wiki A prim or linkset will have prim
  12958. // equivalent of the number of prims in a linkset if it does not
  12959. // contain a mesh anywhere in the link set or is not a normal prim
  12960. // The value returned in SL for normal prims is prim count
  12961. ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
  12962. break;
  12963. // costs below may need to be diferent for root parts, need to check
  12964. case ScriptBaseClass.OBJECT_SERVER_COST:
  12965. // The linden calculation is here
  12966. // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
  12967. // The value returned in SL for normal prims looks like the prim count
  12968. ret.Add(new LSL_Float(0));
  12969. break;
  12970. case ScriptBaseClass.OBJECT_STREAMING_COST:
  12971. // The value returned in SL for normal prims is prim count * 0.06
  12972. ret.Add(new LSL_Float(obj.StreamingCost));
  12973. break;
  12974. case ScriptBaseClass.OBJECT_PHYSICS_COST:
  12975. // The value returned in SL for normal prims is prim count
  12976. ret.Add(new LSL_Float(obj.PhysicsCost));
  12977. break;
  12978. case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
  12979. ret.Add(new LSL_Float(0));
  12980. break;
  12981. case ScriptBaseClass.OBJECT_ROOT:
  12982. ret.Add(new LSL_String(obj.ParentGroup.RootPart.UUID.ToString()));
  12983. break;
  12984. case ScriptBaseClass.OBJECT_ATTACHED_POINT:
  12985. ret.Add(new LSL_Integer(obj.ParentGroup.AttachmentPoint));
  12986. break;
  12987. case ScriptBaseClass.OBJECT_PATHFINDING_TYPE:
  12988. byte pcode = obj.Shape.PCode;
  12989. if (obj.ParentGroup.AttachmentPoint != 0
  12990. || pcode == (byte)PCode.Grass
  12991. || pcode == (byte)PCode.Tree
  12992. || pcode == (byte)PCode.NewTree)
  12993. {
  12994. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_OTHER));
  12995. }
  12996. else
  12997. {
  12998. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_LEGACY_LINKSET));
  12999. }
  13000. break;
  13001. case ScriptBaseClass.OBJECT_PHYSICS:
  13002. if (obj.ParentGroup.AttachmentPoint != 0)
  13003. {
  13004. ret.Add(new LSL_Integer(0)); // Always false if attached
  13005. }
  13006. else
  13007. {
  13008. ret.Add(new LSL_Integer(obj.ParentGroup.UsesPhysics ? 1 : 0));
  13009. }
  13010. break;
  13011. case ScriptBaseClass.OBJECT_PHANTOM:
  13012. if (obj.ParentGroup.AttachmentPoint != 0)
  13013. {
  13014. ret.Add(new LSL_Integer(0)); // Always false if attached
  13015. }
  13016. else
  13017. {
  13018. ret.Add(new LSL_Integer(obj.ParentGroup.IsPhantom ? 1 : 0));
  13019. }
  13020. break;
  13021. case ScriptBaseClass.OBJECT_TEMP_ON_REZ:
  13022. ret.Add(new LSL_Integer(obj.ParentGroup.IsTemporary ? 1 : 0));
  13023. break;
  13024. case ScriptBaseClass.OBJECT_RENDER_WEIGHT:
  13025. ret.Add(new LSL_Integer(0));
  13026. break;
  13027. case ScriptBaseClass.OBJECT_HOVER_HEIGHT:
  13028. ret.Add(new LSL_Float(0));
  13029. break;
  13030. case ScriptBaseClass.OBJECT_BODY_SHAPE_TYPE:
  13031. ret.Add(new LSL_Float(-1));
  13032. break;
  13033. case ScriptBaseClass.OBJECT_LAST_OWNER_ID:
  13034. ret.Add(new LSL_Key(obj.ParentGroup.LastOwnerID.ToString()));
  13035. break;
  13036. case ScriptBaseClass.OBJECT_CLICK_ACTION:
  13037. ret.Add(new LSL_Integer(obj.ClickAction));
  13038. break;
  13039. case ScriptBaseClass.OBJECT_OMEGA:
  13040. ret.Add(new LSL_Vector(obj.AngularVelocity));
  13041. break;
  13042. case ScriptBaseClass.OBJECT_PRIM_COUNT:
  13043. ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
  13044. break;
  13045. case ScriptBaseClass.OBJECT_TOTAL_INVENTORY_COUNT:
  13046. SceneObjectPart[] parts = obj.ParentGroup.Parts;
  13047. count = 0;
  13048. for(int i = 0; i < parts.Length; i++)
  13049. count += parts[i].Inventory.Count;
  13050. ret.Add(new LSL_Integer(count));
  13051. break;
  13052. case ScriptBaseClass.OBJECT_REZZER_KEY:
  13053. ret.Add(new LSL_Key(obj.ParentGroup.RezzerID.ToString()));
  13054. break;
  13055. case ScriptBaseClass.OBJECT_GROUP_TAG:
  13056. ret.Add(new LSL_String(String.Empty));
  13057. break;
  13058. case ScriptBaseClass.OBJECT_TEMP_ATTACHED:
  13059. if (obj.ParentGroup.AttachmentPoint != 0 && obj.ParentGroup.FromItemID == UUID.Zero)
  13060. {
  13061. ret.Add(new LSL_Integer(1));
  13062. }
  13063. else
  13064. {
  13065. ret.Add(new LSL_Integer(0));
  13066. }
  13067. break;
  13068. case ScriptBaseClass.OBJECT_ATTACHED_SLOTS_AVAILABLE:
  13069. ret.Add(new LSL_Integer(0));
  13070. break;
  13071. case ScriptBaseClass.OBJECT_CREATION_TIME:
  13072. DateTime date = Util.ToDateTime(m_host.ParentGroup.RootPart.CreationDate);
  13073. ret.Add(new LSL_String(date.ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture)));
  13074. break;
  13075. case ScriptBaseClass.OBJECT_SELECT_COUNT:
  13076. ret.Add(new LSL_Integer(0));
  13077. break;
  13078. case ScriptBaseClass.OBJECT_SIT_COUNT:
  13079. ret.Add(new LSL_Integer(m_host.ParentGroup.GetSittingAvatarsCount()));
  13080. break;
  13081. case ScriptBaseClass.OBJECT_ANIMATED_COUNT:
  13082. if(m_host.ParentGroup.RootPart.Shape.MeshFlagEntry)
  13083. ret.Add(new LSL_Integer(1));
  13084. else
  13085. ret.Add(new LSL_Integer(0));
  13086. break;
  13087. case ScriptBaseClass.OBJECT_ANIMATED_SLOTS_AVAILABLE:
  13088. ret.Add(new LSL_Integer(0));
  13089. break;
  13090. default:
  13091. // Invalid or unhandled constant.
  13092. ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
  13093. break;
  13094. }
  13095. }
  13096. }
  13097. return ret;
  13098. }
  13099. internal UUID GetScriptByName(string name)
  13100. {
  13101. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  13102. if (item == null || item.Type != 10)
  13103. return UUID.Zero;
  13104. return item.ItemID;
  13105. }
  13106. /// <summary>
  13107. /// Reports the script error in the viewer's Script Warning/Error dialog and shouts it on the debug channel.
  13108. /// </summary>
  13109. /// <param name="command">The name of the command that generated the error.</param>
  13110. /// <param name="message">The error message to report to the user.</param>
  13111. internal void Error(string command, string message)
  13112. {
  13113. string text = command + ": " + message;
  13114. if (text.Length > 1023)
  13115. {
  13116. text = text.Substring(0, 1023);
  13117. }
  13118. World.SimChat(Utils.StringToBytes(text), ChatTypeEnum.DebugChannel, ScriptBaseClass.DEBUG_CHANNEL,
  13119. m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  13120. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  13121. if (wComm != null)
  13122. {
  13123. wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, text);
  13124. }
  13125. Sleep(1000);
  13126. }
  13127. /// <summary>
  13128. /// Reports that the command is not implemented as a script error.
  13129. /// </summary>
  13130. /// <param name="command">The name of the command that is not implemented.</param>
  13131. /// <param name="message">Additional information to report to the user. (Optional)</param>
  13132. internal void NotImplemented(string command, string message = "")
  13133. {
  13134. if (throwErrorOnNotImplemented)
  13135. {
  13136. if (message != "")
  13137. {
  13138. message = " - " + message;
  13139. }
  13140. throw new NotImplementedException("Command not implemented: " + command + message);
  13141. }
  13142. else
  13143. {
  13144. string text = "Command not implemented";
  13145. if (message != "")
  13146. {
  13147. text = text + " - " + message;
  13148. }
  13149. Error(command, text);
  13150. }
  13151. }
  13152. /// <summary>
  13153. /// Reports that the command is deprecated as a script error.
  13154. /// </summary>
  13155. /// <param name="command">The name of the command that is deprecated.</param>
  13156. /// <param name="message">Additional information to report to the user. (Optional)</param>
  13157. internal void Deprecated(string command, string message = "")
  13158. {
  13159. string text = "Command deprecated";
  13160. if (message != "")
  13161. {
  13162. text = text + " - " + message;
  13163. }
  13164. Error(command, text);
  13165. }
  13166. public delegate void AssetRequestCallback(UUID assetID, AssetBase asset);
  13167. protected void WithNotecard(UUID assetID, AssetRequestCallback cb)
  13168. {
  13169. World.AssetService.Get(assetID.ToString(), this,
  13170. delegate(string i, object sender, AssetBase a)
  13171. {
  13172. UUID uuid = UUID.Zero;
  13173. UUID.TryParse(i, out uuid);
  13174. cb(uuid, a);
  13175. });
  13176. }
  13177. public LSL_Key llGetNumberOfNotecardLines(string name)
  13178. {
  13179. m_host.AddScriptLPS(1);
  13180. UUID assetID = UUID.Zero;
  13181. if (!UUID.TryParse(name, out assetID))
  13182. {
  13183. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  13184. if (item != null && item.Type == 7)
  13185. assetID = item.AssetID;
  13186. }
  13187. if (assetID == UUID.Zero)
  13188. {
  13189. // => complain loudly, as specified by the LSL docs
  13190. Error("llGetNumberOfNotecardLines", "Can't find notecard '" + name + "'");
  13191. return ScriptBaseClass.NULL_KEY;
  13192. }
  13193. if (NotecardCache.IsCached(assetID))
  13194. {
  13195. string ftid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId, m_item.ItemID, NotecardCache.GetLines(assetID).ToString());
  13196. ScriptSleep(m_sleepMsOnGetNumberOfNotecardLines);
  13197. return ftid;
  13198. }
  13199. Action<string> act = eventID =>
  13200. {
  13201. if (NotecardCache.IsCached(assetID))
  13202. {
  13203. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, NotecardCache.GetLines(assetID).ToString());
  13204. return;
  13205. }
  13206. AssetBase a = World.AssetService.Get(assetID.ToString());
  13207. if (a == null || a.Type != 7)
  13208. {
  13209. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, string.Empty);
  13210. return;
  13211. }
  13212. NotecardCache.Cache(assetID, a.Data);
  13213. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, NotecardCache.GetLines(assetID).ToString());
  13214. };
  13215. UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  13216. ScriptSleep(m_sleepMsOnGetNumberOfNotecardLines);
  13217. return tid.ToString();
  13218. }
  13219. public LSL_Key llGetNotecardLine(string name, int line)
  13220. {
  13221. m_host.AddScriptLPS(1);
  13222. UUID assetID = UUID.Zero;
  13223. if (!UUID.TryParse(name, out assetID))
  13224. {
  13225. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  13226. if (item != null && item.Type == 7)
  13227. assetID = item.AssetID;
  13228. }
  13229. if (assetID == UUID.Zero)
  13230. {
  13231. // => complain loudly, as specified by the LSL docs
  13232. Error("llGetNotecardLine", "Can't find notecard '" + name + "'");
  13233. return ScriptBaseClass.NULL_KEY;
  13234. }
  13235. if (NotecardCache.IsCached(assetID))
  13236. {
  13237. string eid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId, m_item.ItemID,
  13238. NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  13239. ScriptSleep(m_sleepMsOnGetNotecardLine);
  13240. return eid;
  13241. }
  13242. Action<string> act = eventID =>
  13243. {
  13244. if (NotecardCache.IsCached(assetID))
  13245. {
  13246. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  13247. return;
  13248. }
  13249. AssetBase a = World.AssetService.Get(assetID.ToString());
  13250. if (a == null || a.Type != 7)
  13251. {
  13252. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, string.Empty);
  13253. return;
  13254. }
  13255. NotecardCache.Cache(assetID, a.Data);
  13256. m_AsyncCommands.DataserverPlugin.DataserverReply(
  13257. eventID, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  13258. };
  13259. UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  13260. ScriptSleep(m_sleepMsOnGetNotecardLine);
  13261. return tid.ToString();
  13262. }
  13263. public void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules, string originFunc)
  13264. {
  13265. if (!UUID.TryParse(prim, out UUID id))
  13266. return;
  13267. SceneObjectPart obj = World.GetSceneObjectPart(id);
  13268. if (obj == null || obj.OwnerID != m_host.OwnerID)
  13269. return;
  13270. uint rulesParsed = 0;
  13271. LSL_List remaining = SetPrimParams(obj, rules, originFunc, ref rulesParsed);
  13272. while (remaining.Length > 2)
  13273. {
  13274. int linknumber;
  13275. try
  13276. {
  13277. linknumber = remaining.GetLSLIntegerItem(0);
  13278. }
  13279. catch (InvalidCastException)
  13280. {
  13281. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_LINK_TARGET parameter must be integer", rulesParsed));
  13282. return;
  13283. }
  13284. List<ISceneEntity> entities = GetLinkEntities(obj, linknumber);
  13285. if (entities.Count == 0)
  13286. break;
  13287. rules = remaining.GetSublist(1, -1);
  13288. foreach (ISceneEntity entity in entities)
  13289. {
  13290. if (entity is SceneObjectPart)
  13291. remaining = SetPrimParams((SceneObjectPart)entity, rules, originFunc, ref rulesParsed);
  13292. else
  13293. remaining = SetAgentParams((ScenePresence)entity, rules, originFunc, ref rulesParsed);
  13294. }
  13295. }
  13296. }
  13297. public LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules)
  13298. {
  13299. LSL_List result = new LSL_List();
  13300. if (!UUID.TryParse(prim, out UUID id))
  13301. return result;
  13302. SceneObjectPart obj = World.GetSceneObjectPart(id);
  13303. if (obj == null || obj.OwnerID != m_host.OwnerID)
  13304. return result;
  13305. LSL_List remaining = GetPrimParams(obj, rules, ref result);
  13306. while (remaining.Length > 1)
  13307. {
  13308. int linknumber;
  13309. try
  13310. {
  13311. linknumber = remaining.GetLSLIntegerItem(0);
  13312. }
  13313. catch (InvalidCastException)
  13314. {
  13315. Error("", string.Format("Error PRIM_LINK_TARGET: parameter must be integer"));
  13316. return result;
  13317. }
  13318. List<ISceneEntity> entities = GetLinkEntities(obj, linknumber);
  13319. if (entities.Count == 0)
  13320. break;
  13321. rules = remaining.GetSublist(1, -1);
  13322. foreach (ISceneEntity entity in entities)
  13323. {
  13324. if (entity is SceneObjectPart)
  13325. remaining = GetPrimParams((SceneObjectPart)entity, rules, ref result);
  13326. else
  13327. remaining = GetPrimParams((ScenePresence)entity, rules, ref result);
  13328. }
  13329. }
  13330. return result;
  13331. }
  13332. public void print(string str)
  13333. {
  13334. // yes, this is a real LSL function. See: http://wiki.secondlife.com/wiki/Print
  13335. IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
  13336. if (ossl != null)
  13337. {
  13338. ossl.CheckThreatLevel(ThreatLevel.High, "print");
  13339. m_log.Info("LSL print():" + str);
  13340. }
  13341. }
  13342. public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
  13343. {
  13344. List<SceneObjectPart> parts = GetLinkParts(link);
  13345. if (parts.Count < 1)
  13346. return 0;
  13347. return GetNumberOfSides(parts[0]);
  13348. }
  13349. private string Name2Username(string name)
  13350. {
  13351. string[] parts = name.Split(new char[] {' '});
  13352. if (parts.Length < 2)
  13353. return name.ToLower();
  13354. if (parts[1] == "Resident")
  13355. return parts[0].ToLower();
  13356. return name.Replace(" ", ".").ToLower();
  13357. }
  13358. public LSL_String llGetUsername(LSL_Key id)
  13359. {
  13360. return Name2Username(llKey2Name(id));
  13361. }
  13362. public LSL_Key llRequestUsername(LSL_Key id)
  13363. {
  13364. m_host.AddScriptLPS(1);
  13365. if (!UUID.TryParse(id, out UUID key) || key == UUID.Zero)
  13366. return string.Empty;
  13367. ScenePresence lpresence = World.GetScenePresence(key);
  13368. if (lpresence != null)
  13369. {
  13370. string lname = lpresence.Name;
  13371. string ftid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId,
  13372. m_item.ItemID, Name2Username(lname));
  13373. return ftid;
  13374. }
  13375. Action<string> act = eventID =>
  13376. {
  13377. string name = String.Empty;
  13378. ScenePresence presence = World.GetScenePresence(key);
  13379. if (presence != null)
  13380. {
  13381. name = presence.Name;
  13382. }
  13383. else if (World.TryGetSceneObjectPart(key, out SceneObjectPart sop ) && sop != null)
  13384. {
  13385. name = sop.Name;
  13386. }
  13387. else
  13388. {
  13389. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, key);
  13390. if(account != null)
  13391. {
  13392. name = account.FirstName + " " + account.LastName;
  13393. }
  13394. }
  13395. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, Name2Username(name));
  13396. };
  13397. UUID rq = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  13398. ScriptSleep(m_sleepMsOnRequestAgentData);
  13399. return rq.ToString();
  13400. }
  13401. public LSL_String llGetDisplayName(LSL_Key id)
  13402. {
  13403. m_host.AddScriptLPS(1);
  13404. if (UUID.TryParse(id, out UUID key) && key != UUID.Zero)
  13405. {
  13406. ScenePresence presence = World.GetScenePresence(key);
  13407. if (presence != null)
  13408. {
  13409. return presence.Name;
  13410. }
  13411. }
  13412. return String.Empty;
  13413. }
  13414. public LSL_Key llRequestDisplayName(LSL_Key id)
  13415. {
  13416. m_host.AddScriptLPS(1);
  13417. if (!UUID.TryParse(id, out UUID key) || key == UUID.Zero)
  13418. return string.Empty;
  13419. ScenePresence lpresence = World.GetScenePresence(key);
  13420. if (lpresence != null)
  13421. {
  13422. string lname = lpresence.Name;
  13423. string ftid = m_AsyncCommands.DataserverPlugin.RequestWithImediatePost(m_host.LocalId,
  13424. m_item.ItemID, lname);
  13425. return ftid;
  13426. }
  13427. Action<string> act = eventID =>
  13428. {
  13429. string name = String.Empty;
  13430. ScenePresence presence = World.GetScenePresence(key);
  13431. if (presence != null)
  13432. {
  13433. name = presence.Name;
  13434. }
  13435. else if (World.TryGetSceneObjectPart(key, out SceneObjectPart sop) && sop != null)
  13436. {
  13437. name = sop.Name;
  13438. }
  13439. else
  13440. {
  13441. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, key);
  13442. if (account != null)
  13443. {
  13444. name = account.FirstName + " " + account.LastName;
  13445. }
  13446. }
  13447. m_AsyncCommands.DataserverPlugin.DataserverReply(eventID, name);
  13448. };
  13449. UUID rq = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  13450. return rq.ToString();
  13451. }
  13452. private struct Tri
  13453. {
  13454. public Vector3 p1;
  13455. public Vector3 p2;
  13456. public Vector3 p3;
  13457. }
  13458. private bool InBoundingBox(ScenePresence avatar, Vector3 point)
  13459. {
  13460. float height = avatar.Appearance.AvatarHeight;
  13461. Vector3 b1 = avatar.AbsolutePosition + new Vector3(-0.22f, -0.22f, -height/2);
  13462. Vector3 b2 = avatar.AbsolutePosition + new Vector3(0.22f, 0.22f, height/2);
  13463. if (point.X > b1.X && point.X < b2.X &&
  13464. point.Y > b1.Y && point.Y < b2.Y &&
  13465. point.Z > b1.Z && point.Z < b2.Z)
  13466. return true;
  13467. return false;
  13468. }
  13469. private ContactResult[] AvatarIntersection(Vector3 rayStart, Vector3 rayEnd, bool skipPhys)
  13470. {
  13471. List<ContactResult> contacts = new List<ContactResult>();
  13472. Vector3 ab = rayEnd - rayStart;
  13473. float ablen = ab.Length();
  13474. World.ForEachScenePresence(delegate(ScenePresence sp)
  13475. {
  13476. if(skipPhys && sp.PhysicsActor != null)
  13477. return;
  13478. Vector3 ac = sp.AbsolutePosition - rayStart;
  13479. double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / ablen);
  13480. if (d > 1.5)
  13481. return;
  13482. double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
  13483. if (d2 > 0)
  13484. return;
  13485. double dp = Math.Sqrt(Vector3.Mag(ac) * Vector3.Mag(ac) - d * d);
  13486. Vector3 p = rayStart + Vector3.Divide(Vector3.Multiply(ab, (float)dp), (float)Vector3.Mag(ab));
  13487. if (!InBoundingBox(sp, p))
  13488. return;
  13489. ContactResult result = new ContactResult
  13490. {
  13491. ConsumerID = sp.LocalId,
  13492. Depth = Vector3.Distance(rayStart, p),
  13493. Normal = Vector3.Zero,
  13494. Pos = p
  13495. };
  13496. contacts.Add(result);
  13497. });
  13498. return contacts.ToArray();
  13499. }
  13500. private ContactResult[] ObjectIntersection(Vector3 rayStart, Vector3 rayEnd, bool includePhysical, bool includeNonPhysical, bool includePhantom)
  13501. {
  13502. Ray ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
  13503. List<ContactResult> contacts = new List<ContactResult>();
  13504. Vector3 ab = rayEnd - rayStart;
  13505. World.ForEachSOG(delegate(SceneObjectGroup group)
  13506. {
  13507. if (m_host.ParentGroup == group)
  13508. return;
  13509. if (group.IsAttachment)
  13510. return;
  13511. if (group.RootPart.PhysActor == null)
  13512. {
  13513. if (!includePhantom)
  13514. return;
  13515. }
  13516. else
  13517. {
  13518. if (group.RootPart.PhysActor.IsPhysical)
  13519. {
  13520. if (!includePhysical)
  13521. return;
  13522. }
  13523. else
  13524. {
  13525. if (!includeNonPhysical)
  13526. return;
  13527. }
  13528. }
  13529. // Find the radius ouside of which we don't even need to hit test
  13530. float radius = 0.0f;
  13531. group.GetAxisAlignedBoundingBoxRaw(out float minX, out float maxX, out float minY, out float maxY, out float minZ, out float maxZ);
  13532. if (Math.Abs(minX) > radius)
  13533. radius = Math.Abs(minX);
  13534. if (Math.Abs(minY) > radius)
  13535. radius = Math.Abs(minY);
  13536. if (Math.Abs(minZ) > radius)
  13537. radius = Math.Abs(minZ);
  13538. if (Math.Abs(maxX) > radius)
  13539. radius = Math.Abs(maxX);
  13540. if (Math.Abs(maxY) > radius)
  13541. radius = Math.Abs(maxY);
  13542. if (Math.Abs(maxZ) > radius)
  13543. radius = Math.Abs(maxZ);
  13544. radius = radius*1.413f;
  13545. Vector3 ac = group.AbsolutePosition - rayStart;
  13546. // Vector3 bc = group.AbsolutePosition - rayEnd;
  13547. double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd));
  13548. // Too far off ray, don't bother
  13549. if (d > radius)
  13550. return;
  13551. // Behind ray, drop
  13552. double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
  13553. if (d2 > 0)
  13554. return;
  13555. ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
  13556. EntityIntersection intersection = group.TestIntersection(ray, true, false);
  13557. // Miss.
  13558. if (!intersection.HitTF)
  13559. return;
  13560. Vector3 b1 = group.AbsolutePosition + new Vector3(minX, minY, minZ);
  13561. Vector3 b2 = group.AbsolutePosition + new Vector3(maxX, maxY, maxZ);
  13562. //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);
  13563. if (!(intersection.ipoint.X >= b1.X && intersection.ipoint.X <= b2.X &&
  13564. intersection.ipoint.Y >= b1.Y && intersection.ipoint.Y <= b2.Y &&
  13565. intersection.ipoint.Z >= b1.Z && intersection.ipoint.Z <= b2.Z))
  13566. return;
  13567. ContactResult result = new ContactResult
  13568. {
  13569. ConsumerID = group.LocalId,
  13570. //Depth = intersection.distance;
  13571. Normal = intersection.normal,
  13572. Pos = intersection.ipoint
  13573. };
  13574. result.Depth = Vector3.Mag(rayStart - result.Pos);
  13575. contacts.Add(result);
  13576. });
  13577. return contacts.ToArray();
  13578. }
  13579. private ContactResult? GroundIntersection(Vector3 rayStart, Vector3 rayEnd)
  13580. {
  13581. double[,] heightfield = World.Heightmap.GetDoubles();
  13582. List<ContactResult> contacts = new List<ContactResult>();
  13583. double min = 2048.0;
  13584. double max = 0.0;
  13585. // Find the min and max of the heightfield
  13586. for (int x = 0 ; x < World.Heightmap.Width ; x++)
  13587. {
  13588. for (int y = 0 ; y < World.Heightmap.Height ; y++)
  13589. {
  13590. if (heightfield[x, y] > max)
  13591. max = heightfield[x, y];
  13592. if (heightfield[x, y] < min)
  13593. min = heightfield[x, y];
  13594. }
  13595. }
  13596. // A ray extends past rayEnd, but doesn't go back before
  13597. // rayStart. If the start is above the highest point of the ground
  13598. // and the ray goes up, we can't hit the ground. Ever.
  13599. if (rayStart.Z > max && rayEnd.Z >= rayStart.Z)
  13600. return null;
  13601. // Same for going down
  13602. if (rayStart.Z < min && rayEnd.Z <= rayStart.Z)
  13603. return null;
  13604. List<Tri> trilist = new List<Tri>();
  13605. // Create our triangle list
  13606. for (int x = 1 ; x < World.Heightmap.Width ; x++)
  13607. {
  13608. for (int y = 1 ; y < World.Heightmap.Height ; y++)
  13609. {
  13610. Tri t1 = new Tri();
  13611. Tri t2 = new Tri();
  13612. Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]);
  13613. Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]);
  13614. Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]);
  13615. Vector3 p4 = new Vector3(x-1, y, (float)heightfield[x-1, y]);
  13616. t1.p1 = p1;
  13617. t1.p2 = p2;
  13618. t1.p3 = p3;
  13619. t2.p1 = p3;
  13620. t2.p2 = p4;
  13621. t2.p3 = p1;
  13622. trilist.Add(t1);
  13623. trilist.Add(t2);
  13624. }
  13625. }
  13626. // Ray direction
  13627. Vector3 rayDirection = rayEnd - rayStart;
  13628. foreach (Tri t in trilist)
  13629. {
  13630. // Compute triangle plane normal and edges
  13631. Vector3 u = t.p2 - t.p1;
  13632. Vector3 v = t.p3 - t.p1;
  13633. Vector3 n = Vector3.Cross(u, v);
  13634. if (n == Vector3.Zero)
  13635. continue;
  13636. Vector3 w0 = rayStart - t.p1;
  13637. double a = -Vector3.Dot(n, w0);
  13638. double b = Vector3.Dot(n, rayDirection);
  13639. // Not intersecting the plane, or in plane (same thing)
  13640. // Ignoring this MAY cause the ground to not be detected
  13641. // sometimes
  13642. if (Math.Abs(b) < 0.000001)
  13643. continue;
  13644. double r = a / b;
  13645. // ray points away from plane
  13646. if (r < 0.0)
  13647. continue;
  13648. Vector3 ip = rayStart + Vector3.Multiply(rayDirection, (float)r);
  13649. float uu = Vector3.Dot(u, u);
  13650. float uv = Vector3.Dot(u, v);
  13651. float vv = Vector3.Dot(v, v);
  13652. Vector3 w = ip - t.p1;
  13653. float wu = Vector3.Dot(w, u);
  13654. float wv = Vector3.Dot(w, v);
  13655. float d = uv * uv - uu * vv;
  13656. float cs = (uv * wv - vv * wu) / d;
  13657. if (cs < 0 || cs > 1.0)
  13658. continue;
  13659. float ct = (uv * wu - uu * wv) / d;
  13660. if (ct < 0 || (cs + ct) > 1.0)
  13661. continue;
  13662. // Add contact point
  13663. ContactResult result = new ContactResult
  13664. {
  13665. ConsumerID = 0,
  13666. Depth = Vector3.Distance(rayStart, ip),
  13667. Normal = n,
  13668. Pos = ip
  13669. };
  13670. contacts.Add(result);
  13671. }
  13672. if (contacts.Count == 0)
  13673. return null;
  13674. contacts.Sort(delegate(ContactResult a, ContactResult b)
  13675. {
  13676. return (int)(a.Depth - b.Depth);
  13677. });
  13678. return contacts[0];
  13679. }
  13680. /*
  13681. // not done:
  13682. private ContactResult[] testRay2NonPhysicalPhantom(Vector3 rayStart, Vector3 raydir, float raylenght)
  13683. {
  13684. ContactResult[] contacts = null;
  13685. World.ForEachSOG(delegate(SceneObjectGroup group)
  13686. {
  13687. if (m_host.ParentGroup == group)
  13688. return;
  13689. if (group.IsAttachment)
  13690. return;
  13691. if(group.RootPart.PhysActor != null)
  13692. return;
  13693. contacts = group.RayCastGroupPartsOBBNonPhysicalPhantom(rayStart, raydir, raylenght);
  13694. });
  13695. return contacts;
  13696. }
  13697. */
  13698. public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
  13699. {
  13700. LSL_List list = new LSL_List();
  13701. m_host.AddScriptLPS(1);
  13702. Vector3 rayStart = start;
  13703. Vector3 rayEnd = end;
  13704. Vector3 dir = rayEnd - rayStart;
  13705. float dist = dir.Length();
  13706. int count = 1;
  13707. bool detectPhantom = false;
  13708. int dataFlags = 0;
  13709. int rejectTypes = 0;
  13710. for (int i = 0; i < options.Length; i += 2)
  13711. {
  13712. if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
  13713. count = options.GetLSLIntegerItem(i + 1);
  13714. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
  13715. detectPhantom = (options.GetLSLIntegerItem(i + 1) > 0);
  13716. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
  13717. dataFlags = options.GetLSLIntegerItem(i + 1);
  13718. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
  13719. rejectTypes = options.GetLSLIntegerItem(i + 1);
  13720. }
  13721. if (count > 16)
  13722. count = 16;
  13723. List<ContactResult> results = new List<ContactResult>();
  13724. bool checkTerrain = !((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND);
  13725. bool checkAgents = !((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) == ScriptBaseClass.RC_REJECT_AGENTS);
  13726. bool checkNonPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) == ScriptBaseClass.RC_REJECT_NONPHYSICAL);
  13727. bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL);
  13728. bool rejectHost = ((rejectTypes & ScriptBaseClass.RC_REJECT_HOST) != 0);
  13729. bool rejectHostGroup = ((rejectTypes & ScriptBaseClass.RC_REJECT_HOSTGROUP) != 0);
  13730. if (World.SupportsRayCastFiltered())
  13731. {
  13732. if (dist == 0)
  13733. return list;
  13734. RayFilterFlags rayfilter = RayFilterFlags.BackFaceCull;
  13735. if (checkTerrain)
  13736. rayfilter |= RayFilterFlags.land;
  13737. if (checkAgents)
  13738. rayfilter |= RayFilterFlags.agent;
  13739. if (checkPhysical)
  13740. rayfilter |= RayFilterFlags.physical;
  13741. if (checkNonPhysical)
  13742. rayfilter |= RayFilterFlags.nonphysical;
  13743. if (detectPhantom)
  13744. rayfilter |= RayFilterFlags.LSLPhantom;
  13745. Vector3 direction = dir * ( 1/dist);
  13746. if(rayfilter == 0)
  13747. {
  13748. list.Add(new LSL_Integer(0));
  13749. return list;
  13750. }
  13751. // get some more contacts to sort ???
  13752. int physcount = 4 * count;
  13753. if (physcount > 20)
  13754. physcount = 20;
  13755. object physresults;
  13756. physresults = World.RayCastFiltered(rayStart, direction, dist, physcount, rayfilter);
  13757. if (physresults == null)
  13758. {
  13759. // list.Add(new LSL_Integer(-3)); // timeout error
  13760. // return list;
  13761. results = new List<ContactResult>();
  13762. }
  13763. else
  13764. results = (List<ContactResult>)physresults;
  13765. // for now physics doesn't detect sitted avatars so do it outside physics
  13766. if (checkAgents)
  13767. {
  13768. ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd, true);
  13769. foreach (ContactResult r in agentHits)
  13770. results.Add(r);
  13771. }
  13772. // TODO: Replace this with a better solution. ObjectIntersection can only
  13773. // detect nonphysical phantoms. They are detected by virtue of being
  13774. // nonphysical (e.g. no PhysActor) so will not conflict with detecting
  13775. // physicsl phantoms as done by the physics scene
  13776. // We don't want anything else but phantoms here.
  13777. if (detectPhantom)
  13778. {
  13779. ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, false, false, true);
  13780. foreach (ContactResult r in objectHits)
  13781. results.Add(r);
  13782. }
  13783. // Double check this because of current ODE distance problems
  13784. if (checkTerrain && dist > 60)
  13785. {
  13786. bool skipGroundCheck = false;
  13787. foreach (ContactResult c in results)
  13788. {
  13789. if (c.ConsumerID == 0) // Physics gave us a ground collision
  13790. skipGroundCheck = true;
  13791. }
  13792. if (!skipGroundCheck)
  13793. {
  13794. float tmp = dir.X * dir.X + dir.Y * dir.Y;
  13795. if(tmp > 2500)
  13796. {
  13797. ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
  13798. if (groundContact != null)
  13799. results.Add((ContactResult)groundContact);
  13800. }
  13801. }
  13802. }
  13803. }
  13804. else
  13805. {
  13806. if (checkAgents)
  13807. {
  13808. ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd, false);
  13809. foreach (ContactResult r in agentHits)
  13810. results.Add(r);
  13811. }
  13812. if (checkPhysical || checkNonPhysical || detectPhantom)
  13813. {
  13814. ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, checkPhysical, checkNonPhysical, detectPhantom);
  13815. for (int iter = 0; iter < objectHits.Length; iter++)
  13816. {
  13817. // Redistance the Depth because the Scene RayCaster returns distance from center to make the rezzing code simpler.
  13818. objectHits[iter].Depth = Vector3.Distance(objectHits[iter].Pos, rayStart);
  13819. results.Add(objectHits[iter]);
  13820. }
  13821. }
  13822. if (checkTerrain)
  13823. {
  13824. ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
  13825. if (groundContact != null)
  13826. results.Add((ContactResult)groundContact);
  13827. }
  13828. }
  13829. results.Sort(delegate(ContactResult a, ContactResult b)
  13830. {
  13831. return a.Depth.CompareTo(b.Depth);
  13832. });
  13833. int values = 0;
  13834. SceneObjectGroup thisgrp = m_host.ParentGroup;
  13835. foreach (ContactResult result in results)
  13836. {
  13837. if (result.Depth > dist)
  13838. continue;
  13839. // physics ray can return colisions with host prim
  13840. if (rejectHost && m_host.LocalId == result.ConsumerID)
  13841. continue;
  13842. UUID itemID = UUID.Zero;
  13843. int linkNum = 0;
  13844. SceneObjectPart part = World.GetSceneObjectPart(result.ConsumerID);
  13845. // It's a prim!
  13846. if (part != null)
  13847. {
  13848. if (rejectHostGroup && part.ParentGroup == thisgrp)
  13849. continue;
  13850. if ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) == ScriptBaseClass.RC_GET_ROOT_KEY)
  13851. itemID = part.ParentGroup.UUID;
  13852. else
  13853. itemID = part.UUID;
  13854. linkNum = part.LinkNum;
  13855. }
  13856. else
  13857. {
  13858. ScenePresence sp = World.GetScenePresence(result.ConsumerID);
  13859. /// It it a boy? a girl?
  13860. if (sp != null)
  13861. itemID = sp.UUID;
  13862. }
  13863. list.Add(new LSL_String(itemID.ToString()));
  13864. list.Add(new LSL_String(result.Pos.ToString()));
  13865. if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
  13866. list.Add(new LSL_Integer(linkNum));
  13867. if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
  13868. list.Add(new LSL_Vector(result.Normal));
  13869. values++;
  13870. if (values >= count)
  13871. break;
  13872. }
  13873. list.Add(new LSL_Integer(values));
  13874. return list;
  13875. }
  13876. /// <summary>
  13877. /// Implementation of llCastRay similar to SL 2015-04-21.
  13878. /// http://wiki.secondlife.com/wiki/LlCastRay
  13879. /// Uses pure geometry, bounding shapes, meshing and no physics
  13880. /// for prims, sculpts, meshes, avatars and terrain.
  13881. /// Implements all flags, reject types and data flags.
  13882. /// Can handle both objects/groups and prims/parts, by config.
  13883. /// May sometimes be inaccurate owing to calculation precision,
  13884. /// meshing detail level and a bug in libopenmetaverse PrimMesher.
  13885. /// </summary>
  13886. public LSL_List llCastRayV3(LSL_Vector start, LSL_Vector end, LSL_List options)
  13887. {
  13888. m_host.AddScriptLPS(1);
  13889. LSL_List result = new LSL_List();
  13890. // Prepare throttle data
  13891. int calledMs = Environment.TickCount;
  13892. Stopwatch stopWatch = new Stopwatch();
  13893. stopWatch.Start();
  13894. UUID regionId = World.RegionInfo.RegionID;
  13895. UUID userId = UUID.Zero;
  13896. int msAvailable = 0;
  13897. // Throttle per owner when attachment or "vehicle" (sat upon)
  13898. if (m_host.ParentGroup.IsAttachment || m_host.ParentGroup.GetSittingAvatarsCount() > 0)
  13899. {
  13900. userId = m_host.OwnerID;
  13901. msAvailable = m_msPerAvatarInCastRay;
  13902. }
  13903. // Throttle per parcel when not attachment or vehicle
  13904. else
  13905. {
  13906. LandData land = World.GetLandData(m_host.GetWorldPosition());
  13907. if (land != null)
  13908. msAvailable = m_msPerRegionInCastRay * land.Area / 65536;
  13909. }
  13910. // Clamp for "oversized" parcels on varregions
  13911. if (msAvailable > m_msMaxInCastRay)
  13912. msAvailable = m_msMaxInCastRay;
  13913. // Check throttle data
  13914. int fromCalledMs = calledMs - m_msThrottleInCastRay;
  13915. lock (m_castRayCalls)
  13916. {
  13917. for (int i = m_castRayCalls.Count - 1; i >= 0; i--)
  13918. {
  13919. // Delete old calls from throttle data
  13920. if (m_castRayCalls[i].CalledMs < fromCalledMs)
  13921. m_castRayCalls.RemoveAt(i);
  13922. // Use current region (in multi-region sims)
  13923. else if (m_castRayCalls[i].RegionId == regionId)
  13924. {
  13925. // Reduce available time with recent calls
  13926. if (m_castRayCalls[i].UserId == userId)
  13927. msAvailable -= m_castRayCalls[i].UsedMs;
  13928. }
  13929. }
  13930. // Return failure if not enough available time
  13931. if (msAvailable < m_msMinInCastRay)
  13932. {
  13933. result.Add(new LSL_Integer(ScriptBaseClass.RCERR_CAST_TIME_EXCEEDED));
  13934. return result;
  13935. }
  13936. }
  13937. // Initialize
  13938. List<RayHit> rayHits = new List<RayHit>();
  13939. float tol = m_floatToleranceInCastRay;
  13940. Vector3 pos1Ray = start;
  13941. Vector3 pos2Ray = end;
  13942. // Get input options
  13943. int rejectTypes = 0;
  13944. int dataFlags = 0;
  13945. int maxHits = 1;
  13946. bool notdetectPhantom = true;
  13947. for (int i = 0; i < options.Length; i += 2)
  13948. {
  13949. if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
  13950. rejectTypes = options.GetLSLIntegerItem(i + 1);
  13951. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
  13952. dataFlags = options.GetLSLIntegerItem(i + 1);
  13953. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
  13954. maxHits = options.GetLSLIntegerItem(i + 1);
  13955. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
  13956. notdetectPhantom = (options.GetLSLIntegerItem(i + 1) == 0);
  13957. }
  13958. if (maxHits > m_maxHitsInCastRay)
  13959. maxHits = m_maxHitsInCastRay;
  13960. bool rejectAgents = ((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) != 0);
  13961. bool rejectPhysical = ((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) != 0);
  13962. bool rejectNonphysical = ((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) != 0);
  13963. bool rejectLand = ((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) != 0);
  13964. bool getNormal = ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) != 0);
  13965. bool getRootKey = ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) != 0);
  13966. bool getLinkNum = ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) != 0);
  13967. // Calculate some basic parameters
  13968. Vector3 vecRay = pos2Ray - pos1Ray;
  13969. float rayLength = vecRay.Length();
  13970. // Try to get a mesher and return failure if none, degenerate ray, or max 0 hits
  13971. IRendering primMesher = null;
  13972. List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory());
  13973. if (renderers.Count < 1 || rayLength < tol || m_maxHitsInCastRay < 1)
  13974. {
  13975. result.Add(new LSL_Integer(ScriptBaseClass.RCERR_UNKNOWN));
  13976. return result;
  13977. }
  13978. primMesher = RenderingLoader.LoadRenderer(renderers[0]);
  13979. // Iterate over all objects/groups and prims/parts in region
  13980. World.ForEachSOG(
  13981. delegate(SceneObjectGroup group)
  13982. {
  13983. if(group.IsDeleted || group.RootPart == null)
  13984. return;
  13985. // Check group filters unless part filters are configured
  13986. bool isPhysical = (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical);
  13987. bool isNonphysical = !isPhysical;
  13988. bool isPhantom = group.IsPhantom || group.IsVolumeDetect;
  13989. bool isAttachment = group.IsAttachment;
  13990. if (isPhysical && rejectPhysical)
  13991. return;
  13992. if (isNonphysical && rejectNonphysical)
  13993. return;
  13994. if (isPhantom && notdetectPhantom)
  13995. return;
  13996. if (isAttachment && !m_doAttachmentsInCastRay)
  13997. return;
  13998. // Parse object/group if passed filters
  13999. // Iterate over all prims/parts in object/group
  14000. foreach(SceneObjectPart part in group.Parts)
  14001. {
  14002. // ignore PhysicsShapeType.None as physics engines do
  14003. // or we will get into trouble in future
  14004. if(part.PhysicsShapeType == (byte)PhysicsShapeType.None)
  14005. continue;
  14006. isPhysical = (part.PhysActor != null && part.PhysActor.IsPhysical);
  14007. isNonphysical = !isPhysical;
  14008. isPhantom = ((part.Flags & PrimFlags.Phantom) != 0) ||
  14009. (part.VolumeDetectActive);
  14010. if (isPhysical && rejectPhysical)
  14011. continue;
  14012. if (isNonphysical && rejectNonphysical)
  14013. continue;
  14014. if (isPhantom && notdetectPhantom)
  14015. continue;
  14016. // Parse prim/part and project ray if passed filters
  14017. Vector3 scalePart = part.Scale;
  14018. Vector3 posPart = part.GetWorldPosition();
  14019. Quaternion rotPart = part.GetWorldRotation();
  14020. Quaternion rotPartInv = Quaternion.Inverse(rotPart);
  14021. Vector3 pos1RayProj = ((pos1Ray - posPart) * rotPartInv) / scalePart;
  14022. Vector3 pos2RayProj = ((pos2Ray - posPart) * rotPartInv) / scalePart;
  14023. // Filter parts by shape bounding boxes
  14024. Vector3 shapeBoxMax = new Vector3(0.5f, 0.5f, 0.5f);
  14025. if (!part.Shape.SculptEntry)
  14026. shapeBoxMax = shapeBoxMax * (new Vector3(m_primSafetyCoeffX, m_primSafetyCoeffY, m_primSafetyCoeffZ));
  14027. shapeBoxMax = shapeBoxMax + (new Vector3(tol, tol, tol));
  14028. if (RayIntersectsShapeBox(pos1RayProj, pos2RayProj, shapeBoxMax))
  14029. {
  14030. // Prepare data needed to check for ray hits
  14031. RayTrans rayTrans = new RayTrans
  14032. {
  14033. PartId = part.UUID,
  14034. GroupId = part.ParentGroup.UUID,
  14035. Link = group.PrimCount > 1 ? part.LinkNum : 0,
  14036. ScalePart = scalePart,
  14037. PositionPart = posPart,
  14038. RotationPart = rotPart,
  14039. ShapeNeedsEnds = true,
  14040. Position1Ray = pos1Ray,
  14041. Position1RayProj = pos1RayProj,
  14042. VectorRayProj = pos2RayProj - pos1RayProj
  14043. };
  14044. // Get detail level depending on type
  14045. int lod = 0;
  14046. // Mesh detail level
  14047. if (part.Shape.SculptEntry && part.Shape.SculptType == (byte)SculptType.Mesh)
  14048. lod = (int)m_meshLodInCastRay;
  14049. // Sculpt detail level
  14050. else if (part.Shape.SculptEntry && part.Shape.SculptType == (byte)SculptType.Mesh)
  14051. lod = (int)m_sculptLodInCastRay;
  14052. // Shape detail level
  14053. else if (!part.Shape.SculptEntry)
  14054. lod = (int)m_primLodInCastRay;
  14055. // Try to get cached mesh if configured
  14056. ulong meshKey = 0;
  14057. FacetedMesh mesh = null;
  14058. if (m_useMeshCacheInCastRay)
  14059. {
  14060. meshKey = part.Shape.GetMeshKey(Vector3.One, (float)(4 << lod));
  14061. lock (m_cachedMeshes)
  14062. {
  14063. m_cachedMeshes.TryGetValue(meshKey, out mesh);
  14064. }
  14065. }
  14066. // Create mesh if no cached mesh
  14067. if (mesh == null)
  14068. {
  14069. // Make an OMV prim to be able to mesh part
  14070. Primitive omvPrim = part.Shape.ToOmvPrimitive(posPart, rotPart);
  14071. byte[] sculptAsset = null;
  14072. if (omvPrim.Sculpt != null)
  14073. sculptAsset = World.AssetService.GetData(omvPrim.Sculpt.SculptTexture.ToString());
  14074. // When part is mesh, get mesh
  14075. if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type == SculptType.Mesh && sculptAsset != null)
  14076. {
  14077. AssetMesh meshAsset = new AssetMesh(omvPrim.Sculpt.SculptTexture, sculptAsset);
  14078. FacetedMesh.TryDecodeFromAsset(omvPrim, meshAsset, m_meshLodInCastRay, out mesh);
  14079. meshAsset = null;
  14080. }
  14081. // When part is sculpt, create mesh
  14082. // Quirk: Generated sculpt mesh is about 2.8% smaller in X and Y than visual sculpt.
  14083. else if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type != SculptType.Mesh && sculptAsset != null)
  14084. {
  14085. IJ2KDecoder imgDecoder = World.RequestModuleInterface<IJ2KDecoder>();
  14086. if (imgDecoder != null)
  14087. {
  14088. Image sculpt = imgDecoder.DecodeToImage(sculptAsset);
  14089. if (sculpt != null)
  14090. {
  14091. mesh = primMesher.GenerateFacetedSculptMesh(omvPrim, (Bitmap)sculpt, m_sculptLodInCastRay);
  14092. sculpt.Dispose();
  14093. }
  14094. }
  14095. }
  14096. // When part is shape, create mesh
  14097. else if (omvPrim.Sculpt == null)
  14098. {
  14099. if (
  14100. omvPrim.PrimData.PathBegin == 0.0 && omvPrim.PrimData.PathEnd == 1.0 &&
  14101. omvPrim.PrimData.PathTaperX == 0.0 && omvPrim.PrimData.PathTaperY == 0.0 &&
  14102. omvPrim.PrimData.PathSkew == 0.0 &&
  14103. omvPrim.PrimData.PathTwist - omvPrim.PrimData.PathTwistBegin == 0.0
  14104. )
  14105. rayTrans.ShapeNeedsEnds = false;
  14106. mesh = primMesher.GenerateFacetedMesh(omvPrim, m_primLodInCastRay);
  14107. }
  14108. // Cache mesh if configured
  14109. if (m_useMeshCacheInCastRay && mesh != null)
  14110. {
  14111. lock(m_cachedMeshes)
  14112. {
  14113. if (!m_cachedMeshes.ContainsKey(meshKey))
  14114. m_cachedMeshes.Add(meshKey, mesh);
  14115. }
  14116. }
  14117. }
  14118. // Check mesh for ray hits
  14119. AddRayInFacetedMesh(mesh, rayTrans, ref rayHits);
  14120. mesh = null;
  14121. }
  14122. }
  14123. }
  14124. );
  14125. // Check avatar filter
  14126. if (!rejectAgents)
  14127. {
  14128. // Iterate over all avatars in region
  14129. World.ForEachRootScenePresence(
  14130. delegate (ScenePresence sp)
  14131. {
  14132. // Get bounding box
  14133. BoundingBoxOfScenePresence(sp, out Vector3 lower, out Vector3 upper);
  14134. // Parse avatar
  14135. Vector3 scalePart = upper - lower;
  14136. Vector3 posPart = sp.AbsolutePosition;
  14137. Quaternion rotPart = sp.GetWorldRotation();
  14138. Quaternion rotPartInv = Quaternion.Inverse(rotPart);
  14139. posPart = posPart + (lower + upper) * 0.5f * rotPart;
  14140. // Project ray
  14141. Vector3 pos1RayProj = ((pos1Ray - posPart) * rotPartInv) / scalePart;
  14142. Vector3 pos2RayProj = ((pos2Ray - posPart) * rotPartInv) / scalePart;
  14143. // Filter avatars by shape bounding boxes
  14144. Vector3 shapeBoxMax = new Vector3(0.5f + tol, 0.5f + tol, 0.5f + tol);
  14145. if (RayIntersectsShapeBox(pos1RayProj, pos2RayProj, shapeBoxMax))
  14146. {
  14147. // Prepare data needed to check for ray hits
  14148. RayTrans rayTrans = new RayTrans
  14149. {
  14150. PartId = sp.UUID,
  14151. GroupId = sp.ParentPart != null ? sp.ParentPart.ParentGroup.UUID : sp.UUID,
  14152. Link = sp.ParentPart != null ? UUID2LinkNumber(sp.ParentPart, sp.UUID) : 0,
  14153. ScalePart = scalePart,
  14154. PositionPart = posPart,
  14155. RotationPart = rotPart,
  14156. ShapeNeedsEnds = false,
  14157. Position1Ray = pos1Ray,
  14158. Position1RayProj = pos1RayProj,
  14159. VectorRayProj = pos2RayProj - pos1RayProj
  14160. };
  14161. // Try to get cached mesh if configured
  14162. PrimitiveBaseShape prim = PrimitiveBaseShape.CreateSphere();
  14163. int lod = (int)m_avatarLodInCastRay;
  14164. ulong meshKey = prim.GetMeshKey(Vector3.One, (float)(4 << lod));
  14165. FacetedMesh mesh = null;
  14166. if (m_useMeshCacheInCastRay)
  14167. {
  14168. lock (m_cachedMeshes)
  14169. {
  14170. m_cachedMeshes.TryGetValue(meshKey, out mesh);
  14171. }
  14172. }
  14173. // Create mesh if no cached mesh
  14174. if (mesh == null)
  14175. {
  14176. // Make OMV prim and create mesh
  14177. prim.Scale = scalePart;
  14178. Primitive omvPrim = prim.ToOmvPrimitive(posPart, rotPart);
  14179. mesh = primMesher.GenerateFacetedMesh(omvPrim, m_avatarLodInCastRay);
  14180. // Cache mesh if configured
  14181. if (m_useMeshCacheInCastRay && mesh != null)
  14182. {
  14183. lock(m_cachedMeshes)
  14184. {
  14185. if (!m_cachedMeshes.ContainsKey(meshKey))
  14186. m_cachedMeshes.Add(meshKey, mesh);
  14187. }
  14188. }
  14189. }
  14190. // Check mesh for ray hits
  14191. AddRayInFacetedMesh(mesh, rayTrans, ref rayHits);
  14192. mesh = null;
  14193. }
  14194. }
  14195. );
  14196. }
  14197. // Check terrain filter
  14198. if (!rejectLand)
  14199. {
  14200. // Parse terrain
  14201. // Mesh terrain and check bounding box
  14202. List<Tri> triangles = TrisFromHeightmapUnderRay(pos1Ray, pos2Ray, out Vector3 lower, out Vector3 upper);
  14203. lower.Z -= tol;
  14204. upper.Z += tol;
  14205. if ((pos1Ray.Z >= lower.Z || pos2Ray.Z >= lower.Z) && (pos1Ray.Z <= upper.Z || pos2Ray.Z <= upper.Z))
  14206. {
  14207. // Prepare data needed to check for ray hits
  14208. RayTrans rayTrans = new RayTrans
  14209. {
  14210. PartId = UUID.Zero,
  14211. GroupId = UUID.Zero,
  14212. Link = 0,
  14213. ScalePart = new Vector3(1.0f, 1.0f, 1.0f),
  14214. PositionPart = Vector3.Zero,
  14215. RotationPart = Quaternion.Identity,
  14216. ShapeNeedsEnds = true,
  14217. Position1Ray = pos1Ray,
  14218. Position1RayProj = pos1Ray,
  14219. VectorRayProj = vecRay
  14220. };
  14221. // Check mesh
  14222. AddRayInTris(triangles, rayTrans, ref rayHits);
  14223. triangles = null;
  14224. }
  14225. }
  14226. // Sort hits by ascending distance
  14227. rayHits.Sort((s1, s2) => s1.Distance.CompareTo(s2.Distance));
  14228. // Check excess hits per part and group
  14229. for (int t = 0; t < 2; t++)
  14230. {
  14231. int maxHitsPerType = 0;
  14232. UUID id = UUID.Zero;
  14233. if (t == 0)
  14234. maxHitsPerType = m_maxHitsPerPrimInCastRay;
  14235. else
  14236. maxHitsPerType = m_maxHitsPerObjectInCastRay;
  14237. // Handle excess hits only when needed
  14238. if (maxHitsPerType < m_maxHitsInCastRay)
  14239. {
  14240. // Find excess hits
  14241. Hashtable hits = new Hashtable();
  14242. for (int i = rayHits.Count - 1; i >= 0; i--)
  14243. {
  14244. if (t == 0)
  14245. id = rayHits[i].PartId;
  14246. else
  14247. id = rayHits[i].GroupId;
  14248. if (hits.ContainsKey(id))
  14249. hits[id] = (int)hits[id] + 1;
  14250. else
  14251. hits[id] = 1;
  14252. }
  14253. // Remove excess hits
  14254. for (int i = rayHits.Count - 1; i >= 0; i--)
  14255. {
  14256. if (t == 0)
  14257. id = rayHits[i].PartId;
  14258. else
  14259. id = rayHits[i].GroupId;
  14260. int hit = (int)hits[id];
  14261. if (hit > m_maxHitsPerPrimInCastRay)
  14262. {
  14263. rayHits.RemoveAt(i);
  14264. hit--;
  14265. hits[id] = hit;
  14266. }
  14267. }
  14268. }
  14269. }
  14270. // Parse hits into result list according to data flags
  14271. int hitCount = rayHits.Count;
  14272. if (hitCount > maxHits)
  14273. hitCount = maxHits;
  14274. for (int i = 0; i < hitCount; i++)
  14275. {
  14276. RayHit rayHit = rayHits[i];
  14277. if (getRootKey)
  14278. result.Add(new LSL_Key(rayHit.GroupId.ToString()));
  14279. else
  14280. result.Add(new LSL_Key(rayHit.PartId.ToString()));
  14281. result.Add(new LSL_Vector(rayHit.Position));
  14282. if (getLinkNum)
  14283. result.Add(new LSL_Integer(rayHit.Link));
  14284. if (getNormal)
  14285. result.Add(new LSL_Vector(rayHit.Normal));
  14286. }
  14287. result.Add(new LSL_Integer(hitCount));
  14288. // Add to throttle data
  14289. stopWatch.Stop();
  14290. lock (m_castRayCalls)
  14291. {
  14292. CastRayCall castRayCall = new CastRayCall
  14293. {
  14294. RegionId = regionId,
  14295. UserId = userId,
  14296. CalledMs = calledMs,
  14297. UsedMs = (int)stopWatch.ElapsedMilliseconds
  14298. };
  14299. m_castRayCalls.Add(castRayCall);
  14300. }
  14301. // Return hits
  14302. return result;
  14303. }
  14304. /// <summary>
  14305. /// Struct for transmitting parameters required for finding llCastRay ray hits.
  14306. /// </summary>
  14307. public struct RayTrans
  14308. {
  14309. public UUID PartId;
  14310. public UUID GroupId;
  14311. public int Link;
  14312. public Vector3 ScalePart;
  14313. public Vector3 PositionPart;
  14314. public Quaternion RotationPart;
  14315. public bool ShapeNeedsEnds;
  14316. public Vector3 Position1Ray;
  14317. public Vector3 Position1RayProj;
  14318. public Vector3 VectorRayProj;
  14319. }
  14320. /// <summary>
  14321. /// Struct for llCastRay ray hits.
  14322. /// </summary>
  14323. public struct RayHit
  14324. {
  14325. public UUID PartId;
  14326. public UUID GroupId;
  14327. public int Link;
  14328. public Vector3 Position;
  14329. public Vector3 Normal;
  14330. public float Distance;
  14331. }
  14332. /// <summary>
  14333. /// Struct for llCastRay throttle data.
  14334. /// </summary>
  14335. public struct CastRayCall
  14336. {
  14337. public UUID RegionId;
  14338. public UUID UserId;
  14339. public int CalledMs;
  14340. public int UsedMs;
  14341. }
  14342. /// <summary>
  14343. /// Helper to check if a ray intersects a shape bounding box.
  14344. /// </summary>
  14345. private bool RayIntersectsShapeBox(Vector3 pos1RayProj, Vector3 pos2RayProj, Vector3 shapeBoxMax)
  14346. {
  14347. // Skip if ray can't intersect bounding box;
  14348. Vector3 rayBoxProjMin = Vector3.Min(pos1RayProj, pos2RayProj);
  14349. Vector3 rayBoxProjMax = Vector3.Max(pos1RayProj, pos2RayProj);
  14350. if (
  14351. rayBoxProjMin.X > shapeBoxMax.X || rayBoxProjMin.Y > shapeBoxMax.Y || rayBoxProjMin.Z > shapeBoxMax.Z ||
  14352. rayBoxProjMax.X < -shapeBoxMax.X || rayBoxProjMax.Y < -shapeBoxMax.Y || rayBoxProjMax.Z < -shapeBoxMax.Z
  14353. )
  14354. return false;
  14355. // Check if ray intersect any bounding box side
  14356. int sign = 0;
  14357. float dist = 0.0f;
  14358. Vector3 posProj = Vector3.Zero;
  14359. Vector3 vecRayProj = pos2RayProj - pos1RayProj;
  14360. // Check both X sides unless ray is parallell to them
  14361. if (Math.Abs(vecRayProj.X) > m_floatToleranceInCastRay)
  14362. {
  14363. for (sign = -1; sign <= 1; sign += 2)
  14364. {
  14365. dist = ((float)sign * shapeBoxMax.X - pos1RayProj.X) / vecRayProj.X;
  14366. posProj = pos1RayProj + vecRayProj * dist;
  14367. if (Math.Abs(posProj.Y) <= shapeBoxMax.Y && Math.Abs(posProj.Z) <= shapeBoxMax.Z)
  14368. return true;
  14369. }
  14370. }
  14371. // Check both Y sides unless ray is parallell to them
  14372. if (Math.Abs(vecRayProj.Y) > m_floatToleranceInCastRay)
  14373. {
  14374. for (sign = -1; sign <= 1; sign += 2)
  14375. {
  14376. dist = ((float)sign * shapeBoxMax.Y - pos1RayProj.Y) / vecRayProj.Y;
  14377. posProj = pos1RayProj + vecRayProj * dist;
  14378. if (Math.Abs(posProj.X) <= shapeBoxMax.X && Math.Abs(posProj.Z) <= shapeBoxMax.Z)
  14379. return true;
  14380. }
  14381. }
  14382. // Check both Z sides unless ray is parallell to them
  14383. if (Math.Abs(vecRayProj.Z) > m_floatToleranceInCastRay)
  14384. {
  14385. for (sign = -1; sign <= 1; sign += 2)
  14386. {
  14387. dist = ((float)sign * shapeBoxMax.Z - pos1RayProj.Z) / vecRayProj.Z;
  14388. posProj = pos1RayProj + vecRayProj * dist;
  14389. if (Math.Abs(posProj.X) <= shapeBoxMax.X && Math.Abs(posProj.Y) <= shapeBoxMax.Y)
  14390. return true;
  14391. }
  14392. }
  14393. // No hits on bounding box so return false
  14394. return false;
  14395. }
  14396. /// <summary>
  14397. /// Helper to parse FacetedMesh for ray hits.
  14398. /// </summary>
  14399. private void AddRayInFacetedMesh(FacetedMesh mesh, RayTrans rayTrans, ref List<RayHit> rayHits)
  14400. {
  14401. if (mesh != null)
  14402. {
  14403. foreach (Face face in mesh.Faces)
  14404. {
  14405. for (int i = 0; i < face.Indices.Count; i += 3)
  14406. {
  14407. Tri triangle = new Tri
  14408. {
  14409. p1 = face.Vertices[face.Indices[i]].Position,
  14410. p2 = face.Vertices[face.Indices[i + 1]].Position,
  14411. p3 = face.Vertices[face.Indices[i + 2]].Position
  14412. };
  14413. AddRayInTri(triangle, rayTrans, ref rayHits);
  14414. }
  14415. }
  14416. }
  14417. }
  14418. /// <summary>
  14419. /// Helper to parse Tri (triangle) List for ray hits.
  14420. /// </summary>
  14421. private void AddRayInTris(List<Tri> triangles, RayTrans rayTrans, ref List<RayHit> rayHits)
  14422. {
  14423. foreach (Tri triangle in triangles)
  14424. {
  14425. AddRayInTri(triangle, rayTrans, ref rayHits);
  14426. }
  14427. }
  14428. /// <summary>
  14429. /// Helper to add ray hit in a Tri (triangle).
  14430. /// </summary>
  14431. private void AddRayInTri(Tri triProj, RayTrans rayTrans, ref List<RayHit> rayHits)
  14432. {
  14433. // Check for hit in triangle
  14434. if (HitRayInTri(triProj, rayTrans.Position1RayProj, rayTrans.VectorRayProj, out Vector3 posHitProj, out Vector3 normalProj))
  14435. {
  14436. // Hack to circumvent ghost face bug in PrimMesher by removing hits in (ghost) face plane through shape center
  14437. if (Math.Abs(Vector3.Dot(posHitProj, normalProj)) < m_floatToleranceInCastRay && !rayTrans.ShapeNeedsEnds)
  14438. return;
  14439. // Transform hit and normal to region coordinate system
  14440. Vector3 posHit = rayTrans.PositionPart + (posHitProj * rayTrans.ScalePart) * rayTrans.RotationPart;
  14441. Vector3 normal = Vector3.Normalize((normalProj * rayTrans.ScalePart) * rayTrans.RotationPart);
  14442. // Remove duplicate hits at triangle intersections
  14443. float distance = Vector3.Distance(rayTrans.Position1Ray, posHit);
  14444. for (int i = rayHits.Count - 1; i >= 0; i--)
  14445. {
  14446. if (rayHits[i].PartId != rayTrans.PartId)
  14447. break;
  14448. if (Math.Abs(rayHits[i].Distance - distance) < m_floatTolerance2InCastRay)
  14449. return;
  14450. }
  14451. // Build result data set
  14452. RayHit rayHit = new RayHit
  14453. {
  14454. PartId = rayTrans.PartId,
  14455. GroupId = rayTrans.GroupId,
  14456. Link = rayTrans.Link,
  14457. Position = posHit,
  14458. Normal = normal,
  14459. Distance = distance
  14460. };
  14461. rayHits.Add(rayHit);
  14462. }
  14463. }
  14464. /// <summary>
  14465. /// Helper to find ray hit in triangle
  14466. /// </summary>
  14467. bool HitRayInTri(Tri triProj, Vector3 pos1RayProj, Vector3 vecRayProj, out Vector3 posHitProj, out Vector3 normalProj)
  14468. {
  14469. float tol = m_floatToleranceInCastRay;
  14470. posHitProj = Vector3.Zero;
  14471. // Calculate triangle edge vectors
  14472. Vector3 vec1Proj = triProj.p2 - triProj.p1;
  14473. Vector3 vec2Proj = triProj.p3 - triProj.p2;
  14474. Vector3 vec3Proj = triProj.p1 - triProj.p3;
  14475. // Calculate triangle normal
  14476. normalProj = Vector3.Cross(vec1Proj, vec2Proj);
  14477. // Skip if degenerate triangle or ray parallell with triangle plane
  14478. float divisor = Vector3.Dot(vecRayProj, normalProj);
  14479. if (Math.Abs(divisor) < tol)
  14480. return false;
  14481. // Skip if exit and not configured to detect
  14482. if (divisor > tol && !m_detectExitsInCastRay)
  14483. return false;
  14484. // Skip if outside ray ends
  14485. float distanceProj = Vector3.Dot(triProj.p1 - pos1RayProj, normalProj) / divisor;
  14486. if (distanceProj < -tol || distanceProj > 1 + tol)
  14487. return false;
  14488. // Calculate hit position in triangle
  14489. posHitProj = pos1RayProj + vecRayProj * distanceProj;
  14490. // Skip if outside triangle bounding box
  14491. Vector3 triProjMin = Vector3.Min(Vector3.Min(triProj.p1, triProj.p2), triProj.p3);
  14492. Vector3 triProjMax = Vector3.Max(Vector3.Max(triProj.p1, triProj.p2), triProj.p3);
  14493. if (
  14494. posHitProj.X < triProjMin.X - tol || posHitProj.Y < triProjMin.Y - tol || posHitProj.Z < triProjMin.Z - tol ||
  14495. posHitProj.X > triProjMax.X + tol || posHitProj.Y > triProjMax.Y + tol || posHitProj.Z > triProjMax.Z + tol
  14496. )
  14497. return false;
  14498. // Skip if outside triangle
  14499. if (
  14500. Vector3.Dot(Vector3.Cross(vec1Proj, normalProj), posHitProj - triProj.p1) > tol ||
  14501. Vector3.Dot(Vector3.Cross(vec2Proj, normalProj), posHitProj - triProj.p2) > tol ||
  14502. Vector3.Dot(Vector3.Cross(vec3Proj, normalProj), posHitProj - triProj.p3) > tol
  14503. )
  14504. return false;
  14505. // Return hit
  14506. return true;
  14507. }
  14508. /// <summary>
  14509. /// Helper to parse selected parts of HeightMap into a Tri (triangle) List and calculate bounding box.
  14510. /// </summary>
  14511. private List<Tri> TrisFromHeightmapUnderRay(Vector3 posStart, Vector3 posEnd, out Vector3 lower, out Vector3 upper)
  14512. {
  14513. // Get bounding X-Y rectangle of terrain under ray
  14514. lower = Vector3.Min(posStart, posEnd);
  14515. upper = Vector3.Max(posStart, posEnd);
  14516. lower.X = (float)Math.Floor(lower.X);
  14517. lower.Y = (float)Math.Floor(lower.Y);
  14518. float zLower = float.MaxValue;
  14519. upper.X = (float)Math.Ceiling(upper.X);
  14520. upper.Y = (float)Math.Ceiling(upper.Y);
  14521. float zUpper = float.MinValue;
  14522. // Initialize Tri (triangle) List
  14523. List<Tri> triangles = new List<Tri>();
  14524. // Set parsing lane direction to major ray X-Y axis
  14525. Vector3 vec = posEnd - posStart;
  14526. float xAbs = Math.Abs(vec.X);
  14527. float yAbs = Math.Abs(vec.Y);
  14528. bool bigX = true;
  14529. if (yAbs > xAbs)
  14530. {
  14531. bigX = false;
  14532. vec = vec / yAbs;
  14533. }
  14534. else if (xAbs > yAbs || xAbs > 0.0f)
  14535. vec = vec / xAbs;
  14536. else
  14537. vec = new Vector3(1.0f, 1.0f, 0.0f);
  14538. // Simplify by start parsing in lower end of lane
  14539. if ((bigX && vec.X < 0.0f) || (!bigX && vec.Y < 0.0f))
  14540. {
  14541. Vector3 posTemp = posStart;
  14542. posStart = posEnd;
  14543. posEnd = posTemp;
  14544. vec = vec * -1.0f;
  14545. }
  14546. // First 1x1 rectangle under ray
  14547. float xFloorOld = 0.0f;
  14548. float yFloorOld = 0.0f;
  14549. Vector3 pos = posStart;
  14550. float xFloor = (float)Math.Floor(pos.X);
  14551. float yFloor = (float)Math.Floor(pos.Y);
  14552. AddTrisFromHeightmap(xFloor, yFloor, ref triangles, ref zLower, ref zUpper);
  14553. // Parse every remaining 1x1 rectangle under ray
  14554. while (pos != posEnd)
  14555. {
  14556. // Next 1x1 rectangle under ray
  14557. xFloorOld = xFloor;
  14558. yFloorOld = yFloor;
  14559. pos = pos + vec;
  14560. // Clip position to 1x1 rectangle border
  14561. xFloor = (float)Math.Floor(pos.X);
  14562. yFloor = (float)Math.Floor(pos.Y);
  14563. if (bigX && pos.X > xFloor)
  14564. {
  14565. pos.Y -= vec.Y * (pos.X - xFloor);
  14566. pos.X = xFloor;
  14567. }
  14568. else if (!bigX && pos.Y > yFloor)
  14569. {
  14570. pos.X -= vec.X * (pos.Y - yFloor);
  14571. pos.Y = yFloor;
  14572. }
  14573. // Last 1x1 rectangle under ray
  14574. if ((bigX && pos.X >= posEnd.X) || (!bigX && pos.Y >= posEnd.Y))
  14575. {
  14576. pos = posEnd;
  14577. xFloor = (float)Math.Floor(pos.X);
  14578. yFloor = (float)Math.Floor(pos.Y);
  14579. }
  14580. // Add new 1x1 rectangle in lane
  14581. if ((bigX && xFloor != xFloorOld) || (!bigX && yFloor != yFloorOld))
  14582. AddTrisFromHeightmap(xFloor, yFloor, ref triangles, ref zLower, ref zUpper);
  14583. // Add last 1x1 rectangle in old lane at lane shift
  14584. if (bigX && yFloor != yFloorOld)
  14585. AddTrisFromHeightmap(xFloor, yFloorOld, ref triangles, ref zLower, ref zUpper);
  14586. if (!bigX && xFloor != xFloorOld)
  14587. AddTrisFromHeightmap(xFloorOld, yFloor, ref triangles, ref zLower, ref zUpper);
  14588. }
  14589. // Finalize bounding box Z
  14590. lower.Z = zLower;
  14591. upper.Z = zUpper;
  14592. // Done and returning Tri (triangle)List
  14593. return triangles;
  14594. }
  14595. /// <summary>
  14596. /// Helper to add HeightMap squares into Tri (triangle) List and adjust bounding box.
  14597. /// </summary>
  14598. private void AddTrisFromHeightmap(float xPos, float yPos, ref List<Tri> triangles, ref float zLower, ref float zUpper)
  14599. {
  14600. int xInt = (int)xPos;
  14601. int yInt = (int)yPos;
  14602. // Corner 1 of 1x1 rectangle
  14603. int x = Util.Clamp<int>(xInt+1, 0, World.Heightmap.Width - 1);
  14604. int y = Util.Clamp<int>(yInt+1, 0, World.Heightmap.Height - 1);
  14605. Vector3 pos1 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14606. // Adjust bounding box
  14607. zLower = Math.Min(zLower, pos1.Z);
  14608. zUpper = Math.Max(zUpper, pos1.Z);
  14609. // Corner 2 of 1x1 rectangle
  14610. x = Util.Clamp<int>(xInt, 0, World.Heightmap.Width - 1);
  14611. y = Util.Clamp<int>(yInt+1, 0, World.Heightmap.Height - 1);
  14612. Vector3 pos2 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14613. // Adjust bounding box
  14614. zLower = Math.Min(zLower, pos2.Z);
  14615. zUpper = Math.Max(zUpper, pos2.Z);
  14616. // Corner 3 of 1x1 rectangle
  14617. x = Util.Clamp<int>(xInt, 0, World.Heightmap.Width - 1);
  14618. y = Util.Clamp<int>(yInt, 0, World.Heightmap.Height - 1);
  14619. Vector3 pos3 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14620. // Adjust bounding box
  14621. zLower = Math.Min(zLower, pos3.Z);
  14622. zUpper = Math.Max(zUpper, pos3.Z);
  14623. // Corner 4 of 1x1 rectangle
  14624. x = Util.Clamp<int>(xInt+1, 0, World.Heightmap.Width - 1);
  14625. y = Util.Clamp<int>(yInt, 0, World.Heightmap.Height - 1);
  14626. Vector3 pos4 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14627. // Adjust bounding box
  14628. zLower = Math.Min(zLower, pos4.Z);
  14629. zUpper = Math.Max(zUpper, pos4.Z);
  14630. // Add triangle 1
  14631. Tri triangle1 = new Tri
  14632. {
  14633. p1 = pos1,
  14634. p2 = pos2,
  14635. p3 = pos3
  14636. };
  14637. triangles.Add(triangle1);
  14638. // Add triangle 2
  14639. Tri triangle2 = new Tri
  14640. {
  14641. p1 = pos3,
  14642. p2 = pos4,
  14643. p3 = pos1
  14644. };
  14645. triangles.Add(triangle2);
  14646. }
  14647. /// <summary>
  14648. /// Helper to get link number for a UUID.
  14649. /// </summary>
  14650. private int UUID2LinkNumber(SceneObjectPart part, UUID id)
  14651. {
  14652. SceneObjectGroup group = part.ParentGroup;
  14653. if (group != null)
  14654. {
  14655. // Parse every link for UUID
  14656. int linkCount = group.PrimCount + group.GetSittingAvatarsCount();
  14657. for (int link = linkCount; link > 0; link--)
  14658. {
  14659. ISceneEntity entity = GetLinkEntity(part, link);
  14660. // Return link number if UUID match
  14661. if (entity != null && entity.UUID == id)
  14662. return link;
  14663. }
  14664. }
  14665. // Return link number 0 if no links or UUID matches
  14666. return 0;
  14667. }
  14668. public LSL_Integer llManageEstateAccess(int action, string avatar)
  14669. {
  14670. m_host.AddScriptLPS(1);
  14671. EstateSettings estate = World.RegionInfo.EstateSettings;
  14672. bool isAccount = false;
  14673. bool isGroup = false;
  14674. if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManagerOrOwner(m_host.OwnerID))
  14675. return 0;
  14676. UUID id = new UUID();
  14677. if (!UUID.TryParse(avatar, out id))
  14678. return 0;
  14679. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, id);
  14680. isAccount = account != null ? true : false;
  14681. if (!isAccount)
  14682. {
  14683. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  14684. if (groups != null)
  14685. {
  14686. GroupRecord group = groups.GetGroupRecord(id);
  14687. isGroup = group != null ? true : false;
  14688. if (!isGroup)
  14689. return 0;
  14690. }
  14691. else
  14692. return 0;
  14693. }
  14694. switch (action)
  14695. {
  14696. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_ADD:
  14697. if (!isAccount) return 0;
  14698. if (estate.HasAccess(id)) return 1;
  14699. if (estate.IsBanned(id, World.GetUserFlags(id)))
  14700. estate.RemoveBan(id);
  14701. estate.AddEstateUser(id);
  14702. break;
  14703. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_REMOVE:
  14704. if (!isAccount || !estate.HasAccess(id)) return 0;
  14705. estate.RemoveEstateUser(id);
  14706. break;
  14707. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_GROUP_ADD:
  14708. if (!isGroup) return 0;
  14709. if (estate.GroupAccess(id)) return 1;
  14710. estate.AddEstateGroup(id);
  14711. break;
  14712. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_GROUP_REMOVE:
  14713. if (!isGroup || !estate.GroupAccess(id)) return 0;
  14714. estate.RemoveEstateGroup(id);
  14715. break;
  14716. case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_ADD:
  14717. if (!isAccount) return 0;
  14718. if (estate.IsBanned(id, World.GetUserFlags(id))) return 1;
  14719. EstateBan ban = new EstateBan
  14720. {
  14721. EstateID = estate.EstateID,
  14722. BannedUserID = id
  14723. };
  14724. estate.AddBan(ban);
  14725. break;
  14726. case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_REMOVE:
  14727. if (!isAccount || !estate.IsBanned(id, World.GetUserFlags(id))) return 0;
  14728. estate.RemoveBan(id);
  14729. break;
  14730. default: return 0;
  14731. }
  14732. return 1;
  14733. }
  14734. public LSL_Integer llGetMemoryLimit()
  14735. {
  14736. m_host.AddScriptLPS(1);
  14737. // The value returned for Mono scripts in SL
  14738. return 65536;
  14739. }
  14740. public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
  14741. {
  14742. m_host.AddScriptLPS(1);
  14743. // Treat as an LSO script
  14744. return ScriptBaseClass.FALSE;
  14745. }
  14746. public LSL_Integer llGetSPMaxMemory()
  14747. {
  14748. m_host.AddScriptLPS(1);
  14749. // The value returned for Mono scripts in SL
  14750. return 65536;
  14751. }
  14752. public virtual LSL_Integer llGetUsedMemory()
  14753. {
  14754. m_host.AddScriptLPS(1);
  14755. // The value returned for Mono scripts in SL
  14756. return 65536;
  14757. }
  14758. public void llScriptProfiler(LSL_Integer flags)
  14759. {
  14760. m_host.AddScriptLPS(1);
  14761. // This does nothing for LSO scripts in SL
  14762. }
  14763. #region Not Implemented
  14764. //
  14765. // Listing the unimplemented lsl functions here, please move
  14766. // them from this region as they are completed
  14767. //
  14768. public void llSetSoundQueueing(int queue)
  14769. {
  14770. m_host.AddScriptLPS(1);
  14771. if (m_SoundModule != null)
  14772. m_SoundModule.SetSoundQueueing(m_host.UUID, queue == ScriptBaseClass.TRUE.value);
  14773. }
  14774. public void llCollisionSprite(LSL_String impact_sprite)
  14775. {
  14776. m_host.AddScriptLPS(1);
  14777. // Viewer 2.0 broke this and it's likely LL has no intention
  14778. // of fixing it. Therefore, letting this be a NOP seems appropriate.
  14779. }
  14780. public void llGodLikeRezObject(string inventory, LSL_Vector pos)
  14781. {
  14782. m_host.AddScriptLPS(1);
  14783. if (!World.Permissions.IsGod(m_host.OwnerID))
  14784. NotImplemented("llGodLikeRezObject");
  14785. AssetBase rezAsset = World.AssetService.Get(inventory);
  14786. if (rezAsset == null)
  14787. {
  14788. llSay(0, "Asset not found");
  14789. return;
  14790. }
  14791. SceneObjectGroup group = null;
  14792. try
  14793. {
  14794. string xmlData = Utils.BytesToString(rezAsset.Data);
  14795. group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
  14796. }
  14797. catch
  14798. {
  14799. llSay(0, "Asset not found");
  14800. return;
  14801. }
  14802. if (group == null)
  14803. {
  14804. llSay(0, "Asset not found");
  14805. return;
  14806. }
  14807. group.RootPart.AttachedPos = group.AbsolutePosition;
  14808. group.ResetIDs();
  14809. Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
  14810. World.AddNewSceneObject(group, true, llpos, Quaternion.Identity, Vector3.Zero);
  14811. group.CreateScriptInstances(0, true, World.DefaultScriptEngine, 3);
  14812. group.ScheduleGroupForFullUpdate();
  14813. // objects rezzed with this method are die_at_edge by default.
  14814. group.RootPart.SetDieAtEdge(true);
  14815. group.ResumeScripts();
  14816. m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
  14817. "object_rez", new Object[] {
  14818. new LSL_String(
  14819. group.RootPart.UUID.ToString()) },
  14820. new DetectParams[0]));
  14821. }
  14822. public LSL_Key llTransferLindenDollars(LSL_Key destination, LSL_Integer amount)
  14823. {
  14824. m_host.AddScriptLPS(1);
  14825. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  14826. UUID txn = UUID.Random();
  14827. UUID toID = UUID.Zero;
  14828. string replydata = "UnKnownError";
  14829. bool bad = true;
  14830. while(true)
  14831. {
  14832. if (amount <= 0)
  14833. {
  14834. replydata = "INVALID_AMOUNT";
  14835. break;
  14836. }
  14837. if (money == null)
  14838. {
  14839. replydata = "TRANSFERS_DISABLED";
  14840. break;
  14841. }
  14842. if (m_host.OwnerID == m_host.GroupID)
  14843. {
  14844. replydata = "GROUP_OWNED";
  14845. break;
  14846. }
  14847. if (m_item == null)
  14848. {
  14849. replydata = "SERVICE_ERROR";
  14850. break;
  14851. }
  14852. if (m_item.PermsGranter == UUID.Zero)
  14853. {
  14854. replydata = "MISSING_PERMISSION_DEBIT";
  14855. break;
  14856. }
  14857. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  14858. {
  14859. replydata = "MISSING_PERMISSION_DEBIT";
  14860. break;
  14861. }
  14862. if (!UUID.TryParse(destination, out toID))
  14863. {
  14864. replydata = "INVALID_AGENT";
  14865. break;
  14866. }
  14867. bad = false;
  14868. break;
  14869. }
  14870. if(bad)
  14871. {
  14872. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  14873. "transaction_result", new Object[] {
  14874. new LSL_String(txn.ToString()),
  14875. new LSL_Integer(0),
  14876. new LSL_String(replydata) },
  14877. new DetectParams[0]));
  14878. return txn.ToString();
  14879. }
  14880. //fire and forget...
  14881. Action<string> act = eventID =>
  14882. {
  14883. int replycode = 0;
  14884. try
  14885. {
  14886. UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, toID);
  14887. if (account == null)
  14888. {
  14889. replydata = "LINDENDOLLAR_ENTITYDOESNOTEXIST";
  14890. return;
  14891. }
  14892. bool result = money.ObjectGiveMoney( m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID,
  14893. toID, amount, txn, out string reason);
  14894. if (result)
  14895. {
  14896. replycode = 1;
  14897. replydata = destination + "," + amount.ToString();
  14898. return;
  14899. }
  14900. replydata = reason;
  14901. }
  14902. finally
  14903. {
  14904. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  14905. "transaction_result", new Object[] {
  14906. new LSL_String(txn.ToString()),
  14907. new LSL_Integer(replycode),
  14908. new LSL_String(replydata) },
  14909. new DetectParams[0]));
  14910. }
  14911. };
  14912. m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act);
  14913. return txn.ToString();
  14914. }
  14915. #endregion
  14916. protected LSL_List SetPrimParams(ScenePresence av, LSL_List rules, string originFunc, ref uint rulesParsed)
  14917. {
  14918. //This is a special version of SetPrimParams to deal with avatars which are sitting on the linkset.
  14919. int idx = 0;
  14920. int idxStart = 0;
  14921. bool positionChanged = false;
  14922. try
  14923. {
  14924. while (idx < rules.Length)
  14925. {
  14926. ++rulesParsed;
  14927. int code = rules.GetLSLIntegerItem(idx++);
  14928. int remain = rules.Length - idx;
  14929. idxStart = idx;
  14930. switch (code)
  14931. {
  14932. case (int)ScriptBaseClass.PRIM_POSITION:
  14933. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  14934. {
  14935. if (remain < 1)
  14936. return new LSL_List();
  14937. LSL_Vector v;
  14938. v = rules.GetVector3Item(idx++);
  14939. if(!av.LegacySitOffsets)
  14940. {
  14941. LSL_Vector sitOffset = (llRot2Up(new LSL_Rotation(av.Rotation.X, av.Rotation.Y, av.Rotation.Z, av.Rotation.W)) * av.Appearance.AvatarHeight * 0.02638f);
  14942. v = v + 2 * sitOffset;
  14943. }
  14944. av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
  14945. positionChanged = true;
  14946. }
  14947. break;
  14948. case (int)ScriptBaseClass.PRIM_ROTATION:
  14949. {
  14950. if (remain < 1)
  14951. return new LSL_List();
  14952. Quaternion r;
  14953. r = rules.GetQuaternionItem(idx++);
  14954. av.Rotation = m_host.GetWorldRotation() * r;
  14955. positionChanged = true;
  14956. }
  14957. break;
  14958. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  14959. {
  14960. if (remain < 1)
  14961. return new LSL_List();
  14962. LSL_Rotation r;
  14963. r = rules.GetQuaternionItem(idx++);
  14964. av.Rotation = r;
  14965. positionChanged = true;
  14966. }
  14967. break;
  14968. // parse rest doing nothing but number of parameters error check
  14969. case (int)ScriptBaseClass.PRIM_SIZE:
  14970. case (int)ScriptBaseClass.PRIM_MATERIAL:
  14971. case (int)ScriptBaseClass.PRIM_PHANTOM:
  14972. case (int)ScriptBaseClass.PRIM_PHYSICS:
  14973. case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  14974. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  14975. case (int)ScriptBaseClass.PRIM_NAME:
  14976. case (int)ScriptBaseClass.PRIM_DESC:
  14977. if (remain < 1)
  14978. return new LSL_List();
  14979. idx++;
  14980. break;
  14981. case (int)ScriptBaseClass.PRIM_GLOW:
  14982. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  14983. case (int)ScriptBaseClass.PRIM_TEXGEN:
  14984. if (remain < 2)
  14985. return new LSL_List();
  14986. idx += 2;
  14987. break;
  14988. case (int)ScriptBaseClass.PRIM_TYPE:
  14989. if (remain < 3)
  14990. return new LSL_List();
  14991. code = (int)rules.GetLSLIntegerItem(idx++);
  14992. remain = rules.Length - idx;
  14993. switch (code)
  14994. {
  14995. case (int)ScriptBaseClass.PRIM_TYPE_BOX:
  14996. case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
  14997. case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
  14998. if (remain < 6)
  14999. return new LSL_List();
  15000. idx += 6;
  15001. break;
  15002. case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
  15003. if (remain < 5)
  15004. return new LSL_List();
  15005. idx += 5;
  15006. break;
  15007. case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
  15008. case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
  15009. case (int)ScriptBaseClass.PRIM_TYPE_RING:
  15010. if (remain < 11)
  15011. return new LSL_List();
  15012. idx += 11;
  15013. break;
  15014. case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
  15015. if (remain < 2)
  15016. return new LSL_List();
  15017. idx += 2;
  15018. break;
  15019. }
  15020. break;
  15021. case (int)ScriptBaseClass.PRIM_COLOR:
  15022. case (int)ScriptBaseClass.PRIM_TEXT:
  15023. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  15024. case (int)ScriptBaseClass.PRIM_OMEGA:
  15025. case (int)ScriptBaseClass.PRIM_SIT_TARGET:
  15026. if (remain < 3)
  15027. return new LSL_List();
  15028. idx += 3;
  15029. break;
  15030. case (int)ScriptBaseClass.PRIM_TEXTURE:
  15031. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  15032. case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
  15033. if (remain < 5)
  15034. return new LSL_List();
  15035. idx += 5;
  15036. break;
  15037. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  15038. if (remain < 7)
  15039. return new LSL_List();
  15040. idx += 7;
  15041. break;
  15042. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  15043. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  15044. return new LSL_List();
  15045. return rules.GetSublist(idx, -1);
  15046. }
  15047. }
  15048. }
  15049. catch (InvalidCastException e)
  15050. {
  15051. Error(originFunc,string.Format(
  15052. " error running rule #{0}: arg #{1} {2}",
  15053. rulesParsed, idx - idxStart, e.Message));
  15054. }
  15055. finally
  15056. {
  15057. if (positionChanged)
  15058. av.SendTerseUpdateToAllClients();
  15059. }
  15060. return new LSL_List();
  15061. }
  15062. public LSL_List GetPrimParams(ScenePresence avatar, LSL_List rules, ref LSL_List res)
  15063. {
  15064. // avatars case
  15065. // replies as SL wiki
  15066. // SceneObjectPart sitPart = avatar.ParentPart; // most likelly it will be needed
  15067. SceneObjectPart sitPart = World.GetSceneObjectPart(avatar.ParentID); // maybe better do this expensive search for it in case it's gone??
  15068. int idx = 0;
  15069. while (idx < rules.Length)
  15070. {
  15071. int code = (int)rules.GetLSLIntegerItem(idx++);
  15072. int remain = rules.Length - idx;
  15073. switch (code)
  15074. {
  15075. case (int)ScriptBaseClass.PRIM_MATERIAL:
  15076. res.Add(new LSL_Integer((int)SOPMaterialData.SopMaterial.Flesh));
  15077. break;
  15078. case (int)ScriptBaseClass.PRIM_PHYSICS:
  15079. res.Add(new LSL_Integer(0));
  15080. break;
  15081. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  15082. res.Add(new LSL_Integer(0));
  15083. break;
  15084. case (int)ScriptBaseClass.PRIM_PHANTOM:
  15085. res.Add(new LSL_Integer(0));
  15086. break;
  15087. case (int)ScriptBaseClass.PRIM_POSITION:
  15088. Vector3 pos;
  15089. if (sitPart.ParentGroup.RootPart != null)
  15090. {
  15091. pos = avatar.OffsetPosition;
  15092. if(!avatar.LegacySitOffsets)
  15093. {
  15094. Vector3 sitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f *2.0f);
  15095. pos -= sitOffset;
  15096. }
  15097. SceneObjectPart sitroot = sitPart.ParentGroup.RootPart;
  15098. pos = sitroot.AbsolutePosition + pos * sitroot.GetWorldRotation();
  15099. }
  15100. else
  15101. pos = avatar.AbsolutePosition;
  15102. res.Add(new LSL_Vector(pos.X,pos.Y,pos.Z));
  15103. break;
  15104. case (int)ScriptBaseClass.PRIM_SIZE:
  15105. Vector3 s = avatar.Appearance.AvatarSize;
  15106. res.Add(new LSL_Vector(s.X, s.Y, s.Z));
  15107. break;
  15108. case (int)ScriptBaseClass.PRIM_ROTATION:
  15109. res.Add(new LSL_Rotation(avatar.GetWorldRotation()));
  15110. break;
  15111. case (int)ScriptBaseClass.PRIM_TYPE:
  15112. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TYPE_BOX));
  15113. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_HOLE_DEFAULT));
  15114. res.Add(new LSL_Vector(0f,1.0f,0f));
  15115. res.Add(new LSL_Float(0.0f));
  15116. res.Add(new LSL_Vector(0, 0, 0));
  15117. res.Add(new LSL_Vector(1.0f,1.0f,0f));
  15118. res.Add(new LSL_Vector(0, 0, 0));
  15119. break;
  15120. case (int)ScriptBaseClass.PRIM_TEXTURE:
  15121. if (remain < 1)
  15122. return new LSL_List();
  15123. int face = (int)rules.GetLSLIntegerItem(idx++);
  15124. if (face == ScriptBaseClass.ALL_SIDES)
  15125. {
  15126. for (face = 0; face < 21; face++)
  15127. {
  15128. res.Add(new LSL_String(""));
  15129. res.Add(new LSL_Vector(0,0,0));
  15130. res.Add(new LSL_Vector(0,0,0));
  15131. res.Add(new LSL_Float(0.0));
  15132. }
  15133. }
  15134. else
  15135. {
  15136. if (face >= 0 && face < 21)
  15137. {
  15138. res.Add(new LSL_String(""));
  15139. res.Add(new LSL_Vector(0,0,0));
  15140. res.Add(new LSL_Vector(0,0,0));
  15141. res.Add(new LSL_Float(0.0));
  15142. }
  15143. }
  15144. break;
  15145. case (int)ScriptBaseClass.PRIM_COLOR:
  15146. if (remain < 1)
  15147. return new LSL_List();
  15148. face = (int)rules.GetLSLIntegerItem(idx++);
  15149. if (face == ScriptBaseClass.ALL_SIDES)
  15150. {
  15151. for (face = 0; face < 21; face++)
  15152. {
  15153. res.Add(new LSL_Vector(0,0,0));
  15154. res.Add(new LSL_Float(0));
  15155. }
  15156. }
  15157. else
  15158. {
  15159. res.Add(new LSL_Vector(0,0,0));
  15160. res.Add(new LSL_Float(0));
  15161. }
  15162. break;
  15163. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  15164. if (remain < 1)
  15165. return new LSL_List();
  15166. face = (int)rules.GetLSLIntegerItem(idx++);
  15167. if (face == ScriptBaseClass.ALL_SIDES)
  15168. {
  15169. for (face = 0; face < 21; face++)
  15170. {
  15171. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
  15172. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
  15173. }
  15174. }
  15175. else
  15176. {
  15177. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
  15178. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
  15179. }
  15180. break;
  15181. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  15182. if (remain < 1)
  15183. return new LSL_List();
  15184. face = (int)rules.GetLSLIntegerItem(idx++);
  15185. if (face == ScriptBaseClass.ALL_SIDES)
  15186. {
  15187. for (face = 0; face < 21; face++)
  15188. {
  15189. res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
  15190. }
  15191. }
  15192. else
  15193. {
  15194. res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
  15195. }
  15196. break;
  15197. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  15198. res.Add(new LSL_Integer(0));
  15199. res.Add(new LSL_Integer(0));// softness
  15200. res.Add(new LSL_Float(0.0f)); // gravity
  15201. res.Add(new LSL_Float(0.0f)); // friction
  15202. res.Add(new LSL_Float(0.0f)); // wind
  15203. res.Add(new LSL_Float(0.0f)); // tension
  15204. res.Add(new LSL_Vector(0f,0f,0f));
  15205. break;
  15206. case (int)ScriptBaseClass.PRIM_TEXGEN:
  15207. // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
  15208. if (remain < 1)
  15209. return new LSL_List();
  15210. face = (int)rules.GetLSLIntegerItem(idx++);
  15211. if (face == ScriptBaseClass.ALL_SIDES)
  15212. {
  15213. for (face = 0; face < 21; face++)
  15214. {
  15215. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  15216. }
  15217. }
  15218. else
  15219. {
  15220. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  15221. }
  15222. break;
  15223. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  15224. res.Add(new LSL_Integer(0));
  15225. res.Add(new LSL_Vector(0f,0f,0f));
  15226. res.Add(new LSL_Float(0f)); // intensity
  15227. res.Add(new LSL_Float(0f)); // radius
  15228. res.Add(new LSL_Float(0f)); // falloff
  15229. break;
  15230. case (int)ScriptBaseClass.PRIM_GLOW:
  15231. if (remain < 1)
  15232. return new LSL_List();
  15233. face = (int)rules.GetLSLIntegerItem(idx++);
  15234. if (face == ScriptBaseClass.ALL_SIDES)
  15235. {
  15236. for (face = 0; face < 21; face++)
  15237. {
  15238. res.Add(new LSL_Float(0f));
  15239. }
  15240. }
  15241. else
  15242. {
  15243. res.Add(new LSL_Float(0f));
  15244. }
  15245. break;
  15246. case (int)ScriptBaseClass.PRIM_TEXT:
  15247. res.Add(new LSL_String(""));
  15248. res.Add(new LSL_Vector(0f,0f,0f));
  15249. res.Add(new LSL_Float(1.0f));
  15250. break;
  15251. case (int)ScriptBaseClass.PRIM_NAME:
  15252. res.Add(new LSL_String(avatar.Name));
  15253. break;
  15254. case (int)ScriptBaseClass.PRIM_DESC:
  15255. res.Add(new LSL_String(""));
  15256. break;
  15257. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  15258. Quaternion lrot = avatar.Rotation;
  15259. res.Add(new LSL_Rotation(lrot.X, lrot.Y, lrot.Z, lrot.W));
  15260. break;
  15261. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  15262. Vector3 lpos = avatar.OffsetPosition;
  15263. if(!avatar.LegacySitOffsets)
  15264. {
  15265. Vector3 lsitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f * 2.0f);
  15266. lpos -= lsitOffset;
  15267. }
  15268. res.Add(new LSL_Vector(lpos.X,lpos.Y,lpos.Z));
  15269. break;
  15270. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  15271. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  15272. return new LSL_List();
  15273. return rules.GetSublist(idx, -1);
  15274. }
  15275. }
  15276. return new LSL_List();
  15277. }
  15278. public void llSetAnimationOverride(LSL_String animState, LSL_String anim)
  15279. {
  15280. string state = String.Empty;
  15281. foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
  15282. {
  15283. if (kvp.Value.ToLower() == ((string)animState).ToLower())
  15284. {
  15285. state = kvp.Key;
  15286. break;
  15287. }
  15288. }
  15289. if (state == String.Empty)
  15290. {
  15291. llShout(ScriptBaseClass.DEBUG_CHANNEL, "Invalid animation state " + animState);
  15292. return;
  15293. }
  15294. if (m_item.PermsGranter == UUID.Zero)
  15295. {
  15296. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15297. return;
  15298. }
  15299. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS) == 0)
  15300. {
  15301. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15302. return;
  15303. }
  15304. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  15305. if (presence == null)
  15306. return;
  15307. UUID animID;
  15308. animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  15309. if (animID == UUID.Zero)
  15310. {
  15311. String animupper = ((string)anim).ToUpperInvariant();
  15312. DefaultAvatarAnimations.AnimsUUIDbyName.TryGetValue(animupper, out animID);
  15313. }
  15314. if (animID == UUID.Zero)
  15315. {
  15316. llShout(ScriptBaseClass.DEBUG_CHANNEL, "Animation not found");
  15317. return;
  15318. }
  15319. presence.SetAnimationOverride(state, animID);
  15320. }
  15321. public void llResetAnimationOverride(LSL_String animState)
  15322. {
  15323. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  15324. if (presence == null)
  15325. return;
  15326. if (m_item.PermsGranter == UUID.Zero)
  15327. {
  15328. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15329. return;
  15330. }
  15331. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS) == 0)
  15332. {
  15333. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15334. return;
  15335. }
  15336. if (animState == "ALL")
  15337. {
  15338. presence.SetAnimationOverride("ALL", UUID.Zero);
  15339. return;
  15340. }
  15341. string state = String.Empty;
  15342. foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
  15343. {
  15344. if (kvp.Value.ToLower() == ((string)animState).ToLower())
  15345. {
  15346. state = kvp.Key;
  15347. break;
  15348. }
  15349. }
  15350. if (state == String.Empty)
  15351. {
  15352. return;
  15353. }
  15354. presence.SetAnimationOverride(state, UUID.Zero);
  15355. }
  15356. public LSL_String llGetAnimationOverride(LSL_String animState)
  15357. {
  15358. m_host.AddScriptLPS(1);
  15359. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  15360. if (presence == null)
  15361. return String.Empty;
  15362. if (m_item.PermsGranter == UUID.Zero)
  15363. {
  15364. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15365. return String.Empty;
  15366. }
  15367. if ((m_item.PermsMask & (ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS | ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION)) == 0)
  15368. {
  15369. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  15370. return String.Empty;
  15371. }
  15372. string state = String.Empty;
  15373. foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
  15374. {
  15375. if (kvp.Value.ToLower() == ((string)animState).ToLower())
  15376. {
  15377. state = kvp.Key;
  15378. break;
  15379. }
  15380. }
  15381. if (state == String.Empty)
  15382. {
  15383. return String.Empty;
  15384. }
  15385. UUID animID = presence.GetAnimationOverride(state);
  15386. if (animID == UUID.Zero)
  15387. return animState;
  15388. foreach (KeyValuePair<string, UUID> kvp in DefaultAvatarAnimations.AnimsUUIDbyName)
  15389. {
  15390. if (kvp.Value == animID)
  15391. return kvp.Key.ToLower();
  15392. }
  15393. foreach (TaskInventoryItem item in m_host.Inventory.GetInventoryItems())
  15394. {
  15395. if (item.AssetID == animID)
  15396. return item.Name;
  15397. }
  15398. return String.Empty;
  15399. }
  15400. public LSL_Integer llGetDayLength()
  15401. {
  15402. m_host.AddScriptLPS(1);
  15403. if (m_envModule == null)
  15404. return 14400;
  15405. return m_envModule.GetDayLength(m_host.GetWorldPosition());
  15406. }
  15407. public LSL_Integer llGetRegionDayLength()
  15408. {
  15409. m_host.AddScriptLPS(1);
  15410. if (m_envModule == null)
  15411. return 14400;
  15412. return m_envModule.GetRegionDayLength();
  15413. }
  15414. public LSL_Integer llGetDayOffset()
  15415. {
  15416. m_host.AddScriptLPS(1);
  15417. if (m_envModule == null)
  15418. return 57600;
  15419. return m_envModule.GetDayOffset(m_host.GetWorldPosition());
  15420. }
  15421. public LSL_Integer llGetRegionDayOffset()
  15422. {
  15423. m_host.AddScriptLPS(1);
  15424. if (m_envModule == null)
  15425. return 57600;
  15426. return m_envModule.GetRegionDayOffset();
  15427. }
  15428. public LSL_Vector llGetSunDirection()
  15429. {
  15430. m_host.AddScriptLPS(1);
  15431. if (m_envModule == null)
  15432. return Vector3.Zero;
  15433. return m_envModule.GetSunDir(m_host.GetWorldPosition());
  15434. }
  15435. public LSL_Vector llGetRegionSunDirection()
  15436. {
  15437. m_host.AddScriptLPS(1);
  15438. if (m_envModule == null)
  15439. return Vector3.Zero;
  15440. float z = m_host.GetWorldPosition().Z;
  15441. return m_envModule.GetRegionSunDir(z);
  15442. }
  15443. public LSL_Vector llGetMoonDirection()
  15444. {
  15445. m_host.AddScriptLPS(1);
  15446. if (m_envModule == null)
  15447. return Vector3.Zero;
  15448. return m_envModule.GetMoonDir(m_host.GetWorldPosition());
  15449. }
  15450. public LSL_Vector llGetRegionMoonDirection()
  15451. {
  15452. m_host.AddScriptLPS(1);
  15453. if (m_envModule == null)
  15454. return Vector3.Zero;
  15455. float z = m_host.GetWorldPosition().Z;
  15456. return m_envModule.GetRegionMoonDir(z);
  15457. }
  15458. public LSL_Rotation llGetSunRotation()
  15459. {
  15460. m_host.AddScriptLPS(1);
  15461. if (m_envModule == null)
  15462. return Quaternion.Identity;
  15463. return m_envModule.GetSunRot(m_host.GetWorldPosition());
  15464. }
  15465. public LSL_Rotation llGetRegionSunRotation()
  15466. {
  15467. m_host.AddScriptLPS(1);
  15468. if (m_envModule == null)
  15469. return Quaternion.Identity;
  15470. float z = m_host.GetWorldPosition().Z;
  15471. return m_envModule.GetRegionSunRot(z);
  15472. }
  15473. public LSL_Rotation llGetMoonRotation()
  15474. {
  15475. m_host.AddScriptLPS(1);
  15476. if (m_envModule == null)
  15477. return Quaternion.Identity;
  15478. return m_envModule.GetMoonRot(m_host.GetWorldPosition());
  15479. }
  15480. public LSL_Rotation llGetRegionMoonRotation()
  15481. {
  15482. m_host.AddScriptLPS(1);
  15483. if (m_envModule == null)
  15484. return Quaternion.Identity;
  15485. float z = m_host.GetWorldPosition().Z;
  15486. return m_envModule.GetRegionMoonRot(z);
  15487. }
  15488. public LSL_List llJson2List(LSL_String json)
  15489. {
  15490. m_host.AddScriptLPS(1);
  15491. if (String.IsNullOrEmpty(json))
  15492. return new LSL_List();
  15493. if(json == "[]")
  15494. return new LSL_List();
  15495. if(json == "{}")
  15496. return new LSL_List();
  15497. char first = ((string)json)[0];
  15498. if(first != '[' && first !='{')
  15499. {
  15500. // we already have a single element
  15501. LSL_List l = new LSL_List();
  15502. l.Add(json);
  15503. return l;
  15504. }
  15505. LitJson.JsonData jsdata;
  15506. try
  15507. {
  15508. jsdata = LitJson.JsonMapper.ToObject(json);
  15509. }
  15510. catch (Exception e)
  15511. {
  15512. string m = e.Message; // debug point
  15513. return json;
  15514. }
  15515. try
  15516. {
  15517. return JsonParseTop(jsdata);
  15518. }
  15519. catch (Exception e)
  15520. {
  15521. string m = e.Message; // debug point
  15522. return (LSL_String)ScriptBaseClass.JSON_INVALID;
  15523. }
  15524. }
  15525. private LSL_List JsonParseTop(LitJson.JsonData elem)
  15526. {
  15527. LSL_List retl = new LSL_List();
  15528. if(elem == null)
  15529. retl.Add((LSL_String)ScriptBaseClass.JSON_NULL);
  15530. LitJson.JsonType elemType = elem.GetJsonType();
  15531. switch (elemType)
  15532. {
  15533. case LitJson.JsonType.Int:
  15534. retl.Add(new LSL_Integer((int)elem));
  15535. return retl;
  15536. case LitJson.JsonType.Boolean:
  15537. retl.Add((LSL_String)((bool)elem ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE));
  15538. return retl;
  15539. case LitJson.JsonType.Double:
  15540. retl.Add(new LSL_Float((double)elem));
  15541. return retl;
  15542. case LitJson.JsonType.None:
  15543. retl.Add((LSL_String)ScriptBaseClass.JSON_NULL);
  15544. return retl;
  15545. case LitJson.JsonType.String:
  15546. retl.Add(new LSL_String((string)elem));
  15547. return retl;
  15548. case LitJson.JsonType.Array:
  15549. foreach (LitJson.JsonData subelem in elem)
  15550. retl.Add(JsonParseTopNodes(subelem));
  15551. return retl;
  15552. case LitJson.JsonType.Object:
  15553. IDictionaryEnumerator e = ((IOrderedDictionary)elem).GetEnumerator();
  15554. while (e.MoveNext())
  15555. {
  15556. retl.Add(new LSL_String((string)e.Key));
  15557. retl.Add(JsonParseTopNodes((LitJson.JsonData)e.Value));
  15558. }
  15559. return retl;
  15560. default:
  15561. throw new Exception(ScriptBaseClass.JSON_INVALID);
  15562. }
  15563. }
  15564. private object JsonParseTopNodes(LitJson.JsonData elem)
  15565. {
  15566. if(elem == null)
  15567. return ((LSL_String)ScriptBaseClass.JSON_NULL);
  15568. LitJson.JsonType elemType = elem.GetJsonType();
  15569. switch (elemType)
  15570. {
  15571. case LitJson.JsonType.Int:
  15572. return (new LSL_Integer((int)elem));
  15573. case LitJson.JsonType.Boolean:
  15574. return ((bool)elem ? (LSL_String)ScriptBaseClass.JSON_TRUE : (LSL_String)ScriptBaseClass.JSON_FALSE);
  15575. case LitJson.JsonType.Double:
  15576. return (new LSL_Float((double)elem));
  15577. case LitJson.JsonType.None:
  15578. return ((LSL_String)ScriptBaseClass.JSON_NULL);
  15579. case LitJson.JsonType.String:
  15580. return (new LSL_String((string)elem));
  15581. case LitJson.JsonType.Array:
  15582. case LitJson.JsonType.Object:
  15583. string s = LitJson.JsonMapper.ToJson(elem);
  15584. return (LSL_String)s;
  15585. default:
  15586. throw new Exception(ScriptBaseClass.JSON_INVALID);
  15587. }
  15588. }
  15589. public LSL_String llList2Json(LSL_String type, LSL_List values)
  15590. {
  15591. try
  15592. {
  15593. StringBuilder sb = new StringBuilder();
  15594. if (type == ScriptBaseClass.JSON_ARRAY)
  15595. {
  15596. sb.Append("[");
  15597. int i= 0;
  15598. foreach (object o in values.Data)
  15599. {
  15600. sb.Append(ListToJson(o));
  15601. if((i++) < values.Data.Length - 1)
  15602. sb.Append(",");
  15603. }
  15604. sb.Append("]");
  15605. return (LSL_String)sb.ToString();;
  15606. }
  15607. else if (type == ScriptBaseClass.JSON_OBJECT)
  15608. {
  15609. sb.Append("{");
  15610. for (int i = 0; i < values.Data.Length; i += 2)
  15611. {
  15612. if (!(values.Data[i] is LSL_String))
  15613. return ScriptBaseClass.JSON_INVALID;
  15614. string key = ((LSL_String)values.Data[i]).m_string;
  15615. key = EscapeForJSON(key, true);
  15616. sb.Append(key);
  15617. sb.Append(":");
  15618. sb.Append(ListToJson(values.Data[i+1]));
  15619. if(i < values.Data.Length - 2)
  15620. sb.Append(",");
  15621. }
  15622. sb.Append("}");
  15623. return (LSL_String)sb.ToString();
  15624. }
  15625. return ScriptBaseClass.JSON_INVALID;
  15626. }
  15627. catch
  15628. {
  15629. return ScriptBaseClass.JSON_INVALID;
  15630. }
  15631. }
  15632. private string ListToJson(object o)
  15633. {
  15634. if (o is LSL_Float || o is double)
  15635. {
  15636. double float_val;
  15637. if (o is double)
  15638. float_val = ((double)o);
  15639. else
  15640. float_val = ((LSL_Float)o).value;
  15641. if(double.IsInfinity(float_val))
  15642. return "\"Inf\"";
  15643. if(double.IsNaN(float_val))
  15644. return "\"NaN\"";
  15645. return ((LSL_Float)float_val).ToString();
  15646. }
  15647. if (o is LSL_Integer || o is int)
  15648. {
  15649. int i;
  15650. if (o is int)
  15651. i = ((int)o);
  15652. else
  15653. i = ((LSL_Integer)o).value;
  15654. return i.ToString();
  15655. }
  15656. if (o is LSL_Rotation)
  15657. {
  15658. StringBuilder sb = new StringBuilder(128);
  15659. sb.Append("\"");
  15660. LSL_Rotation r = (LSL_Rotation)o;
  15661. sb.Append(r.ToString());
  15662. sb.Append("\"");
  15663. return sb.ToString();
  15664. }
  15665. if (o is LSL_Vector)
  15666. {
  15667. StringBuilder sb = new StringBuilder(128);
  15668. sb.Append("\"");
  15669. LSL_Vector v = (LSL_Vector)o;
  15670. sb.Append(v.ToString());
  15671. sb.Append("\"");
  15672. return sb.ToString();
  15673. }
  15674. if (o is LSL_String || o is string)
  15675. {
  15676. string str;
  15677. if (o is string)
  15678. str = ((string)o);
  15679. else
  15680. str = ((LSL_String)o).m_string;
  15681. if(str == ScriptBaseClass.JSON_TRUE || str == "true")
  15682. return "true";
  15683. if(str == ScriptBaseClass.JSON_FALSE ||str == "false")
  15684. return "false";
  15685. if(str == ScriptBaseClass.JSON_NULL || str == "null")
  15686. return "null";
  15687. str.Trim();
  15688. if(str.Length == 0)
  15689. return "\"\"";
  15690. if (str[0] == '{')
  15691. return str;
  15692. if (str[0] == '[')
  15693. return str;
  15694. return EscapeForJSON(str, true);
  15695. }
  15696. throw new IndexOutOfRangeException();
  15697. }
  15698. private string EscapeForJSON(string s, bool AddOuter)
  15699. {
  15700. int i;
  15701. char c;
  15702. String t;
  15703. int len = s.Length;
  15704. StringBuilder sb = new StringBuilder(len + 64);
  15705. if(AddOuter)
  15706. sb.Append("\"");
  15707. for (i = 0; i < len; i++)
  15708. {
  15709. c = s[i];
  15710. switch (c)
  15711. {
  15712. case '\\':
  15713. case '"':
  15714. case '/':
  15715. sb.Append('\\');
  15716. sb.Append(c);
  15717. break;
  15718. case '\b':
  15719. sb.Append("\\b");
  15720. break;
  15721. case '\t':
  15722. sb.Append("\\t");
  15723. break;
  15724. case '\n':
  15725. sb.Append("\\n");
  15726. break;
  15727. case '\f':
  15728. sb.Append("\\f");
  15729. break;
  15730. case '\r':
  15731. sb.Append("\\r");
  15732. break;
  15733. default:
  15734. if (c < ' ')
  15735. {
  15736. t = "000" + String.Format("{0:X}", c);
  15737. sb.Append("\\u" + t.Substring(t.Length - 4));
  15738. }
  15739. else
  15740. {
  15741. sb.Append(c);
  15742. }
  15743. break;
  15744. }
  15745. }
  15746. if(AddOuter)
  15747. sb.Append("\"");
  15748. return sb.ToString();
  15749. }
  15750. public LSL_String llJsonSetValue(LSL_String json, LSL_List specifiers, LSL_String value)
  15751. {
  15752. bool noSpecifiers = specifiers.Length == 0;
  15753. LitJson.JsonData workData;
  15754. try
  15755. {
  15756. if(noSpecifiers)
  15757. specifiers.Add(new LSL_Integer(0));
  15758. if(!String.IsNullOrEmpty(json))
  15759. workData = LitJson.JsonMapper.ToObject(json);
  15760. else
  15761. {
  15762. workData = new LitJson.JsonData();
  15763. workData.SetJsonType(LitJson.JsonType.Array);
  15764. }
  15765. }
  15766. catch (Exception e)
  15767. {
  15768. string m = e.Message; // debug point
  15769. return ScriptBaseClass.JSON_INVALID;
  15770. }
  15771. try
  15772. {
  15773. LitJson.JsonData replace = JsonSetSpecific(workData, specifiers, 0, value);
  15774. if(replace != null)
  15775. workData = replace;
  15776. }
  15777. catch (Exception e)
  15778. {
  15779. string m = e.Message; // debug point
  15780. return ScriptBaseClass.JSON_INVALID;
  15781. }
  15782. try
  15783. {
  15784. string r = LitJson.JsonMapper.ToJson(workData);
  15785. if(noSpecifiers)
  15786. r = r.Substring(1,r.Length -2); // strip leading and trailing brakets
  15787. return r;
  15788. }
  15789. catch (Exception e)
  15790. {
  15791. string m = e.Message; // debug point
  15792. }
  15793. return ScriptBaseClass.JSON_INVALID;
  15794. }
  15795. private LitJson.JsonData JsonSetSpecific(LitJson.JsonData elem, LSL_List specifiers, int level, LSL_String val)
  15796. {
  15797. object spec = specifiers.Data[level];
  15798. if(spec is LSL_String)
  15799. spec = ((LSL_String)spec).m_string;
  15800. else if (spec is LSL_Integer)
  15801. spec = ((LSL_Integer)spec).value;
  15802. if(!(spec is string || spec is int))
  15803. throw new IndexOutOfRangeException();
  15804. int speclen = specifiers.Data.Length - 1;
  15805. bool hasvalue = false;
  15806. LitJson.JsonData value = null;
  15807. LitJson.JsonType elemType = elem.GetJsonType();
  15808. if (elemType == LitJson.JsonType.Array)
  15809. {
  15810. if (spec is int)
  15811. {
  15812. int v = (int)spec;
  15813. int c = elem.Count;
  15814. if(v < 0 || (v != 0 && v > c))
  15815. throw new IndexOutOfRangeException();
  15816. if(v == c)
  15817. elem.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15818. else
  15819. {
  15820. hasvalue = true;
  15821. value = elem[v];
  15822. }
  15823. }
  15824. else if (spec is string)
  15825. {
  15826. if((string)spec == ScriptBaseClass.JSON_APPEND)
  15827. elem.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15828. else if(elem.Count < 2)
  15829. {
  15830. // our initial guess of array was wrong
  15831. LitJson.JsonData newdata = new LitJson.JsonData();
  15832. newdata.SetJsonType(LitJson.JsonType.Object);
  15833. IOrderedDictionary no = newdata as IOrderedDictionary;
  15834. no.Add((string)spec,JsonBuildRestOfSpec(specifiers, level + 1, val));
  15835. return newdata;
  15836. }
  15837. }
  15838. }
  15839. else if (elemType == LitJson.JsonType.Object)
  15840. {
  15841. if (spec is string)
  15842. {
  15843. IOrderedDictionary e = elem as IOrderedDictionary;
  15844. string key = (string)spec;
  15845. if(e.Contains(key))
  15846. {
  15847. hasvalue = true;
  15848. value = (LitJson.JsonData)e[key];
  15849. }
  15850. else
  15851. e.Add(key, JsonBuildRestOfSpec(specifiers, level + 1, val));
  15852. }
  15853. else if(spec is int && (int)spec == 0)
  15854. {
  15855. //we are replacing a object by a array
  15856. LitJson.JsonData newData = new LitJson.JsonData();
  15857. newData.SetJsonType(LitJson.JsonType.Array);
  15858. newData.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15859. return newData;
  15860. }
  15861. }
  15862. else
  15863. {
  15864. LitJson.JsonData newData = JsonBuildRestOfSpec(specifiers, level, val);
  15865. return newData;
  15866. }
  15867. if (hasvalue)
  15868. {
  15869. if (level < speclen)
  15870. {
  15871. LitJson.JsonData replace = JsonSetSpecific(value, specifiers, level + 1, val);
  15872. if(replace != null)
  15873. {
  15874. if(elemType == LitJson.JsonType.Array)
  15875. {
  15876. if(spec is int)
  15877. elem[(int)spec] = replace;
  15878. else if( spec is string)
  15879. {
  15880. LitJson.JsonData newdata = new LitJson.JsonData();
  15881. newdata.SetJsonType(LitJson.JsonType.Object);
  15882. IOrderedDictionary no = newdata as IOrderedDictionary;
  15883. no.Add((string)spec, replace);
  15884. return newdata;
  15885. }
  15886. }
  15887. else if(elemType == LitJson.JsonType.Object)
  15888. {
  15889. if(spec is string)
  15890. elem[(string)spec] = replace;
  15891. else if(spec is int && (int)spec == 0)
  15892. {
  15893. LitJson.JsonData newdata = new LitJson.JsonData();
  15894. newdata.SetJsonType(LitJson.JsonType.Array);
  15895. newdata.Add(replace);
  15896. return newdata;
  15897. }
  15898. }
  15899. }
  15900. return null;
  15901. }
  15902. else if(speclen == level)
  15903. {
  15904. if(val == ScriptBaseClass.JSON_DELETE)
  15905. {
  15906. if(elemType == LitJson.JsonType.Array)
  15907. {
  15908. if(spec is int)
  15909. {
  15910. IList el = elem as IList;
  15911. el.RemoveAt((int)spec);
  15912. }
  15913. }
  15914. else if(elemType == LitJson.JsonType.Object)
  15915. {
  15916. if(spec is string)
  15917. {
  15918. IOrderedDictionary eo = elem as IOrderedDictionary;
  15919. eo.Remove((string) spec);
  15920. }
  15921. }
  15922. return null;
  15923. }
  15924. LitJson.JsonData newval = null;
  15925. if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null")
  15926. newval = null;
  15927. else if(val == ScriptBaseClass.JSON_TRUE || val == "true")
  15928. newval = new LitJson.JsonData(true);
  15929. else if(val == ScriptBaseClass.JSON_FALSE || val == "false")
  15930. newval = new LitJson.JsonData(false);
  15931. else if(float.TryParse(val, out float num))
  15932. {
  15933. // assuming we are at en.us already
  15934. if(num - (int)num == 0.0f && !val.Contains("."))
  15935. newval = new LitJson.JsonData((int)num);
  15936. else
  15937. {
  15938. num = (float)Math.Round(num,6);
  15939. newval = new LitJson.JsonData((double)num);
  15940. }
  15941. }
  15942. else
  15943. {
  15944. string str = val.m_string;
  15945. newval = new LitJson.JsonData(str);
  15946. }
  15947. if(elemType == LitJson.JsonType.Array)
  15948. {
  15949. if(spec is int)
  15950. elem[(int)spec] = newval;
  15951. else if( spec is string)
  15952. {
  15953. LitJson.JsonData newdata = new LitJson.JsonData();
  15954. newdata.SetJsonType(LitJson.JsonType.Object);
  15955. IOrderedDictionary no = newdata as IOrderedDictionary;
  15956. no.Add((string)spec,newval);
  15957. return newdata;
  15958. }
  15959. }
  15960. else if(elemType == LitJson.JsonType.Object)
  15961. {
  15962. if(spec is string)
  15963. elem[(string)spec] = newval;
  15964. else if(spec is int && (int)spec == 0)
  15965. {
  15966. LitJson.JsonData newdata = new LitJson.JsonData();
  15967. newdata.SetJsonType(LitJson.JsonType.Array);
  15968. newdata.Add(newval);
  15969. return newdata;
  15970. }
  15971. }
  15972. }
  15973. }
  15974. if(val == ScriptBaseClass.JSON_DELETE)
  15975. throw new IndexOutOfRangeException();
  15976. return null;
  15977. }
  15978. private LitJson.JsonData JsonBuildRestOfSpec(LSL_List specifiers, int level, LSL_String val)
  15979. {
  15980. object spec = level >= specifiers.Data.Length ? null : specifiers.Data[level];
  15981. // 20131224 not used object specNext = i+1 >= specifiers.Data.Length ? null : specifiers.Data[i+1];
  15982. if (spec == null)
  15983. {
  15984. if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null")
  15985. return null;
  15986. if(val == ScriptBaseClass.JSON_DELETE)
  15987. throw new IndexOutOfRangeException();
  15988. if(val == ScriptBaseClass.JSON_TRUE || val == "true")
  15989. return new LitJson.JsonData(true);
  15990. if(val == ScriptBaseClass.JSON_FALSE || val == "false")
  15991. return new LitJson.JsonData(false);
  15992. if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null")
  15993. return null;
  15994. if(float.TryParse(val, out float num))
  15995. {
  15996. // assuming we are at en.us already
  15997. if(num - (int)num == 0.0f && !val.Contains("."))
  15998. return new LitJson.JsonData((int)num);
  15999. else
  16000. {
  16001. num = (float)Math.Round(num,6);
  16002. return new LitJson.JsonData(num);
  16003. }
  16004. }
  16005. else
  16006. {
  16007. string str = val.m_string;
  16008. return new LitJson.JsonData(str);
  16009. }
  16010. throw new IndexOutOfRangeException();
  16011. }
  16012. if(spec is LSL_String)
  16013. spec = ((LSL_String)spec).m_string;
  16014. else if (spec is LSL_Integer)
  16015. spec = ((LSL_Integer)spec).value;
  16016. if (spec is int ||
  16017. (spec is string && ((string)spec) == ScriptBaseClass.JSON_APPEND) )
  16018. {
  16019. if(spec is int && (int)spec != 0)
  16020. throw new IndexOutOfRangeException();
  16021. LitJson.JsonData newdata = new LitJson.JsonData();
  16022. newdata.SetJsonType(LitJson.JsonType.Array);
  16023. newdata.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  16024. return newdata;
  16025. }
  16026. else if (spec is string)
  16027. {
  16028. LitJson.JsonData newdata = new LitJson.JsonData();
  16029. newdata.SetJsonType(LitJson.JsonType.Object);
  16030. IOrderedDictionary no = newdata as IOrderedDictionary;
  16031. no.Add((string)spec,JsonBuildRestOfSpec(specifiers, level + 1, val));
  16032. return newdata;
  16033. }
  16034. throw new IndexOutOfRangeException();
  16035. }
  16036. private bool JsonFind(LitJson.JsonData elem, LSL_List specifiers, int level, out LitJson.JsonData value)
  16037. {
  16038. value = null;
  16039. if(elem == null)
  16040. return false;
  16041. object spec;
  16042. spec = specifiers.Data[level];
  16043. bool haveVal = false;
  16044. LitJson.JsonData next = null;
  16045. if (elem.GetJsonType() == LitJson.JsonType.Array)
  16046. {
  16047. if (spec is LSL_Integer)
  16048. {
  16049. int indx = (LSL_Integer)spec;
  16050. if(indx >= 0 && indx < elem.Count)
  16051. {
  16052. haveVal = true;
  16053. next = (LitJson.JsonData)elem[indx];
  16054. }
  16055. }
  16056. }
  16057. else if (elem.GetJsonType() == LitJson.JsonType.Object)
  16058. {
  16059. if (spec is LSL_String)
  16060. {
  16061. IOrderedDictionary e = elem as IOrderedDictionary;
  16062. string key = (LSL_String)spec;
  16063. if(e.Contains(key))
  16064. {
  16065. haveVal = true;
  16066. next = (LitJson.JsonData)e[key];
  16067. }
  16068. }
  16069. }
  16070. if (haveVal)
  16071. {
  16072. if(level == specifiers.Data.Length - 1)
  16073. {
  16074. value = next;
  16075. return true;
  16076. }
  16077. level++;
  16078. if(next == null)
  16079. return false;
  16080. LitJson.JsonType nextType = next.GetJsonType();
  16081. if(nextType != LitJson.JsonType.Object && nextType != LitJson.JsonType.Array)
  16082. return false;
  16083. return JsonFind(next, specifiers, level, out value);
  16084. }
  16085. return false;
  16086. }
  16087. public LSL_String llJsonGetValue(LSL_String json, LSL_List specifiers)
  16088. {
  16089. if(String.IsNullOrWhiteSpace(json))
  16090. return ScriptBaseClass.JSON_INVALID;
  16091. if(specifiers.Length > 0 && (json == "{}" || json == "[]"))
  16092. return ScriptBaseClass.JSON_INVALID;
  16093. char first = ((string)json)[0];
  16094. if((first != '[' && first !='{'))
  16095. {
  16096. if(specifiers.Length > 0)
  16097. return ScriptBaseClass.JSON_INVALID;
  16098. json = "[" + json + "]"; // could handle single element case.. but easier like this
  16099. specifiers.Add((LSL_Integer)0);
  16100. }
  16101. LitJson.JsonData jsonData;
  16102. try
  16103. {
  16104. jsonData = LitJson.JsonMapper.ToObject(json);
  16105. }
  16106. catch (Exception e)
  16107. {
  16108. string m = e.Message; // debug point
  16109. return ScriptBaseClass.JSON_INVALID;
  16110. }
  16111. LitJson.JsonData elem = null;
  16112. if(specifiers.Length == 0)
  16113. elem = jsonData;
  16114. else
  16115. {
  16116. if(!JsonFind(jsonData, specifiers, 0, out elem))
  16117. return ScriptBaseClass.JSON_INVALID;
  16118. }
  16119. return JsonElementToString(elem);
  16120. }
  16121. private LSL_String JsonElementToString(LitJson.JsonData elem)
  16122. {
  16123. if(elem == null)
  16124. return ScriptBaseClass.JSON_NULL;
  16125. LitJson.JsonType elemType = elem.GetJsonType();
  16126. switch(elemType)
  16127. {
  16128. case LitJson.JsonType.Array:
  16129. return new LSL_String(LitJson.JsonMapper.ToJson(elem));
  16130. case LitJson.JsonType.Boolean:
  16131. return new LSL_String((bool)elem ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE);
  16132. case LitJson.JsonType.Double:
  16133. double d= (double)elem;
  16134. string sd = String.Format(Culture.FormatProvider, "{0:0.0#####}",d);
  16135. return new LSL_String(sd);
  16136. case LitJson.JsonType.Int:
  16137. int i = (int)elem;
  16138. return new LSL_String(i.ToString());
  16139. case LitJson.JsonType.Long:
  16140. long l = (long)elem;
  16141. return new LSL_String(l.ToString());
  16142. case LitJson.JsonType.Object:
  16143. return new LSL_String(LitJson.JsonMapper.ToJson(elem));
  16144. case LitJson.JsonType.String:
  16145. string s = (string)elem;
  16146. return new LSL_String(s);
  16147. case LitJson.JsonType.None:
  16148. return ScriptBaseClass.JSON_NULL;
  16149. default:
  16150. return ScriptBaseClass.JSON_INVALID;
  16151. }
  16152. }
  16153. public LSL_String llJsonValueType(LSL_String json, LSL_List specifiers)
  16154. {
  16155. if(String.IsNullOrWhiteSpace(json))
  16156. return ScriptBaseClass.JSON_INVALID;
  16157. if(specifiers.Length > 0 && (json == "{}" || json == "[]"))
  16158. return ScriptBaseClass.JSON_INVALID;
  16159. char first = ((string)json)[0];
  16160. if((first != '[' && first !='{'))
  16161. {
  16162. if(specifiers.Length > 0)
  16163. return ScriptBaseClass.JSON_INVALID;
  16164. json = "[" + json + "]"; // could handle single element case.. but easier like this
  16165. specifiers.Add((LSL_Integer)0);
  16166. }
  16167. LitJson.JsonData jsonData;
  16168. try
  16169. {
  16170. jsonData = LitJson.JsonMapper.ToObject(json);
  16171. }
  16172. catch (Exception e)
  16173. {
  16174. string m = e.Message; // debug point
  16175. return ScriptBaseClass.JSON_INVALID;
  16176. }
  16177. LitJson.JsonData elem = null;
  16178. if(specifiers.Length == 0)
  16179. elem = jsonData;
  16180. else
  16181. {
  16182. if(!JsonFind(jsonData, specifiers, 0, out elem))
  16183. return ScriptBaseClass.JSON_INVALID;
  16184. }
  16185. if(elem == null)
  16186. return ScriptBaseClass.JSON_NULL;
  16187. LitJson.JsonType elemType = elem.GetJsonType();
  16188. switch(elemType)
  16189. {
  16190. case LitJson.JsonType.Array:
  16191. return ScriptBaseClass.JSON_ARRAY;
  16192. case LitJson.JsonType.Boolean:
  16193. return (bool)elem ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE;
  16194. case LitJson.JsonType.Double:
  16195. case LitJson.JsonType.Int:
  16196. case LitJson.JsonType.Long:
  16197. return ScriptBaseClass.JSON_NUMBER;
  16198. case LitJson.JsonType.Object:
  16199. return ScriptBaseClass.JSON_OBJECT;
  16200. case LitJson.JsonType.String:
  16201. string s = (string)elem;
  16202. if(s == ScriptBaseClass.JSON_NULL)
  16203. return ScriptBaseClass.JSON_NULL;
  16204. if(s == ScriptBaseClass.JSON_TRUE)
  16205. return ScriptBaseClass.JSON_TRUE;
  16206. if(s == ScriptBaseClass.JSON_FALSE)
  16207. return ScriptBaseClass.JSON_FALSE;
  16208. return ScriptBaseClass.JSON_STRING;
  16209. case LitJson.JsonType.None:
  16210. return ScriptBaseClass.JSON_NULL;
  16211. default:
  16212. return ScriptBaseClass.JSON_INVALID;
  16213. }
  16214. }
  16215. }
  16216. public class NotecardCache
  16217. {
  16218. private static ExpiringCacheOS<UUID, string[]> m_Notecards = new ExpiringCacheOS<UUID, string[]>(30000);
  16219. public static void Cache(UUID assetID, byte[] text)
  16220. {
  16221. if (m_Notecards.ContainsKey(assetID, 30000))
  16222. return;
  16223. m_Notecards.AddOrUpdate(assetID, SLUtil.ParseNotecardToArray(text), 30);
  16224. }
  16225. public static bool IsCached(UUID assetID)
  16226. {
  16227. return m_Notecards.ContainsKey(assetID, 30000);
  16228. }
  16229. public static int GetLines(UUID assetID)
  16230. {
  16231. if (m_Notecards.TryGetValue(assetID, 30000, out string[] text))
  16232. return text.Length;
  16233. return -1;
  16234. }
  16235. /// <summary>
  16236. /// Get a notecard line.
  16237. /// </summary>
  16238. /// <param name="assetID"></param>
  16239. /// <param name="lineNumber">Lines start at index 0</param>
  16240. /// <returns></returns>
  16241. public static string GetLine(UUID assetID, int lineNumber)
  16242. {
  16243. if (lineNumber >= 0 && m_Notecards.TryGetValue(assetID, 30000, out string[] text))
  16244. {
  16245. if (lineNumber >= text.Length)
  16246. return "\n\n\n";
  16247. return text[lineNumber];
  16248. }
  16249. return "";
  16250. }
  16251. /// <summary>
  16252. /// Get a notecard line.
  16253. /// </summary>
  16254. /// <param name="assetID"></param>
  16255. /// <param name="lineNumber">Lines start at index 0</param>
  16256. /// <param name="maxLength">
  16257. /// Maximum length of the returned line.
  16258. /// </param>
  16259. /// <returns>
  16260. /// If the line length is longer than <paramref name="maxLength"/>,
  16261. /// the return string will be truncated.
  16262. /// </returns>
  16263. public static string GetLine(UUID assetID, int lineNumber, int maxLength)
  16264. {
  16265. string line = GetLine(assetID, lineNumber);
  16266. if (line.Length > maxLength)
  16267. return line.Substring(0, maxLength);
  16268. return line;
  16269. }
  16270. }
  16271. }